[PATCH] drm/amdkfd: range check cp bad op exception interrupts

Kim, Jonathan Jonathan.Kim at amd.com
Thu Mar 21 16:21:38 UTC 2024


[Public]

Ping for review.

Thanks,

Jon

> -----Original Message-----
> From: Kim, Jonathan <Jonathan.Kim at amd.com>
> Sent: Wednesday, March 13, 2024 10:21 AM
> To: amd-gfx at lists.freedesktop.org
> Cc: Kuehling, Felix <Felix.Kuehling at amd.com>; Huang, JinHuiEric
> <JinHuiEric.Huang at amd.com>; Kim, Jonathan <Jonathan.Kim at amd.com>;
> Kim, Jonathan <Jonathan.Kim at amd.com>; Zhang, Jesse(Jie)
> <Jesse.Zhang at amd.com>
> Subject: [PATCH] drm/amdkfd: range check cp bad op exception interrupts
>
> Due to a CP interrupt bug, bad packet garbage exception codes are raised.
> Do a range check so that the debugger and runtime do not receive garbage
> codes.
> Update the user api to guard exception code type checking as well.
>
> Signed-off-by: Jonathan Kim <jonathan.kim at amd.com>
> Tested-by: Jesse Zhang <jesse.zhang at amd.com>
> ---
>  .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c    |  3 ++-
>  .../gpu/drm/amd/amdkfd/kfd_int_process_v11.c    |  3 ++-
>  drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c |  3 ++-
>  include/uapi/linux/kfd_ioctl.h                  | 17 ++++++++++++++---
>  4 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
> b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
> index a8e76287dde0..013d0a073b9b 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
> @@ -339,7 +339,8 @@ static void event_interrupt_wq_v10(struct kfd_node
> *dev,
>                               break;
>                       }
>                       kfd_signal_event_interrupt(pasid, context_id0 &
> 0x7fffff, 23);
> -             } else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE) {
> +             } else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE &&
> +
> KFD_DBG_EC_TYPE_IS_PACKET(KFD_DEBUG_CP_BAD_OP_ECODE(context_id
> 0))) {
>                       kfd_set_dbg_ev_from_interrupt(dev, pasid,
>                               KFD_DEBUG_DOORBELL_ID(context_id0),
>
>       KFD_EC_MASK(KFD_DEBUG_CP_BAD_OP_ECODE(context_id0)),
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v11.c
> b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v11.c
> index 7e2859736a55..fe2ad0c0de95 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v11.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v11.c
> @@ -328,7 +328,8 @@ static void event_interrupt_wq_v11(struct kfd_node
> *dev,
>               /* CP */
>               if (source_id == SOC15_INTSRC_CP_END_OF_PIPE)
>                       kfd_signal_event_interrupt(pasid, context_id0, 32);
> -             else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE)
> +             else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE &&
> +
> KFD_DBG_EC_TYPE_IS_PACKET(KFD_CTXID0_CP_BAD_OP_ECODE(context_id
> 0)))
>                       kfd_set_dbg_ev_from_interrupt(dev, pasid,
>                               KFD_CTXID0_DOORBELL_ID(context_id0),
>
>       KFD_EC_MASK(KFD_CTXID0_CP_BAD_OP_ECODE(context_id0)),
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
> b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
> index ff7392336795..5483211c5d3d 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
> @@ -388,7 +388,8 @@ static void event_interrupt_wq_v9(struct kfd_node
> *dev,
>                               break;
>                       }
>                       kfd_signal_event_interrupt(pasid, sq_int_data, 24);
> -             } else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE) {
> +             } else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE &&
> +
> KFD_DBG_EC_TYPE_IS_PACKET(KFD_DEBUG_CP_BAD_OP_ECODE(context_id
> 0))) {
>                       kfd_set_dbg_ev_from_interrupt(dev, pasid,
>                               KFD_DEBUG_DOORBELL_ID(context_id0),
>
>       KFD_EC_MASK(KFD_DEBUG_CP_BAD_OP_ECODE(context_id0)),
> diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
> index 9ce46edc62a5..2040a470ddb4 100644
> --- a/include/uapi/linux/kfd_ioctl.h
> +++ b/include/uapi/linux/kfd_ioctl.h
> @@ -913,14 +913,25 @@ enum kfd_dbg_trap_exception_code {
>                                KFD_EC_MASK(EC_DEVICE_NEW))
>  #define KFD_EC_MASK_PROCESS
>       (KFD_EC_MASK(EC_PROCESS_RUNTIME) |      \
>
> KFD_EC_MASK(EC_PROCESS_DEVICE_REMOVE))
> +#define KFD_EC_MASK_PACKET
>       (KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_DIM_INVALID) |
>       \
> +
> KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVA
> LID) |        \
> +
> KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_CODE_INVALID) |  \
> +
> KFD_EC_MASK(EC_QUEUE_PACKET_RESERVED) |       \
> +
> KFD_EC_MASK(EC_QUEUE_PACKET_UNSUPPORTED) |    \
> +
> KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID
> ) |   \
> +
> KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID) |      \
> +
> KFD_EC_MASK(EC_QUEUE_PACKET_VENDOR_UNSUPPORTED))
>
>  /* Checks for exception code types for KFD search */
> +#define KFD_DBG_EC_IS_VALID(ecode) (ecode > EC_NONE && ecode <
> EC_MAX)
>  #define KFD_DBG_EC_TYPE_IS_QUEUE(ecode)
>       \
> -                     (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_QUEUE))
> +                     (KFD_DBG_EC_IS_VALID(ecode)
> && !!(KFD_EC_MASK(ecode) & KFD_EC_MASK_QUEUE))
>  #define KFD_DBG_EC_TYPE_IS_DEVICE(ecode)                             \
> -                     (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_DEVICE))
> +                     (KFD_DBG_EC_IS_VALID(ecode)
> && !!(KFD_EC_MASK(ecode) & KFD_EC_MASK_DEVICE))
>  #define KFD_DBG_EC_TYPE_IS_PROCESS(ecode)
>       \
> -                     (!!(KFD_EC_MASK(ecode) &
> KFD_EC_MASK_PROCESS))
> +                     (KFD_DBG_EC_IS_VALID(ecode)
> && !!(KFD_EC_MASK(ecode) & KFD_EC_MASK_PROCESS))
> +#define KFD_DBG_EC_TYPE_IS_PACKET(ecode)
>       \
> +                     (KFD_DBG_EC_IS_VALID(ecode)
> && !!(KFD_EC_MASK(ecode) & KFD_EC_MASK_PACKET))
>
>
>  /* Runtime enable states */
> --
> 2.34.1



More information about the amd-gfx mailing list