drm/amdkfd: add mask for debug trap flag setting
Subsystems (3)
PATCH 1/1 drm/amdkfd: add mask for debug trap flag setting
to specify which bits are valid setting on flags.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 48 ++++++++++++------------ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 +- include/uapi/linux/kfd_ioctl.h | 3 +- 4 files changed, 30 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
@@ -3377,7 +3377,7 @@ 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); + r =kfd_dbg_trap_set_flags (target, &args->set_flags);break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : r = kfd_dbg_ev_query_debug_event(target,
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +25 -23
87 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2 -1
@@ -62,7 +62,8 @@ 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_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags); int kfd_dbg_trap_query_exception_info(struct kfd_process *target, uint32_t source_id, uint32_t exception_code,
include/uapi/linux/kfd_ioctl.h +2 -1
@@ -1515,6 +1515,7 @@ struct kfd_ioctl_dbg_trap_clear_node_address_watch_args {* Sets flags for wave behaviour. * * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled +* @mask (IN) - IN = specified debug trap operation bits on flag * * Generic errors apply (see kfd_dbg_trap_operations). * Return - 0 on SUCCESS.
@@ -1522,7 +1523,7 @@ struct kfd_ioctl_dbg_trap_clear_node_address_watch_args {*/ struct kfd_ioctl_dbg_trap_set_flags_args {__u32 flags; -__u32 pad; +__u32 mask; };/**
Signature · 1 line
2.34.1
[Public]
Quoted 9 lines
-----Original Message-----
From: Zhu, James <[email protected]>
Sent: Monday, January 19, 2026 12:15 PM
To: [email protected]
Cc: Six, Lancelot <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, James <[email protected]>
Subject: [PATCH] drm/amdkfd: add mask for debug trap flag settingto specify which bits are valid setting on flags.
Can you elaborate?
Quoted 33 lines
Signed-off-by James Zhu <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 48 ++++++++++++------------ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 +- include/uapi/linux/kfd_ioctl.h | 3 +- 4 files changed, 30 insertions(+), 26 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -3377,7 +3377,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep,struct
kfd_process*p, vargs->clear_node_address_watch.id); break; case KFD_IOC_DBG_TRAP_SET_FLAGS:drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1- r =kfd_dbg_trap_set_flags (target, &args->set_flags.flags); + r =kfd_dbg_trap_set_flags (target, &args->set_flags);break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : r = kfd_dbg_ev_query_debug_event(target,drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -512,38 +512,42 @@ static void kfd_dbg_clear_process_address_watch(struct kfd_process *target) kfd_dbg_trap_clear_dev_address_watch(target- >pdds[i], j);
drivers/gpu/drm/amd/amdkfd/kfd_debug.c static void · line 523
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1} -int kfd_dbg_trap_set_flags (struct kfd_process *target,uint32_t *flags) +int kfd_dbg_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags) {uint32_t prev_flags = target->dbg_flags;int i, r =0 , rewind_count =0 ; +if (!((set_flags->flags ^ prev_flags) & set_flags->mask))
Does this block old debuggers from setting debug mode if pad is 0?
Quoted 28 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1+return 0 ; +for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (target->pdds[i]- >dev->id);uint32_t caps = topo_dev->node_props.capability;uint32_t caps2 = topo_dev->node_props.capability2; +struct amdgpu_device *adev = target->pdds[i]->dev->adev; - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
- (*flags &KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE)) {
drivers/gpu/drm/amd/amdkfd/kfd_debug.c static void kfd_dbg_clear_process_address_watch(struct kfd_process *target) · line 532
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-1- *flags = prev_flags; +if (set_flags->mask ==0xFFFFFFFF && !set_flags->flags) +break ;
Seems like this is only for a deactivation system call.
Probably don't want to let users abuse this with a magic number then.
Maybe breakout into new static call in deactivation or just device loop deactivate directly there since this logic is starting to get complicated.
Quoted 7 lines
+ if ((!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) ||
+ (!(caps &HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP))
Quoted 5 lines
|| + (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE))) {
Please vertically indent align "caps" and "set_flags" underneath each other for legibility.
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0+ set_flags->flags = prev_flags; + dev_dbg(adev->dev, "Debug Trap set mask 0x%x caps0x%x caps2 0x%x",
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-2+ set_flags->mask, caps, caps2);return -EACCES ; } } - target->dbg_flags = *flags; - *flags = prev_flags; + target->dbg_flags ^= (target->dbg_flags ^ set_flags->flags) & set_flags-
Quoted 1 line
Quoted 1 line
mask;
I assume we can only set/unset 1 flag at a time, which is why this works. Otherwise, maybe I don't have enough background on this, but please do elaborate.
Quoted 10 lines
+ pr_debug("Debug Trap previous flags 0x%x set flags 0x%x set mask 0x%x
target flags 0x%x",
+prev_flags,set_flags->flags,set_flags->mask, target-Quoted 1 line
dbg_flags);drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0+ + set_flags->flags = prev_flags;for (i =0 ; i < target->n_pdds; i++) {struct kfd_process_device *pdd = target->pdds[i];
drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_set_flags(struct kfd_process *target, · line 560
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-2@@ -555,10 +559,8 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) else r =kfd_dbg_set_mes_debug_mode (pdd, true); -if (r) { - target->dbg_flags = prev_flags;
Doesn't rewind require the previous value for something to rewind to?
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1+if (r)break ; - } rewind_count++;}drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -596,7 +598,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target,bool unwind, int unwind
int i; if (!unwind) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1-uint32_t flags =0 ; +struct kfd_ioctl_dbg_trap_set_flags_args set_flags = {0 ,
Quoted 1 line
0xFFFFFFFF};
Similar to 3 comments above. Just call a new static or loop directly to reset debug mode (i.e. all flags clear).
i.e. you don't have to rewind on preemption failure here because deactivation itself is a rewind we're pretty much out of luck at this point if we fail.
Jon
Quoted 54 lines
int resume_count = resume_queues(target, 0, NULL); if (resume_count)drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -606,7 +608,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target,bool unwind, int unwind
kfd_dbg_clear_process_address_watch(target); kfd_dbg_trap_set_wave_launch_mode(target, 0);drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1-kfd_dbg_trap_set_flags (target, &flags); +kfd_dbg_trap_set_flags (target, &set_flags); }for (i =0 ; i < target->n_pdds; i++) {drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2
-1@@ -62,7 +62,8 @@ int kfd_dbg_trap_set_dev_address_watch(structkfd_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_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags); int kfd_dbg_trap_query_exception_info(struct kfd_process *target, uint32_t source_id,
uint32_texception_code,include/uapi/linux/kfd_ioctl.h +1
-0@@ -1515,6 +1515,7 @@ struct kfd_ioctl_dbg_trap_clear_node_address_watch_args { * Sets flags for wave behaviour. * * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled + * @mask (IN) - IN = specified debug trap operation bits on flag * * Generic errors apply (see kfd_dbg_trap_operations).* Return - 0 on SUCCESS.
include/uapi/linux/kfd_ioctl.h +1
-1@@ -1522,7 +1523,7 @@ structkfd_ioctl_dbg_trap_clear_node_address_watch_args { */ struct kfd_ioctl_dbg_trap_set_flags_args {__u32 flags; -__u32 pad; +__u32 mask; };/**
--
2.34.1
Hi Jon,
thanks!
Answers are in line.
Best Regards!
James Zhu
Quoted 10 lines · Jonathan
[Public]
Quoted 8 lines
-----Original Message-----
From: Zhu, James<[email protected]>
Sent: Monday, January 19, 2026 12:15 PM To:[email protected]
Cc: Six, Lancelot<[email protected]>; Kim, Jonathan <[email protected]>; Zhu, James<[email protected]>
Subject: [PATCH] drm/amdkfd: add mask for debug trap flag setting
Quoted 3 lines
Quoted 1 line
to specify which bits are valid setting on flags.
Can you elaborate?
Without mask setting, Need read current flags 1st, any update flags'
specified bits, others bits keep unchanged, then send absolute flags value to system.
mask can indicate which bits in flags are need to been touched, we can put value(0 or 1) into
those specified bits, and send to system directly without read back operation. For example. flags = 0x2 mask =0x3, will keep MSB31-MSB2 unchanged, LSB1 set to 1,LSB0 set 0.
Will update messages to:
*/apply masked bit update on debug trap flags/*
*/The implementation uses an XOR-AND-XOR pattern to atomically update bits within the 'set_flags->mask' range./*
*/Logic: /*
*/- Difference: (target_flags->flags ^ set_flags->flags) identifies bit mismatches. /*
*/- Filtering: The result is masked by 'set_flags->mask' to restrict changes. /*
*/- Application: XORing back to 'target_flags->flags' flips only the mismatched bits to the desired state./*
*/This approach avoids multiple assignment steps and preserves all bits outside of the mask./*
Quoted 72 lines
Quoted 33 lines
Signed-off-by James Zhu<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 48 ++++++++++++------------ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 +- include/uapi/linux/kfd_ioctl.h | 3 +- 4 files changed, 30 insertions(+), 26 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -3377,7 +3377,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep,struct
kfd_process*p, vargs->clear_node_address_watch.id); break; case KFD_IOC_DBG_TRAP_SET_FLAGS:drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1- r =kfd_dbg_trap_set_flags (target, &args->set_flags.flags); + r =kfd_dbg_trap_set_flags (target, &args->set_flags);break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : r = kfd_dbg_ev_query_debug_event(target,drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -512,38 +512,42 @@ static void kfd_dbg_clear_process_address_watch(struct kfd_process *target) kfd_dbg_trap_clear_dev_address_watch(target- > pdds[i], j);drivers/gpu/drm/amd/amdkfd/kfd_debug.c static void · line 523
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1} -int kfd_dbg_trap_set_flags (struct kfd_process *target,uint32_t *flags) +int kfd_dbg_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags) {uint32_t prev_flags = target->dbg_flags;int i, r =0 , rewind_count =0 ; +if (!((set_flags->flags ^ prev_flags) & set_flags->mask))Does this block old debuggers from setting debug mode if pad is 0? [JZ] Yes, this logical can been moved down after
target->dbg_flagsgets updated if (target->dbg_flags==prev_flags) return 0;Quoted 26 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1+return 0 ; +for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (target->pdds[i]- > dev->id);uint32_t caps = topo_dev->node_props.capability;uint32_t caps2 = topo_dev->node_props.capability2; +struct amdgpu_device *adev = target->pdds[i]->dev->adev; - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c static void kfd_dbg_clear_process_address_watch(struct kfd_process *target) · line 532
Quoted 5 lines
- (*flags &
KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE)) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-1- *flags = prev_flags; +if (set_flags->mask ==0xFFFFFFFF && !set_flags->flags) +break ;Seems like this is only for a deactivation system call.
Probably don't want to let users abuse this with a magic number then.
Maybe breakout into new static call in deactivation or just device loop deactivate directly there since this logic is starting to get complicated.
[JZ] Yes, only for deactivation system call.
Quoted 13 lines
Quoted 8 lines
+ if ((!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) ||
+ (!(caps &HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP))Quoted 5 lines
|| + (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE))) {
Quoted 1 line
Please vertically indent align "caps" and "
set_flags" underneath each other for legibility.
[JZ] sure
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0+ set_flags->flags = prev_flags; + dev_dbg(adev->dev, "Debug Trap set mask 0x%x caps0x%x caps2 0x%x",
+ set_flags->mask, caps, caps2); return -EACCES; } }
Quoted 6 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-2- target->dbg_flags = *flags; - *flags = prev_flags; + target->dbg_flags ^= (target->dbg_flags ^ set_flags->flags) & set_flags-Quoted 1 line
mask;
I assume we can only set/unset 1 flag at a time, which is why this works. Otherwise, maybe I don't have enough background on this, but please do elaborate.
[JZ] Here is not just for set/unset 1 bit. ^ is bitwise XOR.
target->dbg_flags ^ set_flags->flags can find which bits are changed
(set those bits to 1 if not equal), & set_flags-mask can filter out unrelated bits.
target->dbg_flags ^= can change related bits accordingly.
Quoted 12 lines
mask
Quoted 9 lines
+ pr_debug("Debug Trap previous flags 0x%x set flags 0x%x set mask 0x%x
target flags 0x%x",
+prev_flags,set_flags->flags,set_flags->mask, target-Quoted 1 line
dbg_flags);drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0+ + set_flags->flags = prev_flags;for (i =0 ; i < target->n_pdds; i++) {struct kfd_process_device *pdd = target->pdds[i];
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c int kfd_dbg_trap_set_flags(struct kfd_process *target, · line 560
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-2@@ -555,10 +559,8 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) else r =kfd_dbg_set_mes_debug_mode (pdd, true); -if (r) { - target->dbg_flags = prev_flags;Doesn't rewind require the previous value for something to rewind to?
[JZ] Yes, since after break, it will rewind flags over there when check r value at the end.
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1+if (r)break ; - } rewind_count++;}drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -596,7 +598,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target,bool unwind, int unwind
int i;
Quoted 6 lines
Quoted 4 lines
if (!unwind) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1-uint32_t flags =0 ; +struct kfd_ioctl_dbg_trap_set_flags_args set_flags = {0 ,
0xFFFFFFFF};Similar to 3 comments above. Just call a new static or loop directly to reset debug mode (i.e. all flags clear).
i.e. you don't have to rewind on preemption failure here because deactivation itself is a rewind we're pretty much out of luck at this point if we fail.
[JZ] I will send out v2 soon, See if your concern gets addressed or not.
Quoted 57 lines
Jon
Quoted 54 lines
int resume_count = resume_queues(target, 0, NULL); if (resume_count)drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-0@@ -606,7 +608,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target,bool unwind, int unwind
kfd_dbg_clear_process_address_watch(target); kfd_dbg_trap_set_wave_launch_mode(target, 0);drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1-kfd_dbg_trap_set_flags (target, &flags); +kfd_dbg_trap_set_flags (target, &set_flags); }for (i =0 ; i < target->n_pdds; i++) {drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2
-1@@ -62,7 +62,8 @@ int kfd_dbg_trap_set_dev_address_watch(structkfd_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_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags); int kfd_dbg_trap_query_exception_info(struct kfd_process *target, uint32_t source_id,
uint32_texception_code,include/uapi/linux/kfd_ioctl.h +1
-0@@ -1515,6 +1515,7 @@ struct kfd_ioctl_dbg_trap_clear_node_address_watch_args { * Sets flags for wave behaviour. * * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled + * @mask (IN) - IN = specified debug trap operation bits on flag * * Generic errors apply (see kfd_dbg_trap_operations).* Return - 0 on SUCCESS.
include/uapi/linux/kfd_ioctl.h +1
-1@@ -1522,7 +1523,7 @@ structkfd_ioctl_dbg_trap_clear_node_address_watch_args { */ struct kfd_ioctl_dbg_trap_set_flags_args {__u32 flags; -__u32 pad; +__u32 mask; };/**
--
2.34.1
[AMD Official Use Only - AMD Internal Distribution Only]
Hi,
Quoted 97 lines
-----Original Message-----
From: Zhu, James <[email protected]>
Sent: 19 January 2026 17:15
To: [email protected]
Cc: Six, Lancelot <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, James <[email protected]>
Subject: [PATCH] drm/amdkfd: add mask for debug trap flag settingto specify which bits are valid setting on flags.
Signed-off-by James Zhu <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 48 ++++++++++++------------ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 +- include/uapi/linux/kfd_ioctl.h | 3 +- 4 files changed, 30 insertions(+), 26 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -3377,7 +3377,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep,struct
kfd_process*p, vargs->clear_node_address_watch.id); break; case KFD_IOC_DBG_TRAP_SET_FLAGS:drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1- r =kfd_dbg_trap_set_flags (target, &args->set_flags.flags); + r =kfd_dbg_trap_set_flags (target, &args->set_flags);break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : r = kfd_dbg_ev_query_debug_event(target,drivers/gpu/drm/amd/amdkfd/kfd_debug.c +6
-2@@ -512,38 +512,42 @@ 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) +int kfd_dbg_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags) {uint32_t prev_flags = target->dbg_flags;int i, r =0 , rewind_count =0 ; +if (!((set_flags->flags ^ prev_flags) & set_flags->mask)) +return 0 ; +for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (target->pdds[i]- >dev->id);uint32_t caps = topo_dev->node_props.capability;uint32_t caps2 = topo_dev->node_props.capability2; +struct amdgpu_device *adev = target->pdds[i]->dev->adev; - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
- (*flags &KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE)) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1- *flags = prev_flags; +if (set_flags->mask ==0xFFFFFFFF && !set_flags->flags) +break ; + if ((!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) ||
+ (!(caps &HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP))|| + (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE))) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0+ set_flags->flags = prev_flags; + dev_dbg(adev->dev, "Debug Trap set mask 0x%x caps
Quoted 2 lines
0x%x caps2 0x%x",
+set_flags->mask, caps, caps2);
The logic here seems odd. If "set_flags->mask" is the set of flags a caller wants to modify (I don't think it should, see below), a call which asks for PRECISE_MEMORY to be disabled would return EACCESS if PRECISE_MEMORY is not supported. Before this patch, it would have been perfectly valid set (or confirm) the PRECISE_MEMORY flag to 0.
Also, consider the following scenario where a user wants to set PRECISE_ALU=0 and PRECISE_MEMORY=1:
set_flags->flags = KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP; set_flags->mask = KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP | KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP;
If the platform only supports PRECISE_MEMORY (like gfx11 for example), the call would erroneously fail with EACCESS. This was possible before this patch.
Quoted 71 lines
return -EACCES; } }drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-2- target->dbg_flags = *flags; - *flags = prev_flags; + target->dbg_flags ^= (target->dbg_flags ^ set_flags->flags) & set_flags-Quoted 1 line
mask;
+ pr_debug("Debug Trap previous flags 0x%x set flags 0x%x set mask
0x%x target flags 0x%x",drivers/gpu/drm/amd/amdkfd/kfd_debug.c +4
-3+ prev_flags, set_flags->flags, set_flags->mask, target->dbg_flags); + + set_flags->flags = prev_flags;for (i =0 ; i < target->n_pdds; i++) {struct kfd_process_device *pdd = target->pdds[i];@@ -555,10 +559,8 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) else r =kfd_dbg_set_mes_debug_mode (pdd, true); -if (r) { - target->dbg_flags = prev_flags; +if (r)break ; - } rewind_count++;}drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1@@ -596,7 +598,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindint i;if (!unwind) { -uint32_t flags =0 ; +struct kfd_ioctl_dbg_trap_set_flags_args set_flags = {0 ,0xFFFFFFFF };int resume_count =resume_queues (target,0 ,NULL );if (
resume_count)drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1@@ -606,7 +608,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindkfd_dbg_clear_process_address_watch (target );kfd_dbg_trap_set_wave_launch_mode (target,0 ); -kfd_dbg_trap_set_flags (target, &flags); +kfd_dbg_trap_set_flags (target, &set_flags); }for (i = 0; i < target->n_pdds; i++) {drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2
-1@@ -62,7 +62,8 @@ int kfd_dbg_trap_set_dev_address_watch(structkfd_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_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags); int kfd_dbg_trap_query_exception_info(struct kfd_process *target, uint32_t source_id,
uint32_texception_code,include/uapi/linux/kfd_ioctl.h +0
-0
include/uapi/linux/kfd_ioctl.h struct · line 1519
Quoted 5 lines
include/uapi/linux/kfd_ioctl.h +1
-0@@ -1515,6 +1515,7 @@ struct kfd_ioctl_dbg_trap_clear_node_address_watch_args { * Sets flags for wave behaviour. * * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled + * @mask (IN) - IN = specified debug trap operation bits on flag
I am not sure I fully understand this comment. Is it meant to say which bits from FLAGS will be set?
Also, this seems to break backwards compatibility. Before this patch, a caller would call this ioctl with "flags" set, and the PAD field would be 0. The semantics of this call is to set all bits from flags. The updated semantics of MASK would make it so no flags are set instead of alle.
The updated ioctl must preserve this existing pattern, so instead of mask telling which bits must be changed, it should specify which bits should be preserved (or ignored from FLAGS).
To make it clearer, I'd probably call this "preserve_mask"
@preserve_mask (IN) - IN = Specify flags which must not be modified.
Best,
Lancelot.
Quoted 15 lines
include/uapi/linux/kfd_ioctl.h +0
-0* * Generic errors apply (see kfd_dbg_trap_operations). * Return - 0 on SUCCESS.
include/uapi/linux/kfd_ioctl.h +1
-1@@ -1522,7 +1523,7 @@ structkfd_ioctl_dbg_trap_clear_node_address_watch_args { */ struct kfd_ioctl_dbg_trap_set_flags_args {__u32 flags; -__u32 pad; +__u32 mask; };/**
--
2.34.1
Quoted 108 lines · Lancelot
[AMD Official Use Only - AMD Internal Distribution Only]
Hi,
Quoted 97 lines
-----Original Message-----
From: Zhu, James<[email protected]>
Sent: 19 January 2026 17:15 To:[email protected]
Cc: Six, Lancelot<[email protected]>; Kim, Jonathan <[email protected]>; Zhu, James<[email protected]>
Subject: [PATCH] drm/amdkfd: add mask for debug trap flag settingto specify which bits are valid setting on flags.
Signed-off-by James Zhu<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 48 ++++++++++++------------ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 +- include/uapi/linux/kfd_ioctl.h | 3 +- 4 files changed, 30 insertions(+), 26 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -3377,7 +3377,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep,struct
kfd_process*p, vargs->clear_node_address_watch.id); break; case KFD_IOC_DBG_TRAP_SET_FLAGS:drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1- r =kfd_dbg_trap_set_flags (target, &args->set_flags.flags); + r =kfd_dbg_trap_set_flags (target, &args->set_flags);break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : r = kfd_dbg_ev_query_debug_event(target,drivers/gpu/drm/amd/amdkfd/kfd_debug.c +6
-2@@ -512,38 +512,42 @@ 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) +int kfd_dbg_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags) {uint32_t prev_flags = target->dbg_flags;int i, r =0 , rewind_count =0 ; +if (!((set_flags->flags ^ prev_flags) & set_flags->mask)) +return 0 ; +for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (target->pdds[i]- > dev->id);uint32_t caps = topo_dev->node_props.capability;uint32_t caps2 = topo_dev->node_props.capability2; +struct amdgpu_device *adev = target->pdds[i]->dev->adev; - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
- (*flags &KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE)) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1- *flags = prev_flags; +if (set_flags->mask ==0xFFFFFFFF && !set_flags->flags) +break ; + if ((!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) ||
+ (!(caps &HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP))|| + (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE))) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0+ set_flags->flags = prev_flags; + dev_dbg(adev->dev, "Debug Trap set mask 0x%x capsQuoted 2 lines
0x%x caps2 0x%x",
+set_flags->mask, caps, caps2);The logic here seems odd. If "
set_flags->mask" is the set of flags a caller wants to modify (I don't think it should, see below), a call which asks forPRECISE_MEMORYto be disabled would return EACCESS ifPRECISE_MEMORYis not supported. Before this patch, it would have been perfectly valid set (or confirm) thePRECISE_MEMORYflag to 0. [JZ] the logical here is checking input setting, if caps does not support such feature, mask trys to set this feature bit, then exit with-EACCESS.
Also, consider the following scenario where a user wants to set PRECISE_ALU=0 and PRECISE_MEMORY=1:
Quoted 4 lines
set_flags->flags = KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP; set_flags->mask = KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP | KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP;If the platform only supports
PRECISE_MEMORY(like gfx11 for example), the call would erroneously fail with EACCESS. This was possible before this patch.
[JZ] then mask should not include KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP which tells user want to clear KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP on this
ASIC, but it actually not been supported. err tells user that the operation clearing PRECISE_ALU is invalid.
Quoted 79 lines
Quoted 72 lines
return -EACCES; } }drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-2- target->dbg_flags = *flags; - *flags = prev_flags; + target->dbg_flags ^= (target->dbg_flags ^ set_flags->flags) & set_flags-Quoted 1 line
mask;
+ pr_debug("Debug Trap previous flags 0x%x set flags 0x%x set mask
0x%x target flags 0x%x",drivers/gpu/drm/amd/amdkfd/kfd_debug.c +4
-3+ prev_flags, set_flags->flags, set_flags->mask, target->dbg_flags); + + set_flags->flags = prev_flags;for (i =0 ; i < target->n_pdds; i++) {struct kfd_process_device *pdd = target->pdds[i];@@ -555,10 +559,8 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) else r =kfd_dbg_set_mes_debug_mode (pdd, true); -if (r) { - target->dbg_flags = prev_flags; +if (r)break ; - } rewind_count++;}drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1@@ -596,7 +598,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindint i;if (!unwind) { -uint32_t flags =0 ; +struct kfd_ioctl_dbg_trap_set_flags_args set_flags = {0 ,0xFFFFFFFF };int resume_count =resume_queues (target,0 ,NULL );if (
resume_count)drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1@@ -606,7 +608,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindkfd_dbg_clear_process_address_watch (target );kfd_dbg_trap_set_wave_launch_mode (target,0 ); -kfd_dbg_trap_set_flags (target, &flags); +kfd_dbg_trap_set_flags (target, &set_flags); }for (i = 0; i < target->n_pdds; i++) {drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2
-1@@ -62,7 +62,8 @@ int kfd_dbg_trap_set_dev_address_watch(structkfd_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_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags); int kfd_dbg_trap_query_exception_info(struct kfd_process *target, uint32_t source_id,
uint32_texception_code,include/uapi/linux/kfd_ioctl.h +0
-0include/uapi/linux/kfd_ioctl.h struct · line 1519
Quoted 5 lines
include/uapi/linux/kfd_ioctl.h +1
-0@@ -1515,6 +1515,7 @@ struct kfd_ioctl_dbg_trap_clear_node_address_watch_args { * Sets flags for wave behaviour. * * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled + * @mask (IN) - IN = specified debug trap operation bits on flagI am not sure I fully understand this comment. Is it meant to say which bits from FLAGS will be set?
Quoted 1 line
Also, this seems to break backwards compatibility. Before this patch, a caller would call this ioctl with "flags" set, and the PAD field would be 0. The semantics of this call is to set all bits from flags. The updated semantics of MASK would make it so no flags are set instead of alle.
[JZ] Jon has pointed out this. I have a new version to fix it. I will add below code fallback to old version. if (!set_flags->mask)
set_flags->mask = set_flags->flags;
Quoted 4 lines
The updated ioctl must preserve this existing pattern, so instead of mask telling which bits must be changed, it should specify which bits should be preserved (or ignored from FLAGS).
To make it clearer, I'd probably call this "
preserve_mask"
[JZ] to use mask to tell which bits in flag will be modified seem more straightforward.
Quoted 21 lines
@preserve_mask (IN) - IN = Specify flags which must not be modified.
Best,
Lancelot.Quoted 15 lines
include/uapi/linux/kfd_ioctl.h +0
-0* * Generic errors apply (see kfd_dbg_trap_operations). * Return - 0 on SUCCESS.
include/uapi/linux/kfd_ioctl.h +1
-1@@ -1522,7 +1523,7 @@ structkfd_ioctl_dbg_trap_clear_node_address_watch_args { */ struct kfd_ioctl_dbg_trap_set_flags_args {__u32 flags; -__u32 pad; +__u32 mask; };/**
--
2.34.1
Quoted 110 lines · James Zhu
Quoted 108 lines · Lancelot
[AMD Official Use Only - AMD Internal Distribution Only]
Hi,
Quoted 97 lines
-----Original Message-----
From: Zhu, James<[email protected]>
Sent: 19 January 2026 17:15 To:[email protected]
Cc: Six, Lancelot<[email protected]>; Kim, Jonathan <[email protected]>; Zhu, James<[email protected]>
Subject: [PATCH] drm/amdkfd: add mask for debug trap flag settingto specify which bits are valid setting on flags.
Signed-off-by James Zhu<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_debug.c | 48 ++++++++++++------------ drivers/gpu/drm/amd/amdkfd/kfd_debug.h | 3 +- include/uapi/linux/kfd_ioctl.h | 3 +- 4 files changed, 30 insertions(+), 26 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -3377,7 +3377,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep,struct
kfd_process*p, vargs->clear_node_address_watch.id); break; case KFD_IOC_DBG_TRAP_SET_FLAGS:drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1- r =kfd_dbg_trap_set_flags (target, &args->set_flags.flags); + r =kfd_dbg_trap_set_flags (target, &args->set_flags);break ;case KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT : r = kfd_dbg_ev_query_debug_event(target,drivers/gpu/drm/amd/amdkfd/kfd_debug.c +6
-2@@ -512,38 +512,42 @@ 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) +int kfd_dbg_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags) {uint32_t prev_flags = target->dbg_flags;int i, r =0 , rewind_count =0 ; +if (!((set_flags->flags ^ prev_flags) & set_flags->mask)) +return 0 ; +for (i =0 ; i < target->n_pdds; i++) {struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (target->pdds[i]- > dev->id);uint32_t caps = topo_dev->node_props.capability;uint32_t caps2 = topo_dev->node_props.capability2; +struct amdgpu_device *adev = target->pdds[i]->dev->adev; - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&drivers/gpu/drm/amd/amdkfd/kfd_debug.c +0
-6- (*flags & KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP)) { - *flags = prev_flags; -return -EACCES ; - } - - if (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
- (*flags &KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE)) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +3
-1- *flags = prev_flags; +if (set_flags->mask ==0xFFFFFFFF && !set_flags->flags) +break ; + if ((!(caps &
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) ||
+ (!(caps &HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP))|| + (!(caps2 &
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
+ (set_flags->mask&KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE))) {drivers/gpu/drm/amd/amdkfd/kfd_debug.c +2
-0+ set_flags->flags = prev_flags; + dev_dbg(adev->dev, "Debug Trap set mask 0x%x capsQuoted 2 lines
0x%x caps2 0x%x",
+set_flags->mask, caps, caps2);The logic here seems odd. If "
set_flags->mask" is the set of flags a caller wants to modify (I don't think it should, see below), a call which asks forPRECISE_MEMORYto be disabled would return EACCESS ifPRECISE_MEMORYis not supported. Before this patch, it would have been perfectly valid set (or confirm) thePRECISE_MEMORYflag to 0. [JZ] the logical here is checking input setting, if caps does not support such feature, mask trys to set this feature bit, then exit with-EACCESS.
Also, consider the following scenario where a user wants to set PRECISE_ALU=0 and PRECISE_MEMORY=1:
Quoted 8 lines
Quoted 4 lines
set_flags->flags = KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP; set_flags->mask = KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP | KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP;If the platform only supports
PRECISE_MEMORY(like gfx11 for example), the call would erroneously fail with EACCESS. This was possible before this patch.[JZ] then mask should not include
KFD_DBG_TRAP_FLAG_SINGLE_ALU_OPwhich tells user want to clearKFD_DBG_TRAP_FLAG_SINGLE_ALU_OPon thisASIC, but it actually not been supported. err tells user that the operation clearing
PRECISE_ALUis invalid.
See below.
Quoted 80 lines
Quoted 79 lines
Quoted 72 lines
return -EACCES; } }drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-2- target->dbg_flags = *flags; - *flags = prev_flags; + target->dbg_flags ^= (target->dbg_flags ^ set_flags->flags) & set_flags-Quoted 1 line
mask;
+ pr_debug("Debug Trap previous flags 0x%x set flags 0x%x set mask
0x%x target flags 0x%x",drivers/gpu/drm/amd/amdkfd/kfd_debug.c +4
-3+ prev_flags, set_flags->flags, set_flags->mask, target->dbg_flags); + + set_flags->flags = prev_flags;for (i =0 ; i < target->n_pdds; i++) {struct kfd_process_device *pdd = target->pdds[i];@@ -555,10 +559,8 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, uint32_t *flags) else r =kfd_dbg_set_mes_debug_mode (pdd, true); -if (r) { - target->dbg_flags = prev_flags; +if (r)break ; - } rewind_count++;}drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1@@ -596,7 +598,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindint i;if (!unwind) { -uint32_t flags =0 ; +struct kfd_ioctl_dbg_trap_set_flags_args set_flags = {0 ,0xFFFFFFFF };int resume_count =resume_queues (target,0 ,NULL );if (
resume_count)drivers/gpu/drm/amd/amdkfd/kfd_debug.c +1
-1@@ -606,7 +608,7 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwindkfd_dbg_clear_process_address_watch (target );kfd_dbg_trap_set_wave_launch_mode (target,0 ); -kfd_dbg_trap_set_flags (target, &flags); +kfd_dbg_trap_set_flags (target, &set_flags); }for (i = 0; i < target->n_pdds; i++) {drivers/gpu/drm/amd/amdkfd/kfd_debug.h +2
-1@@ -62,7 +62,8 @@ int kfd_dbg_trap_set_dev_address_watch(structkfd_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_trap_set_flags (struct kfd_process *target, +struct kfd_ioctl_dbg_trap_set_flags_args *set_flags); int kfd_dbg_trap_query_exception_info(struct kfd_process *target, uint32_t source_id,
uint32_texception_code,include/uapi/linux/kfd_ioctl.h +0
-0include/uapi/linux/kfd_ioctl.h struct · line 1519
Quoted 5 lines
include/uapi/linux/kfd_ioctl.h +1
-0@@ -1515,6 +1515,7 @@ struct kfd_ioctl_dbg_trap_clear_node_address_watch_args { * Sets flags for wave behaviour. * * @flags (IN/OUT) - IN = flags to enable, OUT = flags previously enabled + * @mask (IN) - IN = specified debug trap operation bits on flagI am not sure I fully understand this comment. Is it meant to say which bits from FLAGS will be set?
Quoted 1 line
Also, this seems to break backwards compatibility. Before this patch, a caller would call this ioctl with "flags" set, and the PAD field would be 0. The semantics of this call is to set all bits from flags. The updated semantics of MASK would make it so no flags are set instead of alle.
Quoted 8 lines
[JZ] Jon has pointed out this. I have a new version to fix it. I will add below code fallback to old version.
if (!set_flags->mask)
set_flags->mask=set_flags->flags;Quoted 3 lines
The updated ioctl must preserve this existing pattern, so instead of mask telling which bits must be changed, it should specify which bits should be preserved (or ignored from FLAGS).
To make it clearer, I'd probably call this "
preserve_mask"[JZ] to use mask to tell which bits in flag will be modified seem more straightforward.
I agree, but I don't think this is relevant.
There are clients today using this ioctl, which 0-initialize the bits used to hold MASK.
If you change the meaning of those bits, this breaks backwards compatibility, and this is a no-go.
I see 2 options:
- add the MASK field after the existing PAD (effectively extend the struct).
- Re-use PAD's bit to hold the mask, in which case we need to ensure that old patterns contiune to work as they do today: setting 0s means to replace all flags, and it is valid to ask clear flags which are not supported for the current platform.
I don't have a strong opinion either way, just need to make sure old clients continue to work once this patch lands.
Best,
Lancelot.
Quoted 20 lines
Quoted 20 lines
@preserve_mask (IN) - IN = Specify flags which must not be modified.
Best,
Lancelot.Quoted 15 lines
include/uapi/linux/kfd_ioctl.h +0
-0* * Generic errors apply (see kfd_dbg_trap_operations). * Return - 0 on SUCCESS.
include/uapi/linux/kfd_ioctl.h +1
-1@@ -1522,7 +1523,7 @@ structkfd_ioctl_dbg_trap_clear_node_address_watch_args { */ struct kfd_ioctl_dbg_trap_set_flags_args {__u32 flags; -__u32 pad; +__u32 mask; };/**
--
2.34.1