From nobody Wed Apr 8 02:54:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DAA53B8BCB for ; Tue, 10 Mar 2026 15:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773158290; cv=none; b=mC9p+y7BWRQNzXZKZywV+UG4Ajooqz5MjhJuZWrhmAfBS9sXYMS16wILoVN/NxUB5tNqIF6UCYUFHoC2ja+CxP1yo3ndQrvp1kKTfTOwW28JR7BNfPIeuWLb1ZJA6k/unUBg3MlOMXV/rigdeTOdLG9tdP9irxKs8G4fYRVEV5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773158290; c=relaxed/simple; bh=suJDybSf2bJqRVbjzEF27konpZySIM4+uxLXQPLFNOQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mShN0si+sJ9fD7EVWP24wcoMDtwYtjYTt3ps97Ueq/IOadckhIKyOimEAZzJhwHjUFe/3DKsXboINFmT+i5gMDxQt4kucYURZ5hjF5ueKUXldSa++US4wp2lwxzT4cCYHomaWPikzHB4LPOXJROQdakxVxUTddv27nYxQl8T5Wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ReO47uHN; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ReO47uHN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1773158288; x=1804694288; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=suJDybSf2bJqRVbjzEF27konpZySIM4+uxLXQPLFNOQ=; b=ReO47uHNH9k9BunfAypS04DP906Ubcxs14jgQqLsDmwFStuZqfcarUkR 2md2vpxnCOhRUQY86sqKTPPV5rqjnsAqJyOmh5HeZpATIdFYS9NiXc9jL FzBaxyFLveFN6yOuWssIsDN+r2TYXOWxgDRefsFkdJ1X6eRGm8GFTHNwe iT6khaiYuQaeov8zUMICZ6TH32CJBpUiKPsVeTEZdrdg+PDO1ed9XUTeO UW4oPgIJVpeVFL4k464NKGHM4BvS6nbsg30Or0eQKy3R8V+xk+BZkGIbi aNKmKXMzCZhBwuEW25xNribYYXPB3lrgyKZE7L48RNkp5oHgtUBLNrffg A==; X-CSE-ConnectionGUID: NsF5wga3TD6pQ5JbxuymzQ== X-CSE-MsgGUID: jONKHPMsTK2RJU4SxpsMnA== X-IronPort-AV: E=McAfee;i="6800,10657,11725"; a="84842726" X-IronPort-AV: E=Sophos;i="6.23,112,1770624000"; d="scan'208";a="84842726" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2026 08:58:08 -0700 X-CSE-ConnectionGUID: 9lrVPpsOQMOw2aUR9hxX3g== X-CSE-MsgGUID: qevIcnH6Sci9p6WR8mT8Jw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,112,1770624000"; d="scan'208";a="224615389" Received: from fpallare-mobl4.ger.corp.intel.com (HELO fedora) ([10.245.244.90]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2026 08:58:04 -0700 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Brost , Maarten Lankhorst , Michal Mrozek , John Falkowski , Rodrigo Vivi , Lahtinen Joonas , David Howells , Christian Brauner , Kees Cook , Davidlohr Bueso , =?UTF-8?q?Christian=20K=C3=B6nig?= , Dave Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, LMKL Subject: [RFC PATCH RESEND 1/2] watch_queue: Add a DRM_XE_NOTIFY watch type and export init_watch() Date: Tue, 10 Mar 2026 16:57:40 +0100 Message-ID: <20260310155741.87191-2-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260310155741.87191-1-thomas.hellstrom@linux.intel.com> References: <20260310155741.87191-1-thomas.hellstrom@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add a DRM_XE_NOTIFY watch type for asynchronous error notifications from the DRM_XE kernel module. Also export the init_watch() function for use from kernel drivers. Use EXPORT_SYMBOL() to align with other exports from the same file. Assisted-by: GitHub Copilot:claude-sonnet-4.6 Signed-off-by: Thomas Hellstr=C3=B6m --- include/uapi/linux/watch_queue.h | 3 ++- kernel/watch_queue.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/watch_queue.h b/include/uapi/linux/watch_qu= eue.h index c3d8320b5d3a..c800c153989d 100644 --- a/include/uapi/linux/watch_queue.h +++ b/include/uapi/linux/watch_queue.h @@ -14,7 +14,8 @@ enum watch_notification_type { WATCH_TYPE_META =3D 0, /* Special record */ WATCH_TYPE_KEY_NOTIFY =3D 1, /* Key change event notification */ - WATCH_TYPE__NR =3D 2 + WATCH_TYPE_DRM_XE_NOTIFY =3D 2, /* DRM device event notification */ + WATCH_TYPE__NR =3D 3 }; =20 enum watch_meta_notification_subtype { diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 538520861e8b..701b5c388808 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -445,11 +445,17 @@ static void put_watch(struct watch *watch) } =20 /** - * init_watch - Initialise a watch + * init_watch() - Initialise a watch subscription * @watch: The watch to initialise. - * @wqueue: The queue to assign. + * @wqueue: The watch queue (notification pipe) to associate with the watc= h. * - * Initialise a watch and set the watch queue. + * Initialise a newly allocated watch object and associate it with @wqueue. + * The caller must subsequently set @watch->id and @watch->info_id before + * calling add_watch_to_object() to subscribe the watch to a notification + * source. + * + * The watch queue reference is held internally; call put_watch_queue() if + * the watch is not successfully passed to add_watch_to_object(). */ void init_watch(struct watch *watch, struct watch_queue *wqueue) { @@ -458,6 +464,7 @@ void init_watch(struct watch *watch, struct watch_queue= *wqueue) INIT_HLIST_NODE(&watch->queue_node); rcu_assign_pointer(watch->queue, wqueue); } +EXPORT_SYMBOL(init_watch); =20 static int add_one_watch(struct watch *watch, struct watch_list *wlist, st= ruct watch_queue *wqueue) { --=20 2.53.0 From nobody Wed Apr 8 02:54:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3EAC3BAD80 for ; Tue, 10 Mar 2026 15:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773158294; cv=none; b=NCI5c5FpkMBl/dXinw4UODZ/9BYEmULzOkQICuiR0/QBaZ1URguxJIYUjfPb1CheTE5z0bQGTPJHEzSdxjcAW6HAjdQEI0yGodK7f6w7iijd06VJIsu+4+4LL8seKCwzxYEIbOzv88XVNNXYxZeWrROH9LllAoXYTupXV2Ae0OY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773158294; c=relaxed/simple; bh=bXneDRdaSJoXs3ZRhW1iEhJw3rzdA5kUAgpjCBwsYvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VB0rJq5v6VliI0W/yADgTL+5uFsgZqp6d4Oo+1O4/6XolUGqqQAXs2Y28Ot2Vb21dUK+jC96niRcZl2A/SllZogNcgskotv3C6smHVzYa6knUcMTNlYxHIg2kdO4UH6lUMmWjqQW0OdKBuczQlTLbePyYqMDo6didyLrmginuYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=M8ki7/bo; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="M8ki7/bo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1773158292; x=1804694292; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bXneDRdaSJoXs3ZRhW1iEhJw3rzdA5kUAgpjCBwsYvY=; b=M8ki7/bopoO9qZsCVX8fuF76EHUeWwQ14LTNCFK1nN6F2CDDuSDnhP4O Ps2G/0RC2ShXV24GGFJR6mdfEs+rPoRgQRHsGJfR1Mb52FmdZFMgdHmMg 4gCbsTwy8Xvk+crGU038mhvLjGVumj+beGiAKYVv7MrAtlkwPIx8071oi DsNIX5VgTme7fjGj4NuK87sxAnGuOon9INQLGXRHeyI4fvi6HAOxMzV+P TYmz6vSYPP+D/MxYwg0dGZguvC1yAnWGg6CnWWstWtNuL9mgYnyjxxZ5a X5liFhKdg8t+w6tpF+ERDKATkHPHW12aoVrN1pb1OucJwynUMGLzUGh8m w==; X-CSE-ConnectionGUID: WHemaUAvSf+kEK5znsKC+Q== X-CSE-MsgGUID: N2SG2kqcRMGMn/qnHLXCDQ== X-IronPort-AV: E=McAfee;i="6800,10657,11725"; a="84842745" X-IronPort-AV: E=Sophos;i="6.23,112,1770624000"; d="scan'208";a="84842745" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2026 08:58:12 -0700 X-CSE-ConnectionGUID: oiYfVUoQS6W7eY041nSDbg== X-CSE-MsgGUID: F1WWHhg2T7iGr9eaeIfXcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,112,1770624000"; d="scan'208";a="224615404" Received: from fpallare-mobl4.ger.corp.intel.com (HELO fedora) ([10.245.244.90]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2026 08:58:08 -0700 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Brost , Maarten Lankhorst , Michal Mrozek , John Falkowski , Rodrigo Vivi , Lahtinen Joonas , David Howells , Christian Brauner , Kees Cook , Davidlohr Bueso , =?UTF-8?q?Christian=20K=C3=B6nig?= , Dave Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, LMKL Subject: [RFC PATCH RESEND 2/2] drm/xe: Add watch_queue-based device event notification Date: Tue, 10 Mar 2026 16:57:41 +0100 Message-ID: <20260310155741.87191-3-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260310155741.87191-1-thomas.hellstrom@linux.intel.com> References: <20260310155741.87191-1-thomas.hellstrom@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add a watch_queue notification channel tied to struct xe_vm so that userspace can subscribe to asynchronous GPU device events via the general kernel notification mechanism. Introduce DRM_IOCTL_XE_WATCH_QUEUE to let userspace subscribe a notification pipe (opened with pipe2(O_NOTIFICATION_PIPE)) to the device event stream. Embed the watch_id field (0-255) in the WATCH_INFO_ID field of every notification, allowing multiple watches to share a single pipe and be told apart by the reader. Deliver notifications as struct drm_xe_watch_notification records, with type always set to WATCH_TYPE_DRM_XE_NOTIFY and subtype drawn from enum drm_xe_watch_event. Define DRM_XE_WATCH_EVENT_DEVICE_RESET as the first event, to be posted by the GPU reset path to inform userspace that in-flight work has been lost. Expose xe_watch_queue_post_event() as the in-kernel posting API. Add event definitions in a separate uapi header, . The main reason is that the header needs to include which in turn includes which may conflict with the system . Hence user-space must pay special attention when including this file. Assisted-by: N/A:claude-sonnet-4.6 Tool1 Tool2=20 Signed-off-by: Thomas Hellstr=C3=B6m --- drivers/gpu/drm/xe/Kconfig | 1 + drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 7 ++ drivers/gpu/drm/xe/xe_device_types.h | 6 ++ drivers/gpu/drm/xe/xe_vm.c | 7 +- drivers/gpu/drm/xe/xe_vm_types.h | 2 + drivers/gpu/drm/xe/xe_watch_queue.c | 107 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_watch_queue.h | 20 +++++ include/uapi/drm/xe_drm.h | 46 ++++++++++++ include/uapi/drm/xe_drm_events.h | 56 ++++++++++++++ 10 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_watch_queue.c create mode 100644 drivers/gpu/drm/xe/xe_watch_queue.h create mode 100644 include/uapi/drm/xe_drm_events.h diff --git a/drivers/gpu/drm/xe/Kconfig b/drivers/gpu/drm/xe/Kconfig index 4d7dcaff2b91..dbdc2fb49c53 100644 --- a/drivers/gpu/drm/xe/Kconfig +++ b/drivers/gpu/drm/xe/Kconfig @@ -25,6 +25,7 @@ config DRM_XE select DRM_MIPI_DSI select RELAY select IRQ_WORK + select WATCH_QUEUE # xe depends on ACPI_VIDEO when ACPI is enabled # but for select to work, need to select ACPI_VIDEO's dependencies, ick select BACKLIGHT_CLASS_DEVICE if ACPI diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile index ff778fb2d4ff..1129583865ad 100644 --- a/drivers/gpu/drm/xe/Makefile +++ b/drivers/gpu/drm/xe/Makefile @@ -144,6 +144,7 @@ xe-y +=3D xe_bb.o \ xe_vsec.o \ xe_wa.o \ xe_wait_user_fence.o \ + xe_watch_queue.o \ xe_wopcm.o =20 xe-$(CONFIG_I2C) +=3D xe_i2c.o diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index 3462645ca13c..89bc221546ce 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 #include #include @@ -75,6 +76,7 @@ #include "xe_vsec.h" #include "xe_wait_user_fence.h" #include "xe_wa.h" +#include "xe_watch_queue.h" =20 #include #include @@ -110,6 +112,8 @@ static int xe_file_open(struct drm_device *dev, struct = drm_file *file) file->driver_priv =3D xef; kref_init(&xef->refcount); =20 + init_watch_list(&xef->watch_list, NULL); + task =3D get_pid_task(rcu_access_pointer(file->pid), PIDTYPE_PID); if (task) { xef->process_name =3D kstrdup(task->comm, GFP_KERNEL); @@ -124,6 +128,8 @@ static void xe_file_destroy(struct kref *ref) { struct xe_file *xef =3D container_of(ref, struct xe_file, refcount); =20 + remove_watch_from_object(&xef->watch_list, NULL, 0, true); + xa_destroy(&xef->exec_queue.xa); mutex_destroy(&xef->exec_queue.lock); xa_destroy(&xef->vm.xa); @@ -211,6 +217,7 @@ static const struct drm_ioctl_desc xe_ioctls[] =3D { DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(XE_EXEC_QUEUE_SET_PROPERTY, xe_exec_queue_set_property_= ioctl, DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(XE_WATCH_QUEUE, xe_watch_queue_ioctl, DRM_RENDER_ALLOW), }; =20 static long xe_drm_ioctl(struct file *file, unsigned int cmd, unsigned lon= g arg) diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_d= evice_types.h index caa8f34a6744..a42e6125c069 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -11,6 +11,7 @@ #include #include #include +#include =20 #include "xe_devcoredump_types.h" #include "xe_heci_gsc.h" @@ -629,6 +630,11 @@ struct xe_file { =20 /** @refcount: ref count of this xe file */ struct kref refcount; + +#ifdef CONFIG_WATCH_QUEUE + /** @watch_list: per-file notification source for device events */ + struct watch_list watch_list; +#endif }; =20 #endif diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c index 548b0769b3ef..1f331a2b2ecc 100644 --- a/drivers/gpu/drm/xe/xe_vm.c +++ b/drivers/gpu/drm/xe/xe_vm.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include "xe_tlb_inval.h" #include "xe_trace_bo.h" #include "xe_wa.h" +#include "xe_watch_queue.h" =20 static struct drm_gem_object *xe_vm_obj(struct xe_vm *vm) { @@ -567,13 +569,13 @@ static void preempt_rebind_work_func(struct work_stru= ct *w) } =20 if (err) { - drm_warn(&vm->xe->drm, "VM worker error: %d\n", err); + xe_watch_queue_post_vm_err_event(vm->xef, vm->id, err); + drm_dbg(&vm->xe->drm, "VM worker error: %d\n", err); xe_vm_kill(vm, true); } up_write(&vm->lock); =20 free_preempt_fences(&preempt_fences); - trace_xe_vm_rebind_worker_exit(vm); } =20 @@ -2008,6 +2010,7 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *= data, if (err) goto err_close_and_put; =20 + vm->id =3D id; args->vm_id =3D id; =20 return 0; diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_ty= pes.h index 1f6f7e30e751..df559cf87b4c 100644 --- a/drivers/gpu/drm/xe/xe_vm_types.h +++ b/drivers/gpu/drm/xe/xe_vm_types.h @@ -365,6 +365,8 @@ struct xe_vm { bool batch_invalidate_tlb; /** @xef: Xe file handle for tracking this VM's drm client */ struct xe_file *xef; + /** @id: The id of the VM in the VM table of @xef. */ + u32 id; }; =20 /** struct xe_vma_op_map - VMA map operation */ diff --git a/drivers/gpu/drm/xe/xe_watch_queue.c b/drivers/gpu/drm/xe/xe_wa= tch_queue.c new file mode 100644 index 000000000000..14c93cdebefe --- /dev/null +++ b/drivers/gpu/drm/xe/xe_watch_queue.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright =C2=A9 2026 Intel Corporation + */ + +#include +#include + +#include +#include + +#include "xe_device.h" +#include "xe_device_types.h" +#include "xe_macros.h" +#include "xe_watch_queue.h" + +/** + * struct xe_watch_notification_vm_err - kernel-side VM error event notifi= cation + * + * Layout mirrors &struct drm_xe_watch_notification_vm_err. + * + * @base: common watch notification header; type is %WATCH_TYPE_DRM_XE_NOT= IFY, + * subtype is %DRM_XE_WATCH_EVENT_VM_ERR + * @vm_id: ID of the VM that hit error + * @error_code: error code describing the error condition (negative errno) + */ +struct xe_watch_notification_vm_err { + struct watch_notification base; + u32 vm_id; + s32 error_code; +}; + +/** + * xe_watch_queue_ioctl() - Subscribe a pipe to per-file device event noti= fications + * @dev: DRM device + * @data: pointer to &struct drm_xe_watch_queue from userspace + * @file: DRM file handle of the subscribing process + * + * Subscribes a notification pipe to receive Xe device events for the call= ing + * process's file handle. Only events scoped to this file (e.g. VM error = on a + * VM owned by this file) are delivered. The pipe must have been opened w= ith + * O_NOTIFICATION_PIPE and sized with %IOC_WATCH_QUEUE_SET_SIZE before cal= ling + * this IOCTL. + * + * Return: 0 on success, negative errno on failure. + */ +int xe_watch_queue_ioctl(struct drm_device *dev, void *data, struct drm_fi= le *file) +{ + struct xe_file *xef =3D file->driver_priv; + struct xe_device *xe =3D to_xe_device(dev); + struct drm_xe_watch_queue *args =3D data; + struct watch_queue *wqueue; + struct watch *watch; + int ret; + + if (XE_IOCTL_DBG(xe, args->flags || args->pad)) + return -EINVAL; + if (XE_IOCTL_DBG(xe, args->watch_id > 0xff)) + return -EINVAL; + + wqueue =3D get_watch_queue(args->fd); + if (XE_IOCTL_DBG(xe, IS_ERR(wqueue))) + return PTR_ERR(wqueue); + + watch =3D kzalloc(sizeof(*watch), GFP_KERNEL | __GFP_ACCOUNT); + if (XE_IOCTL_DBG(xe, !watch)) { + ret =3D -ENOMEM; + goto out_put_queue; + } + + init_watch(watch, wqueue); + watch->id =3D 0; + watch->info_id =3D (u32)args->watch_id << WATCH_INFO_ID__SHIFT; + + ret =3D add_watch_to_object(watch, &xef->watch_list); + if (XE_IOCTL_DBG(xe, ret)) + kfree(watch); + +out_put_queue: + put_watch_queue(wqueue); + return ret; +} + +/** + * xe_watch_queue_post_vm_err_event() - Post a VM error event + * @xef: xe file handle that owns the VM + * @vm_id: userspace ID of the VM that hit error + * @error_code: error code describing the error condition (negative errno) + * + * Posts a %DRM_XE_WATCH_EVENT_VM_ERR notification carrying @vm_id and + * @error_code to every pipe that @xef has subscribed via + * %DRM_IOCTL_XE_WATCH_QUEUE. Only the owning process is notified, + * preventing information leaks to other clients. + */ +void xe_watch_queue_post_vm_err_event(struct xe_file *xef, u32 vm_id, + int error_code) +{ + struct xe_watch_notification_vm_err n =3D {}; + + n.base.type =3D WATCH_TYPE_DRM_XE_NOTIFY; + n.base.subtype =3D DRM_XE_WATCH_EVENT_VM_ERR; + n.base.info =3D watch_sizeof(struct xe_watch_notification_vm_err); + n.vm_id =3D vm_id; + n.error_code =3D error_code; + + post_watch_notification(&xef->watch_list, &n.base, current_cred(), 0); +} diff --git a/drivers/gpu/drm/xe/xe_watch_queue.h b/drivers/gpu/drm/xe/xe_wa= tch_queue.h new file mode 100644 index 000000000000..ad199ee68205 --- /dev/null +++ b/drivers/gpu/drm/xe/xe_watch_queue.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright =C2=A9 2026 Intel Corporation + */ + +#ifndef _XE_WATCH_QUEUE_H_ +#define _XE_WATCH_QUEUE_H_ + +#include + +struct drm_device; +struct drm_file; +struct xe_file; + +int xe_watch_queue_ioctl(struct drm_device *dev, void *data, + struct drm_file *file); +void xe_watch_queue_post_vm_err_event(struct xe_file *xef, u32 vm_id, + int error_code); + +#endif /* _XE_WATCH_QUEUE_H_ */ diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h index ef2565048bdf..bc3917700c82 100644 --- a/include/uapi/drm/xe_drm.h +++ b/include/uapi/drm/xe_drm.h @@ -83,6 +83,7 @@ extern "C" { * - &DRM_IOCTL_XE_OBSERVATION * - &DRM_IOCTL_XE_MADVISE * - &DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS + * - &DRM_IOCTL_XE_WATCH_QUEUE */ =20 /* @@ -107,6 +108,7 @@ extern "C" { #define DRM_XE_MADVISE 0x0c #define DRM_XE_VM_QUERY_MEM_RANGE_ATTRS 0x0d #define DRM_XE_EXEC_QUEUE_SET_PROPERTY 0x0e +#define DRM_XE_WATCH_QUEUE 0x0f =20 /* Must be kept compact -- no holes */ =20 @@ -125,6 +127,7 @@ extern "C" { #define DRM_IOCTL_XE_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_MADVISE, = struct drm_xe_madvise) #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 + DR= M_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property) +#define DRM_IOCTL_XE_WATCH_QUEUE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_WATCH_= QUEUE, struct drm_xe_watch_queue) =20 /** * DOC: Xe IOCTL Extensions @@ -2357,6 +2360,49 @@ struct drm_xe_exec_queue_set_property { __u64 reserved[2]; }; =20 +/** + * DOC: DRM_XE_WATCH_QUEUE + * + * Subscribe a notification pipe to receive device events for the calling + * process's DRM file handle. Events are scoped to the subscribing file: + * only events that belong to that file (for example, VM error on a VM cre= ated + * through the same file) are delivered, preventing information leaks betw= een + * processes sharing the same GPU device. + * + * The pipe must first be opened with O_NOTIFICATION_PIPE (i.e. O_EXCL pas= sed + * to pipe2()) and sized via %IOC_WATCH_QUEUE_SET_SIZE before subscribing. + * + * Events are delivered as notification records read from the pipe. The + * @watch_id field is embedded in the notification info field and can be u= sed + * to distinguish multiple watches sharing a pipe. + * + * Currently defined event subtypes: + * - %DRM_XE_WATCH_EVENT_VM_ERR - a VM owned by this file has encountered= an error + */ + +/** + * struct drm_xe_watch_queue - subscribe to device event notifications + * + * Used with %DRM_IOCTL_XE_WATCH_QUEUE. Notifications are scoped to the + * DRM file handle used to issue this IOCTL. + */ +struct drm_xe_watch_queue { + /** @fd: file descriptor of pipe opened with O_NOTIFICATION_PIPE */ + __u32 fd; + + /** + * @watch_id: identifier (0=E2=80=93255) embedded in the watch notificati= on + * info field; allows multiplexing several watches on one pipe + */ + __u32 watch_id; + + /** @flags: must be zero */ + __u32 flags; + + /** @pad: reserved, must be zero */ + __u32 pad; +}; + #if defined(__cplusplus) } #endif diff --git a/include/uapi/drm/xe_drm_events.h b/include/uapi/drm/xe_drm_eve= nts.h new file mode 100644 index 000000000000..91813548ae01 --- /dev/null +++ b/include/uapi/drm/xe_drm_events.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright =C2=A9 2026 Intel Corporation + */ + +#ifndef _UAPI_XE_DRM_EVENTS_H_ +#define _UAPI_XE_DRM_EVENTS_H_ + +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +/** + * enum drm_xe_watch_event - Xe device watch event subtypes + * + * Subtypes for notifications delivered via %WATCH_TYPE_DRM_XE_NOTIFY when + * reading from a pipe subscribed with %DRM_IOCTL_XE_WATCH_QUEUE. + */ +enum drm_xe_watch_event { + /** + * @DRM_XE_WATCH_EVENT_VM_ERR: a VM has encountered an error. + * + * Indicates that a memory allocation failure occurred within the + * given VM. The vm_id of the affected VM is carried in the + * @drm_xe_watch_notification_vm_err::vm_id field of the extended + * notification record. + */ + DRM_XE_WATCH_EVENT_VM_ERR =3D 0, +}; + +/** + * struct drm_xe_watch_notification_vm_err - VM error event notification + * + * Notification record delivered for %DRM_XE_WATCH_EVENT_VM_ERR. + * The record type is always %WATCH_TYPE_DRM_XE_NOTIFY and the subtype is + * %DRM_XE_WATCH_EVENT_VM_ERR. + */ +struct drm_xe_watch_notification_vm_err { + /** @base: common watch notification header */ + struct watch_notification base; + + /** @vm_id: ID of the VM that hit out-of-memory */ + __u32 vm_id; + + /** @error_code: error code describing the error condition (negative errn= o) */ + __s32 error_code; +}; + +#if defined(__cplusplus) +} +#endif + +#endif /* _UAPI_XE_DRM_H_ */ --=20 2.53.0