All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bob Zhou <bobzhou2@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <christian.koenig@amd.com>,
	<Alexander.Deucher@amd.com>
Cc: Bob Zhou <bobzhou2@amd.com>
Subject: [PATCH] drm/amdgpu: avoid building unused VM update fences
Date: Mon, 10 Aug 2026 17:18:03 +0800	[thread overview]
Message-ID: <20260810091803.777940-1-bobzhou2@amd.com> (raw)

amdgpu_gem_va_update_vm() returns a fence for every immediate VA
update, but the ioctl caller only consumes that fence when userspace
requests a VM timeline syncobj. Without a timeline syncobj, the helper
may take fence references or allocate a merged fence that is
immediately released.

Pass the timeline syncobj into the helper and skip fence construction
when no output fence is requested. Preserve the existing stub,
merged-fence and error behavior for callers that do request a timeline
update.

Signed-off-by: Bob Zhou <bobzhou2@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index f754a4a3a1c22..2837553e4f58a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -754,6 +754,7 @@ int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
  * @vm: vm to update
  * @bo_va: bo_va to update
  * @operation: map, unmap or clear
+ * @timeline_syncobj: VM timeline syncobj the fence gets attached to, or NULL
  *
  * Update the bo_va directly after setting its address. Errors are not
  * vital here, so they are not reported back to userspace.
@@ -765,15 +766,15 @@ static struct dma_fence *
 amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 			struct amdgpu_vm *vm,
 			struct amdgpu_bo_va *bo_va,
-			uint32_t operation)
+			uint32_t operation,
+			struct drm_syncobj *timeline_syncobj)
 {
 	struct dma_fence *fence;
 	int r = 0;
 
 	/* If the VM is not ready return only a stub. */
 	if (!amdgpu_vm_ready(vm))
-		return dma_fence_get_stub();
-
+		return timeline_syncobj ? dma_fence_get_stub() : NULL;
 
 	/*
 	 * First clean up any freed mappings in the VM.
@@ -799,6 +800,14 @@ amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 	if (r)
 		goto error;
 
+	/*
+	 * The VM update work above is already committed. If the caller does
+	 * not need a fence (no VM timeline syncobj was requested) skip building
+	 * the otherwise-unused merged/last-update fence.
+	 */
+	if (!timeline_syncobj)
+		return NULL;
+
 	if ((operation == AMDGPU_VA_OP_MAP ||
 	     operation == AMDGPU_VA_OP_REPLACE) &&
 	    !amdgpu_vm_is_bo_always_valid(vm, bo_va->base.bo)) {
@@ -826,7 +835,7 @@ amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
 	if (r && r != -ERESTARTSYS)
 		DRM_ERROR("Couldn't update BO_VA (%d)\n", r);
 
-	return dma_fence_get(vm->last_update);
+	return timeline_syncobj ? dma_fence_get(vm->last_update) : NULL;
 }
 
 int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
@@ -996,7 +1005,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 		struct dma_fence *fence;
 
 		fence = amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va,
-						args->operation);
+						args->operation,
+						timeline_syncobj);
 		if (timeline_syncobj) {
 			if (!args->vm_timeline_point) {
 				/* Replace the existing fence when no point is given. */
-- 
2.34.1


             reply	other threads:[~2026-08-10  9:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10  9:18 Bob Zhou [this message]
2026-08-10 14:00 ` [PATCH] drm/amdgpu: avoid building unused VM update fences Christian König

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=20260810091803.777940-1-bobzhou2@amd.com \
    --to=bobzhou2@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@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.