Introduce AMD GPU ISA Debugging for HSA Compute
Subsystems (3)
cover Introduce AMD GPU ISA Debugging for HSA Compute
This series is to expose the required KFD IOCTLs targeted to enable ROCm's extension of the GNU Debugger for HSA compute debugging.
The series is divided into the following sections:
Section 1 - Drawing out the interfaces and preparing the KFD for enable/disable calls
[PATCH 01/29] drm/amdkfd: add debug and runtime enable interface [PATCH 02/29] drm/amdkfd: display debug capabilities [PATCH 03/29] drm/amdkfd: prepare per-process debug enable and
Section 2 - HW initialization and handling the per device HW debug mode enable/disable requirement
[PATCH 04/29] drm/amdgpu: add kgd hw debug mode setting interface [PATCH 05/29] drm/amdgpu: setup hw debug registers on driver [PATCH 06/29] drm/amdgpu: add gfx9 hw debug mode enable and disable [PATCH 07/29] drm/amdgpu: add gfx9.4.1 hw debug mode enable and [PATCH 08/29] drm/amdgpu: add gfx10 hw debug mode enable and disable [PATCH 09/29] drm/amdgpu: add gfx9.4.2 hw debug mode enable and
Section 3 - Preparation for HW debug mode setting and event handling
[PATCH 10/29] drm/amdgpu: add configurable grace period for unmap [PATCH 11/29] drm/amdkfd: prepare map process for single process [PATCH 12/29] drm/amdgpu: prepare map process for multi-process debug [PATCH 13/29] drm/amdkfd: add per process hw trap enable and disable [PATCH 14/29] drm/amdkfd: add raise exception event function [PATCH 15/29] drm/amdkfd: add send exception operation [PATCH 16/29] drm/amdkfd: add runtime enable operation [PATCH 17/29] drm/amdkfd: Add debug trap enabled flag to TMA [PATCH 18/29] drm/amdkfd: update process interrupt handling for debug
Section 4 - Implementation of the HW debug mode setting operations
[PATCH 19/29] drm/amdkfd: add debug set exceptions enabled operation [PATCH 20/29] drm/amdkfd: add debug wave launch override operation [PATCH 21/29] drm/amdkfd: add debug wave launch mode operation [PATCH 22/29] drm/amdkfd: add debug suspend and resume process queues [PATCH 23/29] drm/amdkfd: add debug set and clear address watch [PATCH 24/29] drm/amdkfd: add debug set flags operation [PATCH 25/29] drm/amdkfd: add debug query event operation [PATCH 26/29] drm/amdkfd: add debug query exception info operation [PATCH 27/29] drm/amdkfd: add debug queue snapshot operation [PATCH 28/29] drm/amdkfd: add debug device snapshot operation
Section 5 - Final version bump for interface access checks
[PATCH 29/29] drm/amdkfd: bump kfd ioctl minor version for debug api
BR,
Jon
PATCH 1/29 drm/amdkfd: add debug and runtime enable interface
Introduce the GPU debug operations interface.
For ROCm-GDB to extend the GNU Debugger's ability to inspect the AMD GPU instruction set, provide the necessary interface to allow the debugger to HW debug-mode set and query exceptions per HSA queue, process or device.
The runtime_enable interface coordinates exception handling with the HSA runtime.
Full documention is available in the kern docs at uapi/linux/kfd_ioctl.h.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 48 ++ include/uapi/linux/kfd_ioctl.h | 562 ++++++++++++++++++++++- 2 files changed, 609 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +48 -0
@@ -2614,6 +2614,48 @@ static int kfd_ioctl_criu(struct file *filep, struct kfd_process *p, void *data)return ret; } +static int kfd_ioctl_runtime_enable (struct file *filep,struct kfd_process *p,void *data) +{ +return 0 ; +} + +static int kfd_ioctl_set_debug_trap (struct file *filep,struct kfd_process *p,void *data) +{ +struct kfd_ioctl_dbg_trap_args *args = data; +int r =0 ; + +if (sched_policy ==KFD_SCHED_POLICY_NO_HWS ) { +pr_err ("Debugging does not support sched_policy %i" , sched_policy); +return -EINVAL ; + } + +switch (args->op) { +case KFD_IOC_DBG_TRAP_ENABLE : +case KFD_IOC_DBG_TRAP_DISABLE : +case KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT : +case KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED : +case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE : +case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE : +case KFD_IOC_DBG_TRAP_SUSPEND_QUEUES : +case KFD_IOC_DBG_TRAP_RESUME_QUEUES : +case KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH : +case KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH : +case KFD_IOC_DBG_TRAP_SET_FLAGS : +case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : +case KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO : +case KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT : +case KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT : +pr_warn ("Debugging not supported yet\n" ); + r = -EPERM ; +break ; +default : +pr_err ("Invalid option: %i\n" , args->op); + r = -EINVAL ; + } + +return r; +} +#define AMDKFD_IOCTL_DEF (ioctl, _func, _flags) \ [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags, \ .cmd_drv = 0, .name = #ioctl}
@@ -2723,6 +2765,12 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {AMDKFD_IOCTL_DEF (AMDKFD_IOC_AVAILABLE_MEMORY , kfd_ioctl_get_available_memory,0 ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_RUNTIME_ENABLE , + kfd_ioctl_runtime_enable,0 ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_DBG_TRAP , + kfd_ioctl_set_debug_trap, 0), };#define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls)
include/uapi/linux/kfd_ioctl.h +561 -1
580 lines not on this page · raw message
Signature · 1 line
2.25.1
Felix Kuehling
maintainerRe: [PATCH 01/29] drm/amdkfd: add debug and runtime enable interface
Quoted 11 lines · Jonathan Kim
Introduce the GPU debug operations interface.
For ROCm-GDB to extend the GNU Debugger's ability to inspect the AMD GPU instruction set, provide the necessary interface to allow the debugger to HW debug-mode set and query exceptions per HSA queue, process or device.
The
runtime_enableinterface coordinates exception handling with the HSA runtime.Full documention is available in the kern docs at
uapi/linux/kfd_ioctl.h.
"Full documentation" is a bold claim. ;) Some more specific comments and suggestions inline.
Quoted 255 lines
Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 48 ++ include/uapi/linux/kfd_ioctl.h | 562 ++++++++++++++++++++++- 2 files changed, 609 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +48
-0@@ -2614,6 +2614,48 @@ static int kfd_ioctl_criu(struct file *filep, struct kfd_process *p, void *data)return ret; } +static int kfd_ioctl_runtime_enable (struct file *filep,struct kfd_process *p,void *data) +{ +return 0 ; +} + +static int kfd_ioctl_set_debug_trap (struct file *filep,struct kfd_process *p,void *data) +{ +struct kfd_ioctl_dbg_trap_args *args = data; +int r =0 ; + +if (sched_policy ==KFD_SCHED_POLICY_NO_HWS ) { +pr_err ("Debugging does not support sched_policy %i" , sched_policy); +return -EINVAL ; + } + +switch (args->op) { +case KFD_IOC_DBG_TRAP_ENABLE : +case KFD_IOC_DBG_TRAP_DISABLE : +case KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT : +case KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED : +case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE : +case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE : +case KFD_IOC_DBG_TRAP_SUSPEND_QUEUES : +case KFD_IOC_DBG_TRAP_RESUME_QUEUES : +case KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH : +case KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH : +case KFD_IOC_DBG_TRAP_SET_FLAGS : +case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : +case KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO : +case KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT : +case KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT : +pr_warn ("Debugging not supported yet\n" ); + r = -EPERM ; +break ; +default : +pr_err ("Invalid option: %i\n" , args->op); + r = -EINVAL ; + } + +return r; +} +#define AMDKFD_IOCTL_DEF (ioctl, _func, _flags) \ [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags, \ .cmd_drv = 0, .name = #ioctl}@@ -2723,6 +2765,12 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {AMDKFD_IOCTL_DEF (AMDKFD_IOC_AVAILABLE_MEMORY , kfd_ioctl_get_available_memory,0 ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_RUNTIME_ENABLE , + kfd_ioctl_runtime_enable,0 ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_DBG_TRAP , + kfd_ioctl_set_debug_trap, 0), };#define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls)include/uapi/linux/kfd_ioctl.h +167
-0@@ -109,6 +109,18 @@ struct kfd_ioctl_get_available_memory_args {__u32 pad; }; +struct kfd_dbg_device_info_entry { +__u64 exception_status; +__u64 lds_base; +__u64 lds_limit; +__u64 scratch_base; +__u64 scratch_limit; +__u64 gpuvm_base; +__u64 gpuvm_limit; +__u32 gpu_id; +__u32 pad; +}; +/* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */ #define KFD_IOC_CACHE_POLICY_COHERENT 0#define KFD_IOC_CACHE_POLICY_NONCOHERENT 1@@ -766,6 +778,548 @@ struct kfd_ioctl_set_xnack_mode_args {__s32 xnack_enabled; }; +/* Wave launch override modes */ +enum kfd_dbg_trap_override_mode { +KFD_DBG_TRAP_OVERRIDE_OR =0 , +KFD_DBG_TRAP_OVERRIDE_REPLACE =1 +}; + +/* Wave launch overrides */ +enum kfd_dbg_trap_mask { +KFD_DBG_TRAP_MASK_FP_INVALID =1 , +KFD_DBG_TRAP_MASK_FP_INPUT_DENORMAL =2 , +KFD_DBG_TRAP_MASK_FP_DIVIDE_BY_ZERO =4 , +KFD_DBG_TRAP_MASK_FP_OVERFLOW =8 , +KFD_DBG_TRAP_MASK_FP_UNDERFLOW =16 , +KFD_DBG_TRAP_MASK_FP_INEXACT =32 , +KFD_DBG_TRAP_MASK_INT_DIVIDE_BY_ZERO =64 , +KFD_DBG_TRAP_MASK_DBG_ADDRESS_WATCH =128 , +KFD_DBG_TRAP_MASK_DBG_MEMORY_VIOLATION =256 +}; + +/* Wave launch modes */ +enum kfd_dbg_trap_wave_launch_mode { +KFD_DBG_TRAP_WAVE_LAUNCH_MODE_NORMAL =0 , +KFD_DBG_TRAP_WAVE_LAUNCH_MODE_HALT =1 , +KFD_DBG_TRAP_WAVE_LAUNCH_MODE_KILL =2 , +KFD_DBG_TRAP_WAVE_LAUNCH_MODE_DEBUG =3 , +KFD_DBG_TRAP_WAVE_LAUNCH_MODE_STALL =4 +}; + +/* Address watch modes */ +enum kfd_dbg_trap_address_watch_mode { +KFD_DBG_TRAP_ADDRESS_WATCH_MODE_READ =0 , +KFD_DBG_TRAP_ADDRESS_WATCH_MODE_NONREAD =1 , +KFD_DBG_TRAP_ADDRESS_WATCH_MODE_ATOMIC =2 , +KFD_DBG_TRAP_ADDRESS_WATCH_MODE_ALL =3 +}; + +/* Additional wave settings */ +enum kfd_dbg_trap_flags { +KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP =1 , +KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP =2 +}; + +/* Trap exceptions */ +enum kfd_dbg_trap_exception_code { +EC_NONE =0 , +/* per queue */ +EC_QUEUE_WAVE_ABORT =1 , +EC_QUEUE_WAVE_TRAP =2 , +EC_QUEUE_WAVE_MATH_ERROR =3 , +EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION =4 , +EC_QUEUE_WAVE_MEMORY_VIOLATION =5 , +EC_QUEUE_WAVE_APERTURE_VIOLATION =6 , +EC_QUEUE_PACKET_DISPATCH_DIM_INVALID =16 , +EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID =17 , +EC_QUEUE_PACKET_DISPATCH_CODE_INVALID =18 , +EC_QUEUE_PACKET_RESERVED =19 , +EC_QUEUE_PACKET_UNSUPPORTED =20 , +EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID =21 , +EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID =22 , +EC_QUEUE_PACKET_VENDOR_UNSUPPORTED =23 , +EC_QUEUE_PREEMPTION_ERROR =30 , +EC_QUEUE_NEW =31 , +/* per device */ +EC_DEVICE_QUEUE_DELETE =32 , +EC_DEVICE_MEMORY_VIOLATION =33 , +EC_DEVICE_RAS_ERROR =34 , +EC_DEVICE_FATAL_HALT =35 , +EC_DEVICE_NEW =36 , +/* per process */ +EC_PROCESS_RUNTIME =48 , +EC_PROCESS_DEVICE_REMOVE =49 , +EC_MAX +}; + +/* Mask generated by ecode in kfd_dbg_trap_exception_code */ +#define KFD_EC_MASK (ecode) (1ULL << (ecode - 1)) + +/* Masks for exception code type checks below */ +#define KFD_EC_MASK_QUEUE (KFD_EC_MASK(EC_QUEUE_WAVE_ABORT) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_TRAP) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_MATH_ERROR) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_MEMORY_VIOLATION) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_APERTURE_VIOLATION) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_DIM_INVALID) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_CODE_INVALID) | \ + 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) | \ + KFD_EC_MASK(EC_QUEUE_PREEMPTION_ERROR) | \ + KFD_EC_MASK(EC_QUEUE_NEW)) +#define KFD_EC_MASK_DEVICE (KFD_EC_MASK(EC_DEVICE_QUEUE_DELETE) | \ + KFD_EC_MASK(EC_DEVICE_RAS_ERROR) | \ + KFD_EC_MASK(EC_DEVICE_FATAL_HALT) | \ + KFD_EC_MASK(EC_DEVICE_MEMORY_VIOLATION) | \ + KFD_EC_MASK(EC_DEVICE_NEW)) +#define KFD_EC_MASK_PROCESS (KFD_EC_MASK(EC_PROCESS_RUNTIME) | \ + KFD_EC_MASK(EC_PROCESS_DEVICE_REMOVE)) + +/* Checks for exception code types for KFD search */ +#define KFD_DBG_EC_TYPE_IS_QUEUE (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)) +#define KFD_DBG_EC_TYPE_IS_PROCESS (ecode) \ + (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_PROCESS)) + + +/* Runtime enable states */ +enum kfd_dbg_runtime_state { +DEBUG_RUNTIME_STATE_DISABLED =0 , +DEBUG_RUNTIME_STATE_ENABLED =1 , +DEBUG_RUNTIME_STATE_ENABLED_BUSY =2 , +DEBUG_RUNTIME_STATE_ENABLED_ERROR =3 +}; + +/* Runtime enable status */ +struct kfd_runtime_info { +__u64 r_debug; +__u32 runtime_state; +__u32 ttmp_setup; +}; + +/* Enable modes for runtime enable */ +#define KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK 1 +#define KFD_RUNTIME_ENABLE_MODE_TTMP_SAVE_MASK 2 + +/** +* kfd_ioctl_runtime_enable_args - Arguments for runtime enable +* +* Coordinates debug exception signalling and debug device enablement with runtime. +* +* @r_debug - pointer to user struct for sharing information between ROCr and the debuggger +* @mode_mask - mask to set mode +* KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK - enable runtime for debugging, otherwise disable +* KFD_RUNTIME_ENABLE_MODE_TTMP_SAVE_MASK - enable trap temporary setup (ignore on disable) +* +* Return - 0 on SUCCESS. +* - EBUSY if runtime enable call already pending. +* - EEXIST if user queues already active prior to call. +* If process is debug enabled, runtime enable will enable debug devices and +* wait for debugger process to send runtime exception EC_PROCESS_RUNTIME +* to unblock - see kfd_ioctl_dbg_trap_args. +* +*/ +struct kfd_ioctl_runtime_enable_args { +__u64 r_debug; +__u32 mode_mask; +}; + +/* Queue information */ +struct kfd_queue_snapshot_entry { +__u64 exception_status;
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 945
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+__u64 ring_base_address; +__u64 write_pointer_address; +__u64 read_pointer_address; +__u64 ctx_save_restore_address; +__u32 queue_id; +__u32 gpu_id; +__u32 ring_size; +__u32 queue_type; +__u32 ctx_save_restore_area_size; +__u32 reserved[17 ];
Probably a single u32 of padding is sufficient, since we added a mechanism to grow this struct in backwards compatible way in the future.
Quoted 44 lines
include/uapi/linux/kfd_ioctl.h +44
-0+}; + +/* Queue status return for suspend/resume */ +#define KFD_DBG_QUEUE_ERROR_BIT 30 +#define KFD_DBG_QUEUE_INVALID_BIT 31 +#define KFD_DBG_QUEUE_ERROR_MASK (1 << KFD_DBG_QUEUE_ERROR_BIT) +#define KFD_DBG_QUEUE_INVALID_MASK (1 << KFD_DBG_QUEUE_INVALID_BIT) + +/* Context save area header information */ +struct kfd_context_save_area_header { +__u32 control_stack_offset; +__u32 control_stack_size; +__u32 wave_state_offset; +__u32 wave_state_size; +__u32 debug_offset; +__u32 debug_size; +__u64 err_payload_addr; +__u32 err_event_id; +__u32 reserved1; +}; + +/* Debug operations */ +enum kfd_dbg_trap_operations { +KFD_IOC_DBG_TRAP_ENABLE =0 , +KFD_IOC_DBG_TRAP_DISABLE =1 , +KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT =2 , +KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED =3 , +KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE =4 , +KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE =5 , +KFD_IOC_DBG_TRAP_SUSPEND_QUEUES =6 , +KFD_IOC_DBG_TRAP_RESUME_QUEUES =7 , +KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH =8 , +KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH =9 , +KFD_IOC_DBG_TRAP_SET_FLAGS =10 , +KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT =11 , +KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO =12 , +KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT =13 , +KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT =14 +}; + +/** +* kfd_ioctl_dbg_trap_enable_args +* +* Arguments for KFD_IOC_DBG_TRAP_ENABLE.
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 999
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+* +* Enables debug session for target process. Call @op KFD_IOC_DBG_TRAP_DISABLE in +* kfd_ioctl_dbg_trap_args to disable debug session. +* +* @exception_mask (IN) - exceptions to raise to the debugger +* @rinfo_ptr (IN) - pointer to runtime info buffer (see kfd_runtime_info) +* @rinfo_size (IN/OUT) - size of runtime info buffer in bytes +* @dbg_fd (IN) - fd the KFD will nofify the debugger with of raised +* exceptions set in exception_mask +* Return - 0 on SUCCESS.
Please document possible error conditions and the corresponding error codes.
Quoted 11 lines
include/uapi/linux/kfd_ioctl.h +11
-0+* Copies KFD saved kfd_runtime_info to @rinfo_ptr on enable. +* Size of kfd_runtime saved by the KFD returned to @rinfo_size. +*/ +struct kfd_ioctl_dbg_trap_enable_args { +__u64 exception_mask; +__u64 rinfo_ptr; +__u32 rinfo_size; +__u32 dbg_fd; +}; + +/**
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1020
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+* kfd_ioctl_dbg_trap_send_runtime_event_args +* +* Arguments for KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT. +* Raises exceptions to runtime. +* +* @exception_mask (IN) - exceptions to raise to runtime +* @gpu_id (IN) - target device id +* @queue_id (IN) - target queue id +* +* Return - 0 on SUCCESS.
Please document possible error conditions and the corresponding error codes.
Quoted 22 lines
include/uapi/linux/kfd_ioctl.h +22
-0+* If exception_mask contains EC_PROCESS_RUNTIME, unblocks pending +* AMDKFD_IOC_RUNTIME_ENABLE call - see kfd_ioctl_runtime_enable_args. +* All other exceptions are raised to runtime through err_payload_addr. +* See kfd_context_save_area_header. +*/ +struct kfd_ioctl_dbg_trap_send_runtime_event_args { +__u64 exception_mask; +__u32 gpu_id; +__u32 queue_id; +}; + +/** +* kfd_ioctl_dbg_trap_set_exceptions_enabled_args +* +* Arguments for KFD_IOC_SET_EXCEPTIONS_ENABLED +* Set new exceptions to be raised to the debugger. +* +* @exception_mask (IN) - new exceptions to raise the debugger +*/ +struct kfd_ioctl_dbg_trap_set_exceptions_enabled_args { +__u64 exception_mask; +};
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1052
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+ +/** +* kfd_ioctl_dbg_trap_set_wave_launch_override_args +* +* Arguments for KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE +* Enable HW exceptions to raise trap. +* +* @override_mode (IN) - see kfd_dbg_trap_override_mode +* @enable_mask (IN/OUT) - see kfd_dbg_trap_mask +* @support_request_mask (IN/OUT) - see kfd_dbg_trap_mask
The meaning of the enable_mask and support_request_mask needs more explanation.
Quoted 14 lines
include/uapi/linux/kfd_ioctl.h +14
-0+* +* Return - 0 on SUCCESS. +* - EPERM if mode is not supported. +* - EPERM if mode is not supported. +* - EACCES if trap support requested is not actually supported. +* Previous enablement is returned in @enable_mask. +* Actual support is returned in @support_request_mask. +*/ +struct kfd_ioctl_dbg_trap_set_wave_launch_override_args { +__u32 override_mode; +__u32 enable_mask; +__u32 support_request_mask; +__u32 pad; +};
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1076
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+ +/** +* kfd_ioctl_dbg_trap_set_wave_launch_mode_args +* +* Arguments for KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE +* Set wave launch mode. +* +* @mode (IN) - see kfd_dbg_trap_wave_launch_mode +* +* Return - 0 on SUCCESS.
Please document possible error conditions and the corresponding error codes.
Quoted 4 lines
include/uapi/linux/kfd_ioctl.h +4
-0+*/ +struct kfd_ioctl_dbg_trap_set_wave_launch_mode_args { +__u32 launch_mode; +__u32 pad;
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1090
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+}; + +/** +* kfd_ioctl_dbg_trap_suspend_queues_args +* +* Arguments for KFD_IOC_DBG_TRAP_SUSPEND_QUEUES +* Suspend queues. +* +* @exception_mask (IN) - raised exceptions to clear +* @queue_array_ptr (IN) - pointer to array of queue ids (DWORD per queue id)
Better to call this "u32 per queue id". DWORD is ambiguous.
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1093
Quoted 3 lines
include/uapi/linux/kfd_ioctl.h +3
-0+* to suspend +* @num_queues (IN) - number of queues to suspend in @queue_array_ptr +* @grace_period (IN) - wave time allowance before preemption
What's the unit for the grace period?
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1102
Quoted 9 lines
include/uapi/linux/kfd_ioctl.h +9
-0+* +* Return - Number of queues suspended on SUCCESS. +* KFD_DBG_QUEUE_ERROR_MASK and KFD_DBG_QUEUE_INVALID_MASK masked +* for each queue id in @queue_array_ptr array reports unsuccessful +* suspend reason. +* KFD_DBG_QUEUE_ERROR_MASK = HW failure. +* KFD_DBG_QUEUE_INVALID_MASK = queue does not exist, is new or +* is being destroyed. +* Suspended queues can never be destroyed.
I think this should say "Destroying of suspended queues blocks until the queue is resumed. This allows the debugger to access queue information and context save areas of suspended queues without fears of racing with a queue destruction."
Quoted 8 lines
include/uapi/linux/kfd_ioctl.h +8
-0+* Automatically copies per queue context save area header information +* into the save area base +* (see kfd_queue_snapshot_entry and kfd_context_save_area_header). +*/ +struct kfd_ioctl_dbg_trap_suspend_queues_args { +__u64 exception_mask; +__u64 queue_array_ptr; +__u32 num_queues;
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1120
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+__u32 grace_period; +}; + +/** +* kfd_ioctl_dbg_trap_resume_queues_args +* +* Arguments for KFD_IOC_DBG_TRAP_RESUME_QUEUES +* Resume queues. +* +* @queue_array_ptr (IN) - pointer to array of queue ids (DWORD per queue id)
DWORD -> u32
Quoted 19 lines
include/uapi/linux/kfd_ioctl.h +19
-0+* to resume +* @num_queues (IN) - number of queues to resume in @queue_array_ptr +* +* Return - Number of queues resumed on SUCCESS. +* KFD_DBG_QUEUE_ERROR_MASK and KFD_DBG_QUEUE_INVALID_MASK mask +* for each queue id in @queue_array_ptr array reports unsuccessful +* resume reason. +* KFD_DBG_QUEUE_ERROR_MASK = HW failure. +* KFD_DBG_QUEUE_INVALID_MASK = queue does not exist. +*/ +struct kfd_ioctl_dbg_trap_resume_queues_args { +__u64 queue_array_ptr; +__u32 num_queues; +__u32 pad; +}; + +/** +* kfd_ioctl_dbg_trap_set_node_address_watch_args +*
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1149
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+* Arguments for KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH +* Sets address watch for device. +* +* @address (IN) - watch address to set +* @mode (IN) - see kfd_dbg_trap_address_watch_mode +* @mask (IN) - watch address mask +* @dev_id (IN) - target device to set watch point +* @id (OUT) - watch id allocated +* +* Return - 0 on SUCCESS.
Please document possible error conditions and the corresponding error codes.
Quoted 23 lines
include/uapi/linux/kfd_ioctl.h +23
-0+* Allocated watch ID returned to @id. +*/ +struct kfd_ioctl_dbg_trap_set_node_address_watch_args { +__u64 address; +__u32 mode; +__u32 mask; +__u32 dev_id; +__u32 id; +}; + +/** +* kfd_ioctl_dbg_trap_clear_node_address_watch_args +* +* Arguments for KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH +* Clear address watch for device. +* +* @dev_id (IN) - target device to clear watch point +* @id (IN) - allocated watch id to clear +* +* Return - 0 on SUCCESS. +*/ +struct kfd_ioctl_dbg_trap_clear_node_address_watch_args { +__u32 dev_id;
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1182
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+__u32 id; +}; + +/** +* kfd_ioctl_dbg_trap_set_flags_args +* +* Arguments for KFD_IOC_DBG_TRAP_SET_FLAGS +* Sets flags for wave behaviour. +* +* @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled
(see kfd_dbg_trap_flags).
Quoted 4 lines
include/uapi/linux/kfd_ioctl.h +4
-0+* +* Return - 0 on SUCCESS. +* - EPERM if any debug device does not allow flag options. +*/
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1196
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+struct kfd_ioctl_dbg_trap_set_flags_args { +__u32 flags; +__u32 pad; +}; + +/** +* kfd_ioctl_dbg_trap_query_debug_event_args +* +* Arguments for KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT +* Find a raised exception.
Find one ore more raised exceptions. This function can return multiple exceptions from a single queue or a single device with one call. To find all raised exceptions, this function must be called repeatedly until it returns -EAGAIN. Returned exceptions can optionally be cleared by setting the corresponding bit in the @exception_mask input parameter. However, clearing an exception prevents retrieving further information about it with KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO.
Quoted 44 lines
include/uapi/linux/kfd_ioctl.h +44
-0+* +* @exception_mask (IN/OUT) - exception to clear (IN) and raised (OUT) +* @gpu_id (OUT) - gpu id of exceptions raised +* @queue_id (OUT) - queue id of exceptions raised +* +* Return - 0 on raised exception found +* - EAGAIN if no raised exception has been found +* Raised exceptions found are returned in @exception mask +* with reported source id returned in @gpu_id or @queue_id. +*/ +struct kfd_ioctl_dbg_trap_query_debug_event_args { +__u64 exception_mask; +__u32 gpu_id; +__u32 queue_id; +}; + +/** +* kfd_ioctl_dbg_trap_query_exception_info_args +* +* Arguments KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO +* Get additional info on raised exception. +* +* @info_ptr (IN) - pointer to exception info buffer to copy to +* @info_size (IN/OUT) - exception info buffer size (bytes) +* @source_id (IN) - target gpu or queue id +* @exception_code (IN) - target exception +* @clear_exception (IN) - clear raised @exception_code exception +* (0 = false, 1 = true) +* +* Return - 0 on SUCCESS. +* If @exception_code is EC_DEVICE_MEMORY_VIOLATION, copy @info_size(OUT) +* bytes of memory exception data to @info_ptr. +* If @exception_code is EC_PROCESS_RUNTIME, copy saved +* kfd_runtime_info to @info_ptr. +* Actual required @info_ptr size (bytes) is returned in @info_size. +*/ +struct kfd_ioctl_dbg_trap_query_exception_info_args { +__u64 info_ptr; +__u32 info_size; +__u32 source_id; +__u32 exception_code; +__u32 clear_exception; +}; +
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1250
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+/** +* kfd_ioctl_dbg_trap_get_queue_snapshot_args +* +* Arguments KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT +* Get queue information. +* +* @exception_mask (IN) - exceptions raised to clear +* @snapshot_buf_ptr (IN) - queue snapshot entry buffer +* (see kfd_queue_snapshot_entry) +* @buf_size (IN/OUT) - number of queue snapshot entries
Call this num_queues to avoid ambiguity.
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1251
Quoted 1 line
include/uapi/linux/kfd_ioctl.h +1
-0+* @entry_size (IN/OUT) - size per entry in bytes
The debugger specifies the size of the array allocated in @num_queues. KFD returns the number of queues that actually existed. If this is larger than the size specified by the debugger, KFD will not overflow the array allocated by the debugger.
The debugger specifies sizeof(struct kfd_queue_snapshot_entry) in @entry_size. KFD returns the number of bytes actually populated per entry. The debugger should use the KFD_IOCTL_MINOR_VERSION to determine, which fields in struct kfd_queue_snapshot_entry are valid. This allows growing the ABI in a backwards compatible manner.
Quoted 11 lines
include/uapi/linux/kfd_ioctl.h +11
-0+* +* Return - 0 on SUCCESS. +* Copies @size(IN) queue snapshot entries into @snapshot_buf_ptr if +* @buf_size(IN) > 0. +* Otherwise return @buf_size(OUT) queue snapshot entries that exist. +*/ +struct kfd_ioctl_dbg_trap_queue_snapshot_args { +__u64 exception_mask; +__u64 snapshot_buf_ptr; +__u32 buf_size; +__u32 entry_size;
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1272
Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +10
-0+}; + +/** +* kfd_ioctl_dbg_trap_get_device_snapshot_args +* +* Arguments for KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT +* Get device information. +* +* @exception_mask (IN) - exceptions raised to clear +* @snapshot_buf_ptr (IN) - pointer to snapshot buffer (see kfd_device_snapshot_entry)
The definition of struct kfd_device_snapshot_entry is missing in this patch.
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1273
Quoted 1 line
include/uapi/linux/kfd_ioctl.h +1
-0+* @buf_size (IN/OUT) - number of debug devices to snapshot
Call this num_devices to avoid ambiguity.
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1274
Quoted 1 line
include/uapi/linux/kfd_ioctl.h +1
-0+* @entry_size (IN/OUT) - size per entry in bytes
The debugger specifies the size of the array allocated in @num_devices. KFD returns the number of devices that actually existed.
The debugger specifies sizeof(struct kfd_device_snapshot_entry) in @entry_size. KFD returns the number of bytes actually populated. The debugger should use KFD_IOCTL_MINOR_VERSION to determine, which fields in struct kfd_device_snapshot_entry are valid. This allows growing the ABI in a backwards compatible manner.
include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_set_xnack_mode_args { · line 1278
Quoted 4 lines
include/uapi/linux/kfd_ioctl.h +4
-0+* +* Return - 0 on SUCCESS. +* - ENOSPC if requested number of debug devices is less than the +* actual number of debug devices.
This is different from now the queue snapshot works. Is there a reason for this difference? Maybe it's because the number of devices is expected to be static and should be known by the debugger ahead of time, while the number of queues can change dynamically. However, given that the queue and device snapshot interfaces are otherwise identical, this subtle semantic difference is a bit disturbing.
Regards,
Felix
Quoted 62 lines
include/uapi/linux/kfd_ioctl.h +51
-1+* Copies @buf_size(OUT) number of device snapshot entries into +* @snapshot_buf_ptr. +* Actual number of device snapshot entries returned in @buf_size. +*/ +struct kfd_ioctl_dbg_trap_device_snapshot_args { +__u64 exception_mask; +__u64 snapshot_buf_ptr; +__u32 buf_size; +__u32 entry_size; +}; + +/** +* kfd_ioctl_dbg_trap_args +* +* Arguments to debug target process. +* +* @pid - target process to debug +* @op - debug operation (see kfd_dbg_trap_operations) +* +* @op determines which union struct args to use. +* Refer to kern docs for each kfd_ioctl_dbg_trap_*_args struct. +*/ +struct kfd_ioctl_dbg_trap_args { +__u32 pid; +__u32 op; + +union { +struct kfd_ioctl_dbg_trap_enable_args enable; +struct kfd_ioctl_dbg_trap_send_runtime_event_args send_runtime_event; +struct kfd_ioctl_dbg_trap_set_exceptions_enabled_args set_exceptions_enabled; +struct kfd_ioctl_dbg_trap_set_wave_launch_override_args launch_override; +struct kfd_ioctl_dbg_trap_set_wave_launch_mode_args launch_mode; +struct kfd_ioctl_dbg_trap_suspend_queues_args suspend_queues; +struct kfd_ioctl_dbg_trap_resume_queues_args resume_queues; +struct kfd_ioctl_dbg_trap_set_node_address_watch_args set_node_address_watch; +struct kfd_ioctl_dbg_trap_clear_node_address_watch_args clear_node_address_watch; +struct kfd_ioctl_dbg_trap_set_flags_args set_flags; +struct kfd_ioctl_dbg_trap_query_debug_event_args query_debug_event; +struct kfd_ioctl_dbg_trap_query_exception_info_args query_exception_info; +struct kfd_ioctl_dbg_trap_queue_snapshot_args queue_snapshot; +struct kfd_ioctl_dbg_trap_device_snapshot_args device_snapshot; + }; +}; +#define AMDKFD_IOCTL_BASE 'K'#define AMDKFD_IO (nr) _IO(AMDKFD_IOCTL_BASE, nr)#define AMDKFD_IOR (nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type)@@ -877,7 +1431,13 @@ struct kfd_ioctl_set_xnack_mode_args {#define AMDKFD_IOC_AVAILABLE_MEMORY \ AMDKFD_IOWR(0x23, struct kfd_ioctl_get_available_memory_args) +#define AMDKFD_IOC_RUNTIME_ENABLE \ + AMDKFD_IOWR(0x24, struct kfd_ioctl_runtime_enable_args) + +#define AMDKFD_IOC_DBG_TRAP \ + AMDKFD_IOWR(0x25, struct kfd_ioctl_dbg_trap_args) +#define AMDKFD_COMMAND_START 0x01 -#define AMDKFD_COMMAND_END 0x24 +#define AMDKFD_COMMAND_END 0x26#endif
PATCH 2/29 drm/amdkfd: display debug capabilities
In reply to Jonathan KimExpose debug capabilities in the KFD topology node's HSA capabilities and debug properties flags.
Ensure correct capabilities are exposed based on firmware support.
Flag definitions can be referenced in uapi/linux/kfd_sysfs.h.
--- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 88 +++++++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_topology.h | 6 ++ include/uapi/linux/kfd_sysfs.h | 15 ++++ 3 files changed, 104 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +83 -5
@@ -551,6 +551,8 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr, dev->gpu->mec_fw_version);sysfs_show_32bit_prop (buffer, offs,"capability" , dev->node_props.capability); +sysfs_show_64bit_prop (buffer, offs,"debug_prop" , + dev->node_props.debug_prop);sysfs_show_32bit_prop (buffer, offs,"sdma_fw_version" , dev->gpu->sdma_fw_version); sysfs_show_64bit_prop(buffer, offs, "unique_id",
@@ -1593,6 +1595,84 @@ static int kfd_dev_create_p2p_links(void)return ret; } +static void kfd_topology_set_dbg_firmware_support (struct kfd_topology_device *dev) +{ +bool firmware_supported = true; + +/* +* Note: Any unlisted devices here are assumed to support exception handling. +* Add additional checks here as needed. +*/ +switch (KFD_GC_VERSION (dev->gpu)) { +case IP_VERSION (9 ,0 ,1 ):/* Vega10 */ + firmware_supported = dev->gpu->mec_fw_version >=459 +32768 ; +break ; +case IP_VERSION (9 ,1 ,0 ):/* Raven */ +case IP_VERSION (9 ,2 ,1 ):/* Vega12 */ +case IP_VERSION (9 ,2 ,2 ):/* Raven */ +case IP_VERSION (9 ,3 ,0 ):/* Renoir */ +case IP_VERSION (9 ,4 ,0 ):/* Vega20 */ + firmware_supported = dev->gpu->mec_fw_version >=459 ; +break ; +case IP_VERSION (9 ,4 ,1 ):/* Arcturus */ + firmware_supported = dev->gpu->mec_fw_version >=60 ; +break ; +case IP_VERSION (9 ,4 ,2 ):/* Aldebaran */ + firmware_supported = dev->gpu->mec_fw_version >=51 ; +break ; +case IP_VERSION (10 ,1 ,10 ):/* Navi10 */ +case IP_VERSION (10 ,1 ,2 ):/* Navi12 */ +case IP_VERSION (10 ,1 ,1 ):/* Navi14 */ + firmware_supported = dev->gpu->mec_fw_version >=144 ; +break ; +case IP_VERSION (10 ,3 ,0 ):/* Sieanna Cichlid */ +case IP_VERSION (10 ,3 ,2 ):/* Navy Flounder */ +case IP_VERSION (10 ,3 ,1 ):/* Van Gogh */ +case IP_VERSION (10 ,3 ,4 ):/* Dimgrey Cavefish */ +case IP_VERSION (10 ,3 ,5 ):/* Beige Goby */ + firmware_supported = dev->gpu->mec_fw_version >=89 ; +break ; +case IP_VERSION (10 ,1 ,3 ):/* Cyan Skillfish */ +case IP_VERSION (10 ,3 ,3 ):/* Yellow Carp*/ + firmware_supported = false; +break ; +default : +break ; + } + +if (firmware_supported) + dev->node_props.capability |=HSA_CAP_TRAP_DEBUG_FIRMWARE_SUPPORTED ; +} + +static void kfd_topology_set_capabilities (struct kfd_topology_device *dev) +{ + dev->node_props.capability |= ((HSA_CAP_DOORBELL_TYPE_2_0 << +HSA_CAP_DOORBELL_TYPE_TOTALBITS_SHIFT ) & +HSA_CAP_DOORBELL_TYPE_TOTALBITS_MASK ); + + dev->node_props.capability |=HSA_CAP_TRAP_DEBUG_SUPPORT | +HSA_CAP_TRAP_DEBUG_WAVE_LAUNCH_TRAP_OVERRIDE_SUPPORTED | +HSA_CAP_TRAP_DEBUG_WAVE_LAUNCH_MODE_SUPPORTED ; + +if (KFD_GC_VERSION (dev->gpu) <IP_VERSION (10 ,0 ,0 )) { + dev->node_props.debug_prop |=HSA_DBG_WATCH_ADDR_MASK_LO_BIT_GFX9 | +HSA_DBG_WATCH_ADDR_MASK_HI_BIT ; + +if (KFD_GC_VERSION (dev->gpu) <IP_VERSION (9 ,4 ,2 )) + dev->node_props.debug_prop |= +HSA_DBG_DISPATCH_INFO_ALWAYS_VALID ; +else + dev->node_props.capability |= +HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED ; + }else { + dev->node_props.debug_prop |=HSA_DBG_WATCH_ADDR_MASK_LO_BIT_GFX10 | +HSA_DBG_WATCH_ADDR_MASK_HI_BIT | +HSA_DBG_DISPATCH_INFO_ALWAYS_VALID ; + } + +kfd_topology_set_dbg_firmware_support (dev); +} +int kfd_topology_add_device (struct kfd_dev *gpu) {uint32_t gpu_id;
@@ -1737,13 +1817,11 @@ int kfd_topology_add_device(struct kfd_dev *gpu) HSA_CAP_DOORBELL_TYPE_TOTALBITS_MASK);break ;default : -if (KFD_GC_VERSION (dev->gpu) >=IP_VERSION (9 ,0 ,1 )) - dev->node_props.capability |= ((HSA_CAP_DOORBELL_TYPE_2_0 << -HSA_CAP_DOORBELL_TYPE_TOTALBITS_SHIFT ) & -HSA_CAP_DOORBELL_TYPE_TOTALBITS_MASK ); -else +if (KFD_GC_VERSION (dev->gpu) <IP_VERSION (9 ,0 ,1 ))WARN (1 ,"Unexpected ASIC family %u" , dev->gpu->adev->asic_type); +else +kfd_topology_set_capabilities (dev); }/*
drivers/gpu/drm/amd/amdkfd/kfd_topology.h +6 -0
@@ -31,6 +31,11 @@#define KFD_TOPOLOGY_PUBLIC_NAME_SIZE 32 +#define HSA_DBG_WATCH_ADDR_MASK_LO_BIT_GFX9 6 +#define HSA_DBG_WATCH_ADDR_MASK_LO_BIT_GFX10 7 +#define HSA_DBG_WATCH_ADDR_MASK_HI_BIT \ + (29 << HSA_DBG_WATCH_ADDR_MASK_HI_BIT_SHIFT) +struct kfd_node_properties {uint64_t hive_id;uint32_t cpu_cores_count;
@@ -42,6 +47,7 @@ struct kfd_node_properties {uint32_t cpu_core_id_base;uint32_t simd_id_base;uint32_t capability; +uint64_t debug_prop;uint32_t max_waves_per_simd;uint32_t lds_size_in_kb;uint32_t gds_size_in_kb;
include/uapi/linux/kfd_sysfs.h +15 -0
@@ -43,6 +43,11 @@#define HSA_CAP_DOORBELL_TYPE_2_0 0x2#define HSA_CAP_AQL_QUEUE_DOUBLE_MAP 0x00004000 +#define HSA_CAP_TRAP_DEBUG_SUPPORT 0x00008000 +#define HSA_CAP_TRAP_DEBUG_WAVE_LAUNCH_TRAP_OVERRIDE_SUPPORTED 0x00010000 +#define HSA_CAP_TRAP_DEBUG_WAVE_LAUNCH_MODE_SUPPORTED 0x00020000 +#define HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED 0x00040000 +/* Old buggy user mode depends on this being 0 */ #define HSA_CAP_RESERVED_WAS_SRAM_EDCSUPPORTED 0x00080000
@@ -53,8 +58,18 @@#define HSA_CAP_SRAM_EDCSUPPORTED 0x04000000#define HSA_CAP_SVMAPI_SUPPORTED 0x08000000#define HSA_CAP_FLAGS_COHERENTHOSTACCESS 0x10000000 +#define HSA_CAP_TRAP_DEBUG_FIRMWARE_SUPPORTED 0x20000000#define HSA_CAP_RESERVED 0xe00f8000 +/* debug_prop bits in node properties */ +#define HSA_DBG_WATCH_ADDR_MASK_LO_BIT_MASK 0x0000000f +#define HSA_DBG_WATCH_ADDR_MASK_LO_BIT_SHIFT 0 +#define HSA_DBG_WATCH_ADDR_MASK_HI_BIT_MASK 0x000003f0 +#define HSA_DBG_WATCH_ADDR_MASK_HI_BIT_SHIFT 4 +#define HSA_DBG_DISPATCH_INFO_ALWAYS_VALID 0x00000400 +#define HSA_DBG_WATCHPOINTS_EXCLUSIVE 0x00000800 +#define HSA_DBG_RESERVED 0xfffffffffffff000ull +/* Heap types in memory properties */ #define HSA_MEM_HEAP_TYPE_SYSTEM 0#define HSA_MEM_HEAP_TYPE_FB_PUBLIC 1
Signature · 1 line
2.25.1
PATCH 3/29 drm/amdkfd: prepare per-process debug enable and disable
In reply to Jonathan KimThe ROCm debugger will attach to a process to debug by PTRACE and will expect the KFD to prepare a process for the target PID, whether the target PID has opened the KFD device or not.
This patch is to explicity handle this requirement. Further HW mode setting and runtime coordination requirements will be handled in following patches.
In the case where the target process has not opened the KFD device, a new KFD process must be created for the target PID.
The debugger as well as the target process for this case will have not acquired any VMs so handle process restoration to correctly account for this.
To coordinate with HSA runtime, the debugger must be aware of the target process' runtime enablement status and will copy the runtime status information into the debugged KFD process for later query.
On enablement, the debugger will subscribe to a set of exceptions where each exception events will notify the debugger through a pollable FIFO file descriptor that the debugger provides to the KFD to manage. Some events will be synchronously raised while other are scheduled, which is why a debug_event_workarea worker is initialized.
Finally on process termination of either the debugger or the target, debugging must be disabled if it has not been done so.
--- drivers/gpu/drm/amd/amdkfd/Makefile | 3 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 87 +++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 91 +++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 33 +++++++ .../drm/amd/amdkfd/kfd_device_queue_manager.c | 24 ++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 34 ++++++- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 65 +++++++++---- 7 files changed, 308 insertions(+), 29 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_debug.c create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_debug.h
drivers/gpu/drm/amd/amdkfd/Makefile +2 -1
@@ -55,7 +55,8 @@ AMDKFD_FILES := $(AMDKFD_PATH)/kfd_module.o \ $(AMDKFD_PATH)/kfd_int_process_v9.o \ $(AMDKFD_PATH)/kfd_int_process_v11.o \ $(AMDKFD_PATH)/kfd_smi_events.o \ - $(AMDKFD_PATH)/kfd_crat.o + $(AMDKFD_PATH)/kfd_crat.o \ + $(AMDKFD_PATH)/kfd_debug.o ifneq ($(CONFIG_AMD_IOMMU_V2),) AMDKFD_FILES += $(AMDKFD_PATH)/kfd_iommu.o
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +85 -2
129 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.c new file +91 -0
91 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright 2022 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef KFD_DEBUG_EVENTS_H_INCLUDED +#define KFD_DEBUG_EVENTS_H_INCLUDED + +#include "kfd_priv.h" + +int kfd_dbg_trap_disable (struct kfd_process *target); +int kfd_dbg_trap_enable (struct kfd_process *target,uint32_t fd, +void __user *runtime_info, +uint32_t *runtime_info_size); +void debug_event_write_work_handler (struct work_struct *work); +#endif
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +19 -5
@@ -977,6 +977,14 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm, goto out; pdd =qpd_to_pdd (qpd); + +/* The debugger creates processes that temporarily have not acquired +* all VMs for all devices and has no VMs itself. +* Skip queue eviction on process eviction. +*/ +if (!pdd->drm_priv) + goto out; +pr_debug_ratelimited ("Evicting PASID 0x%x queues\n" , pdd->process->pasid);
@@ -1098,13 +1106,10 @@ static int restore_process_queues_cpsch(struct device_queue_manager *dqm, {struct queue *q;struct kfd_process_device *pdd; -uint64_t pd_base;uint64_t eviction_duration;int retval =0 ; pdd =qpd_to_pdd (qpd); -/* Retrieve PD base */ - pd_base =amdgpu_amdkfd_gpuvm_get_process_page_dir (pdd->drm_priv);dqm_lock (dqm);if (WARN_ON_ONCE (!qpd->evicted))/* already restored, do nothing */
@@ -1114,12 +1119,19 @@ static int restore_process_queues_cpsch(struct device_queue_manager *dqm, goto out; } +/* The debugger creates processes that temporarily have not acquired +* all VMs for all devices and has no VMs itself. +* Skip queue restore on process restore. +*/ +if (!pdd->drm_priv) + goto vm_not_acquired; +pr_debug_ratelimited ("Restoring PASID 0x%x queues\n" , pdd->process->pasid);/* Update PD Base in QPD */ - qpd->page_table_base = pd_base; -pr_debug ("Updated PD address to 0x%llx\n" , pd_base); + qpd->page_table_base =amdgpu_amdkfd_gpuvm_get_process_page_dir (pdd->drm_priv); +pr_debug ("Updated PD address to 0x%llx\n" , qpd->page_table_base);/* activate all active queues on the qpd */ list_for_each_entry (q, &qpd->queues_list, list) {
@@ -1145,6 +1157,8 @@ static int restore_process_queues_cpsch(struct device_queue_manager *dqm, qpd->evicted =0 ; eviction_duration =get_jiffies_64 () - pdd->last_evict_timestamp;atomic64_add (eviction_duration, &pdd->evict_duration_counter); +vm_not_acquired: + qpd->evicted =0 ; out:dqm_unlock (dqm);return retval;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +33 -1
@@ -886,19 +886,48 @@ struct kfd_process {*/ unsigned long last_restore_timestamp; +/* Indicates device process is debug attached with reserved vmid. */ +bool debug_trap_enabled; + +/* per-process-per device debug event fd file */ +struct file *dbg_ev_file; + +/* If the process is a kfd debugger, we need to know so we can clean +* up at exit time. If a process enables debugging on itself, it does +* its own clean-up, so we don't set the flag here. We track this by +* counting the number of processes this process is debugging. +*/ +atomic_t debugged_process_count; + +/* If the process is a debugged, this is the debugger process */ +struct kfd_process *debugger_process; +/* Kobj for our procfs */ struct kobject *kobj;struct kobject *kobj_queues;struct attribute attr_pasid; +/* Keep track cwsr init */ +bool has_cwsr; + +/* Exception code enable mask and status */ +uint64_t exception_enable_mask; +/* shared virtual memory registered by this process */ struct svm_range_list svms;bool xnack_enabled; +/* Work area for debugger event writer worker. */ +struct work_struct debug_event_workarea; +atomic_t poison;/* Queues are in paused stated because we are in the process of doing a CRIU checkpoint */ bool queues_paused; + +/* Tracks runtime enable status */ +struct kfd_runtime_info runtime_info; + };#define KFD_PROCESS_TABLE_SIZE 5/* bits: 32 entries */
@@ -928,7 +957,7 @@ bool kfd_dev_is_large_bar(struct kfd_dev *dev);int kfd_process_create_wq (void );void kfd_process_destroy_wq (void ); -struct kfd_process *kfd_create_process (struct file *filep); +struct kfd_process *kfd_create_process (struct task_struct *thread);struct kfd_process *kfd_get_process (const struct task_struct *task);struct kfd_process *kfd_lookup_process_by_pasid (u32 pasid);struct kfd_process *kfd_lookup_process_by_mm (const struct mm_struct *mm);
@@ -1055,6 +1084,9 @@ void kfd_process_set_trap_handler(struct qcm_process_device *qpd,uint64_t tba_addr, uint64_t tma_addr); +/* CWSR initialization */ +int kfd_process_init_cwsr_apu (struct kfd_process *process,struct file *filep); +/* CRIU */ /* * Need to increment KFD_CRIU_PRIV_VERSION each time a change is made to any of the CRIU private
drivers/gpu/drm/amd/amdkfd/kfd_process.c +45 -20
145 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 4/29 drm/amdgpu: add kgd hw debug mode setting interface
In reply to Jonathan KimIntroduce the require KGD debug calls that will execute hardware debug mode setting.
--- .../gpu/drm/amd/include/kgd_kfd_interface.h | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +34 -0
@@ -288,6 +288,40 @@ struct kfd2kgd_calls { uint32_t vmid, uint64_t page_table_base);uint32_t (*read_vmid_from_vmfault_reg)(struct amdgpu_device *adev); +uint32_t (*enable_debug_trap)(struct amdgpu_device *adev, +bool restore_dbg_registers, +uint32_t vmid); +uint32_t (*disable_debug_trap)(struct amdgpu_device *adev, +bool keep_trap_enabled, +uint32_t vmid); +int (*validate_trap_override_request)(struct amdgpu_device *adev, +uint32_t trap_override, +uint32_t *trap_mask_supported); +uint32_t (*set_wave_launch_trap_override)(struct amdgpu_device *adev, +uint32_t vmid, +uint32_t trap_override, +uint32_t trap_mask_bits, +uint32_t trap_mask_request, +uint32_t *trap_mask_prev, +uint32_t kfd_dbg_trap_cntl_prev); +uint32_t (*set_wave_launch_mode)(struct amdgpu_device *adev, +uint8_t wave_launch_mode, +uint32_t vmid); +uint32_t (*set_address_watch)(struct amdgpu_device *adev, +uint64_t watch_address, +uint32_t watch_address_mask, +uint32_t watch_id, +uint32_t watch_mode, +uint32_t debug_vmid); +uint32_t (*clear_address_watch)(struct amdgpu_device *adev, +uint32_t watch_id); +void (*get_iq_wait_times)(struct amdgpu_device *adev, +uint32_t *wait_times); +void (*build_grace_period_packet_info)(struct amdgpu_device *adev, +uint32_t wait_times, +uint32_t grace_period, +uint32_t *reg_offset, +uint32_t *reg_data);void (*get_cu_occupancy)(struct amdgpu_device *adev,int pasid,int *wave_cnt,int *max_waves_per_cu); void (*program_trap_handler_settings)(struct amdgpu_device *adev,
Signature · 1 line
2.25.1
PATCH 5/29 drm/amdgpu: setup hw debug registers on driver initialization
In reply to Jonathan KimAdd missing debug trap registers references and initialize all debug registers on boot by clearing the hardware exception overrides and the wave allocation ID index.
For debug devices that only support single process debugging, enable trap temporary setup by default.
Debug devices that support multi-process debugging require trap temporary setup to be disabled by default in order to satisfy microbench performance when in non-debug mode.
The debugger requires that TTMPs 6 & 7 save the dispatch ID to map waves onto dispatch during compute context inspection.
In order to correctly this up, set the special reserved CP bit by default whenever the MQD is initailized.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 26 +++++++ drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 30 ++++++++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c | 5 ++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 5 ++ .../include/asic_reg/gc/gc_10_1_0_offset.h | 14 ++++ .../include/asic_reg/gc/gc_10_1_0_sh_mask.h | 69 +++++++++++++++++++ .../include/asic_reg/gc/gc_10_3_0_offset.h | 10 +++ .../include/asic_reg/gc/gc_10_3_0_sh_mask.h | 4 ++ 8 files changed, 163 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +26 -0
@@ -5142,6 +5142,29 @@ static u32 gfx_v10_0_init_pa_sc_tile_steering_override(struct amdgpu_device *ade#define DEFAULT_SH_MEM_BASES (0x6000) +static void gfx_v10_0_debug_trap_config_init (struct amdgpu_device *adev, +uint32_t first_vmid, +uint32_t last_vmid) +{ +uint32_t data; +uint32_t trap_config_vmid_mask =0 ; +int i; + +/* Calculate trap config vmid mask */ +for (i = first_vmid; i < last_vmid; i++) + trap_config_vmid_mask |= (1 << i); + + data =REG_SET_FIELD (0 ,SPI_GDBG_TRAP_CONFIG , +VMID_SEL , trap_config_vmid_mask); + data =REG_SET_FIELD (data,SPI_GDBG_TRAP_CONFIG , +TRAP_EN ,1 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_CONFIG), data); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_MASK),0 ); + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_DATA0),0 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_DATA1),0 ); +} +static void gfx_v10_0_init_compute_vmid (struct amdgpu_device *adev) {int i;
@@ -5173,6 +5196,9 @@ static void gfx_v10_0_init_compute_vmid(struct amdgpu_device *adev)WREG32_SOC15_OFFSET (GC ,0 , mmGDS_GWS_VMID0, i,0 );WREG32_SOC15_OFFSET (GC ,0 , mmGDS_OA_VMID0, i,0 ); } + +gfx_v10_0_debug_trap_config_init (adev, adev->vm_manager.first_kfd_vmid, +AMDGPU_NUM_VMID ); }static void gfx_v10_0_init_gds_vmid (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +30 -0
@@ -2515,6 +2515,29 @@ static void gfx_v9_0_setup_rb(struct amdgpu_device *adev) adev->gfx.config.num_rbs =hweight32 (active_rbs); } +static void gfx_v9_0_debug_trap_config_init (struct amdgpu_device *adev, +uint32_t first_vmid, +uint32_t last_vmid) +{ +uint32_t data; +uint32_t trap_config_vmid_mask =0 ; +int i; + +/* Calculate trap config vmid mask */ +for (i = first_vmid; i < last_vmid; i++) + trap_config_vmid_mask |= (1 << i); + + data =REG_SET_FIELD (0 ,SPI_GDBG_TRAP_CONFIG , +VMID_SEL , trap_config_vmid_mask); + data =REG_SET_FIELD (data,SPI_GDBG_TRAP_CONFIG , +TRAP_EN ,1 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_CONFIG), data); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_MASK),0 ); + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_DATA0),0 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_DATA1),0 ); +} +#define DEFAULT_SH_MEM_BASES (0x6000)static void gfx_v9_0_init_compute_vmid (struct amdgpu_device *adev) {
@@ -4786,6 +4809,13 @@ static int gfx_v9_0_late_init(void *handle)if (r)return r; +if (adev->ip_versions[GC_HWIP ][0 ] ==IP_VERSION (9 ,4 ,2 )) +gfx_v9_4_2_debug_trap_config_init (adev, + adev->vm_manager.first_kfd_vmid,AMDGPU_NUM_VMID ); +else +gfx_v9_0_debug_trap_config_init (adev, + adev->vm_manager.first_kfd_vmid,AMDGPU_NUM_VMID ); +return 0 ; }
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +5 -0
@@ -117,6 +117,11 @@ static void init_mqd(struct mqd_manager *mm, void **mqd,1 <<CP_HQD_QUANTUM__QUANTUM_SCALE__SHIFT |1 <<CP_HQD_QUANTUM__QUANTUM_DURATION__SHIFT ; +/* Set cp_hqd_hq_scheduler0 bit 14 to 1 to have the CP set up the +* DISPATCH_PTR. This is required for the kfd debugger +*/ + m->cp_hqd_hq_scheduler0 =1 <<14 ; +if (q->format ==KFD_QUEUE_FORMAT_AQL ) { m->cp_hqd_aql_control =1 <<CP_HQD_AQL_CONTROL__CONTROL0__SHIFT ;
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +5 -0
@@ -164,6 +164,11 @@ static void init_mqd(struct mqd_manager *mm, void **mqd,1 <<CP_HQD_QUANTUM__QUANTUM_SCALE__SHIFT |1 <<CP_HQD_QUANTUM__QUANTUM_DURATION__SHIFT ; +/* Set cp_hqd_hq_scheduler0 bit 14 to 1 to have the CP set up the +* DISPATCH_PTR. This is required for the kfd debugger +*/ + m->cp_hqd_hq_status0 =1 <<14 ; +if (q->format ==KFD_QUEUE_FORMAT_AQL ) { m->cp_hqd_aql_control =1 <<CP_HQD_AQL_CONTROL__CONTROL0__SHIFT ;
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_1_0_offset.h +14 -0
@@ -5190,6 +5190,20 @@#define mmSPI_WCL_PIPE_PERCENT_CS6_BASE_IDX 0#define mmSPI_WCL_PIPE_PERCENT_CS7 0x1f70#define mmSPI_WCL_PIPE_PERCENT_CS7_BASE_IDX 0 +#define mmSPI_GDBG_WAVE_CNTL 0x1f71 +#define mmSPI_GDBG_WAVE_CNTL_BASE_IDX 0 +#define mmSPI_GDBG_TRAP_CONFIG 0x1f72 +#define mmSPI_GDBG_TRAP_CONFIG_BASE_IDX 0 +#define mmSPI_GDBG_TRAP_MASK 0x1f73 +#define mmSPI_GDBG_TRAP_MASK_BASE_IDX 0 +#define mmSPI_GDBG_WAVE_CNTL2 0x1f74 +#define mmSPI_GDBG_WAVE_CNTL2_BASE_IDX 0 +#define mmSPI_GDBG_WAVE_CNTL3 0x1f75 +#define mmSPI_GDBG_WAVE_CNTL3_BASE_IDX 0 +#define mmSPI_GDBG_TRAP_DATA0 0x1f78 +#define mmSPI_GDBG_TRAP_DATA0_BASE_IDX 0 +#define mmSPI_GDBG_TRAP_DATA1 0x1f79 +#define mmSPI_GDBG_TRAP_DATA1_BASE_IDX 0#define mmSPI_COMPUTE_QUEUE_RESET 0x1f7b#define mmSPI_COMPUTE_QUEUE_RESET_BASE_IDX 0#define mmSPI_RESOURCE_RESERVE_CU_0 0x1f7c
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_1_0_sh_mask.h +69 -0
75 lines not on this page · raw message
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_3_0_offset.h +10 -0
@@ -26,6 +26,8 @@#define mmSQ_DEBUG_STS_GLOBAL_BASE_IDX 0#define mmSQ_DEBUG_STS_GLOBAL2 0x10B0#define mmSQ_DEBUG_STS_GLOBAL2_BASE_IDX 0 +#define mmSQ_DEBUG 0x10B1 +#define mmSQ_DEBUG_BASE_IDX 0// addressBlock: gc_sdma0_sdma0dec // base address: 0x4980
@@ -4849,10 +4851,18 @@#define mmSPI_WCL_PIPE_PERCENT_CS3_BASE_IDX 0#define mmSPI_GDBG_WAVE_CNTL 0x1f71#define mmSPI_GDBG_WAVE_CNTL_BASE_IDX 0 +#define mmSPI_GDBG_TRAP_CONFIG 0x1f72 +#define mmSPI_GDBG_TRAP_CONFIG_BASE_IDX 0#define mmSPI_GDBG_TRAP_MASK 0x1f73#define mmSPI_GDBG_TRAP_MASK_BASE_IDX 0#define mmSPI_GDBG_WAVE_CNTL2 0x1f74#define mmSPI_GDBG_WAVE_CNTL2_BASE_IDX 0 +#define mmSPI_GDBG_WAVE_CNTL3 0x1f75 +#define mmSPI_GDBG_WAVE_CNTL3_BASE_IDX 0 +#define mmSPI_GDBG_TRAP_DATA0 0x1f78 +#define mmSPI_GDBG_TRAP_DATA0_BASE_IDX 0 +#define mmSPI_GDBG_TRAP_DATA1 0x1f79 +#define mmSPI_GDBG_TRAP_DATA1_BASE_IDX 0#define mmSPI_COMPUTE_QUEUE_RESET 0x1f7b#define mmSPI_COMPUTE_QUEUE_RESET_BASE_IDX 0#define mmSPI_RESOURCE_RESERVE_CU_0 0x1f7c
drivers/gpu/drm/amd/include/asic_reg/gc/gc_10_3_0_sh_mask.h +4 -0
@@ -46386,6 +46386,10 @@// addressBlock: sqind +//SQ_DEBUG +#define SQ_DEBUG__SINGLE_MEMOP_MASK 0x00000001L +#define SQ_DEBUG__SINGLE_MEMOP__SHIFT 0x00000000 +//SQ_DEBUG_STS_GLOBAL #define SQ_DEBUG_STS_GLOBAL2__FIFO_LEVEL_GFX0_MASK 0x000000ffL#define SQ_DEBUG_STS_GLOBAL2__FIFO_LEVEL_GFX0__SHIFT 0x00000000
Signature · 1 line
2.25.1
PATCH 6/29 drm/amdgpu: add gfx9 hw debug mode enable and disable calls
In reply to Jonathan KimImplement the per-device calls to enable or disable HW debug mode for GFX9 prior to GFX9.4.1.
GFX9.4.1 and onward will require their own enable/disable sequence as follow on patches.
When hardware debug mode setting is requested, waves will inherit these settings in the Shader Processor Input's (SPI) Sequencer Global Block (SQG). This means that the KGD must drain all waves from the SPI into SQG (approximately 96 SPI clock cycles) prior to debug mode setting to ensure that the order of operations that the debugger expects with regards to debug mode setting transaction requests and wave inheritence of that mode is upheld.
Also ensure that exception overrides are reset to their original state prior to debug enable or disable.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 100 ++++++++++++++++-- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h | 9 ++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 + 3 files changed, 102 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +90 -10
@@ -46,14 +46,14 @@ enum hqd_dequeue_request_type { SAVE_WAVES }; -static void lock_srbm (struct amdgpu_device *adev,uint32_t mec,uint32_t pipe, +static void kgd_gfx_v9_lock_srbm (struct amdgpu_device *adev,uint32_t mec,uint32_t pipe,uint32_t queue,uint32_t vmid) {mutex_lock (&adev->srbm_mutex);soc15_grbm_select (adev, mec, pipe, queue, vmid); } -static void unlock_srbm (struct amdgpu_device *adev) +static void kgd_gfx_v9_unlock_srbm (struct amdgpu_device *adev) {soc15_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);
@@ -65,7 +65,7 @@ static void acquire_queue(struct amdgpu_device *adev, uint32_t pipe_id,uint32_t mec = (pipe_id / adev->gfx.mec.num_pipe_per_mec) +1 ;uint32_t pipe = (pipe_id % adev->gfx.mec.num_pipe_per_mec); -lock_srbm (adev, mec, pipe, queue_id,0 ); +kgd_gfx_v9_lock_srbm (adev, mec, pipe, queue_id,0 ); } static uint64_t get_queue_mask(struct amdgpu_device *adev,
@@ -79,7 +79,7 @@ static uint64_t get_queue_mask(struct amdgpu_device *adev,static void release_queue (struct amdgpu_device *adev) { -unlock_srbm (adev); +kgd_gfx_v9_unlock_srbm (adev); } void kgd_gfx_v9_program_sh_mem_settings(struct amdgpu_device *adev, uint32_t vmid,
@@ -88,13 +88,13 @@ void kgd_gfx_v9_program_sh_mem_settings(struct amdgpu_device *adev, uint32_t vmiuint32_t sh_mem_ape1_limit, uint32_t sh_mem_bases) { - lock_srbm(adev, 0, 0, 0, vmid); + kgd_gfx_v9_lock_srbm(adev, 0, 0, 0, vmid);WREG32_RLC (SOC15_REG_OFFSET (GC ,0 , mmSH_MEM_CONFIG), sh_mem_config);WREG32_RLC (SOC15_REG_OFFSET (GC ,0 , mmSH_MEM_BASES), sh_mem_bases);/* APE1 no longer exists on GFX9 */ -unlock_srbm (adev); +kgd_gfx_v9_unlock_srbm (adev); } int kgd_gfx_v9_set_pasid_vmid_mapping(struct amdgpu_device *adev, u32 pasid,
@@ -164,13 +164,13 @@ int kgd_gfx_v9_init_interrupts(struct amdgpu_device *adev, uint32_t pipe_id) mec = (pipe_id / adev->gfx.mec.num_pipe_per_mec) +1 ; pipe = (pipe_id % adev->gfx.mec.num_pipe_per_mec); -lock_srbm (adev, mec, pipe,0 ,0 ); +kgd_gfx_v9_lock_srbm (adev, mec, pipe,0 ,0 );WREG32_SOC15 (GC ,0 , mmCPC_INT_CNTL,CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK |CP_INT_CNTL_RING0__OPCODE_ERROR_INT_ENABLE_MASK ); -unlock_srbm (adev); +kgd_gfx_v9_unlock_srbm (adev);return 0 ; }
@@ -646,6 +646,84 @@ int kgd_gfx_v9_wave_control_execute(struct amdgpu_device *adev,return 0 ; } +/* +* GFX9 helper for wave launch stall requirements on debug trap setting. +* +* vmid: +* Target VMID to stall/unstall. +* +* stall: +* 0-unstall wave launch (enable), 1-stall wave launch (disable). +* After wavefront launch has been stalled, allocated waves must drain from +* SPI in order for debug trap settings to take effect on those waves. +* This is roughly a ~96 clock cycle wait on SPI where a read on +* SPI_GDBG_WAVE_CNTL translates to ~32 clock cycles. +* KGD_GFX_V9_WAVE_LAUNCH_SPI_DRAIN_LATENCY indicates the number of reads required. +* +* NOTE: We can afford to clear the entire STALL_VMID field on unstall +* because GFX9.4.1 cannot support multi-process debugging due to trap +* configuration and masking being limited to global scope. Always assume +* single process conditions. + +*/ +#define KGD_GFX_V9_WAVE_LAUNCH_SPI_DRAIN_LATENCY 3 +void kgd_gfx_v9_set_wave_launch_stall (struct amdgpu_device *adev, +uint32_t vmid, +bool stall) +{ +int i; +uint32_t data =RREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL)); + +if (adev->ip_versions[GC_HWIP ][0 ] ==IP_VERSION (9 ,4 ,1 )) + data =REG_SET_FIELD (data,SPI_GDBG_WAVE_CNTL ,STALL_VMID , + stall ?1 << vmid :0 ); +else + data =REG_SET_FIELD (data,SPI_GDBG_WAVE_CNTL ,STALL_RA , + stall ?1 :0 ); + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL), data); + +if (!stall) +return ; + +for (i =0 ; i <KGD_GFX_V9_WAVE_LAUNCH_SPI_DRAIN_LATENCY ; i++) +RREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL)); +} + +uint32_t kgd_gfx_v9_enable_debug_trap (struct amdgpu_device *adev, +bool restore_dbg_registers, +uint32_t vmid) +{ +mutex_lock (&adev->grbm_idx_mutex); + +kgd_gfx_v9_set_wave_launch_stall (adev, vmid, true); + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_MASK),0 ); + +kgd_gfx_v9_set_wave_launch_stall (adev, vmid, false); + +mutex_unlock (&adev->grbm_idx_mutex); + +return 0 ; +} + +uint32_t kgd_gfx_v9_disable_debug_trap (struct amdgpu_device *adev, +bool keep_trap_enabled, +uint32_t vmid) +{ +mutex_lock (&adev->grbm_idx_mutex); + +kgd_gfx_v9_set_wave_launch_stall (adev, vmid, true); + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_MASK),0 ); + +kgd_gfx_v9_set_wave_launch_stall (adev, vmid, false); + +mutex_unlock (&adev->grbm_idx_mutex); + +return 0 ; +} +void kgd_gfx_v9_set_vm_context_page_table_base (struct amdgpu_device *adev,uint32_t vmid,uint64_t page_table_base) {
@@ -833,7 +911,7 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,void kgd_gfx_v9_program_trap_handler_settings (struct amdgpu_device *adev,uint32_t vmid,uint64_t tba_addr,uint64_t tma_addr) { -lock_srbm (adev,0 ,0 ,0 , vmid); +kgd_gfx_v9_lock_srbm (adev,0 ,0 ,0 , vmid);/* * Program TBA registers
@@ -851,7 +929,7 @@ void kgd_gfx_v9_program_trap_handler_settings(struct amdgpu_device *adev,WREG32_SOC15 (GC ,0 , mmSQ_SHADER_TMA_HI,upper_32_bits (tma_addr >>8 )); -unlock_srbm (adev); +kgd_gfx_v9_unlock_srbm (adev); }const struct kfd2kgd_calls gfx_v9_kfd2kgd = {
@@ -871,6 +949,8 @@ const struct kfd2kgd_calls gfx_v9_kfd2kgd = { .get_atc_vmid_pasid_mapping_info = kgd_gfx_v9_get_atc_vmid_pasid_mapping_info, .set_vm_context_page_table_base = kgd_gfx_v9_set_vm_context_page_table_base, + .enable_debug_trap = kgd_gfx_v9_enable_debug_trap, + .disable_debug_trap = kgd_gfx_v9_disable_debug_trap, .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy, .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings, };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h +9 -0
@@ -58,3 +58,12 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid, int *pasid_wave_cnt, int *max_waves_per_cu);void kgd_gfx_v9_program_trap_handler_settings (struct amdgpu_device *adev,uint32_t vmid,uint64_t tba_addr,uint64_t tma_addr); +void kgd_gfx_v9_set_wave_launch_stall (struct amdgpu_device *adev, +uint32_t vmid, +bool stall); +uint32_t kgd_gfx_v9_enable_debug_trap (struct amdgpu_device *adev, +bool restore_dbg_registers, +uint32_t vmid); +uint32_t kgd_gfx_v9_disable_debug_trap (struct amdgpu_device *adev, +bool keep_trap_enabled, +uint32_t vmid);
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +3 -0
@@ -25,6 +25,9 @@#include "kfd_priv.h" +void kgd_gfx_v9_set_wave_launch_stall (struct amdgpu_device *adev, +uint32_t vmid, +bool stall);int kfd_dbg_trap_disable (struct kfd_process *target); int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd, void __user *runtime_info,
Signature · 1 line
2.25.1
PATCH 7/29 drm/amdgpu: add gfx9.4.1 hw debug mode enable and disable calls
In reply to Jonathan KimOn GFX9.4.1, the implicit wait count instruction on s_barrier is disabled by default in the driver during normal operation for performance requirements.
There is a hardware bug in GFX9.4.1 where if the implicit wait count instruction after an s_barrier instruction is disabled, any wave that hits an exception may step over the s_barrier when returning from the trap handler with the barrier logic having no ability to be aware of this, thereby causing other waves to wait at the barrier indefinitely resulting in a shader hang. This bug has been corrected for GFX9.4.2 and onward.
Since the debugger subscribes to hardware exceptions, in order to avoid this bug, the debugger must enable implicit wait count on s_barrier for a debug session and disable it on detach.
In order to change this setting in the in the device global SQ_CONFIG register, the GFX pipeline must be idle. GFX9.4.1 as a compute device will either dispatch work through the compute ring buffers used for image post processing or through the hardware scheduler by the KFD.
Have the KGD suspend and drain the compute ring buffer, then suspend the hardware scheduler and block any future KFD process job requests before changing the implicit wait count setting. Once set, resume all work.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 105 +++++++++++++++++- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 4 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +- 4 files changed, 110 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
@@ -1036,6 +1036,9 @@ struct amdgpu_device {struct pci_saved_state *pci_state;pci_channel_state_t pci_channel_state; +/* Track auto wait count on s_barrier settings */ +bool barrier_has_auto_waitcnt; +struct amdgpu_reset_control *reset_cntl;uint32_t ip_versions[MAX_HWIP ][HWIP_MAX_INSTANCE ];
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +104 -1
128 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -2
@@ -2602,8 +2602,8 @@ static void gfx_v9_0_init_sq_config(struct amdgpu_device *adev)switch (adev->ip_versions[GC_HWIP ][0 ]) {case IP_VERSION (9 ,4 ,1 ): tmp =RREG32_SOC15 (GC ,0 , mmSQ_CONFIG); - tmp =REG_SET_FIELD (tmp,SQ_CONFIG , -DISABLE_BARRIER_WAITCNT ,1 ); + tmp =REG_SET_FIELD (tmp,SQ_CONFIG ,DISABLE_BARRIER_WAITCNT , +READ_ONCE (adev->barrier_has_auto_waitcnt) ?0 :1 );WREG32_SOC15 (GC ,0 , mmSQ_CONFIG, tmp);break ;default :
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
@@ -1951,7 +1951,7 @@ void kfd_suspend_all_processes(void)WARN (debug_evictions,"Evicting all processes" );hash_for_each_rcu (kfd_processes_table, temp, p, kfd_processes) {cancel_delayed_work_sync (&p->eviction_work); -cancel_delayed_work_sync (&p->restore_work); +flush_delayed_work (&p->restore_work);if (kfd_process_evict_queues (p,KFD_QUEUE_EVICTION_TRIGGER_SUSPEND ))pr_err ("Failed to suspend process 0x%x\n" , p->pasid);
Signature · 1 line
2.25.1
PATCH 8/29 drm/amdgpu: add gfx10 hw debug mode enable and disable calls
In reply to Jonathan KimSimilar to GFX9 debug devices, set the hardware debug mode by draining the SPI appropriately prior the mode setting request.
Because GFX10 has waves allocated by the work group boundaray and each SE's SPI instances do not communicate, the SPI drain time is much longer. This long drain time will be fixed for GFX11 onwards.
Also remove a bunch of deprecated misplaced references for GFX10.3.
--- .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 95 +++++++++++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h | 28 ++++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 147 +----------------- 3 files changed, 126 insertions(+), 144 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c +95 -0
@@ -708,6 +708,99 @@ static void set_vm_context_page_table_base(struct amdgpu_device *adev, adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base); } +/* +* GFX10 helper for wave launch stall requirements on debug trap setting. +* +* vmid: +* Target VMID to stall/unstall. +* +* stall: +* 0-unstall wave launch (enable), 1-stall wave launch (disable). +* After wavefront launch has been stalled, allocated waves must drain from +* SPI in order for debug trap settings to take effect on those waves. +* This is roughly a ~3500 clock cycle wait on SPI where a read on +* SPI_GDBG_WAVE_CNTL translates to ~32 clock cycles. +* KGD_GFX_V10_WAVE_LAUNCH_SPI_DRAIN_LATENCY indicates the number of reads required. +* +* NOTE: We can afford to clear the entire STALL_VMID field on unstall +* because current GFX10 chips cannot support multi-process debugging due to +* trap configuration and masking being limited to global scope. Always +* assume single process conditions. +* +*/ + +#define KGD_GFX_V10_WAVE_LAUNCH_SPI_DRAIN_LATENCY 110 +static void kgd_gfx_v10_set_wave_launch_stall (struct amdgpu_device *adev,uint32_t vmid,bool stall) +{ +uint32_t data =RREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL)); +int i; + + data =REG_SET_FIELD (data,SPI_GDBG_WAVE_CNTL ,STALL_VMID , + stall ?1 << vmid :0 ); + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL), data); + +if (!stall) +return ; + +for (i =0 ; i <KGD_GFX_V10_WAVE_LAUNCH_SPI_DRAIN_LATENCY ; i++) +RREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL)); +} + +uint32_t kgd_gfx_v10_enable_debug_trap (struct amdgpu_device *adev, +bool restore_dbg_registers, +uint32_t vmid) +{ + +mutex_lock (&adev->grbm_idx_mutex); + +kgd_gfx_v10_set_wave_launch_stall (adev, vmid, true); + +/* assume gfx off is disabled for the debug session if rlc restore not supported. */ +if (restore_dbg_registers) { +uint32_t data =0 ; + + data =REG_SET_FIELD (data,SPI_GDBG_TRAP_CONFIG , +VMID_SEL ,1 << vmid); + data =REG_SET_FIELD (data,SPI_GDBG_TRAP_CONFIG , +TRAP_EN ,1 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_CONFIG), data); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_DATA0),0 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_DATA1),0 ); + +kgd_gfx_v10_set_wave_launch_stall (adev, vmid, false); + +mutex_unlock (&adev->grbm_idx_mutex); + +return 0 ; + } + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_MASK),0 ); + +kgd_gfx_v10_set_wave_launch_stall (adev, vmid, false); + +mutex_unlock (&adev->grbm_idx_mutex); + +return 0 ; +} + +uint32_t kgd_gfx_v10_disable_debug_trap (struct amdgpu_device *adev, +bool keep_trap_enabled, +uint32_t vmid) +{ +mutex_lock (&adev->grbm_idx_mutex); + +kgd_gfx_v10_set_wave_launch_stall (adev, vmid, true); + +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_MASK),0 ); + +kgd_gfx_v10_set_wave_launch_stall (adev, vmid, false); + +mutex_unlock (&adev->grbm_idx_mutex); + +return 0 ; +} +static void program_trap_handler_settings (struct amdgpu_device *adev,uint32_t vmid,uint64_t tba_addr,uint64_t tma_addr) {
@@ -750,5 +843,7 @@ const struct kfd2kgd_calls gfx_v10_kfd2kgd = { .get_atc_vmid_pasid_mapping_info = get_atc_vmid_pasid_mapping_info, .set_vm_context_page_table_base = set_vm_context_page_table_base, + .enable_debug_trap = kgd_gfx_v10_enable_debug_trap, + .disable_debug_trap = kgd_gfx_v10_disable_debug_trap, .program_trap_handler_settings = program_trap_handler_settings, };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright 2022 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +uint32_t kgd_gfx_v10_enable_debug_trap (struct amdgpu_device *adev, +bool restore_dbg_registers, +uint32_t vmid); +uint32_t kgd_gfx_v10_disable_debug_trap (struct amdgpu_device *adev, +bool keep_trap_enabled, +uint32_t vmid);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c +3 -144
163 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 9/29 drm/amdgpu: add gfx9.4.2 hw debug mode enable and disable calls
In reply to Jonathan KimGFX9.4.2 now supports per-VMID debug mode controls registers (SPI_GDBG_PER_VMID_CNTL).
Because the KFD lets the HWS handle PASID-VMID mapping, the KFD will forward all debug mode setting register writes to the HWS scheduler using a new MAP_PROCESS API, so instead of writing to registers, return the required register values that the HWS needs to write on debug enable and disable.
--- .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +33 -1
@@ -23,6 +23,36 @@#include "amdgpu_amdkfd.h" #include "amdgpu_amdkfd_arcturus.h" #include "amdgpu_amdkfd_gfx_v9.h" +#include "gc/gc_9_4_2_offset.h" +#include "gc/gc_9_4_2_sh_mask.h" + +/* returns TRAP_EN, EXCP_EN and EXCP_REPLACE. */ +static uint32_t kgd_aldebaran_enable_debug_trap (struct amdgpu_device *adev, +bool restore_dbg_registers, +uint32_t vmid) +{ +uint32_t data =0 ; + + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,TRAP_EN ,1 ); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,EXCP_EN ,0 ); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,EXCP_REPLACE ,0 ); + +return data; +} + +/* returns TRAP_EN, EXCP_EN and EXCP_REPLACE. */ +static uint32_t kgd_aldebaran_disable_debug_trap (struct amdgpu_device *adev, +bool keep_trap_enabled, +uint32_t vmid) +{ +uint32_t data =0 ; + + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,TRAP_EN , keep_trap_enabled); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,EXCP_EN ,0 ); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,EXCP_REPLACE ,0 ); + +return data; +}const struct kfd2kgd_calls aldebaran_kfd2kgd = { .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
@@ -41,5 +71,7 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = { .get_atc_vmid_pasid_mapping_info = kgd_gfx_v9_get_atc_vmid_pasid_mapping_info, .set_vm_context_page_table_base = kgd_gfx_v9_set_vm_context_page_table_base, - .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings + .enable_debug_trap = kgd_aldebaran_enable_debug_trap, + .disable_debug_trap = kgd_aldebaran_disable_debug_trap, + .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings, };
Signature · 1 line
2.25.1
PATCH 10/29 drm/amdgpu: add configurable grace period for unmap queues
In reply to Jonathan KimThe HWS schedule allows a grace period for wave completion prior to preemption but the debugger requires good performance since it preempts on every HW debug mode setting transaction request.
For good performance, allow immediate preemption by setting the grace period to 0.
Note that setting the preepmtion grace period to 0 will result in an infinite grace period being set due to a CP FW bug so set it to 1 for now.
--- .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c | 2 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 + .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 43 ++++++++++++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h | 6 ++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 2 + .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 43 ++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h | 9 ++- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 61 ++++++++++++----- .../drm/amd/amdkfd/kfd_device_queue_manager.h | 2 + .../gpu/drm/amd/amdkfd/kfd_packet_manager.c | 32 +++++++++ .../drm/amd/amdkfd/kfd_packet_manager_v9.c | 39 +++++++++++ .../gpu/drm/amd/amdkfd/kfd_pm4_headers_ai.h | 65 +++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 5 ++ 13 files changed, 291 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +2 -0
@@ -73,5 +73,7 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = { .set_vm_context_page_table_base = kgd_gfx_v9_set_vm_context_page_table_base, .enable_debug_trap = kgd_aldebaran_enable_debug_trap, .disable_debug_trap = kgd_aldebaran_disable_debug_trap, + .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, + .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings, };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +2 -0
@@ -397,6 +397,8 @@ const struct kfd2kgd_calls arcturus_kfd2kgd = { kgd_gfx_v9_set_vm_context_page_table_base, .enable_debug_trap = kgd_arcturus_enable_debug_trap, .disable_debug_trap = kgd_arcturus_disable_debug_trap, + .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, + .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy, .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings, };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c +43 -0
54 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h +6 -0
@@ -26,3 +26,9 @@ uint32_t kgd_gfx_v10_enable_debug_trap(struct amdgpu_device *adev,uint32_t kgd_gfx_v10_disable_debug_trap (struct amdgpu_device *adev,bool keep_trap_enabled,uint32_t vmid); +void kgd_gfx_v10_get_iq_wait_times (struct amdgpu_device *adev,uint32_t *wait_times); +void kgd_gfx_v10_build_grace_period_packet_info (struct amdgpu_device *adev, +uint32_t wait_times, +uint32_t grace_period, +uint32_t *reg_offset, +uint32_t *reg_data);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c +2 -0
@@ -670,6 +670,8 @@ const struct kfd2kgd_calls gfx_v10_3_kfd2kgd = { .get_atc_vmid_pasid_mapping_info = get_atc_vmid_pasid_mapping_info_v10_3, .set_vm_context_page_table_base = set_vm_context_page_table_base_v10_3, .program_trap_handler_settings = program_trap_handler_settings_v10_3, + .get_iq_wait_times = kgd_gfx_v10_get_iq_wait_times, + .build_grace_period_packet_info = kgd_gfx_v10_build_grace_period_packet_info, .enable_debug_trap = kgd_gfx_v10_enable_debug_trap, .disable_debug_trap = kgd_gfx_v10_disable_debug_trap };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +43 -0
61 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h +6 -3
@@ -20,8 +20,6 @@* OTHER DEALINGS IN THE SOFTWARE. */ - - void kgd_gfx_v9_program_sh_mem_settings(struct amdgpu_device *adev, uint32_t vmid, uint32_t sh_mem_config, uint32_t sh_mem_ape1_base, uint32_t sh_mem_ape1_limit,
@@ -51,7 +49,6 @@ int kgd_gfx_v9_wave_control_execute(struct amdgpu_device *adev, uint32_t sq_cmd);bool kgd_gfx_v9_get_atc_vmid_pasid_mapping_info (struct amdgpu_device *adev,uint8_t vmid,uint16_t *p_pasid); -void kgd_gfx_v9_set_vm_context_page_table_base (struct amdgpu_device *adev,uint32_t vmid,uint64_t page_table_base); void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,
@@ -67,3 +64,9 @@ uint32_t kgd_gfx_v9_enable_debug_trap(struct amdgpu_device *adev,uint32_t kgd_gfx_v9_disable_debug_trap (struct amdgpu_device *adev,bool keep_trap_enabled,uint32_t vmid); +void kgd_gfx_v9_get_iq_wait_times (struct amdgpu_device *adev,uint32_t *wait_times); +void kgd_gfx_v9_build_grace_period_packet_info (struct amdgpu_device *adev, +uint32_t wait_times, +uint32_t grace_period, +uint32_t *reg_offset, +uint32_t *reg_data);
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +44 -17
176 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +2 -0
@@ -37,6 +37,7 @@#define KFD_MES_PROCESS_QUANTUM 100000#define KFD_MES_GANG_QUANTUM 10000 +#define USE_DEFAULT_GRACE_PERIOD 0xffffffffstruct device_process_node {struct qcm_process_device *qpd;
@@ -256,6 +257,7 @@ struct device_queue_manager {struct work_struct hw_exception_work;struct kfd_mem_obj hiq_sdma_mqd;bool sched_running; +uint32_t wait_times; }; void device_queue_manager_init_cik(
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c +32 -0
@@ -369,6 +369,38 @@ int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address,return retval; } +int pm_update_grace_period (struct packet_manager *pm,uint32_t grace_period) +{ +int retval =0 ; +uint32_t *buffer, size; + + size = pm->pmf->set_grace_period_size; + +mutex_lock (&pm->lock); + +if (size) { +kq_acquire_packet_buffer (pm->priv_queue, + size /sizeof (uint32_t ), + (unsigned int **)&buffer); + +if (!buffer) { +pr_err ("Failed to allocate buffer on kernel queue\n" ); + retval = -ENOMEM ; + goto out; + } + + retval = pm->pmf->set_grace_period (pm, buffer, grace_period); +if (!retval) +kq_submit_packet (pm->priv_queue); +else +kq_rollback_packet (pm->priv_queue); + } + +out: +mutex_unlock (&pm->lock); +return retval; +} +int pm_send_unmap_queue (struct packet_manager *pm,enum kfd_unmap_queues_filter filter,uint32_t filter_param,bool reset)
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager_v9.c +39 -0
@@ -251,6 +251,41 @@ static int pm_map_queues_v9(struct packet_manager *pm, uint32_t *buffer,return 0 ; } +static int pm_set_grace_period_v9 (struct packet_manager *pm, +uint32_t *buffer, +uint32_t grace_period) +{ +struct pm4_mec_write_data_mmio *packet; +uint32_t reg_offset =0 ; +uint32_t reg_data =0 ; + + pm->dqm->dev->kfd2kgd->build_grace_period_packet_info ( + pm->dqm->dev->adev, + pm->dqm->wait_times, + grace_period, + ®_offset, + ®_data); + +if (grace_period ==USE_DEFAULT_GRACE_PERIOD ) + reg_data = pm->dqm->wait_times; + + packet = (struct pm4_mec_write_data_mmio *)buffer; +memset (buffer,0 ,sizeof (struct pm4_mec_write_data_mmio )); + + packet->header.u32All =pm_build_pm4_header (IT_WRITE_DATA , +sizeof (struct pm4_mec_write_data_mmio )); + + packet->bitfields2.dst_sel = dst_sel___write_data__mem_mapped_register; + packet->bitfields2.addr_incr = + addr_incr___write_data__do_not_increment_address; + + packet->bitfields3.dst_mmreg_addr = reg_offset; + + packet->data = reg_data; + +return 0 ; +} +static int pm_unmap_queues_v9 (struct packet_manager *pm,uint32_t *buffer,enum kfd_unmap_queues_filter filter,uint32_t filter_param,bool reset)
@@ -333,6 +368,7 @@ const struct packet_manager_funcs kfd_v9_pm_funcs = { .set_resources = pm_set_resources_v9, .map_queues = pm_map_queues_v9, .unmap_queues = pm_unmap_queues_v9, + .set_grace_period = pm_set_grace_period_v9, .query_status = pm_query_status_v9, .release_mem = NULL, .map_process_size = sizeof(struct pm4_mes_map_process),
@@ -340,6 +376,7 @@ const struct packet_manager_funcs kfd_v9_pm_funcs = { .set_resources_size = sizeof(struct pm4_mes_set_resources), .map_queues_size = sizeof(struct pm4_mes_map_queues), .unmap_queues_size = sizeof(struct pm4_mes_unmap_queues), + .set_grace_period_size = sizeof(struct pm4_mec_write_data_mmio), .query_status_size = sizeof(struct pm4_mes_query_status), .release_mem_size = 0, };
@@ -350,6 +387,7 @@ const struct packet_manager_funcs kfd_aldebaran_pm_funcs = { .set_resources = pm_set_resources_v9, .map_queues = pm_map_queues_v9, .unmap_queues = pm_unmap_queues_v9, + .set_grace_period = pm_set_grace_period_v9, .query_status = pm_query_status_v9, .release_mem = NULL, .map_process_size = sizeof(struct pm4_mes_map_process_aldebaran),
@@ -357,6 +395,7 @@ const struct packet_manager_funcs kfd_aldebaran_pm_funcs = { .set_resources_size = sizeof(struct pm4_mes_set_resources), .map_queues_size = sizeof(struct pm4_mes_map_queues), .unmap_queues_size = sizeof(struct pm4_mes_unmap_queues), + .set_grace_period_size = sizeof(struct pm4_mec_write_data_mmio), .query_status_size = sizeof(struct pm4_mes_query_status), .release_mem_size = 0, };
drivers/gpu/drm/amd/amdkfd/kfd_pm4_headers_ai.h +65 -0
71 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +5 -0
@@ -1300,6 +1300,8 @@ struct packet_manager_funcs {int (*unmap_queues)(struct packet_manager *pm,uint32_t *buffer,enum kfd_unmap_queues_filter mode,uint32_t filter_param,bool reset); +int (*set_grace_period)(struct packet_manager *pm,uint32_t *buffer, +uint32_t grace_period);int (*query_status)(struct packet_manager *pm,uint32_t *buffer,uint64_t fence_address,uint64_t fence_value);int (*release_mem)(uint64_t gpu_addr,uint32_t *buffer);
@@ -1310,6 +1312,7 @@ struct packet_manager_funcs {int set_resources_size;int map_queues_size;int unmap_queues_size; +int set_grace_period_size;int query_status_size;int release_mem_size; };
@@ -1332,6 +1335,8 @@ int pm_send_unmap_queue(struct packet_manager *pm,void pm_release_ib (struct packet_manager *pm); +int pm_update_grace_period (struct packet_manager *pm,uint32_t grace_period); +/* Following PM funcs can be shared among VI and AI */ unsigned int pm_build_pm4_header (unsigned int opcode,size_t packet_size);
Signature · 1 line
2.25.1
PATCH 11/29 drm/amdkfd: prepare map process for single process debug devices
In reply to Jonathan KimOlder HW only supports debugging on a single process because the SPI debug mode setting registers are device global.
The HWS has supplied a single pinned VMID (0xf) for MAP_PROCESS for debug purposes. To pin the VMID, the KFD will remove the VMID from the HWS dynamic VMID allocation via SET_RESOUCES so that a debugged process will never migrate away from its pinned VMID.
The KFD is responsible for reserving and releasing this pinned VMID accordingly whenever the debugger attaches and detaches respectively.
--- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 101 +++++++++++++++++- .../drm/amd/amdkfd/kfd_device_queue_manager.h | 5 + .../drm/amd/amdkfd/kfd_packet_manager_v9.c | 9 ++ .../gpu/drm/amd/amdkfd/kfd_pm4_headers_ai.h | 5 +- 4 files changed, 115 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +97 -4
@@ -1495,6 +1495,8 @@ static int initialize_cpsch(struct device_queue_manager *dqm)else dqm->xgmi_sdma_bitmap = (BIT_ULL (num_xgmi_sdma_queues) -1 ); + dqm->trap_debug_vmid =0 ; +INIT_WORK (&dqm->hw_exception_work, kfd_process_hw_exception);if (dqm->dev->kfd2kgd->get_iq_wait_times)
@@ -1936,8 +1938,7 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,if (!dqm->dev->shared_resources.enable_mes) {decrement_queue_count (dqm, qpd, q); retval =execute_queues_cpsch (dqm, -KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES ,0 , -USE_DEFAULT_GRACE_PERIOD ); +KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES ,0 ,USE_DEFAULT_GRACE_PERIOD );if (retval == -ETIME ) qpd->reset_wavefronts = true; }else {
@@ -2466,6 +2467,98 @@ static void kfd_process_hw_exception(struct work_struct *work)amdgpu_amdkfd_gpu_reset (dqm->dev->adev); } +int reserve_debug_trap_vmid (struct device_queue_manager *dqm, +struct qcm_process_device *qpd) +{ +int r; +int updated_vmid_mask; + +if (dqm->sched_policy ==KFD_SCHED_POLICY_NO_HWS ) { +pr_err ("Unsupported on sched_policy: %i\n" , dqm->sched_policy); +return -EINVAL ; + } + +dqm_lock (dqm); + +if (dqm->trap_debug_vmid !=0 ) { +pr_err ("Trap debug id already reserved\n" ); + r = -EBUSY ; + goto out_unlock; + } + + r =unmap_queues_cpsch (dqm,KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES ,0 , +USE_DEFAULT_GRACE_PERIOD , false); +if (r) + goto out_unlock; + + updated_vmid_mask = dqm->dev->shared_resources.compute_vmid_bitmap; + updated_vmid_mask &= ~(1 << dqm->dev->vm_info.last_vmid_kfd); + + dqm->dev->shared_resources.compute_vmid_bitmap = updated_vmid_mask; + dqm->trap_debug_vmid = dqm->dev->vm_info.last_vmid_kfd; + r =set_sched_resources (dqm); +if (r) + goto out_unlock; + + r =map_queues_cpsch (dqm); +if (r) + goto out_unlock; + +pr_debug ("Reserved VMID for trap debug: %i\n" , dqm->trap_debug_vmid); + +out_unlock: +dqm_unlock (dqm); +return r; +} + +/* +* Releases vmid for the trap debugger +*/ +int release_debug_trap_vmid (struct device_queue_manager *dqm, +struct qcm_process_device *qpd) +{ +int r; +int updated_vmid_mask; +uint32_t trap_debug_vmid; + +if (dqm->sched_policy ==KFD_SCHED_POLICY_NO_HWS ) { +pr_err ("Unsupported on sched_policy: %i\n" , dqm->sched_policy); +return -EINVAL ; + } + +dqm_lock (dqm); + trap_debug_vmid = dqm->trap_debug_vmid; +if (dqm->trap_debug_vmid ==0 ) { +pr_err ("Trap debug id is not reserved\n" ); + r = -EINVAL ; + goto out_unlock; + } + + r =unmap_queues_cpsch (dqm,KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES ,0 , +USE_DEFAULT_GRACE_PERIOD , false); +if (r) + goto out_unlock; + + updated_vmid_mask = dqm->dev->shared_resources.compute_vmid_bitmap; + updated_vmid_mask |= (1 << dqm->dev->vm_info.last_vmid_kfd); + + dqm->dev->shared_resources.compute_vmid_bitmap = updated_vmid_mask; + dqm->trap_debug_vmid =0 ; + r =set_sched_resources (dqm); +if (r) + goto out_unlock; + + r =map_queues_cpsch (dqm); +if (r) + goto out_unlock; + +pr_debug ("Released VMID for trap debug: %i\n" , trap_debug_vmid); + +out_unlock: +dqm_unlock (dqm); +return r; +} +#if defined(CONFIG_DEBUG_FS ) static void seq_reg_dump(struct seq_file *m,
@@ -2566,8 +2659,8 @@ int dqm_debugfs_hang_hws(struct device_queue_manager *dqm)return r; } dqm->active_runlist = true; - r =execute_queues_cpsch (dqm,KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES , -0 ,USE_DEFAULT_GRACE_PERIOD ); + r =execute_queues_cpsch (dqm,KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES ,0 , +USE_DEFAULT_GRACE_PERIOD );dqm_unlock (dqm);return r;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +5 -0
@@ -250,6 +250,7 @@ struct device_queue_manager {struct kfd_mem_obj *fence_mem;bool active_runlist;int sched_policy; +uint32_t trap_debug_vmid;/* hw exception */ bool is_hws_hang;
@@ -281,6 +282,10 @@ unsigned int get_queues_per_pipe(struct device_queue_manager *dqm);unsigned int get_pipes_per_mec (struct device_queue_manager *dqm);unsigned int get_num_sdma_queues (struct device_queue_manager *dqm);unsigned int get_num_xgmi_sdma_queues (struct device_queue_manager *dqm); +int reserve_debug_trap_vmid (struct device_queue_manager *dqm, +struct qcm_process_device *qpd); +int release_debug_trap_vmid (struct device_queue_manager *dqm, +struct qcm_process_device *qpd);static inline unsigned int get_sh_mem_bases_32 (struct kfd_process_device *pdd) {
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager_v9.c +9 -0
@@ -34,6 +34,9 @@ static int pm_map_process_v9(struct packet_manager *pm, {struct pm4_mes_map_process *packet;uint64_t vm_page_table_base_addr = qpd->page_table_base; +struct kfd_dev *kfd = pm->dqm->dev; +struct kfd_process_device *pdd = + container_of(qpd, struct kfd_process_device, qpd); packet = (struct pm4_mes_map_process *)buffer;memset (buffer,0 ,sizeof (struct pm4_mes_map_process ));
@@ -49,6 +52,12 @@ static int pm_map_process_v9(struct packet_manager *pm, packet->bitfields14.sdma_enable =1 ; packet->bitfields14.num_queues = (qpd->is_debug) ?0 : qpd->queue_count; +if (kfd->dqm->trap_debug_vmid && pdd->process->debug_trap_enabled && + pdd->process->runtime_info.runtime_state ==DEBUG_RUNTIME_STATE_ENABLED ) { + packet->bitfields2.debug_vmid = kfd->dqm->trap_debug_vmid; + packet->bitfields2.new_debug =1 ; + } + packet->sh_mem_config = qpd->sh_mem_config; packet->sh_mem_bases = qpd->sh_mem_bases;if (qpd->tba_addr) {
drivers/gpu/drm/amd/amdkfd/kfd_pm4_headers_ai.h +4 -1
@@ -146,7 +146,10 @@ struct pm4_mes_map_process {union {struct {uint32_t pasid:16 ; -uint32_t reserved1:8 ; +uint32_t reserved1:2 ; +uint32_t debug_vmid:4 ; +uint32_t new_debug:1 ; +uint32_t reserved2:1 ;uint32_t diq_enable:1 ;uint32_t process_quantum:7 ; } bitfields2;
Signature · 1 line
2.25.1
PATCH 12/29 drm/amdgpu: prepare map process for multi-process debug devices
In reply to Jonathan KimUnlike single process debug devices, multi-process debug devices allow debug mode setting per-VMID (non-device-global).
Because the HWS manages PASID-VMID mapping, the new MAP_PROCESS API allows the KFD to forward the required SPI debug register write requests.
To request a new debug mode setting change, the KFD must be able to preempt all queues then remap all queues with these new setting requests for MAP_PROCESS to take effect.
Note that by default, debug mode must be disabled for performance reasons for multi-process debug devices for performance reasons.
--- drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 7 +++ .../drm/amd/amdkfd/kfd_device_queue_manager.c | 50 +++++++++++++++++++ .../drm/amd/amdkfd/kfd_device_queue_manager.h | 3 ++ .../drm/amd/amdkfd/kfd_packet_manager_v9.c | 15 ++++++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 9 ++++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 5 ++ 6 files changed, 89 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +7 -0
@@ -32,5 +32,12 @@ int kfd_dbg_trap_disable(struct kfd_process *target);int kfd_dbg_trap_enable (struct kfd_process *target,uint32_t fd,void __user *runtime_info,uint32_t *runtime_info_size); + +static inline bool kfd_dbg_is_per_vmid_supported (struct kfd_dev *dev) +{ +return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 );/* Aldebaran */ +} +void debug_event_write_work_handler (struct work_struct *work); +#endif
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +50 -0
56 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +3 -0
@@ -286,6 +286,9 @@ int reserve_debug_trap_vmid(struct device_queue_manager *dqm, struct qcm_process_device *qpd);int release_debug_trap_vmid (struct device_queue_manager *dqm,struct qcm_process_device *qpd); +int debug_lock_and_unmap (struct device_queue_manager *dqm); +int debug_map_and_unlock (struct device_queue_manager *dqm); +int debug_refresh_runlist (struct device_queue_manager *dqm);static inline unsigned int get_sh_mem_bases_32 (struct kfd_process_device *pdd) {
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager_v9.c +15 -0
@@ -88,6 +88,10 @@ static int pm_map_process_aldebaran(struct packet_manager *pm, {struct pm4_mes_map_process_aldebaran *packet;uint64_t vm_page_table_base_addr = qpd->page_table_base; +struct kfd_dev *kfd = pm->dqm->dev; +struct kfd_process_device *pdd = + container_of(qpd, struct kfd_process_device, qpd); +int i; packet = (struct pm4_mes_map_process_aldebaran *)buffer;memset (buffer,0 ,sizeof (struct pm4_mes_map_process_aldebaran ));
@@ -102,6 +106,17 @@ static int pm_map_process_aldebaran(struct packet_manager *pm, packet->bitfields14.num_oac = qpd->num_oac; packet->bitfields14.sdma_enable =1 ; packet->bitfields14.num_queues = (qpd->is_debug) ?0 : qpd->queue_count; +/* TRAP_EN is set on boot so keep it set in non-debug mode. */ + packet->spi_gdbg_per_vmid_cntl = pdd->spi_dbg_override | + pdd->spi_dbg_launch_mode; + +if (pdd->process->debug_trap_enabled) { +for (i =0 ; i < kfd->device_info.num_of_watch_points; i++) + packet->tcp_watch_cntl[i] = pdd->watch_points[i]; + + packet->bitfields2.single_memops = + !!(pdd->process->dbg_flags &KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP ); + } packet->sh_mem_config = qpd->sh_mem_config; packet->sh_mem_bases = qpd->sh_mem_bases;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +9 -0
@@ -782,6 +782,12 @@ struct kfd_process_device {uint64_t faults;uint64_t page_in;uint64_t page_out; + +/* Tracks debug per-vmid request settings */ +uint32_t spi_dbg_override; +uint32_t spi_dbg_launch_mode; +uint32_t watch_points[4 ]; +/* * If this process has been checkpointed before, then the user * application will use the original gpu_id on the
@@ -918,6 +924,9 @@ struct kfd_process {bool xnack_enabled; +/* Tracks debug per-vmid request for debug flags */ +bool dbg_flags; +/* Work area for debugger event writer worker. */ struct work_struct debug_event_workarea;
drivers/gpu/drm/amd/amdkfd/kfd_process.c +5 -0
@@ -1563,6 +1563,11 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, } p->pdds[p->n_pdds++] = pdd; +if (kfd_dbg_is_per_vmid_supported (pdd->dev)) + pdd->spi_dbg_override = pdd->dev->kfd2kgd->disable_debug_trap ( + pdd->dev->adev, + false, +0 );/* Init idr used for memory handle translation */ idr_init (&pdd->alloc_idr);
Signature · 1 line
2.25.1
PATCH 13/29 drm/amdkfd: add per process hw trap enable and disable functions
In reply to Jonathan KimTo enable HW debug mode per process, all devices must be debug enabled successfully. If a failure occures, rewind the enablement of debug mode on the enabled devices.
A power management scenario that needs to be considered is HW debug mode setting during GFXOFF. During GFXOFF, these registers will be unreachable so we have to transiently disable GFXOFF when setting. Also, some devices don't support the RLC save restore function for these debug registers so we have to disable GFXOFF completely during a debug session.
Cooperative launch also has debugging restriction based on FW bugs. If such bugs exists, the debugger cannot attach to a process that uses GWS resources nor can GWS resources be requested if a process is being debugged.
Also multi-process debug devices can only enable trap temporaries based on certain runtime scenerios, which will be explained when the runtime enable functions are implemented in a follow up patch.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 + drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 134 +++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 23 +++ .../drm/amd/amdkfd/kfd_device_queue_manager.c | 1 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 9 ++ 5 files changed, 170 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +5 -0
@@ -1442,6 +1442,11 @@ static int kfd_ioctl_alloc_queue_gws(struct file *filep, goto out_unlock; } +if (!kfd_dbg_has_gws_support (dev) && p->debug_trap_enabled) { + retval = -EBUSY ; + goto out_unlock; + } + retval =pqm_set_gws (&p->pqm, args->queue_id, args->num_gws ? dev->gws :NULL );mutex_unlock (&p->mutex);
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +132 -2
176 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +23 -0
@@ -40,4 +40,27 @@ static inline bool kfd_dbg_is_per_vmid_supported(struct kfd_dev *dev)void debug_event_write_work_handler (struct work_struct *work); +/* +* If GFX off is enabled, chips that do not support RLC restore for the debug +* registers will disable GFX off temporarily for the entire debug session. +* See disable_on_trap_action_entry and enable_on_trap_action_exit for details. +*/ +static inline bool kfd_dbg_is_rlc_restore_supported (struct kfd_dev *dev) +{ +return !(KFD_GC_VERSION (dev) ==IP_VERSION (10 ,1 ,10 ) ||/* Navi10 */ +KFD_GC_VERSION (dev) ==IP_VERSION (10 ,1 ,1 ));/* Navi14 */ +} + +static inline bool kfd_dbg_has_gws_support (struct kfd_dev *dev) +{ +return ((KFD_GC_VERSION (dev) ==IP_VERSION (9 ,0 ,1 ) + && dev->mec2_fw_version >=0x81b6 ) || + (KFD_GC_VERSION (dev) >=IP_VERSION (9 ,1 ,0 ) + &&KFD_GC_VERSION (dev) <=IP_VERSION (9 ,2 ,2 ) + && dev->mec2_fw_version >=0x1b6 ) || + (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ) + && dev->mec2_fw_version >=0x1b6 ) || + (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) + && dev->mec2_fw_version >=0x30 )); +}#endif
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -0
@@ -36,6 +36,7 @@#include "kfd_kernel_queue.h" #include "amdgpu_amdkfd.h" #include "mes_api_def.h" +#include "kfd_debug.h" /* Size of the per-pipe EOP queue */ #define CIK_HPD_EOP_BYTES_LOG2 11
drivers/gpu/drm/amd/amdkfd/kfd_process.c +9 -0
@@ -1161,6 +1161,7 @@ static void kfd_process_notifier_release(struct mmu_notifier *mn, struct mm_struct *mm) {struct kfd_process *p; +int i;/* * The kfd_process structure can not be free because the
@@ -1178,6 +1179,14 @@ static void kfd_process_notifier_release(struct mmu_notifier *mn,cancel_delayed_work_sync (&p->eviction_work);cancel_delayed_work_sync (&p->restore_work); +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +/* re-enable GFX OFF since runtime enable with ttmp setup disabled it. */ +if (!kfd_dbg_is_rlc_restore_supported (pdd->dev) && p->runtime_info.ttmp_setup) +amdgpu_gfx_off_ctrl (pdd->dev->adev, true); + } +if (p->debug_trap_enabled)kfd_dbg_trap_disable (p);
Signature · 1 line
2.25.1
PATCH 14/29 drm/amdkfd: add raise exception event function
In reply to Jonathan KimException events can be generated from interrupts or queue activitity.
The raise event function will save exception status of a queue, device or process then notify the debugger of the status change by writing to a debugger polled file descriptor that the debugger provides during debug attach.
For memory violation exceptions, extra exception data will be saved.
The debugger will be able to query the saved exception states by query operation that will be provided by follow up patches.
--- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 90 ++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 5 ++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 7 ++ 3 files changed, 102 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +90 -0
@@ -38,6 +38,93 @@ void debug_event_write_work_handler(struct work_struct *work)kernel_write (process->dbg_ev_file, &write_data,1 , &pos); } +/* update process/device/queue exception status, write to descriptor +* only if exception_status is enabled. +*/ +bool kfd_dbg_ev_raise (uint64_t event_mask, +struct kfd_process *process,struct kfd_dev *dev, +unsigned int source_id,bool use_worker, +void *exception_data,size_t exception_data_size) +{ +struct process_queue_manager *pqm; +struct process_queue_node *pqn; +int i; +static const char write_data ='.' ; +loff_t pos =0 ; +bool is_subscribed = true; + +if (!(process && process->debug_trap_enabled)) +return false; + +mutex_lock (&process->event_mutex); + +if (event_mask &KFD_EC_MASK_DEVICE ) { +for (i =0 ; i < process->n_pdds; i++) { +struct kfd_process_device *pdd = process->pdds[i]; + +if (pdd->dev != dev) +continue ; + + pdd->exception_status |= event_mask &KFD_EC_MASK_DEVICE ; + +if (event_mask &KFD_EC_MASK (EC_DEVICE_MEMORY_VIOLATION )) { +if (!pdd->vm_fault_exc_data) { + pdd->vm_fault_exc_data =kmemdup ( + exception_data, + exception_data_size, +GFP_KERNEL ); +if (!pdd->vm_fault_exc_data) +pr_debug ("Failed to allocate exception data memory" ); + }else { +pr_debug ("Debugger exception data not saved\n" ); +print_hex_dump_bytes ("exception data: " , +DUMP_PREFIX_OFFSET , + exception_data, + exception_data_size); + } + } +break ; + } + }else if (event_mask &KFD_EC_MASK_PROCESS ) { + process->exception_status |= event_mask &KFD_EC_MASK_PROCESS ; + }else { + pqm = &process->pqm; +list_for_each_entry (pqn, &pqm->queues, + process_queue_list) { +int target_id; + +if (!pqn->q) +continue ; + + target_id = event_mask &KFD_EC_MASK (EC_QUEUE_NEW ) ? + pqn->q->properties.queue_id : + pqn->q->doorbell_id; + +if (pqn->q->device != dev || target_id != source_id) +continue ; + + pqn->q->properties.exception_status |= event_mask; +break ; + } + } + +if (process->exception_enable_mask & event_mask) { +if (use_worker) +schedule_work (&process->debug_event_workarea); +else +kernel_write (process->dbg_ev_file, + &write_data, +1 , + &pos); + }else { + is_subscribed = false; + } + +mutex_unlock (&process->event_mutex); + +return is_subscribed; +} +/* kfd_dbg_trap_deactivate: * target: target process * unwind: If this is unwinding a failed kfd_dbg_trap_enable()
@@ -50,6 +137,9 @@ static void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int {int i, count =0 ; +if (!unwind) +cancel_work_sync (&target->debug_event_workarea); +for (i =0 ; i < target->n_pdds; i++) {struct kfd_process_device *pdd = target->pdds[i];
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +5 -0
@@ -28,6 +28,11 @@void kgd_gfx_v9_set_wave_launch_stall (struct amdgpu_device *adev,uint32_t vmid,bool stall); +bool kfd_dbg_ev_raise (uint64_t event_mask, +struct kfd_process *process,struct kfd_dev *dev, +unsigned int source_id,bool use_worker, +void *exception_data, +size_t exception_data_size);int kfd_dbg_trap_disable (struct kfd_process *target); int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd, void __user *runtime_info,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +7 -0
@@ -493,6 +493,7 @@ struct queue_properties {uint32_t ctl_stack_size;uint64_t tba_addr;uint64_t tma_addr; +uint64_t exception_status; };#define QUEUE_IS_ACTIVE (q) ((q).queue_size > 0 && \
@@ -783,6 +784,11 @@ struct kfd_process_device {uint64_t page_in;uint64_t page_out; +/* Exception code status*/ +uint64_t exception_status; +void *vm_fault_exc_data; +size_t vm_fault_exc_data_size; +/* Tracks debug per-vmid request settings */ uint32_t spi_dbg_override;uint32_t spi_dbg_launch_mode;
@@ -918,6 +924,7 @@ struct kfd_process {/* Exception code enable mask and status */ uint64_t exception_enable_mask; +uint64_t exception_status;/* shared virtual memory registered by this process */ struct svm_range_list svms;
Signature · 1 line
2.25.1
PATCH 15/29 drm/amdkfd: add send exception operation
In reply to Jonathan KimAdd a debug operation that allows the debugger to send an exception directly to runtime through a payload address.
For memory violations, normal vmfault signals will be applied to notify runtime instead after passing in the saved exception data when a memory violation was raised to the debugger.
For runtime exceptions, this will unblock the runtime enable function which will be explained and implemented in a follow up patch.
--- .../gpu/drm/amd/amdkfd/cik_event_interrupt.c | 4 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 ++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 43 +++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 5 ++ drivers/gpu/drm/amd/amdkfd/kfd_events.c | 3 +- .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 7 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 71 ++++++++++++++++++- 8 files changed, 134 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/cik_event_interrupt.c +2 -2
@@ -118,9 +118,9 @@ static void cik_event_interrupt_wq(struct kfd_dev *dev,return ;if (info.vmid == vmid) -kfd_signal_vm_fault_event (dev, pasid, &info); +kfd_signal_vm_fault_event (dev, pasid, &info,NULL );else -kfd_signal_vm_fault_event (dev, pasid,NULL ); +kfd_signal_vm_fault_event (dev, pasid,NULL ,NULL ); } }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +5 -0
@@ -2708,6 +2708,11 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v r =kfd_dbg_trap_disable (target);break ;case KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT : + r =kfd_dbg_send_exception_to_runtime (target, + args->send_runtime_event.gpu_id, + args->send_runtime_event.queue_id, + args->send_runtime_event.exception_mask); +break ;case KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED :case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE :case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +43 -0
49 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +5 -0
@@ -38,6 +38,11 @@ int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,void __user *runtime_info, uint32_t *runtime_info_size); +int kfd_dbg_send_exception_to_runtime (struct kfd_process *p, +unsigned int dev_id, +unsigned int queue_id, +uint64_t error_reason); +static inline bool kfd_dbg_is_per_vmid_supported (struct kfd_dev *dev) {return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 );/* Aldebaran */
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -1
@@ -1226,7 +1226,8 @@ void kfd_signal_hw_exception_event(u32 pasid) }void kfd_signal_vm_fault_event (struct kfd_dev *dev,u32 pasid, -struct kfd_vm_fault_info *info) +struct kfd_vm_fault_info *info, +struct kfd_hsa_memory_exception_data *data) {struct kfd_event *ev;uint32_t id;
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +1 -1
@@ -362,7 +362,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,kfd_smi_event_update_vmfault (dev, pasid);kfd_dqm_evict_pasid (dev->dqm, pasid); -kfd_signal_vm_fault_event (dev, pasid, &info); +kfd_signal_vm_fault_event (dev, pasid, &info,NULL ); } }
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -1
@@ -942,6 +942,7 @@ struct kfd_process {bool queues_paused;/* Tracks runtime enable status */ +struct semaphore runtime_enable_sema;struct kfd_runtime_info runtime_info; };
@@ -1391,7 +1392,8 @@ int kfd_get_num_events(struct kfd_process *p);int kfd_event_destroy (struct kfd_process *p,uint32_t event_id);void kfd_signal_vm_fault_event (struct kfd_dev *dev,u32 pasid, -struct kfd_vm_fault_info *info); +struct kfd_vm_fault_info *info, +struct kfd_hsa_memory_exception_data *data);void kfd_signal_reset_event (struct kfd_dev *dev);
@@ -1407,6 +1409,9 @@ static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); } +int kfd_send_exception_to_runtime (struct kfd_process *p, +unsigned int queue_id, +uint64_t error_reason);bool kfd_is_locked (void );/* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_process.c +70 -1
86 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 16/29 drm/amdkfd: add runtime enable operation
In reply to Jonathan KimThis operation coordinates the debugger with the target HSA runtime process.
The main motive for this coordination is due to CP performance overhead when enabling trap temporaries via SPI_GDBG_PER_VMID_CNTL.Trap_en. This overhead is unacceptable for microbench performance in normal mode for certain customers.
ROCr allows the user to bypass trap temporary setup through the HSA_ENABLE_DEBUG environment variable. As a result, the debugger has to consider two scenarios.
For the first scenario, if the runtime enable of the target has already occurred prior to the debugger attaching, then the debugger will go ahead and setup the trap temporaries whether runtime has requested them or not. The debugger will be able to query the runtime status on attach.
For the second scenario where the debugger spawns the target process, it will have to wait for ROCr's runtime enable request from the target. The runtime enable request will be able to see that it's process has been debug attached. It then enables the trap temporaries since it now knows it's in debug mode, raises an EC_PROCESS_RUNTIME signal to the debugger then waits for the debugger's response. Once the debugger has received the runtime signal, it will wake the target process.
In addition there is an additional restriction that is required to be enforced with runtime enable and HW debug mode setting. The debugger must first ensure that HW debug mode has been enabled before permitting HW debug mode operations.
With single process debug devices, allowing the debugger to set debug HW modes prior to trap activation means that debug HW mode setting can occur before the KFD has reserved the debug VMID (0xf) from the hardware scheduler's VMID allocation resource pool. This can result in the hardware scheduler assigning VMID 0xf to a non-debugged process and having that process inherit debug HW mode settings intended for the debugged target process instead, which is both incorrect and potentially fatal for normal mode operation.
With multi process debug devices, allowing the debugger to set debug HW modes prior to trap activation means that non-debugged processes migrating to a new VMID could inherit unintended debug settings.
All debug operations that touch HW settings must require trap activation where trap activation is triggered by both debug attach and runtime enablement (target has KFD opened and is ready to dispatch work).
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 144 ++++++++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 4 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 2 + drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + 4 files changed, 148 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +143 -1
@@ -2625,11 +2625,141 @@ static int kfd_ioctl_criu(struct file *filep, struct kfd_process *p, void *data)return ret; } -static int kfd_ioctl_runtime_enable (struct file *filep,struct kfd_process *p,void *data) +static int runtime_enable (struct kfd_process *p,uint64_t r_debug, +bool enable_ttmp_setup) { +int i =0 , ret =0 ; + +if (p->is_runtime_retry) + goto retry; + +if (p->runtime_info.runtime_state !=DEBUG_RUNTIME_STATE_DISABLED ) +return -EBUSY ; + +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (pdd->qpd.queue_count) +return -EEXIST ; + } + + p->runtime_info.runtime_state =DEBUG_RUNTIME_STATE_ENABLED ; + p->runtime_info.r_debug = r_debug; + p->runtime_info.ttmp_setup = enable_ttmp_setup; + +if (p->runtime_info.ttmp_setup) { +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (!kfd_dbg_is_rlc_restore_supported (pdd->dev)) { +amdgpu_gfx_off_ctrl (pdd->dev->adev, false); + pdd->dev->kfd2kgd->enable_debug_trap ( + pdd->dev->adev, + true, + pdd->dev->vm_info.last_vmid_kfd); + } + +if (kfd_dbg_is_per_vmid_supported (pdd->dev)) { + pdd->spi_dbg_override = pdd->dev->kfd2kgd->enable_debug_trap ( + pdd->dev->adev, + false, + pdd->dev->vm_info.last_vmid_kfd); + +debug_refresh_runlist (pdd->dev->dqm); + } + } + } + +retry: +if (p->debug_trap_enabled) { +if (!p->is_runtime_retry) { +kfd_dbg_trap_activate (p); +kfd_dbg_ev_raise (KFD_EC_MASK (EC_PROCESS_RUNTIME ), + p,NULL ,0 , false,NULL ,0 ); + } + +mutex_unlock (&p->mutex); + ret =down_interruptible (&p->runtime_enable_sema); +mutex_lock (&p->mutex); + + p->is_runtime_retry = !!ret; + } + +return ret; +} + +static int runtime_disable (struct kfd_process *p) +{ +int i =0 , ret; +bool was_enabled = p->runtime_info.runtime_state ==DEBUG_RUNTIME_STATE_ENABLED ; + + p->runtime_info.runtime_state =DEBUG_RUNTIME_STATE_DISABLED ; + p->runtime_info.r_debug =0 ; + +if (p->debug_trap_enabled) { +if (was_enabled) +kfd_dbg_trap_deactivate (p, false,0 ); + +if (!p->is_runtime_retry) +kfd_dbg_ev_raise (KFD_EC_MASK (EC_PROCESS_RUNTIME ), + p,NULL ,0 , false,NULL ,0 ); + +mutex_unlock (&p->mutex); + ret =down_interruptible (&p->runtime_enable_sema); +mutex_lock (&p->mutex); + + p->is_runtime_retry = !!ret; +if (ret) +return ret; + } + +if (was_enabled && p->runtime_info.ttmp_setup) { +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (!kfd_dbg_is_rlc_restore_supported (pdd->dev)) +amdgpu_gfx_off_ctrl (pdd->dev->adev, true); + } + } + + p->runtime_info.ttmp_setup = false; + +/* disable DISPATCH_PTR save */ +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (kfd_dbg_is_per_vmid_supported (pdd->dev)) { + pdd->spi_dbg_override = + pdd->dev->kfd2kgd->disable_debug_trap ( + pdd->dev->adev, + false, + pdd->dev->vm_info.last_vmid_kfd); + +debug_refresh_runlist (pdd->dev->dqm); + } + } +return 0 ; } +static int kfd_ioctl_runtime_enable (struct file *filep,struct kfd_process *p,void *data) +{ +struct kfd_ioctl_runtime_enable_args *args = data; +int r; + +mutex_lock (&p->mutex); + +if (args->mode_mask &KFD_RUNTIME_ENABLE_MODE_ENABLE_MASK ) + r =runtime_enable (p, args->r_debug, + !!(args->mode_mask &KFD_RUNTIME_ENABLE_MODE_TTMP_SAVE_MASK )); +else + r =runtime_disable (p); + +mutex_unlock (&p->mutex); + +return r; +} +static int kfd_ioctl_set_debug_trap (struct file *filep,struct kfd_process *p,void *data) {struct kfd_ioctl_dbg_trap_args *args = data;
@@ -2690,6 +2820,18 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v goto unlock_out; } +if (target->runtime_info.runtime_state !=DEBUG_RUNTIME_STATE_ENABLED && + (args->op ==KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE || + args->op ==KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE || + args->op ==KFD_IOC_DBG_TRAP_SUSPEND_QUEUES || + args->op ==KFD_IOC_DBG_TRAP_RESUME_QUEUES || + args->op ==KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH || + args->op ==KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH || + args->op ==KFD_IOC_DBG_TRAP_SET_FLAGS )) { + r = -EPERM ; + goto unlock_out; + } +switch (args->op) {case KFD_IOC_DBG_TRAP_ENABLE :if (target != p)
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2 -2
@@ -176,7 +176,7 @@ int kfd_dbg_send_exception_to_runtime(struct kfd_process *p,* to unwind * else: ignored */ -static void kfd_dbg_trap_deactivate (struct kfd_process *target,bool unwind,int unwind_count) +void kfd_dbg_trap_deactivate (struct kfd_process *target,bool unwind,int unwind_count) {int i, count =0 ;
@@ -238,7 +238,7 @@ int kfd_dbg_trap_disable(struct kfd_process *target)return 0 ; } -static int kfd_dbg_trap_activate (struct kfd_process *target) +int kfd_dbg_trap_activate (struct kfd_process *target) {int i, r =0 , unwind_count =0 ;
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2 -0
@@ -28,6 +28,8 @@void kgd_gfx_v9_set_wave_launch_stall (struct amdgpu_device *adev,uint32_t vmid,bool stall); +void kfd_dbg_trap_deactivate (struct kfd_process *target,bool unwind,int unwind_count); +int kfd_dbg_trap_activate (struct kfd_process *target); bool kfd_dbg_ev_raise(uint64_t event_mask, struct kfd_process *process, struct kfd_dev *dev, unsigned int source_id, bool use_worker,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -943,6 +943,7 @@ struct kfd_process {/* Tracks runtime enable status */ struct semaphore runtime_enable_sema; +bool is_runtime_retry;struct kfd_runtime_info runtime_info; };
Signature · 1 line
2.25.1
PATCH 17/29 drm/amdkfd: Add debug trap enabled flag to TMA
In reply to Jonathan KimFrom: Jay Cornwall <[email protected]>
Trap handler behavior will differ when a debugger is attached.
Make the debug trap flag available in the trap handler TMA. Update it when the debug trap ioctl is invoked.
v3: Rebase for upstream
v2:
Add missing debug flag setup on APUs
--- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 4 ++++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 ++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +4 -0
@@ -193,6 +193,8 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindif (unwind && count == unwind_count)break ; +kfd_process_set_trap_debug_flag (&pdd->qpd, false); +/* GFX off is already disabled by debug activate if not RLC restore supported. */ if (kfd_dbg_is_rlc_restore_supported (pdd->dev))amdgpu_gfx_off_ctrl (pdd->dev->adev, false);
@@ -278,6 +280,8 @@ int kfd_dbg_trap_activate(struct kfd_process *target)if (kfd_dbg_is_rlc_restore_supported (pdd->dev))amdgpu_gfx_off_ctrl (pdd->dev->adev, true); +kfd_process_set_trap_debug_flag (&pdd->qpd, true); + r =debug_refresh_runlist (pdd->dev->dqm);if (r) { target->runtime_info.runtime_state =
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
@@ -1101,6 +1101,8 @@ int kfd_init_apertures(struct kfd_process *process);void kfd_process_set_trap_handler (struct qcm_process_device *qpd,uint64_t tba_addr,uint64_t tma_addr); +void kfd_process_set_trap_debug_flag (struct qcm_process_device *qpd, +bool enabled);/* CWSR initialization */ int kfd_process_init_cwsr_apu (struct kfd_process *process,struct file *filep);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +16 -0
@@ -1252,6 +1252,8 @@ int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep)memcpy (qpd->cwsr_kaddr, dev->cwsr_isa, dev->cwsr_isa_size); +kfd_process_set_trap_debug_flag (qpd, p->debug_trap_enabled); + qpd->tma_addr = qpd->tba_addr +KFD_CWSR_TMA_OFFSET ;pr_debug ("set tba :0x%llx, tma:0x%llx, cwsr_kaddr:%p for pqm.\n" , qpd->tba_addr, qpd->tma_addr, qpd->cwsr_kaddr);
@@ -1288,6 +1290,9 @@ static int kfd_process_device_init_cwsr_dgpu(struct kfd_process_device *pdd)memcpy (qpd->cwsr_kaddr, dev->cwsr_isa, dev->cwsr_isa_size); +kfd_process_set_trap_debug_flag (&pdd->qpd, + pdd->process->debug_trap_enabled); + qpd->tma_addr = qpd->tba_addr +KFD_CWSR_TMA_OFFSET ;pr_debug ("set tba :0x%llx, tma:0x%llx, cwsr_kaddr:%p for pqm.\n" , qpd->tba_addr, qpd->tma_addr, qpd->cwsr_kaddr);
@@ -1374,6 +1379,17 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)return true; } +void kfd_process_set_trap_debug_flag (struct qcm_process_device *qpd, +bool enabled) +{ +/* If TMA doesn't exist then flag will be set during allocation. */ +if (qpd->cwsr_kaddr) { +uint64_t *tma = + (uint64_t *)(qpd->cwsr_kaddr +KFD_CWSR_TMA_OFFSET ); + tma[2 ] = enabled; + } +} +/* * On return the kfd_process is fully operational and will be freed when the * mm is released
Signature · 1 line
2.25.1
PATCH 18/29 drm/amdkfd: update process interrupt handling for debug events
In reply to Jonathan KimThe debugger must be notified by any debugger subscribed exception that comes from hardware interrupts.
Debugger notification must be scheduled as HW state may be unknown when receiving an exception that could require an immediate process eviction.
If a debugger session exits, any exceptions it subscribed to may still have interrupts in the interrupt ring buffer or KGD/KFD pipeline. To prevent a new session from inheriting stale interrupts, when a new queue is created, open an interrupt drain and allow the IH ring to drain from a timestamped checkpoint. Then inject a custom IV so that once the custom IV is picked up by the KFD, it's safe to close the drain and proceed with queue creation.
The debugger may also not be attached nor subscibed to certain exceptions so forward them directly to the runtime.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 16 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 2 + drivers/gpu/drm/amd/amdkfd/Makefile | 1 + drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 59 +++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 6 + drivers/gpu/drm/amd/amdkfd/kfd_device.c | 4 +- .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c | 402 ++++++++++++++++++ .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 95 ++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 12 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 43 ++ .../amd/amdkfd/kfd_process_queue_manager.c | 1 + 11 files changed, 631 insertions(+), 10 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +16 -0
@@ -760,6 +760,22 @@ void amdgpu_amdkfd_ras_poison_consumption_handler(struct amdgpu_device *adev, boamdgpu_amdkfd_gpu_reset (adev); } +int amdgpu_amdkfd_send_close_event_drain_irq (struct amdgpu_device *adev, +uint32_t *payload) +{ +int ret; + +/* Device or IH ring is not ready so bail. */ + ret =amdgpu_ih_wait_on_checkpoint_process_ts (adev, &adev->irq.ih); +if (ret) +return ret; + +/* Send payload to fence KFD interrupts */ +amdgpu_amdkfd_interrupt (adev, payload); + +return 0 ; +} +bool amdgpu_amdkfd_ras_query_utcl2_poison_status (struct amdgpu_device *adev) {if (adev->gfx.ras && adev->gfx.ras->query_utcl2_poison_status)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
@@ -236,6 +236,8 @@ int amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(struct amdgpu_device *dst,struct amdgpu_device *src, bool is_min);int amdgpu_amdkfd_get_pcie_bandwidth_mbytes (struct amdgpu_device *adev,bool is_min); +int amdgpu_amdkfd_send_close_event_drain_irq (struct amdgpu_device *adev, +uint32_t *payload);/* Read user wptr from a specified user address space with page fault * disabled. The memory must be pinned and mapped to the hardware when
drivers/gpu/drm/amd/amdkfd/Makefile +1 -0
@@ -53,6 +53,7 @@ AMDKFD_FILES := $(AMDKFD_PATH)/kfd_module.o \ $(AMDKFD_PATH)/kfd_events.o \ $(AMDKFD_PATH)/cik_event_interrupt.o \ $(AMDKFD_PATH)/kfd_int_process_v9.o \ + $(AMDKFD_PATH)/kfd_int_process_v10.o \ $(AMDKFD_PATH)/kfd_int_process_v11.o \ $(AMDKFD_PATH)/kfd_smi_events.o \ $(AMDKFD_PATH)/kfd_crat.o \
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +59 -0
65 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +6 -0
@@ -30,6 +30,12 @@ void kgd_gfx_v9_set_wave_launch_stall(struct amdgpu_device *adev, bool stall);void kfd_dbg_trap_deactivate (struct kfd_process *target,bool unwind,int unwind_count);int kfd_dbg_trap_activate (struct kfd_process *target); +bool kfd_set_dbg_ev_from_interrupt (struct kfd_dev *dev, +unsigned int pasid, +uint32_t doorbell_id, +uint64_t trap_mask, +void *exception_data, +size_t exception_data_size); bool kfd_dbg_ev_raise(uint64_t event_mask, struct kfd_process *process, struct kfd_dev *dev, unsigned int source_id, bool use_worker,
drivers/gpu/drm/amd/amdkfd/kfd_device.c +3 -1
@@ -133,6 +133,8 @@ static void kfd_device_info_set_event_interrupt_class(struct kfd_dev *kfd)case IP_VERSION (9 ,4 ,0 ):/* VEGA20 */ case IP_VERSION (9 ,4 ,1 ):/* ARCTURUS */ case IP_VERSION (9 ,4 ,2 ):/* ALDEBARAN */ + kfd->device_info.event_interrupt_class = &event_interrupt_class_v9; +break ;case IP_VERSION (10 ,3 ,1 ):/* VANGOGH */ case IP_VERSION (10 ,3 ,3 ):/* YELLOW_CARP */ case IP_VERSION (10 ,3 ,6 ):/* GC 10.3.6 */
@@ -146,7 +148,7 @@ static void kfd_device_info_set_event_interrupt_class(struct kfd_dev *kfd)case IP_VERSION (10 ,3 ,2 ):/* NAVY_FLOUNDER */ case IP_VERSION (10 ,3 ,4 ):/* DIMGREY_CAVEFISH */ case IP_VERSION (10 ,3 ,5 ):/* BEIGE_GOBY */ - kfd->device_info.event_interrupt_class = &event_interrupt_class_v9; + kfd->device_info.event_interrupt_class = &event_interrupt_class_v10;break ;case IP_VERSION (11 ,0 ,0 ):case IP_VERSION (11 ,0 ,1 ):
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c new file +402 -0
402 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +86 -9
164 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +12 -0
@@ -926,6 +926,10 @@ struct kfd_process {uint64_t exception_enable_mask;uint64_t exception_status; +/* Used to drain stale interrupts */ +wait_queue_head_t wait_irq_drain; +bool irq_drain_is_open; +/* shared virtual memory registered by this process */ struct svm_range_list svms;
@@ -1088,12 +1092,19 @@ int kfd_numa_node_to_apic_id(int numa_node_id);void kfd_double_confirm_iommu_support (struct kfd_dev *gpu);/* Interrupts */ +#define KFD_IRQ_FENCE_CLIENTID 0xff +#define KFD_IRQ_FENCE_SOURCEID 0xff +#define KFD_IRQ_IS_FENCE (client, source) \ + ((client) == KFD_IRQ_FENCE_CLIENTID && \ + (source) == KFD_IRQ_FENCE_SOURCEID)int kfd_interrupt_init (struct kfd_dev *dev);void kfd_interrupt_exit (struct kfd_dev *dev);bool enqueue_ih_ring_entry (struct kfd_dev *kfd,const void *ih_ring_entry);bool interrupt_is_wanted (struct kfd_dev *dev,const uint32_t *ih_ring_entry,uint32_t *patched_ihre,bool *flag); +void kfd_process_drain_interrupts (struct kfd_process_device *pdd); +void kfd_process_close_interrupt_drain (unsigned int pasid);/* amdkfd Apertures */ int kfd_init_apertures (struct kfd_process *process);
@@ -1365,6 +1376,7 @@ uint64_t kfd_get_number_elems(struct kfd_dev *kfd);/* Events */ extern const struct kfd_event_interrupt_class event_interrupt_class_cik;extern const struct kfd_event_interrupt_class event_interrupt_class_v9; +extern const struct kfd_event_interrupt_class event_interrupt_class_v10;extern const struct kfd_event_interrupt_class event_interrupt_class_v11;extern const struct kfd_device_global_init_class device_global_init_class_cik;
drivers/gpu/drm/amd/amdkfd/kfd_process.c +43 -0
55 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1 -0
@@ -330,6 +330,7 @@ int pqm_create_queue(struct process_queue_manager *pqm, kq->queue->properties.queue_id = *qid; pqn->kq = kq; pqn->q =NULL ; +kfd_process_drain_interrupts (pdd); retval = dev->dqm->ops.create_kernel_queue (dev->dqm, kq, &pdd->qpd);break ;
Signature · 1 line
2.25.1
Felix Kuehling
maintainerRe: [PATCH 18/29] drm/amdkfd: update process interrupt handling for debug events
Quoted 6 lines · Jonathan Kim
The debugger must be notified by any debugger subscribed exception that comes from hardware interrupts.
Debugger notification must be scheduled as HW state may be unknown when receiving an exception that could require an immediate process eviction.
I don't understand this statement. Is this a reference to debug_event_write_work_handler that gets scheduled in a workqueue (which is actually implemented in a different patch)? I think the reasoning here was, that kernel_write can stall, which could stall further event processing.
Quoted 11 lines
If a debugger session exits, any exceptions it subscribed to may still have interrupts in the interrupt ring buffer or KGD/KFD pipeline. To prevent a new session from inheriting stale interrupts, when a new queue is created, open an interrupt drain and allow the IH ring to drain from a timestamped checkpoint. Then inject a custom IV so that once the custom IV is picked up by the KFD, it's safe to close the drain and proceed with queue creation.
The debugger may also not be attached nor subscibed to certain exceptions so forward them directly to the runtime.
Can you add a paragraph that explains why you split kfd_int_process_v10 into a separate file?
Two more nit-picks and one potential problem inline.
Quoted 639 lines
Signed-off-by Jonathan Kim <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 16 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 2 + drivers/gpu/drm/amd/amdkfd/Makefile | 1 + drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 59 +++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 6 + drivers/gpu/drm/amd/amdkfd/kfd_device.c | 4 +- .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c | 402 ++++++++++++++++++ .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c | 95 ++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 12 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 43 ++ .../amd/amdkfd/kfd_process_queue_manager.c | 1 + 11 files changed, 631 insertions(+), 10 deletions(-)create mode 100644
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.cdrivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +16
-0@@ -760,6 +760,22 @@ void amdgpu_amdkfd_ras_poison_consumption_handler(struct amdgpu_device *adev, boamdgpu_amdkfd_gpu_reset (adev); } +int amdgpu_amdkfd_send_close_event_drain_irq (struct amdgpu_device *adev, +uint32_t *payload) +{ +int ret; + +/* Device or IH ring is not ready so bail. */ + ret =amdgpu_ih_wait_on_checkpoint_process_ts (adev, &adev->irq.ih); +if (ret) +return ret; + +/* Send payload to fence KFD interrupts */ +amdgpu_amdkfd_interrupt (adev, payload); + +return 0 ; +} +bool amdgpu_amdkfd_ras_query_utcl2_poison_status (struct amdgpu_device *adev) {if (adev->gfx.ras && adev->gfx.ras->query_utcl2_poison_status)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-0@@ -236,6 +236,8 @@ int amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(struct amdgpu_device *dst,struct amdgpu_device *src, bool is_min);int amdgpu_amdkfd_get_pcie_bandwidth_mbytes (struct amdgpu_device *adev,bool is_min); +int amdgpu_amdkfd_send_close_event_drain_irq (struct amdgpu_device *adev, +uint32_t *payload);/* Read user wptr from a specified user address space with page fault * disabled. The memory must be pinned and mapped to the hardware when drivers/gpu/drm/amd/amdkfd/Makefile +1
-0@@ -53,6 +53,7 @@ AMDKFD_FILES := $(AMDKFD_PATH)/kfd_module.o \ $(AMDKFD_PATH)/kfd_events.o \ $(AMDKFD_PATH)/cik_event_interrupt.o \ $(AMDKFD_PATH)/kfd_int_process_v9.o \ + $(AMDKFD_PATH)/kfd_int_process_v10.o \ $(AMDKFD_PATH)/kfd_int_process_v11.o \ $(AMDKFD_PATH)/kfd_smi_events.o \ $(AMDKFD_PATH)/kfd_crat.o \drivers/gpu/drm/amd/amdkfd/kfd_debug.c +59
-0@@ -125,6 +125,65 @@ bool kfd_dbg_ev_raise(uint64_t event_mask,return is_subscribed; } +/* set pending event queue entry from ring entry */ +bool kfd_set_dbg_ev_from_interrupt (struct kfd_dev *dev, +unsigned int pasid, +uint32_t doorbell_id, +uint64_t trap_mask, +void *exception_data, +size_t exception_data_size) +{ +struct kfd_process *p; +bool signaled_to_debugger_or_runtime = false; + + p =kfd_lookup_process_by_pasid (pasid); + +if (!p) +return false; + +if (!kfd_dbg_ev_raise (trap_mask, p, dev, doorbell_id, true, + exception_data, exception_data_size)) { +struct process_queue_manager *pqm; +struct process_queue_node *pqn; + +if (!!(trap_mask &KFD_EC_MASK_QUEUE ) && + p->runtime_info.runtime_state ==DEBUG_RUNTIME_STATE_ENABLED ) { +mutex_lock (&p->mutex); + + pqm = &p->pqm; +list_for_each_entry (pqn, &pqm->queues, + process_queue_list) { + +if (!(pqn->q && pqn->q->device == dev && + pqn->q->doorbell_id == doorbell_id)) +continue ; + +kfd_send_exception_to_runtime (p, + pqn->q->properties.queue_id, + trap_mask); + + signaled_to_debugger_or_runtime = true; + +break ; + } + +mutex_unlock (&p->mutex); + }else if (trap_mask &KFD_EC_MASK (EC_DEVICE_MEMORY_VIOLATION )) { +kfd_dqm_evict_pasid (dev->dqm, p->pasid); +kfd_signal_vm_fault_event (dev, p->pasid,NULL , + exception_data); + + signaled_to_debugger_or_runtime = true; + } + }else { + signaled_to_debugger_or_runtime = true; + } + +kfd_unref_process (p); + +return signaled_to_debugger_or_runtime; +} + int kfd_dbg_send_exception_to_runtime(struct kfd_process *p, unsigned int dev_id, unsigned int queue_id,drivers/gpu/drm/amd/amdkfd/kfd_debug.h +6
-0@@ -30,6 +30,12 @@ void kgd_gfx_v9_set_wave_launch_stall(struct amdgpu_device *adev, bool stall);void kfd_dbg_trap_deactivate (struct kfd_process *target,bool unwind,int unwind_count);int kfd_dbg_trap_activate (struct kfd_process *target); +bool kfd_set_dbg_ev_from_interrupt (struct kfd_dev *dev, +unsigned int pasid, +uint32_t doorbell_id, +uint64_t trap_mask, +void *exception_data, +size_t exception_data_size); bool kfd_dbg_ev_raise(uint64_t event_mask, struct kfd_process *process, struct kfd_dev *dev, unsigned int source_id, bool use_worker,drivers/gpu/drm/amd/amdkfd/kfd_device.c +3
-1@@ -133,6 +133,8 @@ static void kfd_device_info_set_event_interrupt_class(struct kfd_dev *kfd)case IP_VERSION (9 ,4 ,0 ):/* VEGA20 */ case IP_VERSION (9 ,4 ,1 ):/* ARCTURUS */ case IP_VERSION (9 ,4 ,2 ):/* ALDEBARAN */ + kfd->device_info.event_interrupt_class = &event_interrupt_class_v9; +break ;case IP_VERSION (10 ,3 ,1 ):/* VANGOGH */ case IP_VERSION (10 ,3 ,3 ):/* YELLOW_CARP */ case IP_VERSION (10 ,3 ,6 ):/* GC 10.3.6 */ @@ -146,7 +148,7 @@ static void kfd_device_info_set_event_interrupt_class(struct kfd_dev *kfd)case IP_VERSION (10 ,3 ,2 ):/* NAVY_FLOUNDER */ case IP_VERSION (10 ,3 ,4 ):/* DIMGREY_CAVEFISH */ case IP_VERSION (10 ,3 ,5 ):/* BEIGE_GOBY */ - kfd->device_info.event_interrupt_class = &event_interrupt_class_v9; + kfd->device_info.event_interrupt_class = &event_interrupt_class_v10;break ;case IP_VERSION (11 ,0 ,0 ):case IP_VERSION (11 ,0 ,1 ):drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c new file +402
-0@@ -0,0 +1,402 @@ +/* +* Copyright 2022 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "kfd_events.h" +#include "kfd_debug.h" +#include "soc15_int.h" +#include "kfd_device_queue_manager.h" + +/* +* GFX10 SQ Interrupts +* +* There are 3 encoding types of interrupts sourced from SQ sent as a 44-bit +* packet to the Interrupt Handler: +* Auto - Generated by the SQG (various cmd overflows, timestamps etc) +* Wave - Generated by S_SENDMSG through a shader program +* Error - HW generated errors (Illegal instructions, Memviols, EDC etc) +* +* The 44-bit packet is mapped as {context_id1[7:0],context_id0[31:0]} plus +* 4-bits for VMID (SOC15_VMID_FROM_IH_ENTRY) as such: +* +* - context_id1[7:6] +* Encoding type (0 = Auto, 1 = Wave, 2 = Error) +* +* - context_id0[24] +* PRIV bit indicates that Wave S_SEND or error occurred within trap +* +* - context_id0[22:0] +* 23-bit data with the following layout per encoding type: +* Auto - only context_id0[8:0] is used, which reports various interrupts +* generated by SQG. The rest is 0. +* Wave - user data sent from m0 via S_SENDMSG +* Error - Error type (context_id0[22:19]), Error Details (rest of bits) +* +* The other context_id bits show coordinates (SE/SH/CU/SIMD/WGP) for wave +* S_SENDMSG and Errors. These are 0 for Auto. +*/ + +enum SQ_INTERRUPT_WORD_ENCODING { +SQ_INTERRUPT_WORD_ENCODING_AUTO =0x0 , +SQ_INTERRUPT_WORD_ENCODING_INST , +SQ_INTERRUPT_WORD_ENCODING_ERROR , +}; + +enum SQ_INTERRUPT_ERROR_TYPE { +SQ_INTERRUPT_ERROR_TYPE_EDC_FUE =0x0 , +SQ_INTERRUPT_ERROR_TYPE_ILLEGAL_INST , +SQ_INTERRUPT_ERROR_TYPE_MEMVIOL , +SQ_INTERRUPT_ERROR_TYPE_EDC_FED , +}; + +/* SQ_INTERRUPT_WORD_AUTO_CTXID */ +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE__SHIFT 0 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__WLT__SHIFT 1 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE_BUF0_FULL__SHIFT 2 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE_BUF1_FULL__SHIFT 3 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE_UTC_ERROR__SHIFT 7 +#define SQ_INTERRUPT_WORD_AUTO_CTXID1__SE_ID__SHIFT 4 +#define SQ_INTERRUPT_WORD_AUTO_CTXID1__ENCODING__SHIFT 6 + +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE_MASK 0x00000001 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__WLT_MASK 0x00000002 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE_BUF0_FULL_MASK 0x00000004 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE_BUF1_FULL_MASK 0x00000008 +#define SQ_INTERRUPT_WORD_AUTO_CTXID0__THREAD_TRACE_UTC_ERROR_MASK 0x00000080 +#define SQ_INTERRUPT_WORD_AUTO_CTXID1__SE_ID_MASK 0x030 +#define SQ_INTERRUPT_WORD_AUTO_CTXID1__ENCODING_MASK 0x0c0 + +/* SQ_INTERRUPT_WORD_WAVE_CTXID */ +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__DATA__SHIFT 0 +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__SA_ID__SHIFT 23 +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__PRIV__SHIFT 24 +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__WAVE_ID__SHIFT 25 +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__SIMD_ID__SHIFT 30 +#define SQ_INTERRUPT_WORD_WAVE_CTXID1__WGP_ID__SHIFT 0 +#define SQ_INTERRUPT_WORD_WAVE_CTXID1__SE_ID__SHIFT 4 +#define SQ_INTERRUPT_WORD_WAVE_CTXID1__ENCODING__SHIFT 6 + +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__DATA_MASK 0x000007fffff +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__SA_ID_MASK 0x0000800000 +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__PRIV_MASK 0x00001000000 +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__WAVE_ID_MASK 0x0003e000000 +#define SQ_INTERRUPT_WORD_WAVE_CTXID0__SIMD_ID_MASK 0x000c0000000 +#define SQ_INTERRUPT_WORD_WAVE_CTXID1__WGP_ID_MASK 0x00f +#define SQ_INTERRUPT_WORD_WAVE_CTXID1__SE_ID_MASK 0x030 +#define SQ_INTERRUPT_WORD_WAVE_CTXID1__ENCODING_MASK 0x0c0 + +#define KFD_CTXID0__ERR_TYPE_MASK 0x780000 +#define KFD_CTXID0__ERR_TYPE__SHIFT 19 + +/* GFX10 SQ interrupt ENC type bit (context_id1[7:6]) for wave s_sendmsg */ +#define KFD_CONTEXT_ID1_ENC_TYPE_WAVE_MASK 0x40 +/* GFX10 SQ interrupt PRIV bit (context_id0[24]) for s_sendmsg inside trap */ +#define KFD_CONTEXT_ID0_PRIV_MASK 0x1000000 +/* +* The debugger will send user data(m0) with PRIV=1 to indicate it requires +* notification from the KFD with the following queue id (DOORBELL_ID) and +* trap code (TRAP_CODE). +*/ +#define KFD_CONTEXT_ID0_DEBUG_DOORBELL_MASK 0x0003ff +#define KFD_CONTEXT_ID0_DEBUG_TRAP_CODE_SHIFT 10 +#define KFD_CONTEXT_ID0_DEBUG_TRAP_CODE_MASK 0x07fc00 +#define KFD_DEBUG_DOORBELL_ID (ctxid0) ((ctxid0) & \ + KFD_CONTEXT_ID0_DEBUG_DOORBELL_MASK) +#define KFD_DEBUG_TRAP_CODE (ctxid0) (((ctxid0) & \ + KFD_CONTEXT_ID0_DEBUG_TRAP_CODE_MASK) \ + >> KFD_CONTEXT_ID0_DEBUG_TRAP_CODE_SHIFT) +#define KFD_DEBUG_CP_BAD_OP_ECODE (ctxid0) (((ctxid0) & 0x3ffffff) \ + >> KFD_CONTEXT_ID0_DEBUG_TRAP_CODE_SHIFT) + +static void event_interrupt_poison_consumption (struct kfd_dev *dev, +uint16_t pasid,uint16_t client_id) +{ +int old_poison, ret = -EINVAL ; +struct kfd_process *p =kfd_lookup_process_by_pasid (pasid); + +if (!p) +return ; + +/* all queues of a process will be unmapped in one time */ + old_poison =atomic_cmpxchg (&p->poison,0 ,1 ); +kfd_unref_process (p); +if (old_poison) +return ; + +switch (client_id) { +case SOC15_IH_CLIENTID_SE0SH : +case SOC15_IH_CLIENTID_SE1SH : +case SOC15_IH_CLIENTID_SE2SH : +case SOC15_IH_CLIENTID_SE3SH : +case SOC15_IH_CLIENTID_UTCL2 : + ret =kfd_dqm_evict_pasid (dev->dqm, pasid); +break ; +case SOC15_IH_CLIENTID_SDMA0 : +case SOC15_IH_CLIENTID_SDMA1 : +case SOC15_IH_CLIENTID_SDMA2 : +case SOC15_IH_CLIENTID_SDMA3 : +case SOC15_IH_CLIENTID_SDMA4 : +break ; +default : +break ; + } + +kfd_signal_poison_consumed_event (dev, pasid); + +/* resetting queue passes, do page retirement without gpu reset +* resetting queue fails, fallback to gpu reset solution +*/ +if (!ret) { +dev_warn (dev->adev->dev, +"RAS poison consumption, unmap queue flow succeeded: client id %d\n" , + client_id); +amdgpu_amdkfd_ras_poison_consumption_handler (dev->adev, false); + }else { +dev_warn (dev->adev->dev, +"RAS poison consumption, fall back to gpu reset flow: client id %d\n" , + client_id); +amdgpu_amdkfd_ras_poison_consumption_handler (dev->adev, true); + } +} + +static bool event_interrupt_isr_v10 (struct kfd_dev *dev, +const uint32_t *ih_ring_entry, +uint32_t *patched_ihre, +bool *patched_flag) +{ +uint16_t source_id, client_id, pasid, vmid; +const uint32_t *data = ih_ring_entry; + + source_id =SOC15_SOURCE_ID_FROM_IH_ENTRY (ih_ring_entry); + client_id =SOC15_CLIENT_ID_FROM_IH_ENTRY (ih_ring_entry); + +/* Only handle interrupts from KFD VMIDs */ + vmid =SOC15_VMID_FROM_IH_ENTRY (ih_ring_entry); +if (!KFD_IRQ_IS_FENCE (client_id, source_id) && + (vmid < dev->vm_info.first_vmid_kfd || + vmid > dev->vm_info.last_vmid_kfd)) +return false; + + pasid =SOC15_PASID_FROM_IH_ENTRY (ih_ring_entry); + +/* Only handle clients we care about */ +if (client_id !=SOC15_IH_CLIENTID_GRBM_CP && + client_id !=SOC15_IH_CLIENTID_SDMA0 && + client_id !=SOC15_IH_CLIENTID_SDMA1 && + client_id !=SOC15_IH_CLIENTID_SDMA2 && + client_id !=SOC15_IH_CLIENTID_SDMA3 && + client_id !=SOC15_IH_CLIENTID_SDMA4 && + client_id !=SOC15_IH_CLIENTID_SDMA5 && + client_id !=SOC15_IH_CLIENTID_SDMA6 && + client_id !=SOC15_IH_CLIENTID_SDMA7 && + client_id !=SOC15_IH_CLIENTID_VMC && + client_id !=SOC15_IH_CLIENTID_VMC1 && + client_id !=SOC15_IH_CLIENTID_UTCL2 && + client_id !=SOC15_IH_CLIENTID_SE0SH && + client_id !=SOC15_IH_CLIENTID_SE1SH && + client_id !=SOC15_IH_CLIENTID_SE2SH && + client_id !=SOC15_IH_CLIENTID_SE3SH ) +return false; + +pr_debug ("client id 0x%x, source id %d, vmid %d, pasid 0x%x. raw data:\n" , + client_id, source_id, vmid, pasid); +pr_debug ("%8X, %8X, %8X, %8X, %8X, %8X, %8X, %8X.\n" , + data[0 ], data[1 ], data[2 ], data[3 ], + data[4 ], data[5 ], data[6 ], data[7 ]); + +/* If there is no valid PASID, it's likely a bug */ +if (WARN_ONCE (pasid ==0 ,"Bug: No PASID in KFD interrupt" )) +return 0 ; + +/* Interrupt types we care about: various signals and faults. +* They will be forwarded to a work queue (see below). +*/ +return source_id ==SOC15_INTSRC_CP_END_OF_PIPE || + source_id ==SOC15_INTSRC_SDMA_TRAP || + source_id ==SOC15_INTSRC_SQ_INTERRUPT_MSG || + source_id ==SOC15_INTSRC_CP_BAD_OPCODE || + client_id ==SOC15_IH_CLIENTID_VMC || + client_id ==SOC15_IH_CLIENTID_VMC1 || + client_id ==SOC15_IH_CLIENTID_UTCL2 || +KFD_IRQ_IS_FENCE (client_id, source_id); +} + +static void event_interrupt_wq_v10 (struct kfd_dev *dev, +const uint32_t *ih_ring_entry) +{ +uint16_t source_id, client_id, pasid, vmid; +uint32_t context_id0, context_id1; +uint32_t encoding, sq_intr_err_type; + + source_id =SOC15_SOURCE_ID_FROM_IH_ENTRY (ih_ring_entry); + client_id =SOC15_CLIENT_ID_FROM_IH_ENTRY (ih_ring_entry); + pasid =SOC15_PASID_FROM_IH_ENTRY (ih_ring_entry); + vmid =SOC15_VMID_FROM_IH_ENTRY (ih_ring_entry); + context_id0 =SOC15_CONTEXT_ID0_FROM_IH_ENTRY (ih_ring_entry); + context_id1 =SOC15_CONTEXT_ID1_FROM_IH_ENTRY (ih_ring_entry); + +if (client_id ==SOC15_IH_CLIENTID_GRBM_CP || + client_id ==SOC15_IH_CLIENTID_SE0SH || + client_id ==SOC15_IH_CLIENTID_SE1SH || + client_id ==SOC15_IH_CLIENTID_SE2SH || + client_id ==SOC15_IH_CLIENTID_SE3SH ) { +if (source_id ==SOC15_INTSRC_CP_END_OF_PIPE ) +kfd_signal_event_interrupt (pasid, context_id0,32 ); +else if (source_id ==SOC15_INTSRC_SQ_INTERRUPT_MSG ) { + encoding =REG_GET_FIELD (context_id1, +SQ_INTERRUPT_WORD_WAVE_CTXID1 ,ENCODING ); +switch (encoding) { +case SQ_INTERRUPT_WORD_ENCODING_AUTO : +pr_debug ( +"sq_intr: auto, se %d, ttrace %d, wlt %d, ttrac_buf0_full %d, ttrac_buf1_full %d, ttrace_utc_err %d\n" , +REG_GET_FIELD (context_id1,SQ_INTERRUPT_WORD_AUTO_CTXID1 , +SE_ID ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_AUTO_CTXID0 , +THREAD_TRACE ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_AUTO_CTXID0 , +WLT ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_AUTO_CTXID0 , +THREAD_TRACE_BUF0_FULL ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_AUTO_CTXID0 , +THREAD_TRACE_BUF1_FULL ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_AUTO_CTXID0 , +THREAD_TRACE_UTC_ERROR )); +break ; +case SQ_INTERRUPT_WORD_ENCODING_INST : +pr_debug ("sq_intr: inst, se %d, data 0x%x, sa %d, priv %d, wave_id %d, simd_id %d, wgp_id %d\n" , +REG_GET_FIELD (context_id1,SQ_INTERRUPT_WORD_WAVE_CTXID1 , +SE_ID ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +DATA ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +SA_ID ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +PRIV ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +WAVE_ID ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +SIMD_ID ), +REG_GET_FIELD (context_id1,SQ_INTERRUPT_WORD_WAVE_CTXID1 , +WGP_ID )); +if (context_id0 &SQ_INTERRUPT_WORD_WAVE_CTXID0__PRIV_MASK ) { +if (kfd_set_dbg_ev_from_interrupt (dev, pasid, +KFD_DEBUG_DOORBELL_ID (context_id0), +KFD_DEBUG_TRAP_CODE (context_id0), +NULL ,0 )) +return ; + } +break ; +case SQ_INTERRUPT_WORD_ENCODING_ERROR : + sq_intr_err_type =REG_GET_FIELD (context_id0,KFD_CTXID0 , +ERR_TYPE ); +pr_warn ("sq_intr: error, se %d, data 0x%x, sa %d, priv %d, wave_id %d, simd_id %d, wgp_id %d, err_type %d\n" , +REG_GET_FIELD (context_id1,SQ_INTERRUPT_WORD_WAVE_CTXID1 , +SE_ID ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +DATA ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +SA_ID ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +PRIV ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +WAVE_ID ), +REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID0 , +SIMD_ID ), +REG_GET_FIELD (context_id1,SQ_INTERRUPT_WORD_WAVE_CTXID1 , +WGP_ID ), + sq_intr_err_type); +if (sq_intr_err_type !=SQ_INTERRUPT_ERROR_TYPE_ILLEGAL_INST && + sq_intr_err_type !=SQ_INTERRUPT_ERROR_TYPE_MEMVIOL ) { +event_interrupt_poison_consumption (dev, pasid, source_id); +return ; + } +break ; +default : +break ; + } +kfd_signal_event_interrupt (pasid, context_id0 &0x7fffff ,23 ); + }else if (source_id ==SOC15_INTSRC_CP_BAD_OPCODE ) { +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)), +NULL , +0 ); + } + }else if (client_id ==SOC15_IH_CLIENTID_SDMA0 || + client_id ==SOC15_IH_CLIENTID_SDMA1 || + client_id ==SOC15_IH_CLIENTID_SDMA2 || + client_id ==SOC15_IH_CLIENTID_SDMA3 || + (client_id == SOC15_IH_CLIENTID_SDMA3_Sienna_Cichlid && +KFD_GC_VERSION (dev) ==IP_VERSION (10 ,3 ,0 )) || + client_id ==SOC15_IH_CLIENTID_SDMA4 || + client_id ==SOC15_IH_CLIENTID_SDMA5 || + client_id ==SOC15_IH_CLIENTID_SDMA6 || + client_id ==SOC15_IH_CLIENTID_SDMA7 ) { +if (source_id ==SOC15_INTSRC_SDMA_TRAP ) { +kfd_signal_event_interrupt (pasid, context_id0 &0xfffffff ,28 ); + }else if (source_id ==SOC15_INTSRC_SDMA_ECC ) { +event_interrupt_poison_consumption (dev, pasid, source_id); +return ; + } + }else if (client_id ==SOC15_IH_CLIENTID_VMC || + client_id ==SOC15_IH_CLIENTID_VMC1 || + client_id ==SOC15_IH_CLIENTID_UTCL2 ) { +struct kfd_vm_fault_info info = {0 }; +uint16_t ring_id =SOC15_RING_ID_FROM_IH_ENTRY (ih_ring_entry); +struct kfd_hsa_memory_exception_data exception_data; + +if (client_id ==SOC15_IH_CLIENTID_UTCL2 && +amdgpu_amdkfd_ras_query_utcl2_poison_status (dev->adev)) { +event_interrupt_poison_consumption (dev, pasid, client_id); +return ; + } + + info.vmid = vmid; + info.mc_id = client_id; + info.page_addr = ih_ring_entry[4 ] | + (uint64_t )(ih_ring_entry[5 ] &0xf ) <<32 ; + info.prot_valid = ring_id &0x08 ; + info.prot_read = ring_id &0x10 ; + info.prot_write = ring_id &0x20 ; + +memset (&exception_data,0 ,sizeof (exception_data)); + exception_data.gpu_id = dev->id; + exception_data.va = (info.page_addr) <<PAGE_SHIFT ; + exception_data.failure.NotPresent = info.prot_valid ?1 :0 ; + exception_data.failure.NoExecute = info.prot_exec ?1 :0 ; + exception_data.failure.ReadOnly = info.prot_write ?1 :0 ; + exception_data.failure.imprecise =0 ; + +kfd_set_dbg_ev_from_interrupt (dev, + pasid, +-1 , +KFD_EC_MASK (EC_DEVICE_MEMORY_VIOLATION ), + &exception_data, +sizeof (exception_data)); + }else if (KFD_IRQ_IS_FENCE (client_id, source_id)) { +kfd_process_close_interrupt_drain (pasid); + } +} + +const struct kfd_event_interrupt_class event_interrupt_class_v10 = { + .interrupt_isr = event_interrupt_isr_v10, + .interrupt_wq = event_interrupt_wq_v10, +};drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +31
-0@@ -23,10 +23,40 @@#include "kfd_priv.h" #include "kfd_events.h" +#include "kfd_debug.h" #include "soc15_int.h" #include "kfd_device_queue_manager.h" #include "kfd_smi_events.h" +/* +* GFX9 SQ Interrupts +* +* There are 3 encoding types of interrupts sourced from SQ sent as a 44-bit +* packet to the Interrupt Handler: +* Auto - Generated by the SQG (various cmd overflows, timestamps etc) +* Wave - Generated by S_SENDMSG through a shader program +* Error - HW generated errors (Illegal instructions, Memviols, EDC etc) +* +* The 44-bit packet is mapped as {context_id1[7:0],context_id0[31:0]} plus +* 4-bits for VMID (SOC15_VMID_FROM_IH_ENTRY) as such: +* +* - context_id0[27:26] +* Encoding type (0 = Auto, 1 = Wave, 2 = Error) +* +* - context_id0[13] +* PRIV bit indicates that Wave S_SEND or error occurred within trap +* +* - {context_id1[7:0],context_id0[31:28],context_id0[11:0]} +* 24-bit data with the following layout per encoding type: +* Auto - only context_id0[8:0] is used, which reports various interrupts +* generated by SQG. The rest is 0. +* Wave - user data sent from m0 via S_SENDMSG +* Error - Error type (context_id1[7:4]), Error Details (rest of bits) +* +* The other context_id bits show coordinates (SE/SH/CU/SIMD/WAVE) for wave +* S_SENDMSG and Errors. These are 0 for Auto. +*/ +enum SQ_INTERRUPT_WORD_ENCODING {SQ_INTERRUPT_WORD_ENCODING_AUTO =0x0 ,SQ_INTERRUPT_WORD_ENCODING_INST ,@@ -84,12 +114,29 @@ enum SQ_INTERRUPT_ERROR_TYPE {#define SQ_INTERRUPT_WORD_WAVE_CTXID__SE_ID_MASK 0x03000000#define SQ_INTERRUPT_WORD_WAVE_CTXID__ENCODING_MASK 0x0c000000 +/* GFX9 SQ interrupt 24-bit data from context_id<0,1> */ #define KFD_CONTEXT_ID_GET_SQ_INT_DATA (ctx0, ctx1) \ ((ctx0 & 0xfff) | ((ctx0 >> 16) & 0xf000) | ((ctx1 << 16) & 0xff0000))
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c enum SQ_INTERRUPT_ERROR_TYPE { · line 130
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +7
-0#define KFD_SQ_INT_DATA__ERR_TYPE_MASK 0xF00000#define KFD_SQ_INT_DATA__ERR_TYPE__SHIFT 20 +/* +* The debugger will send user data(m0) with PRIV=1 to indicate it requires +* notification from the KFD with the following queue id (DOORBELL_ID) and +* trap code (TRAP_CODE). +*/ +#define KFD_SQ_INT_DATA_DEBUG_DOORBELL_MASK 0x0003ff +#define KFD_SQ_INT_DATA_DEBUG_TRAP_CODE_SHIFT 10
The doorbell mask and trap-code shift are not SQ-specific. They are also used for CP interrupts. So they should not have SQ in the name.
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c enum SQ_INTERRUPT_ERROR_TYPE { · line 138
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +8
-0+#define KFD_SQ_INT_DATA_DEBUG_TRAP_CODE_MASK 0x07fc00 +#define KFD_DEBUG_DOORBELL_ID (sq_int_data) ((sq_int_data) & \ + KFD_SQ_INT_DATA_DEBUG_DOORBELL_MASK) +#define KFD_DEBUG_TRAP_CODE (sq_int_data) (((sq_int_data) & \ + KFD_SQ_INT_DATA_DEBUG_TRAP_CODE_MASK) \ + >> KFD_SQ_INT_DATA_DEBUG_TRAP_CODE_SHIFT) +#define KFD_DEBUG_CP_BAD_OP_ECODE (ctxid0) (((ctxid0) & 0x3ffffff) \ + >> KFD_SQ_INT_DATA_DEBUG_TRAP_CODE_SHIFT)
The mask should not be hard-coded here. It should be defined as another #define KFD_CP_BAD_OP_ECODE_MASK. It's also misleading that the mask includes low bits that then get shifted out to the right.
The same applies to kfd_int_process_v10.c.
Quoted 181 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +40
-9+static void event_interrupt_poison_consumption_v9 (struct kfd_dev *dev,uint16_t pasid,uint16_t client_id) {@@ -168,14 +215,16 @@ static bool event_interrupt_isr_v9(struct kfd_dev *dev,uint16_t source_id, client_id, pasid, vmid;const uint32_t *data = ih_ring_entry; + source_id =SOC15_SOURCE_ID_FROM_IH_ENTRY (ih_ring_entry); + client_id =SOC15_CLIENT_ID_FROM_IH_ENTRY (ih_ring_entry); +/* Only handle interrupts from KFD VMIDs */ vmid =SOC15_VMID_FROM_IH_ENTRY (ih_ring_entry); -if (vmid < dev->vm_info.first_vmid_kfd || - vmid > dev->vm_info.last_vmid_kfd) +if (!KFD_IRQ_IS_FENCE (client_id, source_id) && + (vmid < dev->vm_info.first_vmid_kfd || + vmid > dev->vm_info.last_vmid_kfd))return false; - source_id =SOC15_SOURCE_ID_FROM_IH_ENTRY (ih_ring_entry); - client_id =SOC15_CLIENT_ID_FROM_IH_ENTRY (ih_ring_entry); pasid =SOC15_PASID_FROM_IH_ENTRY (ih_ring_entry);/* Only handle clients we care about */ @@ -194,7 +243,8 @@ static bool event_interrupt_isr_v9(struct kfd_dev *dev, client_id !=SOC15_IH_CLIENTID_SE0SH && client_id !=SOC15_IH_CLIENTID_SE1SH && client_id !=SOC15_IH_CLIENTID_SE2SH && - client_id != SOC15_IH_CLIENTID_SE3SH) + client_id !=SOC15_IH_CLIENTID_SE3SH && + !KFD_IRQ_IS_FENCE(client_id, source_id)) return false;/* This is a known issue for gfx9. Under non HWS, pasid is not set @@ -247,6 +297,7 @@ static bool event_interrupt_isr_v9(struct kfd_dev *dev, source_id ==SOC15_INTSRC_SDMA_ECC || source_id ==SOC15_INTSRC_SQ_INTERRUPT_MSG || source_id ==SOC15_INTSRC_CP_BAD_OPCODE || + KFD_IRQ_IS_FENCE(client_id, source_id) || ((client_id == SOC15_IH_CLIENTID_VMC || client_id == SOC15_IH_CLIENTID_VMC1 || client_id == SOC15_IH_CLIENTID_UTCL2) &&@@ -302,6 +353,13 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID ,SIMD_ID ),REG_GET_FIELD (context_id0,SQ_INTERRUPT_WORD_WAVE_CTXID ,CU_ID ), sq_int_data); +if (context_id0 &SQ_INTERRUPT_WORD_WAVE_CTXID__PRIV_MASK ) { +if (kfd_set_dbg_ev_from_interrupt (dev, pasid, +KFD_DEBUG_DOORBELL_ID (sq_int_data), +KFD_DEBUG_TRAP_CODE (sq_int_data), +NULL ,0 )) +return ; + }break ;case SQ_INTERRUPT_WORD_ENCODING_ERROR : sq_intr_err =REG_GET_FIELD (sq_int_data,KFD_SQ_INT_DATA ,ERR_TYPE );@@ -324,8 +382,12 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev,break ; }kfd_signal_event_interrupt (pasid, context_id0 &0xffffff ,24 ); - }else if (source_id ==SOC15_INTSRC_CP_BAD_OPCODE ) -kfd_signal_hw_exception_event (pasid); + }else if (source_id ==SOC15_INTSRC_CP_BAD_OPCODE ) { +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)), +NULL ,0 ); + } } else if (client_id == SOC15_IH_CLIENTID_SDMA0 || client_id == SOC15_IH_CLIENTID_SDMA1 || client_id == SOC15_IH_CLIENTID_SDMA2 ||@@ -345,6 +407,7 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev, client_id == SOC15_IH_CLIENTID_UTCL2) {struct kfd_vm_fault_info info = {0 };uint16_t ring_id =SOC15_RING_ID_FROM_IH_ENTRY (ih_ring_entry); +struct kfd_hsa_memory_exception_data exception_data;if (client_id ==SOC15_IH_CLIENTID_UTCL2 &&amdgpu_amdkfd_ras_query_utcl2_poison_status (dev->adev)) {@@ -360,9 +423,23 @@ static void event_interrupt_wq_v9(struct kfd_dev *dev, info.prot_read = ring_id &0x10 ; info.prot_write = ring_id &0x20 ; +memset (&exception_data,0 ,sizeof (exception_data)); + exception_data.gpu_id = dev->id; + exception_data.va = (info.page_addr) <<PAGE_SHIFT ; + exception_data.failure.NotPresent = info.prot_valid ?1 :0 ; + exception_data.failure.NoExecute = info.prot_exec ?1 :0 ; + exception_data.failure.ReadOnly = info.prot_write ?1 :0 ; + exception_data.failure.imprecise =0 ; + +kfd_set_dbg_ev_from_interrupt (dev, + pasid, +-1 , +KFD_EC_MASK (EC_DEVICE_MEMORY_VIOLATION ), + &exception_data, +sizeof (exception_data));kfd_smi_event_update_vmfault (dev, pasid); -kfd_dqm_evict_pasid (dev->dqm, pasid); -kfd_signal_vm_fault_event (dev, pasid, &info,NULL ); + }else if (KFD_IRQ_IS_FENCE (client_id, source_id)) { +kfd_process_close_interrupt_drain (pasid); } }drivers/gpu/drm/amd/amdkfd/kfd_priv.h +12
-0@@ -926,6 +926,10 @@ struct kfd_process {uint64_t exception_enable_mask;uint64_t exception_status; +/* Used to drain stale interrupts */ +wait_queue_head_t wait_irq_drain; +bool irq_drain_is_open; +/* shared virtual memory registered by this process */ struct svm_range_list svms;@@ -1088,12 +1092,19 @@ int kfd_numa_node_to_apic_id(int numa_node_id);void kfd_double_confirm_iommu_support (struct kfd_dev *gpu);/* Interrupts */ +#define KFD_IRQ_FENCE_CLIENTID 0xff +#define KFD_IRQ_FENCE_SOURCEID 0xff +#define KFD_IRQ_IS_FENCE (client, source) \ + ((client) == KFD_IRQ_FENCE_CLIENTID && \ + (source) == KFD_IRQ_FENCE_SOURCEID)int kfd_interrupt_init (struct kfd_dev *dev);void kfd_interrupt_exit (struct kfd_dev *dev);bool enqueue_ih_ring_entry (struct kfd_dev *kfd,const void *ih_ring_entry);bool interrupt_is_wanted (struct kfd_dev *dev,const uint32_t *ih_ring_entry,uint32_t *patched_ihre,bool *flag); +void kfd_process_drain_interrupts (struct kfd_process_device *pdd); +void kfd_process_close_interrupt_drain (unsigned int pasid);/* amdkfd Apertures */ int kfd_init_apertures (struct kfd_process *process);@@ -1365,6 +1376,7 @@ uint64_t kfd_get_number_elems(struct kfd_dev *kfd);/* Events */ extern const struct kfd_event_interrupt_class event_interrupt_class_cik;extern const struct kfd_event_interrupt_class event_interrupt_class_v9; +extern const struct kfd_event_interrupt_class event_interrupt_class_v10;extern const struct kfd_event_interrupt_class event_interrupt_class_v11;extern const struct kfd_device_global_init_class device_global_init_class_cik;drivers/gpu/drm/amd/amdkfd/kfd_process.c +17
-0@@ -856,6 +856,8 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)kfd_procfs_add_sysfs_stats (process);kfd_procfs_add_sysfs_files (process);kfd_procfs_add_sysfs_counters (process); + +init_waitqueue_head (&process->wait_irq_drain); } out:if (!IS_ERR (process))@@ -2068,6 +2070,47 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type) } } +/* assumes caller holds process lock. */ +void kfd_process_drain_interrupts (struct kfd_process_device *pdd) +{ +uint32_t irq_drain_fence[8 ]; + +if (!KFD_IS_SOC15 (pdd->dev)) +return ; + + pdd->process->irq_drain_is_open = true; + +memset (irq_drain_fence,0 ,sizeof (irq_drain_fence)); + irq_drain_fence[0 ] = (KFD_IRQ_FENCE_SOURCEID <<8 ) | +KFD_IRQ_FENCE_CLIENTID ; + irq_drain_fence[3 ] = pdd->process->pasid; +
drivers/gpu/drm/amd/amdkfd/kfd_process.c void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type) · line 2097
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +10
-0+/* ensure stale irqs scheduled KFD interrupts and send drain fence. */ +if (amdgpu_amdkfd_send_close_event_drain_irq (pdd->dev->adev, + irq_drain_fence)) { + pdd->process->irq_drain_is_open = false; +return ; + } + +if (wait_event_interruptible (pdd->process->wait_irq_drain, + !READ_ONCE (pdd->process->irq_drain_is_open))) + pdd->process->irq_drain_is_open = false;
I believe we only get into this if-block, if wait_event_interruptible returns -ERESTARTSYS. This happens when the ioctl gets interrupted to process a user mode signal. I think we should pass that error code back up to the caller. See below.
Quoted 24 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +16
-0+} + +void kfd_process_close_interrupt_drain (unsigned int pasid) +{ +struct kfd_process *p; + + p =kfd_lookup_process_by_pasid (pasid); + +if (!p) +return ; + +WRITE_ONCE (p->irq_drain_is_open, false); +wake_up_all (&p->wait_irq_drain); +kfd_unref_process (p); +} +struct send_exception_work_handler_workarea {struct work_struct work;struct kfd_process *p;drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_create_queue(struct process_queue_manager *pqm, · line 333
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1
-0@@ -330,6 +330,7 @@ int pqm_create_queue(struct process_queue_manager *pqm, kq->queue->properties.queue_id = *qid; pqn->kq = kq; pqn->q =NULL ; +kfd_process_drain_interrupts (pdd);
If draining got interrupted by a signal, we should set retval to the error code (-ERESTARTSYS) and break here. When the ioctl gets restarted, we'll retry the drain.
Regards,
Felix
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0
-0retval = dev->dqm->ops.create_kernel_queue (dev->dqm, kq, &pdd->qpd);break ;
PATCH 19/29 drm/amdkfd: add debug set exceptions enabled operation
In reply to Jonathan KimThe debugger subscibes to nofication for requested exceptions on attach. Allow the debugger to change its subsciption later on.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 ++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 36 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 2 ++ 3 files changed, 41 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -0
@@ -2856,6 +2856,9 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v args->send_runtime_event.exception_mask);break ;case KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED : +kfd_dbg_set_enabled_debug_exception_mask (target, + args->set_exceptions_enabled.exception_mask); +break ;case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE :case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE :case KFD_IOC_DBG_TRAP_SUSPEND_QUEUES :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +36 -0
@@ -415,3 +415,39 @@ int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,return r; } + +void kfd_dbg_set_enabled_debug_exception_mask (struct kfd_process *target, +uint64_t exception_set_mask) +{ +uint64_t found_mask =0 ; +struct process_queue_manager *pqm; +struct process_queue_node *pqn; +static const char write_data ='.' ; +loff_t pos =0 ; +int i; + +mutex_lock (&target->event_mutex); + + found_mask |= target->exception_status; + + pqm = &target->pqm; +list_for_each_entry (pqn, &pqm->queues, process_queue_list) { +if (!pqn) +continue ; + + found_mask |= pqn->q->properties.exception_status; + } + +for (i =0 ; i < target->n_pdds; i++) { +struct kfd_process_device *pdd = target->pdds[i]; + + found_mask |= pdd->exception_status; + } + +if (exception_set_mask & found_mask) +kernel_write (target->dbg_ev_file, &write_data,1 , &pos); + + target->exception_enable_mask = exception_set_mask; + +mutex_unlock (&target->event_mutex); +}
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2 -0
@@ -58,6 +58,8 @@ static inline bool kfd_dbg_is_per_vmid_supported(struct kfd_dev *dev)void debug_event_write_work_handler (struct work_struct *work); +void kfd_dbg_set_enabled_debug_exception_mask (struct kfd_process *target, +uint64_t exception_set_mask);/* * If GFX off is enabled, chips that do not support RLC restore for the debug * registers will disable GFX off temporarily for the entire debug session.
Signature · 1 line
2.25.1
PATCH 20/29 drm/amdkfd: add debug wave launch override operation
In reply to Jonathan KimThis operation allows the debugger to override the enabled HW exceptions on the device.
On debug devices that only support the debugging of a single process, the HW exceptions are global and set through the SPI_GDBG_TRAP_MASK register.
Because they are global, only address watch exceptions are allowed to be enabled. In other words, the debugger must preserve all non-address watch exception states in normal mode operation by barring a full replacement override or a non-address watch override request.
For multi-process debugging, all HW exception overrides are per-VMID so all exceptions can be overridden or fully replaced.
In order for the debugger to know what is permissible, returned the supported override mask back to the debugger along with the previously enable overrides.
--- .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c | 47 ++++++++++++++ .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 + .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 55 ++++++++++++++++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h | 10 +++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 5 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 55 ++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h | 10 +++ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 7 ++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 65 +++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 6 ++ 10 files changed, 261 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +47 -0
@@ -25,6 +25,7 @@#include "amdgpu_amdkfd_gfx_v9.h" #include "gc/gc_9_4_2_offset.h" #include "gc/gc_9_4_2_sh_mask.h" +#include <uapi/linux/kfd_ioctl.h> /* returns TRAP_EN, EXCP_EN and EXCP_REPLACE. */ static uint32_t kgd_aldebaran_enable_debug_trap(struct amdgpu_device *adev,
@@ -54,6 +55,50 @@ static uint32_t kgd_aldebaran_disable_debug_trap(struct amdgpu_device *adev,return data; } +static int kgd_aldebaran_validate_trap_override_request (struct amdgpu_device *adev, +uint32_t trap_override, +uint32_t *trap_mask_supported) +{ + *trap_mask_supported &=KFD_DBG_TRAP_MASK_FP_INVALID | +KFD_DBG_TRAP_MASK_FP_INPUT_DENORMAL | +KFD_DBG_TRAP_MASK_FP_DIVIDE_BY_ZERO | +KFD_DBG_TRAP_MASK_FP_OVERFLOW | +KFD_DBG_TRAP_MASK_FP_UNDERFLOW | +KFD_DBG_TRAP_MASK_FP_INEXACT | +KFD_DBG_TRAP_MASK_INT_DIVIDE_BY_ZERO | +KFD_DBG_TRAP_MASK_DBG_ADDRESS_WATCH | +KFD_DBG_TRAP_MASK_DBG_MEMORY_VIOLATION ; + +if (trap_override !=KFD_DBG_TRAP_OVERRIDE_OR && + trap_override !=KFD_DBG_TRAP_OVERRIDE_REPLACE ) +return -EPERM ; + +return 0 ; +} + +/* returns TRAP_EN, EXCP_EN and EXCP_RPLACE. */ +static uint32_t kgd_aldebaran_set_wave_launch_trap_override (struct amdgpu_device *adev, +uint32_t vmid, +uint32_t trap_override, +uint32_t trap_mask_bits, +uint32_t trap_mask_request, +uint32_t *trap_mask_prev, +uint32_t kfd_dbg_trap_cntl_prev) + +{ +uint32_t data =0 ; + + *trap_mask_prev =REG_GET_FIELD (kfd_dbg_trap_cntl_prev,SPI_GDBG_PER_VMID_CNTL ,EXCP_EN ); + trap_mask_bits = (trap_mask_bits & trap_mask_request) | + (*trap_mask_prev & ~trap_mask_request); + + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,TRAP_EN ,1 ); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,EXCP_EN , trap_mask_bits); + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,EXCP_REPLACE , trap_override); + +return data; +} +const struct kfd2kgd_calls aldebaran_kfd2kgd = { .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings, .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
@@ -73,6 +118,8 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = { .set_vm_context_page_table_base = kgd_gfx_v9_set_vm_context_page_table_base, .enable_debug_trap = kgd_aldebaran_enable_debug_trap, .disable_debug_trap = kgd_aldebaran_disable_debug_trap, + .validate_trap_override_request = kgd_aldebaran_validate_trap_override_request, + .set_wave_launch_trap_override = kgd_aldebaran_set_wave_launch_trap_override, .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +2 -0
@@ -397,6 +397,8 @@ const struct kfd2kgd_calls arcturus_kfd2kgd = { kgd_gfx_v9_set_vm_context_page_table_base, .enable_debug_trap = kgd_arcturus_enable_debug_trap, .disable_debug_trap = kgd_arcturus_disable_debug_trap, + .validate_trap_override_request = kgd_gfx_v9_validate_trap_override_request, + .set_wave_launch_trap_override = kgd_gfx_v9_set_wave_launch_trap_override, .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c +55 -0
73 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h +10 -0
@@ -26,6 +26,16 @@ uint32_t kgd_gfx_v10_enable_debug_trap(struct amdgpu_device *adev,uint32_t kgd_gfx_v10_disable_debug_trap (struct amdgpu_device *adev,bool keep_trap_enabled,uint32_t vmid); +int kgd_gfx_v10_validate_trap_override_request (struct amdgpu_device *adev, +uint32_t trap_override, +uint32_t *trap_mask_supported); +uint32_t kgd_gfx_v10_set_wave_launch_trap_override (struct amdgpu_device *adev, +uint32_t vmid, +uint32_t trap_override, +uint32_t trap_mask_bits, +uint32_t trap_mask_request, +uint32_t *trap_mask_prev, +uint32_t kfd_dbg_trap_cntl_prev);void kgd_gfx_v10_get_iq_wait_times (struct amdgpu_device *adev,uint32_t *wait_times); void kgd_gfx_v10_build_grace_period_packet_info(struct amdgpu_device *adev, uint32_t wait_times,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c +4 -1
@@ -673,5 +673,8 @@ const struct kfd2kgd_calls gfx_v10_3_kfd2kgd = { .get_iq_wait_times = kgd_gfx_v10_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v10_build_grace_period_packet_info, .enable_debug_trap = kgd_gfx_v10_enable_debug_trap, - .disable_debug_trap = kgd_gfx_v10_disable_debug_trap + .disable_debug_trap = kgd_gfx_v10_disable_debug_trap, + .validate_trap_override_request = kgd_gfx_v10_validate_trap_override_request, + .set_wave_launch_trap_override = kgd_gfx_v10_set_wave_launch_trap_override + };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +55 -0
73 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h +10 -0
@@ -64,6 +64,16 @@ uint32_t kgd_gfx_v9_enable_debug_trap(struct amdgpu_device *adev,uint32_t kgd_gfx_v9_disable_debug_trap (struct amdgpu_device *adev,bool keep_trap_enabled,uint32_t vmid); +int kgd_gfx_v9_validate_trap_override_request (struct amdgpu_device *adev, +uint32_t trap_override, +uint32_t *trap_mask_supported); +uint32_t kgd_gfx_v9_set_wave_launch_trap_override (struct amdgpu_device *adev, +uint32_t vmid, +uint32_t trap_override, +uint32_t trap_mask_bits, +uint32_t trap_mask_request, +uint32_t *trap_mask_prev, +uint32_t kfd_dbg_trap_cntl_prev);void kgd_gfx_v9_get_iq_wait_times (struct amdgpu_device *adev,uint32_t *wait_times); void kgd_gfx_v9_build_grace_period_packet_info(struct amdgpu_device *adev, uint32_t wait_times,
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -0
@@ -2860,6 +2860,13 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v args->set_exceptions_enabled.exception_mask);break ;case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE : + r =kfd_dbg_trap_set_wave_launch_override (target, + args->launch_override.override_mode, + args->launch_override.enable_mask, + args->launch_override.support_request_mask, + &args->launch_override.enable_mask, + &args->launch_override.support_request_mask); +break ;case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE :case KFD_IOC_DBG_TRAP_SUSPEND_QUEUES :case KFD_IOC_DBG_TRAP_RESUME_QUEUES :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +65 -0
71 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +6 -0
@@ -45,6 +45,12 @@ int kfd_dbg_trap_disable(struct kfd_process *target);int kfd_dbg_trap_enable (struct kfd_process *target,uint32_t fd,void __user *runtime_info,uint32_t *runtime_info_size); +int kfd_dbg_trap_set_wave_launch_override (struct kfd_process *target, +uint32_t trap_override, +uint32_t trap_mask_bits, +uint32_t trap_mask_request, +uint32_t *trap_mask_prev, +uint32_t *trap_mask_supported); int kfd_dbg_send_exception_to_runtime(struct kfd_process *p, unsigned int dev_id,
Signature · 1 line
2.25.1
PATCH 21/29 drm/amdkfd: add debug wave launch mode operation
In reply to Jonathan KimAllow the debugger to set wave behaviour on to either normally operate, halt at launch, trap on every instruction, terminate immediately or stall on allocation.
--- .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c | 18 ++++++++++ .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 1 + .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 27 +++++++++++++++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h | 3 ++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 3 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 34 +++++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h | 3 ++ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 ++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 27 ++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 5 ++- 10 files changed, 119 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +18 -0
@@ -99,6 +99,23 @@ static uint32_t kgd_aldebaran_set_wave_launch_trap_override(struct amdgpu_devicereturn data; } +static uint32_t kgd_aldebaran_set_wave_launch_mode (struct amdgpu_device *adev, +uint8_t wave_launch_mode, +uint32_t vmid) +{ +uint32_t data =0 ; +bool is_stall_mode = wave_launch_mode ==KFD_DBG_TRAP_WAVE_LAUNCH_MODE_HALT ; + +if (is_stall_mode) + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,STALL_VMID , +1 ); +else + data =REG_SET_FIELD (data,SPI_GDBG_PER_VMID_CNTL ,LAUNCH_MODE , + wave_launch_mode); + +return data; +} +const struct kfd2kgd_calls aldebaran_kfd2kgd = { .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings, .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
@@ -120,6 +137,7 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = { .disable_debug_trap = kgd_aldebaran_disable_debug_trap, .validate_trap_override_request = kgd_aldebaran_validate_trap_override_request, .set_wave_launch_trap_override = kgd_aldebaran_set_wave_launch_trap_override, + .set_wave_launch_mode = kgd_aldebaran_set_wave_launch_mode, .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +1 -0
@@ -399,6 +399,7 @@ const struct kfd2kgd_calls arcturus_kfd2kgd = { .disable_debug_trap = kgd_arcturus_disable_debug_trap, .validate_trap_override_request = kgd_gfx_v9_validate_trap_override_request, .set_wave_launch_trap_override = kgd_gfx_v9_set_wave_launch_trap_override, + .set_wave_launch_mode = kgd_gfx_v9_set_wave_launch_mode, .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c +27 -0
@@ -854,6 +854,32 @@ uint32_t kgd_gfx_v10_set_wave_launch_trap_override(struct amdgpu_device *adev,return 0 ; } +uint32_t kgd_gfx_v10_set_wave_launch_mode (struct amdgpu_device *adev, +uint8_t wave_launch_mode, +uint32_t vmid) +{ +uint32_t data =0 ; +bool is_stall_mode = wave_launch_mode ==KFD_DBG_TRAP_WAVE_LAUNCH_MODE_STALL ; +bool is_mode_set = wave_launch_mode && !is_stall_mode; + +mutex_lock (&adev->grbm_idx_mutex); + +kgd_gfx_v10_set_wave_launch_stall (adev, vmid, true); + + data =REG_SET_FIELD (data,SPI_GDBG_WAVE_CNTL2 , +VMID_MASK , is_mode_set ?1 << vmid :0 ); + data =REG_SET_FIELD (data,SPI_GDBG_WAVE_CNTL2 , +MODE , is_mode_set ? wave_launch_mode :0 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL2), data); + +if (!is_stall_mode) +kgd_gfx_v10_set_wave_launch_stall (adev, vmid, false); + +mutex_unlock (&adev->grbm_idx_mutex); + +return 0 ; +} +/* kgd_gfx_v10_get_iq_wait_times: Returns the mmCP_IQ_WAIT_TIME1/2 values * The values read are: * ib_offload_wait_time -- Wait Count for Indirect Buffer Offloads.
@@ -941,6 +967,7 @@ const struct kfd2kgd_calls gfx_v10_kfd2kgd = { .disable_debug_trap = kgd_gfx_v10_disable_debug_trap, .validate_trap_override_request = kgd_gfx_v10_validate_trap_override_request, .set_wave_launch_trap_override = kgd_gfx_v10_set_wave_launch_trap_override, + .set_wave_launch_mode = kgd_gfx_v10_set_wave_launch_mode, .get_iq_wait_times = kgd_gfx_v10_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v10_build_grace_period_packet_info, .program_trap_handler_settings = program_trap_handler_settings,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h +3 -0
@@ -36,6 +36,9 @@ uint32_t kgd_gfx_v10_set_wave_launch_trap_override(struct amdgpu_device *adev,uint32_t trap_mask_request, uint32_t *trap_mask_prev, uint32_t kfd_dbg_trap_cntl_prev); +uint32_t kgd_gfx_v10_set_wave_launch_mode (struct amdgpu_device *adev, +uint8_t wave_launch_mode, +uint32_t vmid);void kgd_gfx_v10_get_iq_wait_times (struct amdgpu_device *adev,uint32_t *wait_times); void kgd_gfx_v10_build_grace_period_packet_info(struct amdgpu_device *adev, uint32_t wait_times,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c +2 -1
@@ -675,6 +675,7 @@ const struct kfd2kgd_calls gfx_v10_3_kfd2kgd = { .enable_debug_trap = kgd_gfx_v10_enable_debug_trap, .disable_debug_trap = kgd_gfx_v10_disable_debug_trap, .validate_trap_override_request = kgd_gfx_v10_validate_trap_override_request, - .set_wave_launch_trap_override = kgd_gfx_v10_set_wave_launch_trap_override + .set_wave_launch_trap_override = kgd_gfx_v10_set_wave_launch_trap_override, + .set_wave_launch_mode = kgd_gfx_v10_set_wave_launch_mode };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +34 -0
@@ -777,6 +777,39 @@ uint32_t kgd_gfx_v9_set_wave_launch_trap_override(struct amdgpu_device *adev,return 0 ; } +uint32_t kgd_gfx_v9_set_wave_launch_mode (struct amdgpu_device *adev, +uint8_t wave_launch_mode, +uint32_t vmid) +{ +uint32_t data =0 ; +bool is_stall_mode = wave_launch_mode == +KFD_DBG_TRAP_WAVE_LAUNCH_MODE_STALL ; +bool is_mode_set = wave_launch_mode && !is_stall_mode; + +mutex_lock (&adev->grbm_idx_mutex); + +kgd_gfx_v9_set_wave_launch_stall (adev, vmid, true); + + data =REG_SET_FIELD (data,SPI_GDBG_WAVE_CNTL2 , +VMID_MASK , is_mode_set ?1 << vmid :0 ); + data =REG_SET_FIELD (data,SPI_GDBG_WAVE_CNTL2 , +MODE , is_mode_set ? wave_launch_mode :0 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_WAVE_CNTL2), data); + +/* Although Pre-GFX9.4.1 stalls globally, the per-VMID stall for +* GFX9.4.1 effectively does the same thing as global STALL_RA as +* all other VMID allocations are back logged by the stalled VMID. +* +* Use with caution. +*/ +if (!is_stall_mode) +kgd_gfx_v9_set_wave_launch_stall (adev, vmid, false); + +mutex_unlock (&adev->grbm_idx_mutex); + +return 0 ; +} +/* kgd_gfx_v9_get_iq_wait_times: Returns the mmCP_IQ_WAIT_TIME1/2 values * The values read are: * ib_offload_wait_time -- Wait Count for Indirect Buffer Offloads.
@@ -1047,6 +1080,7 @@ const struct kfd2kgd_calls gfx_v9_kfd2kgd = { .disable_debug_trap = kgd_gfx_v9_disable_debug_trap, .validate_trap_override_request = kgd_gfx_v9_validate_trap_override_request, .set_wave_launch_trap_override = kgd_gfx_v9_set_wave_launch_trap_override, + .set_wave_launch_mode = kgd_gfx_v9_set_wave_launch_mode, .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h +3 -0
@@ -67,6 +67,9 @@ uint32_t kgd_gfx_v9_disable_debug_trap(struct amdgpu_device *adev,int kgd_gfx_v9_validate_trap_override_request (struct amdgpu_device *adev,uint32_t trap_override,uint32_t *trap_mask_supported); +uint32_t kgd_gfx_v9_set_wave_launch_mode (struct amdgpu_device *adev, +uint8_t wave_launch_mode, +uint32_t vmid); uint32_t kgd_gfx_v9_set_wave_launch_trap_override(struct amdgpu_device *adev, uint32_t vmid, uint32_t trap_override,
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -0
@@ -2868,6 +2868,9 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v &args->launch_override.support_request_mask);break ;case KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE : + r =kfd_dbg_trap_set_wave_launch_mode (target, + args->launch_mode.launch_mode); +break ;case KFD_IOC_DBG_TRAP_SUSPEND_QUEUES :case KFD_IOC_DBG_TRAP_RESUME_QUEUES :case KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +26 -1
@@ -239,8 +239,10 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwind {int i, count =0 ; -if (!unwind) +if (!unwind) {cancel_work_sync (&target->debug_event_workarea); +kfd_dbg_trap_set_wave_launch_mode (target,0 ); + }for (i =0 ; i < target->n_pdds; i++) {struct kfd_process_device *pdd = target->pdds[i];
@@ -481,6 +483,29 @@ int kfd_dbg_trap_set_wave_launch_override(struct kfd_process *target,return r; } +int kfd_dbg_trap_set_wave_launch_mode (struct kfd_process *target, +uint8_t wave_launch_mode) +{ +int r =0 , i; + +for (i =0 ; i < target->n_pdds; i++) { +struct kfd_process_device *pdd = target->pdds[i]; + +amdgpu_gfx_off_ctrl (pdd->dev->adev, false); + pdd->spi_dbg_launch_mode = pdd->dev->kfd2kgd->set_wave_launch_mode ( + pdd->dev->adev, + wave_launch_mode, + pdd->dev->vm_info.last_vmid_kfd); +amdgpu_gfx_off_ctrl (pdd->dev->adev, true); + + r =debug_refresh_runlist (pdd->dev->dqm); +if (r) +break ; + } + +return r; +} +void kfd_dbg_set_enabled_debug_exception_mask (struct kfd_process *target,uint64_t exception_set_mask) {
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2 -3
@@ -25,9 +25,6 @@#include "kfd_priv.h" -void kgd_gfx_v9_set_wave_launch_stall (struct amdgpu_device *adev, -uint32_t vmid, -bool stall);void kfd_dbg_trap_deactivate (struct kfd_process *target,bool unwind,int unwind_count);int kfd_dbg_trap_activate (struct kfd_process *target); bool kfd_set_dbg_ev_from_interrupt(struct kfd_dev *dev,
@@ -51,6 +48,8 @@ int kfd_dbg_trap_set_wave_launch_override(struct kfd_process *target,uint32_t trap_mask_request, uint32_t *trap_mask_prev, uint32_t *trap_mask_supported); +int kfd_dbg_trap_set_wave_launch_mode (struct kfd_process *target, +uint8_t wave_launch_mode); int kfd_dbg_send_exception_to_runtime(struct kfd_process *p, unsigned int dev_id,
Signature · 1 line
2.25.1
PATCH 22/29 drm/amdkfd: add debug suspend and resume process queues operation
In reply to Jonathan KimIn order to inspect waves from the saved context at any point during a debug session, the debugger must be able to preempt queues to trigger context save by suspending them.
On queue suspend, the KFD will copy the context save header information so that the debugger can correctly crawl the appropriate size of the saved context. The debugger must then also be allowed to resume suspended queues.
A queue that is newly created cannot be suspended because queue ids are recycled after destruction so the debugger needs to know that this has occurred. Query functions will be later added that will clear a given queue of its new queue status.
A queue cannot be destroyed while it is suspended to preserve its saved context during debugger inspection. Have queue destruction block while a queue is suspended and unblocked when it is resumed. Likewise, if a queue is about to be destroyed, it cannot be suspended.
Return the number of queues successfully suspended or resumed along with a per queue status array where the upper bits per queue status show that the request was invalid (new/destroyed queue suspend request, missing queue) or an error occurred (HWS in a fatal state so it can't suspend or resume queues).
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 + drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 7 + .../drm/amd/amdkfd/kfd_device_queue_manager.c | 401 +++++++++++++++++- .../drm/amd/amdkfd/kfd_device_queue_manager.h | 11 + .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c | 10 + .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 14 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 5 +- 7 files changed, 454 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +12 -0
@@ -404,6 +404,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,pr_debug ("Write ptr address == 0x%016llX\n" , args->write_pointer_address); +kfd_dbg_ev_raise (KFD_EC_MASK (EC_QUEUE_NEW ), p, dev, queue_id, false,NULL ,0 );return 0 ; err_create_queue:
@@ -2872,7 +2873,18 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v args->launch_mode.launch_mode);break ;case KFD_IOC_DBG_TRAP_SUSPEND_QUEUES : + r =suspend_queues (target, + args->suspend_queues.num_queues, + args->suspend_queues.grace_period, + args->suspend_queues.exception_mask, + (uint32_t *)args->suspend_queues.queue_array_ptr); + +break ;case KFD_IOC_DBG_TRAP_RESUME_QUEUES : + r =resume_queues (target, false, + args->resume_queues.num_queues, + (uint32_t *)args->resume_queues.queue_array_ptr); +break ;case KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH :case KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH :case KFD_IOC_DBG_TRAP_SET_FLAGS :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +7 -0
@@ -274,6 +274,13 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwind count++; } + +if (!unwind) { +int resume_count =resume_queues (target, true,0 ,NULL ); + +if (resume_count) +pr_debug ("Resumed %d queues\n" , resume_count); + } }int kfd_dbg_trap_disable (struct kfd_process *target)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +397 -4
441 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +11 -0
@@ -259,6 +259,8 @@ struct device_queue_manager {struct kfd_mem_obj hiq_sdma_mqd;bool sched_running;uint32_t wait_times; + +wait_queue_head_t destroy_wait; }; void device_queue_manager_init_cik(
@@ -286,6 +288,15 @@ int reserve_debug_trap_vmid(struct device_queue_manager *dqm, struct qcm_process_device *qpd);int release_debug_trap_vmid (struct device_queue_manager *dqm,struct qcm_process_device *qpd); +int suspend_queues (struct kfd_process *p, +uint32_t num_queues, +uint32_t grace_period, +uint64_t exception_clear_mask, +uint32_t *usr_queue_id_array); +int resume_queues (struct kfd_process *p, +bool resume_all_queues, +uint32_t num_queues, +uint32_t *usr_queue_id_array);int debug_lock_and_unmap (struct device_queue_manager *dqm);int debug_map_and_unlock (struct device_queue_manager *dqm);int debug_refresh_runlist (struct device_queue_manager *dqm);
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +10 -0
@@ -237,6 +237,7 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd, u32 *save_area_used_size) {struct v10_compute_mqd *m; +struct kfd_context_save_area_header header; m =get_mqd (mqd);
@@ -255,6 +256,15 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd,* accessible to user mode */ + header.control_stack_size = *ctl_stack_used_size; + header.wave_state_size = *save_area_used_size; + + header.wave_state_offset = m->cp_hqd_wg_state_offset; + header.control_stack_offset = m->cp_hqd_cntl_stack_offset; + +if (copy_to_user (ctl_stack, &header,sizeof (header))) +return -EFAULT ; +return 0 ; }
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +13 -1
@@ -289,6 +289,7 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd, u32 *save_area_used_size) {struct v9_mqd *m; +struct kfd_context_save_area_header header;/* Control stack is located one page after MQD. */ void *mqd_ctl_stack = (void *)((uintptr_t )mqd +PAGE_SIZE );
@@ -300,7 +301,18 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd, *save_area_used_size = m->cp_hqd_wg_state_offset - m->cp_hqd_cntl_stack_size; -if (copy_to_user (ctl_stack, mqd_ctl_stack, m->cp_hqd_cntl_stack_size)) + header.control_stack_size = *ctl_stack_used_size; + header.wave_state_size = *save_area_used_size; + + header.wave_state_offset = m->cp_hqd_wg_state_offset; + header.control_stack_offset = m->cp_hqd_cntl_stack_offset; + +if (copy_to_user (ctl_stack, &header,sizeof (header))) +return -EFAULT ; + +if (copy_to_user (ctl_stack + m->cp_hqd_cntl_stack_offset, + mqd_ctl_stack + m->cp_hqd_cntl_stack_offset, + *ctl_stack_used_size))return -EFAULT ;return 0 ;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +4 -1
@@ -477,6 +477,8 @@ struct queue_properties {uint32_t doorbell_off;bool is_interop;bool is_evicted; +bool is_suspended; +bool is_being_destroyed;bool is_active;bool is_gws;/* Not relevant for user mode queues in cp scheduling */
@@ -499,7 +501,8 @@ struct queue_properties {#define QUEUE_IS_ACTIVE (q) ((q).queue_size > 0 && \ (q).queue_address != 0 && \ (q).queue_percent > 0 && \ - !(q).is_evicted) + !(q).is_evicted && \ + !(q).is_suspended)enum mqd_update_flag {UPDATE_FLAG_CU_MASK =0 ,
Signature · 1 line
2.25.1
PATCH 23/29 drm/amdkfd: add debug set and clear address watch points operation
In reply to Jonathan KimShader read, write and atomic memory operations can be alerted to the debugger as an address watch exception.
Allow the debugger to pass in a watch point to a particular memory address per device.
Note that there exists only 4 watch points per devices to date, so have the KFD keep track of what watch points are allocated or not.
--- .../drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c | 2 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 + .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 78 +++++++++++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h | 8 ++ .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 5 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 128 +++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h | 8 ++ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 24 ++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 130 ++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 8 +- drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c | 7 + drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 9 +- 12 files changed, 405 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_aldebaran.c +2 -0
@@ -138,6 +138,8 @@ const struct kfd2kgd_calls aldebaran_kfd2kgd = { .validate_trap_override_request = kgd_aldebaran_validate_trap_override_request, .set_wave_launch_trap_override = kgd_aldebaran_set_wave_launch_trap_override, .set_wave_launch_mode = kgd_aldebaran_set_wave_launch_mode, + .set_address_watch = kgd_gfx_v9_set_address_watch, + .clear_address_watch = kgd_gfx_v9_clear_address_watch, .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .program_trap_handler_settings = kgd_gfx_v9_program_trap_handler_settings,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +2 -0
@@ -400,6 +400,8 @@ const struct kfd2kgd_calls arcturus_kfd2kgd = { .validate_trap_override_request = kgd_gfx_v9_validate_trap_override_request, .set_wave_launch_trap_override = kgd_gfx_v9_set_wave_launch_trap_override, .set_wave_launch_mode = kgd_gfx_v9_set_wave_launch_mode, + .set_address_watch = kgd_gfx_v9_set_address_watch, + .clear_address_watch = kgd_gfx_v9_clear_address_watch, .get_iq_wait_times = kgd_gfx_v9_get_iq_wait_times, .build_grace_period_packet_info = kgd_gfx_v9_build_grace_period_packet_info, .get_cu_occupancy = kgd_gfx_v9_get_cu_occupancy,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c +78 -0
90 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.h +8 -0
@@ -39,6 +39,14 @@ uint32_t kgd_gfx_v10_set_wave_launch_trap_override(struct amdgpu_device *adev,uint32_t kgd_gfx_v10_set_wave_launch_mode (struct amdgpu_device *adev,uint8_t wave_launch_mode,uint32_t vmid); +uint32_t kgd_gfx_v10_set_address_watch (struct amdgpu_device *adev, +uint64_t watch_address, +uint32_t watch_address_mask, +uint32_t watch_id, +uint32_t watch_mode, +uint32_t debug_vmid); +uint32_t kgd_gfx_v10_clear_address_watch (struct amdgpu_device *adev, +uint32_t watch_id);void kgd_gfx_v10_get_iq_wait_times (struct amdgpu_device *adev,uint32_t *wait_times); void kgd_gfx_v10_build_grace_period_packet_info(struct amdgpu_device *adev, uint32_t wait_times,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c +3 -2
@@ -676,6 +676,7 @@ const struct kfd2kgd_calls gfx_v10_3_kfd2kgd = { .disable_debug_trap = kgd_gfx_v10_disable_debug_trap, .validate_trap_override_request = kgd_gfx_v10_validate_trap_override_request, .set_wave_launch_trap_override = kgd_gfx_v10_set_wave_launch_trap_override, - .set_wave_launch_mode = kgd_gfx_v10_set_wave_launch_mode - + .set_wave_launch_mode = kgd_gfx_v10_set_wave_launch_mode, + .set_address_watch = kgd_gfx_v10_set_address_watch, + .clear_address_watch = kgd_gfx_v10_clear_address_watch };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +128 -0
140 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h +8 -0
@@ -77,6 +77,14 @@ uint32_t kgd_gfx_v9_set_wave_launch_trap_override(struct amdgpu_device *adev,uint32_t trap_mask_request, uint32_t *trap_mask_prev, uint32_t kfd_dbg_trap_cntl_prev); +uint32_t kgd_gfx_v9_set_address_watch (struct amdgpu_device *adev, +uint64_t watch_address, +uint32_t watch_address_mask, +uint32_t watch_id, +uint32_t watch_mode, +uint32_t debug_vmid); +uint32_t kgd_gfx_v9_clear_address_watch (struct amdgpu_device *adev, +uint32_t watch_id);void kgd_gfx_v9_get_iq_wait_times (struct amdgpu_device *adev,uint32_t *wait_times); void kgd_gfx_v9_build_grace_period_packet_info(struct amdgpu_device *adev, uint32_t wait_times,
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +24 -0
@@ -2767,6 +2767,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, vstruct task_struct *thread =NULL ;struct pid *pid =NULL ;struct kfd_process *target =NULL ; +struct kfd_process_device *pdd =NULL ;int r =0 ;if (sched_policy ==KFD_SCHED_POLICY_NO_HWS ) {
@@ -2833,6 +2834,20 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v goto unlock_out; } +if (args->op ==KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH || + args->op ==KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH ) { +int user_gpu_id =kfd_process_get_user_gpu_id (target, + args->op ==KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH ? + args->set_node_address_watch.dev_id : + args->clear_node_address_watch.dev_id); + + pdd =kfd_process_device_data_by_id (target, user_gpu_id); +if (user_gpu_id == -EINVAL || !pdd) { + r = -ENODEV ; + goto unlock_out; + } + } +switch (args->op) {case KFD_IOC_DBG_TRAP_ENABLE :if (target != p)
@@ -2886,7 +2901,16 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v (uint32_t *)args->resume_queues.queue_array_ptr);break ;case KFD_IOC_DBG_TRAP_SET_NODE_ADDRESS_WATCH : + r =kfd_dbg_trap_set_dev_address_watch (pdd, + args->set_node_address_watch.address, + args->set_node_address_watch.mask, + &args->set_node_address_watch.id, + args->set_node_address_watch.mode); +break ;case KFD_IOC_DBG_TRAP_CLEAR_NODE_ADDRESS_WATCH : + r =kfd_dbg_trap_clear_dev_address_watch (pdd, + args->clear_node_address_watch.id); +break ;case KFD_IOC_DBG_TRAP_SET_FLAGS :case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT :case KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +130 -0
148 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +7 -1
@@ -50,7 +50,13 @@ int kfd_dbg_trap_set_wave_launch_override(struct kfd_process *target, uint32_t *trap_mask_supported);int kfd_dbg_trap_set_wave_launch_mode (struct kfd_process *target,uint8_t wave_launch_mode); - +int kfd_dbg_trap_clear_dev_address_watch (struct kfd_process_device *pdd, +uint32_t watch_id); +int kfd_dbg_trap_set_dev_address_watch (struct kfd_process_device *pdd, +uint64_t watch_address, +uint32_t watch_address_mask, +uint32_t *watch_id, +uint32_t watch_mode); int kfd_dbg_send_exception_to_runtime(struct kfd_process *p, unsigned int dev_id, unsigned int queue_id,
drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c +7 -0
@@ -395,6 +395,8 @@ int kfd_init_apertures(struct kfd_process *process) pdd->gpuvm_base = pdd->gpuvm_limit =0 ; pdd->scratch_base = pdd->scratch_limit =0 ; }else { +int num_watchpoints = pdd->dev->device_info.num_of_watch_points; +switch (dev->adev->asic_type) {case CHIP_KAVERI :case CHIP_HAWAII :
@@ -424,6 +426,11 @@ int kfd_init_apertures(struct kfd_process *process) pdd->qpd.cwsr_base =SVM_CWSR_BASE ; pdd->qpd.ib_base =SVM_IB_BASE ; } + + process->max_watch_points = + !process->max_watch_points ? num_watchpoints : +min (num_watchpoints, process->max_watch_points); + }dev_dbg (kfd_device,"node id %u\n" , id);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -1
@@ -348,6 +348,9 @@ struct kfd_dev {/* HMM page migration MEMORY_DEVICE_PRIVATE mapping */ struct dev_pagemap pgmap; + +/* Track per device allocated watch points */ +uint32_t alloc_watch_ids; };enum kfd_mempool {
@@ -796,6 +799,7 @@ struct kfd_process_device {uint32_t spi_dbg_override;uint32_t spi_dbg_launch_mode;uint32_t watch_points[4 ]; +uint32_t alloc_watch_ids;/* * If this process has been checkpointed before, then the user
@@ -907,6 +911,10 @@ struct kfd_process {/* per-process-per device debug event fd file */ struct file *dbg_ev_file; +/* Allocated debug watch point IDs bitmask */ +uint32_t allocated_debug_watch_point_bitmask; +int max_watch_points; +/* If the process is a kfd debugger, we need to know so we can clean * up at exit time. If a process enables debugging on itself, it does * its own clean-up, so we don't set the flag here. We track this by
@@ -952,7 +960,6 @@ struct kfd_process {struct semaphore runtime_enable_sema;bool is_runtime_retry;struct kfd_runtime_info runtime_info; - };#define KFD_PROCESS_TABLE_SIZE 5/* bits: 32 entries */
Signature · 1 line
2.25.1
PATCH 24/29 drm/amdkfd: add debug set flags operation
In reply to Jonathan KimAllow the debugger to set single memory and single ALU operations.
Some exceptions are imprecise (memory violations, address watch) in the sense that a trap occurs only when the exception interrupt occurs and not at the non-halting faulty instruction. Trap temporaries 0 & 1 save the program counter address, which means that these values will not point to the faulty instruction address but to whenever the interrupt was raised.
Setting the Single Memory Operations flag will inject an automatic wait on every memory operation instruction forcing imprecise memory exceptions to become precise at the cost of performance. This setting is not permitted on debug devices that support only a global setting of this option.
Likewise, Single ALU Operations will force in-order ALU operations. Although this is available on current hardware, it's not required so it will be treated as a NOP.
Return the previous set flags to the debugger as well.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 ++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 35 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 1 + 3 files changed, 38 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
@@ -2912,6 +2912,8 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v args->clear_node_address_watch.id);break ;case KFD_IOC_DBG_TRAP_SET_FLAGS : + r =kfd_dbg_trap_set_flags (target, &args->set_flags.flags); +break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT :case KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO :case KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +35 -0
@@ -23,6 +23,7 @@#include "kfd_debug.h" #include "kfd_device_queue_manager.h" #include <linux/file.h> +#include <uapi/linux/kfd_ioctl.h> /* * The spinlock protects the per device dev->alloc_watch_ids for multi-process access.
@@ -355,6 +356,37 @@ static void kfd_dbg_clear_process_address_watch(struct kfd_process *target)kfd_dbg_trap_clear_dev_address_watch (target->pdds[i], j); } +int kfd_dbg_trap_set_flags (struct kfd_process *target,uint32_t *flags) +{ +uint32_t prev_flags = target->dbg_flags; +int i, r =0 ; + +for (i =0 ; i < target->n_pdds; i++) { +if (!kfd_dbg_is_per_vmid_supported (target->pdds[i]->dev) && + (*flags &KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP )) { + *flags = prev_flags; +return -EPERM ; + } + } + + target->dbg_flags = *flags; + *flags = prev_flags; +for (i =0 ; i < target->n_pdds; i++) { +struct kfd_process_device *pdd = target->pdds[i]; + +if (!kfd_dbg_is_per_vmid_supported (pdd->dev)) +continue ; + + r =debug_refresh_runlist (target->pdds[i]->dev->dqm); +if (r) { + target->dbg_flags = prev_flags; +break ; + } + } + +return r; +} +/* kfd_dbg_trap_deactivate: * target: target process
@@ -369,9 +401,12 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindint i, count =0 ;if (!unwind) { +uint32_t flags =0 ;cancel_work_sync (&target->debug_event_workarea);kfd_dbg_clear_process_address_watch (target);kfd_dbg_trap_set_wave_launch_mode (target,0 ); + +kfd_dbg_trap_set_flags (target, &flags); }for (i =0 ; i < target->n_pdds; i++) {
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +1 -0
@@ -57,6 +57,7 @@ int kfd_dbg_trap_set_dev_address_watch(struct kfd_process_device *pdd,uint32_t watch_address_mask, uint32_t *watch_id, uint32_t watch_mode); +int kfd_dbg_trap_set_flags (struct kfd_process *target,uint32_t *flags); int kfd_dbg_send_exception_to_runtime(struct kfd_process *p, unsigned int dev_id, unsigned int queue_id,
Signature · 1 line
2.25.1
PATCH 25/29 drm/amdkfd: add debug query event operation
In reply to Jonathan KimAllow the debugger to a single query queue, device and process exception in a FIFO manner.
The KFD should also return the GPU or Queue id of the exception. The debugger also has the option of clearing exceptions after being queried.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 +++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 64 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 5 ++ 3 files changed, 75 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -0
@@ -2915,6 +2915,12 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v r =kfd_dbg_trap_set_flags (target, &args->set_flags.flags);break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : + r =kfd_dbg_ev_query_debug_event (target, + &args->query_debug_event.queue_id, + &args->query_debug_event.gpu_id, + args->query_debug_event.exception_mask, + &args->query_debug_event.exception_mask); +break ;case KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO :case KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT :case KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT :
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +64 -0
70 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +5 -0
@@ -27,6 +27,11 @@void kfd_dbg_trap_deactivate (struct kfd_process *target,bool unwind,int unwind_count);int kfd_dbg_trap_activate (struct kfd_process *target); +int kfd_dbg_ev_query_debug_event (struct kfd_process *process, +unsigned int *queue_id, +unsigned int *gpu_id, +uint64_t exception_clear_mask, +uint64_t *event_status); bool kfd_set_dbg_ev_from_interrupt(struct kfd_dev *dev, unsigned int pasid, uint32_t doorbell_id,
Signature · 1 line
2.25.1
PATCH 26/29 drm/amdkfd: add debug query exception info operation
In reply to Jonathan KimAllow the debugger to query additional info based on an exception code. For device exceptions, it's currently only memory violation information. For process exceptions, it's currently only runtime information. Queue exception only report the queue exception status.
The debugger has the option of clearing the target exception on query.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 7 ++ drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 120 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 6 ++ 3 files changed, 133 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -0
@@ -2922,6 +2922,13 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v &args->query_debug_event.exception_mask);break ;case KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO : + r =kfd_dbg_trap_query_exception_info (target, + args->query_exception_info.source_id, + args->query_exception_info.exception_code, + args->query_exception_info.clear_exception, + (void __user *)args->query_exception_info.info_ptr, + &args->query_exception_info.info_size); +break ;case KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT :case KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT :pr_warn ("Debug op %i not supported yet\n" , args->op);
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +120 -0
126 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +6 -0
@@ -63,6 +63,12 @@ int kfd_dbg_trap_set_dev_address_watch(struct kfd_process_device *pdd,uint32_t *watch_id, uint32_t watch_mode);int kfd_dbg_trap_set_flags (struct kfd_process *target,uint32_t *flags); +int kfd_dbg_trap_query_exception_info (struct kfd_process *target, +uint32_t source_id, +uint32_t exception_code, +bool clear_exception, +void __user *info, +uint32_t *info_size); int kfd_dbg_send_exception_to_runtime(struct kfd_process *p, unsigned int dev_id, unsigned int queue_id,
Signature · 1 line
2.25.1
PATCH 27/29 drm/amdkfd: add debug queue snapshot operation
In reply to Jonathan KimAllow the debugger to get a snapshot of a specified number of queues containing various queue property information that is copied to the debugger.
Since the debugger doesn't know how many queues exist at any given time, allow the debugger to pass the requested number of snapshots as 0 to get the actual number of potential snapshots to use for a subsequent snapshot request for actual information.
To prevent future ABI breakage, pass in the requested entry_size. The KFD will return it's own entry_size in case the debugger still wants log the information in a core dump on sizing failure.
Also allow the debugger to clear exceptions when doing a snapshot.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 +++ .../drm/amd/amdkfd/kfd_device_queue_manager.c | 41 +++++++++++++++++++ .../drm/amd/amdkfd/kfd_device_queue_manager.h | 4 ++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 5 +++ .../amd/amdkfd/kfd_process_queue_manager.c | 40 ++++++++++++++++++ 5 files changed, 96 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -0
@@ -2930,6 +2930,12 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v &args->query_exception_info.info_size);break ;case KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT : + r =pqm_get_queue_snapshot (&target->pqm, + args->queue_snapshot.exception_mask, + (void __user *)args->queue_snapshot.snapshot_buf_ptr, + &args->queue_snapshot.buf_size, + &args->queue_snapshot.entry_size); +break ;case KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT :pr_warn ("Debug op %i not supported yet\n" , args->op); r = -EPERM ;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +41 -0
47 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +4 -0
@@ -297,6 +297,10 @@ int resume_queues(struct kfd_process *p,bool resume_all_queues, uint32_t num_queues, uint32_t *usr_queue_id_array); +void set_queue_snapshot_entry (struct device_queue_manager *dqm, +struct queue *q, +uint64_t exception_clear_mask, +struct kfd_queue_snapshot_entry *qss_entry);int debug_lock_and_unmap (struct device_queue_manager *dqm);int debug_map_and_unlock (struct device_queue_manager *dqm);int debug_refresh_runlist (struct device_queue_manager *dqm);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +5 -0
@@ -1302,6 +1302,11 @@ int pqm_get_wave_state(struct process_queue_manager *pqm,void __user *ctl_stack, u32 *ctl_stack_used_size, u32 *save_area_used_size); +int pqm_get_queue_snapshot (struct process_queue_manager *pqm, +uint64_t exception_clear_mask, +struct kfd_queue_snapshot_entry __user *buf, +int *num_qss_entries, +uint32_t *entry_size); int amdkfd_fence_wait_timeout(uint64_t *fence_addr, uint64_t fence_value,
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +40 -0
@@ -566,6 +566,46 @@ int pqm_get_wave_state(struct process_queue_manager *pqm, save_area_used_size); } +int pqm_get_queue_snapshot (struct process_queue_manager *pqm, +uint64_t exception_clear_mask, +struct kfd_queue_snapshot_entry __user *buf, +int *num_qss_entries, +uint32_t *entry_size) +{ +struct process_queue_node *pqn; +uint32_t tmp_entry_size = *entry_size, tmp_qss_entries = *num_qss_entries; +int r; + + *num_qss_entries =0 ; +if (!(*entry_size)) +return -EINVAL ; + + *entry_size =min ((size_t )entry_size,sizeof (struct kfd_queue_snapshot_entry )); +mutex_lock (&pqm->process->event_mutex); + +list_for_each_entry (pqn, &pqm->queues, process_queue_list) { +if (!pqn->q) +continue ; + +if (*num_qss_entries < tmp_qss_entries) { +struct kfd_queue_snapshot_entry src = {0 }; + +set_queue_snapshot_entry (pqn->q->device->dqm, + pqn->q, exception_clear_mask, &src); + +if (copy_to_user (buf, &src, *entry_size)) { + r = -EFAULT ; +break ; + } + buf += tmp_entry_size; + } + *num_qss_entries +=1 ; + } + +mutex_unlock (&pqm->process->event_mutex); +return r; +} + static int get_queue_data_sizes(struct kfd_process_device *pdd, struct queue *q, uint32_t *mqd_size,
Signature · 1 line
2.25.1
PATCH 28/29 drm/amdkfd: add debug device snapshot operation
In reply to Jonathan KimSimilar to queue snapshot, return an array of device information using an entry_size check and return.
Unlike queue snapshots, the debugger needs to pass to correct number of devices that exist. If it fails to do so, the KFD will return the number of actual devices so that the debugger can make a subsequent successful call.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 7 +++- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 52 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 5 +++ 3 files changed, 62 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +5 -2
@@ -2937,8 +2937,11 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v &args->queue_snapshot.entry_size);break ;case KFD_IOC_DBG_TRAP_GET_DEVICE_SNAPSHOT : -pr_warn ("Debug op %i not supported yet\n" , args->op); - r = -EPERM ; + r =kfd_dbg_trap_device_snapshot (target, + args->device_snapshot.exception_mask, + (void __user *)args->device_snapshot.snapshot_buf_ptr, + &args->device_snapshot.buf_size, + &args->device_snapshot.entry_size);break ;default :pr_err ("Invalid option: %i\n" , args->op);
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +52 -0
58 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +5 -0
@@ -80,6 +80,11 @@ static inline bool kfd_dbg_is_per_vmid_supported(struct kfd_dev *dev) }void debug_event_write_work_handler (struct work_struct *work); +int kfd_dbg_trap_device_snapshot (struct kfd_process *target, +uint64_t exception_clear_mask, +void __user *user_info, +uint32_t *number_of_device_infos, +uint32_t *entry_size);void kfd_dbg_set_enabled_debug_exception_mask (struct kfd_process *target,uint64_t exception_set_mask);
Signature · 1 line
2.25.1
PATCH 29/29 drm/amdkfd: bump kfd ioctl minor version for debug api availability
In reply to Jonathan KimBump the minor version to declare debugging capability is now available.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 1 - include/uapi/linux/kfd_ioctl.h | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -1
@@ -2860,7 +2860,6 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, vif (!r) target->exception_enable_mask = args->enable.exception_mask; -pr_warn ("Debug functions limited\n" );break ;case KFD_IOC_DBG_TRAP_DISABLE : r =kfd_dbg_trap_disable (target);
include/uapi/linux/kfd_ioctl.h +2 -1
@@ -37,9 +37,10 @@* - 1.9 - Add available memory ioctl * - 1.10 - Add SMI profiler event log * - 1.11 - Add unified memory for ctx save/restore area +* - 1.12 - Add debugger API */ #define KFD_IOCTL_MAJOR_VERSION 1 -#define KFD_IOCTL_MINOR_VERSION 11 +#define KFD_IOCTL_MINOR_VERSION 12struct kfd_ioctl_get_version_args {__u32 major_version;/* from KFD */
Signature · 1 line
2.25.1