On 2026-11-18 00:49, Jesse Zhang wrote:
suspend_queues() goes through all devices of the process, and on MES does
the debug memory fence and a heavy-weight TLB flush when total_suspended,
the number of queues suspended so far on any device, is non-zero. On a
later device without suspended queues that flushes the TLB of a VM the
process may not even have: kfd_flush_tlb() dereferences pdd->drm_priv,
which is NULL when the process never acquired a VM on that GPU.

That is a process using only one GPU of a system with more, e.g. a dGPU
plus the APU's iGPU, stopped by a debugger. On navi31 with the iGPU,
a debugger suspending a compute queue of a ptraced child that only
acquired the navi31 VM:

   Oops: general protection fault, probably for non-canonical address 
0xdffffc000000002f: 0000 [#1] SMP KASAN NOPTI
   KASAN: null-ptr-deref in range [0x0000000000000178-0x000000000000017f]
   RIP: 0010:suspend_queues+0x104b/0x1a80 [amdgpu]
   Call Trace:
    kfd_ioctl_set_debug_trap+0x1234/0x1720 [amdgpu]
    kfd_ioctl+0x46a/0xb70 [amdgpu]

and the debugger ends up in D state.

Count the queues MES suspended per device and only fence and flush for
those devices. With that the queue is suspended and resumed (status 0) and
the kfdtest KFDDBGTest tests pass.

Fixes: ff114e705d6a ("drm/amdkfd: Add TLB flush after MES queue 
eviction/suspension")
Signed-off-by: Jesse Zhang<[email protected]>
---
  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index b5d7d13f31a5..a50a49d6ed01 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -3952,7 +3952,7 @@ int suspend_queues(struct kfd_process *p,
                struct device *dev = dqm->dev->adev->dev;
                struct qcm_process_device *qpd = &pdd->qpd;
                struct queue *q;
-               int r, per_device_suspended = 0;
+               int r, per_device_suspended = 0, mes_suspended = 0;
mutex_lock(&p->event_mutex);
                dqm_lock(dqm);
@@ -3974,7 +3974,7 @@ int suspend_queues(struct kfd_process *p,
                                                        ~exception_clear_mask;
if (is_mes)
-                                               total_suspended++;
+                                               mes_suspended++;

I don't think you need a new variable. Just use per_device_suspended for both MES and HWS. That name is more meaningful anyway.


                                        else
                                                per_device_suspended++;
                                } else if (err != -EBUSY) {
@@ -3987,7 +3987,12 @@ int suspend_queues(struct kfd_process *p,
                if (!per_device_suspended) {

Then this condition becomes

if (!per_device_suspended || is_mes)

Regards,
  Felix


                        dqm_unlock(dqm);
                        mutex_unlock(&p->event_mutex);
-                       if (total_suspended) {
+                       /*
+                        * Only for the queues of this device, the process may
+                        * not even have a VM on the other devices.
+                        */
+                       if (mes_suspended) {
+                               total_suspended += mes_suspended;
                                amdgpu_amdkfd_debug_mem_fence(dqm->dev->adev);
                                /* Heavy-weight TLB flush after MES suspends 
queues */
                                kfd_flush_tlb(pdd);

Reply via email to