From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Michal Mrozek" <michal.mrozek@intel.com>,
"John Falkowski" <john.falkowski@intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Lahtinen Joonas" <joonas.lahtinen@intel.com>
Subject: [PATCH i-g-t 1/4] lib/xe: add xe_vm_restart ioctl helper
Date: Fri, 12 Jun 2026 13:06:16 +0200 [thread overview]
Message-ID: <20260612110619.103198-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20260612110619.103198-1-thomas.hellstrom@linux.intel.com>
Add DRM_XE_VM_RESTART (ioctl 0x10) and struct drm_xe_vm_restart to the
Xe DRM UAPI header, taken from the xe_event kernel branch.
Add DRM_XE_VM_CREATE_FLAG_RESTARTABLE (bit 4) to allow VMs to opt in to
the restart mechanism.
Add __xe_vm_restart() (failable, with bounded EAGAIN retry) and
xe_vm_restart() (asserting wrapper) to lib/xe/xe_ioctl. Both take an
optional CLOCK_MONOTONIC timestamp_ns which is forwarded to the IOCTL so
the driver can log event-to-restart latency.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
---
include/drm-uapi/xe_drm.h | 40 +++++++++++++++++++++++++++++++++++
lib/xe/xe_ioctl.c | 44 +++++++++++++++++++++++++++++++++++++++
lib/xe/xe_ioctl.h | 2 ++
3 files changed, 86 insertions(+)
diff --git a/include/drm-uapi/xe_drm.h b/include/drm-uapi/xe_drm.h
index 5a96a7910..43b65b1d9 100644
--- a/include/drm-uapi/xe_drm.h
+++ b/include/drm-uapi/xe_drm.h
@@ -84,6 +84,7 @@ extern "C" {
* - &DRM_IOCTL_XE_MADVISE
* - &DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS
* - &DRM_IOCTL_XE_VM_GET_PROPERTY
+ * - &DRM_IOCTL_XE_VM_RESTART
*/
/*
@@ -109,6 +110,7 @@ extern "C" {
#define DRM_XE_VM_QUERY_MEM_RANGE_ATTRS 0x0d
#define DRM_XE_EXEC_QUEUE_SET_PROPERTY 0x0e
#define DRM_XE_VM_GET_PROPERTY 0x0f
+#define DRM_XE_VM_RESTART 0x10
/* Must be kept compact -- no holes */
@@ -128,6 +130,7 @@ extern "C" {
#define DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_QUERY_MEM_RANGE_ATTRS, struct drm_xe_vm_query_mem_range_attr)
#define DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property)
#define DRM_IOCTL_XE_VM_GET_PROPERTY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_GET_PROPERTY, struct drm_xe_vm_get_property)
+#define DRM_IOCTL_XE_VM_RESTART DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_RESTART, struct drm_xe_vm_restart)
/**
* DOC: Xe IOCTL Extensions
@@ -991,6 +994,7 @@ struct drm_xe_vm_create {
#define DRM_XE_VM_CREATE_FLAG_LR_MODE (1 << 1)
#define DRM_XE_VM_CREATE_FLAG_FAULT_MODE (1 << 2)
#define DRM_XE_VM_CREATE_FLAG_NO_VM_OVERCOMMIT (1 << 3)
+#define DRM_XE_VM_CREATE_FLAG_RESTARTABLE (1 << 4)
/** @flags: Flags */
__u32 flags;
@@ -2609,6 +2613,42 @@ enum drm_xe_ras_error_component {
[DRM_XE_RAS_ERR_COMP_SOC_INTERNAL] = "soc-internal" \
}
+/**
+ * DOC: DRM_XE_VM_RESTART
+ *
+ * Synchronously restart a VM by running its preempt-rebind worker in the
+ * calling context. The VM must be in preempt-fence mode (i.e. it must have
+ * been created with exec queues that use preempt fences).
+ *
+ * On return the rebind attempt has completed or a retriable error was
+ * encountered. Any non-retriable error is surfaced through the event
+ * mechanism if the caller has subscribed to %DRM_XE_EVENT_MASK_VM_ERR.
+ * The IOCTL may return -EAGAIN if userptr memory needs to be repinned;
+ * callers should retry in that case.
+ */
+
+/**
+ * struct drm_xe_vm_restart - restart a VM's preempt-rebind worker
+ *
+ * Used with %DRM_IOCTL_XE_VM_RESTART.
+ */
+struct drm_xe_vm_restart {
+ /** @vm_id: ID of the VM to restart */
+ __u32 vm_id;
+ /** @pad: reserved, must be zero */
+ __u32 pad;
+ /**
+ * @timestamp_ns: optional CLOCK_MONOTONIC timestamp in nanoseconds.
+ * When non-zero, the driver logs the delay between this timestamp and
+ * the point the rebind completes, which can be used to measure the
+ * response latency from event delivery to VM restart. Pass zero to
+ * disable the logging.
+ */
+ __u64 timestamp_ns;
+ /** @reserved: reserved, must be zero */
+ __u64 reserved;
+};
+
#if defined(__cplusplus)
}
#endif
diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c
index c8ed99182..f102fe34e 100644
--- a/lib/xe/xe_ioctl.c
+++ b/lib/xe/xe_ioctl.c
@@ -337,6 +337,50 @@ void xe_vm_get_property(int fd, uint32_t vm, struct drm_xe_vm_get_property *quer
igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, query), 0);
}
+/**
+ * __xe_vm_restart() - restart a VM's preempt-rebind worker (failable)
+ * @fd: open Xe DRM device file descriptor
+ * @vm: VM id to restart
+ * @timestamp_ns: CLOCK_MONOTONIC timestamp from the triggering event, or 0
+ *
+ * Calls %DRM_IOCTL_XE_VM_RESTART, retrying up to 10 times on -EAGAIN as
+ * required when userptr memory needs repinning.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int __xe_vm_restart(int fd, uint32_t vm, uint64_t timestamp_ns)
+{
+ struct drm_xe_vm_restart restart = {
+ .vm_id = vm,
+ .timestamp_ns = timestamp_ns,
+ };
+ int err, tries = 10;
+
+ do {
+ err = igt_ioctl(fd, DRM_IOCTL_XE_VM_RESTART, &restart);
+ if (err) {
+ err = -errno;
+ igt_assume(err);
+ errno = 0;
+ }
+ } while (err == -EAGAIN && --tries > 0);
+
+ return err;
+}
+
+/**
+ * xe_vm_restart() - restart a VM's preempt-rebind worker
+ * @fd: open Xe DRM device file descriptor
+ * @vm: VM id to restart
+ * @timestamp_ns: CLOCK_MONOTONIC timestamp from the triggering event, or 0
+ *
+ * Calls __xe_vm_restart() and asserts success.
+ */
+void xe_vm_restart(int fd, uint32_t vm, uint64_t timestamp_ns)
+{
+ igt_assert_eq(__xe_vm_restart(fd, vm, timestamp_ns), 0);
+}
+
void xe_vm_destroy(int fd, uint32_t vm)
{
struct drm_xe_vm_destroy destroy = {
diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h
index bf40fb6bd..95f2ec3d8 100644
--- a/lib/xe/xe_ioctl.h
+++ b/lib/xe/xe_ioctl.h
@@ -66,6 +66,8 @@ void xe_vm_unbind_all_async(int fd, uint32_t vm, uint32_t exec_queue,
uint32_t bo, struct drm_xe_sync *sync,
uint32_t num_syncs);
void xe_vm_get_property(int fd, uint32_t vm, struct drm_xe_vm_get_property *query);
+int __xe_vm_restart(int fd, uint32_t vm, uint64_t timestamp_ns);
+void xe_vm_restart(int fd, uint32_t vm, uint64_t timestamp_ns);
void xe_vm_destroy(int fd, uint32_t vm);
uint32_t __xe_bo_create(int fd, uint32_t vm, uint64_t size, uint32_t placement,
uint32_t flags, void *ext, uint32_t *handle);
--
2.54.0
next prev parent reply other threads:[~2026-06-12 11:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 11:06 [PATCH i-g-t 0/4] xe: watch queue event support and VM restart recovery Thomas Hellström
2026-06-12 11:06 ` Thomas Hellström [this message]
2026-06-12 14:38 ` [PATCH i-g-t 1/4] lib/xe: add xe_vm_restart ioctl helper Kamil Konieczny
2026-06-12 11:06 ` [PATCH i-g-t 2/4] lib/xe: add xe_watch listener for watch queue events Thomas Hellström
2026-06-12 11:06 ` [PATCH i-g-t 3/4] tests/intel/xe_exec_compute_mode: Add a listener for file events Thomas Hellström
2026-06-12 11:06 ` [PATCH i-g-t 4/4] tests/intel/xe_exec_compute_mode: Restart VM on ENOMEM/ENOSPC errors Thomas Hellström
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=20260612110619.103198-2-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=john.falkowski@intel.com \
--cc=joonas.lahtinen@intel.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=michal.mrozek@intel.com \
--cc=rodrigo.vivi@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