AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/10] Consolidate and fix root PD fence resverations
@ 2026-11-18 19:07 Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences Benjamin Cheng
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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 is mostly an independent fix. It is not related to the VM root
PD, but follows almost the same logic as patch 2 through 5 below.

Patch 2 through 5 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 6 and 7 are cleanups that I found (not everywhere locking the PD
does validation or VM updates), and patches 8 through 10 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 (10):
  drm/amdkfd: reserve TTM move fences
  drm/amdgpu/gem: reserve fences on the VM root PD
  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  | 16 +++++++-----
 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       | 13 ++++++++--
 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, 68 insertions(+), 57 deletions(-)

-- 
2.56.1


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

* [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-19 13:53   ` Christian König
  2026-11-18 19:07 ` [PATCH v2 02/10] drm/amdgpu/gem: reserve fences on the VM root PD Benjamin Cheng
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

Validation of the BO can add up to TTM_NUM_MOVE_FENCES, so we should fix
that.

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_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index f060b206c255..a6616447abc8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -3009,7 +3009,8 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence __rcu *
 			struct drm_gem_object *gobj;
 
 			gobj = &mem->bo->tbo.base;
-			ret = drm_exec_prepare_obj(&exec, gobj, 1);
+			ret = drm_exec_prepare_obj(&exec, gobj,
+						   TTM_NUM_MOVE_FENCES + 1);
 			drm_exec_retry_on_contention(&exec);
 			if (unlikely(ret)) {
 				pr_err("drm_exec_prepare_obj failed, ret: %d\n", ret);
-- 
2.56.1


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

* [PATCH v2 02/10] drm/amdgpu/gem: reserve fences on the VM root PD
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-19 13:58   ` Christian König
  2026-11-18 19:07 ` [PATCH v2 03/10] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani, Benjamin Cheng

When creating a BO that shares the VM root PD's resv, TTM eviction
fences are added to the resv, and there is another fence added for the
BO clear job.

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_gem.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 9da7ae6b9ef3..eb7473ed9e0e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -504,6 +504,14 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
 		if (r)
 			return r;
 
+		/* ttm_bo_init_reserved() + clear fence */
+		r = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv,
+					    TTM_NUM_MOVE_FENCES + 1);
+		if (r) {
+			amdgpu_bo_unreserve(vm->root.bo);
+			return r;
+		}
+
 		resv = vm->root.bo->tbo.base.resv;
 	}
 
-- 
2.56.1


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

* [PATCH v2 03/10] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 02/10] drm/amdgpu/gem: reserve fences on the VM root PD Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 04/10] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* [PATCH v2 04/10] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (2 preceding siblings ...)
  2026-11-18 19:07 ` [PATCH v2 03/10] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 05/10] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* [PATCH v2 05/10] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (3 preceding siblings ...)
  2026-11-18 19:07 ` [PATCH v2 04/10] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 06/10] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* [PATCH v2 06/10] drm/amdgpu: reserve only what the caller asks for in lock_pd
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (4 preceding siblings ...)
  2026-11-18 19:07 ` [PATCH v2 05/10] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 07/10] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* [PATCH v2 07/10] drm/amdgpu/userq: remove extra fence request when locking PD
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (5 preceding siblings ...)
  2026-11-18 19:07 ` [PATCH v2 06/10] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 08/10] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* [PATCH v2 08/10] drm/amdgpu/vm: stop using amdgpu_bo_fence
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (6 preceding siblings ...)
  2026-11-18 19:07 ` [PATCH v2 07/10] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 09/10] drm/amdgpu/uvd: " Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 10/10] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
  9 siblings, 0 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* [PATCH v2 09/10] drm/amdgpu/uvd: stop using amdgpu_bo_fence
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (7 preceding siblings ...)
  2026-11-18 19:07 ` [PATCH v2 08/10] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:07 ` [PATCH v2 10/10] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
  9 siblings, 0 replies; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* [PATCH v2 10/10] drm/amdgpu/object: get rid of amdgpu_bo_fence
  2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
                   ` (8 preceding siblings ...)
  2026-11-18 19:07 ` [PATCH v2 09/10] drm/amdgpu/uvd: " Benjamin Cheng
@ 2026-11-18 19:07 ` Benjamin Cheng
  2026-11-18 19:29   ` sashiko-bot
  9 siblings, 1 reply; 14+ messages in thread
From: Benjamin Cheng @ 2026-11-18 19:07 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] 14+ messages in thread

* Re: [PATCH v2 10/10] drm/amdgpu/object: get rid of amdgpu_bo_fence
  2026-11-18 19:07 ` [PATCH v2 10/10] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
@ 2026-11-18 19:29   ` sashiko-bot
  0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-11-18 19:29 UTC (permalink / raw)
  To: Benjamin Cheng, amd-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: removing amdgpu_bo_fence() breaks
  amdgpu_gem_object_close() build
--

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

drm/amdgpu/object: get rid of amdgpu_bo_fence

This commit removes the definition and declaration of amdgpu_bo_fence().

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 6aa895f63aeaf..7fc43363ec626 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -1441,31 +1441,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
>   *

[Severity: High]
Does removing amdgpu_bo_fence() break the build in
amdgpu_gem_object_close()?

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:amdgpu_gem_object_close() {
	...
	r = amdgpu_vm_clear_freed(adev, vm, &fence);
	if (unlikely(r < 0) && !drm_dev_is_unplugged(adev_to_drm(adev)))
		dev_err(adev->dev, "failed to clear page "
			"tables on GEM object close (%ld)\n", r);
	if (r || !fence)
		goto out_unlock;

	amdgpu_bo_fence(bo, fence, true);
	dma_fence_put(fence);
	...
}

amdgpu_gem_object_close() still calls amdgpu_bo_fence(), so removing it
causes compilation of amdgpu_gem.c to fail with an implicit function
declaration error.

Also note that in amdgpu_gem_object_close(), drm_exec_prepare_obj(&exec,
&bo->tbo.base, 1) is followed by amdgpu_vm_lock_pd(vm, &exec,
AMDGPU_VM_UPDATE_FENCES).  Because dma_resv_reserve_fences() is not
additive, only AMDGPU_VM_UPDATE_FENCES slots remain reserved when bo
shares the VM root PD dma_resv, while amdgpu_vm_clear_freed() plus adding
the fence to bo requires AMDGPU_VM_UPDATE_FENCES + 1 slots if replaced
with a direct dma_resv_add_fence() call.

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

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

* Re: [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences
  2026-11-18 19:07 ` [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences Benjamin Cheng
@ 2026-11-19 13:53   ` Christian König
  0 siblings, 0 replies; 14+ messages in thread
From: Christian König @ 2026-11-19 13:53 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 20:07, Benjamin Cheng wrote:
> Validation of the BO can add up to TTM_NUM_MOVE_FENCES, so we should fix
> that.
> 
> Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>

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

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index f060b206c255..a6616447abc8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -3009,7 +3009,8 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence __rcu *
>  			struct drm_gem_object *gobj;
>  
>  			gobj = &mem->bo->tbo.base;
> -			ret = drm_exec_prepare_obj(&exec, gobj, 1);
> +			ret = drm_exec_prepare_obj(&exec, gobj,
> +						   TTM_NUM_MOVE_FENCES + 1);
>  			drm_exec_retry_on_contention(&exec);
>  			if (unlikely(ret)) {
>  				pr_err("drm_exec_prepare_obj failed, ret: %d\n", ret);


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

* Re: [PATCH v2 02/10] drm/amdgpu/gem: reserve fences on the VM root PD
  2026-11-18 19:07 ` [PATCH v2 02/10] drm/amdgpu/gem: reserve fences on the VM root PD Benjamin Cheng
@ 2026-11-19 13:58   ` Christian König
  0 siblings, 0 replies; 14+ messages in thread
From: Christian König @ 2026-11-19 13:58 UTC (permalink / raw)
  To: Benjamin Cheng, Alex Deucher, amd-gfx, Prosyak, Vitaly
  Cc: Pierre-Eric Pelloux-Prayer, Shahyan Soltani

On 11/18/26 20:07, Benjamin Cheng wrote:
> When creating a BO that shares the VM root PD's resv, TTM eviction
> fences are added to the resv, and there is another fence added for the
> BO clear job.

Good catch.

> Fixes: 897ee11ec020 ("drm/amdgpu: create multiple clear/move ttm entities")

Yeah that is most likely incorrect. The bug existed for as long as the driver was upstream.

It's just that nobody ever noticed because it doesn't matter in practice (the VM root PD should always have enough free slots).

It's just that the automated checkers could complain if we start to run them together with lockdep enablement.

> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>

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

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 9da7ae6b9ef3..eb7473ed9e0e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -504,6 +504,14 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
>  		if (r)
>  			return r;
>  
> +		/* ttm_bo_init_reserved() + clear fence */
> +		r = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv,
> +					    TTM_NUM_MOVE_FENCES + 1);
> +		if (r) {
> +			amdgpu_bo_unreserve(vm->root.bo);
> +			return r;
> +		}
> +
>  		resv = vm->root.bo->tbo.base.resv;
>  	}
>  


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

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

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences Benjamin Cheng
2026-11-19 13:53   ` Christian König
2026-11-18 19:07 ` [PATCH v2 02/10] drm/amdgpu/gem: reserve fences on the VM root PD Benjamin Cheng
2026-11-19 13:58   ` Christian König
2026-11-18 19:07 ` [PATCH v2 03/10] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 04/10] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 05/10] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 06/10] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 07/10] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 08/10] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 09/10] drm/amdgpu/uvd: " Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 10/10] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
2026-11-18 19:29   ` sashiko-bot

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