From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: dev@lankhorst.se, "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: [PATCH i-g-t 4/5] lib/xe: add __xe_vm_bind_lr_sync() failable bind helper
Date: Thu, 26 Mar 2026 17:10:06 +0100 [thread overview]
Message-ID: <20260326161007.39294-5-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20260326161007.39294-1-thomas.hellstrom@linux.intel.com>
Add __xe_vm_bind_lr_sync() which performs a synchronous LR VM bind and
returns an error code instead of asserting, allowing callers to handle
expected failures such as -ENOMEM or -ENOSPC from the dmem cgroup
controller.
Refactor xe_vm_bind_lr_sync() to delegate to the new helper and assert
on the result, preserving existing behaviour for callers that do not
need to inspect the error.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
lib/xe/xe_ioctl.c | 79 ++++++++++++++++++++++++++++++++++++++---------
lib/xe/xe_ioctl.h | 3 ++
2 files changed, 67 insertions(+), 15 deletions(-)
diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c
index ea3f2fcaa..9a0903bfb 100644
--- a/lib/xe/xe_ioctl.c
+++ b/lib/xe/xe_ioctl.c
@@ -822,40 +822,89 @@ void xe_vm_madvise(int fd, uint32_t vm, uint64_t addr, uint64_t range,
}
#define BIND_SYNC_VAL 0x686868
-void xe_vm_bind_lr_sync(int fd, uint32_t vm, uint32_t bo, uint64_t offset,
- uint64_t addr, uint64_t size, uint32_t flags)
+/**
+ * __xe_vm_bind_lr_sync() - Bind a BO into an LR VM, returning errors.
+ * @fd: xe device file descriptor.
+ * @vm: VM id (must have been created with %DRM_XE_VM_CREATE_FLAG_LR_MODE).
+ * @bo: GEM handle to bind.
+ * @offset: Offset within @bo.
+ * @addr: GPU virtual address to map at.
+ * @size: Size of the mapping.
+ * @flags: %DRM_XE_VM_BIND_FLAG_* flags.
+ *
+ * Like xe_vm_bind_lr_sync() but returns an error code instead of asserting,
+ * allowing callers to handle expected failures such as -%ENOMEM or -%ENOSPC
+ * from the dmem cgroup controller.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int __xe_vm_bind_lr_sync(int fd, uint32_t vm, uint32_t bo, uint64_t offset,
+ uint64_t addr, uint64_t size, uint32_t flags)
{
- volatile uint64_t *sync_addr = malloc(sizeof(*sync_addr));
+ uint64_t *sync_addr = malloc(sizeof(*sync_addr));
struct drm_xe_sync sync = {
.flags = DRM_XE_SYNC_FLAG_SIGNAL,
.type = DRM_XE_SYNC_TYPE_USER_FENCE,
- .addr = to_user_pointer((uint64_t *)sync_addr),
+ .addr = to_user_pointer(sync_addr),
.timeline_value = BIND_SYNC_VAL,
};
+ int err;
- igt_assert(!!sync_addr);
- xe_vm_bind_async_flags(fd, vm, 0, bo, 0, addr, size, &sync, 1, flags);
- if (*sync_addr != BIND_SYNC_VAL)
- xe_wait_ufence(fd, (uint64_t *)sync_addr, BIND_SYNC_VAL, 0, NSEC_PER_SEC * 10);
+ if (!sync_addr)
+ return -ENOMEM;
+
+ WRITE_ONCE(*sync_addr, 0);
+ err = __xe_vm_bind(fd, vm, 0, bo, offset, addr, size,
+ DRM_XE_VM_BIND_OP_MAP, flags, &sync, 1, 0,
+ DEFAULT_PAT_INDEX, 0);
+ if (err) {
+ free(sync_addr);
+ return err;
+ }
+
+ if (READ_ONCE(*sync_addr) != BIND_SYNC_VAL)
+ xe_wait_ufence(fd, sync_addr, BIND_SYNC_VAL, 0,
+ NSEC_PER_SEC * 10);
/* Only free if the wait succeeds */
- free((void *)sync_addr);
+ free(sync_addr);
+ return 0;
+}
+
+/**
+ * xe_vm_bind_lr_sync() - Bind a BO into an LR VM, asserting on error.
+ * @fd: xe device file descriptor.
+ * @vm: VM id (must have been created with %DRM_XE_VM_CREATE_FLAG_LR_MODE).
+ * @bo: GEM handle to bind.
+ * @offset: Offset within @bo.
+ * @addr: GPU virtual address to map at.
+ * @size: Size of the mapping.
+ * @flags: %DRM_XE_VM_BIND_FLAG_* flags.
+ *
+ * Delegates to __xe_vm_bind_lr_sync() and asserts that the operation
+ * succeeds. Use __xe_vm_bind_lr_sync() directly when the caller needs to
+ * handle expected failures such as -%ENOMEM or -%ENOSPC.
+ */
+void xe_vm_bind_lr_sync(int fd, uint32_t vm, uint32_t bo, uint64_t offset,
+ uint64_t addr, uint64_t size, uint32_t flags)
+{
+ igt_assert_eq(__xe_vm_bind_lr_sync(fd, vm, bo, offset, addr, size, flags), 0);
}
void xe_vm_unbind_lr_sync(int fd, uint32_t vm, uint64_t offset,
uint64_t addr, uint64_t size)
{
- volatile uint64_t *sync_addr = malloc(sizeof(*sync_addr));
+ uint64_t *sync_addr = malloc(sizeof(*sync_addr));
struct drm_xe_sync sync = {
.flags = DRM_XE_SYNC_FLAG_SIGNAL,
.type = DRM_XE_SYNC_TYPE_USER_FENCE,
- .addr = to_user_pointer((uint64_t *)sync_addr),
+ .addr = to_user_pointer(sync_addr),
.timeline_value = BIND_SYNC_VAL,
};
igt_assert(!!sync_addr);
- *sync_addr = 0;
+ WRITE_ONCE(*sync_addr, 0);
xe_vm_unbind_async(fd, vm, 0, 0, addr, size, &sync, 1);
- if (*sync_addr != BIND_SYNC_VAL)
- xe_wait_ufence(fd, (uint64_t *)sync_addr, BIND_SYNC_VAL, 0, NSEC_PER_SEC * 10);
- free((void *)sync_addr);
+ if (READ_ONCE(*sync_addr) != BIND_SYNC_VAL)
+ xe_wait_ufence(fd, sync_addr, BIND_SYNC_VAL, 0, NSEC_PER_SEC * 10);
+ free(sync_addr);
}
diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h
index b62d259fd..7f899ea93 100644
--- a/lib/xe/xe_ioctl.h
+++ b/lib/xe/xe_ioctl.h
@@ -114,6 +114,9 @@ int xe_vm_vma_attrs(int fd, struct drm_xe_vm_query_mem_range_attr *vmas_attr,
struct drm_xe_mem_range_attr
*xe_vm_get_mem_attr_values_in_range(int fd, uint32_t vm, uint64_t start,
uint64_t range, uint32_t *num_ranges);
+int __xe_vm_bind_lr_sync(int fd, uint32_t vm, uint32_t bo,
+ uint64_t offset, uint64_t addr,
+ uint64_t size, uint32_t flags);
void xe_vm_bind_lr_sync(int fd, uint32_t vm, uint32_t bo,
uint64_t offset, uint64_t addr,
uint64_t size, uint32_t flags);
--
2.53.0
next prev parent reply other threads:[~2026-03-26 16:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 16:10 [PATCH i-g-t 0/5] Initial dmem cgroup support Thomas Hellström
2026-03-26 16:10 ` [PATCH i-g-t 1/5] lib/igt_cgroup: add cgroup v2 and dmem controller helpers Thomas Hellström
2026-03-26 16:10 ` [PATCH i-g-t 2/5] tests/cgroup_dmem: add dmem cgroup controller test Thomas Hellström
2026-03-26 16:10 ` [PATCH i-g-t 3/5] lib/xe: add xe_cgroup_region_name() helper Thomas Hellström
2026-03-26 16:10 ` Thomas Hellström [this message]
2026-03-26 16:10 ` [PATCH i-g-t 5/5] tests/xe_cgroups: add dmem cgroup eviction test Thomas Hellström
2026-03-26 23:42 ` ✓ Xe.CI.BAT: success for Initial dmem cgroup support Patchwork
2026-03-27 0:00 ` ✓ i915.CI.BAT: " Patchwork
2026-03-27 17:49 ` ✓ Xe.CI.FULL: " Patchwork
2026-03-28 0:45 ` ✗ i915.CI.Full: failure " 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=20260326161007.39294-5-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=dev@lankhorst.se \
--cc=igt-dev@lists.freedesktop.org \
/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