[BUG] KFD deadlock: profiler_lock and the DQM lock are taken in opposite orders (profiler release vs create_queue_cpsch), all of /dev/kfd hangs on MI355X with amdgpu-dkms 7.1.3

Đang mở
#245 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@benrichard-amd đang làm issue này rồi.

Từ ngày 24/11/2026.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
18/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c
Lĩnh vực
operating-systems

Hướng nghiên cứu

Start in amd/amdkfd/kfd_process.c at kfd_process_profiler_release() and in kfd_device_queue_manager.c at create_queue_cpsch()/set_perfcount(); the opposing profiler_lock read is in kfd_mqd_manager_v9.c and the _v10/_v11/_v12/_vi variants. Read both lock orders together and confirm with lockdep, since the reported reproduction needs an MI355X node plus rocpctl. Done means one order is removed (for example READ_ONCE or computing the flag before dqm_lock) without changing perfcount semantics.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

On a node with 8x AMD Instinct MI355X, amdgpu-dkms 7.1.3 deadlocked in KFD. After that, every open of /dev/kfd, every queue ioctl and every exit of a GPU process blocked in uninterruptible sleep, on all eight GPUs, until the node was rebooted. systemctl reboot itself took about 19 minutes to complete.

The cause is an ABBA lock inversion between kfd->profiler_lock and the device queue manager lock. Both orders are in the DKMS source, quoted below; one side is also in the kernel log.

Environment

  • GPU: 8x AMD Instinct MI355X (gfx950), SR-IOV virtual functions inside a cloud VM ("AMD Instinct MI355X VF", device id 0x75b3)
  • Driver: amdgpu-dkms 1:7.1.3.31500000-2390945.24.04
  • Kernel: 6.8.0-147-generic, Ubuntu 24.04
  • ROCm userspace: 10.0.0 packages (libamdhip64.so.7.15.26333)
  • amd-metrics-exporter running on the host as shipped with the image (/usr/local/bin/amd-metrics-exporter -bind 127.0.0.1). It periodically runs rocpctl, which enables performance counters and so becomes KFD's profiler_process.

The two lock orders

A. profiler_lock, then the DQM lock (teardown of a process that enabled perf counters). amd/amdkfd/kfd_process.c:

static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_process_device *pdd)
{
	mutex_lock(&pdd->dev->kfd->profiler_lock);
	if (pdd->dev->kfd->profiler_process == p) {
		pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
		pdd->dev->kfd->profiler_process = NULL;
	}
	mutex_unlock(&pdd->dev->kfd->profiler_lock);
}

and set_perfcount() in kfd_device_queue_manager.c takes dqm_lock(dqm) to walk the queues.

B. the DQM lock, then profiler_lock (queue creation). create_queue_cpsch() in kfd_device_queue_manager.c calls mqd_mgr->init_mqd(...) between dqm_lock(dqm) and dqm_unlock(dqm), and init_mqd() in kfd_mqd_manager_v9.c does:

	mutex_lock(&mm->dev->kfd->profiler_lock);
	if (mm->dev->kfd->profiler_process != NULL)
		m->compute_perfcount_enable = 1;
	mutex_unlock(&mm->dev->kfd->profiler_lock);

The same block is in kfd_mqd_manager_v10.c, _v11.c, _v12.c and _vi.c.

So when a rocpctl process is torn down (A) while another process creates a compute queue on the same device (B), each holds the lock the other wants.

Kernel log

The first hung task the kernel reported is side A, on the release workqueue:

INFO: task kworker/u385:7:2793338 blocked for more than 122 seconds.
      Tainted: G           OE      6.8.0-147-generic
task:kworker/u385:7  state:D
Workqueue: kfd_process_wq kfd_process_wq_release [amdgpu]
Call Trace:
 __schedule+0x27c/0x6b0
 schedule+0x33/0x110
 schedule_preempt_disabled+0x15/0x30
 __mutex_lock.constprop.0+0x47f/0x790
 __mutex_lock_slowpath+0x13/0x20
 mutex_lock+0x3c/0x50
 set_perfcount+0x7c/0x140 [amdgpu]
 kfd_process_destroy_pdds+0x23f/0x2d0 [amdgpu]
 kfd_process_wq_release+0x494/0x640 [amdgpu]
 process_one_work+0x181/0x3a0
 worker_thread+0x18b/0x330
 kthread+0xef/0x120

The other tasks in the log are victims waiting for the DQM lock, for example on process exit:

INFO: task python:3045132 blocked for more than 122 seconds.
 mutex_lock+0x3c/0x50
 process_termination_cpsch+0x45/0x4b0 [amdgpu]
 kfd_process_dequeue_from_device+0x3d/0xd0 [amdgpu]
 kfd_process_dequeue_from_all_devices+0x36/0x70 [amdgpu]
 kfd_process_notifier_release_internal+0xb8/0x310 [amdgpu]
 kfd_process_notifier_release+0x1b/0x40 [amdgpu]
 __mmu_notifier_release+0x7b/0x200
 exit_mmap+0x3a2/0x3e0

and in kfd_ioctl_destroy_queue → pqm_destroy_queue, and amdgpu_amdkfd_evict_userptr → evict_process_queues_cpsch.

Side B was seen live in /proc/<pid>/stack of one process (create_queue_cpsch → init_mqd → mutex_lock), but I did not save that output and the kernel prints only the first ten hung tasks, so it is not in the log. The source above shows the order.

State when it happened

  • 223 tasks in state D: 218 user processes, 4 rocpctl, one kfd_process_wq kworker. Load average about 224 with idle CPUs.
  • New HIP processes blocked in kfd_ioctl_runtime_enable or on opening /dev/kfd.
  • SIGKILL had no effect on the blocked tasks.

How it was triggered

24 concurrent shell loops, each starting a short Python process that opens the GPU, creates queues, runs for about a second and exits (a test loop for an unrelated hang), spread over four of the eight GPUs, while the host's amd-metrics-exporter kept running rocpctl on its schedule. It had run for some time at 12 loops without the deadlock and hit it a few minutes after going to 24. I have not triggered it again on purpose, since it costs a node reboot, so I have no rate for it.

It needs only two things to coincide: a process that owns profiler_process exiting, and any other process creating a queue. Heavy process churn just makes the window likely.

Suggested direction

init_mqd() only reads whether a profiler process is set. Reading profiler_process without profiler_lock there (for example READ_ONCE), or deciding compute_perfcount_enable before dqm_lock is taken in create_queue_cpsch(), would remove order B. Alternatively kfd_process_profiler_release() could clear profiler_process under profiler_lock and call set_perfcount() after dropping it. I have not tested a patch.

Impact

Any node that runs the metrics exporter's profiler next to workloads that start and stop GPU processes often (CI, test suites, short jobs, sandboxes) can lose all its GPUs until reboot.

Workaround

Not running rocpctl/the exporter's profiler metrics on such nodes should avoid it, since profiler_process is then never set. I have not verified that.

The diagnosis was done with Claude Code on the affected node. The source excerpts and the log above are copied from that node's DKMS source tree and kernel journal.

Ngôn ngữ chính
C
Star
472
Fork
153
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ROCm/amdgpu

Tất cả issue của ROCm/amdgpu

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.