Skip to contentSkip to conversation

Intel Xe GPU debug support (eudebug) v3

PATCH In review Mika Kuoppala 8 participants 62 messages Dec 9, 2024 – Jan 30, 2025

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Intel Xe GPU debug support (eudebug) v3

Hi,

This is continuation of the first and second submission of Intel Xe GPU debug support:

v1: https://lists.freedesktop.org/archives/intel-xe/2024-July/043605.html
v2: https://lists.freedesktop.org/archives/intel-xe/2024-October/052260.html

New features in v3:

- EXEC_QUEUE_PLACEMENT events providing detailed information about engines participating on exec queue. (Dominik Grzegorzek)

- EU thread page fault support (Gwan-gyeong Mun)

- Fixed access to VRAM backed storage (Matthew Brost) Essential for BMG enabling. This work was already merged into xe driver and eudebug takes advantage of that (ttm_bo_access). [8].

- Support for Pantherlake (Dominik Grzegorzek)

v3 supports:
- Lunarlake (LNL)
- Battlemage (BMG)
- Pantherlake (PTL)

Thanks to all contributors!

Latest code can be found in:
[1] https://gitlab.freedesktop.org/miku/kernel/-/tree/eudebug-dev

Branch for this submission:
[2] https://gitlab.freedesktop.org/miku/kernel/-/tree/eudebug-v3

README/instructions:
[3] https://gitlab.freedesktop.org/miku/kernel

IGT tests (needs config switch 'xe_eudebug' to be set)
[4] https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
https://gitlab.freedesktop.org/gfx-ci/i915-infra/-/blob/master/kconfig/debug.kconfig

The user for this uapi:
[5] https://github.com/intel/compute-runtime
Event loop and thread control interaction can be found at:
https://github.com/intel/compute-runtime/tree/master/level_zero/tools/source/debug/linux/xe
And the wrappers in:
https://github.com/intel/compute-runtime/tree/master/shared/source/os_interface/linux/xe
https://github.com/intel/compute-runtime/blob/master/shared/source/os_interface/linux/xe/ioctl_helper_xe_debugger.cpp
Note that the XE support is disabled by default and you will need NEO_ENABLE_XE_EU_DEBUG_SUPPORT enabled in order to test.

GDB support:
[6] https://github.com/intel/gdb/tree/upstream/intelgt-mvp
[7] https://github.com/intel/gdb/tree/upstream/intelgt-mvp-plus
GDB is preparing their own mailing list submission with above and based on v3. I will reply to this cover letter and update README when it happens.

[8]: https://lists.freedesktop.org/archives/intel-xe/2024-November/060247.html
Fix non-contiguous VRAM BO access in Xe

Thanks,
Mika

Andrzej Hajda (2):
drm/xe: add system memory page iterator support to xe_res_cursor drm/xe/eudebug: implement userptr_vma access

Christoph Manszewski (3):
drm/xe/eudebug: Add vm bind and vm bind ops drm/xe/eudebug: Dynamically toggle debugger functionality drm/xe/eudebug_test: Introduce xe_eudebug wa kunit test

Dominik Grzegorzek (11):
drm/xe/eudebug: Introduce exec_queue events drm/xe/eudebug: Introduce exec queue placements event drm/xe/eudebug: hw enablement for eudebug
drm/xe: Add EUDEBUG_ENABLE exec queue property drm/xe/eudebug: Introduce per device attention scan worker drm/xe/eudebug: Introduce EU control interface drm/xe: Debug metadata create/destroy ioctls drm/xe: Attach debug metadata to vma drm/xe/eudebug: Add debug metadata support for xe_eudebug drm/xe/eudebug/ptl: Add support for extra attention register drm/xe/eudebug/ptl: Add RCU_DEBUG_1 register support for xe3

Gwan-gyeong Mun (4):
drm/xe/eudebug: Add read/count/compare helper for eu attention drm/xe/eudebug: Introduce EU pagefault handling interface drm/xe/vm: Support for adding null page VMA to VM on request drm/xe/eudebug: Enable EU pagefault handling

Mika Kuoppala (6):
ptrace: export ptrace_may_access drm/xe/eudebug: Introduce eudebug support drm/xe/eudebug: Introduce discovery for resources drm/xe/eudebug: Add UFENCE events with acks drm/xe/eudebug: vm open/pread/pwrite drm/xe/eudebug: Implement vm_bind_op discovery

 drivers/gpu/drm/xe/Kconfig                   |   10 +
 drivers/gpu/drm/xe/Makefile                  |    4 +
 drivers/gpu/drm/xe/regs/xe_engine_regs.h     |    7 +
 drivers/gpu/drm/xe/regs/xe_gt_regs.h         |   43 +
 drivers/gpu/drm/xe/tests/xe_eudebug.c        |  176 +
 drivers/gpu/drm/xe/tests/xe_live_test_mod.c  |    5 +
 drivers/gpu/drm/xe/xe_debug_metadata.c       |  233 +
 drivers/gpu/drm/xe/xe_debug_metadata.h       |  102 +
 drivers/gpu/drm/xe/xe_debug_metadata_types.h |   25 +
 drivers/gpu/drm/xe/xe_device.c               |   25 +-
 drivers/gpu/drm/xe/xe_device.h               |   36 +
 drivers/gpu/drm/xe/xe_device_types.h         |   54 +
 drivers/gpu/drm/xe/xe_eudebug.c              | 4451 ++++++++++++++++++
 drivers/gpu/drm/xe/xe_eudebug.h              |  128 +
 drivers/gpu/drm/xe/xe_eudebug_types.h        |  448 ++
 drivers/gpu/drm/xe/xe_exec.c                 |    2 +-
 drivers/gpu/drm/xe/xe_exec_queue.c           |   56 +-
 drivers/gpu/drm/xe/xe_exec_queue.h           |    2 +
 drivers/gpu/drm/xe/xe_exec_queue_types.h     |    7 +
 drivers/gpu/drm/xe/xe_execlist.c             |    2 +-
 drivers/gpu/drm/xe/xe_gt_debug.c             |  212 +
 drivers/gpu/drm/xe/xe_gt_debug.h             |   46 +
 drivers/gpu/drm/xe/xe_gt_pagefault.c         |   87 +-
 drivers/gpu/drm/xe/xe_gt_pagefault.h         |    2 +
 drivers/gpu/drm/xe/xe_hw_engine.c            |    1 +
 drivers/gpu/drm/xe/xe_lrc.c                  |   16 +-
 drivers/gpu/drm/xe/xe_lrc.h                  |    4 +-
 drivers/gpu/drm/xe/xe_oa.c                   |    3 +-
 drivers/gpu/drm/xe/xe_reg_sr.c               |   21 +-
 drivers/gpu/drm/xe/xe_reg_sr.h               |    4 +-
 drivers/gpu/drm/xe/xe_res_cursor.h           |   51 +-
 drivers/gpu/drm/xe/xe_rtp.c                  |    2 +-
 drivers/gpu/drm/xe/xe_sync.c                 |   45 +-
 drivers/gpu/drm/xe/xe_sync.h                 |    8 +-
 drivers/gpu/drm/xe/xe_sync_types.h           |   28 +-
 drivers/gpu/drm/xe/xe_vm.c                   |  196 +-
 drivers/gpu/drm/xe/xe_vm.h                   |    5 +
 drivers/gpu/drm/xe/xe_vm_types.h             |   40 +
 drivers/gpu/drm/xe/xe_wa_oob.rules           |    2 +
 include/uapi/drm/xe_drm.h                    |   96 +-
 include/uapi/drm/xe_drm_eudebug.h            |  256 +
 kernel/ptrace.c                              |    1 +
 42 files changed, 6869 insertions(+), 73 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/tests/xe_eudebug.c
 create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata.c
 create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata.h
 create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata_types.h
 create mode 100644 drivers/gpu/drm/xe/xe_eudebug.c
 create mode 100644 drivers/gpu/drm/xe/xe_eudebug.h
 create mode 100644 drivers/gpu/drm/xe/xe_eudebug_types.h
 create mode 100644 drivers/gpu/drm/xe/xe_gt_debug.c
 create mode 100644 drivers/gpu/drm/xe/xe_gt_debug.h
 create mode 100644 include/uapi/drm/xe_drm_eudebug.h
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/26 ptrace: export ptrace_may_access

xe driver would like to allow fine grained access control for GDB debugger using ptrace. Without this export, the only option would be to check for CAP_SYS_ADMIN.

The check intended for an ioctl to attach a GPU debugger is similar to the ptrace use case: allow a calling process to manipulate a target process if it has the necessary capabilities or the same permissions, as described in Documentation/process/adding-syscalls.rst.

Export ptrace_may_access function to allow GPU debugger to have identical access control for debugger(s)
as a CPU debugger.

v2: proper commit message (Lucas)

Cc Oleg Nesterov <[email protected]>
Cc Dave Airlie <[email protected]>
CC Lucas De Marchi <[email protected]>
Cc Matthew Brost <[email protected]>
CC Andi Shyti <[email protected]>
Cc Joonas Lahtinen <[email protected]>
CC Maciej Patelczyk <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
---
 kernel/ptrace.c | 1 +
 1 file changed, 1 insertion(+)
kernel/ptrace.c +1 -0
index d5f89f9ef29f..86be1805ebd8 100644
@@ -354,6 +354,7 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
 	task_unlock(task);
 	return !err;
 }
+EXPORT_SYMBOL_GPL(ptrace_may_access);
 
 static int check_ptrace_options(unsigned long data)
 {
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 01/26] ptrace: export ptrace_may_access

Quoted 10 lines · Mika Kuoppala

xe driver would like to allow fine grained access control for GDB debugger using ptrace. Without this export, the only option would be to check for CAP_SYS_ADMIN.

The check intended for an ioctl to attach a GPU debugger is similar to the ptrace use case: allow a calling process to manipulate a target process if it has the necessary capabilities or the same permissions, as described in Documentation/process/adding-syscalls.rst.

Quoted 3 lines

Export ptrace_may_access function to allow GPU debugger to have identical access control for debugger(s)
as a CPU debugger.

This seems to mis an actual user or you forgot to Cc linux-kernel on it.

#3 lore raw

Re: [PATCH 01/26] ptrace: export ptrace_may_access

Quoting Christoph Hellwig (2024-12-10 06:29:38)

Quoted 11 lines · Mika Kuoppala
Quoted 10 lines

xe driver would like to allow fine grained access control for GDB debugger using ptrace. Without this export, the only option would be to check for CAP_SYS_ADMIN.

The check intended for an ioctl to attach a GPU debugger is similar to the ptrace use case: allow a calling process to manipulate a target process if it has the necessary capabilities or the same permissions, as described in Documentation/process/adding-syscalls.rst.

Quoted 5 lines
Quoted 3 lines

Export ptrace_may_access function to allow GPU debugger to have identical access control for debugger(s)
as a CPU debugger.

This seems to mis an actual user or you forgot to Cc linux-kernel on it.

Right, that is a miss on our side. For the time being, the whole series can be found in lore archive:

https://lore.kernel.org/dri-devel/[email protected]/

The user is introduced in patch: [PATCH 03/26] drm/xe/eudebug: Introduce discovery for resources [1]

Essentially, we want to check if PID1 has permission to ptrace PID2, before we grant the permission for PID1 to debug the GPU address space/memory of PID2.

Mika, please do Cc the relevant other patches of the series to LKML for next iteration.

Regards, Joonas

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#md3d005faaaac1ba01451b139a634e5545c2a266f

#4 lore raw

PATCH 2/26 drm/xe/eudebug: Introduce eudebug support

In reply to Mika Kuoppala

With eudebug event interface, user space debugger process (like gdb) is able to keep track of resources created by another process (debuggee using drm/xe) and act upon these resources.

For example, debugger can find a client vm which contains isa/elf for a particular shader/eu-kernel and then inspect and modify it (for example installing a breakpoint).

Debugger first opens a connection to xe with a drm ioctl specifying target pid to connect. This returns an anon fd handle that can then be used to listen for events with dedicated ioctl.

This patch introduces eudebug connection and event queuing, adding client create/destroy and vm create/destroy events as a baseline. More events for full debugger operation are needed and those will be introduced in follow up patches.

The resource tracking parts are inspired by the work of Maciej Patelczyk on resource handling for i915. Chris Wilson suggested improvement of two ways mapping which makes it easy to use resource map as a definitive bookkeep of what resources are played to debugger in the discovery phase (on follow up patch).

v2: - Kconfig support (Matthew)
- ptraced access control (Lucas)
- pass expected event length to user (Zbigniew)
- only track long running VMs
- checkpatch (Tilak)
- include order (Andrzej)
- 32bit fixes (Andrzej)
- cleaner get_task_struct
- remove xa_array and use clients.list for tracking (Mika)

v3: - adapt to removal of clients.lock (Mika)
- create_event cleanup (Christoph)

Cc Maarten Lankhorst <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
Cc Andi Shyti <[email protected]>
Cc Matt Roper <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Zbigniew Kempczyński <[email protected]>
Cc Andrzej Hajda <[email protected]>
---
 drivers/gpu/drm/xe/Kconfig            |   10 +
 drivers/gpu/drm/xe/Makefile           |    2 +
 drivers/gpu/drm/xe/xe_device.c        |   10 +
 drivers/gpu/drm/xe/xe_device_types.h  |   35 +
 drivers/gpu/drm/xe/xe_eudebug.c       | 1118 +++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_eudebug.h       |   46 +
 drivers/gpu/drm/xe/xe_eudebug_types.h |  169 ++++
 drivers/gpu/drm/xe/xe_vm.c            |    7 +-
 include/uapi/drm/xe_drm.h             |   21 +
 include/uapi/drm/xe_drm_eudebug.h     |   56 ++
 10 files changed, 1473 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/xe/xe_eudebug.c
 create mode 100644 drivers/gpu/drm/xe/xe_eudebug.h
 create mode 100644 drivers/gpu/drm/xe/xe_eudebug_types.h
 create mode 100644 include/uapi/drm/xe_drm_eudebug.h
drivers/gpu/drm/xe/Kconfig +10 -0
index b51a2bde73e2..ed97730b1af3 100644
@@ -87,6 +87,16 @@ config DRM_XE_FORCE_PROBE
 
 	  Use "!*" to block the probe of the driver for all known devices.
 
+config DRM_XE_EUDEBUG
+	bool "Enable gdb debugger support (eudebug)"
+	depends on DRM_XE
+	default y
+	help
+	  Choose this option if you want to add support for debugger (gdb) to
+	  attach into process using Xe and debug the gpu/gpgpu programs.
+	  With debugger support, Xe will provide interface for a debugger to
+	  process to track, inspect and modify resources.
+
 menu "drm/Xe Debugging"
 depends on DRM_XE
 depends on EXPERT
drivers/gpu/drm/xe/Makefile +2 -0
index 7730e0596299..deabcdd3ea52 100644
@@ -116,6 +116,8 @@ xe-y += xe_bb.o \
 	xe_wa.o \
 	xe_wopcm.o
 
+xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o
+
 xe-$(CONFIG_HMM_MIRROR) += xe_hmm.o
 
 # graphics hardware monitoring (HWMON) support
drivers/gpu/drm/xe/xe_device.c +10 -0
index d6fccea1e083..9ed0de1eba0b 100644
@@ -28,6 +28,7 @@
 #include "xe_dma_buf.h"
 #include "xe_drm_client.h"
 #include "xe_drv.h"
+#include "xe_eudebug.h"
 #include "xe_exec.h"
 #include "xe_exec_queue.h"
 #include "xe_force_wake.h"
@@ -100,6 +101,8 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
 		put_task_struct(task);
 	}
 
+	xe_eudebug_file_open(xef);
+
 	return 0;
 }
 
@@ -153,6 +156,8 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
 
 	xe_pm_runtime_get(xe);
 
+	xe_eudebug_file_close(xef);
+
 	/*
 	 * No need for exec_queue.lock here as there is no contention for it
 	 * when FD is closing as IOCTLs presumably can't be modifying the
@@ -191,6 +196,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(XE_WAIT_USER_FENCE, xe_wait_user_fence_ioctl,
 			  DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(XE_OBSERVATION, xe_observation_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(XE_EUDEBUG_CONNECT, xe_eudebug_connect_ioctl, DRM_RENDER_ALLOW),
 };
 
 static long xe_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
@@ -281,6 +287,8 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
 {
 	struct xe_device *xe = to_xe_device(dev);
 
+	xe_eudebug_fini(xe);
+
 	if (xe->preempt_fence_wq)
 		destroy_workqueue(xe->preempt_fence_wq);
 
@@ -352,6 +360,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	INIT_LIST_HEAD(&xe->pinned.external_vram);
 	INIT_LIST_HEAD(&xe->pinned.evicted);
 
+	xe_eudebug_init(xe);
+
 	xe->preempt_fence_wq = alloc_ordered_workqueue("xe-preempt-fence-wq",
 						       WQ_MEM_RECLAIM);
 	xe->ordered_wq = alloc_ordered_workqueue("xe-ordered-wq", 0);
drivers/gpu/drm/xe/xe_device_types.h +35 -0
index 1373a222f5a5..9f04e6476195 100644
@@ -383,6 +383,17 @@ struct xe_device {
 		struct workqueue_struct *wq;
 	} sriov;
 
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	/** @clients: eudebug clients info */
+	struct {
+		/** @clients.lock: Protects client list */
+		spinlock_t lock;
+
+		/** @xa: client list for eudebug discovery */
+		struct list_head list;
+	} clients;
+#endif
+
 	/** @usm: unified memory state */
 	struct {
 		/** @usm.asid: convert a ASID to VM */
@@ -525,6 +536,23 @@ struct xe_device {
 	u8 vm_inject_error_position;
 #endif
 
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	/** @debugger connection list and globals for device */
+	struct {
+		/** @lock: protects the list of connections */
+		spinlock_t lock;
+
+		/** @list: list of connections, aka debuggers */
+		struct list_head list;
+
+		/** @session_count: session counter to track connections */
+		u64 session_count;
+
+		/** @available: is the debugging functionality available */
+		bool available;
+	} eudebug;
+#endif
+
 	/* private: */
 
 #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY)
@@ -642,6 +670,13 @@ struct xe_file {
 
 	/** @refcount: ref count of this xe file */
 	struct kref refcount;
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		/** @client_link: list entry in xe_device.clients.list */
+		struct list_head client_link;
+	} eudebug;
+#endif
 };
 
 #endif
drivers/gpu/drm/xe/xe_eudebug.c new file +1118 -0

1,118 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug.h new file +46 -0

46 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug_types.h new file +169 -0

169 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.c +6 -1
index 7788680da4e5..6f16049f4f6e 100644
@@ -25,6 +25,7 @@
 #include "xe_bo.h"
 #include "xe_device.h"
 #include "xe_drm_client.h"
+#include "xe_eudebug.h"
 #include "xe_exec_queue.h"
 #include "xe_gt_pagefault.h"
 #include "xe_gt_tlb_invalidation.h"
@@ -1797,6 +1798,8 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
 
 	args->vm_id = id;
 
+	xe_eudebug_vm_create(xef, vm);
+
 	return 0;
 
 err_close_and_put:
@@ -1828,8 +1831,10 @@ int xe_vm_destroy_ioctl(struct drm_device *dev, void *data,
 		xa_erase(&xef->vm.xa, args->vm_id);
 	mutex_unlock(&xef->vm.lock);
 
-	if (!err)
+	if (!err) {
+		xe_eudebug_vm_destroy(xef, vm);
 		xe_vm_close_and_put(vm);
+	}
 
 	return err;
 }
include/uapi/drm/xe_drm.h +21 -0
index 4a8a4a63e99c..78479100a0b6 100644
@@ -102,6 +102,7 @@ extern "C" {
 #define DRM_XE_EXEC			0x09
 #define DRM_XE_WAIT_USER_FENCE		0x0a
 #define DRM_XE_OBSERVATION		0x0b
+#define DRM_XE_EUDEBUG_CONNECT		0x0c
 
 /* Must be kept compact -- no holes */
 
@@ -117,6 +118,7 @@ extern "C" {
 #define DRM_IOCTL_XE_EXEC			DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec)
 #define DRM_IOCTL_XE_WAIT_USER_FENCE		DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)
 #define DRM_IOCTL_XE_OBSERVATION		DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param)
+#define DRM_IOCTL_XE_EUDEBUG_CONNECT		DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EUDEBUG_CONNECT, struct drm_xe_eudebug_connect)
 
 /**
  * DOC: Xe IOCTL Extensions
@@ -1713,6 +1715,25 @@ struct drm_xe_oa_stream_info {
 	__u64 reserved[3];
 };
 
+/*
+ * Debugger ABI (ioctl and events) Version History:
+ * 0 - No debugger available
+ * 1 - Initial version
+ */
+#define DRM_XE_EUDEBUG_VERSION 1
+
+struct drm_xe_eudebug_connect {
+	/** @extensions: Pointer to the first extension struct, if any */
+	__u64 extensions;
+
+	__u64 pid; /* input: Target process ID */
+	__u32 flags; /* MBZ */
+
+	__u32 version; /* output: current ABI (ioctl / events) version */
+};
+
+#include "xe_drm_eudebug.h"
+
 #if defined(__cplusplus)
 }
 #endif
include/uapi/drm/xe_drm_eudebug.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

PATCH 3/26 drm/xe/eudebug: Introduce discovery for resources

In reply to Mika Kuoppala

Debugger connection can happen way after the client has created and destroyed arbitrary number of resources.

We need to playback all currently existing resources for the debugger. The client is held until this so called discovery process, executed by workqueue, is complete.

This patch is based on discovery work by Maciej Patelczyk for i915 driver.

v2: - use rw_semaphore to block drm_ioctls during discovery (Matthew)
- only lock according to ioctl at play (Dominik)

---
 drivers/gpu/drm/xe/xe_device.c        |  10 +-
 drivers/gpu/drm/xe/xe_device.h        |  34 +++++++
 drivers/gpu/drm/xe/xe_device_types.h  |   6 ++
 drivers/gpu/drm/xe/xe_eudebug.c       | 135 +++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug_types.h |   7 ++
 5 files changed, 185 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_device.c +8 -2
index 9ed0de1eba0b..f051612908de 100644
@@ -209,8 +209,11 @@ static long xe_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		return -ECANCELED;
 
 	ret = xe_pm_runtime_get_ioctl(xe);
-	if (ret >= 0)
+	if (ret >= 0) {
+		xe_eudebug_discovery_lock(xe, cmd);
 		ret = drm_ioctl(file, cmd, arg);
+		xe_eudebug_discovery_unlock(xe, cmd);
+	}
 	xe_pm_runtime_put(xe);
 
 	return ret;
@@ -227,8 +230,11 @@ static long xe_drm_compat_ioctl(struct file *file, unsigned int cmd, unsigned lo
 		return -ECANCELED;
 
 	ret = xe_pm_runtime_get_ioctl(xe);
-	if (ret >= 0)
+	if (ret >= 0) {
+		xe_eudebug_discovery_lock(xe, cmd);
 		ret = drm_compat_ioctl(file, cmd, arg);
+		xe_eudebug_discovery_unlock(xe, cmd);
+	}
 	xe_pm_runtime_put(xe);
 
 	return ret;
drivers/gpu/drm/xe/xe_device.h +34 -0
index f1fbfe916867..088831a6b863 100644
@@ -7,6 +7,7 @@
 #define _XE_DEVICE_H_
 
 #include <drm/drm_util.h>
+#include <drm/drm_ioctl.h>
 
 #include "xe_device_types.h"
 #include "xe_gt_types.h"
@@ -205,4 +206,37 @@ void xe_file_put(struct xe_file *xef);
 #define LNL_FLUSH_WORK(wrk__) \
 	flush_work(wrk__)
 
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+static inline int xe_eudebug_needs_lock(const unsigned int cmd)
+{
+	const unsigned int xe_cmd = DRM_IOCTL_NR(cmd) - DRM_COMMAND_BASE;
+
+	switch (xe_cmd) {
+	case DRM_XE_VM_CREATE:
+	case DRM_XE_VM_DESTROY:
+	case DRM_XE_VM_BIND:
+	case DRM_XE_EXEC_QUEUE_CREATE:
+	case DRM_XE_EXEC_QUEUE_DESTROY:
+	case DRM_XE_EUDEBUG_CONNECT:
+		return 1;
+	}
+
+	return 0;
+}
+
+static inline void xe_eudebug_discovery_lock(struct xe_device *xe, unsigned int cmd)
+{
+	if (xe_eudebug_needs_lock(cmd))
+		down_read(&xe->eudebug.discovery_lock);
+}
+static inline void xe_eudebug_discovery_unlock(struct xe_device *xe, unsigned int cmd)
+{
+	if (xe_eudebug_needs_lock(cmd))
+		up_read(&xe->eudebug.discovery_lock);
+}
+#else
+static inline void xe_eudebug_discovery_lock(struct xe_device *xe, unsigned int cmd) { }
+static inline void xe_eudebug_discovery_unlock(struct xe_device *xe, unsigned int cmd) { }
+#endif /* CONFIG_DRM_XE_EUDEBUG */
+
 #endif
drivers/gpu/drm/xe/xe_device_types.h +6 -0
index 9f04e6476195..9941ea1400c6 100644
@@ -550,6 +550,12 @@ struct xe_device {
 
 		/** @available: is the debugging functionality available */
 		bool available;
+
+		/** @ordered_wq: used to discovery */
+		struct workqueue_struct *ordered_wq;
+
+		/** discovery_lock: used for discovery to block xe ioctls */
+		struct rw_semaphore discovery_lock;
 	} eudebug;
 #endif
 
drivers/gpu/drm/xe/xe_eudebug.c +130 -5

219 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug_types.h +7 -0
index a5185f18f640..080a821db3e4 100644
@@ -19,6 +19,7 @@
 struct xe_device;
 struct task_struct;
 struct xe_eudebug_event;
+struct workqueue_struct;
 
 #define CONFIG_DRM_XE_DEBUGGER_EVENT_QUEUE_SIZE 64
 
@@ -96,6 +97,12 @@ struct xe_eudebug {
 	/** @session: session number for this connection (for logs) */
 	u64 session;
 
+	/** @discovery: completion to wait for discovery */
+	struct completion discovery;
+
+	/** @discovery_work: worker to discover resources for target_task */
+	struct work_struct discovery_work;
+
 	/** @events: kfifo queue of to-be-delivered events */
 	struct {
 		/** @lock: guards access to fifo */
Signature · 1 line
2.43.0
#6 lore raw

PATCH 4/26 drm/xe/eudebug: Introduce exec_queue events

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Inform debugger about creation and destruction of exec_queues.

1) Use user engine class types instead of internal xe_engine_class enum in exec_queue event.

2) During discovery do not advertise every execqueue created, only ones with class render or compute.

v2: - Only track long running queues
- Checkpatch (Tilak)

v3: __counted_by added

---
 drivers/gpu/drm/xe/xe_eudebug.c       | 189 +++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug.h       |   7 +
 drivers/gpu/drm/xe/xe_eudebug_types.h |  31 ++++-
 drivers/gpu/drm/xe/xe_exec_queue.c    |   5 +
 include/uapi/drm/xe_drm_eudebug.h     |  12 ++
 5 files changed, 241 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_eudebug.c +187 -2
index 228bc36342ba..3ca46ec838b9 100644
@@ -14,6 +14,7 @@
 #include "xe_device.h"
 #include "xe_eudebug.h"
 #include "xe_eudebug_types.h"
+#include "xe_exec_queue.h"
 #include "xe_macros.h"
 #include "xe_vm.h"
 
@@ -716,7 +717,7 @@ static struct xe_eudebug_event *
 xe_eudebug_create_event(struct xe_eudebug *d, u16 type, u64 seqno, u16 flags,
 			u32 len)
 {
-	const u16 max_event = DRM_XE_EUDEBUG_EVENT_VM;
+	const u16 max_event = DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE;
 	const u16 known_flags =
 		DRM_XE_EUDEBUG_EVENT_CREATE |
 		DRM_XE_EUDEBUG_EVENT_DESTROY |
@@ -751,7 +752,7 @@ static long xe_eudebug_read_event(struct xe_eudebug *d,
 		u64_to_user_ptr(arg);
 	struct drm_xe_eudebug_event user_event;
 	struct xe_eudebug_event *event;
-	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_VM;
+	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE;
 	long ret = 0;
 
 	if (XE_IOCTL_DBG(xe, copy_from_user(&user_event, user_orig, sizeof(user_event))))
@@ -1159,8 +1160,183 @@ void xe_eudebug_vm_destroy(struct xe_file *xef, struct xe_vm *vm)
 	xe_eudebug_event_put(d, vm_destroy_event(d, xef, vm));
 }
 
+static bool exec_queue_class_is_tracked(enum xe_engine_class class)
+{
+	return class == XE_ENGINE_CLASS_COMPUTE ||
+		class == XE_ENGINE_CLASS_RENDER;
+}
+
+static const u16 xe_to_user_engine_class[] = {
+	[XE_ENGINE_CLASS_RENDER] = DRM_XE_ENGINE_CLASS_RENDER,
+	[XE_ENGINE_CLASS_COPY] = DRM_XE_ENGINE_CLASS_COPY,
+	[XE_ENGINE_CLASS_VIDEO_DECODE] = DRM_XE_ENGINE_CLASS_VIDEO_DECODE,
+	[XE_ENGINE_CLASS_VIDEO_ENHANCE] = DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE,
+	[XE_ENGINE_CLASS_COMPUTE] = DRM_XE_ENGINE_CLASS_COMPUTE,
+};
+
+static int send_exec_queue_event(struct xe_eudebug *d, u32 flags,
+				 u64 client_handle, u64 vm_handle,
+				 u64 exec_queue_handle, enum xe_engine_class class,
+				 u32 width, u64 *lrc_handles, u64 seqno)
+{
+	struct xe_eudebug_event *event;
+	struct xe_eudebug_event_exec_queue *e;
+	const u32 sz = struct_size(e, lrc_handle, width);
+	const u32 xe_engine_class = xe_to_user_engine_class[class];
+
+	if (!exec_queue_class_is_tracked(class))
+		return -EINVAL;
+
+	event = xe_eudebug_create_event(d, DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE,
+					seqno, flags, sz);
+	if (!event)
+		return -ENOMEM;
+
+	e = cast_event(e, event);
+
+	write_member(struct drm_xe_eudebug_event_exec_queue, e, client_handle, client_handle);
+	write_member(struct drm_xe_eudebug_event_exec_queue, e, vm_handle, vm_handle);
+	write_member(struct drm_xe_eudebug_event_exec_queue, e, exec_queue_handle,
+		     exec_queue_handle);
+	write_member(struct drm_xe_eudebug_event_exec_queue, e, engine_class, xe_engine_class);
+	write_member(struct drm_xe_eudebug_event_exec_queue, e, width, width);
+
+	memcpy(e->lrc_handle, lrc_handles, width);
+
+	return xe_eudebug_queue_event(d, event);
+}
+
+static int exec_queue_create_event(struct xe_eudebug *d,
+				   struct xe_file *xef, struct xe_exec_queue *q)
+{
+	int h_c, h_vm, h_queue;
+	u64 h_lrc[XE_HW_ENGINE_MAX_INSTANCE], seqno;
+	int i;
+
+	if (!xe_exec_queue_is_lr(q))
+		return 0;
+
+	h_c = find_handle(d->res, XE_EUDEBUG_RES_TYPE_CLIENT, xef);
+	if (h_c < 0)
+		return h_c;
+
+	h_vm = find_handle(d->res, XE_EUDEBUG_RES_TYPE_VM, q->vm);
+	if (h_vm < 0)
+		return h_vm;
+
+	if (XE_WARN_ON(q->width >= XE_HW_ENGINE_MAX_INSTANCE))
+		return -EINVAL;
+
+	for (i = 0; i < q->width; i++) {
+		int h, ret;
+
+		ret = _xe_eudebug_add_handle(d,
+					     XE_EUDEBUG_RES_TYPE_LRC,
+					     q->lrc[i],
+					     NULL,
+					     &h);
+
+		if (ret < 0 && ret != -EEXIST)
+			return ret;
+
+		XE_WARN_ON(!h);
+
+		h_lrc[i] = h;
+	}
+
+	h_queue = xe_eudebug_add_handle(d, XE_EUDEBUG_RES_TYPE_EXEC_QUEUE, q, &seqno);
+	if (h_queue <= 0)
+		return h_queue;
+
+	/* No need to cleanup for added handles on error as if we fail
+	 * we disconnect
+	 */
+
+	return send_exec_queue_event(d, DRM_XE_EUDEBUG_EVENT_CREATE,
+				     h_c, h_vm, h_queue, q->class,
+				     q->width, h_lrc, seqno);
+}
+
+static int exec_queue_destroy_event(struct xe_eudebug *d,
+				    struct xe_file *xef,
+				    struct xe_exec_queue *q)
+{
+	int h_c, h_vm, h_queue;
+	u64 h_lrc[XE_HW_ENGINE_MAX_INSTANCE], seqno;
+	int i;
+
+	if (!xe_exec_queue_is_lr(q))
+		return 0;
+
+	h_c = find_handle(d->res, XE_EUDEBUG_RES_TYPE_CLIENT, xef);
+	if (h_c < 0)
+		return h_c;
+
+	h_vm = find_handle(d->res, XE_EUDEBUG_RES_TYPE_VM, q->vm);
+	if (h_vm < 0)
+		return h_vm;
+
+	if (XE_WARN_ON(q->width >= XE_HW_ENGINE_MAX_INSTANCE))
+		return -EINVAL;
+
+	h_queue = xe_eudebug_remove_handle(d,
+					   XE_EUDEBUG_RES_TYPE_EXEC_QUEUE,
+					   q,
+					   &seqno);
+	if (h_queue <= 0)
+		return h_queue;
+
+	for (i = 0; i < q->width; i++) {
+		int ret;
+
+		ret = _xe_eudebug_remove_handle(d,
+						XE_EUDEBUG_RES_TYPE_LRC,
+						q->lrc[i],
+						NULL);
+		if (ret < 0 && ret != -ENOENT)
+			return ret;
+
+		XE_WARN_ON(!ret);
+
+		h_lrc[i] = ret;
+	}
+
+	return send_exec_queue_event(d, DRM_XE_EUDEBUG_EVENT_DESTROY,
+				     h_c, h_vm, h_queue, q->class,
+				     q->width, h_lrc, seqno);
+}
+
+void xe_eudebug_exec_queue_create(struct xe_file *xef, struct xe_exec_queue *q)
+{
+	struct xe_eudebug *d;
+
+	if (!exec_queue_class_is_tracked(q->class))
+		return;
+
+	d = xe_eudebug_get(xef);
+	if (!d)
+		return;
+
+	xe_eudebug_event_put(d, exec_queue_create_event(d, xef, q));
+}
+
+void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q)
+{
+	struct xe_eudebug *d;
+
+	if (!exec_queue_class_is_tracked(q->class))
+		return;
+
+	d = xe_eudebug_get(xef);
+	if (!d)
+		return;
+
+	xe_eudebug_event_put(d, exec_queue_destroy_event(d, xef, q));
+}
+
 static int discover_client(struct xe_eudebug *d, struct xe_file *xef)
 {
+	struct xe_exec_queue *q;
 	struct xe_vm *vm;
 	unsigned long i;
 	int err;
@@ -1175,6 +1351,15 @@ static int discover_client(struct xe_eudebug *d, struct xe_file *xef)
 			break;
 	}
 
+	xa_for_each(&xef->exec_queue.xa, i, q) {
+		if (!exec_queue_class_is_tracked(q->class))
+			continue;
+
+		err = exec_queue_create_event(d, xef, q);
+		if (err)
+			break;
+	}
+
 	return err;
 }
 
drivers/gpu/drm/xe/xe_eudebug.h +7 -0
index e3247365f72f..326ddbd50651 100644
@@ -10,6 +10,7 @@ struct drm_file;
 struct xe_device;
 struct xe_file;
 struct xe_vm;
+struct xe_exec_queue;
 
 #if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
 
@@ -26,6 +27,9 @@ void xe_eudebug_file_close(struct xe_file *xef);
 void xe_eudebug_vm_create(struct xe_file *xef, struct xe_vm *vm);
 void xe_eudebug_vm_destroy(struct xe_file *xef, struct xe_vm *vm);
 
+void xe_eudebug_exec_queue_create(struct xe_file *xef, struct xe_exec_queue *q);
+void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q);
+
 #else
 
 static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
@@ -41,6 +45,9 @@ static inline void xe_eudebug_file_close(struct xe_file *xef) { }
 static inline void xe_eudebug_vm_create(struct xe_file *xef, struct xe_vm *vm) { }
 static inline void xe_eudebug_vm_destroy(struct xe_file *xef, struct xe_vm *vm) { }
 
+static inline void xe_eudebug_exec_queue_create(struct xe_file *xef, struct xe_exec_queue *q) { }
+static inline void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q) { }
+
 #endif /* CONFIG_DRM_XE_EUDEBUG */
 
 #endif
drivers/gpu/drm/xe/xe_eudebug_types.h +30 -1
index 080a821db3e4..4824c4159036 100644
@@ -50,7 +50,9 @@ struct xe_eudebug_resource {
 
 #define XE_EUDEBUG_RES_TYPE_CLIENT	0
 #define XE_EUDEBUG_RES_TYPE_VM		1
-#define XE_EUDEBUG_RES_TYPE_COUNT	(XE_EUDEBUG_RES_TYPE_VM + 1)
+#define XE_EUDEBUG_RES_TYPE_EXEC_QUEUE	2
+#define XE_EUDEBUG_RES_TYPE_LRC		3
+#define XE_EUDEBUG_RES_TYPE_COUNT	(XE_EUDEBUG_RES_TYPE_LRC + 1)
 
 /**
  * struct xe_eudebug_resources - eudebug resources for all types
@@ -173,4 +175,31 @@ struct xe_eudebug_event_vm {
 	u64 vm_handle;
 };
 
+/**
+ * struct xe_eudebug_event_exec_queue - Internal event for
+ * exec_queue create/destroy
+ */
+struct xe_eudebug_event_exec_queue {
+	/** @base: base event */
+	struct xe_eudebug_event base;
+
+	/** @client_handle: client for the engine create/destroy */
+	u64 client_handle;
+
+	/** @vm_handle: vm handle for the engine create/destroy */
+	u64 vm_handle;
+
+	/** @exec_queue_handle: engine handle */
+	u64 exec_queue_handle;
+
+	/** @engine_handle: engine class */
+	u32 engine_class;
+
+	/** @width: submission width (number BB per exec) for this exec queue */
+	u32 width;
+
+	/** @lrc_handles: handles for each logical ring context created with this exec queue */
+	u64 lrc_handle[] __counted_by(width);
+};
+
 #endif
drivers/gpu/drm/xe/xe_exec_queue.c +5 -0
index aab9e561153d..7f5d8af778be 100644
@@ -23,6 +23,7 @@
 #include "xe_ring_ops_types.h"
 #include "xe_trace.h"
 #include "xe_vm.h"
+#include "xe_eudebug.h"
 
 enum xe_exec_queue_sched_prop {
 	XE_EXEC_QUEUE_JOB_TIMEOUT = 0,
@@ -654,6 +655,8 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
 
 	args->exec_queue_id = id;
 
+	xe_eudebug_exec_queue_create(xef, q);
+
 	return 0;
 
 kill_exec_queue:
@@ -840,6 +843,8 @@ int xe_exec_queue_destroy_ioctl(struct drm_device *dev, void *data,
 	if (q->vm && q->hwe->hw_engine_group)
 		xe_hw_engine_group_del_exec_queue(q->hwe->hw_engine_group, q);
 
+	xe_eudebug_exec_queue_destroy(xef, q);
+
 	xe_exec_queue_kill(q);
 
 	trace_xe_exec_queue_close(q);
include/uapi/drm/xe_drm_eudebug.h +12 -0
index acf6071c82bf..ac44e890152a 100644
@@ -26,6 +26,7 @@ struct drm_xe_eudebug_event {
 #define DRM_XE_EUDEBUG_EVENT_READ		1
 #define DRM_XE_EUDEBUG_EVENT_OPEN		2
 #define DRM_XE_EUDEBUG_EVENT_VM			3
+#define DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE		4
 
 	__u16 flags;
 #define DRM_XE_EUDEBUG_EVENT_CREATE		(1 << 0)
@@ -49,6 +50,17 @@ struct drm_xe_eudebug_event_vm {
 	__u64 vm_handle;
 };
 
+struct drm_xe_eudebug_event_exec_queue {
+	struct drm_xe_eudebug_event base;
+
+	__u64 client_handle;
+	__u64 vm_handle;
+	__u64 exec_queue_handle;
+	__u32 engine_class;
+	__u32 width;
+	__u64 lrc_handle[];
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#7 lore raw

PATCH 5/26 drm/xe/eudebug: Introduce exec queue placements event

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

This commit introduces the DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE_PLACEMENTS, which provides dbgUMD with information about the hw engines utilized during execution. The event is sent for every logical ring context (lrc) in scenarios involving parallel submission.

---
 drivers/gpu/drm/xe/xe_eudebug.c       | 99 ++++++++++++++++++++++++---
 drivers/gpu/drm/xe/xe_eudebug_types.h | 26 +++++++
 include/uapi/drm/xe_drm_eudebug.h     | 17 +++++
 3 files changed, 133 insertions(+), 9 deletions(-)
drivers/gpu/drm/xe/xe_eudebug.c +90 -9
index 3ca46ec838b9..cbcf7a72fdba 100644
@@ -717,7 +717,7 @@ static struct xe_eudebug_event *
 xe_eudebug_create_event(struct xe_eudebug *d, u16 type, u64 seqno, u16 flags,
 			u32 len)
 {
-	const u16 max_event = DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE;
+	const u16 max_event = DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE_PLACEMENTS;
 	const u16 known_flags =
 		DRM_XE_EUDEBUG_EVENT_CREATE |
 		DRM_XE_EUDEBUG_EVENT_DESTROY |
@@ -752,7 +752,7 @@ static long xe_eudebug_read_event(struct xe_eudebug *d,
 		u64_to_user_ptr(arg);
 	struct drm_xe_eudebug_event user_event;
 	struct xe_eudebug_event *event;
-	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE;
+	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE_PLACEMENTS;
 	long ret = 0;
 
 	if (XE_IOCTL_DBG(xe, copy_from_user(&user_event, user_orig, sizeof(user_event))))
@@ -1206,12 +1206,88 @@ static int send_exec_queue_event(struct xe_eudebug *d, u32 flags,
 	return xe_eudebug_queue_event(d, event);
 }
 
-static int exec_queue_create_event(struct xe_eudebug *d,
-				   struct xe_file *xef, struct xe_exec_queue *q)
+static int send_exec_queue_placements_event(struct xe_eudebug *d,
+					    u64 client_handle, u64 vm_handle,
+					    u64 exec_queue_handle, u64 lrc_handle,
+					    u32 num_placements, u64 *instances,
+					    u64 seqno)
+{
+	struct xe_eudebug_event_exec_queue_placements *e;
+	const u32 sz = struct_size(e, instances, num_placements);
+	struct xe_eudebug_event *event;
+
+	event = xe_eudebug_create_event(d,
+					DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE_PLACEMENTS,
+					seqno, DRM_XE_EUDEBUG_EVENT_CREATE, sz);
+	if (!event)
+		return -ENOMEM;
+
+	e = cast_event(e, event);
+
+	write_member(struct drm_xe_eudebug_event_exec_queue_placements, e, client_handle,
+		     client_handle);
+	write_member(struct drm_xe_eudebug_event_exec_queue_placements, e, vm_handle, vm_handle);
+	write_member(struct drm_xe_eudebug_event_exec_queue_placements, e, exec_queue_handle,
+		     exec_queue_handle);
+	write_member(struct drm_xe_eudebug_event_exec_queue_placements, e, lrc_handle, lrc_handle);
+	write_member(struct drm_xe_eudebug_event_exec_queue_placements, e, num_placements,
+		     num_placements);
+
+	memcpy(e->instances, instances, num_placements * sizeof(*instances));
+
+	return xe_eudebug_queue_event(d, event);
+}
+
+static int send_exec_queue_placements_events(struct xe_eudebug *d, struct xe_exec_queue *q,
+					     u64 client_handle, u64 vm_handle,
+					     u64 exec_queue_handle, u64 *lrc_handles)
+{
+
+	struct drm_xe_engine_class_instance eci[XE_HW_ENGINE_MAX_INSTANCE] = {};
+	unsigned long mask = q->logical_mask;
+	u32 num_placements = 0;
+	int ret, i, j;
+	u64 seqno;
+
+	for_each_set_bit(i, &mask, sizeof(q->logical_mask) * 8) {
+		if (XE_WARN_ON(num_placements == XE_HW_ENGINE_MAX_INSTANCE))
+			break;
+
+		eci[num_placements].engine_class = xe_to_user_engine_class[q->class];
+		eci[num_placements].engine_instance = i;
+		eci[num_placements++].gt_id = q->gt->info.id;
+	}
+
+	ret = 0;
+	for (i = 0; i < q->width; i++) {
+		seqno = atomic_long_inc_return(&d->events.seqno);
+
+		ret = send_exec_queue_placements_event(d, client_handle, vm_handle,
+						       exec_queue_handle, lrc_handles[i],
+						       num_placements, (u64 *)eci, seqno);
+		if (ret)
+			return ret;
+
+		/*
+		 * Parallel submissions must be logically contiguous,
+		 * so the next placement is just q->logical_mask >> 1
+		 */
+		for (j = 0; j < num_placements; j++) {
+			eci[j].engine_instance++;
+			XE_WARN_ON(eci[j].engine_instance >= XE_HW_ENGINE_MAX_INSTANCE);
+		}
+	}
+
+	return ret;
+}
+
+static int exec_queue_create_events(struct xe_eudebug *d,
+				    struct xe_file *xef, struct xe_exec_queue *q)
 {
 	int h_c, h_vm, h_queue;
 	u64 h_lrc[XE_HW_ENGINE_MAX_INSTANCE], seqno;
 	int i;
+	int ret = 0;
 
 	if (!xe_exec_queue_is_lr(q))
 		return 0;
@@ -1252,9 +1328,14 @@ static int exec_queue_create_event(struct xe_eudebug *d,
 	 * we disconnect
 	 */
 
-	return send_exec_queue_event(d, DRM_XE_EUDEBUG_EVENT_CREATE,
-				     h_c, h_vm, h_queue, q->class,
-				     q->width, h_lrc, seqno);
+	ret = send_exec_queue_event(d, DRM_XE_EUDEBUG_EVENT_CREATE,
+				  h_c, h_vm, h_queue, q->class,
+				  q->width, h_lrc, seqno);
+
+	if (ret)
+		return ret;
+
+	return send_exec_queue_placements_events(d, q, h_c, h_vm, h_queue, h_lrc);
 }
 
 static int exec_queue_destroy_event(struct xe_eudebug *d,
@@ -1317,7 +1398,7 @@ void xe_eudebug_exec_queue_create(struct xe_file *xef, struct xe_exec_queue *q)
 	if (!d)
 		return;
 
-	xe_eudebug_event_put(d, exec_queue_create_event(d, xef, q));
+	xe_eudebug_event_put(d, exec_queue_create_events(d, xef, q));
 }
 
 void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q)
@@ -1355,7 +1436,7 @@ static int discover_client(struct xe_eudebug *d, struct xe_file *xef)
 		if (!exec_queue_class_is_tracked(q->class))
 			continue;
 
-		err = exec_queue_create_event(d, xef, q);
+		err = exec_queue_create_events(d, xef, q);
 		if (err)
 			break;
 	}
drivers/gpu/drm/xe/xe_eudebug_types.h +26 -0
index 4824c4159036..bdffdfb1abff 100644
@@ -202,4 +202,30 @@ struct xe_eudebug_event_exec_queue {
 	u64 lrc_handle[] __counted_by(width);
 };
 
+struct xe_eudebug_event_exec_queue_placements {
+	/** @base: base event */
+	struct xe_eudebug_event base;
+
+	/** @client_handle: client for the engine create/destroy */
+	u64 client_handle;
+
+	/** @vm_handle: vm handle for the engine create/destroy */
+	u64 vm_handle;
+
+	/** @exec_queue_handle: engine handle */
+	u64 exec_queue_handle;
+
+	/** @engine_handle: engine class */
+	u64 lrc_handle;
+
+	/** @num_placements: all possible placements for given lrc */
+	u32 num_placements;
+
+	/** @pad: padding */
+	u32 pad;
+
+	/** @instances: num_placements sized array containing drm_xe_engine_class_instance*/
+	u64 instances[]; __counted_by(num_placements);
+};
+
 #endif
include/uapi/drm/xe_drm_eudebug.h +17 -0
index ac44e890152a..21690008a869 100644
@@ -27,6 +27,7 @@ struct drm_xe_eudebug_event {
 #define DRM_XE_EUDEBUG_EVENT_OPEN		2
 #define DRM_XE_EUDEBUG_EVENT_VM			3
 #define DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE		4
+#define DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE_PLACEMENTS 5
 
 	__u16 flags;
 #define DRM_XE_EUDEBUG_EVENT_CREATE		(1 << 0)
@@ -61,6 +62,22 @@ struct drm_xe_eudebug_event_exec_queue {
 	__u64 lrc_handle[];
 };
 
+struct drm_xe_eudebug_event_exec_queue_placements {
+	struct drm_xe_eudebug_event base;
+
+	__u64 client_handle;
+	__u64 vm_handle;
+	__u64 exec_queue_handle;
+	__u64 lrc_handle;
+	__u32 num_placements;
+	__u32 pad;
+	/**
+	 * @instances: user pointer to num_placements sized array of struct
+	 * drm_xe_engine_class_instance
+	 */
+	__u64 instances[];
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#8 lore raw

PATCH 6/26 drm/xe/eudebug: hw enablement for eudebug

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

In order to turn on debug capabilities, (i.e. breakpoints), TD_CTL and some other registers needs to be programmed. Implement eudebug mode enabling including eudebug related workarounds.

v2: Move workarounds to xe_wa_oob. Use reg_sr directly instead of xe_rtp as it suits better for dynamic manipulation of those register we do later in the series.
v3: get rid of undefining XE_MCR_REG (Mika)

---
 drivers/gpu/drm/xe/regs/xe_engine_regs.h |  4 ++
 drivers/gpu/drm/xe/regs/xe_gt_regs.h     | 10 +++++
 drivers/gpu/drm/xe/xe_eudebug.c          | 49 ++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_eudebug.h          |  3 ++
 drivers/gpu/drm/xe/xe_hw_engine.c        |  2 +
 drivers/gpu/drm/xe/xe_wa_oob.rules       |  2 +
 6 files changed, 70 insertions(+)
drivers/gpu/drm/xe/regs/xe_engine_regs.h +4 -0
index 7c78496e6213..e45c4d5378e5 100644
@@ -115,6 +115,10 @@
 
 #define INDIRECT_RING_STATE(base)		XE_REG((base) + 0x108)
 
+#define CS_DEBUG_MODE2(base)			XE_REG((base) + 0xd8, XE_REG_OPTION_MASKED)
+#define   INST_STATE_CACHE_INVALIDATE		REG_BIT(6)
+#define   GLOBAL_DEBUG_ENABLE			REG_BIT(5)
+
 #define RING_BBADDR(base)			XE_REG((base) + 0x140)
 #define RING_BBADDR_UDW(base)			XE_REG((base) + 0x168)
 
drivers/gpu/drm/xe/regs/xe_gt_regs.h +10 -0
index 162f18e975da..cd8c49a9000f 100644
@@ -455,6 +455,14 @@
 #define   DG2_DISABLE_ROUND_ENABLE_ALLOW_FOR_SSLA	REG_BIT(15)
 #define   CLEAR_OPTIMIZATION_DISABLE			REG_BIT(6)
 
+#define TD_CTL					XE_REG_MCR(0xe400)
+#define   TD_CTL_FEH_AND_FEE_ENABLE		REG_BIT(7) /* forced halt and exception */
+#define   TD_CTL_FORCE_EXTERNAL_HALT		REG_BIT(6)
+#define   TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE	REG_BIT(4)
+#define   TD_CTL_FORCE_EXCEPTION		REG_BIT(3)
+#define   TD_CTL_BREAKPOINT_ENABLE		REG_BIT(2)
+#define   TD_CTL_GLOBAL_DEBUG_ENABLE		REG_BIT(0) /* XeHP */
+
 #define CACHE_MODE_SS				XE_REG_MCR(0xe420, XE_REG_OPTION_MASKED)
 #define   DISABLE_ECC				REG_BIT(5)
 #define   ENABLE_PREFETCH_INTO_IC		REG_BIT(3)
@@ -481,11 +489,13 @@
 #define   MDQ_ARBITRATION_MODE			REG_BIT(12)
 #define   STALL_DOP_GATING_DISABLE		REG_BIT(5)
 #define   EARLY_EOT_DIS				REG_BIT(1)
+#define   STALL_DOP_GATING_DISABLE		REG_BIT(5)
 
 #define ROW_CHICKEN2				XE_REG_MCR(0xe4f4, XE_REG_OPTION_MASKED)
 #define   DISABLE_READ_SUPPRESSION		REG_BIT(15)
 #define   DISABLE_EARLY_READ			REG_BIT(14)
 #define   ENABLE_LARGE_GRF_MODE			REG_BIT(12)
+#define   XEHPC_DISABLE_BTB			REG_BIT(11)
 #define   PUSH_CONST_DEREF_HOLD_DIS		REG_BIT(8)
 #define   DISABLE_TDL_SVHS_GATING		REG_BIT(1)
 #define   DISABLE_DOP_GATING			REG_BIT(0)
drivers/gpu/drm/xe/xe_eudebug.c +49 -0

68 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug.h +3 -0
index 326ddbd50651..3cd6bc7bb682 100644
@@ -11,6 +11,7 @@ struct xe_device;
 struct xe_file;
 struct xe_vm;
 struct xe_exec_queue;
+struct xe_hw_engine;
 
 #if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
 
@@ -20,6 +21,7 @@ int xe_eudebug_connect_ioctl(struct drm_device *dev,
 
 void xe_eudebug_init(struct xe_device *xe);
 void xe_eudebug_fini(struct xe_device *xe);
+void xe_eudebug_init_hw_engine(struct xe_hw_engine *hwe);
 
 void xe_eudebug_file_open(struct xe_file *xef);
 void xe_eudebug_file_close(struct xe_file *xef);
@@ -38,6 +40,7 @@ static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
 
 static inline void xe_eudebug_init(struct xe_device *xe) { }
 static inline void xe_eudebug_fini(struct xe_device *xe) { }
+static inline void xe_eudebug_init_hw_engine(struct xe_hw_engine *hwe) { }
 
 static inline void xe_eudebug_file_open(struct xe_file *xef) { }
 static inline void xe_eudebug_file_close(struct xe_file *xef) { }
drivers/gpu/drm/xe/xe_hw_engine.c +2 -0
index c4b0dc3be39c..8a188ddc99f4 100644
@@ -16,6 +16,7 @@
 #include "xe_assert.h"
 #include "xe_bo.h"
 #include "xe_device.h"
+#include "xe_eudebug.h"
 #include "xe_execlist.h"
 #include "xe_force_wake.h"
 #include "xe_gsc.h"
@@ -558,6 +559,7 @@ static void hw_engine_init_early(struct xe_gt *gt, struct xe_hw_engine *hwe,
 	xe_tuning_process_engine(hwe);
 	xe_wa_process_engine(hwe);
 	hw_engine_setup_default_state(hwe);
+	xe_eudebug_init_hw_engine(hwe);
 
 	xe_reg_sr_init(&hwe->reg_whitelist, hwe->name, gt_to_xe(gt));
 	xe_reg_whitelist_process_engine(hwe);
drivers/gpu/drm/xe/xe_wa_oob.rules +2 -0
index 3ed12a85cc60..cc2f28663072 100644
@@ -42,3 +42,5 @@
 no_media_l3	MEDIA_VERSION(3000)
 14022866841	GRAPHICS_VERSION(3000), GRAPHICS_STEP(A0, B0)
 		MEDIA_VERSION(3000), MEDIA_STEP(A0, B0)
+18022722726	GRAPHICS_VERSION_RANGE(1250, 1274)
+14015474168	PLATFORM(PVC)
Signature · 1 line
2.43.0
#9 lore raw

PATCH 7/26 drm/xe: Add EUDEBUG_ENABLE exec queue property

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Introduce exec queue immutable property of eudebug with a flags as value to enable eudebug specific feature(s).

For now engine lrc will use this flag to set up runalone hw feature. Runalone is used to ensure that only one hw engine of group [rcs0, ccs0-3] is active on a tile.

Note: unlike the i915, xe allows user to set runalone also on devices with single render/compute engine. It should not make much difference, but leave control to the user.

v2: - check CONFIG_DRM_XE_EUDEBUG and LR mode (Matthew)
- disable preempt (Dominik)
- lrc_create remove from engine init

---
 drivers/gpu/drm/xe/xe_eudebug.c          |  4 +--
 drivers/gpu/drm/xe/xe_exec_queue.c       | 46 ++++++++++++++++++++++--
 drivers/gpu/drm/xe/xe_exec_queue.h       |  2 ++
 drivers/gpu/drm/xe/xe_exec_queue_types.h |  7 ++++
 drivers/gpu/drm/xe/xe_execlist.c         |  2 +-
 drivers/gpu/drm/xe/xe_lrc.c              | 16 +++++++--
 drivers/gpu/drm/xe/xe_lrc.h              |  4 ++-
 include/uapi/drm/xe_drm.h                |  3 +-
 8 files changed, 74 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -2
index fecb7c8a9779..4644d6846aae 100644
@@ -1338,7 +1338,7 @@ static int exec_queue_create_events(struct xe_eudebug *d,
 	int i;
 	int ret = 0;
 
-	if (!xe_exec_queue_is_lr(q))
+	if (!xe_exec_queue_is_debuggable(q))
 		return 0;
 
 	h_c = find_handle(d->res, XE_EUDEBUG_RES_TYPE_CLIENT, xef);
@@ -1395,7 +1395,7 @@ static int exec_queue_destroy_event(struct xe_eudebug *d,
 	u64 h_lrc[XE_HW_ENGINE_MAX_INSTANCE], seqno;
 	int i;
 
-	if (!xe_exec_queue_is_lr(q))
+	if (!xe_exec_queue_is_debuggable(q))
 		return 0;
 
 	h_c = find_handle(d->res, XE_EUDEBUG_RES_TYPE_CLIENT, xef);
drivers/gpu/drm/xe/xe_exec_queue.c +44 -2

77 lines not on this page · raw message

drivers/gpu/drm/xe/xe_exec_queue.h +2 -0
index 90c7f73eab88..421d8dc89814 100644
@@ -85,4 +85,6 @@ int xe_exec_queue_last_fence_test_dep(struct xe_exec_queue *q,
 				      struct xe_vm *vm);
 void xe_exec_queue_update_run_ticks(struct xe_exec_queue *q);
 
+int xe_exec_queue_is_debuggable(struct xe_exec_queue *q);
+
 #endif
drivers/gpu/drm/xe/xe_exec_queue_types.h +7 -0
index 1158b6062a6c..03f3ad235e4b 100644
@@ -90,6 +90,13 @@ struct xe_exec_queue {
 	 */
 	unsigned long flags;
 
+	/**
+	 * @eudebug_flags: immutable eudebug flags for this exec queue.
+	 * Set up with DRM_XE_EXEC_QUEUE_SET_PROPERTY_EUDEBUG.
+	 */
+#define EXEC_QUEUE_EUDEBUG_FLAG_ENABLE		BIT(0)
+	unsigned long eudebug_flags;
+
 	union {
 		/** @multi_gt_list: list head for VM bind engines if multi-GT */
 		struct list_head multi_gt_list;
drivers/gpu/drm/xe/xe_execlist.c +1 -1
index a8c416a48812..84b69a5dd361 100644
@@ -265,7 +265,7 @@ struct xe_execlist_port *xe_execlist_port_create(struct xe_device *xe,
 
 	port->hwe = hwe;
 
-	port->lrc = xe_lrc_create(hwe, NULL, SZ_16K);
+	port->lrc = xe_lrc_create(hwe, NULL, SZ_16K, 0);
 	if (IS_ERR(port->lrc)) {
 		err = PTR_ERR(port->lrc);
 		goto err;
drivers/gpu/drm/xe/xe_lrc.c +13 -3
index 22e58c6e2a35..4ff217ca5474 100644
@@ -876,7 +876,7 @@ static void xe_lrc_finish(struct xe_lrc *lrc)
 #define PVC_CTX_ACC_CTR_THOLD	(0x2a + 1)
 
 static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
-		       struct xe_vm *vm, u32 ring_size)
+		       struct xe_vm *vm, u32 ring_size, u32 flags)
 {
 	struct xe_gt *gt = hwe->gt;
 	struct xe_tile *tile = gt_to_tile(gt);
@@ -993,6 +993,16 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 	map = __xe_lrc_start_seqno_map(lrc);
 	xe_map_write32(lrc_to_xe(lrc), &map, lrc->fence_ctx.next_seqno - 1);
 
+	if (flags & LRC_CREATE_RUNALONE) {
+		u32 ctx_control = xe_lrc_read_ctx_reg(lrc, CTX_CONTEXT_CONTROL);
+
+		drm_dbg(&xe->drm, "read CTX_CONTEXT_CONTROL: 0x%x\n", ctx_control);
+		ctx_control |= _MASKED_BIT_ENABLE(CTX_CTRL_RUN_ALONE);
+		drm_dbg(&xe->drm, "written CTX_CONTEXT_CONTROL: 0x%x\n", ctx_control);
+
+		xe_lrc_write_ctx_reg(lrc, CTX_CONTEXT_CONTROL, ctx_control);
+	}
+
 	return 0;
 
 err_lrc_finish:
@@ -1012,7 +1022,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
  * upon failure.
  */
 struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
-			     u32 ring_size)
+			     u32 ring_size, u32 flags)
 {
 	struct xe_lrc *lrc;
 	int err;
@@ -1021,7 +1031,7 @@ struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
 	if (!lrc)
 		return ERR_PTR(-ENOMEM);
 
-	err = xe_lrc_init(lrc, hwe, vm, ring_size);
+	err = xe_lrc_init(lrc, hwe, vm, ring_size, flags);
 	if (err) {
 		kfree(lrc);
 		return ERR_PTR(err);
drivers/gpu/drm/xe/xe_lrc.h +3 -1
index b459dcab8787..3e5656752831 100644
@@ -41,8 +41,10 @@ struct xe_lrc_snapshot {
 
 #define LRC_PPHWSP_SCRATCH_ADDR (0x34 * 4)
 
+#define LRC_CREATE_RUNALONE	BIT(0)
+
 struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
-			     u32 ring_size);
+			     u32 ring_size, u32 flags);
 void xe_lrc_destroy(struct kref *ref);
 
 /**
include/uapi/drm/xe_drm.h +2 -1
index 78479100a0b6..d0b9ef0799b2 100644
@@ -1112,7 +1112,8 @@ struct drm_xe_exec_queue_create {
 #define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY		0
 #define   DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY		0
 #define   DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE		1
-
+#define   DRM_XE_EXEC_QUEUE_SET_PROPERTY_EUDEBUG		2
+#define     DRM_XE_EXEC_QUEUE_EUDEBUG_FLAG_ENABLE		(1 << 0)
 	/** @extensions: Pointer to the first extension struct, if any */
 	__u64 extensions;
 
Signature · 1 line
2.43.0
#10 lore raw

PATCH 8/26 drm/xe/eudebug: Introduce per device attention scan worker

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Scan for EU debugging attention bits periodically to detect if some EU thread has entered the system routine (SIP) due to EU thread exception.

Make the scanning interval 10 times slower when there is no debugger connection open. Send attention event whenever we see attention with debugger presence. If there is no debugger connection active - reset.

Based on work by authors and other folks who were part of attentions in i915.

v2: - use xa_array for files
- null ptr deref fix for non-debugged context (Dominik)
- checkpatch (Tilak)
- use discovery_lock during list traversal

v3: - engine status per gen improvements, force_wake ref
- __counted_by (Mika)

---
 drivers/gpu/drm/xe/Makefile              |   1 +
 drivers/gpu/drm/xe/regs/xe_engine_regs.h |   3 +
 drivers/gpu/drm/xe/regs/xe_gt_regs.h     |   7 +
 drivers/gpu/drm/xe/xe_device.c           |   2 +
 drivers/gpu/drm/xe/xe_device_types.h     |   3 +
 drivers/gpu/drm/xe/xe_eudebug.c          | 410 ++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug.h          |   2 +
 drivers/gpu/drm/xe/xe_eudebug_types.h    |  32 ++
 drivers/gpu/drm/xe/xe_gt_debug.c         | 148 ++++++++
 drivers/gpu/drm/xe/xe_gt_debug.h         |  21 ++
 include/uapi/drm/xe_drm_eudebug.h        |  13 +
 11 files changed, 640 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_gt_debug.c
 create mode 100644 drivers/gpu/drm/xe/xe_gt_debug.h
drivers/gpu/drm/xe/Makefile +1 -0
index deabcdd3ea52..33f457e4fcd3 100644
@@ -48,6 +48,7 @@ xe-y += xe_bb.o \
 	xe_gt_clock.o \
 	xe_gt_freq.o \
 	xe_gt_idle.o \
+	xe_gt_debug.o \
 	xe_gt_mcr.o \
 	xe_gt_pagefault.o \
 	xe_gt_sysfs.o \
drivers/gpu/drm/xe/regs/xe_engine_regs.h +3 -0
index e45c4d5378e5..83b26cb174d6 100644
@@ -133,6 +133,9 @@
 #define RING_EXECLIST_STATUS_LO(base)		XE_REG((base) + 0x234)
 #define RING_EXECLIST_STATUS_HI(base)		XE_REG((base) + 0x234 + 4)
 
+#define RING_CURRENT_LRCA(base)			XE_REG((base) + 0x240)
+#define   CURRENT_LRCA_VALID			REG_BIT(0)
+
 #define RING_CONTEXT_CONTROL(base)		XE_REG((base) + 0x244, XE_REG_OPTION_MASKED)
 #define	  CTX_CTRL_OAC_CONTEXT_ENABLE		REG_BIT(8)
 #define	  CTX_CTRL_RUN_ALONE			REG_BIT(7)
drivers/gpu/drm/xe/regs/xe_gt_regs.h +7 -0
index cd8c49a9000f..a20331b6c20e 100644
@@ -467,6 +467,8 @@
 #define   DISABLE_ECC				REG_BIT(5)
 #define   ENABLE_PREFETCH_INTO_IC		REG_BIT(3)
 
+#define TD_ATT(x)				XE_REG_MCR(0xe470 + (x) * 4)
+
 #define ROW_CHICKEN4				XE_REG_MCR(0xe48c, XE_REG_OPTION_MASKED)
 #define   DISABLE_GRF_CLEAR			REG_BIT(13)
 #define   XEHP_DIS_BBL_SYSPIPE			REG_BIT(11)
@@ -547,6 +549,11 @@
 #define   CCS_MODE_CSLICE(cslice, ccs) \
 	((ccs) << ((cslice) * CCS_MODE_CSLICE_WIDTH))
 
+#define RCU_DEBUG_1				XE_REG(0x14a00)
+#define   RCU_DEBUG_1_ENGINE_STATUS		REG_GENMASK(2, 0)
+#define   RCU_DEBUG_1_RUNALONE_ACTIVE		REG_BIT(2)
+#define   RCU_DEBUG_1_CONTEXT_ACTIVE		REG_BIT(0)
+
 #define FORCEWAKE_ACK_GT			XE_REG(0x130044)
 
 /* Applicable for all FORCEWAKE_DOMAIN and FORCEWAKE_ACK_DOMAIN regs */
drivers/gpu/drm/xe/xe_device.c +2 -0
index f051612908de..dc0336215912 100644
@@ -777,6 +777,8 @@ int xe_device_probe(struct xe_device *xe)
 
 	xe_debugfs_register(xe);
 
+	xe_eudebug_init_late(xe);
+
 	xe_hwmon_register(xe);
 
 	for_each_gt(gt, xe, id)
drivers/gpu/drm/xe/xe_device_types.h +3 -0
index 9941ea1400c6..7b893a86d83f 100644
@@ -556,6 +556,9 @@ struct xe_device {
 
 		/** discovery_lock: used for discovery to block xe ioctls */
 		struct rw_semaphore discovery_lock;
+
+		/** @attention_scan: attention scan worker */
+		struct delayed_work attention_scan;
 	} eudebug;
 #endif
 
drivers/gpu/drm/xe/xe_eudebug.c +408 -2

462 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug.h +2 -0
index 3cd6bc7bb682..1fe86bec99e1 100644
@@ -20,6 +20,7 @@ int xe_eudebug_connect_ioctl(struct drm_device *dev,
 			     struct drm_file *file);
 
 void xe_eudebug_init(struct xe_device *xe);
+void xe_eudebug_init_late(struct xe_device *xe);
 void xe_eudebug_fini(struct xe_device *xe);
 void xe_eudebug_init_hw_engine(struct xe_hw_engine *hwe);
 
@@ -39,6 +40,7 @@ static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
 					   struct drm_file *file) { return 0; }
 
 static inline void xe_eudebug_init(struct xe_device *xe) { }
+static inline void xe_eudebug_init_late(struct xe_device *xe) { }
 static inline void xe_eudebug_fini(struct xe_device *xe) { }
 static inline void xe_eudebug_init_hw_engine(struct xe_hw_engine *hwe) { }
 
drivers/gpu/drm/xe/xe_eudebug_types.h +32 -0
index bdffdfb1abff..410b3ecccc12 100644
@@ -105,6 +105,9 @@ struct xe_eudebug {
 	/** @discovery_work: worker to discover resources for target_task */
 	struct work_struct discovery_work;
 
+	/** eu_lock: guards operations on eus (eu thread control and attention) */
+	struct mutex eu_lock;
+
 	/** @events: kfifo queue of to-be-delivered events */
 	struct {
 		/** @lock: guards access to fifo */
@@ -228,4 +231,33 @@ struct xe_eudebug_event_exec_queue_placements {
 	u64 instances[]; __counted_by(num_placements);
 };
 
+/**
+ * struct xe_eudebug_event_eu_attention - Internal event for EU attention
+ */
+struct xe_eudebug_event_eu_attention {
+	/** @base: base event */
+	struct xe_eudebug_event base;
+
+	/** @client_handle: client for the attention */
+	u64 client_handle;
+
+	/** @exec_queue_handle: handle of exec_queue which raised attention */
+	u64 exec_queue_handle;
+
+	/** @lrc_handle: lrc handle of the workload which raised attention */
+	u64 lrc_handle;
+
+	/** @flags: eu attention event flags, currently MBZ */
+	u32 flags;
+
+	/** @bitmask_size: size of the bitmask, specific to device */
+	u32 bitmask_size;
+
+	/**
+	 * @bitmask: reflects threads currently signalling attention,
+	 * starting from natural hardware order of DSS=0, eu=0
+	 */
+	u8 bitmask[] __counted_by(bitmask_size);
+};
+
 #endif
drivers/gpu/drm/xe/xe_gt_debug.c new file +148 -0

148 lines not on this page · raw message

drivers/gpu/drm/xe/xe_gt_debug.h new file +21 -0
new file mode 100644
index 000000000000..3f13dbb17a5f
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef __XE_GT_DEBUG_
+#define __XE_GT_DEBUG_
+
+#define TD_EU_ATTENTION_MAX_ROWS 2u
+
+#include "xe_gt_types.h"
+
+#define XE_GT_ATTENTION_TIMEOUT_MS 100
+
+int xe_gt_eu_threads_needing_attention(struct xe_gt *gt);
+
+int xe_gt_eu_attention_bitmap_size(struct xe_gt *gt);
+int xe_gt_eu_attention_bitmap(struct xe_gt *gt, u8 *bits,
+			      unsigned int bitmap_size);
+
+#endif
include/uapi/drm/xe_drm_eudebug.h +13 -0
index 21690008a869..144c7cf888bb 100644
@@ -28,12 +28,14 @@ struct drm_xe_eudebug_event {
 #define DRM_XE_EUDEBUG_EVENT_VM			3
 #define DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE		4
 #define DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE_PLACEMENTS 5
+#define DRM_XE_EUDEBUG_EVENT_EU_ATTENTION	6
 
 	__u16 flags;
 #define DRM_XE_EUDEBUG_EVENT_CREATE		(1 << 0)
 #define DRM_XE_EUDEBUG_EVENT_DESTROY		(1 << 1)
 #define DRM_XE_EUDEBUG_EVENT_STATE_CHANGE	(1 << 2)
 #define DRM_XE_EUDEBUG_EVENT_NEED_ACK		(1 << 3)
+
 	__u64 seqno;
 	__u64 reserved;
 };
@@ -78,6 +80,17 @@ struct drm_xe_eudebug_event_exec_queue_placements {
 	__u64 instances[];
 };
 
+struct drm_xe_eudebug_event_eu_attention {
+	struct drm_xe_eudebug_event base;
+
+	__u64 client_handle;
+	__u64 exec_queue_handle;
+	__u64 lrc_handle;
+	__u32 flags;
+	__u32 bitmask_size;
+	__u8 bitmask[];
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#11 lore raw

PATCH 9/26 drm/xe/eudebug: Introduce EU control interface

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Introduce EU control functionality, which allows EU debugger to interrupt, resume, and inform about the current state of EU threads during execution. Provide an abstraction layer, so in the future guc will only need to provide appropriate callbacks.

Based on implementation created by authors and other folks within i915 driver.

v2: - checkpatch (Maciej)
- lrc index off by one fix (Mika)
- checkpatch (Tilak)
- 32bit fixes (Andrzej, Mika)
- find_resource_get for client (Mika)

v3: - fw ref (Mika)

---
 drivers/gpu/drm/xe/regs/xe_gt_regs.h  |   2 +
 drivers/gpu/drm/xe/xe_eudebug.c       | 515 +++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug_types.h |  24 ++
 drivers/gpu/drm/xe/xe_gt_debug.c      |  12 +-
 drivers/gpu/drm/xe/xe_gt_debug.h      |   6 +
 include/uapi/drm/xe_drm_eudebug.h     |  21 +-
 6 files changed, 560 insertions(+), 20 deletions(-)
drivers/gpu/drm/xe/regs/xe_gt_regs.h +2 -0
index a20331b6c20e..5fcf06835ef0 100644
@@ -478,6 +478,8 @@
 #define   THREAD_EX_ARB_MODE			REG_GENMASK(3, 2)
 #define   THREAD_EX_ARB_MODE_RR_AFTER_DEP	REG_FIELD_PREP(THREAD_EX_ARB_MODE, 0x2)
 
+#define TD_CLR(i)				XE_REG_MCR(0xe490 + (i) * 4)
+
 #define ROW_CHICKEN3				XE_REG_MCR(0xe49c, XE_REG_OPTION_MASKED)
 #define   XE2_EUPEND_CHK_FLUSH_DIS		REG_BIT(14)
 #define   DIS_FIX_EOT1_FLUSH			REG_BIT(9)
drivers/gpu/drm/xe/xe_eudebug.c +502 -13

588 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug_types.h +24 -0
index 410b3ecccc12..e1d4e31b32ec 100644
@@ -18,8 +18,12 @@
 
 struct xe_device;
 struct task_struct;
+struct xe_eudebug;
 struct xe_eudebug_event;
+struct xe_hw_engine;
 struct workqueue_struct;
+struct xe_exec_queue;
+struct xe_lrc;
 
 #define CONFIG_DRM_XE_DEBUGGER_EVENT_QUEUE_SIZE 64
 
@@ -65,6 +69,24 @@ struct xe_eudebug_resources {
 	struct xe_eudebug_resource rt[XE_EUDEBUG_RES_TYPE_COUNT];
 };
 
+/**
+ * struct xe_eudebug_eu_control_ops - interface for eu thread
+ * state control backend
+ */
+struct xe_eudebug_eu_control_ops {
+	/** @interrupt_all: interrupts workload active on given hwe */
+	int (*interrupt_all)(struct xe_eudebug *e, struct xe_exec_queue *q,
+			     struct xe_lrc *lrc);
+
+	/** @resume: resumes threads reflected by bitmask active on given hwe */
+	int (*resume)(struct xe_eudebug *e, struct xe_exec_queue *q,
+		      struct xe_lrc *lrc, u8 *bitmap, unsigned int bitmap_size);
+
+	/** @stopped: returns bitmap reflecting threads which signal attention */
+	int (*stopped)(struct xe_eudebug *e, struct xe_exec_queue *q,
+		       struct xe_lrc *lrc, u8 *bitmap, unsigned int bitmap_size);
+};
+
 /**
  * struct xe_eudebug - Top level struct for eudebug: the connection
  */
@@ -128,6 +150,8 @@ struct xe_eudebug {
 		atomic_long_t seqno;
 	} events;
 
+	/** @ops operations for eu_control */
+	struct xe_eudebug_eu_control_ops *ops;
 };
 
 /**
drivers/gpu/drm/xe/xe_gt_debug.c +6 -6
index c4f0d11a20a6..f35b9df5e41b 100644
@@ -13,12 +13,12 @@
 #include "xe_pm.h"
 #include "xe_macros.h"
 
-static int xe_gt_foreach_dss_group_instance(struct xe_gt *gt,
-					    int (*fn)(struct xe_gt *gt,
-						      void *data,
-						      u16 group,
-						      u16 instance),
-					    void *data)
+int xe_gt_foreach_dss_group_instance(struct xe_gt *gt,
+				     int (*fn)(struct xe_gt *gt,
+					       void *data,
+					       u16 group,
+					       u16 instance),
+				     void *data)
 {
 	const enum xe_force_wake_domains fw_domains = XE_FW_GT;
 	unsigned int dss, fw_ref;
drivers/gpu/drm/xe/xe_gt_debug.h +6 -0
index 3f13dbb17a5f..342082699ff6 100644
@@ -13,6 +13,12 @@
 #define XE_GT_ATTENTION_TIMEOUT_MS 100
 
 int xe_gt_eu_threads_needing_attention(struct xe_gt *gt);
+int xe_gt_foreach_dss_group_instance(struct xe_gt *gt,
+				     int (*fn)(struct xe_gt *gt,
+					       void *data,
+					       u16 group,
+					       u16 instance),
+				     void *data);
 
 int xe_gt_eu_attention_bitmap_size(struct xe_gt *gt);
 int xe_gt_eu_attention_bitmap(struct xe_gt *gt, u8 *bits,
include/uapi/drm/xe_drm_eudebug.h +20 -1
index 144c7cf888bb..ccfbe976c509 100644
@@ -15,7 +15,8 @@ extern "C" {
  *
  * This ioctl is available in debug version 1.
  */
-#define DRM_XE_EUDEBUG_IOCTL_READ_EVENT _IO('j', 0x0)
+#define DRM_XE_EUDEBUG_IOCTL_READ_EVENT		_IO('j', 0x0)
+#define DRM_XE_EUDEBUG_IOCTL_EU_CONTROL		_IOWR('j', 0x2, struct drm_xe_eudebug_eu_control)
 
 /* XXX: Document events to match their internal counterparts when moved to xe_drm.h */
 struct drm_xe_eudebug_event {
@@ -91,6 +92,24 @@ struct drm_xe_eudebug_event_eu_attention {
 	__u8 bitmask[];
 };
 
+struct drm_xe_eudebug_eu_control {
+	__u64 client_handle;
+
+#define DRM_XE_EUDEBUG_EU_CONTROL_CMD_INTERRUPT_ALL	0
+#define DRM_XE_EUDEBUG_EU_CONTROL_CMD_STOPPED		1
+#define DRM_XE_EUDEBUG_EU_CONTROL_CMD_RESUME		2
+	__u32 cmd;
+	__u32 flags;
+
+	__u64 seqno;
+
+	__u64 exec_queue_handle;
+	__u64 lrc_handle;
+	__u32 reserved;
+	__u32 bitmask_size;
+	__u64 bitmask_ptr;
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#12 lore raw

PATCH 10/26 drm/xe/eudebug: Add vm bind and vm bind ops

In reply to Mika Kuoppala

From: Christoph Manszewski <[email protected]>

Add events dedicated to track vma bind and vma unbind operations. The events are generated for operations performed on xe_vma MAP and UNMAP for boss and userptrs.

As one bind can result in multiple operations and fail in the middle, we want to store the events until full successful chain of operations can be relayed to debugger.

---
 drivers/gpu/drm/xe/xe_eudebug.c       | 318 +++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug.h       |  13 ++
 drivers/gpu/drm/xe/xe_eudebug_types.h |  29 +++
 drivers/gpu/drm/xe/xe_vm.c            |  16 +-
 drivers/gpu/drm/xe/xe_vm_types.h      |  13 ++
 include/uapi/drm/xe_drm_eudebug.h     |  64 ++++++
 6 files changed, 449 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_eudebug.c +316 -2
index 81d03a860b7f..f544f60d7d6b 100644
@@ -792,7 +792,7 @@ static struct xe_eudebug_event *
 xe_eudebug_create_event(struct xe_eudebug *d, u16 type, u64 seqno, u16 flags,
 			u32 len)
 {
-	const u16 max_event = DRM_XE_EUDEBUG_EVENT_EU_ATTENTION;
+	const u16 max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_OP;
 	const u16 known_flags =
 		DRM_XE_EUDEBUG_EVENT_CREATE |
 		DRM_XE_EUDEBUG_EVENT_DESTROY |
@@ -827,7 +827,7 @@ static long xe_eudebug_read_event(struct xe_eudebug *d,
 		u64_to_user_ptr(arg);
 	struct drm_xe_eudebug_event user_event;
 	struct xe_eudebug_event *event;
-	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_EU_ATTENTION;
+	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_OP;
 	long ret = 0;
 
 	if (XE_IOCTL_DBG(xe, copy_from_user(&user_event, user_orig, sizeof(user_event))))
@@ -2359,6 +2359,320 @@ void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q)
 	xe_eudebug_event_put(d, exec_queue_destroy_event(d, xef, q));
 }
 
+static int xe_eudebug_queue_bind_event(struct xe_eudebug *d,
+				       struct xe_vm *vm,
+				       struct xe_eudebug_event *event)
+{
+	struct xe_eudebug_event_envelope *env;
+
+	lockdep_assert_held_write(&vm->lock);
+
+	env = kmalloc(sizeof(*env), GFP_KERNEL);
+	if (!env)
+		return -ENOMEM;
+
+	INIT_LIST_HEAD(&env->link);
+	env->event = event;
+
+	spin_lock(&vm->eudebug.lock);
+	list_add_tail(&env->link, &vm->eudebug.events);
+
+	if (event->type == DRM_XE_EUDEBUG_EVENT_VM_BIND_OP)
+		++vm->eudebug.ops;
+	spin_unlock(&vm->eudebug.lock);
+
+	return 0;
+}
+
+static int queue_vm_bind_event(struct xe_eudebug *d,
+			       struct xe_vm *vm,
+			       u64 client_handle,
+			       u64 vm_handle,
+			       u32 bind_flags,
+			       u32 num_ops, u64 *seqno)
+{
+	struct xe_eudebug_event_vm_bind *e;
+	struct xe_eudebug_event *event;
+	const u32 sz = sizeof(*e);
+	const u32 base_flags = DRM_XE_EUDEBUG_EVENT_STATE_CHANGE;
+
+	*seqno = atomic_long_inc_return(&d->events.seqno);
+
+	event = xe_eudebug_create_event(d, DRM_XE_EUDEBUG_EVENT_VM_BIND,
+					*seqno, base_flags, sz);
+	if (!event)
+		return -ENOMEM;
+
+	e = cast_event(e, event);
+	write_member(struct drm_xe_eudebug_event_vm_bind, e, client_handle, client_handle);
+	write_member(struct drm_xe_eudebug_event_vm_bind, e, vm_handle, vm_handle);
+	write_member(struct drm_xe_eudebug_event_vm_bind, e, flags, bind_flags);
+	write_member(struct drm_xe_eudebug_event_vm_bind, e, num_binds, num_ops);
+
+	/* If in discovery, no need to collect ops */
+	if (!completion_done(&d->discovery)) {
+		XE_WARN_ON(!num_ops);
+		return xe_eudebug_queue_event(d, event);
+	}
+
+	return xe_eudebug_queue_bind_event(d, vm, event);
+}
+
+static int vm_bind_event(struct xe_eudebug *d,
+			 struct xe_vm *vm,
+			 u32 num_ops,
+			 u64 *seqno)
+{
+	int h_c, h_vm;
+
+	h_c = find_handle(d->res, XE_EUDEBUG_RES_TYPE_CLIENT, vm->xef);
+	if (h_c < 0)
+		return h_c;
+
+	h_vm = find_handle(d->res, XE_EUDEBUG_RES_TYPE_VM, vm);
+	if (h_vm < 0)
+		return h_vm;
+
+	return queue_vm_bind_event(d, vm, h_c, h_vm, 0,
+				   num_ops, seqno);
+}
+
+static int vm_bind_op_event(struct xe_eudebug *d,
+			    struct xe_vm *vm,
+			    const u32 flags,
+			    const u64 bind_ref_seqno,
+			    const u64 num_extensions,
+			    u64 addr, u64 range,
+			    u64 *op_seqno)
+{
+	struct xe_eudebug_event_vm_bind_op *e;
+	struct xe_eudebug_event *event;
+	const u32 sz = sizeof(*e);
+
+	*op_seqno = atomic_long_inc_return(&d->events.seqno);
+
+	event = xe_eudebug_create_event(d, DRM_XE_EUDEBUG_EVENT_VM_BIND_OP,
+					*op_seqno, flags, sz);
+	if (!event)
+		return -ENOMEM;
+
+	e = cast_event(e, event);
+
+	write_member(struct drm_xe_eudebug_event_vm_bind_op, e, vm_bind_ref_seqno, bind_ref_seqno);
+	write_member(struct drm_xe_eudebug_event_vm_bind_op, e, num_extensions, num_extensions);
+	write_member(struct drm_xe_eudebug_event_vm_bind_op, e, addr, addr);
+	write_member(struct drm_xe_eudebug_event_vm_bind_op, e, range, range);
+
+	/* If in discovery, no need to collect ops */
+	if (!completion_done(&d->discovery))
+		return xe_eudebug_queue_event(d, event);
+
+	return xe_eudebug_queue_bind_event(d, vm, event);
+}
+
+static int vm_bind_op(struct xe_eudebug *d, struct xe_vm *vm,
+		      const u32 flags, const u64 bind_ref_seqno,
+		      u64 addr, u64 range)
+{
+	u64 op_seqno = 0;
+	u64 num_extensions = 0;
+	int ret;
+
+	ret = vm_bind_op_event(d, vm, flags, bind_ref_seqno, num_extensions,
+			       addr, range, &op_seqno);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+void xe_eudebug_vm_init(struct xe_vm *vm)
+{
+	INIT_LIST_HEAD(&vm->eudebug.events);
+	spin_lock_init(&vm->eudebug.lock);
+	vm->eudebug.ops = 0;
+	vm->eudebug.ref_seqno = 0;
+}
+
+void xe_eudebug_vm_bind_start(struct xe_vm *vm)
+{
+	struct xe_eudebug *d;
+	u64 seqno = 0;
+	int err;
+
+	if (!xe_vm_in_lr_mode(vm))
+		return;
+
+	d = xe_eudebug_get(vm->xef);
+	if (!d)
+		return;
+
+	lockdep_assert_held_write(&vm->lock);
+
+	if (XE_WARN_ON(!list_empty(&vm->eudebug.events)) ||
+	    XE_WARN_ON(vm->eudebug.ops) ||
+	    XE_WARN_ON(vm->eudebug.ref_seqno)) {
+		eu_err(d, "bind busy on %s",  __func__);
+		xe_eudebug_disconnect(d, -EINVAL);
+	}
+
+	err = vm_bind_event(d, vm, 0, &seqno);
+	if (err) {
+		eu_err(d, "error %d on %s", err, __func__);
+		xe_eudebug_disconnect(d, err);
+	}
+
+	spin_lock(&vm->eudebug.lock);
+	XE_WARN_ON(vm->eudebug.ref_seqno);
+	vm->eudebug.ref_seqno = seqno;
+	vm->eudebug.ops = 0;
+	spin_unlock(&vm->eudebug.lock);
+
+	xe_eudebug_put(d);
+}
+
+void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range)
+{
+	struct xe_eudebug *d;
+	u32 flags;
+
+	if (!xe_vm_in_lr_mode(vm))
+		return;
+
+	switch (op) {
+	case DRM_XE_VM_BIND_OP_MAP:
+	case DRM_XE_VM_BIND_OP_MAP_USERPTR:
+	{
+		flags = DRM_XE_EUDEBUG_EVENT_CREATE;
+		break;
+	}
+	case DRM_XE_VM_BIND_OP_UNMAP:
+	case DRM_XE_VM_BIND_OP_UNMAP_ALL:
+		flags = DRM_XE_EUDEBUG_EVENT_DESTROY;
+		break;
+	default:
+		flags = 0;
+		break;
+	}
+
+	if (!flags)
+		return;
+
+	d = xe_eudebug_get(vm->xef);
+	if (!d)
+		return;
+
+	xe_eudebug_event_put(d, vm_bind_op(d, vm, flags, 0, addr, range));
+}
+
+static struct xe_eudebug_event *fetch_bind_event(struct xe_vm * const vm)
+{
+	struct xe_eudebug_event_envelope *env;
+	struct xe_eudebug_event *e = NULL;
+
+	spin_lock(&vm->eudebug.lock);
+	env = list_first_entry_or_null(&vm->eudebug.events,
+				       struct xe_eudebug_event_envelope, link);
+	if (env) {
+		e = env->event;
+		list_del(&env->link);
+	}
+	spin_unlock(&vm->eudebug.lock);
+
+	kfree(env);
+
+	return e;
+}
+
+static void fill_vm_bind_fields(struct xe_vm *vm,
+				struct xe_eudebug_event *e,
+				bool ufence,
+				u32 bind_ops)
+{
+	struct xe_eudebug_event_vm_bind *eb = cast_event(eb, e);
+
+	eb->flags = ufence ?
+		DRM_XE_EUDEBUG_EVENT_VM_BIND_FLAG_UFENCE : 0;
+	eb->num_binds = bind_ops;
+}
+
+static void fill_vm_bind_op_fields(struct xe_vm *vm,
+				   struct xe_eudebug_event *e,
+				   u64 ref_seqno)
+{
+	struct xe_eudebug_event_vm_bind_op *op;
+
+	if (e->type != DRM_XE_EUDEBUG_EVENT_VM_BIND_OP)
+		return;
+
+	op = cast_event(op, e);
+	op->vm_bind_ref_seqno = ref_seqno;
+}
+
+void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int bind_err)
+{
+	struct xe_eudebug_event *e;
+	struct xe_eudebug *d;
+	u32 bind_ops;
+	u64 ref;
+
+	if (!xe_vm_in_lr_mode(vm))
+		return;
+
+	spin_lock(&vm->eudebug.lock);
+	ref = vm->eudebug.ref_seqno;
+	vm->eudebug.ref_seqno = 0;
+	bind_ops = vm->eudebug.ops;
+	vm->eudebug.ops = 0;
+	spin_unlock(&vm->eudebug.lock);
+
+	e = fetch_bind_event(vm);
+	if (!e)
+		return;
+
+	d = NULL;
+	if (!bind_err && ref) {
+		d = xe_eudebug_get(vm->xef);
+		if (d) {
+			if (bind_ops) {
+				fill_vm_bind_fields(vm, e, has_ufence, bind_ops);
+			} else {
+				/*
+				 * If there was no ops we are interested in,
+				 * we can omit the whole sequence
+				 */
+				xe_eudebug_put(d);
+				d = NULL;
+			}
+		}
+	}
+
+	while (e) {
+		int err = 0;
+
+		if (d) {
+			err = xe_eudebug_queue_event(d, e);
+			if (!err)
+				e = NULL;
+		}
+
+		if (err) {
+			xe_eudebug_disconnect(d, err);
+			xe_eudebug_put(d);
+			d = NULL;
+		}
+
+		kfree(e);
+
+		e = fetch_bind_event(vm);
+		if (e && ref)
+			fill_vm_bind_op_fields(vm, e, ref);
+	}
+
+	if (d)
+		xe_eudebug_put(d);
+}
+
 static int discover_client(struct xe_eudebug *d, struct xe_file *xef)
 {
 	struct xe_exec_queue *q;
drivers/gpu/drm/xe/xe_eudebug.h +13 -0
index 1fe86bec99e1..ccc7202b3308 100644
@@ -5,11 +5,14 @@
 
 #ifndef _XE_EUDEBUG_H_
 
+#include <linux/types.h>
+
 struct drm_device;
 struct drm_file;
 struct xe_device;
 struct xe_file;
 struct xe_vm;
+struct xe_vma;
 struct xe_exec_queue;
 struct xe_hw_engine;
 
@@ -33,6 +36,11 @@ void xe_eudebug_vm_destroy(struct xe_file *xef, struct xe_vm *vm);
 void xe_eudebug_exec_queue_create(struct xe_file *xef, struct xe_exec_queue *q);
 void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q);
 
+void xe_eudebug_vm_init(struct xe_vm *vm);
+void xe_eudebug_vm_bind_start(struct xe_vm *vm);
+void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range);
+void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int err);
+
 #else
 
 static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
@@ -53,6 +61,11 @@ static inline void xe_eudebug_vm_destroy(struct xe_file *xef, struct xe_vm *vm)
 static inline void xe_eudebug_exec_queue_create(struct xe_file *xef, struct xe_exec_queue *q) { }
 static inline void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q) { }
 
+static inline void xe_eudebug_vm_init(struct xe_vm *vm) { }
+static inline void xe_eudebug_vm_bind_start(struct xe_vm *vm) { }
+static inline void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range) { }
+static inline void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int err) { }
+
 #endif /* CONFIG_DRM_XE_EUDEBUG */
 
 #endif
drivers/gpu/drm/xe/xe_eudebug_types.h +29 -0
index e1d4e31b32ec..cbc316ec3593 100644
@@ -177,6 +177,11 @@ struct xe_eudebug_event {
 	u8 data[];
 };
 
+struct xe_eudebug_event_envelope {
+	struct list_head link;
+	struct xe_eudebug_event *event;
+};
+
 /**
  * struct xe_eudebug_event_open - Internal event for client open/close
  */
@@ -284,4 +289,28 @@ struct xe_eudebug_event_eu_attention {
 	u8 bitmask[] __counted_by(bitmask_size);
 };
 
+/**
+ * struct xe_eudebug_event_vm_bind - Internal event for vm bind/unbind operation
+ */
+struct xe_eudebug_event_vm_bind {
+	/** @base: base event */
+	struct xe_eudebug_event base;
+
+	u64 client_handle;
+	u64 vm_handle;
+
+	u32 flags;
+	u32 num_binds;
+};
+
+struct xe_eudebug_event_vm_bind_op {
+	/** @base: base event */
+	struct xe_eudebug_event base;
+	u64 vm_bind_ref_seqno;
+	u64 num_extensions;
+
+	u64 addr; /* Zero for unmap all ? */
+	u64 range; /* Zero for unmap all ? */
+};
+
 #endif
drivers/gpu/drm/xe/xe_vm.c +14 -2
index 6f16049f4f6e..e83420473763 100644
@@ -1413,6 +1413,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
 	for_each_tile(tile, xe, id)
 		xe_range_fence_tree_init(&vm->rftree[id]);
 
+	xe_eudebug_vm_init(vm);
+
 	vm->pt_ops = &xelp_pt_ops;
 
 	/*
@@ -1641,6 +1643,8 @@ static void vm_destroy_work_func(struct work_struct *w)
 	struct xe_tile *tile;
 	u8 id;
 
+	xe_eudebug_vm_bind_end(vm, 0, -ENOENT);
+
 	/* xe_vm_close_and_put was not called? */
 	xe_assert(xe, !vm->size);
 
@@ -2651,7 +2655,7 @@ static void vm_bind_ioctl_ops_fini(struct xe_vm *vm, struct xe_vma_ops *vops,
 				   struct dma_fence *fence)
 {
 	struct xe_exec_queue *wait_exec_queue = to_wait_exec_queue(vm, vops->q);
-	struct xe_user_fence *ufence;
+	struct xe_user_fence *ufence = NULL;
 	struct xe_vma_op *op;
 	int i;
 
@@ -2666,6 +2670,9 @@ static void vm_bind_ioctl_ops_fini(struct xe_vm *vm, struct xe_vma_ops *vops,
 			xe_vma_destroy(gpuva_to_vma(op->base.remap.unmap->va),
 				       fence);
 	}
+
+	xe_eudebug_vm_bind_end(vm, ufence, 0);
+
 	if (ufence)
 		xe_sync_ufence_put(ufence);
 	for (i = 0; i < vops->num_syncs; i++)
@@ -3078,6 +3085,8 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		if (err)
 			goto unwind_ops;
 
+		xe_eudebug_vm_bind_op_add(vm, op, addr, range);
+
 #ifdef TEST_VM_OPS_ERROR
 		if (flags & FORCE_OP_ERROR) {
 			vops.inject_error = true;
@@ -3101,8 +3110,11 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	err = vm_bind_ioctl_ops_execute(vm, &vops);
 
 unwind_ops:
-	if (err && err != -ENODATA)
+	if (err && err != -ENODATA) {
+		xe_eudebug_vm_bind_end(vm, num_ufence > 0, err);
 		vm_bind_ioctl_ops_unwind(vm, ops, args->num_binds);
+	}
+
 	xe_vma_ops_fini(&vops);
 	for (i = args->num_binds - 1; i >= 0; --i)
 		if (ops[i])
drivers/gpu/drm/xe/xe_vm_types.h +13 -0
index 7f9a303e51d8..557b047ebdd7 100644
@@ -282,6 +282,19 @@ struct xe_vm {
 	bool batch_invalidate_tlb;
 	/** @xef: XE file handle for tracking this VM's drm client */
 	struct xe_file *xef;
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		/** @lock: Lock for eudebug_bind members */
+		spinlock_t lock;
+		/** @events: List of vm bind ops gathered */
+		struct list_head events;
+		/** @ops: How many operations we have stored */
+		u32 ops;
+		/** @ref_seqno: Reference to the VM_BIND that the ops relate */
+		u64 ref_seqno;
+	} eudebug;
+#endif
 };
 
 /** struct xe_vma_op_map - VMA map operation */
include/uapi/drm/xe_drm_eudebug.h +64 -0

76 lines not on this page · raw message

Signature · 1 line
2.43.0
#13 lore raw

PATCH 11/26 drm/xe/eudebug: Add UFENCE events with acks

In reply to Mika Kuoppala

When vma is in place, debugger needs to intercept before userspace proceeds with the workload. For example to install a breakpoint in a eu shader.

Attach debugger in xe_user_fence, send UFENCE event and stall normal user fence signal path to yield if there is debugger attached to ufence.

When ack (ioctl) is received for the corresponding seqno, signal ufence.

v2: - return err instead of 0 to guarantee signalling (Dominik)
- checkpatch (Tilak)
- Kconfig (Mika, Andrzej)
- use lock instead of cmpxchg (Mika)

---
 drivers/gpu/drm/xe/xe_eudebug.c       | 283 +++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug.h       |  16 ++
 drivers/gpu/drm/xe/xe_eudebug_types.h |  13 ++
 drivers/gpu/drm/xe/xe_exec.c          |   2 +-
 drivers/gpu/drm/xe/xe_oa.c            |   3 +-
 drivers/gpu/drm/xe/xe_sync.c          |  45 ++--
 drivers/gpu/drm/xe/xe_sync.h          |   8 +-
 drivers/gpu/drm/xe/xe_sync_types.h    |  28 ++-
 drivers/gpu/drm/xe/xe_vm.c            |   4 +-
 include/uapi/drm/xe_drm_eudebug.h     |  13 ++
 10 files changed, 385 insertions(+), 30 deletions(-)
drivers/gpu/drm/xe/xe_eudebug.c +278 -5
index f544f60d7d6b..3cf3616e546d 100644
@@ -32,6 +32,7 @@
 #include "xe_reg_sr.h"
 #include "xe_rtp.h"
 #include "xe_sched_job.h"
+#include "xe_sync.h"
 #include "xe_vm.h"
 #include "xe_wa.h"
 
@@ -239,11 +240,119 @@ static void xe_eudebug_free(struct kref *ref)
 	kfree_rcu(d, rcu);
 }
 
-static void xe_eudebug_put(struct xe_eudebug *d)
+void xe_eudebug_put(struct xe_eudebug *d)
 {
 	kref_put(&d->ref, xe_eudebug_free);
 }
 
+struct xe_eudebug_ack {
+	struct rb_node rb_node;
+	u64 seqno;
+	u64 ts_insert;
+	struct xe_user_fence *ufence;
+};
+
+#define fetch_ack(x) rb_entry(x, struct xe_eudebug_ack, rb_node)
+
+static int compare_ack(const u64 a, const u64 b)
+{
+	if (a < b)
+		return -1;
+	else if (a > b)
+		return 1;
+
+	return 0;
+}
+
+static int ack_insert_cmp(struct rb_node * const node,
+			  const struct rb_node * const p)
+{
+	return compare_ack(fetch_ack(node)->seqno,
+			   fetch_ack(p)->seqno);
+}
+
+static int ack_lookup_cmp(const void * const key,
+			  const struct rb_node * const node)
+{
+	return compare_ack(*(const u64 *)key,
+			   fetch_ack(node)->seqno);
+}
+
+static struct xe_eudebug_ack *remove_ack(struct xe_eudebug *d, u64 seqno)
+{
+	struct rb_root * const root = &d->acks.tree;
+	struct rb_node *node;
+
+	spin_lock(&d->acks.lock);
+	node = rb_find(&seqno, root, ack_lookup_cmp);
+	if (node)
+		rb_erase(node, root);
+	spin_unlock(&d->acks.lock);
+
+	if (!node)
+		return NULL;
+
+	return rb_entry_safe(node, struct xe_eudebug_ack, rb_node);
+}
+
+static void ufence_signal_worker(struct work_struct *w)
+{
+	struct xe_user_fence * const ufence =
+		container_of(w, struct xe_user_fence, eudebug.worker);
+
+	if (READ_ONCE(ufence->signalled))
+		xe_sync_ufence_signal(ufence);
+
+	xe_sync_ufence_put(ufence);
+}
+
+static void kick_ufence_worker(struct xe_user_fence *f)
+{
+	queue_work(f->xe->eudebug.ordered_wq, &f->eudebug.worker);
+}
+
+static void handle_ack(struct xe_eudebug *d, struct xe_eudebug_ack *ack,
+		       bool on_disconnect)
+{
+	struct xe_user_fence *f = ack->ufence;
+	u64 signalled_by;
+	bool signal = false;
+
+	spin_lock(&f->eudebug.lock);
+	if (!f->eudebug.signalled_seqno) {
+		f->eudebug.signalled_seqno = ack->seqno;
+		signal = true;
+	}
+	signalled_by = f->eudebug.signalled_seqno;
+	spin_unlock(&f->eudebug.lock);
+
+	if (signal)
+		kick_ufence_worker(f);
+	else
+		xe_sync_ufence_put(f);
+
+	eu_dbg(d, "ACK: seqno=%llu: signalled by %llu (%s) (held %lluus)",
+	       ack->seqno, signalled_by,
+	       on_disconnect ? "disconnect" : "debugger",
+	       ktime_us_delta(ktime_get(), ack->ts_insert));
+
+	kfree(ack);
+}
+
+static void release_acks(struct xe_eudebug *d)
+{
+	struct xe_eudebug_ack *ack, *n;
+	struct rb_root root;
+
+	spin_lock(&d->acks.lock);
+	root = d->acks.tree;
+	d->acks.tree = RB_ROOT;
+	spin_unlock(&d->acks.lock);
+
+	rbtree_postorder_for_each_entry_safe(ack, n, &root, rb_node)
+		handle_ack(d, ack, true);
+}
+
 static struct task_struct *find_get_target(const pid_t nr)
 {
 	struct task_struct *task;
@@ -328,6 +437,8 @@ static bool xe_eudebug_detach(struct xe_device *xe,
 
 	eu_dbg(d, "session %lld detached with %d", d->session, err);
 
+	release_acks(d);
+
 	/* Our ref with the connection_link */
 	xe_eudebug_put(d);
 
@@ -453,7 +564,7 @@ _xe_eudebug_get(struct xe_file *xef)
 	return d;
 }
 
-static struct xe_eudebug *
+struct xe_eudebug *
 xe_eudebug_get(struct xe_file *xef)
 {
 	struct xe_eudebug *d;
@@ -792,7 +903,7 @@ static struct xe_eudebug_event *
 xe_eudebug_create_event(struct xe_eudebug *d, u16 type, u64 seqno, u16 flags,
 			u32 len)
 {
-	const u16 max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_OP;
+	const u16 max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE;
 	const u16 known_flags =
 		DRM_XE_EUDEBUG_EVENT_CREATE |
 		DRM_XE_EUDEBUG_EVENT_DESTROY |
@@ -827,7 +938,7 @@ static long xe_eudebug_read_event(struct xe_eudebug *d,
 		u64_to_user_ptr(arg);
 	struct drm_xe_eudebug_event user_event;
 	struct xe_eudebug_event *event;
-	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_OP;
+	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE;
 	long ret = 0;
 
 	if (XE_IOCTL_DBG(xe, copy_from_user(&user_event, user_orig, sizeof(user_event))))
@@ -902,6 +1013,44 @@ static long xe_eudebug_read_event(struct xe_eudebug *d,
 	return ret;
 }
 
+static long
+xe_eudebug_ack_event_ioctl(struct xe_eudebug *d,
+			   const unsigned int cmd,
+			   const u64 arg)
+{
+	struct drm_xe_eudebug_ack_event __user * const user_ptr =
+		u64_to_user_ptr(arg);
+	struct drm_xe_eudebug_ack_event user_arg;
+	struct xe_eudebug_ack *ack;
+	struct xe_device *xe = d->xe;
+
+	if (XE_IOCTL_DBG(xe, _IOC_SIZE(cmd) < sizeof(user_arg)))
+		return -EINVAL;
+
+	/* Userland write */
+	if (XE_IOCTL_DBG(xe, !(_IOC_DIR(cmd) & _IOC_WRITE)))
+		return -EINVAL;
+
+	if (XE_IOCTL_DBG(xe, copy_from_user(&user_arg,
+					    user_ptr,
+					    sizeof(user_arg))))
+		return -EFAULT;
+
+	if (XE_IOCTL_DBG(xe, user_arg.flags))
+		return -EINVAL;
+
+	if (XE_IOCTL_DBG(xe, xe_eudebug_detached(d)))
+		return -ENOTCONN;
+
+	ack = remove_ack(d, user_arg.seqno);
+	if (XE_IOCTL_DBG(xe, !ack))
+		return -EINVAL;
+
+	handle_ack(d, ack, false);
+
+	return 0;
+}
+
 static int do_eu_control(struct xe_eudebug *d,
 			 const struct drm_xe_eudebug_eu_control * const arg,
 			 struct drm_xe_eudebug_eu_control __user * const user_ptr)
@@ -1093,7 +1242,10 @@ static long xe_eudebug_ioctl(struct file *file,
 		ret = xe_eudebug_eu_control(d, arg);
 		eu_dbg(d, "ioctl cmd=EU_CONTROL ret=%ld\n", ret);
 		break;
-
+	case DRM_XE_EUDEBUG_IOCTL_ACK_EVENT:
+		ret = xe_eudebug_ack_event_ioctl(d, cmd, arg);
+		eu_dbg(d, "ioctl cmd=EVENT_ACK ret=%ld\n", ret);
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1792,6 +1944,9 @@ xe_eudebug_connect(struct xe_device *xe,
 	INIT_KFIFO(d->events.fifo);
 	INIT_WORK(&d->discovery_work, discovery_work_fn);
 
+	spin_lock_init(&d->acks.lock);
+	d->acks.tree = RB_ROOT;
+
 	d->res = xe_eudebug_resources_alloc();
 	if (IS_ERR(d->res)) {
 		err = PTR_ERR(d->res);
@@ -2486,6 +2641,70 @@ static int vm_bind_op(struct xe_eudebug *d, struct xe_vm *vm,
 	return 0;
 }
 
+static int xe_eudebug_track_ufence(struct xe_eudebug *d,
+				   struct xe_user_fence *f,
+				   u64 seqno)
+{
+	struct xe_eudebug_ack *ack;
+	struct rb_node *old;
+
+	ack = kzalloc(sizeof(*ack), GFP_KERNEL);
+	if (!ack)
+		return -ENOMEM;
+
+	ack->seqno = seqno;
+	ack->ts_insert = ktime_get();
+
+	spin_lock(&d->acks.lock);
+	old = rb_find_add(&ack->rb_node,
+			  &d->acks.tree, ack_insert_cmp);
+	if (!old) {
+		kref_get(&f->refcount);
+		ack->ufence = f;
+	}
+	spin_unlock(&d->acks.lock);
+
+	if (old) {
+		eu_dbg(d, "ACK: seqno=%llu: already exists", seqno);
+		kfree(ack);
+		return -EEXIST;
+	}
+
+	eu_dbg(d, "ACK: seqno=%llu: tracking started", seqno);
+
+	return 0;
+}
+
+static int vm_bind_ufence_event(struct xe_eudebug *d,
+				struct xe_user_fence *ufence)
+{
+	struct xe_eudebug_event *event;
+	struct xe_eudebug_event_vm_bind_ufence *e;
+	const u32 sz = sizeof(*e);
+	const u32 flags = DRM_XE_EUDEBUG_EVENT_CREATE |
+		DRM_XE_EUDEBUG_EVENT_NEED_ACK;
+	u64 seqno;
+	int ret;
+
+	seqno = atomic_long_inc_return(&d->events.seqno);
+
+	event = xe_eudebug_create_event(d, DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE,
+					seqno, flags, sz);
+	if (!event)
+		return -ENOMEM;
+
+	e = cast_event(e, event);
+
+	write_member(struct drm_xe_eudebug_event_vm_bind_ufence,
+		     e, vm_bind_ref_seqno, ufence->eudebug.bind_ref_seqno);
+
+	ret = xe_eudebug_track_ufence(d, ufence, seqno);
+	if (!ret)
+		ret = xe_eudebug_queue_event(d, event);
+
+	return ret;
+}
+
 void xe_eudebug_vm_init(struct xe_vm *vm)
 {
 	INIT_LIST_HEAD(&vm->eudebug.events);
@@ -2673,6 +2892,24 @@ void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int bind_err)
 		xe_eudebug_put(d);
 }
 
+int xe_eudebug_vm_bind_ufence(struct xe_user_fence *ufence)
+{
+	struct xe_eudebug *d;
+	int err;
+
+	d = ufence->eudebug.debugger;
+	if (!d || xe_eudebug_detached(d))
+		return -ENOTCONN;
+
+	err = vm_bind_ufence_event(d, ufence);
+	if (err) {
+		eu_err(d, "error %d on %s", err, __func__);
+		xe_eudebug_disconnect(d, err);
+	}
+
+	return err;
+}
+
 static int discover_client(struct xe_eudebug *d, struct xe_file *xef)
 {
 	struct xe_exec_queue *q;
@@ -2765,3 +3002,39 @@ static void discovery_work_fn(struct work_struct *work)
 
 	xe_eudebug_put(d);
 }
+
+void xe_eudebug_ufence_init(struct xe_user_fence *ufence,
+			    struct xe_file *xef,
+			    struct xe_vm *vm)
+{
+	u64 bind_ref;
+
+	/* Drop if OA */
+	if (!vm)
+		return;
+
+	spin_lock(&vm->eudebug.lock);
+	bind_ref = vm->eudebug.ref_seqno;
+	spin_unlock(&vm->eudebug.lock);
+
+	spin_lock_init(&ufence->eudebug.lock);
+	INIT_WORK(&ufence->eudebug.worker, ufence_signal_worker);
+
+	ufence->eudebug.signalled_seqno = 0;
+
+	if (bind_ref) {
+		ufence->eudebug.debugger = xe_eudebug_get(xef);
+
+		if (ufence->eudebug.debugger)
+			ufence->eudebug.bind_ref_seqno = bind_ref;
+	}
+}
+
+void xe_eudebug_ufence_fini(struct xe_user_fence *ufence)
+{
+	if (!ufence->eudebug.debugger)
+		return;
+
+	xe_eudebug_put(ufence->eudebug.debugger);
+	ufence->eudebug.debugger = NULL;
+}
drivers/gpu/drm/xe/xe_eudebug.h +16 -0
index ccc7202b3308..13ba0167b31b 100644
@@ -15,6 +15,7 @@ struct xe_vm;
 struct xe_vma;
 struct xe_exec_queue;
 struct xe_hw_engine;
+struct xe_user_fence;
 
 #if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
 
@@ -41,6 +42,13 @@ void xe_eudebug_vm_bind_start(struct xe_vm *vm);
 void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range);
 void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int err);
 
+int xe_eudebug_vm_bind_ufence(struct xe_user_fence *ufence);
+void xe_eudebug_ufence_init(struct xe_user_fence *ufence, struct xe_file *xef, struct xe_vm *vm);
+void xe_eudebug_ufence_fini(struct xe_user_fence *ufence);
+
+struct xe_eudebug *xe_eudebug_get(struct xe_file *xef);
+void xe_eudebug_put(struct xe_eudebug *d);
+
 #else
 
 static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
@@ -66,6 +74,14 @@ static inline void xe_eudebug_vm_bind_start(struct xe_vm *vm) { }
 static inline void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range) { }
 static inline void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int err) { }
 
+static inline int xe_eudebug_vm_bind_ufence(struct xe_user_fence *ufence) { return 0; }
+static inline void xe_eudebug_ufence_init(struct xe_user_fence *ufence,
+					  struct xe_file *xef, struct xe_vm *vm) { }
+static inline void xe_eudebug_ufence_fini(struct xe_user_fence *ufence) { }
+
+static inline struct xe_eudebug *xe_eudebug_get(struct xe_file *xef) { return NULL; }
+static inline void xe_eudebug_put(struct xe_eudebug *d) { }
+
 #endif /* CONFIG_DRM_XE_EUDEBUG */
 
 #endif
drivers/gpu/drm/xe/xe_eudebug_types.h +13 -0
index cbc316ec3593..ffb0dc71430a 100644
@@ -150,6 +150,14 @@ struct xe_eudebug {
 		atomic_long_t seqno;
 	} events;
 
+	/* user fences tracked by this debugger */
+	struct {
+		/** @lock: guards access to tree */
+		spinlock_t lock;
+
+		struct rb_root tree;
+	} acks;
+
 	/** @ops operations for eu_control */
 	struct xe_eudebug_eu_control_ops *ops;
 };
@@ -313,4 +321,9 @@ struct xe_eudebug_event_vm_bind_op {
 	u64 range; /* Zero for unmap all ? */
 };
 
+struct xe_eudebug_event_vm_bind_ufence {
+	struct xe_eudebug_event base;
+	u64 vm_bind_ref_seqno;
+};
+
 #endif
drivers/gpu/drm/xe/xe_exec.c +1 -1
index 31cca938956f..17dd7a3f8354 100644
@@ -159,7 +159,7 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	vm = q->vm;
 
 	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
-		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
+		err = xe_sync_entry_parse(xe, xef, vm, &syncs[num_syncs],
 					  &syncs_user[num_syncs], SYNC_PARSE_FLAG_EXEC |
 					  (xe_vm_in_lr_mode(vm) ?
 					   SYNC_PARSE_FLAG_LR_MODE : 0));
drivers/gpu/drm/xe/xe_oa.c +2 -1
index 8dd55798ab31..a32dc3fdabe7 100644
@@ -1379,7 +1379,8 @@ static int xe_oa_parse_syncs(struct xe_oa *oa, struct xe_oa_open_param *param)
 	}
 
 	for (num_syncs = 0; num_syncs < param->num_syncs; num_syncs++) {
-		ret = xe_sync_entry_parse(oa->xe, param->xef, &param->syncs[num_syncs],
+		ret = xe_sync_entry_parse(oa->xe, param->xef, NULL,
+					  &param->syncs[num_syncs],
 					  &param->syncs_user[num_syncs], 0);
 		if (ret)
 			goto err_syncs;
drivers/gpu/drm/xe/xe_sync.c +29 -16

100 lines not on this page · raw message

drivers/gpu/drm/xe/xe_sync.h +7 -1
index 256ffc1e54dc..f5bec2b1b4f6 100644
@@ -9,8 +9,12 @@
 #include "xe_sync_types.h"
 
 struct xe_device;
-struct xe_exec_queue;
 struct xe_file;
+struct xe_exec_queue;
+struct drm_syncobj;
+struct dma_fence;
+struct dma_fence_chain;
+struct drm_xe_sync;
 struct xe_sched_job;
 struct xe_vm;
 
@@ -19,6 +23,7 @@ struct xe_vm;
 #define SYNC_PARSE_FLAG_DISALLOW_USER_FENCE	BIT(2)
 
 int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
+			struct xe_vm *vm,
 			struct xe_sync_entry *sync,
 			struct drm_xe_sync __user *sync_user,
 			unsigned int flags);
@@ -40,5 +45,6 @@ struct xe_user_fence *__xe_sync_ufence_get(struct xe_user_fence *ufence);
 struct xe_user_fence *xe_sync_ufence_get(struct xe_sync_entry *sync);
 void xe_sync_ufence_put(struct xe_user_fence *ufence);
 int xe_sync_ufence_get_status(struct xe_user_fence *ufence);
+void xe_sync_ufence_signal(struct xe_user_fence *ufence);
 
 #endif
drivers/gpu/drm/xe/xe_sync_types.h +23 -5
index 30ac3f51993b..dcd3165e66a7 100644
@@ -6,13 +6,31 @@
 #ifndef _XE_SYNC_TYPES_H_
 #define _XE_SYNC_TYPES_H_
 
+#include <linux/dma-fence-array.h>
+#include <linux/kref.h>
+#include <linux/spinlock.h>
 #include <linux/types.h>
 
-struct drm_syncobj;
-struct dma_fence;
-struct dma_fence_chain;
-struct drm_xe_sync;
-struct user_fence;
+struct xe_user_fence {
+	struct xe_device *xe;
+	struct kref refcount;
+	struct dma_fence_cb cb;
+	struct work_struct worker;
+	struct mm_struct *mm;
+	u64 __user *addr;
+	u64 value;
+	int signalled;
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		spinlock_t lock;
+		struct xe_eudebug *debugger;
+		u64 bind_ref_seqno;
+		u64 signalled_seqno;
+		struct work_struct worker;
+	} eudebug;
+#endif
+};
 
 struct xe_sync_entry {
 	struct drm_syncobj *syncobj;
drivers/gpu/drm/xe/xe_vm.c +3 -1
index e83420473763..0f17bc8b627b 100644
@@ -3037,9 +3037,11 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		}
 	}
 
+	xe_eudebug_vm_bind_start(vm);
+
 	syncs_user = u64_to_user_ptr(args->syncs);
 	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
-		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
+		err = xe_sync_entry_parse(xe, xef, vm, &syncs[num_syncs],
 					  &syncs_user[num_syncs],
 					  (xe_vm_in_lr_mode(vm) ?
 					   SYNC_PARSE_FLAG_LR_MODE : 0) |
include/uapi/drm/xe_drm_eudebug.h +13 -0
index cc34c522fa4d..1d5f1411c9a8 100644
@@ -17,6 +17,7 @@ extern "C" {
  */
 #define DRM_XE_EUDEBUG_IOCTL_READ_EVENT		_IO('j', 0x0)
 #define DRM_XE_EUDEBUG_IOCTL_EU_CONTROL		_IOWR('j', 0x2, struct drm_xe_eudebug_eu_control)
+#define DRM_XE_EUDEBUG_IOCTL_ACK_EVENT		_IOW('j', 0x4, struct drm_xe_eudebug_ack_event)
 
 /* XXX: Document events to match their internal counterparts when moved to xe_drm.h */
 struct drm_xe_eudebug_event {
@@ -32,6 +33,7 @@ struct drm_xe_eudebug_event {
 #define DRM_XE_EUDEBUG_EVENT_EU_ATTENTION	6
 #define DRM_XE_EUDEBUG_EVENT_VM_BIND		7
 #define DRM_XE_EUDEBUG_EVENT_VM_BIND_OP		8
+#define DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE	9
 
 	__u16 flags;
 #define DRM_XE_EUDEBUG_EVENT_CREATE		(1 << 0)
@@ -174,6 +176,17 @@ struct drm_xe_eudebug_event_vm_bind_op {
 	__u64 range; /* XXX: Zero for unmap all? */
 };
 
+struct drm_xe_eudebug_event_vm_bind_ufence {
+	struct drm_xe_eudebug_event base;
+	__u64 vm_bind_ref_seqno; /* *_event_vm_bind.base.seqno */
+};
+
+struct drm_xe_eudebug_ack_event {
+	__u32 type;
+	__u32 flags; /* MBZ */
+	__u64 seqno;
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#14 lore raw

PATCH 12/26 drm/xe/eudebug: vm open/pread/pwrite

In reply to Mika Kuoppala

Debugger needs access to the client's vm to read and write. For example inspecting ISA/ELF and setting up breakpoints.

Add ioctl to open target vm with debugger client and vm_handle and hook up pread/pwrite possibility.

Open will take timeout argument so that standard fsync can be used for explicit flushing between cpu/gpu for the target vm.

Implement this for bo backed storage. userptr will be done in following patch.

v2: - checkpatch (Maciej)
- 32bit fixes (Andrzej)
- bo_vmap (Mika)
- fix vm leak if can't allocate k_buffer (Mika)
- assert vm write held for vma (Matthew)

v3: - fw ref, ttm_bo_access
- timeout boundary check (Dominik)
- dont try to copy to user on zero bytes (Mika)

---
 drivers/gpu/drm/xe/regs/xe_gt_regs.h |  24 ++
 drivers/gpu/drm/xe/xe_eudebug.c      | 442 +++++++++++++++++++++++++++
 include/uapi/drm/xe_drm_eudebug.h    |  19 ++
 3 files changed, 485 insertions(+)
drivers/gpu/drm/xe/regs/xe_gt_regs.h +24 -0
index 5fcf06835ef0..4c620f95b466 100644
@@ -551,6 +551,30 @@
 #define   CCS_MODE_CSLICE(cslice, ccs) \
 	((ccs) << ((cslice) * CCS_MODE_CSLICE_WIDTH))
 
+#define RCU_ASYNC_FLUSH				XE_REG(0x149fc)
+#define   RCU_ASYNC_FLUSH_IN_PROGRESS	REG_BIT(31)
+#define   RCU_ASYNC_FLUSH_ENGINE_ID_SHIFT	28
+#define   RCU_ASYNC_FLUSH_ENGINE_ID_DECODE1 REG_BIT(26)
+#define   RCU_ASYNC_FLUSH_AMFS		REG_BIT(8)
+#define   RCU_ASYNC_FLUSH_PREFETCH	REG_BIT(7)
+#define   RCU_ASYNC_FLUSH_DATA_PORT	REG_BIT(6)
+#define   RCU_ASYNC_FLUSH_DATA_CACHE	REG_BIT(5)
+#define   RCU_ASYNC_FLUSH_HDC_PIPELINE	REG_BIT(4)
+#define   RCU_ASYNC_INVALIDATE_HDC_PIPELINE REG_BIT(3)
+#define   RCU_ASYNC_INVALIDATE_CONSTANT_CACHE REG_BIT(2)
+#define   RCU_ASYNC_INVALIDATE_TEXTURE_CACHE REG_BIT(1)
+#define   RCU_ASYNC_INVALIDATE_INSTRUCTION_CACHE REG_BIT(0)
+#define   RCU_ASYNC_FLUSH_AND_INVALIDATE_ALL ( \
+	RCU_ASYNC_FLUSH_AMFS | \
+	RCU_ASYNC_FLUSH_PREFETCH | \
+	RCU_ASYNC_FLUSH_DATA_PORT | \
+	RCU_ASYNC_FLUSH_DATA_CACHE | \
+	RCU_ASYNC_FLUSH_HDC_PIPELINE | \
+	RCU_ASYNC_INVALIDATE_HDC_PIPELINE | \
+	RCU_ASYNC_INVALIDATE_CONSTANT_CACHE | \
+	RCU_ASYNC_INVALIDATE_TEXTURE_CACHE | \
+	RCU_ASYNC_INVALIDATE_INSTRUCTION_CACHE)
+
 #define RCU_DEBUG_1				XE_REG(0x14a00)
 #define   RCU_DEBUG_1_ENGINE_STATUS		REG_GENMASK(2, 0)
 #define   RCU_DEBUG_1_RUNALONE_ACTIVE		REG_BIT(2)
drivers/gpu/drm/xe/xe_eudebug.c +442 -0

472 lines not on this page · raw message

include/uapi/drm/xe_drm_eudebug.h +19 -0
index 1d5f1411c9a8..a5f13563b3b9 100644
@@ -18,6 +18,7 @@ extern "C" {
 #define DRM_XE_EUDEBUG_IOCTL_READ_EVENT		_IO('j', 0x0)
 #define DRM_XE_EUDEBUG_IOCTL_EU_CONTROL		_IOWR('j', 0x2, struct drm_xe_eudebug_eu_control)
 #define DRM_XE_EUDEBUG_IOCTL_ACK_EVENT		_IOW('j', 0x4, struct drm_xe_eudebug_ack_event)
+#define DRM_XE_EUDEBUG_IOCTL_VM_OPEN		_IOW('j', 0x1, struct drm_xe_eudebug_vm_open)
 
 /* XXX: Document events to match their internal counterparts when moved to xe_drm.h */
 struct drm_xe_eudebug_event {
@@ -187,6 +188,24 @@ struct drm_xe_eudebug_ack_event {
 	__u64 seqno;
 };
 
+struct drm_xe_eudebug_vm_open {
+	/** @extensions: Pointer to the first extension struct, if any */
+	__u64 extensions;
+
+	/** @client_handle: id of client */
+	__u64 client_handle;
+
+	/** @vm_handle: id of vm */
+	__u64 vm_handle;
+
+	/** @flags: flags */
+	__u64 flags;
+
+#define DRM_XE_EUDEBUG_VM_SYNC_MAX_TIMEOUT_NSECS (10ULL * NSEC_PER_SEC)
+	/** @timeout_ns: Timeout value in nanoseconds operations (fsync) */
+	__u64 timeout_ns;
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#15 lore raw

PATCH 13/26 drm/xe: add system memory page iterator support to xe_res_cursor

In reply to Mika Kuoppala

From: Andrzej Hajda <[email protected]>

Currently xe_res_cursor allows iteration only over DMA side of scatter gatter tables.

---
 drivers/gpu/drm/xe/xe_res_cursor.h | 51 +++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_res_cursor.h +39 -12
index dca374b6521c..c1f39a680ae0 100644
@@ -129,18 +129,35 @@ static inline void __xe_res_sg_next(struct xe_res_cursor *cur)
 {
 	struct scatterlist *sgl = cur->sgl;
 	u64 start = cur->start;
+	unsigned int len;
 
-	while (start >= sg_dma_len(sgl)) {
-		start -= sg_dma_len(sgl);
+	while (true) {
+		len = (cur->mem_type == XE_PL_SYSTEM) ? sgl->length : sg_dma_len(sgl);
+		if (start < len)
+			break;
+		start -= len;
 		sgl = sg_next(sgl);
 		XE_WARN_ON(!sgl);
 	}
-
 	cur->start = start;
-	cur->size = sg_dma_len(sgl) - start;
+	cur->size = len - start;
 	cur->sgl = sgl;
 }
 
+static inline void __xe_res_first_sg(const struct sg_table *sg,
+				   u64 start, u64 size,
+				   struct xe_res_cursor *cur, u32 mem_type)
+{
+	XE_WARN_ON(!sg);
+	cur->node = NULL;
+	cur->start = start;
+	cur->remaining = size;
+	cur->size = 0;
+	cur->sgl = sg->sgl;
+	cur->mem_type = mem_type;
+	__xe_res_sg_next(cur);
+}
+
 /**
  * xe_res_first_sg - initialize a xe_res_cursor with a scatter gather table
  *
@@ -155,14 +172,24 @@ static inline void xe_res_first_sg(const struct sg_table *sg,
 				   u64 start, u64 size,
 				   struct xe_res_cursor *cur)
 {
-	XE_WARN_ON(!sg);
-	cur->node = NULL;
-	cur->start = start;
-	cur->remaining = size;
-	cur->size = 0;
-	cur->sgl = sg->sgl;
-	cur->mem_type = XE_PL_TT;
-	__xe_res_sg_next(cur);
+	__xe_res_first_sg(sg, start, size, cur, XE_PL_TT);
+}
+
+/**
+ * xe_res_first_sg_system - initialize a xe_res_cursor for iterate system memory pages
+ *
+ * @sg: scatter gather table to walk
+ * @start: Start of the range
+ * @size: Size of the range
+ * @cur: cursor object to initialize
+ *
+ * Start walking over the range of allocations between @start and @size
+ */
+static inline void xe_res_first_sg_system(const struct sg_table *sg,
+				   u64 start, u64 size,
+				   struct xe_res_cursor *cur)
+{
+	__xe_res_first_sg(sg, start, size, cur, XE_PL_SYSTEM);
 }
 
 /**
Signature · 1 line
2.43.0
#16 lore raw

PATCH 14/26 drm/xe/eudebug: implement userptr_vma access

In reply to Mika Kuoppala

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
- s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
 drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
 drivers/gpu/drm/xe/xe_vm.c      | 47 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vm.h      |  3 +++
 3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
 		return ret;
 	}
 
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma), offset_in_vma,
+				    buf, bytes, write);
 }
 
 static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +47 -0

50 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +3 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
 void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
 void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
 void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write);
Signature · 1 line
2.43.0
#17 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 5 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

Quoted 58 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
- s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
  drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
  drivers/gpu/drm/xe/xe_vm.c      | 47 +++++++++++++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_vm.h      |  3 +++
  3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
  		return ret;
  	}
 
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma), offset_in_vma,
+				    buf, bytes, write);
  }
 
  static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +22 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot *snap)
  	}
  	kvfree(snap);
  }
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write)
+{
+	struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+	struct xe_userptr *up = &uvma->userptr;
+	struct xe_res_cursor cur = {};
+	int cur_len, ret = 0;
+
+	while (true) {
+		down_read(&vm->userptr.notifier_lock);
+		if (!xe_vma_userptr_check_repin(uvma))
+			break;
+
+		spin_lock(&vm->userptr.invalidated_lock);
+		list_del_init(&uvma->userptr.invalidate_link);
+		spin_unlock(&vm->userptr.invalidated_lock);
+
+		up_read(&vm->userptr.notifier_lock);
+		ret = xe_vma_userptr_pin_pages(uvma);
+		if (ret)
+			return ret;

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3448

Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +10 -0
+	}
+
+	if (!up->sg) {
+		ret = -EINVAL;
+		goto out_unlock_notifier;
+	}
+
+	for (xe_res_first_sg_system(up->sg, offset, len, &cur); cur.remaining;
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) + cur.start;

The interface basically creates a side channel to access userptrs in the way an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	ret = len;
+
+out_unlock_notifier:
+	up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +2 -0
+	return ret;
+}
drivers/gpu/drm/xe/xe_vm.h +3 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
  void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
  void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
  void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write);
#18 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

(+ Thomas and Matt B who this was reviewed with as a concept)

Quoting Christian König (2024-12-09 16:03:04)

Quoted 1 line

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

<SNIP>

Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/xe/xe_vm.c +27 -0
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+                      void *buf, u64 len, bool write)
+{
+     struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+     struct xe_userptr *up = &uvma->userptr;
+     struct xe_res_cursor cur = {};
+     int cur_len, ret = 0;
+
+     while (true) {
+             down_read(&vm->userptr.notifier_lock);
+             if (!xe_vma_userptr_check_repin(uvma))
+                     break;
+
+             spin_lock(&vm->userptr.invalidated_lock);
+             list_del_init(&uvma->userptr.invalidate_link);
+             spin_unlock(&vm->userptr.invalidated_lock);
+
+             up_read(&vm->userptr.notifier_lock);
+             ret = xe_vma_userptr_pin_pages(uvma);
+             if (ret)
+                     return ret;
+     }
+
+     if (!up->sg) {
+             ret = -EINVAL;
+             goto out_unlock_notifier;
+     }
Quoted 8 lines

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3448

Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +4 -0
+
+     for (xe_res_first_sg_system(up->sg, offset, len, &cur); cur.remaining;
+          xe_res_next(&cur, cur_len)) {
+             void *ptr = kmap_local_page(sg_page(cur.sgl)) + cur.start;

The interface basically creates a side channel to access userptrs in the way an userspace application would do without actually going through userspace.

That's not quite the case here.

The whole point of the debugger ability to access memory is to access any VMA in the GPU VM emulating as much as possible like the EUs themselves would do the access.

As mentioned in the other threads, that also involves special cache flushes to make sure the contents has been flushed in and out of the EU caches in case we're modifying instruction code for breakpoints as an example.

What the memory access function should do is to establish a temporary pinning situation where the memory would be accessible just like it would be for a short batchbuffer, but without interfering with the command streamers.

If this should be established in a different way from this patch, then we should adapt of course.

Quoted 2 lines

That is generally not something a device driver should ever do as far as I can see.

Given above explanation, does it make more sense? For debugging purposes, we try to emulate the EU threads themselves accessing the memory, not the userspace at all.

Regards, Joonas

#19 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

In reply to Christian König
Quoted 7 lines · Christian König

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 5 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Quoted 7 lines

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr. Probably time we standardize that and put it into gpuvm as an optional part, with consistent locking, naming (like not calling it _pin_pages when it's unpinnged userptr), kerneldoc and all the nice things so that we stop consistently getting confused by other driver's userptr code.

I think that was on the plan originally as an eventual step, I guess time to pump that up. Matt/Thomas, thoughts?
-Sima

Quoted 107 lines
Quoted 57 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
- s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
  drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
  drivers/gpu/drm/xe/xe_vm.c      | 47 +++++++++++++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_vm.h      |  3 +++
  3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
  		return ret;
  	}
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma), offset_in_vma,
+				    buf, bytes, write);
  }
  static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +22 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot *snap)
  	}
  	kvfree(snap);
  }
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write)
+{
+	struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+	struct xe_userptr *up = &uvma->userptr;
+	struct xe_res_cursor cur = {};
+	int cur_len, ret = 0;
+
+	while (true) {
+		down_read(&vm->userptr.notifier_lock);
+		if (!xe_vma_userptr_check_repin(uvma))
+			break;
+
+		spin_lock(&vm->userptr.invalidated_lock);
+		list_del_init(&uvma->userptr.invalidate_link);
+		spin_unlock(&vm->userptr.invalidated_lock);
+
+		up_read(&vm->userptr.notifier_lock);
+		ret = xe_vma_userptr_pin_pages(uvma);
+		if (ret)
+			return ret;

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3448

Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +10 -0
+	}
+
+	if (!up->sg) {
+		ret = -EINVAL;
+		goto out_unlock_notifier;
+	}
+
+	for (xe_res_first_sg_system(up->sg, offset, len, &cur); cur.remaining;
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) + cur.start;

The interface basically creates a side channel to access userptrs in the way an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	ret = len;
+
+out_unlock_notifier:
+	up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +2 -0
+	return ret;
+}
drivers/gpu/drm/xe/xe_vm.h +3 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
  void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
  void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
  void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write);
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#20 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Am 09.12.24 um 16:31 schrieb Simona Vetter:

Quoted 10 lines · Christian König
Quoted 9 lines

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 5 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

Quoted 8 lines
Quoted 4 lines

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

The whole interface re-invents a lot of functionality which is already there just because you don't like the idea to attach to the debugged application in userspace.

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

Regards,
Christian.

Quoted 113 lines

Probably time
we standardize that and put it into gpuvm as an optional part, with consistent locking, naming (like not calling it _pin_pages when it's unpinnged userptr), kerneldoc and all the nice things so that we stop consistently getting confused by other driver's userptr code.

I think that was on the plan originally as an eventual step, I guess time to pump that up. Matt/Thomas, thoughts?
-Sima

Quoted 103 lines
Quoted 56 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
- s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
   drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
   drivers/gpu/drm/xe/xe_vm.c      | 47 +++++++++++++++++++++++++++++++++
   drivers/gpu/drm/xe/xe_vm.h      |  3 +++
   3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
   		return ret;
   	}
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma), offset_in_vma,
+				    buf, bytes, write);
   }
   static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +22 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot *snap)
   	}
   	kvfree(snap);
   }
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write)
+{
+	struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+	struct xe_userptr *up = &uvma->userptr;
+	struct xe_res_cursor cur = {};
+	int cur_len, ret = 0;
+
+	while (true) {
+		down_read(&vm->userptr.notifier_lock);
+		if (!xe_vma_userptr_check_repin(uvma))
+			break;
+
+		spin_lock(&vm->userptr.invalidated_lock);
+		list_del_init(&uvma->userptr.invalidate_link);
+		spin_unlock(&vm->userptr.invalidated_lock);
+
+		up_read(&vm->userptr.notifier_lock);
+		ret = xe_vma_userptr_pin_pages(uvma);
+		if (ret)
+			return ret;

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3448

Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +10 -0
+	}
+
+	if (!up->sg) {
+		ret = -EINVAL;
+		goto out_unlock_notifier;
+	}
+
+	for (xe_res_first_sg_system(up->sg, offset, len, &cur); cur.remaining;
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) + cur.start;

The interface basically creates a side channel to access userptrs in the way an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	ret = len;
+
+out_unlock_notifier:
+	up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +2 -0
+	return ret;
+}
drivers/gpu/drm/xe/xe_vm.h +3 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
   void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
   void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
   void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write);
#21 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Am 09.12.24 um 16:42 schrieb Christian König:

Quoted 17 lines

Am 09.12.24 um 16:31 schrieb Simona Vetter:

Quoted 16 lines · Christian König
Quoted 6 lines

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 5 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Quoted 7 lines

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

One thing I'm missing: Is it possible that mappings are created read-only?

E.g. that you have a read-only mapping of libc and then write through this interface to it?

Of hand I don't see anything preventing this (well could be that you don't allow creating read-only mappings).

Regards,
Christian.

Quoted 135 lines
Quoted 2 lines

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

The whole interface re-invents a lot of functionality which is already there just because you don't like the idea to attach to the debugged application in userspace.

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

Regards,
Christian.

Quoted 118 lines

  Probably time
we standardize that and put it into gpuvm as an optional part, with consistent locking, naming (like not calling it _pin_pages when it's unpinnged userptr), kerneldoc and all the nice things so that we stop consistently getting confused by other driver's userptr code.

I think that was on the plan originally as an eventual step, I guess time to pump that up. Matt/Thomas, thoughts?
-Sima

Quoted 108 lines
Quoted 67 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
      - s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
   drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
   drivers/gpu/drm/xe/xe_vm.c      | 47
+++++++++++++++++++++++++++++++++
   drivers/gpu/drm/xe/xe_vm.h      |  3 +++

   3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct 
 xe_vma *vma, u64 offset_in_vma,
            return ret;
        }
-    return -EINVAL;
+    return xe_vm_userptr_access(to_userptr_vma(vma), offset_in_vma,
+                    buf, bytes, write);
    }
    static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +0 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct 
 xe_vm_snapshot *snap)
        }
        kvfree(snap);

   }

drivers/gpu/drm/xe/xe_vm.c +30 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+             void *buf, u64 len, bool write)
+{
+    struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+    struct xe_userptr *up = &uvma->userptr;
+    struct xe_res_cursor cur = {};
+    int cur_len, ret = 0;
+
+    while (true) {
+        down_read(&vm->userptr.notifier_lock);
+        if (!xe_vma_userptr_check_repin(uvma))
+            break;
+
+        spin_lock(&vm->userptr.invalidated_lock);
+ list_del_init(&uvma->userptr.invalidate_link);
+        spin_unlock(&vm->userptr.invalidated_lock);
+
+        up_read(&vm->userptr.notifier_lock);
+        ret = xe_vma_userptr_pin_pages(uvma);
+        if (ret)
+            return ret;
+    }
+
+    if (!up->sg) {
+        ret = -EINVAL;
+        goto out_unlock_notifier;
+    }
+
+    for (xe_res_first_sg_system(up->sg, offset, len, &cur); 
Quoted 3 lines

cur.remaining;
+         xe_res_next(&cur, cur_len)) {
+        void *ptr = kmap_local_page(sg_page(cur.sgl)) + cur.start;

The interface basically creates a side channel to access userptrs in the way an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+        cur_len = min(cur.size, cur.remaining);
+        if (write)
+            memcpy(ptr, buf, cur_len);
+        else
+            memcpy(buf, ptr, cur_len);
+        kunmap_local(ptr);
+        buf += cur_len;
+    }
+    ret = len;
+
+out_unlock_notifier:
+    up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 14 lines

+    return ret;

drivers/gpu/drm/xe/xe_vm.c +1 -0
+}
drivers/gpu/drm/xe/xe_vm.h +0 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot 
 *xe_vm_snapshot_capture(struct xe_vm *vm);
    void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
    void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);

   void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);

drivers/gpu/drm/xe/xe_vm.h +3 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+             void *buf, u64 len, bool write);
#22 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

In reply to Christian König

Quoting Christian König (2024-12-09 17:42:32)

Quoted 18 lines

Am 09.12.24 um 16:31 schrieb Simona Vetter:

Quoted 17 lines · Christian König
Quoted 6 lines

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 5 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Quoted 7 lines

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

Quoted 6 lines
Quoted 1 line

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

Could you elaborate, what is that a problem in that, exactly?

It's pretty much the equivalent of ptrace() poke/peek but for GPU memory. And it is exactly the kind of interface that makes sense for debugger as GPU memory != CPU memory, and they don't need to align at all.

Quoted 3 lines

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

I don't quite agree here -- at all. "Which CPU address is mapped to which GPU address" makes no sense when the GPU address space and CPU address space is completely controlled by the userspace driver/application.

Please try to consider things outside of the ROCm architecture.

Something like a register scratch region or EU instructions should not even be mapped to CPU address space as CPU has no business accessing it during normal operation. And backing of such region will vary per context/LRC on the same virtual address per EU thread.

You seem to be suggesting to rewrite even our userspace driver to behave the same way as ROCm driver does just so that we could implement debug memory accesses via ptrace() to the CPU address space.

That seems bit of a radical suggestion, especially given the drawbacks pointed out in your suggested design.

Quoted 2 lines

The whole interface re-invents a lot of functionality which is already there

I'm not really sure I would call adding a single interface for memory reading and writing to be "re-inventing a lot of functionality".

All the functionality behind this interface will be needed by GPU core dumping, anyway. Just like for the other patch series.

Quoted 2 lines

just because you don't like the idea to attach to the debugged application in userspace.

A few points that have been brought up as drawback to the GPU debug through ptrace(), but to recap a few relevant ones for this discussion:

- You can only really support GDB stop-all mode or at least have to stop all the CPU threads while you control the GPU threads to avoid interference. Elaborated on this on the other threads more.
- Controlling the GPU threads will always interfere with CPU threads. Doesn't seem feasible to single-step an EU thread while CPU threads continue to run freely?
- You are very much restricted by the CPU VA ~ GPU VA alignment requirement, which is not true for OpenGL or Vulkan etc. Seems like one of the reasons why ROCm debugging is not easily extendable outside compute?
- You have to expose extra memory to CPU process just for GPU debugger access and keep track of GPU VA for each. Makes the GPU more prone to OOB writes from CPU. Exactly what not mapping the memory to CPU tried to protect the GPU from to begin with.

Quoted 2 lines

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

I see it like reinventing a round wheel compared to octagonal wheel.

Could you elaborate with facts much more on your position why the ROCm debugger design is an absolute must for others to adopt?

Otherwise it just looks like you are trying to prevent others from implementing a more flexible debugging interface through vague comments about "questionable design" without going into details. Not listing much concrete benefits nor addressing the very concretely expressed drawbacks of your suggested design, makes it seem like a very biased non-technical discussion.

So while review interest and any comments are very much appreciated, please also work on providing bit more reasoning and facts instead of just claiming things. That'll help make the discussion much more fruitful.

Regards, Joonas

#23 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Am 10.12.24 um 10:33 schrieb Joonas Lahtinen:

Quoted 19 lines

Quoting Christian König (2024-12-09 17:42:32)

Quoted 18 lines

Am 09.12.24 um 16:31 schrieb Simona Vetter:

Quoted 17 lines · Christian König
Quoted 6 lines

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 5 lines

From: Andrzej Hajda<[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Quoted 7 lines

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

Could you elaborate, what is that a problem in that, exactly?

It's pretty much the equivalent of ptrace() poke/peek but for GPU memory.

Exactly that here. You try to debug the GPU without taking control of the CPU process.

This means that you have to re-implement all debug functionalities which where previously invested for the CPU process for the GPU once more.

And that in turn creates a massive attack surface for security related problems, especially when you start messing with things like userptrs which have a very low level interaction with core memory management.

Quoted 2 lines

And it is exactly the kind of interface that makes sense for debugger as GPU memory != CPU memory, and they don't need to align at all.

And that is what I strongly disagree on. When you debug the GPU it is mandatory to gain control of the CPU process as well.

The CPU process is basically the overseer of the GPU activity, so it should know everything about the GPU operation, for example what a mapping actually means.

The kernel driver and the hardware only have the information necessary to execute the work prepared by the CPU process. So the information available is limited to begin with.

Quoted 6 lines
Quoted 3 lines

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

I don't quite agree here -- at all. "Which CPU address is mapped to which GPU address" makes no sense when the GPU address space and CPU address space is completely controlled by the userspace driver/application.

Yeah, that's the reason why you should ask the userspace driver/application for the necessary information and not go over the kernel to debug things.

Quoted 1 line

Please try to consider things outside of the ROCm architecture.

Well I consider a good part of the ROCm architecture rather broken exactly because we haven't pushed back hard enough on bad ideas.

Quoted 8 lines

Something like a register scratch region or EU instructions should not even be mapped to CPU address space as CPU has no business accessing it during normal operation. And backing of such region will vary per context/LRC on the same virtual address per EU thread.

You seem to be suggesting to rewrite even our userspace driver to behave the same way as ROCm driver does just so that we could implement debug memory accesses via ptrace() to the CPU address space.

Oh, well certainly not. That ROCm has an 1 to 1 mapping between CPU and GPU is one thing I've pushed back massively on and has now proven to be problematic.

Quoted 10 lines

That seems bit of a radical suggestion, especially given the drawbacks pointed out in your suggested design.

Quoted 2 lines

The whole interface re-invents a lot of functionality which is already there

I'm not really sure I would call adding a single interface for memory reading and writing to be "re-inventing a lot of functionality".

All the functionality behind this interface will be needed by GPU core dumping, anyway. Just like for the other patch series.

As far as I can see exactly that's an absolutely no-go. Device core dumping should *never ever* touch memory imported by userptrs.

That's what process core dumping is good for.

Quoted 6 lines
Quoted 2 lines

just because you don't like the idea to attach to the debugged application in userspace.

A few points that have been brought up as drawback to the GPU debug through ptrace(), but to recap a few relevant ones for this discussion:

Quoted 6 lines

- You can only really support GDB stop-all mode or at least have to stop all the CPU threads while you control the GPU threads to avoid interference. Elaborated on this on the other threads more.
- Controlling the GPU threads will always interfere with CPU threads. Doesn't seem feasible to single-step an EU thread while CPU threads continue to run freely?

I would say no.

Quoted 4 lines

- You are very much restricted by the CPU VA ~ GPU VA alignment requirement, which is not true for OpenGL or Vulkan etc. Seems like one of the reasons why ROCm debugging is not easily extendable outside compute?

Well as long as you can't take debugged threads from the hardware you can pretty much forget any OpenGL or Vulkan debugging with this interface since it violates the dma_fence restrictions in the kernel.

Quoted 11 lines

- You have to expose extra memory to CPU process just for GPU debugger access and keep track of GPU VA for each. Makes the GPU more prone to OOB writes from CPU. Exactly what not mapping the memory to CPU tried to protect the GPU from to begin with.

Quoted 2 lines

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

I see it like reinventing a round wheel compared to octagonal wheel.

Could you elaborate with facts much more on your position why the ROCm debugger design is an absolute must for others to adopt?

Well I'm trying to prevent some of the mistakes we did with the ROCm design.

And trying to re-invent well proven kernel interfaces is one of the big mistakes made in the ROCm design.

If you really want to expose an interface to userspace which walks the process page table, installs an MMU notifier, kmaps the resulting page and then memcpy to/from it then you absolutely *must* run that by guys like Christoph Hellwig, Andrew and even Linus.

I'm pretty sure that those guys will note that a device driver should absolutely not mess with such stuff.

Regards,
Christian.

Quoted 11 lines

Otherwise it just looks like you are trying to prevent others from implementing a more flexible debugging interface through vague comments about "questionable design" without going into details. Not listing much concrete benefits nor addressing the very concretely expressed drawbacks of your suggested design, makes it seem like a very biased non-technical discussion.

So while review interest and any comments are very much appreciated, please also work on providing bit more reasoning and facts instead of just claiming things. That'll help make the discussion much more fruitful.

Regards, Joonas

#24 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Quoting Christian König (2024-12-10 12:00:48)

Quoted 34 lines

Am 10.12.24 um 10:33 schrieb Joonas Lahtinen:

Quoting Christian König (2024-12-09 17:42:32)

Am 09.12.24 um 16:31 schrieb Simona Vetter:

On Mon, Dec 09, 2024 at 03:03:04PM +0100, Christian König wrote:

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

Quoted 7 lines

Could you elaborate, what is that a problem in that, exactly?

It's pretty much the equivalent of ptrace() poke/peek but for GPU memory.

Exactly that here. You try to debug the GPU without taking control of the CPU process.

You seem to have a built-in expectation that the CPU threads and memory space must be interfered with in order to debug a completely different set of threads and memory space elsewhere that executes independently. I don't quite see why?

In debugging massively parallel workloads, it's a huge drawback to be limited to stop all mode in GDB. If ROCm folks are fine with such limitation, I have nothing against them keeping that limitation. Just it was a starting design principle for this design to avoid such a limitation.

Quoted 2 lines

This means that you have to re-implement all debug functionalities which where previously invested for the CPU process for the GPU once more.

Seems like a strawman argument. Can you list the "all interfaces" being added that would be possible via indirection via ptrace() beyond peek/poke?

Quoted 3 lines

And that in turn creates a massive attack surface for security related problems, especially when you start messing with things like userptrs which have a very low level interaction with core memory management.

Again, just seems like a strawman argument. You seem to generalize to some massive attack surface of hypothetical interfaces which you don't list. We're talking about memory peek/poke here.

Can you explain the high-level difference from security perspective for temporarily pinning userptr pages to write them to page tables for GPU to execute a dma-fence workload with and temporarily pinning pages for peek/poke?

Quoted 6 lines

And it is exactly the kind of interface that makes sense for debugger as GPU memory != CPU memory, and they don't need to align at all.

And that is what I strongly disagree on. When you debug the GPU it is mandatory to gain control of the CPU process as well.

You are free to disagree on that. I simply don't agree and have in this and previous email presented multiple reasons as to why not. We can agree to disagree on the topic.

Quoted 3 lines

The CPU process is basically the overseer of the GPU activity, so it should know everything about the GPU operation, for example what a mapping actually means.

How does that relate to what is being discussed here? You just seem to explain how you think userspace driver should work: Maintain a shadow tree of each ppGTT VM layout? I don't agree on that, but I think it is slightly irrelevant here.

Quoted 3 lines

The kernel driver and the hardware only have the information necessary to execute the work prepared by the CPU process. So the information available is limited to begin with.

And the point here is? Are you saying kernel does not know the actual mappings maintained in the GPU page tables?

Quoted 11 lines

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

I don't quite agree here -- at all. "Which CPU address is mapped to which GPU address" makes no sense when the GPU address space and CPU address space is completely controlled by the userspace driver/application.

Yeah, that's the reason why you should ask the userspace driver/application for the necessary information and not go over the kernel to debug things.

What hypothetical necessary information are you referring to exactly?

I already explained there are good reasons not to map all the GPU memory into the CPU address space.

Quoted 12 lines

Please try to consider things outside of the ROCm architecture.

Well I consider a good part of the ROCm architecture rather broken exactly because we haven't pushed back hard enough on bad ideas.

Something like a register scratch region or EU instructions should not even be mapped to CPU address space as CPU has no business accessing it during normal operation. And backing of such region will vary per context/LRC on the same virtual address per EU thread.

Quoted 7 lines

You seem to be suggesting to rewrite even our userspace driver to behave the same way as ROCm driver does just so that we could implement debug memory accesses via ptrace() to the CPU address space.

Oh, well certainly not. That ROCm has an 1 to 1 mapping between CPU and GPU is one thing I've pushed back massively on and has now proven to be problematic.

Right, so is your claim then that instead of being 1:1 the CPU address space should be a superset of all GPU address spaces instead to make sure ptrace() can modify all memory?

Cause I'm slightly lost here as you don't give much reasoning, just claim things to be certain way.

Quoted 10 lines

That seems bit of a radical suggestion, especially given the drawbacks pointed out in your suggested design.

The whole interface re-invents a lot of functionality which is already there

I'm not really sure I would call adding a single interface for memory reading and writing to be "re-inventing a lot of functionality".

Quoted 6 lines

All the functionality behind this interface will be needed by GPU core dumping, anyway. Just like for the other patch series.

As far as I can see exactly that's an absolutely no-go. Device core dumping should *never ever* touch memory imported by userptrs.

Could you again elaborate on what the great difference is to short term pinning to use in dma-fence workloads? Just the kmap?

Quoted 1 line

That's what process core dumping is good for.

Not really sure I agree. If you do not dump the memory as seen by the GPU, then you need to go parsing the CPU address space in order to make sense which buffers were mapped where and that CPU memory contents containing metadata could be corrupt as we're dealing with a crashing app to begin with.

Big point of relying to the information from GPU VM for the GPU memory layout is that it won't be corrupted by rogue memory accesses in CPU process.

Quoted 15 lines

just because you don't like the idea to attach to the debugged application in userspace.

A few points that have been brought up as drawback to the GPU debug through ptrace(), but to recap a few relevant ones for this discussion:

- You can only really support GDB stop-all mode or at least have to stop all the CPU threads while you control the GPU threads to avoid interference. Elaborated on this on the other threads more.
- Controlling the GPU threads will always interfere with CPU threads. Doesn't seem feasible to single-step an EU thread while CPU threads continue to run freely?

Quoted 1 line

I would say no.

Should this be understood that you agree these are limitations of the ROCm debug architecture?

Quoted 9 lines

- You are very much restricted by the CPU VA ~ GPU VA alignment requirement, which is not true for OpenGL or Vulkan etc. Seems like one of the reasons why ROCm debugging is not easily extendable outside compute?

Well as long as you can't take debugged threads from the hardware you can pretty much forget any OpenGL or Vulkan debugging with this interface since it violates the dma_fence restrictions in the kernel.

Agreed. However doesn't mean because you can't do it right now, you you should design an architecture that actively prevents you from doing that in the future.

Quoted 9 lines

- You have to expose extra memory to CPU process just for GPU debugger access and keep track of GPU VA for each. Makes the GPU more prone to OOB writes from CPU. Exactly what not mapping the memory to CPU tried to protect the GPU from to begin with.

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

Quoted 7 lines

I see it like reinventing a round wheel compared to octagonal wheel.

Could you elaborate with facts much more on your position why the ROCm debugger design is an absolute must for others to adopt?

Well I'm trying to prevent some of the mistakes we did with the ROCm design.

Well, I would say that the above limitations are direct results of the ROCm debugging design. So while we're eager to learn about how you perceive GPU debugging should work, would you mind addressing the above shortcomings?

Quoted 2 lines

And trying to re-invent well proven kernel interfaces is one of the big mistakes made in the ROCm design.

Appreciate the feedback. Please work on the representation a bit as it currently doesn't seem very helpful but appears just as an attempt to try to throw a spanner in the works.

Quoted 1 line

If you really want to expose an interface to userspace

To a debugger process, enabled only behind a flag.

Quoted 2 lines

which walks the process
page table, installs an MMU notifier

This part is already done to put an userptr to the GPU page tables to begin with. So hopefully not too controversial.

Quoted 1 line

kmaps the resulting page

In addition to having it in the page tables where GPU can access it.

Quoted 3 lines

and then memcpy
to/from it then you absolutely *must* run that by guys like Christoph Hellwig, Andrew and even Linus.

Surely, that is why we're seeking out for review.

We could also in theory use an in-kernel GPU context on the GPU hardware for doing the peek/poke operations on userptr.

But that seems like a high-overhead thing to do due to the overhead of setting up a transfer per data word and going over the PCI bus twice compared to accessing the memory directly by CPU when it trivially can.

So this is the current proposal.

Regards, Joonas

Quoted 21 lines

I'm pretty sure that those guys will note that a device driver should absolutely not mess with such stuff.

Regards,
Christian.

Otherwise it just looks like you are trying to prevent others from implementing a more flexible debugging interface through vague comments about "questionable design" without going into details. Not listing much concrete benefits nor addressing the very concretely expressed drawbacks of your suggested design, makes it seem like a very biased non-technical discussion.

So while review interest and any comments are very much appreciated, please also work on providing bit more reasoning and facts instead of just claiming things. That'll help make the discussion much more fruitful.

Regards, Joonas

#25 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Am 10.12.24 um 12:57 schrieb Joonas Lahtinen:

Quoted 37 lines

Quoting Christian König (2024-12-10 12:00:48)

Quoted 36 lines

Am 10.12.24 um 10:33 schrieb Joonas Lahtinen:

Quoting Christian König (2024-12-09 17:42:32)

Am 09.12.24 um 16:31 schrieb Simona Vetter:

On Mon, Dec 09, 2024 at 03:03:04PM +0100, Christian König wrote:

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

From: Andrzej Hajda<[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

Could you elaborate, what is that a problem in that, exactly?

Quoted 8 lines
Quoted 5 lines

It's pretty much the equivalent of ptrace() poke/peek but for GPU memory.

Exactly that here. You try to debug the GPU without taking control of the CPU process.

You seem to have a built-in expectation that the CPU threads and memory space must be interfered with in order to debug a completely different set of threads and memory space elsewhere that executes independently. I don't quite see why?

Because the GPU only gets the information it needs to execute the commands.

A simple example would be to single step through the high level shader code. That is usually not available to the GPU, but only to the application who has submitted the work.

The GPU only sees the result of the compiler from high level into low level assembler.

Quoted 4 lines

In debugging massively parallel workloads, it's a huge drawback to be limited to stop all mode in GDB. If ROCm folks are fine with such limitation, I have nothing against them keeping that limitation. Just it was a starting design principle for this design to avoid such a limitation.

Well, that's the part I don't understand. Why is that a drawback?

Quoted 11 lines
Quoted 2 lines

This means that you have to re-implement all debug functionalities which where previously invested for the CPU process for the GPU once more.

Seems like a strawman argument. Can you list the "all interfaces" being added that would be possible via indirection via ptrace() beyond peek/poke?

Quoted 3 lines

And that in turn creates a massive attack surface for security related problems, especially when you start messing with things like userptrs which have a very low level interaction with core memory management.

Again, just seems like a strawman argument. You seem to generalize to some massive attack surface of hypothetical interfaces which you don't list. We're talking about memory peek/poke here.

That peek/poke interface is more than enough to cause problems.

Quoted 4 lines

Can you explain the high-level difference from security perspective for temporarily pinning userptr pages to write them to page tables for GPU to execute a dma-fence workload with and temporarily pinning pages for peek/poke?

If you want to access userptr imported pages from the GPU going through the hops of using hhm_range_fault()/get_user_pages() plus an MMU notifier is a must have.

For a CPU based debugging interface that isn't necessary, you can just look directly into the application address space with existing interfaces.

Quoted 9 lines
Quoted 6 lines

And it is exactly the kind of interface that makes sense for debugger as GPU memory != CPU memory, and they don't need to align at all.

And that is what I strongly disagree on. When you debug the GPU it is mandatory to gain control of the CPU process as well.

You are free to disagree on that. I simply don't agree and have in this and previous email presented multiple reasons as to why not. We can agree to disagree on the topic.

Yeah, that's ok. I also think we can agree on that this doesn't matter for the discussion.

The question is rather should the userptr functionality be used for debugging or not.

Quoted 7 lines
Quoted 3 lines

The CPU process is basically the overseer of the GPU activity, so it should know everything about the GPU operation, for example what a mapping actually means.

How does that relate to what is being discussed here? You just seem to explain how you think userspace driver should work: Maintain a shadow tree of each ppGTT VM layout? I don't agree on that, but I think it is slightly irrelevant here.

I'm trying to understand why you want to debug only the GPU without also attaching to the CPU process.

Quoted 5 lines
Quoted 3 lines

The kernel driver and the hardware only have the information necessary to execute the work prepared by the CPU process. So the information available is limited to begin with.

And the point here is? Are you saying kernel does not know the actual mappings maintained in the GPU page tables?

The kernel knows that, the question is why does userspace don't know that?

On the other hand I have to agree that this isn't much of a problem.

If userspace really doesn't know what is mapped where in the GPU's VM address space then an IOCTL to query that is probably not an issue.

Quoted 4 lines
Quoted 4 lines

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

Quoted 8 lines
Quoted 7 lines

I don't quite agree here -- at all. "Which CPU address is mapped to which GPU address" makes no sense when the GPU address space and CPU address space is completely controlled by the userspace driver/application.

Yeah, that's the reason why you should ask the userspace driver/application for the necessary information and not go over the kernel to debug things.

What hypothetical necessary information are you referring to exactly?

What you said before: "the GPU address space and CPU address space is completely controlled by the userspace driver/application". When that's the case, then why as the kernel for help? The driver/application is in control.

Quoted 2 lines

I already explained there are good reasons not to map all the GPU memory into the CPU address space.

Well I still don't fully agree to that argumentation, but compared to using userptr the peek/pook on a GEM handle is basically harmless.

Quoted 17 lines
Quoted 17 lines

Please try to consider things outside of the ROCm architecture.

Well I consider a good part of the ROCm architecture rather broken exactly because we haven't pushed back hard enough on bad ideas.

Something like a register scratch region or EU instructions should not even be mapped to CPU address space as CPU has no business accessing it during normal operation. And backing of such region will vary per context/LRC on the same virtual address per EU thread.

You seem to be suggesting to rewrite even our userspace driver to behave the same way as ROCm driver does just so that we could implement debug memory accesses via ptrace() to the CPU address space.

Quoted 5 lines
Quoted 2 lines

Oh, well certainly not. That ROCm has an 1 to 1 mapping between CPU and GPU is one thing I've pushed back massively on and has now proven to be problematic.

Right, so is your claim then that instead of being 1:1 the CPU address space should be a superset of all GPU address spaces instead to make sure ptrace() can modify all memory?

Well why not? Mapping a BO and not accessing it has only minimal overhead.

We already considered to making that mandatory for TTM drivers for better OOM killer handling. That approach was discontinued, but certainly not for the overhead.

Quoted 2 lines

Cause I'm slightly lost here as you don't give much reasoning, just claim things to be certain way.

Ok, that's certainly not what I'm trying to express.

Things don't need to be in a certain way, especially not in the way ROCm does things.

But you should not try to re-create GPU accesses with the CPU, especially when that isn't memory you have control over in the sense that it was allocated through your driver stack.

Quoted 10 lines
Quoted 10 lines

That seems bit of a radical suggestion, especially given the drawbacks pointed out in your suggested design.

The whole interface re-invents a lot of functionality which is already there

I'm not really sure I would call adding a single interface for memory reading and writing to be "re-inventing a lot of functionality".

Quoted 8 lines
Quoted 6 lines

All the functionality behind this interface will be needed by GPU core dumping, anyway. Just like for the other patch series.

As far as I can see exactly that's an absolutely no-go. Device core dumping should *never ever* touch memory imported by userptrs.

Could you again elaborate on what the great difference is to short term pinning to use in dma-fence workloads? Just the kmap?

The big difference is that the memory doesn't belong to the driver who is core dumping.

That is just something you have imported from the MM subsystem, e.g. anonymous memory and file backed mappings.

We also don't allow to mmap() dma-bufs on importing devices for similar reasons.

Quoted 8 lines
Quoted 1 line

That's what process core dumping is good for.

Not really sure I agree. If you do not dump the memory as seen by the GPU, then you need to go parsing the CPU address space in order to make sense which buffers were mapped where and that CPU memory contents containing metadata could be corrupt as we're dealing with a crashing app to begin with.

Big point of relying to the information from GPU VM for the GPU memory layout is that it won't be corrupted by rogue memory accesses in CPU process.

Well that you don't want to use potentially corrupted information is a good argument, but why just not dump an information like "range 0xabcd-0xbcde came as userptr from process 1 VMA 0x1234-0x5678" ?

A process address space is not really something a device driver should be messing with.

Quoted 16 lines
Quoted 16 lines

just because you don't like the idea to attach to the debugged application in userspace.

A few points that have been brought up as drawback to the GPU debug through ptrace(), but to recap a few relevant ones for this discussion:

- You can only really support GDB stop-all mode or at least have to stop all the CPU threads while you control the GPU threads to avoid interference. Elaborated on this on the other threads more.
- Controlling the GPU threads will always interfere with CPU threads. Doesn't seem feasible to single-step an EU thread while CPU threads continue to run freely?

Quoted 3 lines
Quoted 1 line

I would say no.

Should this be understood that you agree these are limitations of the ROCm debug architecture?

ROCm has a bunch of design decisions I would say we should never ever repeat:

1. Forcing a 1 to 1 model between GPU address space and CPU address space.

2. Using a separate file descriptor additional to the DRM render node.

3. Attaching information and context to the CPU process instead of the DRM render node.
....

But stopping the world, e.g. both CPU and GPU threads if you want to debug something is not one of the problematic decisions.

That's why I'm really surprised that you insist so much on that.

Quoted 11 lines
Quoted 9 lines

- You are very much restricted by the CPU VA ~ GPU VA alignment requirement, which is not true for OpenGL or Vulkan etc. Seems like one of the reasons why ROCm debugging is not easily extendable outside compute?

Well as long as you can't take debugged threads from the hardware you can pretty much forget any OpenGL or Vulkan debugging with this interface since it violates the dma_fence restrictions in the kernel.

Agreed. However doesn't mean because you can't do it right now, you you should design an architecture that actively prevents you from doing that in the future.

Good point. That's what I can totally agree on as well.

Quoted 15 lines
Quoted 15 lines

- You have to expose extra memory to CPU process just for GPU debugger access and keep track of GPU VA for each. Makes the GPU more prone to OOB writes from CPU. Exactly what not mapping the memory to CPU tried to protect the GPU from to begin with.

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

I see it like reinventing a round wheel compared to octagonal wheel.

Could you elaborate with facts much more on your position why the ROCm debugger design is an absolute must for others to adopt?

Quoted 5 lines
Quoted 1 line

Well I'm trying to prevent some of the mistakes we did with the ROCm design.

Well, I would say that the above limitations are direct results of the ROCm debugging design. So while we're eager to learn about how you perceive GPU debugging should work, would you mind addressing the above shortcomings?

Yeah, absolutely. That you don't have a 1 to 1 mapping on the GPU is a step in the right direction if you ask me.

Quoted 17 lines
Quoted 2 lines

And trying to re-invent well proven kernel interfaces is one of the big mistakes made in the ROCm design.

Appreciate the feedback. Please work on the representation a bit as it currently doesn't seem very helpful but appears just as an attempt to try to throw a spanner in the works.

Quoted 1 line

If you really want to expose an interface to userspace

To a debugger process, enabled only behind a flag.

Quoted 2 lines

which walks the process
page table, installs an MMU notifier

This part is already done to put an userptr to the GPU page tables to begin with. So hopefully not too controversial.

Quoted 1 line

kmaps the resulting page

In addition to having it in the page tables where GPU can access it.

Quoted 7 lines
Quoted 3 lines

and then memcpy
to/from it then you absolutely *must* run that by guys like Christoph Hellwig, Andrew and even Linus.

Surely, that is why we're seeking out for review.

We could also in theory use an in-kernel GPU context on the GPU hardware for doing the peek/poke operations on userptr.

Yeah, I mean that should clearly work out. We have something similar.

Quoted 3 lines

But that seems like a high-overhead thing to do due to the overhead of setting up a transfer per data word and going over the PCI bus twice compared to accessing the memory directly by CPU when it trivially can.

Understandable, but that will create another way of accessing process memory.

Regards,
Christian.

Quoted 25 lines

So this is the current proposal.

Regards, Joonas

Quoted 20 lines

I'm pretty sure that those guys will note that a device driver should absolutely not mess with such stuff.

Regards,
Christian.

Otherwise it just looks like you are trying to prevent others from implementing a more flexible debugging interface through vague comments about "questionable design" without going into details. Not listing much concrete benefits nor addressing the very concretely expressed drawbacks of your suggested design, makes it seem like a very biased non-technical discussion.

So while review interest and any comments are very much appreciated, please also work on providing bit more reasoning and facts instead of just claiming things. That'll help make the discussion much more fruitful.

Regards, Joonas

#26 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

First of all, do appreciate taking the time to explain your positions much more verbosely this time.

Quoting Christian König (2024-12-10 16:03:14)

Quoted 46 lines

Am 10.12.24 um 12:57 schrieb Joonas Lahtinen:

Quoting Christian König (2024-12-10 12:00:48)

Am 10.12.24 um 10:33 schrieb Joonas Lahtinen:

Quoting Christian König (2024-12-09 17:42:32)

Am 09.12.24 um 16:31 schrieb Simona Vetter:

On Mon, Dec 09, 2024 at 03:03:04PM +0100, Christian König wrote:

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

Could you elaborate, what is that a problem in that, exactly?

It's pretty much the equivalent of ptrace() poke/peek but for GPU memory.

Exactly that here. You try to debug the GPU without taking control of the CPU process.

Quoted 6 lines

You seem to have a built-in expectation that the CPU threads and memory space must be interfered with in order to debug a completely different set of threads and memory space elsewhere that executes independently. I don't quite see why?

Because the GPU only gets the information it needs to execute the commands.

Right, but even for the CPU process, the debug symbols are not part of the execution address space either. There similarly are only the instructions generated by the compiler and the debug symbols are separate. They may be obtainable by parsing /proc/<PID>/exe but can also be in a completely different file in a different host machine.

Quoted 6 lines

A simple example would be to single step through the high level shader code. That is usually not available to the GPU, but only to the application who has submitted the work.

The GPU only sees the result of the compiler from high level into low level assembler.

If we were to have unified executable format where both the GPU and CPU instructions were to be part of the single executable file, so could the DWARF information for both CPU and GPU.

Then GDB, by loading the executable file, would have all the debug information it needed. No need to introspect to the CPU process in order to debug the GPU, similarly as there is no need to introspect CPU process to debug CPU process.

While we don't currently have that and GPU instructions are often JIT generated, we tried to make life easier by userspace driver providing the DWARF information it just generated for the code it JITed as VM_BIND metadata for a VMA and we make copy to store safely to avoid corruption by rogue CPU process writes.

In the history it was exported to a file and then loaded by GDB from that separate file, making user experience quite bad.

So to recap, while for JIT scenarios and for lack of unified carrier format for GPU and CPU instructions, there is some information that is convenient to have in CPU address space, I don't think that is a necessity at all. I guess we could equally export /sys/class/drm/.../clients/<ID>/{load_map,dwarf_symbols} or whatever, similar to /proc/<PID>/{maps,exe}.

TL;DR While getting the information from CPU process for JIT scenarios is convenient for now, I don't think it is a must or explicitly required.

Quoted 7 lines

In debugging massively parallel workloads, it's a huge drawback to be limited to stop all mode in GDB. If ROCm folks are fine with such limitation, I have nothing against them keeping that limitation. Just it was a starting design principle for this design to avoid such a limitation.

Well, that's the part I don't understand. Why is that a drawback?

Hmm, same as for not supporting stop-all mode for CPU threads during CPU debugging? You will not be able to stop and observe a single thread while letting the other threads run.

If the CPU threads are for example supposed to react to memory semaphores/fences written by GPU thread and you want to debug by doing those memory writes from GPU thread from the GDB command line?

Again not being limited to stop-all mode being an input to the design phase from the folks doing in-field debugging, I'm probably not going to be able to give out all the good reasons for it.

And as the CPU side supports it, even if you did not support it for the GPU debugging, if adding GPU to the equation would prevent from using the existing feature for CPU debugging that feels like a regression in user experience.

I think those both are major drawbacks, but we can of course seek out further opinions if it's highly relevant. I'm pretty sure myself at this point that if a feature is desireable for CPU threaded debugging, it'll be very shortly asked to be available for GPU.

That seems to be the trend for any CPU debug feature, even if some are less feasible than others due to the differences of GPUs and CPUs.

Quoted 11 lines

This means that you have to re-implement all debug functionalities which where previously invested for the CPU process for the GPU once more.

Seems like a strawman argument. Can you list the "all interfaces" being added that would be possible via indirection via ptrace() beyond peek/poke?

And that in turn creates a massive attack surface for security related problems, especially when you start messing with things like userptrs which have a very low level interaction with core memory management.

Quoted 6 lines

Again, just seems like a strawman argument. You seem to generalize to some massive attack surface of hypothetical interfaces which you don't list. We're talking about memory peek/poke here.

That peek/poke interface is more than enough to cause problems.

Ok, just wanted to make sure we're talking about concrete things. Happy to discuss any other problems too, but for now let's focus on the peek/poke then, and not get sidetracked.

Quoted 9 lines

Can you explain the high-level difference from security perspective for temporarily pinning userptr pages to write them to page tables for GPU to execute a dma-fence workload with and temporarily pinning pages for peek/poke?

If you want to access userptr imported pages from the GPU going through the hops of using hhm_range_fault()/get_user_pages() plus an MMU notifier is a must have.

Right, the intent was always to make this as close to EU thread memory access as possible from both locking and Linux core MM memory point of view so if we need to improve on that front, we should look into it.

Quoted 2 lines

For a CPU based debugging interface that isn't necessary, you can just look directly into the application address space with existing interfaces.

First, this is only even possible when you have mapped everything the GPUs have access also to the CPU address space, and maintain a load map for each individual <DRM client, GPU VM, GPU VMA> => CPU address.

I don't see the need to do that tracking in the userspace just for debugging, because kernel already has to do all the work.

Second, mapping every GPU VMA to CPU address space will exhaust the vm.max_map_count [1] quite a bit faster. This problem can already be hit if a naive userspace application tries to create too many aligned_alloc blocks for userptr instead of pooling memory.

Third of all when GPU VM size == CPU VM size for modern hardware, you will run out of VA space in the CPU VM. When you consider you have to add VA blocks of (num DRM clients) * (num VM) * (VM size) where (num VM) roughly equals number of engines * 3.

And ultimately, I'm pretty sure there are processes like 32-bit games and emulators, and even demanding compute applications actually expect to be able to use most of the CPU address space :) So don't think we should have a design where we expect to be able to consume significant portions of the CPU VA space (especially if it is just for debug time functionality).

[1] Documentation/admin-guide/sysctl/vm.rst#max_map_count

Quoted 23 lines

And it is exactly the kind of interface that makes sense for debugger as GPU memory != CPU memory, and they don't need to align at all.

And that is what I strongly disagree on. When you debug the GPU it is mandatory to gain control of the CPU process as well.

You are free to disagree on that. I simply don't agree and have in this and previous email presented multiple reasons as to why not. We can agree to disagree on the topic.

Yeah, that's ok. I also think we can agree on that this doesn't matter for the discussion.

The question is rather should the userptr functionality be used for debugging or not.

The CPU process is basically the overseer of the GPU activity, so it should know everything about the GPU operation, for example what a mapping actually means.

Quoted 8 lines

How does that relate to what is being discussed here? You just seem to explain how you think userspace driver should work: Maintain a shadow tree of each ppGTT VM layout? I don't agree on that, but I think it is slightly irrelevant here.

I'm trying to understand why you want to debug only the GPU without also attaching to the CPU process.

Mostly to ensure we're not limited to stop-all mode as described above and to have a clean independent implementation for the thread run-control between the "inferiors" in GDB. Say you have CPU threads and 2 sets of GPU threads (3 inferiors in total). We don't want the CPU inferior to be impacted by the user requesting to control the GPU inferiors.

I know the ROCm GDB implementation takes a different approach, and I'm not quite sure how you folks plan on supporting multi-GPU debugging.

I would spin the question the opposite direction, if you don't need anything from the CPU process why would you make them dependent and interfering?

(Reminder, the peek/poke target page has been made available to the GPU page tables, so we don't want anything from the CPU process per se, we want to know which page the GPU IOMMU unit would get for its access.

For all practical matters, the CPU process could have already exited and should not matter if an EU is executing on the GPU still.)

Quoted 27 lines

The kernel driver and the hardware only have the information necessary to execute the work prepared by the CPU process. So the information available is limited to begin with.

And the point here is? Are you saying kernel does not know the actual mappings maintained in the GPU page tables?

The kernel knows that, the question is why does userspace don't know that?

On the other hand I have to agree that this isn't much of a problem.

If userspace really doesn't know what is mapped where in the GPU's VM address space then an IOCTL to query that is probably not an issue.

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

I don't quite agree here -- at all. "Which CPU address is mapped to which GPU address" makes no sense when the GPU address space and CPU address space is completely controlled by the userspace driver/application.

Yeah, that's the reason why you should ask the userspace driver/application for the necessary information and not go over the kernel to debug things.

Quoted 6 lines

What hypothetical necessary information are you referring to exactly?

What you said before: "the GPU address space and CPU address space is completely controlled by the userspace driver/application". When that's the case, then why as the kernel for help? The driver/application is in control.

I guess the emphasis should have been on the application part. Debugger can agree with userspace driver on conventions to facilitate debugging, but not with the application code.

However, agree that query IOCTL could be avoided maintaining a shadow address space tracking in case ptrace() approach to debugging was otherwise favorable.

Quoted 6 lines

I already explained there are good reasons not to map all the GPU memory into the CPU address space.

Well I still don't fully agree to that argumentation, but compared to using userptr the peek/pook on a GEM handle is basically harmless.

(Sidenote: We don't expose BO handles at all via debugger interface. The debugger interface fully relies on GPU addresses for everything.)

But sounds like we're coming towards a conclusion that the focus of the discussion is only really on the controversy of touching userptr with the debugger peek/poke interface or not.

Quoted 25 lines

Please try to consider things outside of the ROCm architecture.

Well I consider a good part of the ROCm architecture rather broken exactly because we haven't pushed back hard enough on bad ideas.

Something like a register scratch region or EU instructions should not even be mapped to CPU address space as CPU has no business accessing it during normal operation. And backing of such region will vary per context/LRC on the same virtual address per EU thread.

You seem to be suggesting to rewrite even our userspace driver to behave the same way as ROCm driver does just so that we could implement debug memory accesses via ptrace() to the CPU address space.

Oh, well certainly not. That ROCm has an 1 to 1 mapping between CPU and GPU is one thing I've pushed back massively on and has now proven to be problematic.

Right, so is your claim then that instead of being 1:1 the CPU address space should be a superset of all GPU address spaces instead to make sure ptrace() can modify all memory?

Quoted 5 lines

Well why not? Mapping a BO and not accessing it has only minimal overhead.

We already considered to making that mandatory for TTM drivers for better OOM killer handling. That approach was discontinued, but certainly not for the overhead.

I listed the reasons earlier in this message.

Quoted 4 lines

Cause I'm slightly lost here as you don't give much reasoning, just claim things to be certain way.

Quoted 8 lines

Ok, that's certainly not what I'm trying to express.

Things don't need to be in a certain way, especially not in the way ROCm does things.

But you should not try to re-create GPU accesses with the CPU, especially when that isn't memory you have control over in the sense that it was allocated through your driver stack.

I guess thats what I don't quite follow.

It's memory pages that are temporarily pinned and made available via GPU PTE to the GPU IOMMU and it will inherently be able to read/write them outside of the CPU caching domain.

Not sure why replacing "Submit GPU workload to peek/poke such page pinned behind PTE" with "Use CPU to peek/poke because userptr is system memory anyway" seems such controversial and could cause much more complexity than userptr in general?

Quoted 17 lines

That seems bit of a radical suggestion, especially given the drawbacks pointed out in your suggested design.

The whole interface re-invents a lot of functionality which is already there

I'm not really sure I would call adding a single interface for memory reading and writing to be "re-inventing a lot of functionality".

All the functionality behind this interface will be needed by GPU core dumping, anyway. Just like for the other patch series.

As far as I can see exactly that's an absolutely no-go. Device core dumping should *never ever* touch memory imported by userptrs.

Quoted 6 lines

Could you again elaborate on what the great difference is to short term pinning to use in dma-fence workloads? Just the kmap?

The big difference is that the memory doesn't belong to the driver who is core dumping.

But the driver who is core dumping is holding a temporary pin on that memory anyway, and has it in the GPU page tables.

The CPU side of the memory dump would only reflect what was the CPU side memory contents at a dump time. It may have different contents of the GPU side depending on cache flush timing. Maybe this will not be true when CXL or some other coherency protocl is everywhere, but for now it is.

So those two memory dumps may actually have different contents, and that might actually be the bug we're trying to debug. For GPU debugging, we're specifically interested on what was the GPU threads view of the memory.

So I think it is more complex than that.

Quoted 5 lines

That is just something you have imported from the MM subsystem, e.g. anonymous memory and file backed mappings.

We also don't allow to mmap() dma-bufs on importing devices for similar reasons.

That is a reasonable limitation for userspace applications.

And at no point has there been suggestions to expose such API for normal userspace to shoot itself in the foot.

However debugger is not an average userspace consumer. For an example, it needs to be able modify read-only memory (like the EU instructions) and then do special cache flushes to magically change those instructions.

I wouldn't want to expose such a functionality as regular IOCTL for an application.

Quoted 7 lines

That's what process core dumping is good for.

Not really sure I agree. If you do not dump the memory as seen by the GPU, then you need to go parsing the CPU address space in order to make sense which buffers were mapped where and that CPU memory contents containing metadata could be corrupt as we're dealing with a crashing app to begin with.

Quoted 7 lines

Big point of relying to the information from GPU VM for the GPU memory layout is that it won't be corrupted by rogue memory accesses in CPU process.

Well that you don't want to use potentially corrupted information is a good argument, but why just not dump an information like "range 0xabcd-0xbcde came as userptr from process 1 VMA 0x1234-0x5678" ?

I guess that could be done for interactive debugging (but would again add the ptrace() dependency).

In theory you could probably also come up with such a convention for ELF to support core dumps I guess, but I would have to refer to some folks more knowledgeable on the topic.

Feels like that would make things more complex via indirection compared to existing memory maps.

Quoted 33 lines

A process address space is not really something a device driver should be messing with.

just because you don't like the idea to attach to the debugged application in userspace.

A few points that have been brought up as drawback to the GPU debug through ptrace(), but to recap a few relevant ones for this discussion:

- You can only really support GDB stop-all mode or at least have to stop all the CPU threads while you control the GPU threads to avoid interference. Elaborated on this on the other threads more.
- Controlling the GPU threads will always interfere with CPU threads. Doesn't seem feasible to single-step an EU thread while CPU threads continue to run freely?

I would say no.

Should this be understood that you agree these are limitations of the ROCm debug architecture?

ROCm has a bunch of design decisions I would say we should never ever repeat:

1. Forcing a 1 to 1 model between GPU address space and CPU address space.

2. Using a separate file descriptor additional to the DRM render node.

Quoted 8 lines

3. Attaching information and context to the CPU process instead of the DRM render node.
....

But stopping the world, e.g. both CPU and GPU threads if you want to debug something is not one of the problematic decisions.

That's why I'm really surprised that you insist so much on that.

I'm hoping the above explanations clarify my position further.

Again, I would ask myself: "Why add a dependency that is not needed?"

Quoted 34 lines

- You are very much restricted by the CPU VA ~ GPU VA alignment requirement, which is not true for OpenGL or Vulkan etc. Seems like one of the reasons why ROCm debugging is not easily extendable outside compute?

Well as long as you can't take debugged threads from the hardware you can pretty much forget any OpenGL or Vulkan debugging with this interface since it violates the dma_fence restrictions in the kernel.

Agreed. However doesn't mean because you can't do it right now, you you should design an architecture that actively prevents you from doing that in the future.

Good point. That's what I can totally agree on as well.

- You have to expose extra memory to CPU process just for GPU debugger access and keep track of GPU VA for each. Makes the GPU more prone to OOB writes from CPU. Exactly what not mapping the memory to CPU tried to protect the GPU from to begin with.

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

I see it like reinventing a round wheel compared to octagonal wheel.

Could you elaborate with facts much more on your position why the ROCm debugger design is an absolute must for others to adopt?

Well I'm trying to prevent some of the mistakes we did with the ROCm design.

Quoted 8 lines

Well, I would say that the above limitations are direct results of the ROCm debugging design. So while we're eager to learn about how you perceive GPU debugging should work, would you mind addressing the above shortcomings?

Yeah, absolutely. That you don't have a 1 to 1 mapping on the GPU is a step in the right direction if you ask me.

Right, that is to have a possibility of extending to OpenGL/Vulkan etc.

Quoted 29 lines

And trying to re-invent well proven kernel interfaces is one of the big mistakes made in the ROCm design.

Appreciate the feedback. Please work on the representation a bit as it currently doesn't seem very helpful but appears just as an attempt to try to throw a spanner in the works.

If you really want to expose an interface to userspace

To a debugger process, enabled only behind a flag.

which walks the process
page table, installs an MMU notifier

This part is already done to put an userptr to the GPU page tables to begin with. So hopefully not too controversial.

kmaps the resulting page

In addition to having it in the page tables where GPU can access it.

and then memcpy
to/from it then you absolutely *must* run that by guys like Christoph Hellwig, Andrew and even Linus.

Quoted 7 lines

Surely, that is why we're seeking out for review.

We could also in theory use an in-kernel GPU context on the GPU hardware for doing the peek/poke operations on userptr.

Yeah, I mean that should clearly work out. We have something similar.

Right, and that might actually be desireable for the more special GPU VMA like interconnect addresses.

However userptr is one of the items where it makes least sense, given we'd have to set up the transfer over bus, the transfer would read system memory over bus and write the result back to system memory over bus.

And this is just to avoid kmap'ing a page that would otherwise be already temporarily pinned for being in the PTEs.

I'm not saying it can't be done, but I just don't feel like it's a technically sound solution.

Quoted 6 lines

But that seems like a high-overhead thing to do due to the overhead of setting up a transfer per data word and going over the PCI bus twice compared to accessing the memory directly by CPU when it trivially can.

Understandable, but that will create another way of accessing process memory.

Well, we hopefully should be able to align with the regular temporary pinning and making page available to PTEs, but instead of making available to PTEs, do a peek/poke and then release the page already.

I'm kind of hoping to build the case for it making a lot of sense for peek/poke performance (which is important for single-stepping), and should not be a burden due to new locking chains.

And thanks once again for taking the time to share the details behind the thinking and bearing with all my questions.

It seems like the peek/poke access to userptr is the big remaining open where opinions differ, so maybe we should first focus on aligning on it. It impacts both core dumping and interactive debugging.

Regards, Joonas

Quoted 33 lines

Regards,
Christian.

So this is the current proposal.

Regards, Joonas

I'm pretty sure that those guys will note that a device driver should absolutely not mess with such stuff.

Regards,
Christian.

Otherwise it just looks like you are trying to prevent others from implementing a more flexible debugging interface through vague comments about "questionable design" without going into details. Not listing much concrete benefits nor addressing the very concretely expressed drawbacks of your suggested design, makes it seem like a very biased non-technical discussion.

So while review interest and any comments are very much appreciated, please also work on providing bit more reasoning and facts instead of just claiming things. That'll help make the discussion much more fruitful.

Regards, Joonas

#27 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Quoting Joonas Lahtinen (2024-12-11 14:59:33)

Quoted 1 line

Quoting Christian König (2024-12-10 16:03:14)

<SNIP>

Quoted 7 lines
Quoted 7 lines

If you really want to expose an interface to userspace which walks the process page table, installs an MMU notifier, kmaps the resulting page and then memcpy to/from it then you absolutely *must* run that by guys like Christoph Hellwig, Andrew and even Linus.

I'm pretty sure that those guys will note that a device driver should absolutely not mess with such stuff.

<SNIP>

Quoted 6 lines
Quoted 6 lines

But that seems like a high-overhead thing to do due to the overhead of setting up a transfer per data word and going over the PCI bus twice compared to accessing the memory directly by CPU when it trivially can.

Understandable, but that will create another way of accessing process memory.

Based on this feedback and some further discussion, we now have an alternative implementation for this interface via access_process_vm function posted by Mika:

https://lore.kernel.org/dri-devel/[email protected]/

It's a couple of dozen lines don't need to do any open-coded kmapping, only utilizing the pre-existing memory access functions.

Hopefully that would address the above concerns?

Regards, Joonas

PS. It could still be optimized further to directly use the struct mm from within the mm notifier, and go with access_remote_vm using that, but would require new symbol export.

For demonstration it is implemented by grabbing the task_struct and using the already exported access_process_vm function.

#28 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Quoted 20 lines · Joonas Lahtinen

Quoting Joonas Lahtinen (2024-12-11 14:59:33)

Quoted 1 line

Quoting Christian König (2024-12-10 16:03:14)

<SNIP>

Quoted 7 lines
Quoted 7 lines

If you really want to expose an interface to userspace which walks the process page table, installs an MMU notifier, kmaps the resulting page and then memcpy to/from it then you absolutely *must* run that by guys like Christoph Hellwig, Andrew and even Linus.

I'm pretty sure that those guys will note that a device driver should absolutely not mess with such stuff.

<SNIP>

Quoted 5 lines
Quoted 5 lines

But that seems like a high-overhead thing to do due to the overhead of setting up a transfer per data word and going over the PCI bus twice compared to accessing the memory directly by CPU when it trivially can.

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Understandable, but that will create another way of accessing process memory.

Based on this feedback and some further discussion, we now have an alternative implementation for this interface via access_process_vm function posted by Mika:

https://lore.kernel.org/dri-devel/[email protected]/

v2:
https://lore.kernel.org/dri-devel/[email protected]/
-Mika

Quoted 14 lines

It's a couple of dozen lines don't need to do any open-coded kmapping, only utilizing the pre-existing memory access functions.

Hopefully that would address the above concerns?

Regards, Joonas

PS. It could still be optimized further to directly use the struct mm from within the mm notifier, and go with access_remote_vm using that, but would require new symbol export.

For demonstration it is implemented by grabbing the task_struct and using the already exported access_process_vm function.

#29 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

In reply to Christian König
Quoted 13 lines · Christian König

Am 09.12.24 um 16:31 schrieb Simona Vetter:

Quoted 12 lines · Christian König
Quoted 11 lines

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 5 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma. Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML and the MM list as well.

First of all hmm_range_fault() does *not* pin anything!

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

In other words you don't have a page reference when the function returns, but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr.

Well that is part of the issue.

Yeah I ignored the other part, because that didn't seem super interesting really.

Like for compute you can make the architectural assumption that gpu addresses match cpu addresses, and this all becomes easy. Or at least easier, there's still the issue of having to call into the driver for gpu side flushes.

But for 3d userptr that's not the case, and you get two options:
- Have some tracking structure that umd and debugger agree on, so stable abi fun and all that, so you can find the mapping. And I think in some cases this would need to be added first.
- Just ask the kernel, which already knows.

Like for cpu mmaps we also don't inject tracking code into mmap/munmap, we just ask the kernel through /proc/pid/maps. This sounds like the same question, probably should have a similar answer.

I guess you can do a bit a bikeshed about whether the kernel should only do the address translation and then you do a ptrace poke/peek for the actual access. But again you need some flushes, so this might be a bit silly.

But fundamentally this makes sense to me to ask the entity that actually knows how userptr areas map to memory.
-Sima

Quoted 132 lines

The general problem here is that the eudebug interface tries to simulate the memory accesses as they would have happened by the hardware.

What the debugger should probably do is to cleanly attach to the application, get the information which CPU address is mapped to which GPU address and then use the standard ptrace interfaces.

The whole interface re-invents a lot of functionality which is already there just because you don't like the idea to attach to the debugged application in userspace.

As far as I can see this whole idea is extremely questionable. This looks like re-inventing the wheel in a different color.

Regards,
Christian.

Quoted 113 lines

Probably time
we standardize that and put it into gpuvm as an optional part, with consistent locking, naming (like not calling it _pin_pages when it's unpinnged userptr), kerneldoc and all the nice things so that we stop consistently getting confused by other driver's userptr code.

I think that was on the plan originally as an eventual step, I guess time to pump that up. Matt/Thomas, thoughts?
-Sima

Quoted 103 lines
Quoted 56 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
- s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
   drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
   drivers/gpu/drm/xe/xe_vm.c      | 47 +++++++++++++++++++++++++++++++++
   drivers/gpu/drm/xe/xe_vm.h      |  3 +++
   3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
   		return ret;
   	}
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma), offset_in_vma,
+				    buf, bytes, write);
   }
   static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +22 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot *snap)
   	}
   	kvfree(snap);
   }
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write)
+{
+	struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+	struct xe_userptr *up = &uvma->userptr;
+	struct xe_res_cursor cur = {};
+	int cur_len, ret = 0;
+
+	while (true) {
+		down_read(&vm->userptr.notifier_lock);
+		if (!xe_vma_userptr_check_repin(uvma))
+			break;
+
+		spin_lock(&vm->userptr.invalidated_lock);
+		list_del_init(&uvma->userptr.invalidate_link);
+		spin_unlock(&vm->userptr.invalidated_lock);
+
+		up_read(&vm->userptr.notifier_lock);
+		ret = xe_vma_userptr_pin_pages(uvma);
+		if (ret)
+			return ret;

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3448

Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +10 -0
+	}
+
+	if (!up->sg) {
+		ret = -EINVAL;
+		goto out_unlock_notifier;
+	}
+
+	for (xe_res_first_sg_system(up->sg, offset, len, &cur); cur.remaining;
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) + cur.start;

The interface basically creates a side channel to access userptrs in the way an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	ret = len;
+
+out_unlock_notifier:
+	up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +2 -0
+	return ret;
+}
drivers/gpu/drm/xe/xe_vm.h +3 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
   void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
   void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
   void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
+			 void *buf, u64 len, bool write);
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#30 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

In reply to Simona Vetter
Quoted 31 lines · Simona Vetter
Quoted 12 lines · Christian König

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 6 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma.
Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML
and the MM list as well.

Quoted 5 lines

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns,
but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical
access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr. Probably time
we standardize that and put it into gpuvm as an optional part, with consistent locking, naming (like not calling it _pin_pages when it's unpinnged userptr), kerneldoc and all the nice things so that we stop consistently getting confused by other driver's userptr code.

Quoted 3 lines

I think that was on the plan originally as an eventual step, I guess time
to pump that up. Matt/Thomas, thoughts?

It looks like we have this planned and ongoing but there are some complications and thoughts.

1) A drm_gpuvm implementation would be based on vma userptrs, and would be pretty straightforward based on xe's current implementation and, as you say, renaming.

2) Current Intel work to land this on the drm level is based on drm_gpusvm (minus migration to VRAM). I'm not fully sure yet how this will integrate with drm_gpuvm.

3) Christian mentioned a plan to have a common userptr implementation based off drm_exec. I figure that would be bo-based like the amdgpu implemeentation still is. Possibly i915 would be interested in this but I think any VM_BIND based driver would want to use drm_gpuvm / drm_gpusvm implementation, which is also typically O(1), since userptrs are considered vm-local.

Ideas / suggestions welcome

Quoted 129 lines

-Sima

Quoted 126 lines
Quoted 76 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
     - s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
  drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
  drivers/gpu/drm/xe/xe_vm.c      | 47
+++++++++++++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_vm.h      |  3 +++

  3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct
 xe_vma *vma, u64 offset_in_vma,
   		return ret;
   	}
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma),
 offset_in_vma,
+				    buf, bytes, write);
   }
   static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +0 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct
 xe_vm_snapshot *snap)
   	}
   	kvfree(snap);

  }

drivers/gpu/drm/xe/xe_vm.c +2 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64

offset,

drivers/gpu/drm/xe/xe_vm.c +28 -0
+			 void *buf, u64 len, bool write)
+{
+	struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+	struct xe_userptr *up = &uvma->userptr;
+	struct xe_res_cursor cur = {};
+	int cur_len, ret = 0;
+
+	while (true) {
+		down_read(&vm->userptr.notifier_lock);
+		if (!xe_vma_userptr_check_repin(uvma))
+			break;
+
+		spin_lock(&vm->userptr.invalidated_lock);
+		list_del_init(&uvma->userptr.invalidate_link);
+		spin_unlock(&vm->userptr.invalidated_lock);
+
+		up_read(&vm->userptr.notifier_lock);
+		ret = xe_vma_userptr_pin_pages(uvma);
+		if (ret)
+			return ret;
+	}
+
+	if (!up->sg) {
+		ret = -EINVAL;
+		goto out_unlock_notifier;
+	}
+
+	for (xe_res_first_sg_system(up->sg, offset, len, &cur);

cur.remaining;

drivers/gpu/drm/xe/xe_vm.c +2 -0
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) +
Quoted 1 line

cur.start;

The interface basically creates a side channel to access userptrs in the way
an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I
can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	ret = len;
+
+out_unlock_notifier:
+	up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 18 lines
drivers/gpu/drm/xe/xe_vm.c +2 -0
+	return ret;
+}
drivers/gpu/drm/xe/xe_vm.h +0 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot
 *xe_vm_snapshot_capture(struct xe_vm *vm);

  void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
  void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
  void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);

drivers/gpu/drm/xe/xe_vm.h +2 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64

offset,

drivers/gpu/drm/xe/xe_vm.h +1 -0
+			 void *buf, u64 len, bool write);
#31 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Quoted 47 lines · Thomas Hellström
Quoted 31 lines · Simona Vetter
Quoted 12 lines · Christian König

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 6 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma.
Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML
and the MM list as well.

Quoted 5 lines

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns,
but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical
access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr. Probably time
we standardize that and put it into gpuvm as an optional part, with consistent locking, naming (like not calling it _pin_pages when it's unpinnged userptr), kerneldoc and all the nice things so that we stop consistently getting confused by other driver's userptr code.

Quoted 3 lines

I think that was on the plan originally as an eventual step, I guess time
to pump that up. Matt/Thomas, thoughts?

It looks like we have this planned and ongoing but there are some complications and thoughts.

1) A drm_gpuvm implementation would be based on vma userptrs, and would be pretty straightforward based on xe's current implementation and, as you say, renaming.

2) Current Intel work to land this on the drm level is based on drm_gpusvm (minus migration to VRAM). I'm not fully sure yet how this will integrate with drm_gpuvm.

Quoted 8 lines

3) Christian mentioned a plan to have a common userptr implementation based off drm_exec. I figure that would be bo-based like the amdgpu implemeentation still is. Possibly i915 would be interested in this but I think any VM_BIND based driver would want to use drm_gpuvm / drm_gpusvm implementation, which is also typically O(1), since userptrs are considered vm-local.

Ideas / suggestions welcome

So just discussed this a bit with Joonas, and if we use access_remote_vm for the userptr access instead of hand-rolling then we really only need bare-bones data structure changes in gpuvm, and nothing more. So

- add the mm pointer to struct drm_gpuvm
- add a flag indicating that it's a userptr + userspace address to struct drm_gpuva
- since we already have userptr in drivers I guess there should be any need to adjust the actual drm_gpuvm code to cope with these

Then with this you can write the access helper using access_remote_vm since that does the entire remote mm walking internally, and so there's no need to also have all the mmu notifier and locking lifted to gpuvm. But it does already give us some great places to put relevant kerneldocs (not just for debugging architecture, but userptr stuff in general), which is already a solid step forward.

Plus I think it'd would also be a solid first step that we need no matter what for figuring out the questions/options you have above.

Thoughts?
-Sima

Quoted 131 lines
Quoted 130 lines

-Sima

Quoted 126 lines
Quoted 76 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
     - s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
  drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
  drivers/gpu/drm/xe/xe_vm.c      | 47
+++++++++++++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_vm.h      |  3 +++

  3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct
 xe_vma *vma, u64 offset_in_vma,
   		return ret;
   	}
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma),
 offset_in_vma,
+				    buf, bytes, write);
   }
   static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +0 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct
 xe_vm_snapshot *snap)
   	}
   	kvfree(snap);

  }

drivers/gpu/drm/xe/xe_vm.c +2 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64

offset,

drivers/gpu/drm/xe/xe_vm.c +28 -0
+			 void *buf, u64 len, bool write)
+{
+	struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+	struct xe_userptr *up = &uvma->userptr;
+	struct xe_res_cursor cur = {};
+	int cur_len, ret = 0;
+
+	while (true) {
+		down_read(&vm->userptr.notifier_lock);
+		if (!xe_vma_userptr_check_repin(uvma))
+			break;
+
+		spin_lock(&vm->userptr.invalidated_lock);
+		list_del_init(&uvma->userptr.invalidate_link);
+		spin_unlock(&vm->userptr.invalidated_lock);
+
+		up_read(&vm->userptr.notifier_lock);
+		ret = xe_vma_userptr_pin_pages(uvma);
+		if (ret)
+			return ret;
+	}
+
+	if (!up->sg) {
+		ret = -EINVAL;
+		goto out_unlock_notifier;
+	}
+
+	for (xe_res_first_sg_system(up->sg, offset, len, &cur);

cur.remaining;

drivers/gpu/drm/xe/xe_vm.c +2 -0
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) +
Quoted 1 line

cur.start;

The interface basically creates a side channel to access userptrs in the way
an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I
can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	ret = len;
+
+out_unlock_notifier:
+	up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 18 lines
drivers/gpu/drm/xe/xe_vm.c +2 -0
+	return ret;
+}
drivers/gpu/drm/xe/xe_vm.h +0 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot
 *xe_vm_snapshot_capture(struct xe_vm *vm);

  void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
  void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
  void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);

drivers/gpu/drm/xe/xe_vm.h +2 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64

offset,

drivers/gpu/drm/xe/xe_vm.h +1 -0
+			 void *buf, u64 len, bool write);
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
maintainer
#32 lore raw

Re: [PATCH 14/26] drm/xe/eudebug: implement userptr_vma access

Quoted 37 lines · Simona Vetter
Quoted 36 lines · Thomas Hellström
Quoted 34 lines · Simona Vetter
Quoted 12 lines · Christian König

Am 09.12.24 um 14:33 schrieb Mika Kuoppala:

Quoted 6 lines

From: Andrzej Hajda <[email protected]>

Debugger needs to read/write program's vmas including userptr_vma.
Since hmm_range_fault is used to pin userptr vmas, it is possible to map those vmas from debugger context.

Oh, this implementation is extremely questionable as well. Adding the LKML
and the MM list as well.

Quoted 5 lines

First of all hmm_range_fault() does *not* pin anything!

In other words you don't have a page reference when the function returns,
but rather just a sequence number you can check for modifications.

I think it's all there, holds the invalidation lock during the critical
access/section, drops it when reacquiring pages, retries until it works.

I think the issue is more that everyone hand-rolls userptr. Probably time
we standardize that and put it into gpuvm as an optional part, with consistent locking, naming (like not calling it _pin_pages when it's unpinnged userptr), kerneldoc and all the nice things so that we stop consistently getting confused by other driver's userptr code.

I think that was on the plan originally as an eventual step, I guess time
to pump that up. Matt/Thomas, thoughts?

Quoted 7 lines
Quoted 7 lines

It looks like we have this planned and ongoing but there are some complications and thoughts.

1) A drm_gpuvm implementation would be based on vma userptrs, and would be pretty straightforward based on xe's current implementation and, as you say, renaming.

My thoughts...

Standardize gpuvm userptrs gpuvmas a bit. In Xe I think we basically set the BO to NULL in the gpuvmas then have some helpers in Xe to determine if gpuvma is a userptr. I think some this code could be moved into gpuvm so drivers are doing this in a standard way.

I think NULL bindings also set te BO to NULL too, perhaps we standardize that too in gpuvm.

Quoted 4 lines
Quoted 4 lines

2) Current Intel work to land this on the drm level is based on drm_gpusvm (minus migration to VRAM). I'm not fully sure yet how this will integrate with drm_gpuvm.

Implement the userptr locking / page collection (i.e. hmm_range_fault call) on top of gpusvm. Perhaps decouple the current page collection from drm_gpusvm_range into an embedded struct like drm_gpusvm_devmem. The plan was to more or less land gpusvm which in on the list addressing Thomas's feedback before doing the userptr rework on top.

As of now, different engineer will own this rework. Ofc, with Thomas and myself providing guidance and welcoming community input. Xe will likely be the first user of this so if we have to tweak this as more drivers start to use this, ofc that is fine and will be open to any changes.

Quoted 6 lines
Quoted 6 lines

3) Christian mentioned a plan to have a common userptr implementation based off drm_exec. I figure that would be bo-based like the amdgpu implemeentation still is. Possibly i915 would be interested in this but I think any VM_BIND based driver would want to use drm_gpuvm / drm_gpusvm implementation, which is also typically O(1), since userptrs are considered vm-local.

I don't think any new driver would want a userptr implementation based on drm_exec because of having to use BO's and this isn't required if drm_gpuvm / drm_gpusvm is used which I suspect all new drivers will use. Sure could be useful for amdgpu / i915 but for Xe we certainly wouldn't want this nor would a VM bind only driver.

Quoted 20 lines
Quoted 2 lines

Ideas / suggestions welcome

So just discussed this a bit with Joonas, and if we use access_remote_vm for the userptr access instead of hand-rolling then we really only need bare-bones data structure changes in gpuvm, and nothing more. So

- add the mm pointer to struct drm_gpuvm
- add a flag indicating that it's a userptr + userspace address to struct drm_gpuva
- since we already have userptr in drivers I guess there should be any need to adjust the actual drm_gpuvm code to cope with these

Then with this you can write the access helper using access_remote_vm since that does the entire remote mm walking internally, and so there's no need to also have all the mmu notifier and locking lifted to gpuvm. But it does already give us some great places to put relevant kerneldocs (not just for debugging architecture, but userptr stuff in general), which is already a solid step forward.

Quoted 4 lines

Plus I think it'd would also be a solid first step that we need no matter what for figuring out the questions/options you have above.

Thoughts?

This seems like it could work with everything I've written above. Maybe this lives in gpusvm though so we have clear divide where gpuvm is GPU address space, and gpusvm is CPU address space. Kinda a bikeshed, but agree in general if we need to access / modify userptrs this lives in common code.

Do we view this userptr rework as a blocker for EuDebug? My thinking was we don't as we (Intel) have fully committed to a common userptr implementation.

FWIW, I really don't think the implementation in this patch and I stated this may times but that feedback seems to have been ignored yet again. I'd prefer an open code hmm_range_fault loop for now rather than a new xe_res_cursor concept that will get thrown away.

Matt

Quoted 138 lines

-Sima

Quoted 131 lines
Quoted 130 lines

-Sima

Quoted 126 lines
Quoted 76 lines

v2: pin pages vs notifier, move to vm.c (Matthew)
v3: - iterate over system pages instead of DMA, fixes iommu enabled
     - s/xe_uvma_access/xe_vm_uvma_access/ (Matt)

---
  drivers/gpu/drm/xe/xe_eudebug.c |  3 ++-
  drivers/gpu/drm/xe/xe_vm.c      | 47
+++++++++++++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_vm.h      |  3 +++

  3 files changed, 52 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -1
index 9d87df75348b..e5949e4dcad8 100644
@@ -3076,7 +3076,8 @@ static int xe_eudebug_vma_access(struct
 xe_vma *vma, u64 offset_in_vma,
   		return ret;
   	}
-	return -EINVAL;
+	return xe_vm_userptr_access(to_userptr_vma(vma),
 offset_in_vma,
+				    buf, bytes, write);
   }
   static int xe_eudebug_vm_access(struct xe_vm *vm, u64 offset,
drivers/gpu/drm/xe/xe_vm.c +0 -0
index 0f17bc8b627b..224ff9e16941 100644
@@ -3414,3 +3414,50 @@ void xe_vm_snapshot_free(struct
 xe_vm_snapshot *snap)
   	}
   	kvfree(snap);

  }

drivers/gpu/drm/xe/xe_vm.c +2 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64

offset,

drivers/gpu/drm/xe/xe_vm.c +28 -0
+			 void *buf, u64 len, bool write)
+{
+	struct xe_vm *vm = xe_vma_vm(&uvma->vma);
+	struct xe_userptr *up = &uvma->userptr;
+	struct xe_res_cursor cur = {};
+	int cur_len, ret = 0;
+
+	while (true) {
+		down_read(&vm->userptr.notifier_lock);
+		if (!xe_vma_userptr_check_repin(uvma))
+			break;
+
+		spin_lock(&vm->userptr.invalidated_lock);
+		list_del_init(&uvma->userptr.invalidate_link);
+		spin_unlock(&vm->userptr.invalidated_lock);
+
+		up_read(&vm->userptr.notifier_lock);
+		ret = xe_vma_userptr_pin_pages(uvma);
+		if (ret)
+			return ret;
+	}
+
+	if (!up->sg) {
+		ret = -EINVAL;
+		goto out_unlock_notifier;
+	}
+
+	for (xe_res_first_sg_system(up->sg, offset, len, &cur);

cur.remaining;

drivers/gpu/drm/xe/xe_vm.c +2 -0
+	     xe_res_next(&cur, cur_len)) {
+		void *ptr = kmap_local_page(sg_page(cur.sgl)) +
Quoted 1 line

cur.start;

The interface basically creates a side channel to access userptrs in the way
an userspace application would do without actually going through userspace.

That is generally not something a device driver should ever do as far as I
can see.

drivers/gpu/drm/xe/xe_vm.c void xe_vm_snapshot_free(struct xe_vm_snapshot *snap) · line 3461

Quoted 13 lines
drivers/gpu/drm/xe/xe_vm.c +13 -0
+
+		cur_len = min(cur.size, cur.remaining);
+		if (write)
+			memcpy(ptr, buf, cur_len);
+		else
+			memcpy(buf, ptr, cur_len);
+		kunmap_local(ptr);
+		buf += cur_len;
+	}
+	ret = len;
+
+out_unlock_notifier:
+	up_read(&vm->userptr.notifier_lock);

I just strongly hope that this will prevent the mapping from changing.

Regards,
Christian.

Quoted 18 lines
drivers/gpu/drm/xe/xe_vm.c +2 -0
+	return ret;
+}
drivers/gpu/drm/xe/xe_vm.h +0 -0
index 23adb7442881..372ad40ad67f 100644
@@ -280,3 +280,6 @@ struct xe_vm_snapshot
 *xe_vm_snapshot_capture(struct xe_vm *vm);

  void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
  void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
  void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);

drivers/gpu/drm/xe/xe_vm.h +2 -0
+
+int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64

offset,

drivers/gpu/drm/xe/xe_vm.h +1 -0
+			 void *buf, u64 len, bool write);
Signature · 3 lines
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#33 lore raw

PATCH 13/26 RFC drm/xe/eudebug: userptr vm pread/pwrite

In reply to Mika Kuoppala

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

This is based on suggestions from Thomas, Joonas and Simona.

Cc Matthew Brost <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Christian König <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Simona Vetter <[email protected]>
---
 drivers/gpu/drm/xe/xe_eudebug.c  | 12 ++++++++++++
 drivers/gpu/drm/xe/xe_vm.c       | 11 +++++++++++
 drivers/gpu/drm/xe/xe_vm_types.h |  6 ++++++
 3 files changed, 29 insertions(+)
drivers/gpu/drm/xe/xe_eudebug.c +12 -0
index 9d87df75348b..980b5a1383ad 100644
@@ -3074,6 +3074,18 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
 		xe_bo_put(bo);
 
 		return ret;
+	} else if (xe_vma_is_userptr(vma)) {
+		struct xe_userptr *userptr = &to_userptr_vma(vma)->userptr;
+
+		/*
+		 * XXX: access_remote_vm() would fit as userptr notifier has
+		 * mm ref so we would not need to carry task ref at all.
+		 * But access_remote_vm is not exported. access_process_vm()
+		 * is exported so use it instead.
+		 */
+		return access_process_vm(userptr->eudebug.task,
+					 xe_vma_userptr(vma), buf, bytes,
+					 write ? FOLL_WRITE : 0);
 	}
 
 	return -EINVAL;
drivers/gpu/drm/xe/xe_vm.c +11 -0
index 0f17bc8b627b..c23bb4547d66 100644
@@ -999,6 +999,14 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 			}
 
 			userptr->notifier_seq = LONG_MAX;
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+			/*
+			 * We could use the mm which is on notifier. But
+			 * the access_remote_vm() is not exported. Thus
+			 * we get reference to task for access_process_vm()
+			 */
+			userptr->eudebug.task = get_task_struct(current);
+#endif
 		}
 
 		xe_vm_get(vm);
@@ -1023,6 +1031,9 @@ static void xe_vma_destroy_late(struct xe_vma *vma)
 		if (userptr->sg)
 			xe_hmm_userptr_free_sg(uvma);
 
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+		put_task_struct(userptr->eudebug.task);
+#endif
 		/*
 		 * Since userptr pages are not pinned, we can't remove
 		 * the notifer until we're sure the GPU is not accessing
drivers/gpu/drm/xe/xe_vm_types.h +6 -0
index 557b047ebdd7..26176ccbcbbc 100644
@@ -68,6 +68,12 @@ struct xe_userptr {
 #if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
 	u32 divisor;
 #endif
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		struct task_struct *task;
+	} eudebug;
+#endif
 };
 
 struct xe_vma {
Signature · 1 line
2.43.0
#34 lore raw

PATCH 13/26 RFC drm/xe/eudebug: userptr vm pread/pwrite

In reply to Mika Kuoppala

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

This is based on suggestions from Thomas, Joonas and Simona.

v2: need to add offset into vma (Dominik)

Cc Matthew Brost <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
Cc Christian König <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Simona Vetter <[email protected]>
---
 drivers/gpu/drm/xe/xe_eudebug.c  | 13 +++++++++++++
 drivers/gpu/drm/xe/xe_vm.c       |  4 ++++
 drivers/gpu/drm/xe/xe_vm.h       | 28 +++++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_vm_types.h |  6 ++++++
 4 files changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +13 -0
index 9d87df75348b..8b29192ab110 100644
@@ -3074,6 +3074,19 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
 		xe_bo_put(bo);
 
 		return ret;
+	} else if (xe_vma_is_userptr(vma)) {
+		struct xe_userptr *userptr = &to_userptr_vma(vma)->userptr;
+
+		/*
+		 * XXX: access_remote_vm() would fit as userptr notifier has
+		 * mm ref so we would not need to carry task ref at all.
+		 * But access_remote_vm is not exported. access_process_vm()
+		 * is exported so use it instead.
+		 */
+		return access_process_vm(userptr->eudebug.task,
+					 xe_vma_userptr(vma) + offset_in_vma,
+					 buf, bytes,
+					 write ? FOLL_WRITE : 0);
 	}
 
 	return -EINVAL;
drivers/gpu/drm/xe/xe_vm.c +4 -0
index 1cb21325d8dd..235ae2db5188 100644
@@ -999,6 +999,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 			}
 
 			userptr->notifier_seq = LONG_MAX;
+
+			xe_eudebug_track_userptr_task(userptr);
 		}
 
 		xe_vm_get(vm);
@@ -1023,6 +1025,8 @@ static void xe_vma_destroy_late(struct xe_vma *vma)
 		if (userptr->sg)
 			xe_hmm_userptr_free_sg(uvma);
 
+		xe_eudebug_untrack_userptr_task(userptr);
+
 		/*
 		 * Since userptr pages are not pinned, we can't remove
 		 * the notifer until we're sure the GPU is not accessing
drivers/gpu/drm/xe/xe_vm.h +27 -1
index 23adb7442881..4334cf2b0d9d 100644
@@ -274,9 +274,35 @@ static inline void vm_dbg(const struct drm_device *dev,
 			  const char *format, ...)
 { /* noop */ }
 #endif
-#endif
 
 struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
 void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
 void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
 void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr *userptr)
+{
+	/*
+	 * We could use the mm which is on notifier. But
+	 * the access_remote_vm() is not exported. Thus
+	 * we get reference to task for access_process_vm()
+	 */
+	userptr->eudebug.task = get_task_struct(current);
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr *userptr)
+{
+	put_task_struct(userptr->eudebug.task);
+}
+#else
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr *userptr)
+{
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr *userptr)
+{
+}
+#endif /* CONFIG_DRM_XE_EUDEBUG */
+
+#endif
drivers/gpu/drm/xe/xe_vm_types.h +6 -0
index 557b047ebdd7..26176ccbcbbc 100644
@@ -68,6 +68,12 @@ struct xe_userptr {
 #if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
 	u32 divisor;
 #endif
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		struct task_struct *task;
+	} eudebug;
+#endif
 };
 
 struct xe_vma {
Signature · 1 line
2.43.0
#35 lore raw

Re: [PATCH 13/26] RFC drm/xe/eudebug: userptr vm pread/pwrite

Am 20.12.24 um 12:31 schrieb Mika Kuoppala:

Quoted 8 lines

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

This is based on suggestions from Thomas, Joonas and Simona.

Yeah that looks much saner to me. I still have a couple of comments on the general approach, but I'm going to write that up after my vacation.

Regards,
Christian.

Quoted 122 lines

v2: need to add offset into vma (Dominik)

Cc Matthew Brost <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
Cc Christian König <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Simona Vetter <[email protected]>
---
  drivers/gpu/drm/xe/xe_eudebug.c  | 13 +++++++++++++
  drivers/gpu/drm/xe/xe_vm.c       |  4 ++++
  drivers/gpu/drm/xe/xe_vm.h       | 28 +++++++++++++++++++++++++++-
  drivers/gpu/drm/xe/xe_vm_types.h |  6 ++++++
  4 files changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +13 -0
index 9d87df75348b..8b29192ab110 100644
@@ -3074,6 +3074,19 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
  		xe_bo_put(bo);
 
  		return ret;
+	} else if (xe_vma_is_userptr(vma)) {
+		struct xe_userptr *userptr = &to_userptr_vma(vma)->userptr;
+
+		/*
+		 * XXX: access_remote_vm() would fit as userptr notifier has
+		 * mm ref so we would not need to carry task ref at all.
+		 * But access_remote_vm is not exported. access_process_vm()
+		 * is exported so use it instead.
+		 */
+		return access_process_vm(userptr->eudebug.task,
+					 xe_vma_userptr(vma) + offset_in_vma,
+					 buf, bytes,
+					 write ? FOLL_WRITE : 0);
  	}
 
  	return -EINVAL;
drivers/gpu/drm/xe/xe_vm.c +4 -0
index 1cb21325d8dd..235ae2db5188 100644
@@ -999,6 +999,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
  			}
 
  			userptr->notifier_seq = LONG_MAX;
+
+			xe_eudebug_track_userptr_task(userptr);
  		}
 
  		xe_vm_get(vm);
@@ -1023,6 +1025,8 @@ static void xe_vma_destroy_late(struct xe_vma *vma)
  		if (userptr->sg)
  			xe_hmm_userptr_free_sg(uvma);
 
+		xe_eudebug_untrack_userptr_task(userptr);
+
  		/*
  		 * Since userptr pages are not pinned, we can't remove
  		 * the notifer until we're sure the GPU is not accessing
drivers/gpu/drm/xe/xe_vm.h +27 -1
index 23adb7442881..4334cf2b0d9d 100644
@@ -274,9 +274,35 @@ static inline void vm_dbg(const struct drm_device *dev,
  			  const char *format, ...)
  { /* noop */ }
  #endif
-#endif
 
  struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm);
  void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap);
  void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
  void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr *userptr)
+{
+	/*
+	 * We could use the mm which is on notifier. But
+	 * the access_remote_vm() is not exported. Thus
+	 * we get reference to task for access_process_vm()
+	 */
+	userptr->eudebug.task = get_task_struct(current);
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr *userptr)
+{
+	put_task_struct(userptr->eudebug.task);
+}
+#else
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr *userptr)
+{
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr *userptr)
+{
+}
+#endif /* CONFIG_DRM_XE_EUDEBUG */
+
+#endif
drivers/gpu/drm/xe/xe_vm_types.h +6 -0
index 557b047ebdd7..26176ccbcbbc 100644
@@ -68,6 +68,12 @@ struct xe_userptr {
  #if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
  	u32 divisor;
  #endif
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		struct task_struct *task;
+	} eudebug;
+#endif
  };
 
  struct xe_vma {
#36 lore raw

Re: [PATCH 13/26] RFC drm/xe/eudebug: userptr vm pread/pwrite

Quoting Christian König (2024-12-20 14:56:14)

Quoted 8 lines

Am 20.12.24 um 12:31 schrieb Mika Kuoppala:

Quoted 7 lines

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

Quoted 4 lines
Quoted 1 line

This is based on suggestions from Thomas, Joonas and Simona.

Yeah that looks much saner to me. I still have a couple of comments on the general approach, but I'm going to write that up after my vacation.

I see you've had some issues with mail servers, so just pinging here to see if any replies have got lost.

Would be great to reach a consensus on the high level details before spinning off further series addressing the smaller items.

Regards, Joonas

Quoted 3 lines

Regards,
Christian.

#37 lore raw

Re: [PATCH 13/26] RFC drm/xe/eudebug: userptr vm pread/pwrite

Am 29.01.25 um 09:03 schrieb Joonas Lahtinen:

Quoted 9 lines

Quoting Christian König (2024-12-20 14:56:14)

Quoted 8 lines

Am 20.12.24 um 12:31 schrieb Mika Kuoppala:

Quoted 7 lines

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

This is based on suggestions from Thomas, Joonas and Simona.

Yeah that looks much saner to me. I still have a couple of comments on the general approach, but I'm going to write that up after my vacation.

I see you've had some issues with mail servers, so just pinging here to see if any replies have got lost.

No, I'm just overworked and have like 10 things I need to take care of at the same time :(

Quoted 2 lines

Would be great to reach a consensus on the high level details before spinning off further series addressing the smaller items.

I would say that attaching debug metadata to the GPU VMA doesn't look like the best design, but if you just do that inside XE it won't affect any other part of the kernel.

My other concern I have is using ptrace_may_access, I would still try to avoid that.

What if you first grab the DRM render node file descriptor which represents the GPU address space you want to debug with pidfd_getfd() and then either create the eudebug file descriptor from an IOCTL or implement the necessary IOCTLs on the DRM render node directly?

That would make it unnecessary to export ptrace_may_access.

Regards,
Christian.

Quoted 5 lines

Regards, Joonas

Quoted 2 lines

Regards,
Christian.

#38 lore raw

Re: [PATCH 13/26] RFC drm/xe/eudebug: userptr vm pread/pwrite

Quoting Christian König (2025-01-29 12:33:52)

Quoted 10 lines

Am 29.01.25 um 09:03 schrieb Joonas Lahtinen:

Quoted 9 lines

Quoting Christian König (2024-12-20 14:56:14)

Quoted 8 lines

Am 20.12.24 um 12:31 schrieb Mika Kuoppala:

Quoted 7 lines

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

This is based on suggestions from Thomas, Joonas and Simona.

Yeah that looks much saner to me. I still have a couple of comments on the general approach, but I'm going to write that up after my vacation.

I see you've had some issues with mail servers, so just pinging here to see if any replies have got lost.

No, I'm just overworked and have like 10 things I need to take care of at the same time :(

Ack.

Quoted 6 lines
Quoted 2 lines

Would be great to reach a consensus on the high level details before spinning off further series addressing the smaller items.

I would say that attaching debug metadata to the GPU VMA doesn't look like the best design, but if you just do that inside XE it won't affect any other part of the kernel.

It just grew out of convenience of implementation on the side of VM_BIND.

The other alternative would be to maintain a secondary load map in the kernel in a separate data structure from GPU VMA.

I was actually going to suggest such thing as a common DRM thing: GPU VMA metadata interface or parallel "GPU loadmap" interface. It'd allow for userspace tooling to more easier go from GPU EU IP to a module that was loaded at that address. Kind of a step 0 towards backtrace for GPU.

Can you elaborate on what your concern is with the VMA metadata attachment?

Quoted 9 lines

My other concern I have is using ptrace_may_access, I would still try to avoid that.

What if you first grab the DRM render node file descriptor which represents the GPU address space you want to debug with pidfd_getfd() and then either create the eudebug file descriptor from an IOCTL or implement the necessary IOCTLs on the DRM render node directly?

That would make it unnecessary to export ptrace_may_access.

We're prototyping this. At this point there are some caveats recognized:

1. There is a limitation that you don't get a notification when your target PID opens a DRM client, but GDB or other application would have to keep polling for the FDs. I'll have to check with the team how that would fit to GDB side.

2. Debugging multiple DRM clients (to same GPU) under one PID now requires separate debugger connections. This may break the way the debugger locking is currently implemented for the discovery phase to prevent parallel IOCTL from running. Will have to look into it once we have a working prototype.

3. Last but not the least, we'll have to compare which LSM security modules and other conditions checked on the pidfd_getfd() paths for access restrictions.

Reason for using ptrace_may_access() was to have a clear 1:1 mapping between user being allowed to ptrace() a PID to control CPU threads and do debugger IOCTL to control GPU threads. So if user can attach to a PID with GDB, they would certainly also be able to debug the GPU portion.

If there is divergence, I don't see a big benefit in going to pidfd_getfd(). We're all the same not even exporting ptrace_may_access() and YOLO'ing the access check by comparing euid and such which is close to what ptrace does, but not exactly the same (just like pidfd_getfd() access checks).

However I believe this would not be a fundamental blocker for the series? If this would be the only remaining disagreement, I guess we could just do CAP_ADMIN check initially before we can find something agreeable.

Regards, Joonas

Quoted 10 lines

Regards,
Christian.

Quoted 5 lines

Regards, Joonas

Quoted 2 lines

Regards,
Christian.

#39 lore raw

Re: [PATCH 13/26] RFC drm/xe/eudebug: userptr vm pread/pwrite

Am 29.01.25 um 19:18 schrieb Joonas Lahtinen:

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Would be great to reach a consensus on the high level details before spinning off further series addressing the smaller items.

I would say that attaching debug metadata to the GPU VMA doesn't look like the best design, but if you just do that inside XE it won't affect any other part of the kernel.

It just grew out of convenience of implementation on the side of VM_BIND.

The other alternative would be to maintain a secondary load map in the kernel in a separate data structure from GPU VMA.

Quoted 7 lines

I was actually going to suggest such thing as a common DRM thing: GPU VMA metadata interface or parallel "GPU loadmap" interface. It'd allow for userspace tooling to more easier go from GPU EU IP to a module that was loaded at that address. Kind of a step 0 towards backtrace for GPU.

Can you elaborate on what your concern is with the VMA metadata attachment?

In general we should try to avoid putting data into the kernel the kernel doesn't need.

In other words we don't put the debug metadata for the CPU process on the CPU VMA either.

You could reduce the amount of data massively if you just attach the source of the debug metadata to the GPU VMA.

E.g. instead of the symbol table just where to find it. A VA of the CPU process, a file system location or something like that.

Quoted 8 lines
Quoted 8 lines

My other concern I have is using ptrace_may_access, I would still try to avoid that.

What if you first grab the DRM render node file descriptor which represents the GPU address space you want to debug with pidfd_getfd() and then either create the eudebug file descriptor from an IOCTL or implement the necessary IOCTLs on the DRM render node directly?

Quoted 7 lines
Quoted 1 line

That would make it unnecessary to export ptrace_may_access.

We're prototyping this. At this point there are some caveats recognized:

1. There is a limitation that you don't get a notification when your target PID opens a DRM client, but GDB or other application would have to keep polling for the FDs. I'll have to check with the team how that would fit to GDB side.

Well there is the dnotify/inotify API which allows a process to be notified of certain filesystem events.

I never used it, but it potentially provides an event when a specific file is open.

On the other hand I have no idea what permissions are necessary to use it, potentially root.

Quoted 5 lines

2. Debugging multiple DRM clients (to same GPU) under one PID now requires separate debugger connections. This may break the way the debugger locking is currently implemented for the discovery phase to prevent parallel IOCTL from running. Will have to look into it once we have a working prototype.

Well multiple DRM clients would also have multiple GPU VM address spaces, wouldn't they?

So you would need multiple connections, one for each DRM client as well.

Quoted 9 lines

3. Last but not the least, we'll have to compare which LSM security modules and other conditions checked on the pidfd_getfd() paths for access restrictions.

Reason for using ptrace_may_access() was to have a clear 1:1 mapping between user being allowed to ptrace() a PID to control CPU threads and do debugger IOCTL to control GPU threads. So if user can attach to a PID with GDB, they would certainly also be able to debug the GPU portion.

Quoted 5 lines

If there is divergence, I don't see a big benefit in going to pidfd_getfd(). We're all the same not even exporting ptrace_may_access() and YOLO'ing the access check by comparing euid and such which is close to what ptrace does, but not exactly the same (just like pidfd_getfd() access checks).

Well that argumentation is exactly backward to why I suggested not using ptrace_may_access().

When an administrator used LSM to block pidfd_getfd() then a driver which uses a driver specific IOCTL to bypass that is actually a really bad idea.

Quoted 4 lines

However I believe this would not be a fundamental blocker for the series? If this would be the only remaining disagreement, I guess we could just do CAP_ADMIN check initially before we can find something agreeable.

Well as soon as anything is merged upstream it becomes UAPI, which in turn means that changing it fundamentally becomes really hard to do.

What you could do is to expose the interface through debugfs and explicitly state that it isn't stable in any way.

Regards,
Christian.

Quoted 10 lines

Regards, Joonas

Quoted 7 lines

Regards,
Christian.

Quoted 4 lines

Regards, Joonas

Quoted 2 lines

Regards,
Christian.

#40 lore raw

Re: [PATCH 13/26] RFC drm/xe/eudebug: userptr vm pread/pwrite

In reply to Mika Kuoppala
Quoted 32 lines · Mika Kuoppala

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

This is based on suggestions from Thomas, Joonas and Simona.

v2: need to add offset into vma (Dominik)

Cc Matthew Brost <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
Cc Christian König <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Simona Vetter <[email protected]>

---
 drivers/gpu/drm/xe/xe_eudebug.c  | 13 +++++++++++++ drivers/gpu/drm/xe/xe_vm.c       |  4 ++++ drivers/gpu/drm/xe/xe_vm.h       | 28 +++++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_vm_types.h |  6 ++++++

 4 files changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_eudebug.c +0 -0
index 9d87df75348b..8b29192ab110 100644

drivers/gpu/drm/xe/xe_eudebug.c static int xe_eudebug_vma_access(struct xe_vma · line 3074

Quoted 1 line
drivers/gpu/drm/xe/xe_eudebug.c +0 -0
@@ -3074,6 +3074,19 @@ static int xe_eudebug_vma_access(struct xe_vma
 *vma, u64 offset_in_vma,

AFAICT all across the core mm code, unsigned long is used for mm offsets, rather than u64, which we use for gpu- and physical offsets.

Quoted 14 lines
drivers/gpu/drm/xe/xe_eudebug.c +0 -0
  		xe_bo_put(bo);


  return ret;

drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+	} else if (xe_vma_is_userptr(vma)) {
+		struct xe_userptr *userptr = &to_userptr_vma(vma)-
Quoted 1 line

userptr;

drivers/gpu/drm/xe/xe_eudebug.c +3 -0
+
+		/*
+		 * XXX: access_remote_vm() would fit as userptr

notifier has

drivers/gpu/drm/xe/xe_eudebug.c +1 -0
+		 * mm ref so we would not need to carry task ref at

all.

drivers/gpu/drm/xe/xe_eudebug.c +1 -0
+		 * But access_remote_vm is not exported.

access_process_vm()

drivers/gpu/drm/xe/xe_eudebug.c static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma, · line 3085

Quoted 2 lines
drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+		 * is exported so use it instead.
+		 */

Could we add a follow-up patch that exports access_remote_vm() and changes this code to use access_remote_vm() instead?

Quoted 97 lines
drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+		return access_process_vm(userptr->eudebug.task,
+					 xe_vma_userptr(vma) +

offset_in_vma,

drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+					 buf, bytes,
+					 write ? FOLL_WRITE : 0);

  }

  return -EINVAL;

drivers/gpu/drm/xe/xe_vm.c +0 -0
index 1cb21325d8dd..235ae2db5188 100644
@@ -999,6 +999,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm
 *vm,
  			}


  userptr->notifier_seq = LONG_MAX;

drivers/gpu/drm/xe/xe_vm.c +2 -0
+
+			xe_eudebug_track_userptr_task(userptr);

  }

  xe_vm_get(vm);

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -1023,6 +1025,8 @@ static void xe_vma_destroy_late(struct xe_vma
 *vma)
  		if (userptr->sg)
  			xe_hmm_userptr_free_sg(uvma);

drivers/gpu/drm/xe/xe_vm.c +2 -0
+		xe_eudebug_untrack_userptr_task(userptr);
+

  /*
  * Since userptr pages are not pinned, we can't remove
  * the notifer until we're sure the GPU is not accessing

drivers/gpu/drm/xe/xe_vm.h +0 -1
index 23adb7442881..4334cf2b0d9d 100644
@@ -274,9 +274,35 @@ static inline void vm_dbg(const struct
 drm_device *dev,
  			  const char *format, ...)
  { /* noop */ }
  #endif
-#endif


 struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm); void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap); void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
 void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);

drivers/gpu/drm/xe/xe_vm.h +3 -0
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +10 -0
+{
+	/*
+	 * We could use the mm which is on notifier. But
+	 * the access_remote_vm() is not exported. Thus
+	 * we get reference to task for access_process_vm()
+	 */
+	userptr->eudebug.task = get_task_struct(current);
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +5 -0
+{
+	put_task_struct(userptr->eudebug.task);
+}
+#else
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +4 -0
+{
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +5 -0
+{
+}
+#endif /* CONFIG_DRM_XE_EUDEBUG */
+
+#endif
drivers/gpu/drm/xe/xe_vm_types.h +6 -0
index 557b047ebdd7..26176ccbcbbc 100644
@@ -68,6 +68,12 @@ struct xe_userptr {
  #if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
  	u32 divisor;
  #endif
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		struct task_struct *task;
+	} eudebug;
+#endif
  };
Quoted 2 lines


 struct xe_vma {

Otherwise LGTM.
Thanks,
Thomas

#41 lore raw

Re: [PATCH 13/26] RFC drm/xe/eudebug: userptr vm pread/pwrite

Quoted 27 lines · Thomas Hellström
Quoted 26 lines · Mika Kuoppala

Implement debugger vm access for userptrs.

When bind is done, take ref to current task so that we know from which vm the address was bound. Then during debugger pread/pwrite we use this target task as parameter to access the debuggee vm with access_process_vm().

This is based on suggestions from Thomas, Joonas and Simona.

v2: need to add offset into vma (Dominik)

Cc Matthew Brost <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
Cc Christian König <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Simona Vetter <[email protected]>

---
 drivers/gpu/drm/xe/xe_eudebug.c  | 13 +++++++++++++ drivers/gpu/drm/xe/xe_vm.c       |  4 ++++ drivers/gpu/drm/xe/xe_vm.h       | 28 +++++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_vm_types.h |  6 ++++++

 4 files changed, 50 insertions(+), 1 deletion(-)
Quoted 10 lines

drivers/gpu/drm/xe/xe_eudebug.c static int xe_eudebug_vma_access(struct xe_vma · line 3074

Quoted 7 lines
drivers/gpu/drm/xe/xe_eudebug.c +0 -0
index 9d87df75348b..8b29192ab110 100644
@@ -3074,6 +3074,19 @@ static int xe_eudebug_vma_access(struct xe_vma
 *vma, u64 offset_in_vma,

AFAICT all across the core mm code, unsigned long is used for mm offsets, rather than u64, which we use for gpu- and physical offsets.

Yup, changed these on the patch introducing the pread/pwrite.

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/xe/xe_eudebug.c +0 -0
  		xe_bo_put(bo);


  return ret;

drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+	} else if (xe_vma_is_userptr(vma)) {
+		struct xe_userptr *userptr = &to_userptr_vma(vma)-
Quoted 1 line

userptr;

Quoted 14 lines

drivers/gpu/drm/xe/xe_eudebug.c

Quoted 10 lines
drivers/gpu/drm/xe/xe_eudebug.c +3 -0
+
+		/*
+		 * XXX: access_remote_vm() would fit as userptr

notifier has

drivers/gpu/drm/xe/xe_eudebug.c +1 -0
+		 * mm ref so we would not need to carry task ref at

all.

drivers/gpu/drm/xe/xe_eudebug.c +1 -0
+		 * But access_remote_vm is not exported.

access_process_vm()

drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+		 * is exported so use it instead.
+		 */

Could we add a follow-up patch that exports access_remote_vm() and changes this code to use access_remote_vm() instead?

Here is the diff:

drivers/gpu/drm/xe/xe_eudebug.c +18 -9
index 996fcb4b0e9e..3fdafbf30209 100644
@@ -3763,16 +3763,25 @@ static int xe_eudebug_vma_access(struct xe_vma *vma, u64 offset_in_vma,
 		return ret;
 	} else if (xe_vma_is_userptr(vma)) {
 		struct xe_userptr *userptr = &to_userptr_vma(vma)->userptr;
+		struct xe_vm *vm = xe_vma_vm(vma);
+		struct mm_struct *mm = NULL;
+		int ret;
 
-		/*
-		 * XXX: access_remote_vm() would fit as userptr notifier has
-		 * mm ref so we would not need to carry task ref at all.
-		 * But access_remote_vm is not exported. access_process_vm()
-		 * is exported so use it instead.
-		 */
-		return access_process_vm(userptr->eudebug.task,
-					 xe_vma_userptr(vma), buf, bytes,
-					 write ? FOLL_WRITE : 0);
+		down_read(&vm->userptr.notifier_lock);
+		if (mmget_not_zero(userptr->notifier.mm))
+			mm = userptr->notifier.mm;
+		up_read(&vm->userptr.notifier_lock);
+
+		if (!mm)
+			return -EFAULT;
+
+		ret = access_remote_vm(mm,
+				       xe_vma_userptr(vma) + offset_in_vma,
+				       buf, bytes,
+				       write ? FOLL_WRITE : 0);
+		mmput(mm);
+
+		return ret;
 	}
 
 	return -EINVAL;
drivers/gpu/drm/xe/xe_vm.c +0 -11
index cbc7fdb74166..04157b6b26ea 100644
@@ -1003,14 +1003,6 @@ static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 			}
 
 			userptr->notifier_seq = LONG_MAX;
-#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
-			/*
-			 * We could use the mm which is on notifier. But
-			 * the access_remote_vm() is not exported. Thus
-			 * we get reference to task for access_process_vm()
-			 */
-			userptr->eudebug.task = get_task_struct(current);
-#endif
 		}
 
 		xe_vm_get(vm);
@@ -1035,9 +1027,6 @@ static void xe_vma_destroy_late(struct xe_vma *vma)
 		if (userptr->sg)
 			xe_hmm_userptr_free_sg(uvma);
 
-#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
-		put_task_struct(userptr->eudebug.task);
-#endif
 		/*
 		 * Since userptr pages are not pinned, we can't remove
 		 * the notifer until we're sure the GPU is not accessing
drivers/gpu/drm/xe/xe_vm_types.h +0 -6
index 0be999dd513f..1c5776194e54 100644
@@ -68,12 +68,6 @@ struct xe_userptr {
 #if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
 	u32 divisor;
 #endif
-
-#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
-	struct {
-		struct task_struct *task;
-	} eudebug;
-#endif
 };
 
 #if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)

I will reply also with the export patch and
the complete patch. for reference, they can be found here also:

https://gitlab.freedesktop.org/miku/kernel/-/commit/3ffbc66fb6dd2ff0a9f5f282266a97e073f10deb
https://gitlab.freedesktop.org/miku/kernel/-/commit/ee2ebe9a5debabf984b2cfab34bf0996ace63ab7

Thanks,
-Mika

Quoted 105 lines
Quoted 99 lines
drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+		return access_process_vm(userptr->eudebug.task,
+					 xe_vma_userptr(vma) +

offset_in_vma,

drivers/gpu/drm/xe/xe_eudebug.c +2 -0
+					 buf, bytes,
+					 write ? FOLL_WRITE : 0);

  }

  return -EINVAL;

drivers/gpu/drm/xe/xe_vm.c +0 -0
index 1cb21325d8dd..235ae2db5188 100644
@@ -999,6 +999,8 @@ static struct xe_vma *xe_vma_create(struct xe_vm
 *vm,
  			}


  userptr->notifier_seq = LONG_MAX;

drivers/gpu/drm/xe/xe_vm.c +2 -0
+
+			xe_eudebug_track_userptr_task(userptr);

  }

  xe_vm_get(vm);

drivers/gpu/drm/xe/xe_vm.c +0 -0
@@ -1023,6 +1025,8 @@ static void xe_vma_destroy_late(struct xe_vma
 *vma)
  		if (userptr->sg)
  			xe_hmm_userptr_free_sg(uvma);

drivers/gpu/drm/xe/xe_vm.c +2 -0
+		xe_eudebug_untrack_userptr_task(userptr);
+

  /*
  * Since userptr pages are not pinned, we can't remove
  * the notifer until we're sure the GPU is not accessing

drivers/gpu/drm/xe/xe_vm.h +0 -1
index 23adb7442881..4334cf2b0d9d 100644
@@ -274,9 +274,35 @@ static inline void vm_dbg(const struct
 drm_device *dev,
  			  const char *format, ...)
  { /* noop */ }
  #endif
-#endif


 struct xe_vm_snapshot *xe_vm_snapshot_capture(struct xe_vm *vm); void xe_vm_snapshot_capture_delayed(struct xe_vm_snapshot *snap); void xe_vm_snapshot_print(struct xe_vm_snapshot *snap, struct drm_printer *p);
 void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);

drivers/gpu/drm/xe/xe_vm.h +3 -0
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +10 -0
+{
+	/*
+	 * We could use the mm which is on notifier. But
+	 * the access_remote_vm() is not exported. Thus
+	 * we get reference to task for access_process_vm()
+	 */
+	userptr->eudebug.task = get_task_struct(current);
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +5 -0
+{
+	put_task_struct(userptr->eudebug.task);
+}
+#else
+static inline void xe_eudebug_track_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +4 -0
+{
+}
+
+static inline void xe_eudebug_untrack_userptr_task(struct xe_userptr

*userptr)

drivers/gpu/drm/xe/xe_vm.h +5 -0
+{
+}
+#endif /* CONFIG_DRM_XE_EUDEBUG */
+
+#endif
drivers/gpu/drm/xe/xe_vm_types.h +6 -0
index 557b047ebdd7..26176ccbcbbc 100644
@@ -68,6 +68,12 @@ struct xe_userptr {
  #if IS_ENABLED(CONFIG_DRM_XE_USERPTR_INVAL_INJECT)
  	u32 divisor;
  #endif
+
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	struct {
+		struct task_struct *task;
+	} eudebug;
+#endif
  };
Quoted 2 lines


 struct xe_vma {

Otherwise LGTM.
Thanks,
Thomas

#42 lore raw

PATCH 13/27 mm: export access_remote_vm symbol for debugger use

In reply to Thomas Hellström

Export access_remote_vm as GPL symbol to allow debuggers (eudebug) to access and modify memory in target VMs by tracking VM_BIND operations. While access_process_vm() is already exported, it would require maintaining task references in the debugger.

Since the mm reference is already present in the userptr's mm notifier implementation, exporting access_remote_vm allows that existing reference to be used directly without needing to obtain and maintain additional task references just for memory access.

Cc Matthew Brost <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Christian König <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Simona Vetter <[email protected]>
---
 mm/memory.c | 1 +
 1 file changed, 1 insertion(+)
mm/memory.c +1 -0
index 398c031be9ba..9b7c71c83db5 100644
@@ -6690,6 +6690,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
 {
 	return __access_remote_vm(mm, addr, buf, len, gup_flags);
 }
+EXPORT_SYMBOL_GPL(access_remote_vm);
 
 /*
  * Access another process' address space.
Signature · 1 line
2.43.0
#43 lore raw

PATCH 14/27 drm/xe/eudebug: userptr vm access pread/pwrite

In reply to Thomas Hellström

Implement debugger vm access for userptrs.

When userptr bind is done, mmu notifier is added by core xe. Later when debugger wants to access the target memory, this notifier can be used as it carries the struct mm of target.

Implement userptr vm access, for debugger pread/pwrite using notifier mm passed to access_remote_vm().

This is based on suggestions from Thomas, Joonas and Simona.

v2: need to add offset into vma (Dominik)
v3: use exported access_remote_vm (Thomas)

Cc Matthew Brost <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Dominik Grzegorzek <[email protected]>
Cc Christian König <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Simona Vetter <[email protected]>
---
 drivers/gpu/drm/xe/xe_eudebug.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/gpu/drm/xe/xe_eudebug.c +21 -0
index 210d9eeab1a7..25f18aa5447b 100644
@@ -3077,6 +3077,27 @@ static int xe_eudebug_vma_access(struct xe_vma *vma,
 
 		xe_bo_put(bo);
 
+		return ret;
+	} else if (xe_vma_is_userptr(vma)) {
+		struct xe_userptr *userptr = &to_userptr_vma(vma)->userptr;
+		struct xe_vm *vm = xe_vma_vm(vma);
+		struct mm_struct *mm = NULL;
+		int ret;
+
+		down_read(&vm->userptr.notifier_lock);
+		if (mmget_not_zero(userptr->notifier.mm))
+			mm = userptr->notifier.mm;
+		up_read(&vm->userptr.notifier_lock);
+
+		if (!mm)
+			return -EFAULT;
+
+		ret = access_remote_vm(mm,
+				       xe_vma_userptr(vma) + offset_in_vma,
+				       buf, bytes,
+				       write ? FOLL_WRITE : 0);
+		mmput(mm);
+
 		return ret;
 	}
 
Signature · 1 line
2.43.0
#44 lore raw

PATCH 15/26 drm/xe: Debug metadata create/destroy ioctls

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Ad a part of eu debug feature introduce debug metadata objects. These are to be used to pass metadata between client and debugger, by attaching them to vm_bind operations.

todo: WORK_IN_PROGRESS_* defines need to be reworded/refined when
the real usage and need is established by l0+gdb.

v2: - include uapi/drm/xe_drm.h
- metadata behind kconfig (Mika)
- dont leak args->id on error (Matt Auld)

---
 drivers/gpu/drm/xe/Makefile                  |   3 +-
 drivers/gpu/drm/xe/xe_debug_metadata.c       | 107 +++++++++++++++++++
 drivers/gpu/drm/xe/xe_debug_metadata.h       |  50 +++++++++
 drivers/gpu/drm/xe/xe_debug_metadata_types.h |  25 +++++
 drivers/gpu/drm/xe/xe_device.c               |   5 +
 drivers/gpu/drm/xe/xe_device.h               |   2 +
 drivers/gpu/drm/xe/xe_device_types.h         |   7 ++
 drivers/gpu/drm/xe/xe_eudebug.c              |  13 +++
 include/uapi/drm/xe_drm.h                    |  53 ++++++++-
 9 files changed, 263 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata.c
 create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata.h
 create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata_types.h
drivers/gpu/drm/xe/Makefile +2 -1
index 33f457e4fcd3..e7dc299ea178 100644
@@ -117,7 +117,8 @@ xe-y += xe_bb.o \
 	xe_wa.o \
 	xe_wopcm.o
 
-xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o
+xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o \
+	xe_debug_metadata.o
 
 xe-$(CONFIG_HMM_MIRROR) += xe_hmm.o
 
drivers/gpu/drm/xe/xe_debug_metadata.c new file +107 -0

107 lines not on this page · raw message

drivers/gpu/drm/xe/xe_debug_metadata.h new file +50 -0

50 lines not on this page · raw message

drivers/gpu/drm/xe/xe_debug_metadata_types.h new file +25 -0
new file mode 100644
index 000000000000..624852920f58
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef _XE_DEBUG_METADATA_TYPES_H_
+#define _XE_DEBUG_METADATA_TYPES_H_
+
+#include <linux/kref.h>
+
+struct xe_debug_metadata {
+	/** @type: type of given metadata */
+	u64 type;
+
+	/** @ptr: copy of userptr, given as a metadata payload */
+	void *ptr;
+
+	/** @len: length, in bytes of the metadata */
+	u64 len;
+
+	/** @ref: reference count */
+	struct kref refcount;
+};
+
+#endif
drivers/gpu/drm/xe/xe_device.c +5 -0
index dc0336215912..a7a715475184 100644
@@ -25,6 +25,7 @@
 #include "xe_bo.h"
 #include "xe_debugfs.h"
 #include "xe_devcoredump.h"
+#include "xe_debug_metadata.h"
 #include "xe_dma_buf.h"
 #include "xe_drm_client.h"
 #include "xe_drv.h"
@@ -197,6 +198,10 @@ static const struct drm_ioctl_desc xe_ioctls[] = {
 			  DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(XE_OBSERVATION, xe_observation_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(XE_EUDEBUG_CONNECT, xe_eudebug_connect_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(XE_DEBUG_METADATA_CREATE, xe_debug_metadata_create_ioctl,
+			  DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(XE_DEBUG_METADATA_DESTROY, xe_debug_metadata_destroy_ioctl,
+			  DRM_RENDER_ALLOW),
 };
 
 static long xe_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
drivers/gpu/drm/xe/xe_device.h +2 -0
index 088831a6b863..f89f1f0fc25e 100644
@@ -218,6 +218,8 @@ static inline int xe_eudebug_needs_lock(const unsigned int cmd)
 	case DRM_XE_EXEC_QUEUE_CREATE:
 	case DRM_XE_EXEC_QUEUE_DESTROY:
 	case DRM_XE_EUDEBUG_CONNECT:
+	case DRM_XE_DEBUG_METADATA_CREATE:
+	case DRM_XE_DEBUG_METADATA_DESTROY:
 		return 1;
 	}
 
drivers/gpu/drm/xe/xe_device_types.h +7 -0
index 7b893a86d83f..4ab9f06eba2d 100644
@@ -684,6 +684,13 @@ struct xe_file {
 	struct {
 		/** @client_link: list entry in xe_device.clients.list */
 		struct list_head client_link;
+
+		struct {
+			/** @xa: xarray to store debug metadata */
+			struct xarray xa;
+			/** @lock: protects debug metadata xarray */
+			struct mutex lock;
+		} metadata;
 	} eudebug;
 #endif
 };
drivers/gpu/drm/xe/xe_eudebug.c +13 -0
index e5949e4dcad8..e9092ed0b344 100644
@@ -21,6 +21,7 @@
 #include "xe_assert.h"
 #include "xe_bo.h"
 #include "xe_device.h"
+#include "xe_debug_metadata.h"
 #include "xe_eudebug.h"
 #include "xe_eudebug_types.h"
 #include "xe_exec_queue.h"
@@ -2141,6 +2142,8 @@ void xe_eudebug_file_open(struct xe_file *xef)
 	struct xe_eudebug *d;
 
 	INIT_LIST_HEAD(&xef->eudebug.client_link);
+	mutex_init(&xef->eudebug.metadata.lock);
+	xa_init_flags(&xef->eudebug.metadata.xa, XA_FLAGS_ALLOC1);
 
 	down_read(&xef->xe->eudebug.discovery_lock);
 
@@ -2158,12 +2161,22 @@ void xe_eudebug_file_open(struct xe_file *xef)
 void xe_eudebug_file_close(struct xe_file *xef)
 {
 	struct xe_eudebug *d;
+	unsigned long idx;
+	struct xe_debug_metadata *mdata;
 
 	down_read(&xef->xe->eudebug.discovery_lock);
 	d = xe_eudebug_get(xef);
 	if (d)
 		xe_eudebug_event_put(d, client_destroy_event(d, xef));
 
+	mutex_lock(&xef->eudebug.metadata.lock);
+	xa_for_each(&xef->eudebug.metadata.xa, idx, mdata)
+		xe_debug_metadata_put(mdata);
+	mutex_unlock(&xef->eudebug.metadata.lock);
+
+	xa_destroy(&xef->eudebug.metadata.xa);
+	mutex_destroy(&xef->eudebug.metadata.lock);
+
 	spin_lock(&xef->xe->clients.lock);
 	list_del_init(&xef->eudebug.client_link);
 	spin_unlock(&xef->xe->clients.lock);
include/uapi/drm/xe_drm.h +52 -1

71 lines not on this page · raw message

Signature · 1 line
2.43.0
#45 lore raw

PATCH 16/26 drm/xe: Attach debug metadata to vma

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Introduces a vm_bind_op extension, enabling users to attach metadata objects to each [OP_MAP|OP_MAP_USERPTR] operation. This interface will be utilized by the EU debugger to relay information about the contents of specified VMAs from the debugee to the debugger process.

v2: move vma metadata handling behind Kconfig (Mika)

---
 drivers/gpu/drm/xe/xe_debug_metadata.c | 120 +++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_debug_metadata.h |  52 +++++++++++
 drivers/gpu/drm/xe/xe_vm.c             |  99 +++++++++++++++++++-
 drivers/gpu/drm/xe/xe_vm_types.h       |  27 ++++++
 include/uapi/drm/xe_drm.h              |  19 ++++
 5 files changed, 313 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_debug_metadata.c +120 -0
index 1dfed9aed285..b045bdd77235 100644
@@ -10,6 +10,113 @@
 
 #include "xe_device.h"
 #include "xe_macros.h"
+#include "xe_vm.h"
+
+void xe_eudebug_free_vma_metadata(struct xe_eudebug_vma_metadata *mdata)
+{
+	struct xe_vma_debug_metadata *vmad, *tmp;
+
+	list_for_each_entry_safe(vmad, tmp, &mdata->list, link) {
+		list_del(&vmad->link);
+		kfree(vmad);
+	}
+}
+
+static struct xe_vma_debug_metadata *
+vma_new_debug_metadata(u32 metadata_id, u64 cookie)
+{
+	struct xe_vma_debug_metadata *vmad;
+
+	vmad = kzalloc(sizeof(*vmad), GFP_KERNEL);
+	if (!vmad)
+		return ERR_PTR(-ENOMEM);
+
+	INIT_LIST_HEAD(&vmad->link);
+
+	vmad->metadata_id = metadata_id;
+	vmad->cookie = cookie;
+
+	return vmad;
+}
+
+int xe_eudebug_copy_vma_metadata(struct xe_eudebug_vma_metadata *from,
+				 struct xe_eudebug_vma_metadata *to)
+{
+	struct xe_vma_debug_metadata *vmad, *vma;
+
+	list_for_each_entry(vmad, &from->list, link) {
+		vma = vma_new_debug_metadata(vmad->metadata_id, vmad->cookie);
+		if (IS_ERR(vma))
+			return PTR_ERR(vma);
+
+		list_add_tail(&vmad->link, &to->list);
+	}
+
+	return 0;
+}
+
+static int vma_new_debug_metadata_op(struct xe_vma_op *op,
+				     u32 metadata_id, u64 cookie,
+				     u64 flags)
+{
+	struct xe_vma_debug_metadata *vmad;
+
+	vmad = vma_new_debug_metadata(metadata_id, cookie);
+	if (IS_ERR(vmad))
+		return PTR_ERR(vmad);
+
+	list_add_tail(&vmad->link, &op->map.eudebug.metadata.list);
+
+	return 0;
+}
+
+int vm_bind_op_ext_attach_debug(struct xe_device *xe,
+				struct xe_file *xef,
+				struct drm_gpuva_ops *ops,
+				u32 operation, u64 extension)
+{
+	u64 __user *address = u64_to_user_ptr(extension);
+	struct drm_xe_vm_bind_op_ext_attach_debug ext;
+	struct xe_debug_metadata *mdata;
+	struct drm_gpuva_op *__op;
+	int err;
+
+	err = __copy_from_user(&ext, address, sizeof(ext));
+	if (XE_IOCTL_DBG(xe, err))
+		return -EFAULT;
+
+	if (XE_IOCTL_DBG(xe,
+			 operation != DRM_XE_VM_BIND_OP_MAP_USERPTR &&
+			 operation != DRM_XE_VM_BIND_OP_MAP))
+		return -EINVAL;
+
+	if (XE_IOCTL_DBG(xe, ext.flags))
+		return -EINVAL;
+
+	mdata = xe_debug_metadata_get(xef, (u32)ext.metadata_id);
+	if (XE_IOCTL_DBG(xe, !mdata))
+		return -ENOENT;
+
+	/* care about metadata existence only on the time of attach */
+	xe_debug_metadata_put(mdata);
+
+	if (!ops)
+		return 0;
+
+	drm_gpuva_for_each_op(__op, ops) {
+		struct xe_vma_op *op = gpuva_op_to_vma_op(__op);
+
+		if (op->base.op == DRM_GPUVA_OP_MAP) {
+			err = vma_new_debug_metadata_op(op,
+							ext.metadata_id,
+							ext.cookie,
+							ext.flags);
+			if (err)
+				return err;
+		}
+	}
+	return 0;
+}
 
 static void xe_debug_metadata_release(struct kref *ref)
 {
@@ -24,6 +131,19 @@ void xe_debug_metadata_put(struct xe_debug_metadata *mdata)
 	kref_put(&mdata->refcount, xe_debug_metadata_release);
 }
 
+struct xe_debug_metadata *xe_debug_metadata_get(struct xe_file *xef, u32 id)
+{
+	struct xe_debug_metadata *mdata;
+
+	mutex_lock(&xef->eudebug.metadata.lock);
+	mdata = xa_load(&xef->eudebug.metadata.xa, id);
+	if (mdata)
+		kref_get(&mdata->refcount);
+	mutex_unlock(&xef->eudebug.metadata.lock);
+
+	return mdata;
+}
+
 int xe_debug_metadata_create_ioctl(struct drm_device *dev,
 				   void *data,
 				   struct drm_file *file)
drivers/gpu/drm/xe/xe_debug_metadata.h +52 -0

82 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.c +95 -4

190 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm_types.h +27 -0
index 557b047ebdd7..1c5776194e54 100644
@@ -70,6 +70,14 @@ struct xe_userptr {
 #endif
 };
 
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+struct xe_eudebug_vma_metadata {
+	struct list_head list;
+};
+#else
+struct xe_eudebug_vma_metadata { };
+#endif
+
 struct xe_vma {
 	/** @gpuva: Base GPUVA object */
 	struct drm_gpuva gpuva;
@@ -121,6 +129,11 @@ struct xe_vma {
 	 * Needs to be signalled before UNMAP can be processed.
 	 */
 	struct xe_user_fence *ufence;
+
+	struct {
+		/** @metadata: List of vma debug metadata */
+		struct xe_eudebug_vma_metadata metadata;
+	} eudebug;
 };
 
 /**
@@ -311,6 +324,10 @@ struct xe_vma_op_map {
 	bool dumpable;
 	/** @pat_index: The pat index to use for this operation. */
 	u16 pat_index;
+	struct  {
+		/** @vma_metadata: List of vma debug metadata */
+		struct xe_eudebug_vma_metadata metadata;
+	} eudebug;
 };
 
 /** struct xe_vma_op_remap - VMA remap operation */
@@ -388,4 +405,14 @@ struct xe_vma_ops {
 #endif
 };
 
+struct xe_vma_debug_metadata {
+	/** @debug.metadata: id of attached xe_debug_metadata */
+	u32 metadata_id;
+	/** @debug.cookie: user defined cookie */
+	u64 cookie;
+
+	/** @link: list of metadata attached to vma */
+	struct list_head link;
+};
+
 #endif
include/uapi/drm/xe_drm.h +19 -0
index 1a452a8d2a2a..176c348c3fdd 100644
@@ -888,6 +888,23 @@ struct drm_xe_vm_destroy {
 	__u64 reserved[2];
 };
 
+struct drm_xe_vm_bind_op_ext_attach_debug {
+	/** @base: base user extension */
+	struct drm_xe_user_extension base;
+
+	/** @id: Debug object id from create metadata */
+	__u64 metadata_id;
+
+	/** @flags: Flags */
+	__u64 flags;
+
+	/** @cookie: Cookie */
+	__u64 cookie;
+
+	/** @reserved: Reserved */
+	__u64 reserved;
+};
+
 /**
  * struct drm_xe_vm_bind_op - run bind operations
  *
@@ -912,7 +929,9 @@ struct drm_xe_vm_destroy {
  *    handle MBZ, and the BO offset MBZ. This flag is intended to
  *    implement VK sparse bindings.
  */
+
 struct drm_xe_vm_bind_op {
+#define XE_VM_BIND_OP_EXTENSIONS_ATTACH_DEBUG 0
 	/** @extensions: Pointer to the first extension struct, if any */
 	__u64 extensions;
 
Signature · 1 line
2.43.0
#46 lore raw

PATCH 17/26 drm/xe/eudebug: Add debug metadata support for xe_eudebug

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Reflect debug metadata resource creation/destroy as events passed to the debugger. Introduce ioctl allowing to read metadata content on demand.

Each VMA can have multiple metadata attached and it is passed from user on BIND or it's copied on internal remap.

Xe EU Debugger on VM BIND will inform about VMA metadata attachements during bind IOCTL sending proper OP event.

v2: - checkpatch (Maciej, Tilak)
- struct alignment (Matthew)
- Kconfig (Mika)

---
 drivers/gpu/drm/xe/xe_debug_metadata.c |   8 +-
 drivers/gpu/drm/xe/xe_eudebug.c        | 330 ++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug.h        |  21 +-
 drivers/gpu/drm/xe/xe_eudebug_types.h  |  27 +-
 drivers/gpu/drm/xe/xe_vm.c             |   2 +-
 include/uapi/drm/xe_drm_eudebug.h      |  30 +++
 6 files changed, 406 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_debug_metadata.c +7 -1
index b045bdd77235..172fe2b33557 100644
@@ -9,6 +9,7 @@
 #include <uapi/drm/xe_drm.h>
 
 #include "xe_device.h"
+#include "xe_eudebug.h"
 #include "xe_macros.h"
 #include "xe_vm.h"
 
@@ -158,7 +159,7 @@ int xe_debug_metadata_create_ioctl(struct drm_device *dev,
 	if (XE_IOCTL_DBG(xe, args->extensions))
 		return -EINVAL;
 
-	if (XE_IOCTL_DBG(xe, args->type > DRM_XE_DEBUG_METADATA_PROGRAM_MODULE))
+	if (XE_IOCTL_DBG(xe, args->type >= WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_NUM))
 		return -EINVAL;
 
 	if (XE_IOCTL_DBG(xe, !args->user_addr || !args->len))
@@ -194,8 +195,11 @@ int xe_debug_metadata_create_ioctl(struct drm_device *dev,
 	if (err)
 		goto put_mdata;
 
+
 	args->metadata_id = id;
 
+	xe_eudebug_debug_metadata_create(xef, mdata);
+
 	return 0;
 
 put_mdata:
@@ -221,6 +225,8 @@ int xe_debug_metadata_destroy_ioctl(struct drm_device *dev,
 	if (XE_IOCTL_DBG(xe, !mdata))
 		return -ENOENT;
 
+	xe_eudebug_debug_metadata_destroy(xef, mdata);
+
 	xe_debug_metadata_put(mdata);
 
 	return 0;
drivers/gpu/drm/xe/xe_eudebug.c +323 -7

421 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug.h +19 -2
index 13ba0167b31b..572493d341ff 100644
@@ -16,6 +16,8 @@ struct xe_vma;
 struct xe_exec_queue;
 struct xe_hw_engine;
 struct xe_user_fence;
+struct xe_debug_metadata;
+struct drm_gpuva_ops;
 
 #if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
 
@@ -39,7 +41,8 @@ void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q)
 
 void xe_eudebug_vm_init(struct xe_vm *vm);
 void xe_eudebug_vm_bind_start(struct xe_vm *vm);
-void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range);
+void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range,
+			       struct drm_gpuva_ops *ops);
 void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int err);
 
 int xe_eudebug_vm_bind_ufence(struct xe_user_fence *ufence);
@@ -49,6 +52,9 @@ void xe_eudebug_ufence_fini(struct xe_user_fence *ufence);
 struct xe_eudebug *xe_eudebug_get(struct xe_file *xef);
 void xe_eudebug_put(struct xe_eudebug *d);
 
+void xe_eudebug_debug_metadata_create(struct xe_file *xef, struct xe_debug_metadata *m);
+void xe_eudebug_debug_metadata_destroy(struct xe_file *xef, struct xe_debug_metadata *m);
+
 #else
 
 static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
@@ -71,7 +77,8 @@ static inline void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_
 
 static inline void xe_eudebug_vm_init(struct xe_vm *vm) { }
 static inline void xe_eudebug_vm_bind_start(struct xe_vm *vm) { }
-static inline void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range) { }
+static inline void xe_eudebug_vm_bind_op_add(struct xe_vm *vm, u32 op, u64 addr, u64 range,
+					     struct drm_gpuva_ops *ops) { }
 static inline void xe_eudebug_vm_bind_end(struct xe_vm *vm, bool has_ufence, int err) { }
 
 static inline int xe_eudebug_vm_bind_ufence(struct xe_user_fence *ufence) { return 0; }
@@ -82,6 +89,16 @@ static inline void xe_eudebug_ufence_fini(struct xe_user_fence *ufence) { }
 static inline struct xe_eudebug *xe_eudebug_get(struct xe_file *xef) { return NULL; }
 static inline void xe_eudebug_put(struct xe_eudebug *d) { }
 
+static inline void xe_eudebug_debug_metadata_create(struct xe_file *xef,
+						    struct xe_debug_metadata *m)
+{
+}
+
+static inline void xe_eudebug_debug_metadata_destroy(struct xe_file *xef,
+						     struct xe_debug_metadata *m)
+{
+}
+
 #endif /* CONFIG_DRM_XE_EUDEBUG */
 
 #endif
drivers/gpu/drm/xe/xe_eudebug_types.h +26 -1
index ffb0dc71430a..a69051b04698 100644
@@ -56,7 +56,8 @@ struct xe_eudebug_resource {
 #define XE_EUDEBUG_RES_TYPE_VM		1
 #define XE_EUDEBUG_RES_TYPE_EXEC_QUEUE	2
 #define XE_EUDEBUG_RES_TYPE_LRC		3
-#define XE_EUDEBUG_RES_TYPE_COUNT	(XE_EUDEBUG_RES_TYPE_LRC + 1)
+#define XE_EUDEBUG_RES_TYPE_METADATA	4
+#define XE_EUDEBUG_RES_TYPE_COUNT	(XE_EUDEBUG_RES_TYPE_METADATA + 1)
 
 /**
  * struct xe_eudebug_resources - eudebug resources for all types
@@ -326,4 +327,28 @@ struct xe_eudebug_event_vm_bind_ufence {
 	u64 vm_bind_ref_seqno;
 };
 
+struct xe_eudebug_event_metadata {
+	struct xe_eudebug_event base;
+
+	/** @client_handle: client for the attention */
+	u64 client_handle;
+
+	/** @metadata_handle: debug metadata handle it's created/destroyed */
+	u64 metadata_handle;
+
+	/* @type: metadata type, refer to xe_drm.h for options */
+	u64 type;
+
+	/* @len: size of metadata paylad */
+	u64 len;
+};
+
+struct xe_eudebug_event_vm_bind_op_metadata {
+	struct xe_eudebug_event base;
+	u64 vm_bind_op_ref_seqno;
+
+	u64 metadata_handle;
+	u64 metadata_cookie;
+};
+
 #endif
drivers/gpu/drm/xe/xe_vm.c +1 -1
index 19c0b36c10b1..474521d0fea9 100644
@@ -3178,7 +3178,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		if (err)
 			goto unwind_ops;
 
-		xe_eudebug_vm_bind_op_add(vm, op, addr, range);
+		xe_eudebug_vm_bind_op_add(vm, op, addr, range, ops[i]);
 
 #ifdef TEST_VM_OPS_ERROR
 		if (flags & FORCE_OP_ERROR) {
include/uapi/drm/xe_drm_eudebug.h +30 -0
index a5f13563b3b9..3c4d1b511acd 100644
@@ -19,6 +19,7 @@ extern "C" {
 #define DRM_XE_EUDEBUG_IOCTL_EU_CONTROL		_IOWR('j', 0x2, struct drm_xe_eudebug_eu_control)
 #define DRM_XE_EUDEBUG_IOCTL_ACK_EVENT		_IOW('j', 0x4, struct drm_xe_eudebug_ack_event)
 #define DRM_XE_EUDEBUG_IOCTL_VM_OPEN		_IOW('j', 0x1, struct drm_xe_eudebug_vm_open)
+#define DRM_XE_EUDEBUG_IOCTL_READ_METADATA	_IOWR('j', 0x3, struct drm_xe_eudebug_read_metadata)
 
 /* XXX: Document events to match their internal counterparts when moved to xe_drm.h */
 struct drm_xe_eudebug_event {
@@ -35,6 +36,8 @@ struct drm_xe_eudebug_event {
 #define DRM_XE_EUDEBUG_EVENT_VM_BIND		7
 #define DRM_XE_EUDEBUG_EVENT_VM_BIND_OP		8
 #define DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE	9
+#define DRM_XE_EUDEBUG_EVENT_METADATA		10
+#define DRM_XE_EUDEBUG_EVENT_VM_BIND_OP_METADATA 11
 
 	__u16 flags;
 #define DRM_XE_EUDEBUG_EVENT_CREATE		(1 << 0)
@@ -206,6 +209,33 @@ struct drm_xe_eudebug_vm_open {
 	__u64 timeout_ns;
 };
 
+struct drm_xe_eudebug_read_metadata {
+	__u64 client_handle;
+	__u64 metadata_handle;
+	__u32 flags;
+	__u32 reserved;
+	__u64 ptr;
+	__u64 size;
+};
+
+struct drm_xe_eudebug_event_metadata {
+	struct drm_xe_eudebug_event base;
+
+	__u64 client_handle;
+	__u64 metadata_handle;
+	/* XXX: Refer to xe_drm.h for fields */
+	__u64 type;
+	__u64 len;
+};
+
+struct drm_xe_eudebug_event_vm_bind_op_metadata {
+	struct drm_xe_eudebug_event base;
+	__u64 vm_bind_op_ref_seqno; /* *_event_vm_bind_op.base.seqno */
+
+	__u64 metadata_handle;
+	__u64 metadata_cookie;
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#47 lore raw

PATCH 18/26 drm/xe/eudebug: Implement vm_bind_op discovery

In reply to Mika Kuoppala

Follow the vm bind, vm_bind op sequence for discovery process of a vm with the vmas it has. Send events for ops and attach metadata if available.

v2: - Fix bad op ref seqno (Christoph)
- with discovery semaphore, we dont need vm lock (Matthew)

---
 drivers/gpu/drm/xe/xe_eudebug.c | 45 +++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/gpu/drm/xe/xe_eudebug.c +45 -0
index 2514b880d871..e17b8f98c7b6 100644
@@ -3243,6 +3243,47 @@ void xe_eudebug_debug_metadata_destroy(struct xe_file *xef, struct xe_debug_meta
 	xe_eudebug_event_put(d, debug_metadata_destroy_event(d, xef, m));
 }
 
+static int vm_discover_binds(struct xe_eudebug *d, struct xe_vm *vm)
+{
+	struct drm_gpuva *va;
+	unsigned int num_ops = 0, send_ops = 0;
+	u64 ref_seqno = 0;
+	int err;
+
+	/*
+	 * Currently only vm_bind_ioctl inserts vma's
+	 * and with discovery lock, we have exclusivity.
+	 */
+	lockdep_assert_held_write(&d->xe->eudebug.discovery_lock);
+
+	drm_gpuvm_for_each_va(va, &vm->gpuvm)
+		num_ops++;
+
+	if (!num_ops)
+		return 0;
+
+	err = vm_bind_event(d, vm, num_ops, &ref_seqno);
+	if (err)
+		return err;
+
+	drm_gpuvm_for_each_va(va, &vm->gpuvm) {
+		struct xe_vma *vma = container_of(va, struct xe_vma, gpuva);
+
+		if (send_ops >= num_ops)
+			break;
+
+		err = vm_bind_op(d, vm, DRM_XE_EUDEBUG_EVENT_CREATE, ref_seqno,
+				 xe_vma_start(vma), xe_vma_size(vma),
+				 &vma->eudebug.metadata.list);
+		if (err)
+			return err;
+
+		send_ops++;
+	}
+
+	return num_ops == send_ops ? 0 : -EINVAL;
+}
+
 static int discover_client(struct xe_eudebug *d, struct xe_file *xef)
 {
 	struct xe_debug_metadata *m;
@@ -3265,6 +3306,10 @@ static int discover_client(struct xe_eudebug *d, struct xe_file *xef)
 		err = vm_create_event(d, xef, vm);
 		if (err)
 			break;
+
+		err = vm_discover_binds(d, vm);
+		if (err)
+			break;
 	}
 
 	xa_for_each(&xef->exec_queue.xa, i, q) {
Signature · 1 line
2.43.0
#48 lore raw

PATCH 19/26 drm/xe/eudebug: Dynamically toggle debugger functionality

In reply to Mika Kuoppala

From: Christoph Manszewski <[email protected]>

Make it possible to dynamically enable/disable debugger funtionality, including the setting and unsetting of required hw register values via a sysfs entry located at '/sys/class/drm/card<X>/device/enable_eudebug'.

This entry uses 'kstrtobool' and as such it accepts inputs as documented by this function, in particular '0' and '1'.

v2: use new discovery_lock to gain exclusivity (Mika)
v3: remove init_late and init_hw_engine (Dominik)

---
 drivers/gpu/drm/xe/xe_device.c       |   2 -
 drivers/gpu/drm/xe/xe_device_types.h |   3 +
 drivers/gpu/drm/xe/xe_eudebug.c      | 128 +++++++++++++++++++++++----
 drivers/gpu/drm/xe/xe_eudebug.h      |   4 -
 drivers/gpu/drm/xe/xe_exec_queue.c   |   5 ++
 drivers/gpu/drm/xe/xe_hw_engine.c    |   1 -
 drivers/gpu/drm/xe/xe_reg_sr.c       |  21 +++--
 drivers/gpu/drm/xe/xe_reg_sr.h       |   4 +-
 drivers/gpu/drm/xe/xe_rtp.c          |   2 +-
 9 files changed, 137 insertions(+), 33 deletions(-)
drivers/gpu/drm/xe/xe_device.c +0 -2
index a7a715475184..3045f2a2ca1d 100644
@@ -782,8 +782,6 @@ int xe_device_probe(struct xe_device *xe)
 
 	xe_debugfs_register(xe);
 
-	xe_eudebug_init_late(xe);
-
 	xe_hwmon_register(xe);
 
 	for_each_gt(gt, xe, id)
drivers/gpu/drm/xe/xe_device_types.h +3 -0
index 4ab9f06eba2d..f081af5e729d 100644
@@ -557,6 +557,9 @@ struct xe_device {
 		/** discovery_lock: used for discovery to block xe ioctls */
 		struct rw_semaphore discovery_lock;
 
+		/** @enable: is the debugging functionality enabled */
+		bool enable;
+
 		/** @attention_scan: attention scan worker */
 		struct delayed_work attention_scan;
 	} eudebug;
drivers/gpu/drm/xe/xe_eudebug.c +110 -18

184 lines not on this page · raw message

drivers/gpu/drm/xe/xe_eudebug.h +0 -4
index 572493d341ff..a08abf796cc1 100644
@@ -26,9 +26,7 @@ int xe_eudebug_connect_ioctl(struct drm_device *dev,
 			     struct drm_file *file);
 
 void xe_eudebug_init(struct xe_device *xe);
-void xe_eudebug_init_late(struct xe_device *xe);
 void xe_eudebug_fini(struct xe_device *xe);
-void xe_eudebug_init_hw_engine(struct xe_hw_engine *hwe);
 
 void xe_eudebug_file_open(struct xe_file *xef);
 void xe_eudebug_file_close(struct xe_file *xef);
@@ -62,9 +60,7 @@ static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
 					   struct drm_file *file) { return 0; }
 
 static inline void xe_eudebug_init(struct xe_device *xe) { }
-static inline void xe_eudebug_init_late(struct xe_device *xe) { }
 static inline void xe_eudebug_fini(struct xe_device *xe) { }
-static inline void xe_eudebug_init_hw_engine(struct xe_hw_engine *hwe) { }
 
 static inline void xe_eudebug_file_open(struct xe_file *xef) { }
 static inline void xe_eudebug_file_close(struct xe_file *xef) { }
drivers/gpu/drm/xe/xe_exec_queue.c +5 -0
index cca46a32723e..044a0f2e1873 100644
@@ -432,6 +432,11 @@ static int exec_queue_set_eudebug(struct xe_device *xe, struct xe_exec_queue *q,
 			 !(value & DRM_XE_EXEC_QUEUE_EUDEBUG_FLAG_ENABLE)))
 		return -EINVAL;
 
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+	if (XE_IOCTL_DBG(xe, !xe->eudebug.enable))
+		return -EPERM;
+#endif
+
 	q->eudebug_flags = EXEC_QUEUE_EUDEBUG_FLAG_ENABLE;
 	q->sched_props.preempt_timeout_us = 0;
 
drivers/gpu/drm/xe/xe_hw_engine.c +0 -1
index 8a188ddc99f4..c734aae88a57 100644
@@ -559,7 +559,6 @@ static void hw_engine_init_early(struct xe_gt *gt, struct xe_hw_engine *hwe,
 	xe_tuning_process_engine(hwe);
 	xe_wa_process_engine(hwe);
 	hw_engine_setup_default_state(hwe);
-	xe_eudebug_init_hw_engine(hwe);
 
 	xe_reg_sr_init(&hwe->reg_whitelist, hwe->name, gt_to_xe(gt));
 	xe_reg_whitelist_process_engine(hwe);
drivers/gpu/drm/xe/xe_reg_sr.c +15 -6
index e1a0e27cda14..e3a539c1c08e 100644
@@ -93,22 +93,31 @@ static void reg_sr_inc_error(struct xe_reg_sr *sr)
 
 int xe_reg_sr_add(struct xe_reg_sr *sr,
 		  const struct xe_reg_sr_entry *e,
-		  struct xe_gt *gt)
+		  struct xe_gt *gt,
+		  bool overwrite)
 {
 	unsigned long idx = e->reg.addr;
 	struct xe_reg_sr_entry *pentry = xa_load(&sr->xa, idx);
 	int ret;
 
 	if (pentry) {
-		if (!compatible_entries(pentry, e)) {
+		if (overwrite && e->set_bits) {
+			pentry->clr_bits |= e->clr_bits;
+			pentry->set_bits |= e->set_bits;
+			pentry->read_mask |= e->read_mask;
+		} else if (overwrite && !e->set_bits) {
+			pentry->clr_bits |= e->clr_bits;
+			pentry->set_bits &= ~e->clr_bits;
+			pentry->read_mask |= e->read_mask;
+		} else if (!compatible_entries(pentry, e)) {
 			ret = -EINVAL;
 			goto fail;
+		} else {
+			pentry->clr_bits |= e->clr_bits;
+			pentry->set_bits |= e->set_bits;
+			pentry->read_mask |= e->read_mask;
 		}
 
-		pentry->clr_bits |= e->clr_bits;
-		pentry->set_bits |= e->set_bits;
-		pentry->read_mask |= e->read_mask;
-
 		return 0;
 	}
 
drivers/gpu/drm/xe/xe_reg_sr.h +3 -1
index 51fbba423e27..d67fafdcd847 100644
@@ -6,6 +6,8 @@
 #ifndef _XE_REG_SR_
 #define _XE_REG_SR_
 
+#include <linux/types.h>
+
 /*
  * Reg save/restore bookkeeping
  */
@@ -21,7 +23,7 @@ int xe_reg_sr_init(struct xe_reg_sr *sr, const char *name, struct xe_device *xe)
 void xe_reg_sr_dump(struct xe_reg_sr *sr, struct drm_printer *p);
 
 int xe_reg_sr_add(struct xe_reg_sr *sr, const struct xe_reg_sr_entry *e,
-		  struct xe_gt *gt);
+		  struct xe_gt *gt, bool overwrite);
 void xe_reg_sr_apply_mmio(struct xe_reg_sr *sr, struct xe_gt *gt);
 void xe_reg_sr_apply_whitelist(struct xe_hw_engine *hwe);
 
drivers/gpu/drm/xe/xe_rtp.c +1 -1
index b13d4d62f0b1..6006f7c90cac 100644
@@ -153,7 +153,7 @@ static void rtp_add_sr_entry(const struct xe_rtp_action *action,
 	};
 
 	sr_entry.reg.addr += mmio_base;
-	xe_reg_sr_add(sr, &sr_entry, gt);
+	xe_reg_sr_add(sr, &sr_entry, gt, false);
 }
 
 static bool rtp_process_one_sr(const struct xe_rtp_entry_sr *entry,
Signature · 1 line
2.43.0
#49 lore raw

PATCH 20/26 drm/xe/eudebug_test: Introduce xe_eudebug wa kunit test

In reply to Mika Kuoppala

From: Christoph Manszewski <[email protected]>

Introduce kunit test for eudebug. For now it checks the dynamic application of WAs.

v2: adapt to removal of call_for_each_device (Mika)
v3: s/FW_RENDER/FORCEWAKE_ALL (Mika)

---
 drivers/gpu/drm/xe/tests/xe_eudebug.c       | 176 ++++++++++++++++++++
 drivers/gpu/drm/xe/tests/xe_live_test_mod.c |   5 +
 drivers/gpu/drm/xe/xe_eudebug.c             |   4 +
 3 files changed, 185 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/tests/xe_eudebug.c
drivers/gpu/drm/xe/tests/xe_eudebug.c new file +176 -0
new file mode 100644
index 000000000000..d47e4ff259cb
@@ -0,0 +1,176 @@
+// SPDX-License-Identifier: GPL-2.0 AND MIT
+/*
+ * Copyright © 2024 Intel Corporation
+ */
+
+#include <kunit/visibility.h>
+
+#include "tests/xe_kunit_helpers.h"
+#include "tests/xe_pci_test.h"
+#include "tests/xe_test.h"
+
+#undef XE_REG_MCR
+#define XE_REG_MCR(r_, ...)	((const struct xe_reg_mcr){					\
+				 .__reg = XE_REG_INITIALIZER(r_,  ##__VA_ARGS__, .mcr = 1)	\
+				 })
+
+static const char *reg_to_str(struct xe_reg reg)
+{
+	if (reg.raw == TD_CTL.__reg.raw)
+		return "TD_CTL";
+	else if (reg.raw == CS_DEBUG_MODE2(RENDER_RING_BASE).raw)
+		return "CS_DEBUG_MODE2";
+	else if (reg.raw == ROW_CHICKEN.__reg.raw)
+		return "ROW_CHICKEN";
+	else if (reg.raw == ROW_CHICKEN2.__reg.raw)
+		return "ROW_CHICKEN2";
+	else if (reg.raw == ROW_CHICKEN3.__reg.raw)
+		return "ROW_CHICKEN3";
+	else
+		return "UNKNOWN REG";
+}
+
+static u32 get_reg_mask(struct xe_device *xe, struct xe_reg reg)
+{
+	struct kunit *test = kunit_get_current_test();
+	u32 val = 0;
+
+	if (reg.raw == TD_CTL.__reg.raw) {
+		val = TD_CTL_BREAKPOINT_ENABLE |
+		      TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE |
+		      TD_CTL_FEH_AND_FEE_ENABLE;
+
+		if (GRAPHICS_VERx100(xe) >= 1250)
+			val |= TD_CTL_GLOBAL_DEBUG_ENABLE;
+
+	} else if (reg.raw == CS_DEBUG_MODE2(RENDER_RING_BASE).raw) {
+		val = GLOBAL_DEBUG_ENABLE;
+	} else if (reg.raw == ROW_CHICKEN.__reg.raw) {
+		val = STALL_DOP_GATING_DISABLE;
+	} else if (reg.raw == ROW_CHICKEN2.__reg.raw) {
+		val = XEHPC_DISABLE_BTB;
+	} else if (reg.raw == ROW_CHICKEN3.__reg.raw) {
+		val = XE2_EUPEND_CHK_FLUSH_DIS;
+	} else {
+		kunit_warn(test, "Invalid register selection: %u\n", reg.raw);
+	}
+
+	return val;
+}
+
+static u32 get_reg_expected(struct xe_device *xe, struct xe_reg reg, bool enable_eudebug)
+{
+	u32 reg_mask = get_reg_mask(xe, reg);
+	u32 reg_bits = 0;
+
+	if (enable_eudebug || reg.raw == ROW_CHICKEN3.__reg.raw)
+		reg_bits = reg_mask;
+	else
+		reg_bits = 0;
+
+	return reg_bits;
+}
+
+static void check_reg(struct xe_gt *gt, bool enable_eudebug, struct xe_reg reg)
+{
+	struct kunit *test = kunit_get_current_test();
+	struct xe_device *xe = gt_to_xe(gt);
+	u32 reg_bits_expected = get_reg_expected(xe, reg, enable_eudebug);
+	u32 reg_mask = get_reg_mask(xe, reg);
+	u32 reg_bits = 0;
+
+	if (reg.mcr)
+		reg_bits = xe_gt_mcr_unicast_read_any(gt, (struct xe_reg_mcr){.__reg = reg});
+	else
+		reg_bits = xe_mmio_read32(&gt->mmio, reg);
+
+	reg_bits &= reg_mask;
+
+	kunit_printk(KERN_DEBUG, test, "%s bits: expected == 0x%x; actual == 0x%x\n",
+		     reg_to_str(reg), reg_bits_expected, reg_bits);
+	KUNIT_EXPECT_EQ_MSG(test, reg_bits_expected, reg_bits,
+			    "Invalid bits set for %s\n", reg_to_str(reg));
+}
+
+static void __check_regs(struct xe_gt *gt, bool enable_eudebug)
+{
+	struct xe_device *xe = gt_to_xe(gt);
+
+	if (GRAPHICS_VERx100(xe) >= 1200)
+		check_reg(gt, enable_eudebug, TD_CTL.__reg);
+
+	if (GRAPHICS_VERx100(xe) >= 1250 && GRAPHICS_VERx100(xe) <= 1274)
+		check_reg(gt, enable_eudebug, ROW_CHICKEN.__reg);
+
+	if (xe->info.platform == XE_PVC)
+		check_reg(gt, enable_eudebug, ROW_CHICKEN2.__reg);
+
+	if (GRAPHICS_VERx100(xe) >= 2000 && GRAPHICS_VERx100(xe) <= 2004)
+		check_reg(gt, enable_eudebug, ROW_CHICKEN3.__reg);
+}
+
+static void check_regs(struct xe_device *xe, bool enable_eudebug)
+{
+	struct kunit *test = kunit_get_current_test();
+	struct xe_gt *gt;
+	unsigned int fw_ref;
+	u8 id;
+
+	kunit_printk(KERN_DEBUG, test, "Check regs for eudebug %s\n",
+		     enable_eudebug ? "enabled" : "disabled");
+
+	xe_pm_runtime_get(xe);
+	for_each_gt(gt, xe, id) {
+		if (xe_gt_is_media_type(gt))
+			continue;
+
+		/* XXX: Figure out per platform proper domain */
+		fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
+		KUNIT_ASSERT_TRUE_MSG(test, fw_ref, "Forcewake failed.\n");
+
+		__check_regs(gt, enable_eudebug);
+
+		xe_force_wake_put(gt_to_fw(gt), fw_ref);
+	}
+	xe_pm_runtime_put(xe);
+}
+
+static int toggle_reg_value(struct xe_device *xe)
+{
+	struct kunit *test = kunit_get_current_test();
+	bool enable_eudebug = xe->eudebug.enable;
+
+	kunit_printk(KERN_DEBUG, test, "Test eudebug WAs for graphics version: %u\n",
+		     GRAPHICS_VERx100(xe));
+
+	check_regs(xe, enable_eudebug);
+
+	xe_eudebug_enable(xe, !enable_eudebug);
+	check_regs(xe, !enable_eudebug);
+
+	xe_eudebug_enable(xe, enable_eudebug);
+	check_regs(xe, enable_eudebug);
+
+	return 0;
+}
+
+static void xe_eudebug_toggle_reg_kunit(struct kunit *test)
+{
+	struct xe_device *xe = test->priv;
+
+	toggle_reg_value(xe);
+}
+
+static struct kunit_case xe_eudebug_tests[] = {
+	KUNIT_CASE_PARAM(xe_eudebug_toggle_reg_kunit,
+			 xe_pci_live_device_gen_param),
+	{}
+};
+
+VISIBLE_IF_KUNIT
+struct kunit_suite xe_eudebug_test_suite = {
+	.name = "xe_eudebug",
+	.test_cases = xe_eudebug_tests,
+	.init = xe_kunit_helper_xe_device_live_test_init,
+};
+EXPORT_SYMBOL_IF_KUNIT(xe_eudebug_test_suite);
drivers/gpu/drm/xe/tests/xe_live_test_mod.c +5 -0
index 5f14737c8210..7dd8a0a4bdfd 100644
@@ -15,6 +15,11 @@ kunit_test_suite(xe_dma_buf_test_suite);
 kunit_test_suite(xe_migrate_test_suite);
 kunit_test_suite(xe_mocs_test_suite);
 
+#if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
+extern struct kunit_suite xe_eudebug_test_suite;
+kunit_test_suite(xe_eudebug_test_suite);
+#endif
+
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("xe live kunit tests");
drivers/gpu/drm/xe/xe_eudebug.c +4 -0
index fe947d5350d8..f44cc0f8290e 100644
@@ -3947,3 +3947,7 @@ xe_eudebug_vm_open_ioctl(struct xe_eudebug *d, unsigned long arg)
 
 	return ret;
 }
+
+#if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
+#include "tests/xe_eudebug.c"
+#endif
Signature · 1 line
2.43.0
#50 lore raw

PATCH 21/26 drm/xe/eudebug/ptl: Add support for extra attention register

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

xe3 can set bits within an additional attention bit register EU_ATT1. Recalculate bitmask and make sure we read all required data.

---
 drivers/gpu/drm/xe/xe_eudebug.c  | 4 ++--
 drivers/gpu/drm/xe/xe_gt_debug.c | 8 ++++----
 drivers/gpu/drm/xe/xe_gt_debug.h | 8 ++++++--
 3 files changed, 12 insertions(+), 8 deletions(-)
drivers/gpu/drm/xe/xe_eudebug.c +2 -2
index f44cc0f8290e..c259e5804386 100644
@@ -1858,7 +1858,7 @@ static int check_attn_mcr(struct xe_gt *gt, void *data,
 	struct xe_eudebug *d = iter->debugger;
 	unsigned int row;
 
-	for (row = 0; row < TD_EU_ATTENTION_MAX_ROWS; row++) {
+	for (row = 0; row < xe_gt_debug_eu_att_rows(gt); row++) {
 		u32 val, cur = 0;
 
 		if (iter->i >= iter->size)
@@ -1891,7 +1891,7 @@ static int clear_attn_mcr(struct xe_gt *gt, void *data,
 	struct xe_eudebug *d = iter->debugger;
 	unsigned int row;
 
-	for (row = 0; row < TD_EU_ATTENTION_MAX_ROWS; row++) {
+	for (row = 0; row < xe_gt_debug_eu_att_rows(gt); row++) {
 		u32 val;
 
 		if (iter->i >= iter->size)
drivers/gpu/drm/xe/xe_gt_debug.c +4 -4
index f35b9df5e41b..49f24db9da9c 100644
@@ -74,9 +74,9 @@ int xe_gt_eu_attention_bitmap_size(struct xe_gt *gt)
 	bitmap_or(dss_mask, gt->fuse_topo.c_dss_mask,
 		  gt->fuse_topo.g_dss_mask, XE_MAX_DSS_FUSE_BITS);
 
-	return  bitmap_weight(dss_mask, XE_MAX_DSS_FUSE_BITS) *
-		TD_EU_ATTENTION_MAX_ROWS * MAX_THREADS *
-		MAX_EUS_PER_ROW / 8;
+	return bitmap_weight(dss_mask, XE_MAX_DSS_FUSE_BITS) *
+	       xe_gt_debug_eu_att_rows(gt) * MAX_THREADS *
+	       MAX_EUS_PER_ROW / 8;
 }
 
 struct attn_read_iter {
@@ -92,7 +92,7 @@ static int read_eu_attentions_mcr(struct xe_gt *gt, void *data,
 	struct attn_read_iter * const iter = data;
 	unsigned int row;
 
-	for (row = 0; row < TD_EU_ATTENTION_MAX_ROWS; row++) {
+	for (row = 0; row < xe_gt_debug_eu_att_rows(gt); row++) {
 		u32 val;
 
 		if (iter->i >= iter->size)
drivers/gpu/drm/xe/xe_gt_debug.h +6 -2
index 342082699ff6..1edb667154f1 100644
@@ -6,12 +6,16 @@
 #ifndef __XE_GT_DEBUG_
 #define __XE_GT_DEBUG_
 
-#define TD_EU_ATTENTION_MAX_ROWS 2u
-
+#include "xe_device_types.h"
 #include "xe_gt_types.h"
 
 #define XE_GT_ATTENTION_TIMEOUT_MS 100
 
+static inline unsigned int xe_gt_debug_eu_att_rows(struct xe_gt *gt)
+{
+	return (GRAPHICS_VERx100(gt_to_xe(gt)) >= 3000) ? 4u : 2u;
+}
+
 int xe_gt_eu_threads_needing_attention(struct xe_gt *gt);
 int xe_gt_foreach_dss_group_instance(struct xe_gt *gt,
 				     int (*fn)(struct xe_gt *gt,
Signature · 1 line
2.43.0
#51 lore raw

PATCH 22/26 drm/xe/eudebug/ptl: Add RCU_DEBUG_1 register support for xe3

In reply to Mika Kuoppala

From: Dominik Grzegorzek <[email protected]>

Format of Register_RenderControlUnitDebug1 is different from previous gens. Adjust it so it matches PTL/xe3 format.

---
 drivers/gpu/drm/xe/xe_eudebug.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpu/drm/xe/xe_eudebug.c +13 -0
index c259e5804386..09b455a96571 100644
@@ -1443,6 +1443,17 @@ static u32 engine_status_xe2(const struct xe_hw_engine * const hwe,
 	return (rcu_debug1 >> shift) & RCU_DEBUG_1_ENGINE_STATUS;
 }
 
+static u32 engine_status_xe3(const struct xe_hw_engine * const hwe,
+			     u32 rcu_debug1)
+{
+	const unsigned int first = 6;
+	const unsigned int incr = 4;
+	const unsigned int i = rcu_debug1_engine_index(hwe);
+	const unsigned int shift = first + (i * incr);
+
+	return (rcu_debug1 >> shift) & RCU_DEBUG_1_ENGINE_STATUS;
+}
+
 static u32 engine_status(const struct xe_hw_engine * const hwe,
 			 u32 rcu_debug1)
 {
@@ -1452,6 +1463,8 @@ static u32 engine_status(const struct xe_hw_engine * const hwe,
 		status = engine_status_xe1(hwe, rcu_debug1);
 	else if (GRAPHICS_VER(gt_to_xe(hwe->gt)) < 30)
 		status = engine_status_xe2(hwe, rcu_debug1);
+	else if (GRAPHICS_VER(gt_to_xe(hwe->gt)) < 35)
+		status = engine_status_xe3(hwe, rcu_debug1);
 	else
 		XE_WARN_ON(GRAPHICS_VER(gt_to_xe(hwe->gt)));
 
Signature · 1 line
2.43.0
#52 lore raw

PATCH 23/26 drm/xe/eudebug: Add read/count/compare helper for eu attention

In reply to Mika Kuoppala

From: Gwan-gyeong Mun <[email protected]>

Add xe_eu_attentions structure to capture and store eu attention bits. Add a function to count the number of eu threads that have turned on from eu attentions, and add a function to count the number of eu threads that have changed on a state between eu attentions.

---
 drivers/gpu/drm/xe/xe_gt_debug.c | 64 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_gt_debug.h | 15 ++++++++
 2 files changed, 79 insertions(+)
drivers/gpu/drm/xe/xe_gt_debug.c +64 -0
index 49f24db9da9c..a20e1e57212c 100644
@@ -3,6 +3,7 @@
  * Copyright © 2023 Intel Corporation
  */
 
+#include <linux/delay.h>
 #include "regs/xe_gt_regs.h"
 #include "xe_device.h"
 #include "xe_force_wake.h"
@@ -146,3 +147,66 @@ int xe_gt_eu_threads_needing_attention(struct xe_gt *gt)
 
 	return err < 0 ? 0 : err;
 }
+
+static inline unsigned int
+xe_eu_attentions_count(const struct xe_eu_attentions *a)
+{
+	return bitmap_weight((void *)a->att, a->size * BITS_PER_BYTE);
+}
+
+void xe_gt_eu_attentions_read(struct xe_gt *gt,
+			      struct xe_eu_attentions *a,
+			      const unsigned int settle_time_ms)
+{
+	unsigned int prev = 0;
+	ktime_t end, now;
+
+	now = ktime_get_raw();
+	end = ktime_add_ms(now, settle_time_ms);
+
+	a->ts = 0;
+	a->size = min_t(int,
+			xe_gt_eu_attention_bitmap_size(gt),
+			sizeof(a->att));
+
+	do {
+		unsigned int attn;
+
+		xe_gt_eu_attention_bitmap(gt, a->att, a->size);
+		attn = xe_eu_attentions_count(a);
+
+		now = ktime_get_raw();
+
+		if (a->ts == 0)
+			a->ts = now;
+		else if (attn && attn != prev)
+			a->ts = now;
+
+		prev = attn;
+
+		if (settle_time_ms)
+			udelay(5);
+
+		/*
+		 * XXX We are gathering data for production SIP to find
+		 * the upper limit of settle time. For now, we wait full
+		 * timeout value regardless.
+		 */
+	} while (ktime_before(now, end));
+}
+
+unsigned int xe_eu_attentions_xor_count(const struct xe_eu_attentions *a,
+					const struct xe_eu_attentions *b)
+{
+	unsigned int count = 0;
+	unsigned int i;
+
+	if (XE_WARN_ON(a->size != b->size))
+		return -EINVAL;
+
+	for (i = 0; i < a->size; i++)
+		if (a->att[i] ^ b->att[i])
+			count++;
+
+	return count;
+}
drivers/gpu/drm/xe/xe_gt_debug.h +15 -0
index 1edb667154f1..1d50b93235ae 100644
@@ -11,6 +11,15 @@
 
 #define XE_GT_ATTENTION_TIMEOUT_MS 100
 
+struct xe_eu_attentions {
+#define XE_MAX_EUS 1024
+#define XE_MAX_THREADS 10
+
+	u8 att[DIV_ROUND_UP(XE_MAX_EUS * XE_MAX_THREADS, BITS_PER_BYTE)];
+	unsigned int size;
+	ktime_t ts;
+};
+
 static inline unsigned int xe_gt_debug_eu_att_rows(struct xe_gt *gt)
 {
 	return (GRAPHICS_VERx100(gt_to_xe(gt)) >= 3000) ? 4u : 2u;
@@ -28,4 +37,10 @@ int xe_gt_eu_attention_bitmap_size(struct xe_gt *gt);
 int xe_gt_eu_attention_bitmap(struct xe_gt *gt, u8 *bits,
 			      unsigned int bitmap_size);
 
+void xe_gt_eu_attentions_read(struct xe_gt *gt,
+			      struct xe_eu_attentions *a,
+			      const unsigned int settle_time_ms);
+
+unsigned int xe_eu_attentions_xor_count(const struct xe_eu_attentions *a,
+					const struct xe_eu_attentions *b);
 #endif
Signature · 1 line
2.43.0
#53 lore raw

PATCH 24/26 drm/xe/eudebug: Introduce EU pagefault handling interface

In reply to Mika Kuoppala

From: Gwan-gyeong Mun <[email protected]>

The XE2 (and PVC) HW has a limitation that the pagefault due to invalid access will halt the corresponding EUs. To solve this problem, introduce EU pagefault handling functionality, which allows to unhalt pagefaulted eu threads and to EU debugger to get inform about the eu attentions state of EU threads during execution.

If a pagefault occurs, send the DRM_XE_EUDEBUG_EVENT_PAGEFAULT event to the client connected to the xe_eudebug after handling the pagefault. The pagefault eudebug event follows the newly added drm_xe_eudebug_event_pagefault type.
When a pagefault occurs, it prevents to send the DRM_XE_EUDEBUG_EVENT_EU_ATTENTION event to the client during pagefault handling.

The page fault event delivery follows the below policy.
(1) If EU Debugger discovery has completed and pagefaulted eu threads turn on attention bit then pagefault handler delivers pagefault event directly.
(2) If a pagefault occurs during eu debugger discovery process, pagefault handler queues a pagefault event and sends the queued event when discovery has completed and pagefaulted eu threads turn on attention bit.
(3) If the pagefaulted eu thread struggles to turn on the attention bit within the specified time, the attention scan worker sends a pagefault event when it detects that the attention bit is turned on.

If multiple eu threads are running and a pagefault occurs due to accessing the same invalid address, send a single pagefault event (DRM_XE_EUDEBUG_EVENT_PAGEFAULT type) to the user debugger instead of a pagefault event for each of the multiple eu threads.
If eu threads (other than the one that caused the page fault before) access the new invalid addresses, send a new pagefault event.

As the attention scan worker send the eu attention event whenever the attention bit is turned on, user debugger receives attenion event immediately after pagefault event.
In this case, the page-fault event always precedes the attention event.

When the user debugger receives an attention event after a pagefault event, it can detect whether additional breakpoints or interrupts occur in addition to the existing pagefault by comparing the eu threads where the pagefault occurred with the eu threads where the attention bit is newly enabled.

---
 drivers/gpu/drm/xe/xe_eudebug.c       | 489 +++++++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eudebug.h       |  28 ++
 drivers/gpu/drm/xe/xe_eudebug_types.h |  94 +++++
 drivers/gpu/drm/xe/xe_gt_pagefault.c  |   4 +-
 drivers/gpu/drm/xe/xe_gt_pagefault.h  |   2 +
 include/uapi/drm/xe_drm_eudebug.h     |  13 +
 6 files changed, 626 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_eudebug.c +487 -2
index 09b455a96571..0fd0958c5790 100644
@@ -31,6 +31,7 @@
 #include "xe_gt.h"
 #include "xe_gt_debug.h"
 #include "xe_gt_mcr.h"
+#include "xe_gt_pagefault.h"
 #include "xe_guc_exec_queue_types.h"
 #include "xe_hw_engine.h"
 #include "xe_lrc.h"
@@ -236,10 +237,17 @@ static void xe_eudebug_free(struct kref *ref)
 {
 	struct xe_eudebug *d = container_of(ref, typeof(*d), ref);
 	struct xe_eudebug_event *event;
+	struct xe_eudebug_pagefault *pf, *pf_temp;
 
 	while (kfifo_get(&d->events.fifo, &event))
 		kfree(event);
 
+	/* Since it's the last reference no race here */
+	list_for_each_entry_safe(pf, pf_temp, &d->pagefaults, list) {
+		xe_exec_queue_put(pf->q);
+		kfree(pf);
+	}
+
 	xe_eudebug_destroy_resources(d);
 	put_task_struct(d->target_task);
 
@@ -911,7 +919,7 @@ static struct xe_eudebug_event *
 xe_eudebug_create_event(struct xe_eudebug *d, u16 type, u64 seqno, u16 flags,
 			u32 len)
 {
-	const u16 max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_OP_METADATA;
+	const u16 max_event = DRM_XE_EUDEBUG_EVENT_PAGEFAULT;
 	const u16 known_flags =
 		DRM_XE_EUDEBUG_EVENT_CREATE |
 		DRM_XE_EUDEBUG_EVENT_DESTROY |
@@ -946,7 +954,7 @@ static long xe_eudebug_read_event(struct xe_eudebug *d,
 		u64_to_user_ptr(arg);
 	struct drm_xe_eudebug_event user_event;
 	struct xe_eudebug_event *event;
-	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_VM_BIND_OP_METADATA;
+	const unsigned int max_event = DRM_XE_EUDEBUG_EVENT_PAGEFAULT;
 	long ret = 0;
 
 	if (XE_IOCTL_DBG(xe, copy_from_user(&user_event, user_orig, sizeof(user_event))))
@@ -1067,6 +1075,7 @@ static int do_eu_control(struct xe_eudebug *d,
 	struct xe_device *xe = d->xe;
 	u8 *bits = NULL;
 	unsigned int hw_attn_size, attn_size;
+	struct dma_fence *pf_fence;
 	struct xe_exec_queue *q;
 	struct xe_file *xef;
 	struct xe_lrc *lrc;
@@ -1132,6 +1141,23 @@ static int do_eu_control(struct xe_eudebug *d,
 
 	ret = -EINVAL;
 	mutex_lock(&d->eu_lock);
+	rcu_read_lock();
+	pf_fence = dma_fence_get_rcu_safe(&d->pf_fence);
+	rcu_read_unlock();
+
+	while (pf_fence) {
+		mutex_unlock(&d->eu_lock);
+		ret = dma_fence_wait(pf_fence, true);
+		dma_fence_put(pf_fence);
+
+		if (ret)
+			goto out_free;
+
+		mutex_lock(&d->eu_lock);
+		rcu_read_lock();
+		pf_fence = dma_fence_get_rcu_safe(&d->pf_fence);
+		rcu_read_unlock();
+	}
 
 	switch (arg->cmd) {
 	case DRM_XE_EUDEBUG_EU_CONTROL_CMD_INTERRUPT_ALL:
@@ -1720,6 +1746,182 @@ static int xe_eudebug_handle_gt_attention(struct xe_gt *gt)
 	return ret;
 }
 
+static int send_pagefault_event(struct xe_eudebug *d, struct xe_eudebug_pagefault *pf)
+{
+	struct xe_eudebug_event_pagefault *ep;
+	struct xe_eudebug_event *event;
+	int h_c, h_queue, h_lrc;
+	u32 size = xe_gt_eu_attention_bitmap_size(pf->q->gt) * 3;
+	u32 sz = struct_size(ep, bitmask, size);
+
+	XE_WARN_ON(pf->lrc_idx < 0 || pf->lrc_idx >= pf->q->width);
+
+	XE_WARN_ON(!xe_exec_queue_is_debuggable(pf->q));
+
+	h_c = find_handle(d->res, XE_EUDEBUG_RES_TYPE_CLIENT, pf->q->vm->xef);
+	if (h_c < 0)
+		return h_c;
+
+	h_queue = find_handle(d->res, XE_EUDEBUG_RES_TYPE_EXEC_QUEUE, pf->q);
+	if (h_queue < 0)
+		return h_queue;
+
+	h_lrc = find_handle(d->res, XE_EUDEBUG_RES_TYPE_LRC, pf->q->lrc[pf->lrc_idx]);
+	if (h_lrc < 0)
+		return h_lrc;
+
+	event = xe_eudebug_create_event(d, DRM_XE_EUDEBUG_EVENT_PAGEFAULT, 0,
+					DRM_XE_EUDEBUG_EVENT_STATE_CHANGE, sz);
+
+	if (!event)
+		return -ENOSPC;
+
+	ep = cast_event(ep, event);
+	write_member(struct xe_eudebug_event_pagefault, ep, client_handle, (u64)h_c);
+	write_member(struct xe_eudebug_event_pagefault, ep, exec_queue_handle, (u64)h_queue);
+	write_member(struct xe_eudebug_event_pagefault, ep, lrc_handle, (u64)h_lrc);
+	write_member(struct xe_eudebug_event_pagefault, ep, bitmask_size, size);
+	write_member(struct xe_eudebug_event_pagefault, ep, pagefault_address, pf->fault.addr);
+
+	memcpy(ep->bitmask, pf->attentions.before.att, pf->attentions.before.size);
+	memcpy(ep->bitmask + pf->attentions.before.size,
+	       pf->attentions.after.att, pf->attentions.after.size);
+	memcpy(ep->bitmask + pf->attentions.before.size + pf->attentions.after.size,
+	       pf->attentions.resolved.att, pf->attentions.resolved.size);
+
+	event->seqno = atomic_long_inc_return(&d->events.seqno);
+
+	return xe_eudebug_queue_event(d, event);
+}
+
+static int send_pagefault(struct xe_gt *gt, struct xe_eudebug_pagefault *pf,
+			  bool from_attention_scan)
+{
+	struct xe_eudebug *d;
+	struct xe_exec_queue *q;
+	int ret, lrc_idx;
+
+	if (list_empty_careful(&gt_to_xe(gt)->eudebug.list))
+		return -ENOTCONN;
+
+	q = runalone_active_queue_get(gt, &lrc_idx);
+	if (IS_ERR(q))
+		return PTR_ERR(q);
+
+	if (!xe_exec_queue_is_debuggable(q)) {
+		ret = -EPERM;
+		goto out_exec_queue_put;
+	}
+
+	d = _xe_eudebug_get(q->vm->xef);
+	if (!d) {
+		ret = -ENOTCONN;
+		goto out_exec_queue_put;
+	}
+
+	if (!completion_done(&d->discovery)) {
+		eu_dbg(d, "discovery not yet done\n");
+		ret = -EBUSY;
+		goto out_eudebug_put;
+	}
+
+	if (pf->deferred_resolved) {
+		xe_gt_eu_attentions_read(gt, &pf->attentions.resolved,
+					 XE_GT_ATTENTION_TIMEOUT_MS);
+
+		if (!xe_eu_attentions_xor_count(&pf->attentions.after,
+						&pf->attentions.resolved) &&
+		    !from_attention_scan) {
+			eu_dbg(d, "xe attentions not yet updated\n");
+			ret = -EBUSY;
+			goto out_eudebug_put;
+		}
+	}
+
+	ret = send_pagefault_event(d, pf);
+	if (ret)
+		xe_eudebug_disconnect(d, ret);
+
+out_eudebug_put:
+	xe_eudebug_put(d);
+out_exec_queue_put:
+	xe_exec_queue_put(q);
+
+	return ret;
+}
+
+static int send_queued_pagefault(struct xe_eudebug *d, bool from_attention_scan)
+{
+	struct xe_eudebug_pagefault *pf, *pf_temp;
+	int ret = 0;
+
+	mutex_lock(&d->pf_lock);
+	list_for_each_entry_safe(pf, pf_temp, &d->pagefaults, list) {
+		struct xe_gt *gt = pf->q->gt;
+
+		ret = send_pagefault(gt, pf, from_attention_scan);
+
+		/* if resolved attentions are not updated */
+		if (ret == -EBUSY)
+			break;
+
+		/* decrease the reference count of xe_exec_queue obtained from pagefault handler */
+		xe_exec_queue_put(pf->q);
+		list_del(&pf->list);
+		kfree(pf);
+
+		if (ret)
+			break;
+	}
+	mutex_unlock(&d->pf_lock);
+
+	return ret;
+}
+
+static int handle_gt_queued_pagefault(struct xe_gt *gt)
+{
+	struct xe_exec_queue *q;
+	struct xe_eudebug *d;
+	int ret, lrc_idx;
+
+	ret = xe_gt_eu_threads_needing_attention(gt);
+	if (ret <= 0)
+		return ret;
+
+	if (list_empty_careful(&gt_to_xe(gt)->eudebug.list))
+		return -ENOTCONN;
+
+	q = runalone_active_queue_get(gt, &lrc_idx);
+	if (IS_ERR(q))
+		return PTR_ERR(q);
+
+	if (!xe_exec_queue_is_debuggable(q)) {
+		ret = -EPERM;
+		goto out_exec_queue_put;
+	}
+
+	d = _xe_eudebug_get(q->vm->xef);
+	if (!d) {
+		ret = -ENOTCONN;
+		goto out_exec_queue_put;
+	}
+
+	if (!completion_done(&d->discovery)) {
+		eu_dbg(d, "discovery not yet done\n");
+		ret = -EBUSY;
+		goto out_eudebug_put;
+	}
+
+	ret = send_queued_pagefault(d, true);
+
+out_eudebug_put:
+	xe_eudebug_put(d);
+out_exec_queue_put:
+	xe_exec_queue_put(q);
+
+	return ret;
+}
+
 #define XE_EUDEBUG_ATTENTION_INTERVAL 100
 static void attention_scan_fn(struct work_struct *work)
 {
@@ -1741,6 +1943,8 @@ static void attention_scan_fn(struct work_struct *work)
 			if (gt->info.type != XE_GT_TYPE_MAIN)
 				continue;
 
+			handle_gt_queued_pagefault(gt);
+
 			ret = xe_eudebug_handle_gt_attention(gt);
 			if (ret) {
 				// TODO: error capture
@@ -2048,6 +2252,8 @@ xe_eudebug_connect(struct xe_device *xe,
 	kref_init(&d->ref);
 	spin_lock_init(&d->connection.lock);
 	mutex_init(&d->eu_lock);
+	mutex_init(&d->pf_lock);
+	INIT_LIST_HEAD(&d->pagefaults);
 	init_waitqueue_head(&d->events.write_done);
 	init_waitqueue_head(&d->events.read_done);
 	init_completion(&d->discovery);
@@ -3490,6 +3696,8 @@ static void discovery_work_fn(struct work_struct *work)
 
 	up_write(&xe->eudebug.discovery_lock);
 
+	send_queued_pagefault(d, false);
+
 	xe_eudebug_put(d);
 }
 
@@ -3961,6 +4169,283 @@ xe_eudebug_vm_open_ioctl(struct xe_eudebug *d, unsigned long arg)
 	return ret;
 }
 
+static int queue_pagefault(struct xe_gt *gt, struct xe_eudebug_pagefault *pf)
+{
+	struct xe_eudebug *d;
+
+	if (list_empty_careful(&gt_to_xe(gt)->eudebug.list))
+		return -ENOTCONN;
+
+	d = _xe_eudebug_get(pf->q->vm->xef);
+	if (IS_ERR_OR_NULL(d))
+		return -EINVAL;
+
+	mutex_lock(&d->pf_lock);
+	list_add_tail(&pf->list, &d->pagefaults);
+	mutex_unlock(&d->pf_lock);
+
+	xe_eudebug_put(d);
+
+	return 0;
+}
+
+static int handle_pagefault(struct xe_gt *gt, struct xe_eudebug_pagefault *pf)
+{
+	int ret;
+
+	ret = send_pagefault(gt, pf, false);
+
+	/*
+	 * if debugger discovery is not completed or resolved attentions are not
+	 * updated, then queue pagefault
+	 */
+	if (ret == -EBUSY) {
+		ret = queue_pagefault(gt, pf);
+		if (!ret)
+			goto out;
+	}
+
+	xe_exec_queue_put(pf->q);
+	kfree(pf);
+
+out:
+	return ret;
+}
+
+static const char *
+pagefault_get_driver_name(struct dma_fence *dma_fence)
+{
+	return "xe";
+}
+
+static const char *
+pagefault_fence_get_timeline_name(struct dma_fence *dma_fence)
+{
+	return "eudebug_pagefault_fence";
+}
+
+static const struct dma_fence_ops pagefault_fence_ops = {
+	.get_driver_name = pagefault_get_driver_name,
+	.get_timeline_name = pagefault_fence_get_timeline_name,
+};
+
+struct pagefault_fence {
+	struct dma_fence base;
+	spinlock_t lock;
+};
+
+static struct pagefault_fence *pagefault_fence_create(void)
+{
+	struct pagefault_fence *fence;
+
+	fence = kzalloc(sizeof(*fence), GFP_KERNEL);
+	if (fence == NULL)
+		return NULL;
+
+	spin_lock_init(&fence->lock);
+	dma_fence_init(&fence->base, &pagefault_fence_ops, &fence->lock,
+		       dma_fence_context_alloc(1), 1);
+
+	return fence;
+}
+
+struct xe_eudebug_pagefault *
+xe_eudebug_pagefault_create(struct xe_gt *gt, struct xe_vm *vm, u64 page_addr,
+			    u8 fault_type, u8 fault_level, u8 access_type)
+{
+	struct pagefault_fence *pf_fence;
+	struct xe_eudebug_pagefault *pf;
+	struct xe_vma *vma = NULL;
+	struct xe_exec_queue *q;
+	struct dma_fence *fence;
+	struct xe_eudebug *d;
+	unsigned int fw_ref;
+	int lrc_idx;
+	u32 td_ctl;
+
+	down_read(&vm->lock);
+	vma = xe_gt_pagefault_lookup_vma(vm, page_addr);
+	up_read(&vm->lock);
+
+	if (vma)
+		return NULL;
+
+	d = _xe_eudebug_get(vm->xef);
+	if (!d)
+		return NULL;
+
+	q = runalone_active_queue_get(gt, &lrc_idx);
+	if (IS_ERR(q))
+		goto err_put_eudebug;
+
+	if (!xe_exec_queue_is_debuggable(q))
+		goto err_put_exec_queue;
+
+	fw_ref = xe_force_wake_get(gt_to_fw(gt), q->hwe->domain);
+	if (!fw_ref)
+		goto err_put_exec_queue;
+
+	/*
+	 * If there is no debug functionality (TD_CTL_GLOBAL_DEBUG_ENABLE, etc.),
+	 * don't proceed pagefault routine for eu debugger.
+	 */
+
+	td_ctl = xe_gt_mcr_unicast_read_any(gt, TD_CTL);
+	if (!td_ctl)
+		goto err_put_fw;
+
+	pf = kzalloc(sizeof(*pf), GFP_KERNEL);
+	if (!pf)
+		goto err_put_fw;
+
+	attention_scan_cancel(gt_to_xe(gt));
+
+	mutex_lock(&d->eu_lock);
+	rcu_read_lock();
+	fence = dma_fence_get_rcu_safe(&d->pf_fence);
+	rcu_read_unlock();
+
+	if (fence) {
+		/*
+		 * TODO: If the new incoming pagefaulted address is different
+		 * from the pagefaulted address it is currently handling on the
+		 * same ASID, it needs a routine to wait here and then do the
+		 * following pagefault.
+		 */
+		dma_fence_put(fence);
+		goto err_unlock_eu_lock;
+	}
+
+	pf_fence = pagefault_fence_create();
+	if (!pf_fence)
+		goto err_unlock_eu_lock;
+
+	d->pf_fence = &pf_fence->base;
+	mutex_unlock(&d->eu_lock);
+
+	INIT_LIST_HEAD(&pf->list);
+
+	xe_gt_eu_attentions_read(gt, &pf->attentions.before, 0);
+
+	/* Halt on next thread dispatch */
+	while (!(td_ctl & TD_CTL_FORCE_EXTERNAL_HALT)) {
+		xe_gt_mcr_multicast_write(gt, TD_CTL,
+					  td_ctl | TD_CTL_FORCE_EXTERNAL_HALT);
+		/*
+		 * The sleep is needed because some interrupts are ignored
+		 * by the HW, hence we allow the HW some time to acknowledge
+		 * that.
+		 */
+		udelay(200);
+		td_ctl = xe_gt_mcr_unicast_read_any(gt, TD_CTL);
+	}
+
+	/* Halt regardless of thread dependencies */
+	while (!(td_ctl & TD_CTL_FORCE_EXCEPTION)) {
+		xe_gt_mcr_multicast_write(gt, TD_CTL,
+					  td_ctl | TD_CTL_FORCE_EXCEPTION);
+		udelay(200);
+		td_ctl = xe_gt_mcr_unicast_read_any(gt, TD_CTL);
+	}
+
+	xe_gt_eu_attentions_read(gt, &pf->attentions.after,
+				 XE_GT_ATTENTION_TIMEOUT_MS);
+
+	/*
+	 * xe_exec_queue_put() will be called from xe_eudebug_pagefault_destroy()
+	 * or handle_pagefault()
+	 */
+	pf->q = q;
+	pf->lrc_idx = lrc_idx;
+	pf->fault.addr = page_addr;
+	pf->fault.type = fault_type;
+	pf->fault.level = fault_level;
+	pf->fault.access = access_type;
+
+	xe_force_wake_put(gt_to_fw(gt), fw_ref);
+	xe_eudebug_put(d);
+
+	return pf;
+
+err_unlock_eu_lock:
+	mutex_unlock(&d->eu_lock);
+	attention_scan_flush(gt_to_xe(gt));
+	kfree(pf);
+err_put_fw:
+	xe_force_wake_put(gt_to_fw(gt), fw_ref);
+err_put_exec_queue:
+	xe_exec_queue_put(q);
+err_put_eudebug:
+	xe_eudebug_put(d);
+
+	return NULL;
+}
+
+void
+xe_eudebug_pagefault_process(struct xe_gt *gt, struct xe_eudebug_pagefault *pf)
+{
+	xe_gt_eu_attentions_read(gt, &pf->attentions.resolved,
+				 XE_GT_ATTENTION_TIMEOUT_MS);
+
+	if (!xe_eu_attentions_xor_count(&pf->attentions.after,
+					&pf->attentions.resolved))
+		pf->deferred_resolved = true;
+}
+
+void
+xe_eudebug_pagefault_destroy(struct xe_gt *gt, struct xe_vm *vm,
+			     struct xe_eudebug_pagefault *pf, bool send_event)
+{
+	struct xe_eudebug *d;
+	unsigned int fw_ref;
+	u32 td_ctl;
+
+	fw_ref = xe_force_wake_get(gt_to_fw(gt), pf->q->hwe->domain);
+	if (!fw_ref) {
+		struct xe_device *xe = gt_to_xe(gt);
+
+		drm_warn(&xe->drm, "Forcewake fail: Can not recover TD_CTL");
+	} else {
+		td_ctl = xe_gt_mcr_unicast_read_any(gt, TD_CTL);
+		xe_gt_mcr_multicast_write(gt, TD_CTL, td_ctl &
+					  ~(TD_CTL_FORCE_EXTERNAL_HALT | TD_CTL_FORCE_EXCEPTION));
+		xe_force_wake_put(gt_to_fw(gt), fw_ref);
+	}
+
+	if (send_event)
+		handle_pagefault(gt, pf);
+
+	d = _xe_eudebug_get(vm->xef);
+	if (d) {
+		struct dma_fence *fence;
+
+		mutex_lock(&d->eu_lock);
+		rcu_read_lock();
+		fence = dma_fence_get_rcu_safe(&d->pf_fence);
+		rcu_read_unlock();
+
+		if (fence) {
+			if (send_event)
+				dma_fence_signal(fence);
+
+			dma_fence_put(fence); /* deref for dma_fence_get_rcu_safe() */
+			dma_fence_put(fence); /* defef for dma_fence_init() */
+		}
+
+		d->pf_fence = NULL;
+		mutex_unlock(&d->eu_lock);
+
+		xe_eudebug_put(d);
+	}
+
+	if (!send_event) {
+		xe_exec_queue_put(pf->q);
+		kfree(pf);
+	}
+
+	attention_scan_flush(gt_to_xe(gt));
+}
+
 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
 #include "tests/xe_eudebug.c"
 #endif
drivers/gpu/drm/xe/xe_eudebug.h +28 -0
index a08abf796cc1..cf1df4e2c6a6 100644
@@ -11,6 +11,7 @@ struct drm_device;
 struct drm_file;
 struct xe_device;
 struct xe_file;
+struct xe_gt;
 struct xe_vm;
 struct xe_vma;
 struct xe_exec_queue;
@@ -18,6 +19,7 @@ struct xe_hw_engine;
 struct xe_user_fence;
 struct xe_debug_metadata;
 struct drm_gpuva_ops;
+struct xe_eudebug_pagefault;
 
 #if IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)
 
@@ -53,6 +55,13 @@ void xe_eudebug_put(struct xe_eudebug *d);
 void xe_eudebug_debug_metadata_create(struct xe_file *xef, struct xe_debug_metadata *m);
 void xe_eudebug_debug_metadata_destroy(struct xe_file *xef, struct xe_debug_metadata *m);
 
+struct xe_eudebug_pagefault *xe_eudebug_pagefault_create(struct xe_gt *gt, struct xe_vm *vm,
+							 u64 page_addr, u8 fault_type,
+							 u8 fault_level, u8 access_type);
+void xe_eudebug_pagefault_process(struct xe_gt *gt, struct xe_eudebug_pagefault *pf);
+void xe_eudebug_pagefault_destroy(struct xe_gt *gt, struct xe_vm *vm,
+				  struct xe_eudebug_pagefault *pf, bool send_event);
+
 #else
 
 static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
@@ -95,6 +104,25 @@ static inline void xe_eudebug_debug_metadata_destroy(struct xe_file *xef,
 {
 }
 
+static inline struct xe_eudebug_pagefault *
+xe_eudebug_pagefault_create(struct xe_gt *gt, struct xe_vm *vm, u64 page_addr,
+			    u8 fault_type, u8 fault_level, u8 access_type)
+{
+	return NULL;
+}
+
+static inline void
+xe_eudebug_pagefault_process(struct xe_gt *gt, struct xe_eudebug_pagefault *pf)
+{
+}
+
+static inline void xe_eudebug_pagefault_destroy(struct xe_gt *gt,
+						struct xe_vm *vm,
+						struct xe_eudebug_pagefault *pf,
+						bool send_event)
+{
+}
+
 #endif /* CONFIG_DRM_XE_EUDEBUG */
 
 #endif
drivers/gpu/drm/xe/xe_eudebug_types.h +94 -0

110 lines not on this page · raw message

drivers/gpu/drm/xe/xe_gt_pagefault.c +2 -2
index 2606cd396df5..5558342b8e07 100644
@@ -79,7 +79,7 @@ static bool vma_matches(struct xe_vma *vma, u64 page_addr)
 	return true;
 }
 
-static struct xe_vma *lookup_vma(struct xe_vm *vm, u64 page_addr)
+struct xe_vma *xe_gt_pagefault_lookup_vma(struct xe_vm *vm, u64 page_addr)
 {
 	struct xe_vma *vma = NULL;
 
@@ -225,7 +225,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 		goto unlock_vm;
 	}
 
-	vma = lookup_vma(vm, pf->page_addr);
+	vma = xe_gt_pagefault_lookup_vma(vm, pf->page_addr);
 	if (!vma) {
 		err = -EINVAL;
 		goto unlock_vm;
drivers/gpu/drm/xe/xe_gt_pagefault.h +2 -0
index 839c065a5e4c..3c0628b79f33 100644
@@ -10,10 +10,12 @@
 
 struct xe_gt;
 struct xe_guc;
+struct xe_vm;
 
 int xe_gt_pagefault_init(struct xe_gt *gt);
 void xe_gt_pagefault_reset(struct xe_gt *gt);
 int xe_guc_pagefault_handler(struct xe_guc *guc, u32 *msg, u32 len);
 int xe_guc_access_counter_notify_handler(struct xe_guc *guc, u32 *msg, u32 len);
+struct xe_vma *xe_gt_pagefault_lookup_vma(struct xe_vm *vm, u64 page_addr);
 
 #endif	/* _XE_GT_PAGEFAULT_ */
include/uapi/drm/xe_drm_eudebug.h +13 -0
index 3c4d1b511acd..e43576c7bc5e 100644
@@ -38,6 +38,7 @@ struct drm_xe_eudebug_event {
 #define DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE	9
 #define DRM_XE_EUDEBUG_EVENT_METADATA		10
 #define DRM_XE_EUDEBUG_EVENT_VM_BIND_OP_METADATA 11
+#define DRM_XE_EUDEBUG_EVENT_PAGEFAULT		12
 
 	__u16 flags;
 #define DRM_XE_EUDEBUG_EVENT_CREATE		(1 << 0)
@@ -236,6 +237,18 @@ struct drm_xe_eudebug_event_vm_bind_op_metadata {
 	__u64 metadata_cookie;
 };
 
+struct drm_xe_eudebug_event_pagefault {
+	struct drm_xe_eudebug_event base;
+
+	__u64 client_handle;
+	__u64 exec_queue_handle;
+	__u64 lrc_handle;
+	__u32 flags;
+	__u32 bitmask_size;
+	__u64 pagefault_address;
+	__u8 bitmask[];
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#54 lore raw

PATCH 25/26 drm/xe/vm: Support for adding null page VMA to VM on request

In reply to Mika Kuoppala

From: Gwan-gyeong Mun <[email protected]>

The XE2 (and PVC) HW has a limitation that the pagefault due to invalid access will halt the corresponding EUs. So, in order to activate the debugger, kmd needs to install the temporal page to unhalt the EUs. Plan to be used for pagefault handling when the EU debugger is running. The idea is to install a null page vma if the pagefault is from an invalid access. After installing null page pte, the user debugger can continue to run/inspect without causing a fatal failure or reset and stop. Based on Bruce's implementation [1].

[1] https://lore.kernel.org/intel-xe/[email protected]/

Cc Oak Zeng <[email protected]>
Cc Niranjana Vishwanathapura <[email protected]>
Cc Stuart Summers <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/xe/xe_vm.c | 23 +++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vm.h |  2 ++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/xe/xe_vm.c +23 -0
index 474521d0fea9..ff45e5264aed 100644
@@ -3552,3 +3552,26 @@ int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
 	up_read(&vm->userptr.notifier_lock);
 	return ret;
 }
+
+struct xe_vma *xe_vm_create_null_vma(struct xe_vm *vm, u64 addr)
+{
+	struct xe_vma *vma;
+	u32 page_size;
+	int err;
+
+	if (xe_vm_is_closed_or_banned(vm))
+		return ERR_PTR(-ENOENT);
+
+	page_size = vm->flags & XE_VM_FLAG_64K ? SZ_64K : SZ_4K;
+	vma = xe_vma_create(vm, NULL, 0, addr, addr + page_size - 1, 0, VMA_CREATE_FLAG_IS_NULL);
+	if (IS_ERR_OR_NULL(vma))
+		return vma;
+
+	err = xe_vm_insert_vma(vm, vma);
+	if (err) {
+		xe_vma_destroy_late(vma);
+		return ERR_PTR(err);
+	}
+
+	return vma;
+}
drivers/gpu/drm/xe/xe_vm.h +2 -0
index 372ad40ad67f..2ae3749cfd82 100644
@@ -283,3 +283,5 @@ void xe_vm_snapshot_free(struct xe_vm_snapshot *snap);
 
 int xe_vm_userptr_access(struct xe_userptr_vma *uvma, u64 offset,
 			 void *buf, u64 len, bool write);
+
+struct xe_vma *xe_vm_create_null_vma(struct xe_vm *vm, u64 addr);
Signature · 1 line
2.43.0
#55 lore raw

PATCH 26/26 drm/xe/eudebug: Enable EU pagefault handling

In reply to Mika Kuoppala

From: Gwan-gyeong Mun <[email protected]>

The XE2 (and PVC) HW has a limitation that the pagefault due to invalid access will halt the corresponding EUs. To solve this problem, enable EU pagefault handling functionality, which allows to unhalt pagefaulted eu threads and to EU debugger to get inform about the eu attentions state of EU threads during execution.

If a pagefault occurs, send the DRM_XE_EUDEBUG_EVENT_PAGEFAULT event to the client connected to the xe_eudebug after handling the pagefault.

The pagefault handling is a mechanism that allows a stalled EU thread to enter SIP mode by installing a temporal null page to the page table entry where the pagefault happened.

A brief description of the page fault handling mechanism flow between KMD and the eu thread is as follows

(1) eu thread accesses unallocated address
(2) pagefault happens and eu thread stalls
(3) XE kmd set an force eu thread exception to allow the running eu thread to enter SIP mode (kmd set ForceException / ForceExternalHalt bit of TD_CTL register)
Not stalled (none-pagefaulted) eu threads enter SIP mode
(4) XE kmd installs temporal null page to the pagetable entry of the address where pagefault happened.
(5) XE kmd replies pagefault successful message to GUC
(6) stalled eu thread resumes as per pagefault condition has resolved
(7) resumed eu thread enters SIP mode due to force exception set by (3)

As designed this feature to only work when eudbug is enabled, it should have no impact to regular recoverable pagefault code path.

---
 drivers/gpu/drm/xe/xe_gt_pagefault.c | 83 +++++++++++++++++++++++++---
 1 file changed, 75 insertions(+), 8 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +75 -8
index 5558342b8e07..4e2883e19018 100644
@@ -13,6 +13,7 @@
 
 #include "abi/guc_actions_abi.h"
 #include "xe_bo.h"
+#include "xe_eudebug.h"
 #include "xe_gt.h"
 #include "xe_gt_tlb_invalidation.h"
 #include "xe_guc.h"
@@ -199,12 +200,16 @@ static struct xe_vm *asid_to_vm(struct xe_device *xe, u32 asid)
 	return vm;
 }
 
-static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
+static int handle_pagefault_start(struct xe_gt *gt, struct pagefault *pf,
+				  struct xe_vm **pf_vm,
+				  struct xe_eudebug_pagefault **eudebug_pf_out)
 {
-	struct xe_device *xe = gt_to_xe(gt);
+	struct xe_eudebug_pagefault *eudebug_pf;
 	struct xe_tile *tile = gt_to_tile(gt);
-	struct xe_vm *vm;
+	struct xe_device *xe = gt_to_xe(gt);
+	bool  destroy_eudebug_pf = false;
 	struct xe_vma *vma = NULL;
+	struct xe_vm *vm;
 	int err;
 
 	/* SW isn't expected to handle TRTT faults */
@@ -215,6 +220,10 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 	if (IS_ERR(vm))
 		return PTR_ERR(vm);
 
+	eudebug_pf = xe_eudebug_pagefault_create(gt, vm, pf->page_addr,
+						 pf->fault_type, pf->fault_level,
+						 pf->access_type);
+
 	/*
 	 * TODO: Change to read lock? Using write lock for simplicity.
 	 */
@@ -227,8 +236,27 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 
 	vma = xe_gt_pagefault_lookup_vma(vm, pf->page_addr);
 	if (!vma) {
-		err = -EINVAL;
-		goto unlock_vm;
+		if (eudebug_pf)
+			vma = xe_vm_create_null_vma(vm, pf->page_addr);
+
+		if (IS_ERR_OR_NULL(vma)) {
+			err = -EINVAL;
+			if (eudebug_pf)
+				destroy_eudebug_pf = true;
+
+			goto unlock_vm;
+		}
+	} else {
+		/*
+		 * When creating an instance of eudebug_pagefault, there was
+		 * no vma containing the ppgtt address where the pagefault occurred,
+		 * but when reacquiring vm->lock, there is.
+		 * During not aquiring the vm->lock from this context,
+		 * but vma corresponding to the address where the pagefault occurred
+		 * in another context has allocated.
+		 */
+		if (eudebug_pf)
+			destroy_eudebug_pf = true;
 	}
 
 	err = handle_vma_pagefault(tile, pf, vma);
@@ -237,11 +265,43 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
 	if (!err)
 		vm->usm.last_fault_vma = vma;
 	up_write(&vm->lock);
-	xe_vm_put(vm);
+
+	if (destroy_eudebug_pf) {
+		xe_eudebug_pagefault_destroy(gt, vm, eudebug_pf, false);
+		*eudebug_pf_out = NULL;
+	} else {
+		*eudebug_pf_out = eudebug_pf;
+	}
+
+	/* while the lifetime of the eudebug pagefault instance, keep the VM instance.*/
+	if (!*eudebug_pf_out) {
+		xe_vm_put(vm);
+		*pf_vm = NULL;
+	} else {
+		*pf_vm = vm;
+	}
 
 	return err;
 }
 
+static void handle_pagefault_end(struct xe_gt *gt, struct xe_vm *vm,
+				 struct xe_eudebug_pagefault *eudebug_pf)
+{
+	/* if there no eudebug_pagefault then return */
+	if (!eudebug_pf)
+		return;
+
+	xe_eudebug_pagefault_process(gt, eudebug_pf);
+
+	/*
+	 * TODO: Remove VMA added to handle eudebug pagefault
+	 */
+
+	xe_eudebug_pagefault_destroy(gt, vm, eudebug_pf, true);
+
+	xe_vm_put(vm);
+}
+
 static int send_pagefault_reply(struct xe_guc *guc,
 				struct xe_guc_pagefault_reply *reply)
 {
@@ -367,7 +427,10 @@ static void pf_queue_work_func(struct work_struct *w)
 	threshold = jiffies + msecs_to_jiffies(USM_QUEUE_MAX_RUNTIME_MS);
 
 	while (get_pagefault(pf_queue, &pf)) {
-		ret = handle_pagefault(gt, &pf);
+		struct xe_eudebug_pagefault *eudebug_pf = NULL;
+		struct xe_vm *vm = NULL;
+
+		ret = handle_pagefault_start(gt, &pf, &vm, &eudebug_pf);
 		if (unlikely(ret)) {
 			print_pagefault(xe, &pf);
 			pf.fault_unsuccessful = 1;
@@ -385,7 +448,11 @@ static void pf_queue_work_func(struct work_struct *w)
 			FIELD_PREP(PFR_ENG_CLASS, pf.engine_class) |
 			FIELD_PREP(PFR_PDATA, pf.pdata);
 
-		send_pagefault_reply(&gt->uc.guc, &reply);
+		ret = send_pagefault_reply(&gt->uc.guc, &reply);
+		if (unlikely(ret))
+			drm_dbg(&xe->drm, "GuC Pagefault reply failed: %d\n", ret);
+
+		handle_pagefault_end(gt, vm, eudebug_pf);
 
 		if (time_after(jiffies, threshold) &&
 		    pf_queue->tail != pf_queue->head) {
Signature · 1 line
2.43.0
#56 lore raw

✓ CI.Patch_applied: success for Intel Xe GPU debug support (eudebug) v3

In reply to Mika Kuoppala
== Series Details ==

== Series Details ==

Series: Intel Xe GPU debug support (eudebug) v3
URL : https://patchwork.freedesktop.org/series/142295/
State : success

== Summary ==

=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: c266f2fbb9c0 drm-tip: 2024y-12m-09d-14h-13m-53s UTC integration manifest === git am output follows ===
Applying: ptrace: export ptrace_may_access
Applying: drm/xe/eudebug: Introduce eudebug support
Applying: drm/xe/eudebug: Introduce discovery for resources
Applying: drm/xe/eudebug: Introduce exec_queue events
Applying: drm/xe/eudebug: Introduce exec queue placements event
Applying: drm/xe/eudebug: hw enablement for eudebug
Applying: drm/xe: Add EUDEBUG_ENABLE exec queue property
Applying: drm/xe/eudebug: Introduce per device attention scan worker
Applying: drm/xe/eudebug: Introduce EU control interface
Applying: drm/xe/eudebug: Add vm bind and vm bind ops
Applying: drm/xe/eudebug: Add UFENCE events with acks
Applying: drm/xe/eudebug: vm open/pread/pwrite
Applying: drm/xe: add system memory page iterator support to xe_res_cursor
Applying: drm/xe/eudebug: implement userptr_vma access
Applying: drm/xe: Debug metadata create/destroy ioctls
Applying: drm/xe: Attach debug metadata to vma
Applying: drm/xe/eudebug: Add debug metadata support for xe_eudebug
Applying: drm/xe/eudebug: Implement vm_bind_op discovery
Applying: drm/xe/eudebug: Dynamically toggle debugger functionality
Applying: drm/xe/eudebug_test: Introduce xe_eudebug wa kunit test
Applying: drm/xe/eudebug/ptl: Add support for extra attention register
Applying: drm/xe/eudebug/ptl: Add RCU_DEBUG_1 register support for xe3
Applying: drm/xe/eudebug: Add read/count/compare helper for eu attention
Applying: drm/xe/eudebug: Introduce EU pagefault handling interface
Applying: drm/xe/vm: Support for adding null page VMA to VM on request
Applying: drm/xe/eudebug: Enable EU pagefault handling

#57 lore raw

✗ CI.checkpatch: warning for Intel Xe GPU debug support (eudebug) v3

In reply to Mika Kuoppala
== Series Details ==

== Series Details ==

Series: Intel Xe GPU debug support (eudebug) v3
URL : https://patchwork.freedesktop.org/series/142295/
State : warning

== Summary ==

+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 30ab6715fc09baee6cc14cb3c89ad8858688d474
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 00b6bd24a242c98271f20d013a487ae9666d092e

Author: Gwan-gyeong Mun <[email protected]>
Date:   Mon Dec 9 15:33:17 2024 +0200

drm/xe/eudebug: Enable EU pagefault handling

The XE2 (and PVC) HW has a limitation that the pagefault due to invalid access will halt the corresponding EUs. To solve this problem, enable EU pagefault handling functionality, which allows to unhalt pagefaulted eu threads and to EU debugger to get inform about the eu attentions state of EU threads during execution.

If a pagefault occurs, send the DRM_XE_EUDEBUG_EVENT_PAGEFAULT event to the client connected to the xe_eudebug after handling the pagefault.

The pagefault handling is a mechanism that allows a stalled EU thread to enter SIP mode by installing a temporal null page to the page table entry where the pagefault happened.

A brief description of the page fault handling mechanism flow between KMD and the eu thread is as follows

(1) eu thread accesses unallocated address
(2) pagefault happens and eu thread stalls
(3) XE kmd set an force eu thread exception to allow the running eu thread to enter SIP mode (kmd set ForceException / ForceExternalHalt bit of TD_CTL register)
Not stalled (none-pagefaulted) eu threads enter SIP mode
(4) XE kmd installs temporal null page to the pagetable entry of the address where pagefault happened.
(5) XE kmd replies pagefault successful message to GUC
(6) stalled eu thread resumes as per pagefault condition has resolved
(7) resumed eu thread enters SIP mode due to force exception set by (3)

As designed this feature to only work when eudbug is enabled, it should have no impact to regular recoverable pagefault code path.

+ /mt/dim checkpatch c266f2fbb9c0250af17b14788364766adf802a4a drm-intel 729648a2eb39 ptrace: export ptrace_may_access
ac2f364d93cd drm/xe/eudebug: Introduce eudebug support
-:211: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #211:
new file mode 100644

-:249: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #249: FILE: drivers/gpu/drm/xe/xe_eudebug.c:34:
+#define XE_EUDEBUG_DBG_ARGS(d) (d)->session, \
+ atomic_long_read(&(d)->events.seqno), \
+ READ_ONCE(d->connection.status) <= 0 ? "disconnected" : "", \
+ current->pid, \
+ task_tgid_nr(current), \
+ (d)->target_task->pid, \
+ task_tgid_nr((d)->target_task)

-:249: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'd' - possible side-effects? #249: FILE: drivers/gpu/drm/xe/xe_eudebug.c:34:
+#define XE_EUDEBUG_DBG_ARGS(d) (d)->session, \
+ atomic_long_read(&(d)->events.seqno), \
+ READ_ONCE(d->connection.status) <= 0 ? "disconnected" : "", \
+ current->pid, \
+ task_tgid_nr(current), \
+ (d)->target_task->pid, \
+ task_tgid_nr((d)->target_task)

-:257: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'd' - possible side-effects? #257: FILE: drivers/gpu/drm/xe/xe_eudebug.c:42:
+#define eu_err(d, fmt, ...) drm_err(&(d)->xe->drm, XE_EUDEBUG_DBG_STR # fmt, \
+ XE_EUDEBUG_DBG_ARGS(d), ##__VA_ARGS__)

-:259: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'd' - possible side-effects? #259: FILE: drivers/gpu/drm/xe/xe_eudebug.c:44:
+#define eu_warn(d, fmt, ...) drm_warn(&(d)->xe->drm, XE_EUDEBUG_DBG_STR # fmt, \
+ XE_EUDEBUG_DBG_ARGS(d), ##__VA_ARGS__)

-:261: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'd' - possible side-effects? #261: FILE: drivers/gpu/drm/xe/xe_eudebug.c:46:
+#define eu_dbg(d, fmt, ...) drm_dbg(&(d)->xe->drm, XE_EUDEBUG_DBG_STR # fmt, \
+ XE_EUDEBUG_DBG_ARGS(d), ##__VA_ARGS__)

-:266: CHECK:MACRO_ARG_PRECEDENCE: Macro argument 'T' may be better as '(T)' to avoid precedence issues #266: FILE: drivers/gpu/drm/xe/xe_eudebug.c:51:
+#define struct_member(T, member) (((T *)0)->member)

-:266: CHECK:MACRO_ARG_PRECEDENCE: Macro argument 'member' may be better as '(member)' to avoid precedence issues #266: FILE: drivers/gpu/drm/xe/xe_eudebug.c:51:
+#define struct_member(T, member) (((T *)0)->member)

-:269: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'ptr' - possible side-effects? #269: FILE: drivers/gpu/drm/xe/xe_eudebug.c:54:
+#define write_member(T_out, ptr, member, value) { \
+ BUILD_BUG_ON(sizeof(*ptr) != sizeof(T_out)); \
+ BUILD_BUG_ON(offsetof(typeof(*ptr), member) != \
+ offsetof(typeof(T_out), member)); \
+ BUILD_BUG_ON(sizeof(ptr->member) != sizeof(value)); \
+ BUILD_BUG_ON(sizeof(struct_member(T_out, member)) != sizeof(value)); \
+ BUILD_BUG_ON(!typecheck(typeof((ptr)->member), value)); \
+ (ptr)->member = (value); \
+ }

-:269: CHECK:MACRO_ARG_PRECEDENCE: Macro argument 'ptr' may be better as '(ptr)' to avoid precedence issues #269: FILE: drivers/gpu/drm/xe/xe_eudebug.c:54:
+#define write_member(T_out, ptr, member, value) { \
+ BUILD_BUG_ON(sizeof(*ptr) != sizeof(T_out)); \
+ BUILD_BUG_ON(offsetof(typeof(*ptr), member) != \
+ offsetof(typeof(T_out), member)); \
+ BUILD_BUG_ON(sizeof(ptr->member) != sizeof(value)); \
+ BUILD_BUG_ON(sizeof(struct_member(T_out, member)) != sizeof(value)); \
+ BUILD_BUG_ON(!typecheck(typeof((ptr)->member), value)); \
+ (ptr)->member = (value); \
+ }

-:269: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'member' - possible side-effects? #269: FILE: drivers/gpu/drm/xe/xe_eudebug.c:54:
+#define write_member(T_out, ptr, member, value) { \
+ BUILD_BUG_ON(sizeof(*ptr) != sizeof(T_out)); \
+ BUILD_BUG_ON(offsetof(typeof(*ptr), member) != \
+ offsetof(typeof(T_out), member)); \
+ BUILD_BUG_ON(sizeof(ptr->member) != sizeof(value)); \
+ BUILD_BUG_ON(sizeof(struct_member(T_out, member)) != sizeof(value)); \
+ BUILD_BUG_ON(!typecheck(typeof((ptr)->member), value)); \
+ (ptr)->member = (value); \
+ }

-:269: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'value' - possible side-effects? #269: FILE: drivers/gpu/drm/xe/xe_eudebug.c:54:
+#define write_member(T_out, ptr, member, value) { \
+ BUILD_BUG_ON(sizeof(*ptr) != sizeof(T_out)); \
+ BUILD_BUG_ON(offsetof(typeof(*ptr), member) != \
+ offsetof(typeof(T_out), member)); \
+ BUILD_BUG_ON(sizeof(ptr->member) != sizeof(value)); \
+ BUILD_BUG_ON(sizeof(struct_member(T_out, member)) != sizeof(value)); \
+ BUILD_BUG_ON(!typecheck(typeof((ptr)->member), value)); \
+ (ptr)->member = (value); \
+ }

-:541: CHECK:MACRO_ARG_REUSE: Macro argument reuse '_err' - possible side-effects? #541: FILE: drivers/gpu/drm/xe/xe_eudebug.c:326:
+#define xe_eudebug_disconnect(_d, _err) ({ \
+ if (_xe_eudebug_disconnect((_d), (_err))) { \
+ if ((_err) == 0 || (_err) == -ETIMEDOUT) \
+ eu_dbg(d, "Session closed (%d)", (_err)); \
+ else \
+ eu_err(d, "Session disconnected, err = %d (%s:%d)", \
+ (_err), __func__, __LINE__); \
+ } \
+})

-:1201: CHECK:MACRO_ARG_REUSE: Macro argument reuse '_d' - possible side-effects? #1201: FILE: drivers/gpu/drm/xe/xe_eudebug.c:986:
+#define xe_eudebug_event_put(_d, _err) ({ \
+ if ((_err)) \
+ xe_eudebug_disconnect((_d), (_err)); \
+ xe_eudebug_put((_d)); \
+ })

-:1201: CHECK:MACRO_ARG_REUSE: Macro argument reuse '_err' - possible side-effects? #1201: FILE: drivers/gpu/drm/xe/xe_eudebug.c:986:
+#define xe_eudebug_event_put(_d, _err) ({ \
+ if ((_err)) \
+ xe_eudebug_disconnect((_d), (_err)); \
+ xe_eudebug_put((_d)); \
+ })

-:1610: WARNING:LONG_LINE: line length of 130 exceeds 100 columns #1610: FILE: include/uapi/drm/xe_drm.h:121:
+#define DRM_IOCTL_XE_EUDEBUG_CONNECT DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EUDEBUG_CONNECT, struct drm_xe_eudebug_connect)

total: 1 errors, 2 warnings, 13 checks, 1577 lines checked
c97ad7125e5c drm/xe/eudebug: Introduce discovery for resources
-:95: CHECK:LINE_SPACING: Please use a blank line after function/struct/union/enum declarations #95: FILE: drivers/gpu/drm/xe/xe_device.h:232:
+}
+static inline void xe_eudebug_discovery_unlock(struct xe_device *xe, unsigned int cmd)

total: 0 errors, 0 warnings, 1 checks, 318 lines checked 17ef44596324 drm/xe/eudebug: Introduce exec_queue events 9b1663a6ba62 drm/xe/eudebug: Introduce exec queue placements event -:78: CHECK:BRACES: Blank lines aren't necessary after an open brace '{' #78: FILE: drivers/gpu/drm/xe/xe_eudebug.c:1245:
+{
+

-:135: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #135: FILE: drivers/gpu/drm/xe/xe_eudebug.c:1332:
+ ret = send_exec_queue_event(d, DRM_XE_EUDEBUG_EVENT_CREATE,
+ h_c, h_vm, h_queue, q->class,

total: 0 errors, 0 warnings, 2 checks, 198 lines checked d6539334fb02 drm/xe/eudebug: hw enablement for eudebug 71935b719213 drm/xe: Add EUDEBUG_ENABLE exec queue property faa9fdc51a4f drm/xe/eudebug: Introduce per device attention scan worker -:429: CHECK:LINE_SPACING: Please don't use multiple blank lines #429: FILE: drivers/gpu/drm/xe/xe_eudebug.c:1156:
+
+

-:649: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #649:
new file mode 100644

total: 0 errors, 1 warnings, 1 checks, 770 lines checked af1c94d3a52a drm/xe/eudebug: Introduce EU control interface 2ecba6c79908 drm/xe/eudebug: Add vm bind and vm bind ops 19cfd471bec6 drm/xe/eudebug: Add UFENCE events with acks -:667: CHECK:UNCOMMENTED_DEFINITION: spinlock_t definition without comment #667: FILE: drivers/gpu/drm/xe/xe_sync_types.h:26:
+ spinlock_t lock;

total: 0 errors, 0 warnings, 1 checks, 635 lines checked e9ba92596063 drm/xe/eudebug: vm open/pread/pwrite
43ef77a37d6f drm/xe: add system memory page iterator support to xe_res_cursor -:41: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #41: FILE: drivers/gpu/drm/xe/xe_res_cursor.h:148:
+static inline void __xe_res_first_sg(const struct sg_table *sg,
+ u64 start, u64 size,

-:83: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #83: FILE: drivers/gpu/drm/xe/xe_res_cursor.h:189:
+static inline void xe_res_first_sg_system(const struct sg_table *sg,
+ u64 start, u64 size,

total: 0 errors, 0 warnings, 2 checks, 71 lines checked
ea30cab25fb5 drm/xe/eudebug: implement userptr_vma access
ab7e2f12115d drm/xe: Debug metadata create/destroy ioctls
-:36: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #36:
new file mode 100644

-:202: CHECK:LINE_SPACING: Please don't use multiple blank lines #202: FILE: drivers/gpu/drm/xe/xe_debug_metadata.h:49:
+
+

-:351: WARNING:LONG_LINE: line length of 143 exceeds 100 columns #351: FILE: include/uapi/drm/xe_drm.h:123:
+#define DRM_IOCTL_XE_DEBUG_METADATA_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEBUG_METADATA_CREATE, struct drm_xe_debug_metadata_create)

-:352: WARNING:LONG_LINE: line length of 144 exceeds 100 columns #352: FILE: include/uapi/drm/xe_drm.h:124:
+#define DRM_IOCTL_XE_DEBUG_METADATA_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_DEBUG_METADATA_DESTROY, struct drm_xe_debug_metadata_destroy)

total: 0 errors, 3 warnings, 1 checks, 337 lines checked 673be9f4e1cb drm/xe: Attach debug metadata to vma -:315: WARNING:LONG_LINE: line length of 109 exceeds 100 columns #315: FILE: drivers/gpu/drm/xe/xe_vm.c:2261:
+ err = xe_eudebug_copy_vma_metadata(&op->remap.prev->eudebug.metadata,

total: 0 errors, 1 warnings, 0 checks, 485 lines checked 6950a7c43f9e drm/xe/eudebug: Add debug metadata support for xe_eudebug -:48: CHECK:LINE_SPACING: Please don't use multiple blank lines #48: FILE: drivers/gpu/drm/xe/xe_debug_metadata.c:198:

+

total: 0 errors, 0 warnings, 1 checks, 599 lines checked
8f29285760a5 drm/xe/eudebug: Implement vm_bind_op discovery
59784a8a0666 drm/xe/eudebug: Dynamically toggle debugger functionality 1bbfdddec9c4 drm/xe/eudebug_test: Introduce xe_eudebug wa kunit test
-:16: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 194 lines checked 7419000de5f6 drm/xe/eudebug/ptl: Add support for extra attention register cc6676ac179e drm/xe/eudebug/ptl: Add RCU_DEBUG_1 register support for xe3 86497262e6c8 drm/xe/eudebug: Add read/count/compare helper for eu attention 1a6695e5836f drm/xe/eudebug: Introduce EU pagefault handling interface -:409: CHECK:UNCOMMENTED_DEFINITION: spinlock_t definition without comment #409: FILE: drivers/gpu/drm/xe/xe_eudebug.c:4234:
+ spinlock_t lock;

-:417: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "!fence" #417: FILE: drivers/gpu/drm/xe/xe_eudebug.c:4242:
+ if (fence == NULL)

-:514: CHECK:USLEEP_RANGE: usleep_range is preferred over udelay; see function description of usleep_range() and udelay(). #514: FILE: drivers/gpu/drm/xe/xe_eudebug.c:4339:
+ udelay(200);

-:522: CHECK:USLEEP_RANGE: usleep_range is preferred over udelay; see function description of usleep_range() and udelay(). #522: FILE: drivers/gpu/drm/xe/xe_eudebug.c:4347:
+ udelay(200);

total: 0 errors, 0 warnings, 4 checks, 774 lines checked
09839463caad drm/xe/vm: Support for adding null page VMA to VM on request
-:15: WARNING:COMMIT_LOG_LONG_LINE: Prefer a maximum 75 chars per line (possible unwrapped commit description?) #15:
[1] https://lore.kernel.org/intel-xe/[email protected]/

total: 0 errors, 1 warnings, 0 checks, 31 lines checked 00b6bd24a242 drm/xe/eudebug: Enable EU pagefault handling

#58 lore raw

✗ CI.KUnit: failure for Intel Xe GPU debug support (eudebug) v3

In reply to Mika Kuoppala
== Series Details ==

== Series Details ==

Series: Intel Xe GPU debug support (eudebug) v3
URL : https://patchwork.freedesktop.org/series/142295/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig [14:38:55] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[14:39:00] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json ARCH=um O=.kunit --jobs=48
ERROR:root:../lib/iomap.c:156:5: warning: no previous prototype for ‘ioread64_lo_hi’ [-Wmissing-prototypes]
  156 | u64 ioread64_lo_hi(const void __iomem *addr)
      |     ^~~~~~~~~~~~~~
../lib/iomap.c:163:5: warning: no previous prototype for ‘ioread64_hi_lo’ [-Wmissing-prototypes]
  163 | u64 ioread64_hi_lo(const void __iomem *addr)
      |     ^~~~~~~~~~~~~~
../lib/iomap.c:170:5: warning: no previous prototype for ‘ioread64be_lo_hi’ [-Wmissing-prototypes]
  170 | u64 ioread64be_lo_hi(const void __iomem *addr)
      |     ^~~~~~~~~~~~~~~~
../lib/iomap.c:178:5: warning: no previous prototype for ‘ioread64be_hi_lo’ [-Wmissing-prototypes]
  178 | u64 ioread64be_hi_lo(const void __iomem *addr)
      |     ^~~~~~~~~~~~~~~~
../lib/iomap.c:264:6: warning: no previous prototype for ‘iowrite64_lo_hi’ [-Wmissing-prototypes]
  264 | void iowrite64_lo_hi(u64 val, void __iomem *addr)
      |      ^~~~~~~~~~~~~~~
../lib/iomap.c:272:6: warning: no previous prototype for ‘iowrite64_hi_lo’ [-Wmissing-prototypes]
  272 | void iowrite64_hi_lo(u64 val, void __iomem *addr)
      |      ^~~~~~~~~~~~~~~
../lib/iomap.c:280:6: warning: no previous prototype for ‘iowrite64be_lo_hi’ [-Wmissing-prototypes]
  280 | void iowrite64be_lo_hi(u64 val, void __iomem *addr)
      |      ^~~~~~~~~~~~~~~~~
../lib/iomap.c:288:6: warning: no previous prototype for ‘iowrite64be_hi_lo’ [-Wmissing-prototypes]
  288 | void iowrite64be_hi_lo(u64 val, void __iomem *addr)
      |      ^~~~~~~~~~~~~~~~~
In file included from ../include/linux/module.h:22,
                 from ../include/linux/device/driver.h:21,
                 from ../include/linux/device.h:32,
                 from ../include/linux/auxiliary_bus.h:11,
                 from ../include/linux/intel_vsec.h:5,
                 from ../drivers/gpu/drm/xe/xe_vsec.c:7:
../drivers/gpu/drm/xe/xe_vsec.c:233:18: error: expected ‘,’ or ‘;’ before ‘INTEL_VSEC’
  233 | MODULE_IMPORT_NS(INTEL_VSEC);
      |                  ^~~~~~~~~~
../include/linux/moduleparam.h:26:61: note: in definition of macro ‘__MODULE_INFO’
   26 |                 = __MODULE_INFO_PREFIX __stringify(tag) "=" info
      |                                                             ^~~~
../include/linux/module.h:299:33: note: in expansion of macro ‘MODULE_INFO’
  299 | #define MODULE_IMPORT_NS(ns)    MODULE_INFO(import_ns, ns)
      |                                 ^~~~~~~~~~~
../drivers/gpu/drm/xe/xe_vsec.c:233:1: note: in expansion of macro ‘MODULE_IMPORT_NS’
  233 | MODULE_IMPORT_NS(INTEL_VSEC);
      | ^~~~~~~~~~~~~~~~
make[7]: *** [../scripts/Makefile.build:194: drivers/gpu/drm/xe/xe_vsec.o] Error 1
make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:440: drivers/gpu/drm/xe] Error 2
make[5]: *** [../scripts/Makefile.build:440: drivers/gpu/drm] Error 2
make[4]: *** [../scripts/Makefile.build:440: drivers/gpu] Error 2
make[3]: *** [../scripts/Makefile.build:440: drivers] Error 2
make[2]: *** [/kernel/Makefile:1989: .] Error 2
make[1]: *** [/kernel/Makefile:251: __sub-make] Error 2
make: *** [Makefile:251: __sub-make] Error 2

+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel

#59 lore raw

✗ CI.Patch_applied: failure for Intel Xe GPU debug support (eudebug) v3 (rev2)

In reply to Mika Kuoppala
== Series Details ==

== Series Details ==

Series: Intel Xe GPU debug support (eudebug) v3 (rev2)
URL : https://patchwork.freedesktop.org/series/142295/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 5c2a17b3ae90 drm-tip: 2024y-12m-16d-13h-54m-55s UTC integration manifest === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_exec_queue.c:117
error: drivers/gpu/drm/xe/xe_exec_queue.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_execlist.c:265
error: drivers/gpu/drm/xe/xe_execlist.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_lrc.c:876
error: drivers/gpu/drm/xe/xe_lrc.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_lrc.h:41
error: drivers/gpu/drm/xe/xe_lrc.h: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: ptrace: export ptrace_may_access
Applying: drm/xe/eudebug: Introduce eudebug support
Applying: drm/xe/eudebug: Introduce discovery for resources
Applying: drm/xe/eudebug: Introduce exec_queue events
Applying: drm/xe/eudebug: Introduce exec queue placements event
Applying: drm/xe/eudebug: hw enablement for eudebug
Applying: drm/xe: Add EUDEBUG_ENABLE exec queue property
Patch failed at 0007 drm/xe: Add EUDEBUG_ENABLE exec queue property When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

#60 lore raw

✗ CI.Patch_applied: failure for Intel Xe GPU debug support (eudebug) v3 (rev3)

In reply to Mika Kuoppala
== Series Details ==

== Series Details ==

Series: Intel Xe GPU debug support (eudebug) v3 (rev3)
URL : https://patchwork.freedesktop.org/series/142295/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: d57431066901 drm-tip: 2024y-12m-20d-11h-06m-45s UTC integration manifest === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_exec_queue.c:117
error: drivers/gpu/drm/xe/xe_exec_queue.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_execlist.c:265
error: drivers/gpu/drm/xe/xe_execlist.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_lrc.c:876
error: drivers/gpu/drm/xe/xe_lrc.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_lrc.h:41
error: drivers/gpu/drm/xe/xe_lrc.h: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: ptrace: export ptrace_may_access
Applying: drm/xe/eudebug: Introduce eudebug support
Applying: drm/xe/eudebug: Introduce discovery for resources
Applying: drm/xe/eudebug: Introduce exec_queue events
Applying: drm/xe/eudebug: Introduce exec queue placements event
Applying: drm/xe/eudebug: hw enablement for eudebug
Applying: drm/xe: Add EUDEBUG_ENABLE exec queue property
Patch failed at 0007 drm/xe: Add EUDEBUG_ENABLE exec queue property When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

#61 lore raw

✗ CI.Patch_applied: failure for Intel Xe GPU debug support (eudebug) v3 (rev4)

In reply to Mika Kuoppala
== Series Details ==

== Series Details ==

Series: Intel Xe GPU debug support (eudebug) v3 (rev4)
URL : https://patchwork.freedesktop.org/series/142295/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 26615f392d22 drm-tip: 2025y-01m-13d-14h-56m-16s UTC integration manifest === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_exec_queue.c:117
error: drivers/gpu/drm/xe/xe_exec_queue.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_execlist.c:265
error: drivers/gpu/drm/xe/xe_execlist.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_lrc.c:876
error: drivers/gpu/drm/xe/xe_lrc.c: patch does not apply
error: patch failed: drivers/gpu/drm/xe/xe_lrc.h:41
error: drivers/gpu/drm/xe/xe_lrc.h: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: ptrace: export ptrace_may_access
Applying: drm/xe/eudebug: Introduce eudebug support
Applying: drm/xe/eudebug: Introduce discovery for resources
Applying: drm/xe/eudebug: Introduce exec_queue events
Applying: drm/xe/eudebug: Introduce exec queue placements event
Applying: drm/xe/eudebug: hw enablement for eudebug
Applying: drm/xe: Add EUDEBUG_ENABLE exec queue property
Patch failed at 0007 drm/xe: Add EUDEBUG_ENABLE exec queue property When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".