mirror of
https://github.com/torvalds/linux.git
synced 2026-09-26 18:12:03 +02:00
kfd_dev_mapping caches the address_space of the first /dev/kfd opener
so that the GPU reset path can call unmap_mapping_range() to zap all
userspace mappings of doorbell and MMIO ranges. This design has two
bugs that both manifest under SRIOV with multiple containers:
1. Use-after-free / rwsem deadlock. The cached pointer refers to an
inode owned by the first opener's container. When that container
exits and its inode is released, kfd_dev_mapping becomes a dangling
pointer. A subsequent GPU reset dereferences it inside
unmap_mapping_range(), which takes i_mmap_rwsem on the freed inode,
causing a hard hang observable as an uninterruptible rwsem wait.
2. Multi-container gap. Only the first opener's address_space is cached;
VMAs created by later openers live in a different address_space and
are never reached by unmap_mapping_range(). After a GPU reset those
stale mappings keep doorbell and MMIO pages accessible to guest
userspace with no GPU behind them, risking PCIe transaction timeouts
and NMI panics.
Fix both bugs with the same approach used by DRM core (drm_drv.c):
create a private pseudo-filesystem at module init time and allocate one
anonymous inode from it. In kfd_open() redirect every opener's
file->f_mapping to that inode's address_space. The inode is
module-owned, lives exactly as long as the amdgpu module, and collects
VMAs from all openers in one address_space. A single
unmap_mapping_range() call in the reset path then correctly reaches
every container's mappings with no dangling pointer risk.
The hang manifests as an NMI backtrace on the GPU reset workqueue stuck
spinning in rwsem_down_read_slowpath() with a corrupted i_mmap_rwsem:
Workqueue: amdgpu-reset-dev xgpu_ai_mailbox_flr_work [amdgpu]
Call Trace:
<TASK>
kvm_wait+0x1f/0x40
__pv_queued_spin_lock_slowpath+0x31d/0x3a0
_raw_spin_lock_irq+0x51/0x80
rwsem_down_read_slowpath+0xb3/0x550
down_read+0x48/0xd0
unmap_mapping_range+0x71/0x140
kfd_dev_unmap_mapping_range+0x5b/0x140 [amdgpu]
amdgpu_amdkfd_clear_kfd_mapping+0xd8/0x190 [amdgpu]
amdgpu_device_gpu_recover+0x232/0x450 [amdgpu]
xgpu_ai_mailbox_flr_work+0xb5/0xc0 [amdgpu]
process_one_work+0x18e/0x3e0
worker_thread+0x2e3/0x420
kthread+0x10a/0x230
Fixes:
|
||
|---|---|---|
| .. | ||
| cik_event_interrupt.c | ||
| cik_int.h | ||
| cik_regs.h | ||
| cwsr_trap_handler_gfx8.asm | ||
| cwsr_trap_handler_gfx9.asm | ||
| cwsr_trap_handler_gfx10.asm | ||
| cwsr_trap_handler_gfx12.asm | ||
| cwsr_trap_handler.h | ||
| Kconfig | ||
| kfd_chardev.c | ||
| kfd_crat.c | ||
| kfd_crat.h | ||
| kfd_debug.c | ||
| kfd_debug.h | ||
| kfd_debugfs.c | ||
| kfd_device_queue_manager_cik.c | ||
| kfd_device_queue_manager_v9.c | ||
| kfd_device_queue_manager_v10.c | ||
| kfd_device_queue_manager_v11.c | ||
| kfd_device_queue_manager_v12_1.c | ||
| kfd_device_queue_manager_v12.c | ||
| kfd_device_queue_manager_vi.c | ||
| kfd_device_queue_manager.c | ||
| kfd_device_queue_manager.h | ||
| kfd_device.c | ||
| kfd_doorbell.c | ||
| kfd_events.c | ||
| kfd_events.h | ||
| kfd_flat_memory.c | ||
| kfd_int_process_v9.c | ||
| kfd_int_process_v10.c | ||
| kfd_int_process_v11.c | ||
| kfd_int_process_v12_1.c | ||
| kfd_interrupt.c | ||
| kfd_kernel_queue.c | ||
| kfd_kernel_queue.h | ||
| kfd_migrate.c | ||
| kfd_migrate.h | ||
| kfd_module.c | ||
| kfd_mqd_manager_cik.c | ||
| kfd_mqd_manager_v9.c | ||
| kfd_mqd_manager_v10.c | ||
| kfd_mqd_manager_v11.c | ||
| kfd_mqd_manager_v12_1.c | ||
| kfd_mqd_manager_v12.c | ||
| kfd_mqd_manager_vi.c | ||
| kfd_mqd_manager.c | ||
| kfd_mqd_manager.h | ||
| kfd_packet_manager_v9.c | ||
| kfd_packet_manager_vi.c | ||
| kfd_packet_manager.c | ||
| kfd_pm4_headers_ai.h | ||
| kfd_pm4_headers_aldebaran.h | ||
| kfd_pm4_headers_vi.h | ||
| kfd_pm4_headers.h | ||
| kfd_pm4_opcodes.h | ||
| kfd_priv.h | ||
| kfd_process_queue_manager.c | ||
| kfd_process.c | ||
| kfd_queue.c | ||
| kfd_smi_events.c | ||
| kfd_smi_events.h | ||
| kfd_svm.c | ||
| kfd_svm.h | ||
| kfd_topology.c | ||
| kfd_topology.h | ||
| Makefile | ||
| soc15_int.h | ||