AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU
@ 2026-11-25 14:19 Armas Spann
  2026-11-25 14:19 ` [PATCH v2 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Armas Spann @ 2026-11-25 14:19 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, christian.koenig, Felix.Kuehling, Armas Spann

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):

  - F5-TTS dual-GPU training (batch 4 + grad accum 2): 30 min,
    500+ updates, 2.93s/update, both GPUs 100%, stable
  - F5-TTS dual-GPU training (default frame batching, pretrained
    weights): 10 min, 319 updates, 1.58s/update, both GPUs 100%
  - 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
  - VRAM usage stable at 65% throughout, no OOM under normal batch
    sizes

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 <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>

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       |  85 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       |  53 ++
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  54 +-
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        |  55 +-
 drivers/gpu/drm/amd/amdgpu/mes_v12_1.c        |  89 ++-
 drivers/gpu/drm/amd/amdkfd/kfd_device.c       |  42 +-
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 747 ++++++++++++++++--
 .../drm/amd/amdkfd/kfd_device_queue_manager.h |  31 +
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  48 ++
 drivers/gpu/drm/amd/amdkfd/kfd_process.c      |  64 +-
 .../amd/amdkfd/kfd_process_queue_manager.c    | 183 +++--
 drivers/gpu/drm/amd/amdkfd/kfd_queue.c        |  63 +-
 14 files changed, 1460 insertions(+), 154 deletions(-)

Changes v1 -> v2:

Addresses the review of v1. Nine patches as before, the fixes went
into the patches that introduced the problems.

1/9 drm/amdgpu/mes: distinguish rejected from timed out commands
  - mes.fw_gen is one counter per XCC, incremented in the xcc_hw_init of
    each MES version; a ticket records the XCC it was submitted on and
    the poll compares against that entry
  - mes_v12_1 reads the status slot as 64 bits and prints the firmware
    error code in the upper half; it was read as 32 bits, so the code
    the patch set out to print was never seen there
  - dma_rmb() between the fence and the status read in
    amdgpu_mes_ticket_poll() and after the fence poll in the three
    submit paths

3/9 drm/amdkfd: track whether MES knows each queue
  - fence MES on a timed out ADD_QUEUE, as the REMOVE path does
  - a removal that cannot be sent because the scheduler is halted or
    stopped returns -EIO for a queue MES still has, instead of success;
    the is_reset shortcut is gone
  - reset_queue_mes() looks at the result of the remove-after-reset:
    a timeout fences MES and fails the per-queue reset so that the
    caller escalates to a GPU reset, a rejection keeps the queue
    UNKNOWN as before
  - after the grace period, a REMOVE_QUEUE that is still unanswered
    fences MES and escalates directly; reset_queues_mes() and its three
    commands only run when MES answered
  - __remove_queue_mes() retires a queue whose earlier REMOVE_QUEUE
    completed between the caller's check and its own, instead of
    sending a duplicate; after a failed reset_queues_mes() the retired
    state is re-checked before escalating
  - reset_queues_mes() fills gang_context_array_index and the ticket of
    the REMOVE_QUEUE it hands to amdgpu_gfx_reset_mes_compute(), and
    refuses to run behind an unanswered command
  - the explicit removal of a queue the recovery left in MES moved from
    remove_queue_mes_on_reset_option() into reset_queues_mes(), so
    kfd_dqm_suspend_bad_queue_mes() gets it too
  - remove_all_kfd_queues_mes() keys on kfd_mes_queue_retired() instead
    of is_active, like the other teardown paths

4/9 drm/amdkfd: add a quarantine for queues MES has not retired
  - kgd2kfd_teardown_processes() retires the queues and waits for the
    processes also when the process table is already empty; a process
    with zombies leaves the table before it is freed
  - a per-queue reset of a zombie does the MES side only and skips
    set_queue_as_reset(): no counter change, no has_reset_queue and no
    is_reset for a queue the process no longer owns
  - cancel svms.restore_work in the notifier release, next to the other
    works of the process, instead of in the deferred release
  - kfd_queue_ref_bo_vas() dropped (see 5/9)

5/9 drm/amdkfd: keep queue storage until MES confirmed retirement
  - pqm_destroy_queue() drops the bo_va queue_refcounts once, after the
    dqm has dequeued the queue, instead of before the destroy with a
    re-ref on failure; a second destroy of a queue id while the first
    one sleeps on a suspended queue no longer leaves one count too many
  - a queue quarantined from a failed create takes its own references
    on the ring, pointer, EOP and CWSR buffers (kfd_queue_hold_buffers())
    before the ioctl drops its set; zombie_no_user_bos is gone and the
    reaper releases the buffers of every zombie
  - the cleanup path of create_queue_cpsch() clears is_active after it
    decremented the count, so a later per-queue reset of the zombie
    cannot decrement it again
  - kfd_dqm_suspend_bad_queue_mes() decrements the active count only if
    the reset it asked for has not done so already (pre-existing)
  - kfd_queue_unref_bo_vas() reserves the VM without being
    interruptible, it runs after the queue is gone now

6/9 drm/amdkfd: keep eviction and restore consistent when MES fails
  - kfd_process_evict_queues() returns -EIO when any device returned
    it, instead of the result of the last device (pre-existing)
  - a failed restore_process_queues_cpsch() takes the queues restored
    in that attempt off the hardware again, so the process is fully
    evicted and the retry starts from a known state (pre-existing)
  - a queue is counted before ADD_QUEUE is sent and taken out of the
    count on failure, so the GFX11 oversubscription check in
    add_queue_mes() sees it

7/9 drm/amdkfd: apply queue property updates only after unmap
  - the new properties travel in struct mqd_update_info (new_props)
    with the update_queue() call, q->pending_props is gone; a perfcount
    update from another process can no longer apply, or race with, the
    properties of an update in flight
  - update_queue_locked() returns -EBUSY for a no-HWS queue updated
    while the scheduler is stopped, instead of 0 with nothing applied

8/9 drm/amdkfd: reconcile queue state with MES after a restart
  - the deactivate/evict branch is gone; the reconcile retires the
    stale MES state, releases lost tickets and lifts the fence, and
    warns if it finds a queue still marked active. Deactivation stays
    in set_queue_as_reset() and evict_process_queues_cpsch()
  - commit message reworded accordingly

Unchanged: 2/9, 9/9.

Not addressed here, pre-existing and for separate patches: the lock
order between the KGD and KFD per-queue reset paths
(kfd_reset_queue_mes() without the dqm lock), has_reset_queue tested
after the unmap in update_queue(), context id 0 freed on an allocation
failure in create_process(), and the queue_refcount taken on a mapping
without a BO in kfd_queue_buffer_get().

-- 
2.47.3


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

end of thread, other threads:[~2026-11-26  8:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 14:19 [PATCH v2 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU Armas Spann
2026-11-25 14:19 ` [PATCH v2 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
2026-11-26  8:36   ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 2/9] drm/amdkfd: factor out freeing of per-queue MES resources Armas Spann
2026-11-25 14:19 ` [PATCH v2 3/9] drm/amdkfd: track whether MES knows each queue Armas Spann
2026-11-26  8:46   ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 4/9] drm/amdkfd: add a quarantine for queues MES has not retired Armas Spann
2026-11-26  8:49   ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 5/9] drm/amdkfd: keep queue storage until MES confirmed retirement Armas Spann
2026-11-26  8:39   ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 6/9] drm/amdkfd: keep eviction and restore consistent when MES fails Armas Spann
2026-11-26  8:36   ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 7/9] drm/amdkfd: apply queue property updates only after unmap Armas Spann
2026-11-25 14:19 ` [PATCH v2 8/9] drm/amdkfd: reconcile queue state with MES after a restart Armas Spann
2026-11-25 14:19 ` [PATCH v2 9/9] drm/amdkfd: force CWSR on with more than one MES GPU Armas Spann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox