* [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute
@ 2026-12-04 20:16 Amir Shetaia
2026-12-04 20:39 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Amir Shetaia @ 2026-12-04 20:16 UTC (permalink / raw)
To: amd-gfx
Cc: Alex Deucher, Harish Kasiviswanathan, Felix Kuehling,
Christian König
amdgpu_vm_make_compute() switches a VM to CPU page table updates when
compute VMs use the CPU path (vm_update_mode, the default when all of
VRAM is CPU visible). Before switching it waits for the last SDMA
update/clear of the root PD with amdgpu_bo_sync_wait().
That helper goes through amdgpu_sync_resv(), which only iterates
DMA_RESV_USAGE_READ fences. Since commit 4247084057cf
("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2") page table updates add
their fence to the root reservation with DMA_RESV_USAGE_BOOKKEEP, so the
wait no longer covers the clear of the root PD issued at VM creation.
A process that maps memory right after AMDKFD_IOC_ACQUIRE_VM can then
write a root PDE with the CPU before the pending SDMA clear of the root
PD has executed, and the clear wipes the entry. The GPU later takes a
not-present fault on the mapped address. We hit this as a CPC fault on a
user queue's write pointer page; walking the VM with UMR while the fault
was pending showed the root entry as 0x8000000000000000. Adding a short
delay after ACQUIRE_VM made the fault go away.
Wait for all fences on the root reservation, including BOOKKEEP, before
switching to CPU updates. The dma_resv_wait_timeout() result is kept in
a long, since MAX_SCHEDULE_TIMEOUT does not fit in an int.
Tested on gfx1201 with a v7.0 based kernel and a reproducer that
acquires a VM, maps buffers and creates an SDMA queue right away:
8 of 8 runs faulted without this patch, 0 of 8 with it.
Fixes: 4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2")
Signed-off-by: Amir Shetaia <amir.shetaia@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 0b8a8f82ecab..cc743df64af6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2728,6 +2728,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
*/
int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
{
+ long wait;
int r;
r = amdgpu_bo_reserve(vm->root.bo, true);
@@ -2744,11 +2745,16 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
"CPU update of VM recommended only for large BAR system\n");
if (vm->use_cpu_for_update) {
- /* Sync with last SDMA update/clear before switching to CPU */
- r = amdgpu_bo_sync_wait(vm->root.bo,
- AMDGPU_FENCE_OWNER_UNDEFINED, true);
- if (r)
+ /* Sync with last SDMA update/clear before switching to CPU.
+ * PT updates are BOOKKEEP fences, amdgpu_bo_sync_wait() skips them.
+ */
+ wait = dma_resv_wait_timeout(vm->root.bo->tbo.base.resv,
+ DMA_RESV_USAGE_BOOKKEEP, true,
+ MAX_SCHEDULE_TIMEOUT);
+ if (wait < 0) {
+ r = wait;
goto unreserve_bo;
+ }
vm->update_funcs = &amdgpu_vm_cpu_funcs;
r = amdgpu_vm_pt_map_tables(adev, vm);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute
2026-12-04 20:16 [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute Amir Shetaia
@ 2026-12-04 20:39 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 20:39 UTC (permalink / raw)
To: Amir Shetaia, amd-gfx
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amdgpu: BOOKKEEP wait in amdgpu_vm_make_compute() evicts
KGD userqs
- [Low] drm/amdgpu: Fixes tag cites 4247084057cf instead of 926c79ad6ecd
--
commit f7d48a981689f9a016015e4327294adae6c1d421
Author: Amir Shetaia <amir.shetaia@amd.com>
> drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute
>
> amdgpu_vm_make_compute() switches a VM to CPU page table updates when
> compute VMs use the CPU path (vm_update_mode, the default when all of
> VRAM is CPU visible). Before switching it waits for the last SDMA
> update/clear of the root PD with amdgpu_bo_sync_wait().
>
> That helper goes through amdgpu_sync_resv(), which only iterates
> DMA_RESV_USAGE_READ fences. Since commit 4247084057cf
> ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2") page table updates add
> their fence to the root reservation with DMA_RESV_USAGE_BOOKKEEP, so the
> wait no longer covers the clear of the root PD issued at VM creation.
>
> A process that maps memory right after AMDKFD_IOC_ACQUIRE_VM can then
> write a root PDE with the CPU before the pending SDMA clear of the root
> PD has executed, and the clear wipes the entry. The GPU later takes a
> not-present fault on the mapped address. We hit this as a CPC fault on a
> user queue's write pointer page; walking the VM with UMR while the fault
> was pending showed the root entry as 0x8000000000000000. Adding a short
> delay after ACQUIRE_VM made the fault go away.
>
> Wait for all fences on the root reservation, including BOOKKEEP, before
> switching to CPU updates. The dma_resv_wait_timeout() result is kept in
> a long, since MAX_SCHEDULE_TIMEOUT does not fit in an int.
>
> Tested on gfx1201 with a v7.0 based kernel and a reproducer that
> acquires a VM, maps buffers and creates an SDMA queue right away:
> 8 of 8 runs faulted without this patch, 0 of 8 with it.
>
> Fixes: 4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2")
> Signed-off-by: Amir Shetaia <amir.shetaia@amd.com>
[Severity: Low]
Should the Fixes tag (and commit message) cite 926c79ad6ecd ("drm/amdgpu:
promote the implicit sync to the dependent read fences") instead of
4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2")?
amdgpu_sync_resv() still iterated DMA_RESV_USAGE_BOOKKEEP fences until
the 2025 commit changed it to DMA_RESV_USAGE_READ, so
amdgpu_bo_sync_wait() kept waiting on PT updates prior to that. Citing
the earlier commit can cause stable backport tooling to flag unaffected
LTS kernels.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index a3758c654dd42..130dbcbf3c85c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
[ ... ]
> @@ -2721,11 +2722,16 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
> "CPU update of VM recommended only for large BAR system\n");
>
> if (vm->use_cpu_for_update) {
> - /* Sync with last SDMA update/clear before switching to CPU */
> - r = amdgpu_bo_sync_wait(vm->root.bo,
> - AMDGPU_FENCE_OWNER_UNDEFINED, true);
> - if (r)
> + /* Sync with last SDMA update/clear before switching to CPU.
> + * PT updates are BOOKKEEP fences, amdgpu_bo_sync_wait() skips them.
> + */
> + wait = dma_resv_wait_timeout(vm->root.bo->tbo.base.resv,
> + DMA_RESV_USAGE_BOOKKEEP, true,
> + MAX_SCHEDULE_TIMEOUT);
> + if (wait < 0) {
> + r = wait;
> goto unreserve_bo;
> + }
[Severity: Medium]
Can waiting on all DMA_RESV_USAGE_BOOKKEEP fences here trigger an
unintended eviction of active KGD user queues?
If a process creates a KGD user queue on a DRM render fd before calling
AMDKFD_IOC_ACQUIRE_VM on it, amdgpu_evf_mgr_attach_fence() attaches an
unsignaled amdgpu_eviction_fence to vm->root.bo with
DMA_RESV_USAGE_BOOKKEEP.
Waiting on that fence enables signaling and schedules suspend_work ->
amdgpu_userq_evict(), draining every active user queue's last_fence
uninterruptibly and unmapping all user queues via MES while vm->root.bo
is reserved, stalling AMDKFD_IOC_ACQUIRE_VM until they are evicted and
later remapped.
Switching to amdgpu_vm_cpu_funcs only needs to wait for kernel/move
fences and pending SDMA PT updates (AMDGPU_FENCE_OWNER_VM), and can skip
waiting for SDMA updates when vm->update_funcs is already
&amdgpu_vm_cpu_funcs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204201649.375581-1-amir.shetaia@amd.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 20:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 20:16 [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute Amir Shetaia
2026-12-04 20:39 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox