From: Benjamin Cheng <benjamin.cheng@amd.com>
To: "Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
amd-gfx@lists.freedesktop.org
Cc: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>,
"Shahyan Soltani" <shahyan.soltani@amd.com>,
Benjamin Cheng <benjamin.cheng@amd.com>
Subject: [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd
Date: Wed, 18 Nov 2026 13:52:21 -0500 [thread overview]
Message-ID: <20261118185225.1857845-5-benjamin.cheng@amd.com> (raw)
In-Reply-To: <20261118185225.1857845-1-benjamin.cheng@amd.com>
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
next prev parent reply other threads:[~2026-11-18 18:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Benjamin Cheng [this message]
2026-11-19 13:27 ` [PATCH 4/8] drm/amdgpu: reserve only what the caller asks for in lock_pd 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118185225.1857845-5-benjamin.cheng@amd.com \
--to=benjamin.cheng@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=pierre-eric.pelloux-prayer@amd.com \
--cc=shahyan.soltani@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.