Public

> -----Original Message-----
> From: Jesse Zhang <[email protected]>
> Sent: Wednesday, November 18, 2026 12:50 AM
> To: [email protected]
> Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix
> <[email protected]>; Kim, Jonathan <[email protected]>; Zhang,
> Jesse(Jie) <[email protected]>
> Subject: [PATCH 1/3] drm/amdkfd: only flush the TLB of devices whose queues
> got suspended
>
> 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]

I guess this is a problem of runtime masking off a device (no future work 
expected for that runtime instance) while the debugger early attaches to all 
devices (no idea of the mask)?

Maybe a fast fix is to early return in kfd_flush_tlb on null to avoid any other 
caller from hitting the same null pointer problem.
A proper optimization might be to check acquire per pdd on trap activation 
(post runtime enable) and mark the pdd as undebuggable if unacquired (expecting 
no future work).
Then any debug op that touches the device debug context (via suspend, resume, 
override ops etc) can early return and saves unnecessary escape calls to MES.

Jon

>
> 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++;
>                                       else
>                                               per_device_suspended++;
>                               } else if (err != -EBUSY) {
> @@ -3987,7 +3987,12 @@ int suspend_queues(struct kfd_process *p,
>               if (!per_device_suspended) {
>                       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);
> --
> 2.50.1

Reply via email to