linux/drivers/gpu/drm/amd/amdkfd
Asad Kamal c3a31087b1 drm/amdkfd: fix use-after-free and multi-container gap in kfd_dev_mapping
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: 70cadefcc6 ("drm/amdgpu: unmap all user mappings of framebuffer and doorbell before mode1 reset")
Signed-off-by: Asad Kamal <asad.kamal@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 1128b4a52de1572e87431de837fd9850cb99542c)
Cc: stable@vger.kernel.org
2026-09-23 15:53:05 -04:00
..
cik_event_interrupt.c drm/amdkfd: Don't expect signal mailbox update 2026-03-17 10:31:39 -04:00
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 drm/amdkfd: fix CWSR trap handler 2026-02-26 11:20:10 -05:00
cwsr_trap_handler.h drm/amdkfd: gfx12.1 trap handler instruction fixup for VOP3PX 2026-01-28 16:21:21 -05:00
Kconfig dma-buf: Always build with DMABUF_MOVE_NOTIFY 2026-01-27 10:45:11 +01:00
kfd_chardev.c drm/amdkfd: fix use-after-free and multi-container gap in kfd_dev_mapping 2026-09-23 15:53:05 -04:00
kfd_crat.c drm/amdkfd: Add bounds check for CRAT subtype length 2026-07-16 18:27:26 -04:00
kfd_crat.h
kfd_debug.c drm/amdkfd: Unwind debug trap enable on copy_to_user failure 2026-06-04 15:25:55 -04:00
kfd_debug.h drm/amdkfd: fix gfx11 restrictions on debugging cooperative launch 2026-01-20 21:50:12 -05:00
kfd_debugfs.c drm/amdkfd: Do not fail process debugfs setup on debugfs errors 2026-07-15 09:15:10 -04:00
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 drm/amdkfd: Limit per-process xnack support for GFX12.1 2026-04-24 10:57:31 -04:00
kfd_device_queue_manager_v12.c
kfd_device_queue_manager_vi.c
kfd_device_queue_manager.c drm/amdkfd: implement restore_mqd callbacks for GFX12/12.1 2026-09-17 11:53:24 -04:00
kfd_device_queue_manager.h drm/amdkfd: Check bounds on CRIU restore queue type and mqd size 2026-07-08 14:21:51 -04:00
kfd_device.c drm/amdgpu: add support for GC IP version 11.7.1 2026-07-01 13:01:48 -04:00
kfd_doorbell.c drm/amdkfd: check find_first_zero_bit before __set_bit on kfd->doorbell_bitmap 2026-06-17 18:24:47 -04:00
kfd_events.c drm/amdkfd: Fix signal reset event 2026-07-28 19:17:33 -04:00
kfd_events.h drm/amdkfd: drop struct kfd_signal_page wrapper 2026-07-01 11:14:53 -04:00
kfd_flat_memory.c drm/amdgpu: GFX12.1 scratch memory limit up to 57-bit 2026-03-04 11:42:26 -05:00
kfd_int_process_v9.c drm/amdkfd: Don't expect signal mailbox update 2026-03-17 10:31:39 -04:00
kfd_int_process_v10.c drm/amdkfd: Don't expect signal mailbox update 2026-03-17 10:31:39 -04:00
kfd_int_process_v11.c drm/amdkfd: Don't expect signal mailbox update 2026-03-17 10:31:39 -04:00
kfd_int_process_v12_1.c drm/amdkfd: Switch to dev_* printk stuff in kfd_int_process_v12_1.c 2026-03-30 15:13:14 -04:00
kfd_interrupt.c
kfd_kernel_queue.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
kfd_kernel_queue.h
kfd_migrate.c drm/amdkfd: Fix the case that vm range is hole at svm_migrate_copy_to_vram 2026-08-25 18:22:00 -04:00
kfd_migrate.h
kfd_module.c
kfd_mqd_manager_cik.c drm/amdkfd: Removed commented line for MQD queue priority 2026-02-25 16:28:10 -05:00
kfd_mqd_manager_v9.c drm/amdkfd: Avoid integer underflow in EOP ring size calculation. 2026-09-17 11:56:45 -04:00
kfd_mqd_manager_v10.c drm/amdkfd: Avoid integer underflow with ffs in EOP ring size calc 2026-09-17 11:56:02 -04:00
kfd_mqd_manager_v11.c drm/amdkfd: Avoid integer underflow with ffs in EOP ring size calc 2026-09-17 11:56:02 -04:00
kfd_mqd_manager_v12_1.c drm/amdkfd: Avoid integer underflow with ffs in EOP ring size calc 2026-09-17 11:56:02 -04:00
kfd_mqd_manager_v12.c drm/amdkfd: Avoid integer underflow with ffs in EOP ring size calc 2026-09-17 11:56:02 -04:00
kfd_mqd_manager_vi.c drm/amdkfd: Avoid integer underflow in EOP ring size calculation. 2026-09-17 11:56:45 -04:00
kfd_mqd_manager.c drm/amdkfd: Extend MQDs in HBM to gfx944 2026-06-17 16:07:56 -04:00
kfd_mqd_manager.h drm/amdkfd: preserve VRAM MQD across hibernation via unpin/repin 2026-08-12 09:37:44 -04:00
kfd_packet_manager_v9.c drm/amdkfd: allow CWSR grace period of 0 on supported firmware 2026-07-28 19:17:33 -04:00
kfd_packet_manager_vi.c amdkfd: remove DIQ support 2025-12-08 13:56:42 -05:00
kfd_packet_manager.c drm/amdkfd: Clean up debug runlist printing 2026-07-16 18:26:59 -04:00
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 drm/amdkfd: preserve VRAM MQD across hibernation via unpin/repin 2026-08-12 09:37:44 -04:00
kfd_process_queue_manager.c drm/amdkfd: fix scope of mqd_mgr dereference in pqm_debugfs_mqds 2026-09-02 16:58:54 -04:00
kfd_process.c drm/amdkfd: enable rs64mem for kfd queue 2026-08-06 12:46:14 -04:00
kfd_queue.c drm/amdgpu: Fix typo in comment 2026-08-06 13:47:02 -04:00
kfd_smi_events.c drm/amdkfd: use scnprintf/vscnprintf in kfd_smi_event_add 2026-07-01 11:16:48 -04:00
kfd_smi_events.h drm/amdkfd: Fix SMI event PID reporting for containers 2026-06-17 18:12:00 -04:00
kfd_svm.c drm/amdkfd: Unmap svm range from GPU set to no-access 2026-08-06 09:25:49 -04:00
kfd_svm.h drm/amdkfd: Unmap svm range from GPU set to no-access 2026-08-06 09:25:49 -04:00
kfd_topology.c drm/amdkfd: Add gfx12.0 queue reset support to topology 2026-07-01 11:23:26 -04:00
kfd_topology.h
Makefile drm/amdkfd: Add interrupt handling for GFX 12.1.0 2025-12-08 14:13:11 -05:00
soc15_int.h