All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] drm/amdkfd: keep queue storage until MES has retired the queue
@ 2026-12-04 12:52 Armas Spann
  2026-12-04 12:52 ` [PATCH 1/8] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Armas Spann @ 2026-12-04 12:52 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, christian.koenig, Felix.Kuehling, Armas Spann

KFD frees the storage of a user queue without requiring that MES has
confirmed the removal of the queue. When a REMOVE_QUEUE fails or times
out, the MQD, the doorbell id, the gang context, the GART mapping of the
write pointer and the references on the user buffers are released all
the same. On gfx12 the MQD comes from a first fit sub-allocator and the
doorbell id from a first fit bitmap, so both go to the next queue the
process creates. A REMOVE_QUEUE that MES completes after the driver gave
up on it then writes queue state into an MQD that belongs to another
queue, and a queue that MES never let go of keeps running on memory
that has been freed. The same holds for an ADD_QUEUE that timed out and
is executed later.

This series makes KFD keep everything a queue owns until MES has let go
of it: the removal was confirmed, a command that timed out has completed
after all, or the firmware has been restarted.

It is a new series and replaces the two postings of "drm/amdgpu/amdkfd:
fix MES queue lifecycle on multi-GPU" [1] [2], which are obsolete.
Those were built around a failure that I only got with cwsr_enable=0.
Felix pointed out [3] that this is not a supported configuration, and
asked for the storage lifetime problem to be sent separately. This is
that series. The patch that dealt with CWSR is gone, and nothing in
here depends on, or tries to accommodate, a system without CWSR. The
bug itself does not need that setting: any REMOVE_QUEUE or ADD_QUEUE
that MES rejects or does not answer in time takes the paths below, as
does every removal that cannot be sent because a GPU reset is under
way.

  1/8  MES: tell a command the firmware rejected from one it did not
       answer. Let the caller of REMOVE_QUEUE keep the status slot of
       an unanswered command (a "ticket") and poll it later. Count the
       restarts of the scheduler firmware per XCC.
  2/8  Make the helper that frees the per-queue MES resources usable
       from the dqm. No functional change.
  3/8  Record per queue what MES knows about it (unmapped, mapped,
       unknown), from the result of every ADD_QUEUE and REMOVE_QUEUE.
       Give a REMOVE_QUEUE that timed out a grace period, and stop
       sending queue commands behind one that got no answer.
  4/8  Add a quarantine: a per-device list of destroyed queues that MES
       has not retired, a reaper that frees them once it has, and a
       hold on the process whose pdd, VM and doorbell page they use.
  5/8  Convert the paths that free queue storage (destroy in the dqm
       and in the pqm, failed create, process termination) to ask
       whether MES has retired the queue, and to quarantine it
       otherwise. This is the patch that closes the use-after-free.
  6/8  Keep eviction and restore consistent when MES fails: evict every
       queue, report -EIO as long as MES still has one, roll back a
       partial restore.
  7/8  Apply queue property updates at the point where the queue is
       unmapped, not before, so that a failed unmap does not leave the
       scheduler on a ring whose unmap protection is gone.
  8/8  When the scheduler starts after a firmware restart, drop the
       state that belonged to the old instance in one place.

Patches 1 to 4 add infrastructure and change behaviour only where the
commit messages say so. Nothing is quarantined before 5/8. Every patch
builds on its own.

What the series does not do:

- The hold a quarantined queue has on its process is per process, not
  per device. A process that has exited with a queue quarantined on one
  GPU keeps its pdds on all GPUs, so the removal of another GPU waits
  until that queue is retired, which takes a reset or the removal of
  the GPU it is on. The wait logs what it is waiting for. Lifting this
  means releasing the pdds device by device in the release worker and
  is left for a follow-up.
- A per-queue reset that KGD starts calls into the dqm without the dqm
  lock. That is the case today for is_active and the queue counters;
  the per-queue MES state and the quarantine list are now touched on
  that path as well. Taking the lock there needs a lock order between
  the KGD reset mutex and the dqm lock, which the KFD side takes the
  other way round. Not changed here.
- The quarantine keeps the storage of a queue allocated, pinned where
  it was pinned, and referenced. It does not keep TTM from moving the
  user buffers of a process that has exited; the eviction fence is
  signalled when the process is released, as before.
- amdgpu_gfx_reset_mes_compute() sends its RESUME also when a command
  before it got no answer. KGD code, not touched.

Compiled after each of the eight patches: all amdkfd objects and the
amdgpu objects the series touches, x86_64, gcc 14.2. The final tree
also without CONFIG_HSA_AMD_SVM.

Tested on two Radeon AI PRO R9700 (gfx 12.0.1, 32 GB each) in a
PCIe 3.0 system, Gentoo 7.3.7 with the eight patches backported,
default configuration (cwsr_enable=1). A third GPU (CUDA) ran an
unrelated inference workload throughout.

Dual-GPU compute load, long run: an ML training job (F5-TTS, 20311
samples, dual-GPU via PyTorch/accelerate, ROCm 6.4) completed 2539
updates over 21 minutes at 1.98 updates/s with both GPUs above 95%
load. The same workload on the earlier v2 series backported to 7.3.5
ran at 0.34 updates/s (2.93 s/update).
dmesg throughout: zero MES rejects, zero resets, zero KFD errors.

SIGKILL of a process under dual-GPU load: both GPUs dropped to idle
immediately, VRAM returned to baseline. No MES errors, no quarantine
activity, no reaper activity. The teardown paths in 5/8 were taken;
the quarantine path was not because MES retired both queues before the
driver gave up.

Forced GPU reset (debugfs amdgpu_gpu_recover) with a KFD process
running at full load: one GPU reset without MODE1 ("device wedged, but
no recovery needed" -- the sticky -EIO from 6/8 and the reconciliation
from 8/8), the other took a MODE1 reset with MES firmware reload.
Both GPUs: single reset, no cascading failure. A new process started
afterwards reached the same throughput. The reconciliation path in 8/8
was taken on both GPUs.

Suspend to S3 and resume with idle KFD state: both GPUs took a MODE1
reset on suspend, MES firmware reloaded on resume. System functional.

Failure paths reached during testing: sticky -EIO (6/8), reconciliation
after restart (8/8), per-queue MES state tracking (3/8). Not reached:
quarantine (4/8, 5/8), late completion polling (1/8), reaper (4/8).
These require a REMOVE_QUEUE that MES does not answer within the
timeout, which did not occur during the test runs.

Based on amd-staging-drm-next, f0e06b8eb4bb ("drm/amdgpu/gfx9: make room
for the SPM VMID write in the compute rings").

[1] https://lore.kernel.org/all/20261124143433.49736-1-zappel@simple-co.de/T/#u
[2] https://lore.kernel.org/all/20261125141933.154222-1-zappel@simple-co.de/
[3] https://lore.kernel.org/amd-gfx/17841288-f20c-4903-a734-c347a0024264@amd.com/

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>

Armas Spann (8):
  drm/amdgpu/mes: distinguish rejected from timed out commands
  drm/amdkfd: make the per-queue MES resource cleanup usable by the dqm
  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

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |   1 +
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  30 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |   5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c       | 119 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       |  60 ++
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  62 +-
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        |  63 +-
 drivers/gpu/drm/amd/amdgpu/mes_v12_1.c        |  97 +-
 drivers/gpu/drm/amd/amdgpu/mes_v13_0.c        |  69 +-
 drivers/gpu/drm/amd/amdkfd/kfd_device.c       |  36 +-
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 917 ++++++++++++++++--
 .../drm/amd/amdkfd/kfd_device_queue_manager.h |  31 +
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  52 +
 drivers/gpu/drm/amd/amdkfd/kfd_process.c      |  65 +-
 .../amd/amdkfd/kfd_process_queue_manager.c    | 180 +++-
 drivers/gpu/drm/amd/amdkfd/kfd_queue.c        |  78 +-
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c          |  38 +-
 drivers/gpu/drm/amd/amdkfd/kfd_svm.h          |   7 +
 18 files changed, 1744 insertions(+), 166 deletions(-)

-- 
2.47.3


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

end of thread, other threads:[~2026-12-04 17:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 12:52 [PATCH 0/8] drm/amdkfd: keep queue storage until MES has retired the queue Armas Spann
2026-12-04 12:52 ` [PATCH 1/8] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
2026-12-04 14:30   ` sashiko-bot
2026-12-04 12:52 ` [PATCH 2/8] drm/amdkfd: make the per-queue MES resource cleanup usable by the dqm Armas Spann
2026-12-04 12:52 ` [PATCH 3/8] drm/amdkfd: track whether MES knows each queue Armas Spann
2026-12-04 15:25   ` sashiko-bot
2026-12-04 12:52 ` [PATCH 4/8] drm/amdkfd: add a quarantine for queues MES has not retired Armas Spann
2026-12-04 16:00   ` sashiko-bot
2026-12-04 12:52 ` [PATCH 5/8] drm/amdkfd: keep queue storage until MES confirmed retirement Armas Spann
2026-12-04 16:31   ` sashiko-bot
2026-12-04 12:52 ` [PATCH 6/8] drm/amdkfd: keep eviction and restore consistent when MES fails Armas Spann
2026-12-04 17:07   ` sashiko-bot
2026-12-04 12:52 ` [PATCH 7/8] drm/amdkfd: apply queue property updates only after unmap Armas Spann
2026-12-04 17:30   ` sashiko-bot
2026-12-04 12:52 ` [PATCH 8/8] drm/amdkfd: reconcile queue state with MES after a restart Armas Spann

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.