drm/amdkfd: disable SVM when the GPUVM aperture cannot cover CPU addresses
Subsystems (4)
PATCH 1/1 drm/amdkfd: disable SVM when the GPUVM aperture cannot cover CPU addresses
SVM maps memory at the CPU virtual address, so svm_range_map_to_gpu() hands amdgpu_vm_update_range() a PFN derived straight from a userspace address. Nothing on that path compares it against vm_manager.max_pfn.
The buffer object path does compare. amdgpu_vm_bo_map() and friends go through amdgpu_vm_verify_parameters(), which rejects an lpfn at or above vm_manager.max_pfn. The page table walk relies on that check having
happened: amdgpu_vm_pt_entries_mask() returns 0xffffffff for levels at or above the root, so the root index is applied unmasked, while amdgpu_vm_pt_num_entries() sizes the root directory at only round_up(max_pfn, 1ULL << shift) >> shift entries. A PFN at or above max_pfn therefore indexes past the end of root.entries[] on the first descent, and the walk carries on through whatever heap follows the array.
amdgpu_vm_adjust_size() never picks an aperture small enough for a CPU address to land there -- the min_vm_size every gmc_v*_sw_init() passes already reaches AMDGPU_GMC_HOLE_START. An explicit amdgpu.vm_size= below it does, and nothing rejects it.
Seen on a Radeon 780M (gfx1103) with amdgpu.vm_size=64, i.e. max_pfn 0x1000000 and a 64 GiB aperture. A hipMallocManaged() loop asked SVM to map CPU address 0x74bd48000000, 1867 times max_pfn past the end of the GPU address space. Under slub_debug=FZPU the out of bounds root entry read back as the 0x5a5a5a5a5a5a5a5a poison pattern; without it, as recycled heap. amdgpu_vm_cpu_update() then dereferenced it:
Oops: general protection fault, probably for non-canonical address
0xb6aa2327baea2463: 0000 [#1] SMP NOPTI
RIP: 0010:amdgpu_vm_cpu_update+0x2f/0x140 [amdgpu]
amdgpu_vm_pte_update_flags+0xfa/0x1e0 [amdgpu]
amdgpu_vm_ptes_update+0x38b/0xa00 [amdgpu]
amdgpu_vm_update_range+0x279/0x930 [amdgpu]
svm_range_map_to_gpu+0x13d/0x400 [amdgpu]
svm_range_map_to_gpus+0x15c/0x380 [amdgpu]
svm_range_validate_and_map+0x8d3/0xaa0 [amdgpu]
svm_range_set_attr+0x4b6/0x890 [amdgpu]
svm_ioctl+0x66/0x80 [amdgpu]
kfd_ioctl_svm+0x64/0x120 [amdgpu]
kfd_ioctl+0x40a/0x650 [amdgpu]RSI and R14 both held 0xb6aa2327baea2323, so the garbage is the incoming vmbo argument itself rather than a field inside an otherwise valid object.
A UBSAN invalid-load in amdgpu_vm_update_pdes() precedes it on the same thread, loading 180 for the _Bool amdgpu_vm_bo_base.moved -- the same out of bounds entry, reached through vm->relocated.
Rejecting the range in amdgpu_vm_update_range() was proposed in [1] and turned down: the SVM subsystem should refuse to initialize when the GPUVM cannot represent the addresses, rather than failing every map once it is already too late. Do that. Require an aperture reaching AMDGPU_GMC_HOLE_START in KFD_IS_SVM_API_SUPPORTED(), so HSA_CAP_SVMAPI_SUPPORTED stays clear in the KFD topology, svms->bitmap_supported stays empty, and no SVM range is ever handed to the page table walker. Warn at device init so the capability does not just silently vanish.
Converting the macro to a static inline keeps AMDGPU_GMC_HOLE_START's implicit use of adev confined to one place.
[1] https://lore.kernel.org/amd-gfx/FIXME-SEPT-2-2026-MESSAGE-ID/
---
Validated on a Radeon 780M (gfx1103, PCI 1002:15bf), Ubuntu 26.04.1, kernel 7.0.0-38-generic, ROCm 7.13.0-2 / HIP 7.1.52801, booted with amdgpu.vm_size=64 amdgpu.no_system_mem_limit=1 throughout. Workload is the reporter's reproducer, 24 iterations of hipMallocManaged(1 GiB) / hipMemset / hipFree, run up to 40 times per attempt.
stock amdgpu.ko Oops within ~2 s, every attempt patched amdgpu.ko 40/40 runs clean, 594 s stock amdgpu.ko Oops within ~2 s patched amdgpu.ko 40/40 runs clean, 584 s
all four within 30 minutes on the same kernel, module identity confirmed per boot from the taint message and this warning. With the default amdgpu.vm_size the patched module does not log the warning and SVM stays enabled, as expected. A control run at the default aperture on the same kernel is also clean, which isolates amdgpu.vm_size=64 as the trigger rather than the kernel version.
Two things I would like a maintainer opinion on:
- I have read "must fail to initialize" as "do not advertise the capability". If you meant something stronger -- refusing KFD bringup, or rejecting the vm_size in amdgpu_vm_adjust_size() -- say so and I will respin.
- This gate also catches gmc_v6/v7/v8, where max_bits is 40 and so the aperture cannot reach AMDGPU_GMC_HOLE_START at any vm_size. On those ASICs pgmap.type stays 0 (kgd2kfd_init_zone_device() requires gfx9+), so only an APU that set apu_prefer_gtt currently advertises SVM, and by this patch's argument it is unsound there too. It is still a user-visible change on a whole generation, so flagging it rather than burying it. Happy to restrict the gate to an explicitly configured amdgpu_vm_size if you would rather keep the blast radius at the reported configuration.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 8 ++++++++ drivers/gpu/drm/amd/amdkfd/kfd_svm.h | 21 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8 -0
@@ -187,6 +187,14 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev) .enable_mes = adev->enable_mes, }; +/* Say so rather than letting the capability silently vanish +* from the KFD topology. +*/ +if (gpu_resources.gpuvm_size <AMDGPU_GMC_HOLE_START ) +dev_warn (adev->dev, +"GPUVM aperture 0x%llx cannot represent CPU addresses, KFD SVM disabled (amdgpu.vm_size=%d)\n" , + gpu_resources.gpuvm_size, amdgpu_vm_size); +/* this is going to have a few of the MSBs set that we need to * clear */
drivers/gpu/drm/amd/amdkfd/kfd_svm.h +19 -2
@@ -197,11 +197,28 @@ struct kfd_process_device * svm_range_get_pdd_by_node(struct svm_range *prange, struct kfd_node *node);void svm_range_list_lock_and_flush_work (struct svm_range_list *svms,struct mm_struct *mm); +/* SVM maps memory at the CPU virtual address, so the GPUVM aperture has to be +* able to represent every address the CPU can hand out. Below that, the page +* table walk in amdgpu_vm_ptes_update() indexes the root directory past the +* end of its entry array instead of the range being rejected. +* +* The parameter has to be named adev: AMDGPU_GMC_HOLE_START expands to an +* expression referencing adev->vm_manager.max_level. +*/ +static inline bool kfd_svm_vm_covers_user_va (struct amdgpu_device *adev) +{ +return (adev->vm_manager.max_pfn <<AMDGPU_GPU_PAGE_SHIFT ) >= +AMDGPU_GMC_HOLE_START ; +} +/* SVM API and HMM page migration work together, device memory type * is initialized to not 0 when page migration register device memory. */ -#define KFD_IS_SVM_API_SUPPORTED (adev) ((adev)->kfd.pgmap.type != 0 ||\ - ((adev)->apu_prefer_gtt)) +static inline bool KFD_IS_SVM_API_SUPPORTED (struct amdgpu_device *adev) +{ +return (adev->kfd.pgmap.type !=0 || adev->apu_prefer_gtt) && +kfd_svm_vm_covers_user_va (adev); +}void svm_range_bo_unref_async (struct svm_range_bo *svm_bo);
--
2.43.0