From: Nitin Gote <nitin.r.gote@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: himal.prasad.ghimiray@intel.com, matthew.brost@intel.com,
thomas.hellstrom@intel.com, Nitin Gote <nitin.r.gote@intel.com>
Subject: [PATCH v1 3/5] drm/xe: add drm_exec helper to atomically lock VM (+ optional BO) with BOOKKEEP retry
Date: Thu, 18 Sep 2025 19:55:27 +0530 [thread overview]
Message-ID: <20250918142529.608432-4-nitin.r.gote@intel.com> (raw)
In-Reply-To: <20250918142529.608432-1-nitin.r.gote@intel.com>
Add xe_vm_exec_lock_vm_and_bo(), a drm_exec-based helper that atomically
acquires the VM reservation and an optional BO reservation. When requested
(wait_bookkeep) the helper verifies DMA_RESV_USAGE_BOOKKEEP is clear and,
if not, releases the exec locks, waits outside the reservation and retries.
This centralises the drm_exec + BOOKKEEP wait/retry logic used by vm_bind
paths, avoiding duplicated code and preventing sleeps while holding resv
locks. Caller must call drm_exec_fini(exec) on success and must not
re-acquire vm->lock while exec holds the reservations.
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Signed-off-by: Nitin Gote <nitin.r.gote@intel.com>
---
drivers/gpu/drm/xe/xe_vm.c | 53 ++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 0cacab20ff85..fae88c4c981e 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -3496,6 +3496,59 @@ static int xe_vm_bind_ioctl_validate_bo(struct xe_device *xe, struct xe_bo *bo,
return 0;
}
+/* Helper:
+ * Atomically acquire VM (+ optional BO) reservations using drm_exec.
+ * If wait_bookkeep is true, ensure VM BOOKKEEP is clear before returning:
+ * - if BOOKKEEP fences exist, release exec locks, wait outside and retry.
+ *
+ * On success returns 0 with *exec initialized and the reservations held.
+ * Caller MUST call drm_exec_fini(exec) to release reservations.
+ */
+static int xe_vm_exec_lock_vm_and_bo(struct xe_vm *vm, struct xe_bo *bo,
+ struct drm_exec *exec, bool intr,
+ bool wait_bookkeep)
+{
+ int err = 0, wait;
+
+retry:
+ drm_exec_init(exec, intr ? DRM_EXEC_INTERRUPTIBLE_WAIT : 0, 0);
+ drm_exec_until_all_locked(exec) {
+ err = drm_exec_lock_obj(exec, xe_vm_obj(vm));
+ drm_exec_retry_on_contention(exec);
+ if (err)
+ break;
+
+ if (bo) {
+ err = drm_exec_lock_obj(exec, &bo->ttm.base);
+ drm_exec_retry_on_contention(exec);
+ if (err)
+ break;
+ }
+ }
+
+ if (err) {
+ /* Ensure exec cleaned up if partially initialized */
+ drm_exec_fini(exec);
+ return err;
+ }
+
+ if (wait_bookkeep) {
+ /* If BOOKKEEP fences exist, release exec and wait outside, then retry */
+ if (!dma_resv_test_signaled(xe_vm_resv(vm), DMA_RESV_USAGE_BOOKKEEP)) {
+ drm_exec_fini(exec);
+ wait = dma_resv_wait_timeout(xe_vm_resv(vm),
+ DMA_RESV_USAGE_BOOKKEEP,
+ true, MAX_SCHEDULE_TIMEOUT);
+ if (wait <= 0)
+ return -ETIME;
+ goto retry;
+ }
+ }
+
+ /* Success: exec holds the reservations */
+ return 0;
+}
+
int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
{
struct xe_device *xe = to_xe_device(dev);
--
2.25.1
next prev parent reply other threads:[~2025-09-18 13:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 14:25 [PATCH v1 0/5] drm/xe: add VM_BIND DECOMPRESS support and on‑demand decompression Nitin Gote
2025-09-18 14:25 ` [PATCH v1 1/5] drm/xe: add VM_BIND DECOMPRESS uapi flag Nitin Gote
2025-09-23 17:35 ` Matthew Brost
2025-09-18 14:25 ` [PATCH v1 2/5] drm/xe: add xe_migrate_resolve wrapper and is_vram_resolve support Nitin Gote
2025-09-18 14:25 ` Nitin Gote [this message]
2025-09-18 14:25 ` [PATCH v1 4/5] drm/xe: implement VM_BIND decompression in vm_bind_ioctl Nitin Gote
2025-09-18 16:13 ` Matthew Auld
2025-09-22 7:57 ` Gote, Nitin R
2025-09-23 17:26 ` Matthew Brost
2025-09-18 14:25 ` [PATCH v1 5/5] drm/xe: perform on-demand decompression on VMA pagefaults Nitin Gote
2025-09-23 17:29 ` Matthew Brost
2025-09-18 15:12 ` ✓ CI.KUnit: success for drm/xe: add VM_BIND DECOMPRESS support and on‑demand decompression Patchwork
2025-09-18 15:57 ` ✓ Xe.CI.BAT: " Patchwork
2025-09-19 0:37 ` ✓ Xe.CI.Full: " Patchwork
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=20250918142529.608432-4-nitin.r.gote@intel.com \
--to=nitin.r.gote@intel.com \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=thomas.hellstrom@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox