Skip to content

drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU

Armas Spann amd-gfx 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9drm/amdgpu/mes: distinguish rejected from timed out commandsdrivers/gpu/drm/amd/amdgpu/amdgpu_mes.c drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 more+264 -190 replies
2/9drm/amdkfd: factor out freeing of per-queue MES resourcesdrivers/gpu/drm/amd/amdkfd/kfd_priv.h drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c+17 -50 replies
3/9drm/amdkfd: track whether MES knows each queuedrivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 more+278 -180 replies
4/9drm/amdkfd: add a quarantine for queues MES has not retireddrivers/gpu/drm/amd/amdkfd/kfd_device.c drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +3 more+281 -90 replies
5/9drm/amdkfd: keep queue storage until MES confirmed retirementdrivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c+127 -430 replies
6/9drm/amdkfd: keep eviction and restore consistent when MES failsdrivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c+27 -70 replies
7/9drm/amdkfd: apply queue property updates only after unmapdrivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c drivers/gpu/drm/amd/amdkfd/kfd_priv.h drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c+63 -270 replies
8/9drm/amdkfd: reconcile queue state with MES after a restartdrivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c+70 -00 replies
9/9drm/amdkfd: force CWSR on with more than one MES GPUdrivers/gpu/drm/amd/amdgpu/amdgpu.h drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c drivers/gpu/drm/amd/amdkfd/kfd_device.c+123 -30 replies

Reviews trailers per patch

None of the 9 patches has a Reviewed-by or Acked-by.

PatchClaude Fable 5.2
1/9Co-Authored-By
2/9Co-Authored-By
3/9Co-Authored-By
4/9Co-Authored-By
5/9Co-Authored-By
6/9Co-Authored-By
7/9Co-Authored-By
8/9Co-Authored-By
9/9Co-Authored-By

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH v1 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU

On a dual R9700 Pro (gfx 12.0.1) system running RCCL distributed training, MES hits 2-second preemption timeouts on REMOVE_QUEUE and SUSPEND after 90 to 120 seconds of operation. Both GPUs fail during RCCL collectives. The timeout triggers a MODE1 reset, which loses VRAM and cascades into a second reset on the peer GPU.

Root cause: cwsr_enable=0 prevents MES from preempting running compute waves. When an RCCL kernel on GPU0 waits for its peer on GPU1, and GPU1's queue gets evicted, MES cannot preempt GPU0's kernel because there is no CWSR. The 2s MES preemption timeout fires, MES rejects the command, and the driver treats it as a hang.

Separately, KFD frees queue storage (MQD, doorbell id, gang context) before MES has confirmed the removal. A REMOVE_QUEUE that completes late writes the queue state back into an MQD that has been given to the next queue. This is a use-after-free on the firmware side.

This series fixes both problems:

1/9 Distinguish rejected from timed-out MES commands so callers
can tell a firmware that said no from one that stopped answering. Add a ticket for late completion polling.
2/9 Factor out per-queue MES resource freeing into a helper. 3/9 Track per-queue MES state (mapped/unmapped/pending) so the rest
of the dqm knows whether MES may still reference storage.
4/9 Add a quarantine for queues that MES has not released. A reaper
workqueue polls for late completions and cleans up.
5/9 Defer freeing of queue storage until MES has confirmed retirement
in all four teardown paths (destroy, create failure, termination, process exit).
6/9 Keep eviction and restore consistent when MES fails. Do not
restore a queue whose eviction was not confirmed.
7/9 Apply queue property updates only after the queue is unmapped,
not while MES still owns it.
8/9 Reconcile KFD queue state with MES after a scheduler restart.
Queues from the previous firmware instance are retired.
9/9 Force cwsr_enable=1 on gfx11+ discrete GPUs when a second MES
GPU is present. Per-device decision, logged to dmesg.

Tested on a dual R9700 Pro system (gfx 12.0.1, Threadripper 1950X, 64GB, Gentoo, kernel 7.3.5-p1 with these patches):

- RCCL all_reduce stress 150s: 85,582 iters, 570.5 it/s, 0 errors
- RCCL all_reduce stress 600s: 343,647 iters, 572.7 it/s, 0 errors
- F5-TTS dual-GPU training 50,780 steps: completed, no MES errors
- dmesg after all tests: zero MES rejects, zero resets
- Patch 9 override test (cwsr_enable=0 in cmdline): kernel forces 1, logs warning per affected GPU

Related reports:

https://github.com/ROCm/hrx-system/issues/2938
https://github.com/ROCm/TheRock/issues/9279
https://github.com/ROCm/TheRock/issues/9299
https://github.com/ROCm/rccl/issues/2193

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc Felix Kuehling <[email protected]>

Armas Spann (9):
drm/amdgpu/mes: distinguish rejected from timed out commands drm/amdkfd: factor out freeing of per-queue MES resources drm/amdkfd: track whether MES knows each queue drm/amdkfd: add a quarantine for queues MES has not retired drm/amdkfd: keep queue storage until MES confirmed retirement drm/amdkfd: keep eviction and restore consistent when MES fails drm/amdkfd: apply queue property updates only after unmap drm/amdkfd: reconcile queue state with MES after a restart drm/amdkfd: force CWSR on with more than one MES GPU

 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  99 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c       |  79 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       |  44 ++
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  51 +-
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        |  52 +-
 drivers/gpu/drm/amd/amdgpu/mes_v12_1.c        |  57 +-
 drivers/gpu/drm/amd/amdkfd/kfd_device.c       |  35 +-
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 627 ++++++++++++++++--
 .../drm/amd/amdkfd/kfd_device_queue_manager.h |  31 +
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  51 ++
 drivers/gpu/drm/amd/amdkfd/kfd_process.c      |  51 +-
 .../amd/amdkfd/kfd_process_queue_manager.c    | 167 +++--
 drivers/gpu/drm/amd/amdkfd/kfd_queue.c        |  30 +
 14 files changed, 1247 insertions(+), 128 deletions(-)
Signature · 1 line
2.56.1