All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.