All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on
@ 2026-11-23  2:47 Jesse Zhang
  2026-11-23  2:47 ` [PATCH v3 2/3] drm/amdkfd: return the memory violation data to the debugger Jesse Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jesse Zhang @ 2026-11-23  2:47 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Felix Kuehling, Jonathan Kim, Jesse Zhang

A process has a PDD for every device, also the ones it never acquired a
VM on, and pdd->drm_priv of those is NULL. kfd_flush_tlb() dereferences
it unconditionally, which is how suspend_queues() oopsed before the
previous patch.

Return early from kfd_flush_tlb() when there is no VM to flush, so no
caller can oops on such a PDD.

Suggested-by: Jonathan Kim <jonathan.kim@amd.com>
Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 30797e1886d9..e84e364b4d64 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1608,7 +1608,13 @@ void kfd_signal_process_terminate_event(struct kfd_process *p);
 static inline void kfd_flush_tlb(struct kfd_process_device *pdd)
 {
 	struct amdgpu_device *adev = pdd->dev->adev;
-	struct amdgpu_vm *vm = drm_priv_to_vm(pdd->drm_priv);
+	struct amdgpu_vm *vm;
+
+	/* A PDD can exist before the process acquires a VM on this device. */
+	if (!pdd->drm_priv)
+		return;
+
+	vm = drm_priv_to_vm(pdd->drm_priv);
 
 	amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_HEAVYWEIGHT,
 				    pdd->dev->xcc_mask);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/3] drm/amdkfd: return the memory violation data to the debugger
  2026-11-23  2:47 [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on Jesse Zhang
@ 2026-11-23  2:47 ` Jesse Zhang
  2026-11-23  2:47 ` [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails Jesse Zhang
  2026-11-23  3:12 ` [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on sashiko-bot
  2 siblings, 0 replies; 6+ messages in thread
From: Jesse Zhang @ 2026-11-23  2:47 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Felix Kuehling, Jonathan Kim, Jesse Zhang

kfd_dbg_ev_raise() saves the memory exception data of a GPU VM fault for a
debugger subscribed to EC_DEVICE_MEMORY_VIOLATION, but never sets
vm_fault_exc_data_size. QUERY_EXCEPTION_INFO copies that many bytes, so the
debugger always gets 0 bytes and no fault address.

With a process debugging itself and a KFD SDMA queue writing to an
unmapped VA:

  amdgpu 0000:03:00.0: [gfxhub] page fault (src_id:0 ring:40 vmid:8 pasid:63)
  amdgpu 0000:03:00.0:   in page starting at address 0x0000000060200000 from client 10
  amdgpu 0000:03:00.0: 	 Faulty UTCL2 client ID: SDMA0 (0xd)
  memory violation info: 0 bytes, va 0x0 gpu_id 0, fault at 0x60200000

With the size set:

  memory violation info: 32 bytes, va 0x60200000 gpu_id 51573, fault at 0x60200000

The data is also only freed by a query clearing the exception, free it with
the process device as well.

Fixes: 2b36de971d25 ("drm/amdkfd: add debug query exception info operation")
Reviewed-by: Jonathan Kim <jonathan.kim@amd.com>
Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_debug.c   | 4 +++-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
index d5c87de519ac..14e7ee30cbdf 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
@@ -143,7 +143,9 @@ bool kfd_dbg_ev_raise(uint64_t event_mask,
 							exception_data,
 							exception_data_size,
 							GFP_KERNEL);
-					if (!pdd->vm_fault_exc_data)
+					if (pdd->vm_fault_exc_data)
+						pdd->vm_fault_exc_data_size = exception_data_size;
+					else
 						pr_debug("Failed to allocate exception data memory");
 				} else {
 					pr_debug("Debugger exception data not saved\n");
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index aae2c698103e..44b11950b7db 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -1289,6 +1289,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
 		atomic_dec(&pdd->dev->kfd->kfd_processes_count);
 		mutex_destroy(&pdd->doorbell_mutex);
 
+		kfree(pdd->vm_fault_exc_data);
 		kfree(pdd);
 		p->pdds[i] = NULL;
 	}
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails
  2026-11-23  2:47 [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on Jesse Zhang
  2026-11-23  2:47 ` [PATCH v3 2/3] drm/amdkfd: return the memory violation data to the debugger Jesse Zhang
@ 2026-11-23  2:47 ` Jesse Zhang
  2026-11-23  3:11   ` sashiko-bot
  2026-11-23 15:08   ` Kim, Jonathan
  2026-11-23  3:12 ` [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on sashiko-bot
  2 siblings, 2 replies; 6+ messages in thread
From: Jesse Zhang @ 2026-11-23  2:47 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Felix Kuehling, Jonathan Kim, Jesse Zhang

KFD_IOC_DBG_TRAP_ENABLE stores the caller in target->debugger_process
before calling kfd_dbg_trap_enable(), and nothing resets it when that
fails (-EALREADY, -ENODEV, -EBUSY, -EBADF for a bad dbg_fd, -EFAULT).
The permission check at the top of kfd_ioctl_set_debug_trap() accepts
any caller equal to target->debugger_process, so the caller keeps
debug access after it stopped ptracing the target. The pointer is also
not reference counted, so it dangles once the caller exits, and a later
successful ENABLE by the target itself increments
debugged_process_count of the freed process.

A parent that ptraces its child, tries to enable debugging with
dbg_fd = -1 (-EBADF) and then detaches can still enable debugging on
the child with a valid fd:

  1. ptraced, ENABLE with dbg_fd=-1      -> -9 (Bad file descriptor)
  2. ptrace detached
  3. not ptraced, ENABLE with valid fd  -> 0 (success)

An ENABLE of an already enabled session also overwrites the pointer
temporarily, so the exit of the debugger of that session, which looks
for its targets by this pointer before taking target->mutex, can miss
the target and leave its debug mode enabled.

Set the pointer in kfd_dbg_trap_enable() only once the session is
enabled, and clear it again when copying the runtime info fails. Step 3
now fails with -EPERM.

v2: clear the pointer instead of restoring it (Jon)
v3: set the pointer in kfd_dbg_trap_enable() (Jon)

Fixes: 0ab2d7532b05 ("drm/amdkfd: prepare per-process debug enable and disable")
Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 +----
 drivers/gpu/drm/amd/amdkfd/kfd_debug.c   | 7 +++++--
 drivers/gpu/drm/amd/amdkfd/kfd_debug.h   | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 3d2136adb62b..5785cb8b4393 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -3227,10 +3227,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v
 
 	switch (args->op) {
 	case KFD_IOC_DBG_TRAP_ENABLE:
-		if (target != p)
-			target->debugger_process = p;
-
-		r = kfd_dbg_trap_enable(target,
+		r = kfd_dbg_trap_enable(target, p,
 					args->enable.dbg_fd,
 					(void __user *)args->enable.rinfo_ptr,
 					&args->enable.rinfo_size);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
index 14e7ee30cbdf..f7d5dc90f8e1 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
@@ -781,8 +781,8 @@ int kfd_dbg_trap_activate(struct kfd_process *target)
 	return r;
 }
 
-int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
-			void __user *runtime_info, uint32_t *runtime_size)
+int kfd_dbg_trap_enable(struct kfd_process *target, struct kfd_process *debugger,
+			uint32_t fd, void __user *runtime_info, uint32_t *runtime_size)
 {
 	struct file *f;
 	uint32_t copy_size;
@@ -823,6 +823,8 @@ int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
 	kref_get(&target->ref);
 	target->debug_trap_enabled = true;
 
+	if (target != debugger)
+		target->debugger_process = debugger;
 	if (target->debugger_process)
 		atomic_inc(&target->debugger_process->debugged_process_count);
 
@@ -832,6 +834,7 @@ int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
 		target->dbg_ev_file = NULL;
 		if (target->debugger_process)
 			atomic_dec(&target->debugger_process->debugged_process_count);
+		target->debugger_process = NULL;
 		target->debug_trap_enabled = false;
 		kfd_unref_process(target);
 		r = -EFAULT;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.h b/drivers/gpu/drm/amd/amdkfd/kfd_debug.h
index 5babf9b992cd..f675fe6ed353 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.h
@@ -44,8 +44,8 @@ bool kfd_dbg_ev_raise(uint64_t event_mask,
 			void *exception_data,
 			size_t exception_data_size);
 int kfd_dbg_trap_disable(struct kfd_process *target, bool drain_irqs);
-int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
-			void __user *runtime_info,
+int kfd_dbg_trap_enable(struct kfd_process *target, struct kfd_process *debugger,
+			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,
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails
  2026-11-23  2:47 ` [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails Jesse Zhang
@ 2026-11-23  3:11   ` sashiko-bot
  2026-11-23 15:08   ` Kim, Jonathan
  1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23  3:11 UTC (permalink / raw)
  To: Jesse Zhang, amd-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdkfd: premature debugger_process store in
  kfd_dbg_trap_enable()
--

commit aae136214c876252feb4eb6f8aa225bc102db225
Author: Jesse Zhang <Jesse.Zhang@amd.com>

drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails

This commit moves the assignment of target->debugger_process into
kfd_dbg_trap_enable() and clears it if copy_to_user() fails, preventing a
failed KFD_IOC_DBG_TRAP_ENABLE call from leaving target->debugger_process
set.

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> index a025c3189753b..cf62aaffc2600 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> @@ -793,8 +793,8 @@ int kfd_dbg_trap_activate(struct kfd_process *target)
>  	return r;
>  }
>  
> -int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
> -			void __user *runtime_info, uint32_t *runtime_size)
> +int kfd_dbg_trap_enable(struct kfd_process *target, struct kfd_process *debugger,
> +			uint32_t fd, void __user *runtime_info, uint32_t *runtime_size)
>  {
>  	struct file *f;
>  	uint32_t copy_size;
> @@ -835,6 +835,8 @@ int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
>  	kref_get(&target->ref);
>  	target->debug_trap_enabled = true;
>  
> +	if (target != debugger)
> +		target->debugger_process = debugger;
>  	if (target->debugger_process)
>  		atomic_inc(&target->debugger_process->debugged_process_count);
>  
> @@ -844,6 +846,7 @@ int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
>  		target->dbg_ev_file = NULL;
>  		if (target->debugger_process)
>  			atomic_dec(&target->debugger_process->debugged_process_count);
> +		target->debugger_process = NULL;
>  		target->debug_trap_enabled = false;
>  		kfd_unref_process(target);
>  		r = -EFAULT;

[Severity: Medium]
Can setting target->debugger_process before copy_to_user() still allow the
caller to bypass the ptrace check in kfd_ioctl_set_debug_trap()?

kfd_ioctl_set_debug_trap() checks target->debugger_process before taking
target->mutex:

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:kfd_ioctl_set_debug_trap() {
    ...
	rcu_read_lock();
	if (target != p && ptrace_parent(target->lead_thread) != current
			&& target->debugger_process != p) {
		pr_err("PID %i is not PTRACED and cannot be debugged\n", args->pid);
		r = -EPERM;
	}
	rcu_read_unlock();

	if (r)
		goto out;

	mutex_lock(&target->mutex);
    ...
}

If copy_to_user() sleeps (for example via userfaultfd) and then fails with
-EFAULT, a second thread in the debugger process can pass the unlocked
permission check after ptrace is detached and wait on target->mutex:

CPU0                              CPU1
kfd_ioctl_set_debug_trap()
  mutex_lock(&target->mutex)
  kfd_dbg_trap_enable()
    target->debugger_process = p
    copy_to_user() [sleeps]
                                  [ptrace detached]
                                  kfd_ioctl_set_debug_trap()
                                    target->debugger_process == p
                                    mutex_lock(&target->mutex)
    /* copy_to_user() fails */
    target->debugger_process = NULL
    target->debug_trap_enabled = false
  mutex_unlock(&target->mutex)
                                    kfd_dbg_trap_enable()  <-- succeeds without ptrace

Could copy_to_user() be called before setting target->debugger_process and
activating the debug session?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123024737.1475714-1-Jesse.Zhang@amd.com?part=3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on
  2026-11-23  2:47 [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on Jesse Zhang
  2026-11-23  2:47 ` [PATCH v3 2/3] drm/amdkfd: return the memory violation data to the debugger Jesse Zhang
  2026-11-23  2:47 ` [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails Jesse Zhang
@ 2026-11-23  3:12 ` sashiko-bot
  2 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23  3:12 UTC (permalink / raw)
  To: Jesse Zhang, amd-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/amdkfd: commit message cites missing patch and omits Fixes
  trailer
--

commit 49a7c752d976cee4f89634bba3990ab398ece2e3
Author: Jesse Zhang <Jesse.Zhang@amd.com>

> drm/amdkfd: don't flush the TLB of a device the process has no VM on
>
> A process has a PDD for every device, also the ones it never acquired a
> VM on, and pdd->drm_priv of those is NULL. kfd_flush_tlb() dereferences
> it unconditionally, which is how suspend_queues() oopsed before the
> previous patch.
>
> Return early from kfd_flush_tlb() when there is no VM to flush, so no
> caller can oops on such a PDD.
>
> Suggested-by: Jonathan Kim <jonathan.kim@amd.com>
> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>

[Severity: Low]
There is no preceding patch in the tree modifying suspend_queues(), which
still calls kfd_flush_tlb(pdd) on PDDs without a VM when total_suspended >
0.  Because this commit directly fixes that NULL pointer dereference,
should the reference to a previous patch be updated and a Fixes tag added?

  Fixes: f5c4f88e0f9c ("drm/amdkfd: Add TLB flush after MES queue eviction/suspension")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123024737.1475714-1-Jesse.Zhang@amd.com?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails
  2026-11-23  2:47 ` [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails Jesse Zhang
  2026-11-23  3:11   ` sashiko-bot
@ 2026-11-23 15:08   ` Kim, Jonathan
  1 sibling, 0 replies; 6+ messages in thread
From: Kim, Jonathan @ 2026-11-23 15:08 UTC (permalink / raw)
  To: Zhang, Jesse(Jie), amd-gfx@lists.freedesktop.org
  Cc: Deucher, Alexander, Kuehling, Felix, Zhang, Jesse(Jie)

Public

> -----Original Message-----
> From: Jesse Zhang <Jesse.Zhang@amd.com>
> Sent: Sunday, November 22, 2026 9:47 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix
> <Felix.Kuehling@amd.com>; Kim, Jonathan <Jonathan.Kim@amd.com>; Zhang,
> Jesse(Jie) <Jesse.Zhang@amd.com>
> Subject: [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when
> DBG_TRAP_ENABLE fails
>
> KFD_IOC_DBG_TRAP_ENABLE stores the caller in target->debugger_process
> before calling kfd_dbg_trap_enable(), and nothing resets it when that
> fails (-EALREADY, -ENODEV, -EBUSY, -EBADF for a bad dbg_fd, -EFAULT).
> The permission check at the top of kfd_ioctl_set_debug_trap() accepts
> any caller equal to target->debugger_process, so the caller keeps
> debug access after it stopped ptracing the target. The pointer is also
> not reference counted, so it dangles once the caller exits, and a later
> successful ENABLE by the target itself increments
> debugged_process_count of the freed process.
>
> A parent that ptraces its child, tries to enable debugging with
> dbg_fd = -1 (-EBADF) and then detaches can still enable debugging on
> the child with a valid fd:
>
>   1. ptraced, ENABLE with dbg_fd=-1      -> -9 (Bad file descriptor)
>   2. ptrace detached
>   3. not ptraced, ENABLE with valid fd  -> 0 (success)
>
> An ENABLE of an already enabled session also overwrites the pointer
> temporarily, so the exit of the debugger of that session, which looks
> for its targets by this pointer before taking target->mutex, can miss
> the target and leave its debug mode enabled.
>
> Set the pointer in kfd_dbg_trap_enable() only once the session is
> enabled, and clear it again when copying the runtime info fails. Step 3
> now fails with -EPERM.
>
> v2: clear the pointer instead of restoring it (Jon)
> v3: set the pointer in kfd_dbg_trap_enable() (Jon)
>
> Fixes: 0ab2d7532b05 ("drm/amdkfd: prepare per-process debug enable and
> disable")
> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 +----
>  drivers/gpu/drm/amd/amdkfd/kfd_debug.c   | 7 +++++--
>  drivers/gpu/drm/amd/amdkfd/kfd_debug.h   | 4 ++--
>  3 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 3d2136adb62b..5785cb8b4393 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -3227,10 +3227,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep,
> struct kfd_process *p, v
>
>       switch (args->op) {
>       case KFD_IOC_DBG_TRAP_ENABLE:
> -             if (target != p)
> -                     target->debugger_process = p;
> -
> -             r = kfd_dbg_trap_enable(target,
> +             r = kfd_dbg_trap_enable(target, p,
>                                       args->enable.dbg_fd,
>                                       (void __user *)args->enable.rinfo_ptr,
>                                       &args->enable.rinfo_size);
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> index 14e7ee30cbdf..f7d5dc90f8e1 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> @@ -781,8 +781,8 @@ int kfd_dbg_trap_activate(struct kfd_process *target)
>       return r;
>  }
>
> -int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
> -                     void __user *runtime_info, uint32_t *runtime_size)
> +int kfd_dbg_trap_enable(struct kfd_process *target, struct kfd_process
> *debugger,
> +                     uint32_t fd, void __user *runtime_info, uint32_t
> *runtime_size)
>  {
>       struct file *f;
>       uint32_t copy_size;
> @@ -823,6 +823,8 @@ int kfd_dbg_trap_enable(struct kfd_process *target,
> uint32_t fd,
>       kref_get(&target->ref);
>       target->debug_trap_enabled = true;
>
> +     if (target != debugger)
> +             target->debugger_process = debugger;
>       if (target->debugger_process)

We can probably get rid of this test and tuck the atomic_inc under the target != debugger test after debugger_process has been assigned, as create_process will assign debugger_process as NULL by default.

With that fixed this patch is Reviewed-by: Jonathan Kim <Jonathan.kim@amd.com>

Jon

>               atomic_inc(&target->debugger_process-
> >debugged_process_count);
>
> @@ -832,6 +834,7 @@ int kfd_dbg_trap_enable(struct kfd_process *target,
> uint32_t fd,
>               target->dbg_ev_file = NULL;
>               if (target->debugger_process)
>                       atomic_dec(&target->debugger_process-
> >debugged_process_count);
> +             target->debugger_process = NULL;
>               target->debug_trap_enabled = false;
>               kfd_unref_process(target);
>               r = -EFAULT;
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.h
> b/drivers/gpu/drm/amd/amdkfd/kfd_debug.h
> index 5babf9b992cd..f675fe6ed353 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.h
> @@ -44,8 +44,8 @@ bool kfd_dbg_ev_raise(uint64_t event_mask,
>                       void *exception_data,
>                       size_t exception_data_size);
>  int kfd_dbg_trap_disable(struct kfd_process *target, bool drain_irqs);
> -int kfd_dbg_trap_enable(struct kfd_process *target, uint32_t fd,
> -                     void __user *runtime_info,
> +int kfd_dbg_trap_enable(struct kfd_process *target, struct kfd_process
> *debugger,
> +                     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,
> --
> 2.50.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-23 15:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  2:47 [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on Jesse Zhang
2026-11-23  2:47 ` [PATCH v3 2/3] drm/amdkfd: return the memory violation data to the debugger Jesse Zhang
2026-11-23  2:47 ` [PATCH v3 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails Jesse Zhang
2026-11-23  3:11   ` sashiko-bot
2026-11-23 15:08   ` Kim, Jonathan
2026-11-23  3:12 ` [PATCH v3 1/3] drm/amdkfd: don't flush the TLB of a device the process has no VM on sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.