AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] Consolidate and fix root PD fence resverations
@ 2026-11-18 18:52 Benjamin Cheng
  2026-11-18 18:52 ` [PATCH 1/8] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

In [1] I originally wanted to just stop using amdgpu_bo_fence. However
while attempting to address Christian's comment about reserving the
fences upfront when the PD is locked, I realized that there are many
places that are not reserving enough fences in the worst-case.

I went through and audited every lock of the VM root PD and I think I
have caught everything missing fence reservations in this series. I
have lightly tested this and didn't see any issues, and in general
this is reserving more fences than the typical case so it shouldn't
cause any BUG_ONs.

Patch 1 through 3 here are the reservation fixes. Basically since we
started enabling more clear/move entities to be used, we should be
reserving the worst-case space upfront. Also when the TLB flush fence
was added we did not add reserve space for it.

Patch 4 and 5 are cleanups that I found (not everywhere locking the PD
does validation or VM updates), and patches 6 through 8 are the
amdgpu_bo_fence() removal series from [1].

[1]: https://lore.kernel.org/amd-gfx/20261112164408.1748006-1-benjamin.cheng@amd.com/

Benjamin Cheng (8):
  drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd
  drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify
  drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault
  drm/amdgpu: reserve only what the caller asks for in lock_pd
  drm/amdgpu/userq: remove extra fence request when locking PD
  drm/amdgpu/vm: stop using amdgpu_bo_fence
  drm/amdgpu/uvd: stop using amdgpu_bo_fence
  drm/amdgpu/object: get rid of amdgpu_bo_fence

 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 13 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  5 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    | 25 -------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    |  2 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c    | 12 +++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c     |  6 ++---
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c       | 17 ++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 14 ++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        |  8 ++++++
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c          |  3 ++-
 14 files changed, 58 insertions(+), 56 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/8] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-19 13:19   ` Christian König
  2026-11-18 18:52 ` [PATCH 2/8] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

Any page table update may currently add up to three fences to the root
PD's resv (last_unlocked, SDMA commit, and TLB flush). In addition if
any PD/PT BOs need to be allocated, it can add up to TTM_NUM_MOVE_FENCES
on top.

Introduce AMDGPU_VM_UPDATE_FENCES for this count and reserve it in
amdgpu_vm_lock_pd().

Fixes: d8a3f0a0348d ("drm/amdgpu: implement TLB flush fence")
Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
Fixes: ddc3c87584e2 ("drm/amdgpu: clear vm pts upon a vm->generation mismatch")
Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     | 8 ++++++++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index 2d4a17e11a1f..2403cd911058 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -3073,9 +3073,9 @@ static void amdgpu_ualink_invalidate_import_mappings(struct amdgpu_bo *bo)
 		struct amdgpu_vm *vm = bo_base->vm;
 
 		/*
-		 * Fences for the two SDMA page table updates were already
-		 * reserved by amdgpu_vm_lock_pd() above (it reserves 2 +
-		 * num_fences on the same VM root PD dma_resv).
+		 * Fences for the two page table updates were already
+		 * reserved by amdgpu_vm_lock_pd() above on the same VM
+		 * root PD dma_resv.
 		 */
 		r = amdgpu_vm_clear_freed(adev, vm, NULL);
 		if (!r)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 8cc5964f29c0..6d8d639e5986 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -462,9 +462,8 @@ void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
 int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
 		      unsigned int num_fences)
 {
-	/* We need at least two fences for the VM PD/PT updates */
 	return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base,
-				    2 + num_fences);
+				    AMDGPU_VM_UPDATE_FENCES + num_fences);
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index f6285a9d9e98..8117bec01e4e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -187,6 +187,14 @@ struct amdgpu_bo_vm;
 #define AMDGPU_VM_USE_CPU_FOR_GFX (1 << 0)
 #define AMDGPU_VM_USE_CPU_FOR_COMPUTE (1 << 1)
 
+/*
+ * The number of fence slots needed on the root PD resv for a page table
+ * update: last_unlocked, the SDMA commit fence, the TLB flush fence, plus
+ * the TTM eviction/move fences of any PD/PT BO that is validated or allocated.
+ * This needs to be bumped whenever a new fence is added.
+ */
+#define AMDGPU_VM_UPDATE_FENCES (3 + TTM_NUM_MOVE_FENCES)
+
 /* VMPT level enumerate, and the hiberachy is:
  * PDB3->PDB2->PDB1->PDB0->PTB
  */
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/8] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
  2026-11-18 18:52 ` [PATCH 1/8] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-19 13:22   ` Christian König
  2026-11-18 18:52 ` [PATCH 3/8] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

This is about to update the VM so we need to use the macro previously
introduced to make sure there are enough fence slots.

Fixes: d8a3f0a0348d ("drm/amdgpu: implement TLB flush fence")
Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
index 7b85152d6872..d3a7cf9c274c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
@@ -562,7 +562,7 @@ amdgpu_dma_buf_move_notify(struct dma_buf_attachment *attach)
 		}
 
 		/* Reserve fences for two SDMA page table updates */
-		r = dma_resv_reserve_fences(resv, 2);
+		r = dma_resv_reserve_fences(resv, AMDGPU_VM_UPDATE_FENCES);
 		if (!r)
 			r = amdgpu_vm_clear_freed(adev, vm, NULL);
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/8] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
  2026-11-18 18:52 ` [PATCH 1/8] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
  2026-11-18 18:52 ` [PATCH 2/8] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-19 13:24   ` Christian König
  2026-11-18 18:52 ` [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

Reserving 1 hasn't been enough here for a while (last_unlocked was never
considered originally).

Fixes: 2b665c3735b3 ("drm/amdgpu: reserve fence slot to update page table")
Fixes: d8a3f0a0348d ("drm/amdgpu: implement TLB flush fence")
Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 6d8d639e5986..f4a836594e7c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -3186,7 +3186,7 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
 		value = 0;
 	}
 
-	r = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv, 1);
+	r = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv, AMDGPU_VM_UPDATE_FENCES);
 	if (r) {
 		pr_debug("failed %d to reserve fence slot\n", r);
 		goto error_unlock;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (2 preceding siblings ...)
  2026-11-18 18:52 ` [PATCH 3/8] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-19 13:27   ` Christian König
  2026-11-18 18:52 ` [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

amdgpu_vm_lock_pd() reserved AMDGPU_VM_UPDATE_FENCES for every caller,
including ones that only lock the root PD to add or remove a mapping and
never update the page tables.

Address this by making it only reserve what the caller asks for, so that
such callers have the option to not over-reserve. The only touched
call-sites in this change are the ones that do require fences.

Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 13 ++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c           |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          |  5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c       |  6 ++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c        |  6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c           |  8 +++++---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c             |  3 ++-
 7 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index a6616447abc8..56f761089b87 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1188,7 +1188,8 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
 	ctx->sync = &mem->sync;
 	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
 	drm_exec_until_all_locked(&ctx->exec) {
-		ret = amdgpu_vm_lock_pd(vm, &ctx->exec, 2);
+		ret = amdgpu_vm_lock_pd(vm, &ctx->exec,
+					AMDGPU_VM_UPDATE_FENCES + 2);
 		drm_exec_retry_on_contention(&ctx->exec);
 		if (unlikely(ret))
 			goto error;
@@ -1235,8 +1236,8 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
 				&& map_type != BO_VM_ALL))
 				continue;
 
-			ret = amdgpu_vm_lock_pd(entry->bo_va->base.vm,
-						&ctx->exec, 2);
+			ret = amdgpu_vm_lock_pd(entry->bo_va->base.vm, &ctx->exec,
+						AMDGPU_VM_UPDATE_FENCES + 2);
 			drm_exec_retry_on_contention(&ctx->exec);
 			if (unlikely(ret))
 				goto error;
@@ -2729,7 +2730,8 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
 		/* Reserve all the page directories */
 		list_for_each_entry(peer_vm, &process_info->vm_list_head,
 				    vm_list_node) {
-			ret = amdgpu_vm_lock_pd(peer_vm, &exec, 2);
+			ret = amdgpu_vm_lock_pd(peer_vm, &exec,
+						AMDGPU_VM_UPDATE_FENCES + 2);
 			drm_exec_retry_on_contention(&exec);
 			if (unlikely(ret))
 				goto unreserve_out;
@@ -2993,7 +2995,8 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence __rcu *
 	drm_exec_until_all_locked(&exec) {
 		list_for_each_entry(peer_vm, &process_info->vm_list_head,
 				    vm_list_node) {
-			ret = amdgpu_vm_lock_pd(peer_vm, &exec, 2);
+			ret = amdgpu_vm_lock_pd(peer_vm, &exec,
+						AMDGPU_VM_UPDATE_FENCES + 2);
 			drm_exec_retry_on_contention(&exec);
 			if (unlikely(ret)) {
 				pr_err("Locking VM PD failed, ret: %d\n", ret);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 71e2b83faa12..771ab4388eb1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -940,7 +940,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 	}
 
 	drm_exec_until_all_locked(&p->exec) {
-		r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec, 1 + p->gang_size);
+		r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec,
+				      AMDGPU_VM_UPDATE_FENCES + 1 + p->gang_size);
 		drm_exec_retry_on_contention(&p->exec);
 		if (unlikely(r))
 			goto out_free_user_pages;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index eb7473ed9e0e..dfb44426b1e2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -345,7 +345,7 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
 		if (unlikely(r))
 			goto out_unlock;
 
-		r = amdgpu_vm_lock_pd(vm, &exec, 0);
+		r = amdgpu_vm_lock_pd(vm, &exec, AMDGPU_VM_UPDATE_FENCES);
 		drm_exec_retry_on_contention(&exec);
 		if (unlikely(r))
 			goto out_unlock;
@@ -1002,7 +1002,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 				goto error;
 		}
 
-		r = amdgpu_vm_lock_pd(&fpriv->vm, &exec, 2);
+		r = amdgpu_vm_lock_pd(&fpriv->vm, &exec,
+				      AMDGPU_VM_UPDATE_FENCES + 2);
 		drm_exec_retry_on_contention(&exec);
 		if (unlikely(r))
 			goto error;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index 2403cd911058..8a613d83ed53 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -3053,7 +3053,8 @@ static void amdgpu_ualink_invalidate_import_mappings(struct amdgpu_bo *bo)
 			goto fini;
 
 		for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) {
-			r = amdgpu_vm_lock_pd(bo_base->vm, &exec, 0);
+			r = amdgpu_vm_lock_pd(bo_base->vm, &exec,
+					      AMDGPU_VM_UPDATE_FENCES);
 			drm_exec_retry_on_contention(&exec);
 			if (unlikely(r))
 				goto fini;
@@ -4788,7 +4789,8 @@ static int amdgpu_ualink_reserve_npa_vm_and_bos(struct amdgpu_device *adev,
 				goto out;
 		}
 
-		r = amdgpu_vm_lock_pd(&adev->ualink.npa_vm, exec, 0);
+		r = amdgpu_vm_lock_pd(&adev->ualink.npa_vm, exec,
+				      AMDGPU_VM_UPDATE_FENCES);
 		drm_exec_retry_on_contention(exec);
 		if (unlikely(r))
 			goto out;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index ed6f3b67e872..73e58d1a32ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -1054,10 +1054,10 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 0);
 	drm_exec_until_all_locked(&exec) {
 		/*
-		 * Rearm adds one BOOKKEEP fence and validation may queue move fences
-		 * on the root PD BO, so reserve caller-side slots accordingly.
+		 * Rearm adds one BOOKKEEP fence and validation requires
+		 * AMDGPU_VM_UPDATE_FENCES.
 		 */
-		ret = amdgpu_vm_lock_pd(vm, &exec, TTM_NUM_MOVE_FENCES + 1);
+		ret = amdgpu_vm_lock_pd(vm, &exec, AMDGPU_VM_UPDATE_FENCES + 1);
 		drm_exec_retry_on_contention(&exec);
 		if (unlikely(ret))
 			goto unlock_all;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index f4a836594e7c..daf0e75d0bb1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -455,15 +455,17 @@ void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
  *
  * @vm: vm providing the BOs
  * @exec: drm execution context
- * @num_fences: number of extra fences to reserve
+ * @num_fences: number of fence slots to reserve, 0 to only lock the PD
  *
  * Lock the VM root PD in the DRM execution context.
  */
 int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
 		      unsigned int num_fences)
 {
-	return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base,
-				    AMDGPU_VM_UPDATE_FENCES + num_fences);
+	if (!num_fences)
+		return drm_exec_lock_obj(exec, &vm->root.bo->tbo.base);
+
+	return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base, num_fences);
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 3f32507e2aae..6dcc12289e92 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -1686,7 +1686,8 @@ static int svm_range_reserve_bos(struct svm_validate_context *ctx, bool intr)
 			}
 			vm = drm_priv_to_vm(pdd->drm_priv);
 
-			r = amdgpu_vm_lock_pd(vm, &ctx->exec, 2);
+			r = amdgpu_vm_lock_pd(vm, &ctx->exec,
+					      AMDGPU_VM_UPDATE_FENCES + 2);
 			drm_exec_retry_on_contention(&ctx->exec);
 			if (unlikely(r)) {
 				pr_debug("failed %d to reserve bo\n", r);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (3 preceding siblings ...)
  2026-11-18 18:52 ` [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-18 19:05   ` sashiko-bot
  2026-11-19 13:35   ` Christian König
  2026-11-18 18:52 ` [PATCH 6/8] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

These two fences are never used, so just request no fences (lock only).

Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
index dd976a50e053..855e521eb201 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
@@ -382,7 +382,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_device *adev,
 
 	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 2);
 	drm_exec_until_all_locked(&exec) {
-		ret = amdgpu_vm_lock_pd(queue->vm, &exec, 1);
+		ret = amdgpu_vm_lock_pd(queue->vm, &exec, 0);
 		drm_exec_retry_on_contention(&exec);
 		if (unlikely(ret))
 			goto lock_error;
diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 7abb9d95ef59..8b07e21d2686 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -48,7 +48,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
 
 	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 2);
 	drm_exec_until_all_locked(&exec) {
-		ret = amdgpu_vm_lock_pd(vm, &exec, 1);
+		ret = amdgpu_vm_lock_pd(vm, &exec, 0);
 		drm_exec_retry_on_contention(&exec);
 		if (unlikely(ret))
 			goto fail_lock;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 6/8] drm/amdgpu/vm: stop using amdgpu_bo_fence
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (4 preceding siblings ...)
  2026-11-18 18:52 ` [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-19 13:41   ` Christian König
  2026-11-18 18:52 ` [PATCH 7/8] drm/amdgpu/uvd: " Benjamin Cheng
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

Switch to stop using this deprecated helper.

The original could be incorrect under certain circumstances, since the
amdgpu_bo_fence only reserves one slot, and at the time of calling the
SDMA commit and TLB flush fences were not added yet (the reserve_fences
is not additive). In addition this allows us to switch to use BOOKKEEP
usage.

Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index daf0e75d0bb1..2a8abc9684b7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1216,7 +1216,8 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (!unlocked && !dma_fence_is_signaled(vm->last_unlocked)) {
 		struct dma_fence *tmp = dma_fence_get_stub();
 
-		amdgpu_bo_fence(vm->root.bo, vm->last_unlocked, true);
+		dma_resv_add_fence(vm->root.bo->tbo.base.resv, vm->last_unlocked,
+				   DMA_RESV_USAGE_BOOKKEEP);
 		swap(vm->last_unlocked, tmp);
 		dma_fence_put(tmp);
 	}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 7/8] drm/amdgpu/uvd: stop using amdgpu_bo_fence
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (5 preceding siblings ...)
  2026-11-18 18:52 ` [PATCH 6/8] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-19 13:43   ` Christian König
  2026-11-18 18:52 ` [PATCH 8/8] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
  2026-11-18 18:58 ` [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
  8 siblings, 1 reply; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

This helper is deprecated since it is incorrect in most circumstances.
This was a circumstance where it was mostly correct but it is the only
remaining usage, so get rid of it here.

Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index d88dde859615..9570db033b18 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -1154,16 +1154,24 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
 		if (r)
 			goto err_free;
 	} else {
+		r = amdgpu_bo_reserve(bo, true);
+		if (r)
+			goto err_free;
+
 		r = drm_sched_job_add_resv_dependencies(&job->base,
 							bo->tbo.base.resv,
 							DMA_RESV_USAGE_KERNEL);
 		if (r)
-			goto err_free;
+			goto err_unreserve;
 
 		f = amdgpu_job_submit(job);
 
-		amdgpu_bo_reserve(bo, true);
-		amdgpu_bo_fence(bo, f, false);
+		r = dma_resv_reserve_fences(bo->tbo.base.resv, 1);
+		if (r) {
+			dma_fence_wait(f, false);
+			r = 0;
+		} else
+			dma_resv_add_fence(bo->tbo.base.resv, f, DMA_RESV_USAGE_BOOKKEEP);
 		amdgpu_bo_unreserve(bo);
 	}
 
@@ -1173,6 +1181,9 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
 
 	return 0;
 
+err_unreserve:
+	amdgpu_bo_unreserve(bo);
+
 err_free:
 	amdgpu_job_free(job);
 	return r;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 8/8] drm/amdgpu/object: get rid of amdgpu_bo_fence
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (6 preceding siblings ...)
  2026-11-18 18:52 ` [PATCH 7/8] drm/amdgpu/uvd: " Benjamin Cheng
@ 2026-11-18 18:52 ` Benjamin Cheng
  2026-11-19 13:47   ` Christian König
  2026-11-18 18:58 ` [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
  8 siblings, 1 reply; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

All uses of this function have been removed, so we can now get rid of
this function.

Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 25 ----------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  2 --
 2 files changed, 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index d4651f2d437c..ba9b5ed71cf7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -1463,31 +1463,6 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 	return 0;
 }
 
-/**
- * amdgpu_bo_fence - add fence to buffer object
- *
- * @bo: buffer object in question
- * @fence: fence to add
- * @shared: true if fence should be added shared
- *
- */
-void amdgpu_bo_fence(struct amdgpu_bo *bo, struct dma_fence *fence,
-		     bool shared)
-{
-	struct dma_resv *resv = bo->tbo.base.resv;
-	int r;
-
-	r = dma_resv_reserve_fences(resv, 1);
-	if (r) {
-		/* As last resort on OOM we block for the fence */
-		dma_fence_wait(fence, false);
-		return;
-	}
-
-	dma_resv_add_fence(resv, fence, shared ? DMA_RESV_USAGE_READ :
-			   DMA_RESV_USAGE_WRITE);
-}
-
 /**
  * amdgpu_bo_sync_wait_resv - Wait for BO reservation fences
  *
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 8e67a8e60572..33a1bfce79e1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -305,8 +305,6 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
 			   struct ttm_resource *new_mem);
 void amdgpu_bo_release_notify(struct ttm_buffer_object *bo);
 vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
-void amdgpu_bo_fence(struct amdgpu_bo *bo, struct dma_fence *fence,
-		     bool shared);
 int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv,
 			     enum amdgpu_sync_mode sync_mode, void *owner,
 			     bool intr);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/8] Consolidate and fix root PD fence resverations
  2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (7 preceding siblings ...)
  2026-11-18 18:52 ` [PATCH 8/8] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
@ 2026-11-18 18:58 ` Benjamin Cheng
  8 siblings, 0 replies; 19+ messages in thread
From: Benjamin Cheng @ 2026-11-18 18:58 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 2026-11-18 13:52, Benjamin Cheng wrote:
> In [1] I originally wanted to just stop using amdgpu_bo_fence. However
> while attempting to address Christian's comment about reserving the
> fences upfront when the PD is locked, I realized that there are many
> places that are not reserving enough fences in the worst-case.
>
> I went through and audited every lock of the VM root PD and I think I
> have caught everything missing fence reservations in this series. I
> have lightly tested this and didn't see any issues, and in general
> this is reserving more fences than the typical case so it shouldn't
> cause any BUG_ONs.
>
> Patch 1 through 3 here are the reservation fixes. Basically since we
> started enabling more clear/move entities to be used, we should be
> reserving the worst-case space upfront. Also when the TLB flush fence
> was added we did not add reserve space for it.
>
> Patch 4 and 5 are cleanups that I found (not everywhere locking the PD
> does validation or VM updates), and patches 6 through 8 are the
> amdgpu_bo_fence() removal series from [1].
>
> [1]: https://lore.kernel.org/amd-gfx/20261112164408.1748006-1-benjamin.cheng@amd.com/
>
> Benjamin Cheng (8):
>   drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd
>   drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify
>   drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault
>   drm/amdgpu: reserve only what the caller asks for in lock_pd
>   drm/amdgpu/userq: remove extra fence request when locking PD
>   drm/amdgpu/vm: stop using amdgpu_bo_fence
>   drm/amdgpu/uvd: stop using amdgpu_bo_fence
>   drm/amdgpu/object: get rid of amdgpu_bo_fence

Sorry, please disregard this series. I forgot two patches, sending them out shortly...

>
>  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 13 ++++++----
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  3 ++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c   |  2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  5 ++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    | 25 -------------------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    |  2 --
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c    | 12 +++++----
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c     |  6 ++---
>  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   |  2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c       | 17 ++++++++++---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 14 ++++++-----
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        |  8 ++++++
>  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c    |  2 +-
>  drivers/gpu/drm/amd/amdkfd/kfd_svm.c          |  3 ++-
>  14 files changed, 58 insertions(+), 56 deletions(-)
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD
  2026-11-18 18:52 ` [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
@ 2026-11-18 19:05   ` sashiko-bot
  2026-11-19 13:35   ` Christian König
  1 sibling, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-11-18 19:05 UTC (permalink / raw)
  To: Benjamin Cheng, amd-gfx

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] drm/amdgpu: ignored WPTR mapping offsets in userqueue
  synchronization [1]
--

commit c736ecb92e4ba4e91728f33ea27cd11d90100ae5
Author: Benjamin Cheng <benjamin.cheng@amd.com>

drm/amdgpu/userq: remove extra fence request when locking PD

This commit changes amdgpu_vm_lock_pd() calls in
amdgpu_userq_fence_read_wptr() and mes_userq_create_wptr_mapping() to
request zero fence slots instead of one.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> index 6d1f5811d39c3..07a0af9feaf08 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> @@ -380,7 +380,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_device *adev,
>  
>  	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 2);
>  	drm_exec_until_all_locked(&exec) {
> -		ret = amdgpu_vm_lock_pd(queue->vm, &exec, 1);
> +		ret = amdgpu_vm_lock_pd(queue->vm, &exec, 0);
>  		drm_exec_retry_on_contention(&exec);
>  		if (unlikely(ret))
>  			goto lock_error;
> diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> index 7abb9d95ef59a..8b07e21d26862 100644
> --- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> @@ -48,7 +48,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
>  
>  	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 2);
>  	drm_exec_until_all_locked(&exec) {
> -		ret = amdgpu_vm_lock_pd(vm, &exec, 1);
> +		ret = amdgpu_vm_lock_pd(vm, &exec, 0);
>  		drm_exec_retry_on_contention(&exec);
>  		if (unlikely(ret))
>  			goto fail_lock;

[Severity: High]
This problem wasn't introduced by this patch, but does
mes_userq_create_wptr_mapping() ignore the internal mapping and sub-page
offset when setting queue->wptr_obj.gpu_addr [1]?

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c:mes_userq_create_wptr_mapping() {
    ...
	queue->wptr_obj.gpu_addr = amdgpu_bo_gpu_offset(wptr_obj->obj);
    ...
}

When a usermode queue places its WPTR at a non-zero offset within the
backing BO, mes_userq_create_wptr_mapping() sets queue->wptr_obj.gpu_addr
to the base GPU offset of wptr_obj->obj without adding the mapping and
sub-page offsets (and if amdgpu_userq_fence_read_wptr() reads *ptr at
offset 0 directly, it misses the offset on the CPU side as well).  This
causes the firmware and CPU fence polling to read the wrong memory address,
leading to premature fence signaling or command submission deadlocks.

[1] https://sashiko.dev/#/bug/linux-485b27a5-4aad-464a-b5b7-ad02f7bafded

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118185225.1857845-1-benjamin.cheng@amd.com?part=5

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/8] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd
  2026-11-18 18:52 ` [PATCH 1/8] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
@ 2026-11-19 13:19   ` Christian König
  0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:19 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> Any page table update may currently add up to three fences to the root
> PD's resv (last_unlocked, SDMA commit, and TLB flush). In addition if
> any PD/PT BOs need to be allocated, it can add up to TTM_NUM_MOVE_FENCES
> on top.

That is incorrect. The last_unlocked and SDMA commit is on the same timeline, so we only need two.

> Introduce AMDGPU_VM_UPDATE_FENCES for this count and reserve it in
> amdgpu_vm_lock_pd().

The function amdgpu_vm_lock_pd() was introduced to avoid such a define.

Regards,
Christian.

> 
> Fixes: d8a3f0a0348d ("drm/amdgpu: implement TLB flush fence")
> Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
> Fixes: ddc3c87584e2 ("drm/amdgpu: clear vm pts upon a vm->generation mismatch")
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 6 +++---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 3 +--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     | 8 ++++++++
>  3 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index 2d4a17e11a1f..2403cd911058 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> @@ -3073,9 +3073,9 @@ static void amdgpu_ualink_invalidate_import_mappings(struct amdgpu_bo *bo)
>  		struct amdgpu_vm *vm = bo_base->vm;
>  
>  		/*
> -		 * Fences for the two SDMA page table updates were already
> -		 * reserved by amdgpu_vm_lock_pd() above (it reserves 2 +
> -		 * num_fences on the same VM root PD dma_resv).
> +		 * Fences for the two page table updates were already
> +		 * reserved by amdgpu_vm_lock_pd() above on the same VM
> +		 * root PD dma_resv.
>  		 */
>  		r = amdgpu_vm_clear_freed(adev, vm, NULL);
>  		if (!r)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 8cc5964f29c0..6d8d639e5986 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -462,9 +462,8 @@ void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
>  int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
>  		      unsigned int num_fences)
>  {
> -	/* We need at least two fences for the VM PD/PT updates */
>  	return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base,
> -				    2 + num_fences);
> +				    AMDGPU_VM_UPDATE_FENCES + num_fences);
>  }
>  
>  /**
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> index f6285a9d9e98..8117bec01e4e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> @@ -187,6 +187,14 @@ struct amdgpu_bo_vm;
>  #define AMDGPU_VM_USE_CPU_FOR_GFX (1 << 0)
>  #define AMDGPU_VM_USE_CPU_FOR_COMPUTE (1 << 1)
>  
> +/*
> + * The number of fence slots needed on the root PD resv for a page table
> + * update: last_unlocked, the SDMA commit fence, the TLB flush fence, plus
> + * the TTM eviction/move fences of any PD/PT BO that is validated or allocated.
> + * This needs to be bumped whenever a new fence is added.
> + */
> +#define AMDGPU_VM_UPDATE_FENCES (3 + TTM_NUM_MOVE_FENCES)
> +
>  /* VMPT level enumerate, and the hiberachy is:
>   * PDB3->PDB2->PDB1->PDB0->PTB
>   */


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/8] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify
  2026-11-18 18:52 ` [PATCH 2/8] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
@ 2026-11-19 13:22   ` Christian König
  0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:22 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> This is about to update the VM so we need to use the macro previously
> introduced to make sure there are enough fence slots.

The amdgpu_dma_buf_move_notify() path should use the unlocked approach I'm currently working on the KFD team and Timur.

So that here is unnecessary to begin with.

Regards,
Christian.

> 
> Fixes: d8a3f0a0348d ("drm/amdgpu: implement TLB flush fence")
> Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> index 7b85152d6872..d3a7cf9c274c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> @@ -562,7 +562,7 @@ amdgpu_dma_buf_move_notify(struct dma_buf_attachment *attach)
>  		}
>  
>  		/* Reserve fences for two SDMA page table updates */
> -		r = dma_resv_reserve_fences(resv, 2);
> +		r = dma_resv_reserve_fences(resv, AMDGPU_VM_UPDATE_FENCES);
>  		if (!r)
>  			r = amdgpu_vm_clear_freed(adev, vm, NULL);
>  


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/8] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault
  2026-11-18 18:52 ` [PATCH 3/8] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
@ 2026-11-19 13:24   ` Christian König
  0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:24 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> Reserving 1 hasn't been enough here for a while (last_unlocked was never
> considered originally).

Again completely unnecessary. The fault handling can't use a TLB fence.

Regards,
Christian.

> 
> Fixes: 2b665c3735b3 ("drm/amdgpu: reserve fence slot to update page table")
> Fixes: d8a3f0a0348d ("drm/amdgpu: implement TLB flush fence")
> Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 6d8d639e5986..f4a836594e7c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -3186,7 +3186,7 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
>  		value = 0;
>  	}
>  
> -	r = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv, 1);
> +	r = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv, AMDGPU_VM_UPDATE_FENCES);
>  	if (r) {
>  		pr_debug("failed %d to reserve fence slot\n", r);
>  		goto error_unlock;


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd
  2026-11-18 18:52 ` [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
@ 2026-11-19 13:27   ` Christian König
  0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:27 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> amdgpu_vm_lock_pd() reserved AMDGPU_VM_UPDATE_FENCES for every caller,
> including ones that only lock the root PD to add or remove a mapping and
> never update the page tables.

Yeah clear NAK.

First of all reserving fences is cheap there is no need to avoid that.

Then that completely defines the purpose of the amdgpu_vm_lock_pd() function.

Regards,
Christian.

> 
> Address this by making it only reserve what the caller asks for, so that
> such callers have the option to not over-reserve. The only touched
> call-sites in this change are the ones that do require fences.
> 
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 13 ++++++++-----
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c           |  3 ++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          |  5 +++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c       |  6 ++++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c        |  6 +++---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c           |  8 +++++---
>  drivers/gpu/drm/amd/amdkfd/kfd_svm.c             |  3 ++-
>  7 files changed, 27 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index a6616447abc8..56f761089b87 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -1188,7 +1188,8 @@ static int reserve_bo_and_vm(struct kgd_mem *mem,
>  	ctx->sync = &mem->sync;
>  	drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
>  	drm_exec_until_all_locked(&ctx->exec) {
> -		ret = amdgpu_vm_lock_pd(vm, &ctx->exec, 2);
> +		ret = amdgpu_vm_lock_pd(vm, &ctx->exec,
> +					AMDGPU_VM_UPDATE_FENCES + 2);
>  		drm_exec_retry_on_contention(&ctx->exec);
>  		if (unlikely(ret))
>  			goto error;
> @@ -1235,8 +1236,8 @@ static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
>  				&& map_type != BO_VM_ALL))
>  				continue;
>  
> -			ret = amdgpu_vm_lock_pd(entry->bo_va->base.vm,
> -						&ctx->exec, 2);
> +			ret = amdgpu_vm_lock_pd(entry->bo_va->base.vm, &ctx->exec,
> +						AMDGPU_VM_UPDATE_FENCES + 2);
>  			drm_exec_retry_on_contention(&ctx->exec);
>  			if (unlikely(ret))
>  				goto error;
> @@ -2729,7 +2730,8 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
>  		/* Reserve all the page directories */
>  		list_for_each_entry(peer_vm, &process_info->vm_list_head,
>  				    vm_list_node) {
> -			ret = amdgpu_vm_lock_pd(peer_vm, &exec, 2);
> +			ret = amdgpu_vm_lock_pd(peer_vm, &exec,
> +						AMDGPU_VM_UPDATE_FENCES + 2);
>  			drm_exec_retry_on_contention(&exec);
>  			if (unlikely(ret))
>  				goto unreserve_out;
> @@ -2993,7 +2995,8 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence __rcu *
>  	drm_exec_until_all_locked(&exec) {
>  		list_for_each_entry(peer_vm, &process_info->vm_list_head,
>  				    vm_list_node) {
> -			ret = amdgpu_vm_lock_pd(peer_vm, &exec, 2);
> +			ret = amdgpu_vm_lock_pd(peer_vm, &exec,
> +						AMDGPU_VM_UPDATE_FENCES + 2);
>  			drm_exec_retry_on_contention(&exec);
>  			if (unlikely(ret)) {
>  				pr_err("Locking VM PD failed, ret: %d\n", ret);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 71e2b83faa12..771ab4388eb1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -940,7 +940,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
>  	}
>  
>  	drm_exec_until_all_locked(&p->exec) {
> -		r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec, 1 + p->gang_size);
> +		r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec,
> +				      AMDGPU_VM_UPDATE_FENCES + 1 + p->gang_size);
>  		drm_exec_retry_on_contention(&p->exec);
>  		if (unlikely(r))
>  			goto out_free_user_pages;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index eb7473ed9e0e..dfb44426b1e2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -345,7 +345,7 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
>  		if (unlikely(r))
>  			goto out_unlock;
>  
> -		r = amdgpu_vm_lock_pd(vm, &exec, 0);
> +		r = amdgpu_vm_lock_pd(vm, &exec, AMDGPU_VM_UPDATE_FENCES);
>  		drm_exec_retry_on_contention(&exec);
>  		if (unlikely(r))
>  			goto out_unlock;
> @@ -1002,7 +1002,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
>  				goto error;
>  		}
>  
> -		r = amdgpu_vm_lock_pd(&fpriv->vm, &exec, 2);
> +		r = amdgpu_vm_lock_pd(&fpriv->vm, &exec,
> +				      AMDGPU_VM_UPDATE_FENCES + 2);
>  		drm_exec_retry_on_contention(&exec);
>  		if (unlikely(r))
>  			goto error;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index 2403cd911058..8a613d83ed53 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> @@ -3053,7 +3053,8 @@ static void amdgpu_ualink_invalidate_import_mappings(struct amdgpu_bo *bo)
>  			goto fini;
>  
>  		for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) {
> -			r = amdgpu_vm_lock_pd(bo_base->vm, &exec, 0);
> +			r = amdgpu_vm_lock_pd(bo_base->vm, &exec,
> +					      AMDGPU_VM_UPDATE_FENCES);
>  			drm_exec_retry_on_contention(&exec);
>  			if (unlikely(r))
>  				goto fini;
> @@ -4788,7 +4789,8 @@ static int amdgpu_ualink_reserve_npa_vm_and_bos(struct amdgpu_device *adev,
>  				goto out;
>  		}
>  
> -		r = amdgpu_vm_lock_pd(&adev->ualink.npa_vm, exec, 0);
> +		r = amdgpu_vm_lock_pd(&adev->ualink.npa_vm, exec,
> +				      AMDGPU_VM_UPDATE_FENCES);
>  		drm_exec_retry_on_contention(exec);
>  		if (unlikely(r))
>  			goto out;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index ed6f3b67e872..73e58d1a32ba 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -1054,10 +1054,10 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
>  	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 0);
>  	drm_exec_until_all_locked(&exec) {
>  		/*
> -		 * Rearm adds one BOOKKEEP fence and validation may queue move fences
> -		 * on the root PD BO, so reserve caller-side slots accordingly.
> +		 * Rearm adds one BOOKKEEP fence and validation requires
> +		 * AMDGPU_VM_UPDATE_FENCES.
>  		 */
> -		ret = amdgpu_vm_lock_pd(vm, &exec, TTM_NUM_MOVE_FENCES + 1);
> +		ret = amdgpu_vm_lock_pd(vm, &exec, AMDGPU_VM_UPDATE_FENCES + 1);
>  		drm_exec_retry_on_contention(&exec);
>  		if (unlikely(ret))
>  			goto unlock_all;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index f4a836594e7c..daf0e75d0bb1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -455,15 +455,17 @@ void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
>   *
>   * @vm: vm providing the BOs
>   * @exec: drm execution context
> - * @num_fences: number of extra fences to reserve
> + * @num_fences: number of fence slots to reserve, 0 to only lock the PD
>   *
>   * Lock the VM root PD in the DRM execution context.
>   */
>  int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
>  		      unsigned int num_fences)
>  {
> -	return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base,
> -				    AMDGPU_VM_UPDATE_FENCES + num_fences);
> +	if (!num_fences)
> +		return drm_exec_lock_obj(exec, &vm->root.bo->tbo.base);
> +
> +	return drm_exec_prepare_obj(exec, &vm->root.bo->tbo.base, num_fences);
>  }
>  
>  /**
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> index 3f32507e2aae..6dcc12289e92 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> @@ -1686,7 +1686,8 @@ static int svm_range_reserve_bos(struct svm_validate_context *ctx, bool intr)
>  			}
>  			vm = drm_priv_to_vm(pdd->drm_priv);
>  
> -			r = amdgpu_vm_lock_pd(vm, &ctx->exec, 2);
> +			r = amdgpu_vm_lock_pd(vm, &ctx->exec,
> +					      AMDGPU_VM_UPDATE_FENCES + 2);
>  			drm_exec_retry_on_contention(&ctx->exec);
>  			if (unlikely(r)) {
>  				pr_debug("failed %d to reserve bo\n", r);


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD
  2026-11-18 18:52 ` [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
  2026-11-18 19:05   ` sashiko-bot
@ 2026-11-19 13:35   ` Christian König
  1 sibling, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:35 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> These two fences are never used, so just request no fences (lock only).
> 
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +-
>  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c      | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> index dd976a50e053..855e521eb201 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
> @@ -382,7 +382,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_device *adev,
>  
>  	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 2);
>  	drm_exec_until_all_locked(&exec) {
> -		ret = amdgpu_vm_lock_pd(queue->vm, &exec, 1);
> +		ret = amdgpu_vm_lock_pd(queue->vm, &exec, 0);
>  		drm_exec_retry_on_contention(&exec);
>  		if (unlikely(ret))
>  			goto lock_error;
> diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> index 7abb9d95ef59..8b07e21d2686 100644
> --- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> @@ -48,7 +48,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
>  
>  	drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 2);
>  	drm_exec_until_all_locked(&exec) {
> -		ret = amdgpu_vm_lock_pd(vm, &exec, 1);
> +		ret = amdgpu_vm_lock_pd(vm, &exec, 0);
>  		drm_exec_retry_on_contention(&exec);
>  		if (unlikely(ret))
>  			goto fail_lock;


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 6/8] drm/amdgpu/vm: stop using amdgpu_bo_fence
  2026-11-18 18:52 ` [PATCH 6/8] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
@ 2026-11-19 13:41   ` Christian König
  0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:41 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> Switch to stop using this deprecated helper.
> 
> The original could be incorrect under certain circumstances, since the
> amdgpu_bo_fence only reserves one slot, and at the time of calling the
> SDMA commit and TLB flush fences were not added yet (the reserve_fences
> is not additive). In addition this allows us to switch to use BOOKKEEP
> usage.
> 
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index daf0e75d0bb1..2a8abc9684b7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1216,7 +1216,8 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>  	if (!unlocked && !dma_fence_is_signaled(vm->last_unlocked)) {
>  		struct dma_fence *tmp = dma_fence_get_stub();
>  
> -		amdgpu_bo_fence(vm->root.bo, vm->last_unlocked, true);
> +		dma_resv_add_fence(vm->root.bo->tbo.base.resv, vm->last_unlocked,
> +				   DMA_RESV_USAGE_BOOKKEEP);
>  		swap(vm->last_unlocked, tmp);
>  		dma_fence_put(tmp);
>  	}


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 7/8] drm/amdgpu/uvd: stop using amdgpu_bo_fence
  2026-11-18 18:52 ` [PATCH 7/8] drm/amdgpu/uvd: " Benjamin Cheng
@ 2026-11-19 13:43   ` Christian König
  0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:43 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> This helper is deprecated since it is incorrect in most circumstances.
> This was a circumstance where it was mostly correct but it is the only
> remaining usage, so get rid of it here.
> 
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> index d88dde859615..9570db033b18 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> @@ -1154,16 +1154,24 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
>  		if (r)
>  			goto err_free;
>  	} else {
> +		r = amdgpu_bo_reserve(bo, true);
> +		if (r)
> +			goto err_free;
> +
>  		r = drm_sched_job_add_resv_dependencies(&job->base,
>  							bo->tbo.base.resv,
>  							DMA_RESV_USAGE_KERNEL);
>  		if (r)
> -			goto err_free;
> +			goto err_unreserve;
>  
>  		f = amdgpu_job_submit(job);
>  
> -		amdgpu_bo_reserve(bo, true);
> -		amdgpu_bo_fence(bo, f, false);
> +		r = dma_resv_reserve_fences(bo->tbo.base.resv, 1);

That line should come before the amdgpu_job_submit().

> +		if (r) {
> +			dma_fence_wait(f, false);

This way you also don't need that hack here.

Regards,
Christian.

> +			r = 0;
> +		} else
> +			dma_resv_add_fence(bo->tbo.base.resv, f, DMA_RESV_USAGE_BOOKKEEP);
>  		amdgpu_bo_unreserve(bo);
>  	}
>  
> @@ -1173,6 +1181,9 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
>  
>  	return 0;
>  
> +err_unreserve:
> +	amdgpu_bo_unreserve(bo);
> +
>  err_free:
>  	amdgpu_job_free(job);
>  	return r;


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 8/8] drm/amdgpu/object: get rid of amdgpu_bo_fence
  2026-11-18 18:52 ` [PATCH 8/8] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
@ 2026-11-19 13:47   ` Christian König
  0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2026-11-19 13:47 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 19:52, Benjamin Cheng wrote:
> All uses of this function have been removed, so we can now get rid of
> this function.
> 
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 25 ----------------------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  2 --
>  2 files changed, 27 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index d4651f2d437c..ba9b5ed71cf7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -1463,31 +1463,6 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
>  	return 0;
>  }
>  
> -/**
> - * amdgpu_bo_fence - add fence to buffer object
> - *
> - * @bo: buffer object in question
> - * @fence: fence to add
> - * @shared: true if fence should be added shared
> - *
> - */
> -void amdgpu_bo_fence(struct amdgpu_bo *bo, struct dma_fence *fence,
> -		     bool shared)
> -{
> -	struct dma_resv *resv = bo->tbo.base.resv;
> -	int r;
> -
> -	r = dma_resv_reserve_fences(resv, 1);
> -	if (r) {
> -		/* As last resort on OOM we block for the fence */
> -		dma_fence_wait(fence, false);
> -		return;
> -	}
> -
> -	dma_resv_add_fence(resv, fence, shared ? DMA_RESV_USAGE_READ :
> -			   DMA_RESV_USAGE_WRITE);
> -}
> -
>  /**
>   * amdgpu_bo_sync_wait_resv - Wait for BO reservation fences
>   *
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index 8e67a8e60572..33a1bfce79e1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -305,8 +305,6 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
>  			   struct ttm_resource *new_mem);
>  void amdgpu_bo_release_notify(struct ttm_buffer_object *bo);
>  vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
> -void amdgpu_bo_fence(struct amdgpu_bo *bo, struct dma_fence *fence,
> -		     bool shared);
>  int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv,
>  			     enum amdgpu_sync_mode sync_mode, void *owner,
>  			     bool intr);


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-11-19 13:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 18:52 [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng
2026-11-18 18:52 ` [PATCH 1/8] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
2026-11-19 13:19   ` Christian König
2026-11-18 18:52 ` [PATCH 2/8] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
2026-11-19 13:22   ` Christian König
2026-11-18 18:52 ` [PATCH 3/8] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
2026-11-19 13:24   ` Christian König
2026-11-18 18:52 ` [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
2026-11-19 13:27   ` Christian König
2026-11-18 18:52 ` [PATCH 5/8] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
2026-11-18 19:05   ` sashiko-bot
2026-11-19 13:35   ` Christian König
2026-11-18 18:52 ` [PATCH 6/8] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
2026-11-19 13:41   ` Christian König
2026-11-18 18:52 ` [PATCH 7/8] drm/amdgpu/uvd: " Benjamin Cheng
2026-11-19 13:43   ` Christian König
2026-11-18 18:52 ` [PATCH 8/8] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
2026-11-19 13:47   ` Christian König
2026-11-18 18:58 ` [PATCH 0/8] Consolidate and fix root PD fence resverations Benjamin Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox