[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

未关闭
#245 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@benrichard-amd 已经在做这个了。

开始于 2026年11月24日。

评估

难度
5/5
预计耗时
一周以上
新手友好度
18/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
C
星标
472
派生
153
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ROCm/amdgpu 的其他 Issue

查看 ROCm/amdgpu 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。