mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Natalie Vock <nat@pixelcluster.dev>
To: "Felix Kuehling" <Felix.Kuehling@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Timur Kristóf" <timur.kristof@gmail.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org,
	Natalie Vock <nat@pixelcluster.dev>
Subject: [PATCH v2 06/10] drm/amdgpu: Add function to roll back a VM update ctx
Date: Tue, 17 Nov 2026 13:50:12 +0100	[thread overview]
Message-ID: <20261117-prt-explicit-sync-v2-6-bb3851cb6a0c@pixelcluster.dev> (raw)
In-Reply-To: <20261117-prt-explicit-sync-v2-0-bb3851cb6a0c@pixelcluster.dev>

Used for discarding pending operations and retrying. This is needed when
we do lots of mapping operations at once and drm_exec tells us to drop
everything and retry to avoid deadlocks.

Signed-off-by: Natalie Vock <nat@pixelcluster.dev>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 41 +++++++++++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  1 +
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 330c288053352..ac4a1ed9b1196 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1874,37 +1874,48 @@ void amdgpu_vm_update_ctx_init(struct amdgpu_vm_update_ctx *ctx,
 }
 
 /**
- * amdgpu_vm_update_ctx_fini - finish a VM update operation
- * @ctx: The context of the update
+ * amdgpu_vm_update_ctx_rollback - clear pending VM updates
+ * @ctx: The context to roll back
  *
- * Adds any leftover mappings needing to be cleared to the VM's delayed free list,
- * then frees up resources used by the context.
+ * Cleans up any pending mapping changes, but does not reset
+ * anything else (like attached syncobjs).
  */
-void amdgpu_vm_update_ctx_fini(struct amdgpu_vm_update_ctx *ctx)
+void amdgpu_vm_update_ctx_rollback(struct amdgpu_vm_update_ctx *ctx)
 {
+	struct amdgpu_bo_va_mapping *mapping, *next;
 	struct interval_tree_node *node, *next_node;
 	struct amdgpu_bo_va *bo_va, *next_bo_va;
 
-	list_splice(&ctx->freed, &ctx->vm->delayed_freed);
-	amdgpu_sync_free(&ctx->sync);
+	list_for_each_entry_safe(mapping, next, &ctx->new, pending_list)
+		list_del_init(&mapping->pending_list);
+	list_for_each_entry_safe(mapping, next, &ctx->deleted, pending_list)
+		list_del_init(&mapping->pending_list);
 
 	list_for_each_entry_safe(bo_va, next_bo_va, &ctx->dirty_bo_vas,
-				 update_link) {
+				 update_link)
 		list_del_init(&bo_va->update_link);
-	}
 
-	rbtree_postorder_for_each_entry_safe(node, next_node, &ctx->pending_maps.rb_root, rb) {
+	rbtree_postorder_for_each_entry_safe(node, next_node, &ctx->pending_maps.rb_root, rb)
 		kfree(node);
-	}
-	rbtree_postorder_for_each_entry_safe(node, next_node, &ctx->cleared_ranges.rb_root, rb) {
+	rbtree_postorder_for_each_entry_safe(node, next_node, &ctx->cleared_ranges.rb_root, rb)
 		kfree(node);
-	}
 
 	ctx->pending_maps = RB_ROOT_CACHED;
 	ctx->cleared_ranges = RB_ROOT_CACHED;
+}
 
-	WARN_ON(!list_empty(&ctx->new));
-	WARN_ON(!list_empty(&ctx->deleted));
+/**
+ * amdgpu_vm_update_ctx_fini - finish a VM update operation
+ * @ctx: The context of the update
+ *
+ * Adds any leftover mappings needing to be cleared to the VM's delayed free list,
+ * then frees up resources used by the context.
+ */
+void amdgpu_vm_update_ctx_fini(struct amdgpu_vm_update_ctx *ctx)
+{
+	amdgpu_vm_update_ctx_rollback(ctx);
+	list_splice(&ctx->freed, &ctx->vm->delayed_freed);
+	amdgpu_sync_free(&ctx->sync);
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 7a5f558970b5c..8d4f59c286c2a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -623,6 +623,7 @@ void amdgpu_vm_update_ctx_init(struct amdgpu_vm_update_ctx *ctx,
 			       struct amdgpu_vm *vm);
 int amdgpu_vm_update_ctx_execute_replace(struct amdgpu_vm_update_ctx *ctx);
 void amdgpu_vm_update_ctx_commit(struct amdgpu_vm_update_ctx *ctx);
+void amdgpu_vm_update_ctx_rollback(struct amdgpu_vm_update_ctx *ctx);
 void amdgpu_vm_update_ctx_fini(struct amdgpu_vm_update_ctx *ctx);
 int amdgpu_vm_update_ctx_ensure_unmap_synced(struct amdgpu_vm_update_ctx *ctx);
 

-- 
2.56.1


  parent reply	other threads:[~2026-11-17 12:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:50 [PATCH v2 00/10] drm/amdgpu: Rework VM update ops for batching and explicit sync Natalie Vock
2026-11-17 12:50 ` [PATCH v2 01/10] drm/amdgpu: Remove unused parameter from amdgpu_vm_pte_fragment Natalie Vock
2026-11-17 12:50 ` [PATCH v2 02/10] drm/amdgpu: Add and use vm_update_ctx struct Natalie Vock
2026-11-17 12:50 ` [PATCH v2 03/10] drm/amdgpu: Make VM maps pending per update context Natalie Vock
2026-11-17 12:50 ` [PATCH v2 04/10] drm/amdgpu: Make removed/cleared mappings " Natalie Vock
2026-11-17 12:50 ` [PATCH v2 05/10] drm/amdgpu: Track dirty bo_va structures in update ctx Natalie Vock
2026-11-17 12:50 ` Natalie Vock [this message]
2026-11-17 12:50 ` [PATCH v2 07/10] drm/amdgpu: Move some VA op validation to a helper Natalie Vock
2026-11-17 12:50 ` [PATCH v2 08/10] drm/amdgpu: Only reject conflicting mappings if they are not cleared Natalie Vock
2026-11-17 12:50 ` [PATCH v2 09/10] drm/amdgpu: Add new AMDGPU_GEM_VA2 ioctl Natalie Vock
2026-11-17 12:50 ` [PATCH v2 10/10] drm/amdgpu: Bump minor version Natalie Vock

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=20261117-prt-explicit-sync-v2-6-bb3851cb6a0c@pixelcluster.dev \
    --to=nat@pixelcluster.dev \
    --cc=Felix.Kuehling@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=timur.kristof@gmail.com \
    --cc=tzimmermann@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®