Intel Xe GPU Debug Support (eudebug) v11
Subsystems (5)
cover Intel Xe GPU Debug Support (eudebug) v11
Hi,
This is the v11 patch series for Intel Xe GPU debug support (eudebug).
This is eudebug core only. The EU page fault block (v10 patches 20-27) is not part of current series and will be sent when we have reached agreement about this series.
One TTM specific core patch is first in the series.
Series should address all but one (see Open questions) sashiko findings on v10:
https://sashiko.dev/#/patchset/20260903145952.848051-1-mika.kuoppala%40linux.intel.com
Additionally we did multiple local Sashiko runs with claude-opus-5.5 and gemini-4-argon to get further comments on reworks. All non code change issues were addressed by more documentation and comments.
We addressed over 170 review findings. Most came from sashiko of which 13 of them high severity and about 80 medium.
Claude Opus 5.5 was used as an AI coding assistant.
# Major changes from v10
All per connection state is now guarded by a single mutex. It replaces multiple smaller locks and eliminates all use of READ_ONCE/WRITE_ONCE access. This addresses most of sashiko UAF concerns.
Discovery no longer runs on a workqueue. The connect ioctl takes the target's ioctl_lock for write and pushes all discovery events into the kfifo before returing. This avoids the issues discussed in patch 4 in previous series.
eudebug is now mutually exclusive with OA in addition to SR-IOV. These interfere with eachothers in HW.
# Open questions
In patch 14, the userptr vm access path still resolves the addresses through a task_struct's current mm rather than the mm at bind time. See the XXX FIXME comment in the patch.
# Supported HW
The series has been test with IGT on the following platforms:
- Lunarlake (LNL)
- Battlemage (BMG)
- Pantherlake (PTL)
The code for this submission can be found at:
https://gitlab.freedesktop.org/miku/kernel/-/tree/eudebug-v11
Tests:
https://gitlab.freedesktop.org/DominikPiatkowski-Intel/igt-gpu-tools/-/tree/eudebug-dev-next
Userspace:
https://github.com/intel/compute-runtime/
(behind compile-time default disabled flags NEO_ENABLE_XE_EU_DEBUG_SUPPORT and NEO_USE_XE_EU_DEBUG_EXP_UPSTREAM)
GDB: https://sourceware.org/pipermail/gdb-patches/2026-August/229340.html
This series continues from the following previous submissions:
v1: https://lists.freedesktop.org/archives/intel-xe/2024-July/043605.html
v2: https://lists.freedesktop.org/archives/intel-xe/2024-October/052260.html
v3: https://lists.freedesktop.org/archives/intel-xe/2024-December/061476.html
v4: https://lists.freedesktop.org/archives/intel-xe/2025-August/091645.html
v5: https://lists.freedesktop.org/archives/intel-xe/2025-October/097859.html
v6: https://lists.freedesktop.org/archives/intel-xe/2025-December/106405.html
v7: https://lists.freedesktop.org/archives/intel-xe/2026-February/115750.html
v8: https://lists.freedesktop.org/archives/intel-xe/2026-April/124147.html
v9: https://lists.freedesktop.org/archives/intel-xe/2026-June/128834.html
v10: https://lists.freedesktop.org/archives/intel-xe/2026-September/139020.html
Christoph Manszewski (5):
drm/xe: Implement SR-IOV and eudebug exclusivity drm/xe: Introduce ADD_DEBUG_DATA and REMOVE_DEBUG_DATA vm bind ops drm/xe/eudebug: Introduce vm bind and vm bind debug data events drm/xe/eudebug_test: Introduce eudebug live tests drm/xe: Add xe_client_debugfs and introduce debug_data file
Dominik Grzegorzek (5):
drm/xe: Add EUDEBUG_ENABLE exec queue property drm/xe/eudebug: Introduce exec_queue events drm/xe/eudebug: Add hw enablement drm/xe/eudebug: Introduce EU control interface drm/xe/eudebug: Introduce per device attention scan worker
Mika Kuoppala (10):
drm/ttm: Add ttm_bo_access_locked() drm/xe/eudebug: Introduce eudebug interface drm/xe/eudebug: Add documentation drm/xe/eudebug: Add connection establishment documentation drm/xe/eudebug: Introduce discovery for resources drm/xe/eudebug: Mark guc contexts as debuggable drm/xe/eudebug: Add ufence events with acks drm/xe/eudebug: Add vm open/pread/pwrite drm/xe/eudebug: Add userptr vm pread/pwrite drm/xe/eudebug: Track debuggable exec queues
.../ABI/testing/sysfs-driver-intel-xe-eudebug | 61 + Documentation/gpu/driver-uapi.rst | 2 + Documentation/gpu/xe/index.rst | 1 + Documentation/gpu/xe/xe_eudebug.rst | 100 + .../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 2 + drivers/gpu/drm/ttm/ttm_bo_vm.c | 61 +- drivers/gpu/drm/xe/Kconfig | 10 + drivers/gpu/drm/xe/Makefile | 7 +- drivers/gpu/drm/xe/abi/guc_actions_abi.h | 5 + drivers/gpu/drm/xe/abi/guc_klvs_abi.h | 1 + drivers/gpu/drm/xe/regs/xe_engine_regs.h | 1 + drivers/gpu/drm/xe/regs/xe_gt_regs.h | 41 + drivers/gpu/drm/xe/tests/xe_eudebug_test.c | 241 ++ drivers/gpu/drm/xe/tests/xe_live_test_mod.c | 5 + drivers/gpu/drm/xe/xe_client_debugfs.c | 134 + drivers/gpu/drm/xe/xe_client_debugfs.h | 17 + drivers/gpu/drm/xe/xe_debug_data.c | 388 ++ drivers/gpu/drm/xe/xe_debug_data.h | 22 + drivers/gpu/drm/xe/xe_debug_data_types.h | 26 + drivers/gpu/drm/xe/xe_device.c | 36 +- drivers/gpu/drm/xe/xe_device.h | 53 + drivers/gpu/drm/xe/xe_device_types.h | 75 + drivers/gpu/drm/xe/xe_eudebug.c | 3196 +++++++++++++++++ drivers/gpu/drm/xe/xe_eudebug.h | 114 + drivers/gpu/drm/xe/xe_eudebug_hw.c | 806 +++++ drivers/gpu/drm/xe/xe_eudebug_hw.h | 30 + drivers/gpu/drm/xe/xe_eudebug_types.h | 212 ++ drivers/gpu/drm/xe/xe_eudebug_vm.c | 662 ++++ drivers/gpu/drm/xe/xe_eudebug_vm.h | 13 + drivers/gpu/drm/xe/xe_exec_queue.c | 114 +- drivers/gpu/drm/xe/xe_exec_queue.h | 2 + drivers/gpu/drm/xe/xe_exec_queue_types.h | 15 + drivers/gpu/drm/xe/xe_gt_debug.c | 228 ++ drivers/gpu/drm/xe/xe_gt_debug.h | 31 + drivers/gpu/drm/xe/xe_guc.c | 15 + drivers/gpu/drm/xe/xe_guc.h | 6 + drivers/gpu/drm/xe/xe_guc_ads.c | 5 + drivers/gpu/drm/xe/xe_guc_submit.c | 34 + drivers/gpu/drm/xe/xe_hw_engine.h | 14 + drivers/gpu/drm/xe/xe_oa.c | 61 + drivers/gpu/drm/xe/xe_oa.h | 1 + drivers/gpu/drm/xe/xe_reg_sr.c | 19 +- drivers/gpu/drm/xe/xe_reg_sr.h | 4 +- drivers/gpu/drm/xe/xe_reg_whitelist.c | 2 +- drivers/gpu/drm/xe/xe_rtp.c | 2 +- drivers/gpu/drm/xe/xe_sync.c | 47 +- drivers/gpu/drm/xe/xe_sync.h | 3 + drivers/gpu/drm/xe/xe_sync_types.h | 29 +- drivers/gpu/drm/xe/xe_userptr.c | 4 + drivers/gpu/drm/xe/xe_userptr.h | 34 + drivers/gpu/drm/xe/xe_vm.c | 245 +- drivers/gpu/drm/xe/xe_vm_types.h | 31 + drivers/gpu/drm/xe/xe_wa_oob.rules | 4 + include/drm/ttm/ttm_bo.h | 2 + include/uapi/drm/xe_drm.h | 133 +- include/uapi/drm/xe_drm_eudebug.h | 523 +++ 57 files changed, 7870 insertions(+), 61 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug create mode 100644 Documentation/gpu/xe/xe_eudebug.rst create mode 100644 drivers/gpu/drm/xe/tests/xe_eudebug_test.c create mode 100644 drivers/gpu/drm/xe/xe_client_debugfs.c create mode 100644 drivers/gpu/drm/xe/xe_client_debugfs.h create mode 100644 drivers/gpu/drm/xe/xe_debug_data.c create mode 100644 drivers/gpu/drm/xe/xe_debug_data.h create mode 100644 drivers/gpu/drm/xe/xe_debug_data_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_hw.c create mode 100644 drivers/gpu/drm/xe/xe_eudebug_hw.h create mode 100644 drivers/gpu/drm/xe/xe_eudebug_types.h create mode 100644 drivers/gpu/drm/xe/xe_eudebug_vm.c create mode 100644 drivers/gpu/drm/xe/xe_eudebug_vm.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.53.0
PATCH 1/20 drm/ttm: Add ttm_bo_access_locked()
ttm_bo_access() reserves the buffer object itself, so a caller that already holds the reservation cannot use it. Split the body out as ttm_bo_access_locked(), which asserts the reservation is held, and leave ttm_bo_access() as reserve, access, unreserve.
The first user, eudebug vm access, has to wait for the move fences and access the object under one reservation.
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 61 +++++++++++++++++++++++---------- include/drm/ttm/ttm_bo.h | 2 ++ 2 files changed, 44 insertions(+), 19 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +42 -19
@@ -405,6 +405,47 @@ static int ttm_bo_vm_access_kmap(struct ttm_buffer_object *bo,return len; } +/** +* ttm_bo_access_locked - Helper to access a reserved buffer object +* +* @bo: ttm buffer object, reserved by the caller +* @offset: access offset into buffer object +* @buf: pointer to caller memory to read into or write from +* @len: length of access +* @write: write access +* +* Same as ttm_bo_access(), for a caller that already holds the reservation, +* for instance to wait for fences before the access without the placement +* changing in between. +* +* Returns: +* @len if successful, negative error code on failure. +*/ +int ttm_bo_access_locked (struct ttm_buffer_object *bo,unsigned long offset, +void *buf,int len,int write) +{ +dma_resv_assert_held (bo->base.resv); + +if (len <1 || (offset + len) > bo->base.size) +return -EIO ; + +if (!bo->resource) +return -ENODATA ; + +switch (bo->resource->mem_type) { +case TTM_PL_SYSTEM : + fallthrough; +case TTM_PL_TT : +return ttm_bo_vm_access_kmap (bo, offset, buf, len, write); +default : +if (bo->bdev->funcs->access_memory) +return bo->bdev->funcs->access_memory + (bo, offset, buf, len, write); +return -EIO ; + } +} +EXPORT_SYMBOL (ttm_bo_access_locked); +/** * ttm_bo_access - Helper to access a buffer object *
@@ -433,26 +474,8 @@ int ttm_bo_access(struct ttm_buffer_object *bo, unsigned long offset,if (ret)return ret; -if (!bo->resource) { - ret = -ENODATA ; - goto unlock; - } - -switch (bo->resource->mem_type) { -case TTM_PL_SYSTEM : - fallthrough; -case TTM_PL_TT : - ret =ttm_bo_vm_access_kmap (bo, offset, buf, len, write); -break ; -default : -if (bo->bdev->funcs->access_memory) - ret = bo->bdev->funcs->access_memory - (bo, offset, buf, len, write); -else - ret = -EIO ; - } + ret =ttm_bo_access_locked (bo, offset, buf, len, write); -unlock:ttm_bo_unreserve (bo);return ret;
include/drm/ttm/ttm_bo.h +2 -0
@@ -441,6 +441,8 @@ s64 ttm_bo_evict_cgroup(struct ttm_device *bdev,struct dmem_cgroup_pool_state *limit_pool, s64 target_bytes, struct ttm_operation_ctx *ctx); +int ttm_bo_access_locked (struct ttm_buffer_object *bo,unsigned long offset, +void *buf,int len,int write);int ttm_bo_access (struct ttm_buffer_object *bo,unsigned long offset,void *buf,int len,int write); vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,
Signature · 1 line
2.53.0
Re: [PATCH 01/20] drm/ttm: Add ttm_bo_access_locked()
Hi Mika,
the description of the "ttm_bo_access()" API states, "Should not be directly exported to user space via a peak/poke interface."
When the newly added "ttm_bo_access_locked()" is used in "eudebug", it is ultimately exposed to user space via functions such as "pread" and "pwrite". @Mattew Brost,I would like to inquire whether this violates the considerations made when the "ttm_bo_access()" API was initially designed.
Aside from the above point, the added "ttm_bo_access_locked()" API appears to be a simple refactoring, so this patch itself does not seem to pose any issues.
Br,
G.G.
Quoted 114 lines · Mika Kuoppala
ttm_bo_access()reserves the buffer object itself, so a caller that already holds the reservation cannot use it. Split the body out asttm_bo_access_locked(), which asserts the reservation is held, and leavettm_bo_access()as reserve, access, unreserve.The first user, eudebug vm access, has to wait for the move fences and access the object under one reservation.
Cc Felix Kuehling <[email protected]>Cc Christian König <[email protected]>Cc Michel Dänzer <[email protected]>Cc Alex Deucher <[email protected]>Cc Thomas Hellström <[email protected]>Cc Matthew Auld <[email protected]>Cc Matthew Brost <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 61 +++++++++++++++++++++++---------- include/drm/ttm/ttm_bo.h | 2 ++ 2 files changed, 44 insertions(+), 19 deletions(-)drivers/gpu/drm/ttm/ttm_bo_vm.c +42
-19@@ -405,6 +405,47 @@ static int ttm_bo_vm_access_kmap(struct ttm_buffer_object *bo,return len; } +/** +* ttm_bo_access_locked - Helper to access a reserved buffer object +* +* @bo: ttm buffer object, reserved by the caller +* @offset: access offset into buffer object +* @buf: pointer to caller memory to read into or write from +* @len: length of access +* @write: write access +* +* Same as ttm_bo_access(), for a caller that already holds the reservation, +* for instance to wait for fences before the access without the placement +* changing in between. +* +* Returns: +* @len if successful, negative error code on failure. +*/ +int ttm_bo_access_locked (struct ttm_buffer_object *bo,unsigned long offset, +void *buf,int len,int write) +{ +dma_resv_assert_held (bo->base.resv); + +if (len <1 || (offset + len) > bo->base.size) +return -EIO ; + +if (!bo->resource) +return -ENODATA ; + +switch (bo->resource->mem_type) { +case TTM_PL_SYSTEM : + fallthrough; +case TTM_PL_TT : +return ttm_bo_vm_access_kmap (bo, offset, buf, len, write); +default : +if (bo->bdev->funcs->access_memory) +return bo->bdev->funcs->access_memory + (bo, offset, buf, len, write); +return -EIO ; + } +} +EXPORT_SYMBOL (ttm_bo_access_locked); +/** * ttm_bo_access - Helper to access a buffer object * @@ -433,26 +474,8 @@ int ttm_bo_access(struct ttm_buffer_object *bo, unsigned long offset,if (ret)return ret; -if (!bo->resource) { - ret = -ENODATA ; - goto unlock; - } - -switch (bo->resource->mem_type) { -case TTM_PL_SYSTEM : - fallthrough; -case TTM_PL_TT : - ret =ttm_bo_vm_access_kmap (bo, offset, buf, len, write); -break ; -default : -if (bo->bdev->funcs->access_memory) - ret = bo->bdev->funcs->access_memory - (bo, offset, buf, len, write); -else - ret = -EIO ; - } + ret =ttm_bo_access_locked (bo, offset, buf, len, write); -unlock:ttm_bo_unreserve (bo);return ret;include/drm/ttm/ttm_bo.h +2
-0@@ -441,6 +441,8 @@ s64 ttm_bo_evict_cgroup(struct ttm_device *bdev,struct dmem_cgroup_pool_state *limit_pool, s64 target_bytes, struct ttm_operation_ctx *ctx); +int ttm_bo_access_locked (struct ttm_buffer_object *bo,unsigned long offset, +void *buf,int len,int write);int ttm_bo_access (struct ttm_buffer_object *bo,unsigned long offset,void *buf,int len,int write); vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,
Re: [PATCH 01/20] drm/ttm: Add ttm_bo_access_locked()
Quoting Gwan-gyeong Mun (2026-11-13 21:09:04)
Quoted 9 lines
Hi Mika,
the description of the "ttm_bo_access()" API states, "Should not be directly exported to user space via a peak/poke interface."When the newly added "
ttm_bo_access_locked()" is used in "eudebug", it is ultimately exposed to user space via functions such as "pread" and "pwrite". @Mattew Brost,I would like to inquire whether this violates the considerations made when the "ttm_bo_access()" API was initially designed.
This was already discussed during earlier series review.
Here, the application itself doesn't get a peek/poke interface, it's only the debugger process. The debugger process is also given heavy hardware flushing operations that are needed to flush out eg. instruction caches.
This interface is pretty much mandatory to facilitate memory access for debugger on our HW as the RCS/CCS/BCS engines may be stalled due to a later page-fault in the queue while dealing with first page-fault.
In that scenarion, submitting workloads to the engines to facilitate single word modifications to memory would simply be blocked.
It'd also fall off performance cliff for single-stepping as GDB at least on the Intel GPU instruction set is very heavy on sparsely accessing a lot of memory during single-stepping. We already had to separate memory access and memory flushing to different operations to make that more user-friendly for interactive single-stepping.
Regards, Joonas
Re: [PATCH 01/20] drm/ttm: Add ttm_bo_access_locked()
In reply to Mika KuoppalaQuoted 8 lines · Mika Kuoppala
ttm_bo_access()reserves the buffer object itself, so a caller that already holds the reservation cannot use it. Split the body out asttm_bo_access_locked(), which asserts the reservation is held, and leavettm_bo_access()as reserve, access, unreserve.The first user, eudebug vm access, has to wait for the move fences and access the object under one reservation.
Quoted 8 lines
Cc Felix Kuehling <[email protected]>Cc Christian König <[email protected]>Cc Michel Dänzer <[email protected]>Cc Alex Deucher <[email protected]>Cc Thomas Hellström <[email protected]>Cc Matthew Auld <[email protected]>Cc Matthew Brost <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>
Quoted 98 lines
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 61 +++++++++++++++++++++++---------- include/drm/ttm/ttm_bo.h | 2 ++ 2 files changed, 44 insertions(+), 19 deletions(-)drivers/gpu/drm/ttm/ttm_bo_vm.c +42
-19@@ -405,6 +405,47 @@ static int ttm_bo_vm_access_kmap(struct ttm_buffer_object *bo,return len; } +/** +* ttm_bo_access_locked - Helper to access a reserved buffer object +* +* @bo: ttm buffer object, reserved by the caller +* @offset: access offset into buffer object +* @buf: pointer to caller memory to read into or write from +* @len: length of access +* @write: write access +* +* Same as ttm_bo_access(), for a caller that already holds the reservation, +* for instance to wait for fences before the access without the placement +* changing in between. +* +* Returns: +* @len if successful, negative error code on failure. +*/ +int ttm_bo_access_locked (struct ttm_buffer_object *bo,unsigned long offset, +void *buf,int len,int write) +{ +dma_resv_assert_held (bo->base.resv); + +if (len <1 || (offset + len) > bo->base.size) +return -EIO ; + +if (!bo->resource) +return -ENODATA ; + +switch (bo->resource->mem_type) { +case TTM_PL_SYSTEM : + fallthrough; +case TTM_PL_TT : +return ttm_bo_vm_access_kmap (bo, offset, buf, len, write); +default : +if (bo->bdev->funcs->access_memory) +return bo->bdev->funcs->access_memory + (bo, offset, buf, len, write); +return -EIO ; + } +} +EXPORT_SYMBOL (ttm_bo_access_locked); +/** * ttm_bo_access - Helper to access a buffer object * @@ -433,26 +474,8 @@ int ttm_bo_access(struct ttm_buffer_object *bo, unsigned long offset,if (ret)return ret; -if (!bo->resource) { - ret = -ENODATA ; - goto unlock; - } - -switch (bo->resource->mem_type) { -case TTM_PL_SYSTEM : - fallthrough; -case TTM_PL_TT : - ret =ttm_bo_vm_access_kmap (bo, offset, buf, len, write); -break ; -default : -if (bo->bdev->funcs->access_memory) - ret = bo->bdev->funcs->access_memory - (bo, offset, buf, len, write); -else - ret = -EIO ; - } + ret =ttm_bo_access_locked (bo, offset, buf, len, write); -unlock:ttm_bo_unreserve (bo);return ret;include/drm/ttm/ttm_bo.h +2
-0@@ -441,6 +441,8 @@ s64 ttm_bo_evict_cgroup(struct ttm_device *bdev,struct dmem_cgroup_pool_state *limit_pool, s64 target_bytes, struct ttm_operation_ctx *ctx); +int ttm_bo_access_locked (struct ttm_buffer_object *bo,unsigned long offset, +void *buf,int len,int write);int ttm_bo_access (struct ttm_buffer_object *bo,unsigned long offset,void *buf,int len,int write); vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,
PATCH 2/20 drm/xe/eudebug: Introduce eudebug interface
In reply to Mika KuoppalaAdd the eudebug interface to the Xe driver, enabling user-space debuggers (e.g., GDB) to track and interact with GPU resources of a DRM client. Debuggers can inspect or modify these resources, for example, to locate ISA/ELF sections and install breakpoints in a shader's instruction stream.
A debugger opens a connection to the Xe driver via a DRM ioctl, specifying the target DRM client's file descriptor. This returns an anonymous file descriptor for the connection, which can be used to listen for resource creation/destruction events. The same file descriptor can also be used to receive hardware state change events and control execution flow by interrupting EU threads on the GPU (in follow-up patches).
Introduce the eudebug connection and event queuing, adding VM create/destroy events as a baseline. Additional events and hardware control for full debugger operation are needed and will be introduced in follow-up patches.
The resource tracking components are inspired by Maciej Patelczyk's work on resource handling for i915. Chris Wilson suggested a two-way mapping approach, which simplifies using the resource map as definitive bookkeeping for resources relayed to the debugger during the discovery phase (in a 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)
v4: - add proper header guards (Christoph)
- better read_event fault handling (Christoph, Mika)
- simplify attach (Mika)
- connect using target file descriptors
- avoid event->seqno after queue as it can UAF (Mika)
- use drmm for eudebug_fini (Maciej)
- squash dynamic enable
v6: - drm->authenticated is overzealous for render (Mika)
v7: - struct member documentation (Mika)
- enforce seqno mbz (Mika)
v8: - head->seqno fix (Mika)
- resource alloc and removal cleanup (Mika)
- s/wait_interruptible_timeout/wait_timeout (Mika)
- use fd_install in connect (Mika)
v9: - fix xef vs debugger race (Sashiko)
- assign d->xe early (Sashiko)
- simplify locking (Mika)
- fix pending->len outside lock (Sashiko)
- remove version from connect to address fd_install leak (Sashiko)
- create vm by id to avoid use after free (Sashiko)
- use xe_eudebug_detach on connection error path (Sashiko)
- don't sleep on kzalloc as we can disconnect (Sashiko)
- check if enabled on connection (Sashiko)
- preallocated event fifo for lockless allocs (Sashiko, Mika)
v10:
- wakeup after detach, take account of occupied (Sashiko)
- GFP_ACCOUNT for fifo (Sashiko)
- set O_CLOEXEC on connection fd (Sashiko)
- docstrings (Maciej)
- use guard and __kfree (Mika)
- init_early (Maciej)
- remove unused struct members
- no need to send destroy if vm was not announced (Claude)
- avoid dereference of xef on eu_print (Claude)
- don't silently truncate target fd (Claude)
- preallocate resource handles
- zero as target fd (Claude)
- hold drm_device (Claude)
v11: - fix eudebug=n build (Claude)
- document seqno as timeline (Sashiko)
v12: - drain nothing on detach, say so in the uapi (Sashiko)
- drop resource handles on detach to avoid uaf (Sashiko)
- ioctl naming, sysfs abi (Claude)
v13: - create enable_eudebug last, so init cannot undo an enable
(review-prompts)
v14: - one mutex for all debugger state, no lockless accesses (Mika)
v15: - __free() variables defined where they are assigned (Sashiko)
- poll in one lock section, no EPOLLIN once detached (Sashiko)
- connect in the uapi ioctl list (Sashiko)
- copy the event out of @events.pending directly, no bounce allocation per read (Sashiko)
--- .../ABI/testing/sysfs-driver-intel-xe-eudebug | 36 + Documentation/gpu/driver-uapi.rst | 2 + .../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 2 + drivers/gpu/drm/xe/Kconfig | 10 + drivers/gpu/drm/xe/Makefile | 3 + drivers/gpu/drm/xe/xe_device.c | 8 + drivers/gpu/drm/xe/xe_device_types.h | 29 + drivers/gpu/drm/xe/xe_eudebug.c | 1212 +++++++++++++++++ drivers/gpu/drm/xe/xe_eudebug.h | 68 + drivers/gpu/drm/xe/xe_eudebug_types.h | 168 +++ drivers/gpu/drm/xe/xe_vm.c | 15 +- include/uapi/drm/xe_drm.h | 24 + include/uapi/drm/xe_drm_eudebug.h | 131 ++ 14 files changed, 1707 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug 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
Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug new file +36 -0
@@ -0,0 +1,36 @@ +What: /sys/bus/pci/drivers/xe/.../enable_eudebug +Date: August 2026 +KernelVersion: 7.4 +Contact: [email protected] +Description: RW. Controls whether the EU debugger interface is armed for + this device. + + Reads back 1 when the interface is enabled and 0 when it is + not. Writing a boolean value ("0"/"1", "n"/"y", "off"/"on") + enables or disables it. The interface starts out disabled. + + While disabled, DRM_IOCTL_XE_EUDEBUG_CONNECT fails with + -EOPNOTSUPP. + + Writing 0 while any debugger connection is still attached + fails with -EBUSY. + + Once enabled, connecting needs no privilege beyond access to + the render node: a client may attach to any DRM file it holds + a descriptor for, including its own. Any such client can + therefore keep the interface from being disabled for as long + as it keeps its connection open. Disabling does not revoke + existing connections; to disable, the processes holding them + have to close them or be terminated. A connection shows up as + an "anon_inode:[xe_eudebug]" entry under /proc/<pid>/fd. + + Each connection allocates about 4 MiB of kernel memory for + its event queue, held until the connection is closed. The + number of connections is not limited beyond the file + descriptor limit; the memory is charged to the memory cgroup + of the process that connected. + + This attribute is only present when the driver is built with + CONFIG_DRM_XE_EUDEBUG and the interface was set up at probe + time. If probe could not set it up, the attribute is absent + and the connect ioctl fails with -EOPNOTSUPP.
Documentation/gpu/driver-uapi.rst +2 -0
@@ -30,6 +30,8 @@ drm/xe uAPI .. kernel-doc:: include/uapi/drm/xe_drm.h +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + drm/asahi uAPI ================
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
@@ -261,6 +261,7 @@ Code Seq# Include File Comments 'i' 80-8F linux/i8k.h 'i' 90-9F `linux/iio/*.h` IIO 'j' 00-3F linux/joystick.h +'j' 40-4F uapi/drm/xe_drm_eudebug.h Intel Xe EU debugger connection 'k' 00-0F linux/spi/spidev.h conflict! 'k' 00-05 video/kyro.h conflict! 'k' 10-17 linux/hsi/hsi_char.h HSI character device
MAINTAINERS +2 -0
@@ -13397,11 +13397,13 @@ Q: http://patchwork.freedesktop.org/project/intel-xe/ B: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues C: irc://irc.oftc.net/xe T: git https://gitlab.freedesktop.org/drm/xe/kernel.git +F: Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug F: Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon F: Documentation/gpu/xe/ F: drivers/gpu/drm/xe/ F: include/drm/intel/ F: include/uapi/drm/xe_drm.h +F: include/uapi/drm/xe_drm_eudebug.h INTEL ELKHART LAKE PSE I/O DRIVER M: Raag Jadav <[email protected]>
drivers/gpu/drm/xe/Kconfig +10 -0
@@ -143,6 +143,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 n + help + Choose this option if you want to add support for a debugger (gdb) + to attach to a process using Xe and debug its gpu/gpgpu programs. + With debugger support, Xe provides an interface for a debugger to + track, inspect and modify the resources of that process. + menu "drm/Xe Debugging" depends on DRM_XE depends on EXPERT
drivers/gpu/drm/xe/Makefile +3 -0
@@ -163,6 +163,9 @@ xe-$(CONFIG_I2C) += xe_i2c.o \ xe-$(CONFIG_DRM_XE_GPUSVM) += xe_svm.o xe-$(CONFIG_DRM_GPUSVM) += xe_userptr.o +# debugging shaders with gdb (eudebug) support +xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o + # graphics hardware monitoring (HWMON) support xe-$(CONFIG_HWMON) += xe_hwmon.o
drivers/gpu/drm/xe/xe_device.c +8 -0
@@ -34,6 +34,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"
@@ -181,6 +182,8 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)guard (xe_pm_runtime)(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
@@ -231,6 +234,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_GET_PROPERTY , xe_vm_get_property_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)
@@ -1064,6 +1068,8 @@ int xe_device_probe(struct xe_device *xe)if (err)return err; +xe_eudebug_init_early (xe); + err =drm_dev_register (&xe->drm,0 );if (err)return err;
@@ -1101,6 +1107,8 @@ int xe_device_probe(struct xe_device *xe)if (err) goto err_unregister_display; +xe_eudebug_init (xe); +detect_preproduction_hw (xe); err =devm_add_action_or_reset (xe->drm.dev, xe_device_sanitize, xe);
drivers/gpu/drm/xe/xe_device_types.h +29 -0
@@ -15,6 +15,7 @@#include "xe_cper_types.h" #include "xe_devcoredump_types.h" #include "xe_drm_ras_types.h" +#include "xe_eudebug_types.h" #include "xe_heci_gsc.h" #include "xe_late_bind_fw_types.h" #include "xe_oa_types.h"
@@ -621,6 +622,26 @@ struct xe_device {atomic_t g2g_test_count;#endif +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +/** @eudebug: eudebug globals for the device */ +struct { +/** @eudebug.session_count: session counter to track connections */ +u64 session_count; + +/** +* @eudebug.cap_state: eudebug capability state, protected by +* @eudebug.lock +*/ +enum xe_eudebug_cap_state cap_state; + +/** @eudebug.attached: number of debuggers currently attached */ +unsigned int attached; + +/** @eudebug.lock: protects the eudebug state of this device */ +struct mutex lock; + } eudebug; +#endif +/* private: */ #if IS_ENABLED (CONFIG_DRM_XE_DISPLAY )
@@ -708,6 +729,14 @@ struct xe_file {/** @mmio_gem.pci_barrier: MMIO GEM object for PCI barrier mmap. */ struct xe_mmio_gem *pci_barrier; } mmio_gem; + +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +/** @eudebug: struct to hold eudebug connection specifics */ +struct { +/** @eudebug.debugger: the debugger connection into this xe_file */ +struct xe_eudebug *debugger; + } eudebug; +#endif };#endif
drivers/gpu/drm/xe/xe_eudebug.c new file +1212 -0
1,212 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h new file +68 -0
68 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug_types.h new file +168 -0
168 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.c +13 -2
@@ -28,6 +28,7 @@#include "xe_cpu_bind.h" #include "xe_device.h" #include "xe_drm_client.h" +#include "xe_eudebug.h" #include "xe_exec_queue.h" #include "xe_gt.h" #include "xe_migrate.h"
@@ -2226,10 +2227,18 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data, args->reserved[0 ] =xe_bo_main_addr (vm->pt_root[0 ]->bo,XE_PAGE_SIZE );#endif +/* +* Announce to the debugger before the id is published, as from that +* point on a concurrent destroy can race us to the resource map. +*/ +xe_eudebug_vm_create (xef, vm); +/* user id alloc must always be last in ioctl to prevent UAF */ err =xa_alloc (&xef->vm.xa, &id, vm, xa_limit_32b,GFP_KERNEL ); -if (err) +if (err) { +xe_eudebug_vm_destroy (xef, vm); goto err_close_and_put; + } args->vm_id = id;
@@ -2264,8 +2273,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 +24 -0
@@ -85,6 +85,7 @@ extern "C" {* - &DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS * - &DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY * - &DRM_IOCTL_XE_VM_GET_PROPERTY +* - &DRM_IOCTL_XE_EUDEBUG_CONNECT */ /*
@@ -110,6 +111,7 @@ extern "C" {#define DRM_XE_VM_QUERY_MEM_RANGE_ATTRS 0x0d#define DRM_XE_EXEC_QUEUE_SET_PROPERTY 0x0e#define DRM_XE_VM_GET_PROPERTY 0x0f +#define DRM_XE_EUDEBUG_CONNECT 0x10/* Must be kept compact -- no holes */
@@ -129,6 +131,7 @@ extern "C" {#define DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_QUERY_MEM_RANGE_ATTRS, struct drm_xe_vm_query_mem_range_attr)#define DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property)#define DRM_IOCTL_XE_VM_GET_PROPERTY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_GET_PROPERTY, struct drm_xe_vm_get_property) +#define DRM_IOCTL_XE_EUDEBUG_CONNECT DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EUDEBUG_CONNECT, struct drm_xe_eudebug_connect)/** * DOC: Xe IOCTL Extensions
@@ -2634,6 +2637,27 @@ enum drm_xe_ras_error_component { [DRM_XE_RAS_ERR_COMP_FABRIC] = "fabric", \ } +/** +* struct drm_xe_eudebug_connect - Input of &DRM_IOCTL_XE_EUDEBUG_CONNECT +* +* This structure is used to connect to an eudebug interface of target drm file. +*/ +struct drm_xe_eudebug_connect { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @fd: Debug target DRM client fd */ +__u64 fd; + +/** @flags: Flags, MBZ */ +__u64 flags; + +/** @reserved: MBZ */ +__u64 reserved; +}; + +#include "xe_drm_eudebug.h" +#if defined(__cplusplus) }#endif
include/uapi/drm/xe_drm_eudebug.h new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 3/20 drm/xe/eudebug: Add documentation
In reply to Mika KuoppalaAdd core documentation for connection setup and events. Follow-up patches can then incrementally add their workings.
--- Documentation/gpu/xe/index.rst | 1 + Documentation/gpu/xe/xe_eudebug.rst | 56 +++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_eudebug.c | 19 ++++++++++ 3 files changed, 76 insertions(+) create mode 100644 Documentation/gpu/xe/xe_eudebug.rst
Documentation/gpu/xe/index.rst +1 -0
@@ -36,3 +36,4 @@ The display, or :ref:`drm-kms`, support for drm/xe is provided by xe_configfs xe_gt_stats xe_sigid + xe_eudebug
Documentation/gpu/xe/xe_eudebug.rst new file +56 -0
56 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.c +19 -0
@@ -19,6 +19,25 @@#include "xe_macros.h" #include "xe_vm.h" +/** +* DOC: Connection Establishment +* +* To debug a target DRM client, the debugger must first establish +* a connection using :c:type:`drm_xe_eudebug_connect`. +* +*/ + +/** +* DOC: Events +* +* Resource creation/destruction and hardware state changes are +* delivered as events to the debugger. +* +* To read an event, ioctl DRM_XE_EUDEBUG_IOCTL_READ_EVENT command +* can be issued with prefilled :c:type:`drm_xe_eudebug_event` as argument. +* +*/ +#define cast_event (T , event) container_of((event), typeof(*(T)), base)static const struct rhashtable_params rhash_res = {
Signature · 1 line
2.53.0
PATCH 4/20 drm/xe/eudebug: Add connection establishment documentation
In reply to Mika KuoppalaAdd documentation for connecting to a target DRM Xe client for debugging.
v2: improved Pipe and Fork documentation (Sashiko)
v10: qualify the ptrace_may_access() parity claim per fd
acquisition method (Claude)
--- Documentation/gpu/xe/xe_eudebug.rst | 11 +++ drivers/gpu/drm/xe/xe_eudebug.c | 104 +++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 1 deletion(-)
Documentation/gpu/xe/xe_eudebug.rst +11 -0
@@ -27,6 +27,17 @@ Connection Establishment .. kernel-doc:: drivers/gpu/drm/xe/xe_eudebug.c :doc: Connection Establishment +File Descriptor Acquisition Methods +----------------------------------- + +.. kernel-doc:: drivers/gpu/drm/xe/xe_eudebug.c + :doc: File Descriptor Acquisition Methods + +Security Model +-------------- +.. kernel-doc:: drivers/gpu/drm/xe/xe_eudebug.c + :doc: Security Model + Events ======
drivers/gpu/drm/xe/xe_eudebug.c +103 -1
111 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 5/20 drm/xe: Implement SR-IOV and eudebug exclusivity
In reply to Mika KuoppalaFrom: Christoph Manszewski <[email protected]>
EU debug functionality relies on access to specific mmio registers. Since VFs don't have access to those registers and in order to avoid interference with VFs, make SR-IOV and eudebug functionality exclusive. I.e. don't allow enabling eudebug in VF mode and don't allow enabling eudebug when any VFs are enabled. Likewise, don't allow enabling VFs when eudebug is enabled.
v2: initialize lock early (Sashiko)
v3: say why eudebug was refused (Claude)
v4: avoid racing with work (Sashiko)
v5: - don't log per VF probe (Sashiko)
v6: - cap_state under eudebug.lock (Mika)
v7: - poll stop comment: a PF waits the last round out (Sashiko)
v8: - move right after the interface documentation, the vm access, EU
control, attention worker and live tests patches now cover their own parts (Mika)
--- .../ABI/testing/sysfs-driver-intel-xe-eudebug | 4 ++++ drivers/gpu/drm/xe/xe_eudebug.c | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+)
Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug +4 -0
@@ -34,3 +34,7 @@ Description: RW. Controls whether the EU debugger interface is armed for CONFIG_DRM_XE_EUDEBUG and the interface was set up at probe time. If probe could not set it up, the attribute is absent and the connect ioctl fails with -EOPNOTSUPP. + + On an SR-IOV VF the attribute is absent. On a PF, writing 1 + while VFs are enabled fails with -EBUSY, and while the + interface is enabled enabling VFs fails with -EPERM.
drivers/gpu/drm/xe/xe_eudebug.c +21 -0
@@ -17,6 +17,7 @@#include "xe_eudebug.h" #include "xe_eudebug_types.h" #include "xe_macros.h" +#include "xe_sriov_pf.h" #include "xe_vm.h" /**
@@ -1203,6 +1204,8 @@ void xe_eudebug_file_close(struct xe_file *xef)static int xe_eudebug_enable (struct xe_device *xe,bool enable) { +int ret; +guard (mutex)(&xe->eudebug.lock);if (xe->eudebug.cap_state ==XE_EUDEBUG_CAP_NOT_SUPPORTED )
@@ -1214,9 +1217,21 @@ static int xe_eudebug_enable(struct xe_device *xe, bool enable)if (enable ==__xe_eudebug_is_enabled (xe))return 0 ; +/* Lock VFs out first, so that a refusal leaves nothing to take back */ +if (enable &&IS_SRIOV_PF (xe)) { + ret =xe_sriov_pf_lockdown (xe); +if (ret) { +drm_dbg (&xe->drm,"Can't enable eudebug: VFs are enabled\n" ); +return ret; + } + } +set_cap_state (xe, enable ?XE_EUDEBUG_CAP_ENABLED :XE_EUDEBUG_CAP_DISABLED ); +if (!enable &&IS_SRIOV_PF (xe)) +xe_sriov_pf_end_lockdown (xe); +return 0 ; }
@@ -1288,6 +1303,11 @@ void xe_eudebug_init(struct xe_device *xe)if (xe->eudebug.cap_state ==XE_EUDEBUG_CAP_NOT_SUPPORTED )return ; +if (IS_SRIOV_VF (xe)) { +drm_dbg (&xe->drm,"eudebug not available in SR-IOV VF mode\n" ); + goto out_not_supported; + } + err =devm_add_action_or_reset (dev->dev, xe_eudebug_sysfs_fini, xe);if (err) goto out_err;
@@ -1307,6 +1327,7 @@ void xe_eudebug_init(struct xe_device *xe) out_err:drm_warn (&xe->drm,"eudebug disabled, init fail: %d\n" , err); +out_not_supported: scoped_guard(mutex, &xe->eudebug.lock)set_cap_state (xe,XE_EUDEBUG_CAP_NOT_SUPPORTED ); }
Signature · 1 line
2.53.0
PATCH 6/20 drm/xe/eudebug: Introduce discovery for resources
In reply to Mika KuoppalaA debugger connection can occur after a client has created and destroyed an arbitrary number of resources. To support this, we need to relay all currently existing resources to the debugger. The client is held on selected ioctls until this discovery process, run in the connect ioctl, is complete.
Based on discovery work by Maciej Patelczyk for the i915 driver.
v2: - use rw_semaphore to block DRM ioctls during discovery (Matthew)
- only lock according to ioctl at play (Dominik)
v4: - s/discovery_lock/ioctl_lock
- change lock to be per xe_file as is connections
v5: - helper to get eudebug instance during discovery (Maciej)
v6: - complete_all even if no client (Sashiko)
- don't flush on detach (Sashiko)
v7: - guard close with ioctl lock (Sashiko)
v8: - discovery lock comment fix (Maciej)
v9: - disconnect on failed discovery (Sashiko)
- avoid close race (Sashiko)
v10: - unordered discovery workqueue (Sashiko)
v11: - -EBUSY only from the ioctls that wait for discovery, keep
-ENOTTY (review-prompts)
v12: - discover in the connect ioctl, no worker, killable gate (Mika)
v13: - exec queue uapi, helpers and exports moved to their users (Sashiko)
- scoped ioctl_lock in attach, no goto next to __free() (Sashiko)
--- drivers/gpu/drm/xe/xe_device.c | 24 +++++++- drivers/gpu/drm/xe/xe_device.h | 53 ++++++++++++++++ drivers/gpu/drm/xe/xe_device_types.h | 12 ++++ drivers/gpu/drm/xe/xe_eudebug.c | 90 +++++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_eudebug.h | 1 + include/uapi/drm/xe_drm.h | 8 +++ 6 files changed, 183 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_device.c +22 -2
@@ -117,6 +117,10 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)mutex_init (&xef->mmio_gem.lock); +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +init_rwsem (&xef->eudebug.ioctl_lock); +#endif + file->driver_priv = xef;kref_init (&xef->refcount);
@@ -248,8 +252,16 @@ static long xe_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)ACQUIRE (xe_pm_runtime_ioctl, pm)(xe); ret =ACQUIRE_ERR (xe_pm_runtime_ioctl, &pm); -if (ret >=0 ) +if (ret >=0 ) { +int lock =xe_eudebug_discovery_lock (file, cmd); + +if (lock <0 ) +return lock; + ret =drm_ioctl (file, cmd, arg); +if (lock) +xe_eudebug_discovery_unlock (file, cmd); + }return ret; }
@@ -266,8 +278,16 @@ static long xe_drm_compat_ioctl(struct file *file, unsigned int cmd, unsigned loACQUIRE (xe_pm_runtime_ioctl, pm)(xe); ret =ACQUIRE_ERR (xe_pm_runtime_ioctl, &pm); -if (ret >=0 ) +if (ret >=0 ) { +int lock =xe_eudebug_discovery_lock (file, cmd); + +if (lock <0 ) +return lock; + ret =drm_compat_ioctl (file, cmd, arg); +if (lock) +xe_eudebug_discovery_unlock (file, cmd); + }return ret; }
drivers/gpu/drm/xe/xe_device.h +53 -0
63 lines not on this page · raw message
drivers/gpu/drm/xe/xe_device_types.h +12 -0
@@ -735,6 +735,18 @@ struct xe_file {struct {/** @eudebug.debugger: the debugger connection into this xe_file */ struct xe_eudebug *debugger; + +/** +* @eudebug.ioctl_lock: excludes the ioctls that mutate the +* eudebug visible resources of this client, so that a writer +* sees a stable set of vms and exec queues. Taken for read +* around the whole ioctl by xe_eudebug_discovery_lock(), for +* the ioctls named in xe_eudebug_needs_ioctl_lock(), and for +* write by the connect ioctl, across discovery, and by file +* close. Held across an entire ioctl, so it nests outside +* every lock those ioctls take. +*/ +struct rw_semaphore ioctl_lock; } eudebug;#endif };
drivers/gpu/drm/xe/xe_eudebug.c +87 -3
136 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +1 -0
@@ -14,6 +14,7 @@ struct drm_file;struct xe_device ;struct xe_file ;struct xe_vm ; +struct xe_eudebug ;#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG )
include/uapi/drm/xe_drm.h +8 -0
@@ -2641,6 +2641,14 @@ enum drm_xe_ras_error_component {* struct drm_xe_eudebug_connect - Input of &DRM_IOCTL_XE_EUDEBUG_CONNECT * * This structure is used to connect to an eudebug interface of target drm file. +* +* On connect, the resources the target already has are first relayed to +* the debugger as events. This is called discovery. The events are +* queued before the ioctl returns. If they do not fit the event queue, +* the ioctl fails with -ENOSPC. +* +* The ioctl waits for the target's resource ioctls in flight to finish, +* and fails with -EINTR if a fatal signal arrives meanwhile. */ struct drm_xe_eudebug_connect {/** @extensions: Pointer to the first extension struct, if any */
Signature · 1 line
2.53.0
PATCH 7/20 drm/xe: Add EUDEBUG_ENABLE exec queue property
In reply to Mika KuoppalaFrom: Dominik Grzegorzek <[email protected]>
Introduce an immutable eudebug property for exec_queues, using a flags value to enable eudebug-specific features. For now, the engine LRC uses this flag to enable the runalone hardware feature. Runalone ensures that only one hardware engine in a group [rcs0, ccs0-3] is active on a tile.
v2: - check CONFIG_DRM_XE_EUDEBUG and LR mode (Matthew)
- disable preempt (Dominik)
- lrc_create remove from engine init
v3: - remove redundant runalone setup (Sashiko)
v4: - deny if pxp is on (Sashiko)
- deny if secondary mq (Sashiko)
- deny if parallel (Sashiko)
- really deny if pxp (Claude)
v5: - fix the multiqueue (Sashiko)
--- .../ABI/testing/sysfs-driver-intel-xe-eudebug | 10 +++ drivers/gpu/drm/xe/xe_exec_queue.c | 81 ++++++++++++++++++- drivers/gpu/drm/xe/xe_exec_queue.h | 2 + drivers/gpu/drm/xe/xe_exec_queue_types.h | 7 ++ drivers/gpu/drm/xe/xe_hw_engine.h | 9 +++ include/uapi/drm/xe_drm.h | 12 +++ 6 files changed, 120 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug +10 -0
@@ -24,6 +24,16 @@ Description: RW. Controls whether the EU debugger interface is armed for have to close them or be terminated. A connection shows up as an "anon_inode:[xe_eudebug]" entry under /proc/<pid>/fd. + Once enabled, any client with access to the render node can + also create debuggable exec queues + (DRM_XE_EXEC_QUEUE_SET_PROPERTY_EUDEBUG), whether or not a + debugger is attached. While such a queue executes, the other + render and compute engines of its tile are kept idle + (runalone), and as its preemption timeout is infinite it is + not reset if it does not yield the engine when preempted. + Work from other clients on those engines can therefore be + held off for as long as such a queue keeps running. + Each connection allocates about 4 MiB of kernel memory for its event queue, held until the connection is closed. The number of connections is not limited beyond the file
drivers/gpu/drm/xe/xe_exec_queue.c +80 -1
117 lines not on this page · raw message
drivers/gpu/drm/xe/xe_exec_queue.h +2 -0
@@ -162,4 +162,6 @@ int xe_exec_queue_contexts_hwsp_rebase(struct xe_exec_queue *q, void *scratch);struct xe_lrc *xe_exec_queue_lrc (struct xe_exec_queue *q);struct xe_lrc *xe_exec_queue_get_lrc (struct xe_exec_queue *q,u16 idx); +bool xe_exec_queue_is_debuggable (struct xe_exec_queue *q); +#endif
drivers/gpu/drm/xe/xe_exec_queue_types.h +7 -0
@@ -155,6 +155,13 @@ struct xe_exec_queue {/** @ban_reason: Bitmask of ban reasons (DRM_XE_EXEC_QUEUE_BAN_REASON_*) */ atomic_t ban_reason; +/** +* @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 {/** @execlist: execlist backend specific state for exec queue */ struct xe_execlist_exec_queue *execlist;
drivers/gpu/drm/xe/xe_hw_engine.h +9 -0
@@ -78,4 +78,13 @@ enum xe_force_wake_domains xe_hw_engine_to_fw_domain(struct xe_hw_engine *hwe);u32 xe_hw_engine_mmio_read32 (struct xe_hw_engine *hwe,struct xe_reg reg); +static inline bool xe_engine_supports_eudebug (const enum xe_engine_class ec) +{ +if (ec ==XE_ENGINE_CLASS_COMPUTE || + ec ==XE_ENGINE_CLASS_RENDER ) +return true; + +return false; +} +#endif
include/uapi/drm/xe_drm.h +12 -0
@@ -1396,6 +1396,16 @@ struct drm_xe_vm_get_property {* - %DRM_XE_EXEC_QUEUE_SET_DISABLE_STATE_CACHE_PERF_FIX - Set the queue to * enable render color cache keying on BTP+BTI instead of just BTI * (only valid for render queues). +* - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_EUDEBUG - Make the queue debuggable +* by an EU debugger. The queue runs in runalone mode, one engine at +* a time, with a preemption timeout of 0. Fails with -EINVAL unless +* the value is exactly %DRM_XE_EXEC_QUEUE_EUDEBUG_FLAG_ENABLE and the +* queue is a width 1 render or compute queue on a VM created with +* %DRM_XE_VM_CREATE_FLAG_FAULT_MODE, +* not combined with %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE or +* %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP. Fails with +* -EOPNOTSUPP if the kernel is built without CONFIG_DRM_XE_EUDEBUG, +* and with -EPERM if eudebug is not enabled through sysfs. * * The example below shows how to use &struct drm_xe_exec_queue_create to create * a simple exec_queue (no parallel submission) of class
@@ -1443,6 +1453,8 @@ struct drm_xe_exec_queue_create {#define DRM_XE_MULTI_GROUP_CREATE (1ull << 63)#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_QUEUE_PRIORITY 5#define DRM_XE_EXEC_QUEUE_SET_DISABLE_STATE_CACHE_PERF_FIX 6 +#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_EUDEBUG 7 +#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.53.0
PATCH 8/20 drm/xe/eudebug: Introduce exec_queue events
In reply to Mika KuoppalaFrom: Dominik Grzegorzek <[email protected]>
Add events to inform the debugger about the creation and destruction of exec_queues. Use user engine class types instead of the internal xe_engine_class enum in exec_queue events. During discovery, only advertise exec_queues with render or compute class, excluding others.
v2: - Only track long running queues
- Checkpatch (Tilak)
v3: __counted_by added
v4: - use helpers for filtering engines (Mika)
v5: - fix lrc handles memcpy size bug (Mika)
v6: - lookup for create event (Sashiko)
- defer engine class lookup (Sashiko)
- avoid uninitialized read on adding handle (Sashiko)
- too strict warn on q->width check (Sashiko)
- create eudebug eq event early (Claude)
- dont drop session if vm is already gone (Claude)
v7: - lookups under the debugger lock (Mika)
--- Documentation/gpu/xe/xe_eudebug.rst | 3 + drivers/gpu/drm/xe/xe_eudebug.c | 282 +++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_eudebug.h | 7 + drivers/gpu/drm/xe/xe_eudebug_types.h | 6 +- drivers/gpu/drm/xe/xe_exec_queue.c | 8 +- include/uapi/drm/xe_drm_eudebug.h | 31 +++ 6 files changed, 330 insertions(+), 7 deletions(-)
Documentation/gpu/xe/xe_eudebug.rst +3 -0
@@ -65,3 +65,6 @@ Resource Event Types .. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h :identifiers: drm_xe_eudebug_event_vm + +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_event_exec_queue
drivers/gpu/drm/xe/xe_eudebug.c +278 -4
315 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +7 -0
@@ -14,6 +14,7 @@ struct drm_file;struct xe_device ;struct xe_file ;struct xe_vm ; +struct xe_exec_queue ;struct xe_eudebug ;#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG )
@@ -49,6 +50,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,
@@ -64,6 +68,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 /* _XE_EUDEBUG_H_ */
drivers/gpu/drm/xe/xe_eudebug_types.h +4 -2
@@ -31,7 +31,7 @@ enum xe_eudebug_cap_state { XE_EUDEBUG_CAP_ENABLED, }; -#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_VM +#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE/** * struct xe_eudebug_handle - eudebug resource handle
@@ -62,7 +62,9 @@ struct xe_eudebug_resource { };#define XE_EUDEBUG_RES_TYPE_VM 0 -#define XE_EUDEBUG_RES_TYPE_COUNT (XE_EUDEBUG_RES_TYPE_VM + 1) +#define XE_EUDEBUG_RES_TYPE_EXEC_QUEUE 1 +#define XE_EUDEBUG_RES_TYPE_LRC 2 +#define XE_EUDEBUG_RES_TYPE_COUNT (XE_EUDEBUG_RES_TYPE_LRC + 1)/** * struct xe_eudebug - Top level struct for eudebug: the connection
drivers/gpu/drm/xe/xe_exec_queue.c +7 -1
@@ -1548,10 +1548,14 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,if (eci[0 ].engine_class !=DRM_XE_ENGINE_CLASS_VM_BIND )xe_vm_add_exec_queue (vm, q); +xe_eudebug_exec_queue_create (xef, q); +/* user id alloc must always be last in ioctl to prevent UAF */ err =xa_alloc (&xef->exec_queue.xa, &id, q, xa_limit_32b,GFP_KERNEL ); -if (err) +if (err) { +xe_eudebug_exec_queue_destroy (xef, q); goto del_hw_engine_group; + } args->exec_queue_id = id;
@@ -1736,6 +1740,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 +31 -0
@@ -78,6 +78,7 @@ struct drm_xe_eudebug_event {#define DRM_XE_EUDEBUG_EVENT_NONE 0#define DRM_XE_EUDEBUG_EVENT_READ 1#define DRM_XE_EUDEBUG_EVENT_VM 2 +#define DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE 3/** @flags: Flags */ __u16 flags;
@@ -124,6 +125,36 @@ struct drm_xe_eudebug_event_vm {__u64 vm_handle; }; +/** +* struct drm_xe_eudebug_event_exec_queue - Exec Queue resource event +* +* Resource creation/destruction event for an Exec Queue +*/ +struct drm_xe_eudebug_event_exec_queue { +/** @base: base event */ +struct drm_xe_eudebug_event base; + +/** +* @vm_handle: the vm handle this exec queue belongs to, or 0 if the +* vm was destroyed before this event. A vm can be destroyed while +* its exec queues live on, so a destroy event can carry 0 where the +* create event carried the vm handle. +*/ +__u64 vm_handle; + +/** @exec_queue_handle: unique handle for this exec queue */ +__u64 exec_queue_handle; + +/** @engine_class: engine class, a %DRM_XE_ENGINE_CLASS_* value */ +__u32 engine_class; + +/** @width: width of exec queue, how many lrcs (handles) it has */ +__u32 width; + +/** @lrc_handle: array of lrc handles */ + __u64 lrc_handle[] __counted_by(width); +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 08/20] drm/xe/eudebug: Introduce exec_queue events
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/xe/eudebug: discover_client() counts non-debuggable queues in eq_count --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/xe/eudebug: discover_client() counts non-debuggable queues in eq_count
--
commit 926a26106604e590716ee8ab1001dab4ed5f0566
Author: Dominik Grzegorzek <[email protected]>
drm/xe/eudebug: Introduce exec_queue events
This commit adds eudebug resource creation and destruction events for debuggable render and compute exec queues, both during live ioctls and when discovering an existing client's resources.
Quoted 4 lines
drivers/gpu/drm/xe/xe_eudebug.c +0
-0
[ ... ]
Quoted 65 lines
drivers/gpu/drm/xe/xe_eudebug.c +48
-1+void xe_eudebug_exec_queue_create (struct xe_file *xef,struct xe_exec_queue *q) +{ +struct xe_eudebug *d; +int err; + +if (!xe_engine_supports_eudebug (q->class)) +return ; + + d =xe_eudebug_get (xef); +if (!d) +return ; + + err =exec_queue_create_event (d, xef, q); +if (err) +xe_eudebug_disconnect (d, err); + +xe_eudebug_put (d); +} + +void xe_eudebug_exec_queue_destroy (struct xe_file *xef,struct xe_exec_queue *q) +{ +struct xe_eudebug *d; +int err; + +if (!xe_engine_supports_eudebug (q->class)) +return ; + + d =xe_eudebug_get (xef); +if (!d) +return ; + + err =exec_queue_destroy_event (d, xef, q); +if (err) +xe_eudebug_disconnect (d, err); + +xe_eudebug_put (d); +} +/* * All the relevant ioctls that manipulate the xe_file resources eudebug * cares about are gated behind down_read(&xef->eudebug.ioctl_lock). The @@ -807,9 +1069,10 @@ void xe_eudebug_vm_destroy(struct xe_file *xef, struct xe_vm *vm)*/ static int discover_client (struct xe_eudebug *d,struct xe_file *xef) { +struct xe_exec_queue *q;struct xe_vm *vm;unsigned long i; -unsigned int vm_count =0 ; +unsigned int vm_count =0 , eq_count =0 ;int err =0 ;lockdep_assert_held_write (&xef->eudebug.ioctl_lock);@@ -828,10 +1091,21 @@ static int discover_client(struct xe_eudebug *d, struct xe_file *xef) vm_count++; } +xa_for_each (&xef->exec_queue.xa, i, q) { +if (!xe_engine_supports_eudebug (q->class)) +continue ; + + err =exec_queue_create_event (d, xef, q); +if (err) + goto out; +
drivers/gpu/drm/xe/xe_eudebug.c static int discover_client(struct xe_eudebug *d, struct xe_file *xef) · line 1108
Quoted 10 lines
drivers/gpu/drm/xe/xe_eudebug.c +6
-3+ eq_count++; + } + out: -if (vm_count) -eu_dbg (d,"Discovery found %u vms" , - vm_count); +if (vm_count || eq_count) +eu_dbg (d,"Discovery found %u vms, %u exec_queues" , + vm_count, eq_count);
[Severity: Low]
Does discover_client() count non-debuggable render and compute queues in eq_count?
exec_queue_create_event() returns 0 without emitting an event when !xe_exec_queue_is_debuggable(q), so any render or compute queue created without DRM_XE_EXEC_QUEUE_SET_PROPERTY_EUDEBUG still increments eq_count. Checking xe_exec_queue_is_debuggable(q) in discover_client(), as well as at the top of xe_eudebug_exec_queue_create() and xe_eudebug_exec_queue_destroy(), would also avoid taking and dropping the debugger reference for non-debuggable queues. Finally, the kernel-doc for struct drm_xe_eudebug_event_exec_queue in include/uapi/drm/xe_drm_eudebug.h could mention that only queues with DRM_XE_EXEC_QUEUE_SET_PROPERTY_EUDEBUG are reported, matching struct drm_xe_eudebug_event_vm.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH 9/20 drm/xe/eudebug: Mark guc contexts as debuggable
In reply to Mika KuoppalaInform the GuC which contexts are debuggable, as their handling differs from ordinary contexts.
v2: void return, use xe_gt_dbg, no need for lrc (Matt)
v3: add the workaround enabling (Daniele)
v4: version needed to 70.49.4
v5: bail out early before registering eq (Daniele)
v6: export the guc action for future (Mika)
v7: remove redundant xe_gt_info (Sashiko)
--- drivers/gpu/drm/xe/abi/guc_actions_abi.h | 5 ++++ drivers/gpu/drm/xe/abi/guc_klvs_abi.h | 1 + drivers/gpu/drm/xe/xe_exec_queue.c | 5 ++++ drivers/gpu/drm/xe/xe_guc.c | 15 +++++++++++ drivers/gpu/drm/xe/xe_guc.h | 6 +++++ drivers/gpu/drm/xe/xe_guc_ads.c | 5 ++++ drivers/gpu/drm/xe/xe_guc_submit.c | 34 ++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_wa_oob.rules | 2 ++ include/uapi/drm/xe_drm.h | 5 ++-- 9 files changed, 76 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/abi/guc_actions_abi.h +5 -0
@@ -162,6 +162,7 @@ enum xe_guc_action {XE_GUC_ACTION_NOTIFY_FLUSH_LOG_BUFFER_TO_FILE =0x8003 ,XE_GUC_ACTION_NOTIFY_CRASH_DUMP_POSTED =0x8004 ,XE_GUC_ACTION_NOTIFY_EXCEPTION =0x8005 , +XE_GUC_ACTION_EU_KERNEL_DEBUG =0x8006 ,XE_GUC_ACTION_TEST_G2G_SEND =0xF001 ,XE_GUC_ACTION_TEST_G2G_RECV =0xF002 ,XE_GUC_ACTION_LIMIT
@@ -285,4 +286,8 @@ enum xe_guc_g2g_type {/* invalid type for XE_GUC_ACTION_NOTIFY_MEMORY_CAT_ERROR */ #define XE_GUC_CAT_ERR_TYPE_INVALID 0xdeadbeef +enum xe_guc_eu_kernel_debug_request_type { +XE_GUC_EU_KERNEL_DEBUG_ENABLE =0x3 , +}; +#endif
drivers/gpu/drm/xe/abi/guc_klvs_abi.h +1 -0
@@ -522,6 +522,7 @@ enum xe_guc_klv_ids {GUC_WA_KLV_WAKE_POWER_DOMAINS_FOR_OUTBOUND_MMIO =0x900a ,GUC_WA_KLV_RESET_BB_STACK_PTR_ON_VF_SWITCH =0x900b ,GUC_WA_KLV_RESTORE_UNSAVED_MEDIA_CONTROL_REG =0x900c , +GUC_WA_KLV_RESET_DEP_ENGINES_ON_DEBUG_CTX_SWITCH =0x900d ,GUC_WA_KLV_CLR_CS_INDIRECT_RING_STATE_IF_IDLE_AT_CTX_REG =0x900e ,GUC_WA_KLV_REMAP_RANGED_TLB_INV =0x900f , GUC_WA_KLV_IGNORE_MMIO_READ_SEM_TOKEN_64 = 0x9010,
drivers/gpu/drm/xe/xe_exec_queue.c +5 -0
@@ -21,6 +21,7 @@#include "xe_gt.h" #include "xe_gt_sriov_pf.h" #include "xe_gt_sriov_vf.h" +#include "xe_guc.h" #include "xe_hw_engine_class_sysfs.h" #include "xe_hw_engine_group.h" #include "xe_irq.h"
@@ -1058,6 +1059,7 @@ static int exec_queue_set_eudebug(struct xe_device *xe, struct xe_exec_queue *q, u64 value) {const u64 known_flags =DRM_XE_EXEC_QUEUE_EUDEBUG_FLAG_ENABLE ; +struct xe_guc *guc = &q->gt->uc.guc;if (XE_IOCTL_DBG (xe, !xe_engine_supports_eudebug (q->class)))return -EINVAL ;
@@ -1068,6 +1070,9 @@ static int exec_queue_set_eudebug(struct xe_device *xe, struct xe_exec_queue *q,if (XE_IOCTL_DBG (xe, !IS_ENABLED (CONFIG_DRM_XE_EUDEBUG )))return -EOPNOTSUPP ; +if (XE_IOCTL_DBG (xe, !xe_guc_has_debug_contexts (guc))) +return -EOPNOTSUPP ; +/* * The preemption timeout below is infinite, which is only safe where * no dma-fence waits for the queue to be preempted: a fault mode vm
drivers/gpu/drm/xe/xe_guc.c +15 -0
@@ -823,6 +823,13 @@ int xe_guc_init(struct xe_guc *guc)return 0 ; } +if (IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) &&XE_GT_WA (gt,14022766366 ) && + !xe_guc_has_debug_contexts (guc)) +xe_gt_info (gt,"eudebug needs GuC version %u.%u.%u or greater\n" , +XE_GUC_VER_DEBUG_CONTEXTS_MAJOR , +XE_GUC_VER_DEBUG_CONTEXTS_MINOR , +XE_GUC_VER_DEBUG_CONTEXTS_PATCH ); + ret =xe_guc_log_init (&guc->log);if (ret) goto out;
@@ -1959,6 +1966,14 @@ u16 xe_hwe_guc_logical_instance(struct xe_hw_engine *hwe)return hwe->logical_instance; } +bool xe_guc_has_debug_contexts (struct xe_guc *guc) +{ +return GUC_FIRMWARE_VER_AT_LEAST (guc, +XE_GUC_VER_DEBUG_CONTEXTS_MAJOR , +XE_GUC_VER_DEBUG_CONTEXTS_MINOR , +XE_GUC_VER_DEBUG_CONTEXTS_PATCH ); +} +#if IS_ENABLED (CONFIG_DRM_XE_KUNIT_TEST )#include "tests/xe_guc_g2g_test.c" #endif
drivers/gpu/drm/xe/xe_guc.h +6 -0
@@ -29,6 +29,11 @@ #define GUC_FIRMWARE_VER_AT_LEAST(guc, ver...) \ xe_guc_fw_version_at_least((guc), MAKE_GUC_VER_ARGS(ver)) +/* Lowest GuC version that knows how to handle debuggable contexts */ +#define XE_GUC_VER_DEBUG_CONTEXTS_MAJOR 70 +#define XE_GUC_VER_DEBUG_CONTEXTS_MINOR 49 +#define XE_GUC_VER_DEBUG_CONTEXTS_PATCH 4 +struct drm_printer ;struct xe_gt ;
@@ -66,6 +71,7 @@ int xe_guc_start(struct xe_guc *guc);void xe_guc_wedge_declare (struct xe_guc *guc);bool xe_guc_using_main_gamctrl_queues (struct xe_guc *guc);bool xe_guc_has_paging_engine (struct xe_guc *guc); +bool xe_guc_has_debug_contexts (struct xe_guc *guc);#if IS_ENABLED (CONFIG_DRM_XE_KUNIT_TEST )int xe_guc_g2g_test_notification (struct xe_guc *guc,u32 *payload,u32 len);
drivers/gpu/drm/xe/xe_guc_ads.c +5 -0
@@ -402,6 +402,11 @@ static void guc_waklv_init(struct xe_guc_ads *ads) GUC_FEATURE_KLV_DISABLE_MULTI_QUEUE); } +if (IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) &&XE_GT_WA (gt,14022766366 ) && +xe_guc_has_debug_contexts (>->uc.guc)) +guc_waklv_enable (ads,NULL ,0 , &offset, &remain, +GUC_WA_KLV_RESET_DEP_ENGINES_ON_DEBUG_CTX_SWITCH ); + size =guc_ads_waklv_size (ads) - remain;if (!size)return ;
drivers/gpu/drm/xe/xe_guc_submit.c +34 -0
@@ -1023,6 +1023,37 @@ static u32 xe_hwe_guc_logical_to_submit_mask(struct xe_hw_engine *hwe, u32 logicreturn logical_mask; } +static int guc_action_eu_kernel_debug (struct xe_guc *guc,u32 id,u32 cmd) +{ +const u32 action[] = { +XE_GUC_ACTION_EU_KERNEL_DEBUG , + id, + cmd, +0 ,/* reserved */ + }; + +return xe_guc_ct_send (&guc->ct, action, +ARRAY_SIZE (action),0 ,0 ); +} + +static void set_eu_kernel_debug (struct xe_exec_queue *q) +{ +struct xe_guc *guc =exec_queue_to_guc (q); +struct xe_gt *gt =guc_to_gt (guc); +int ret; + + ret =guc_action_eu_kernel_debug (guc, q->guc->id, +XE_GUC_EU_KERNEL_DEBUG_ENABLE ); + +if (ret) +xe_gt_err_ratelimited (gt, +"GuC ctx=%u debug enabling failed with %d\n" , + q->guc->id, ret); +else +xe_gt_dbg (gt, +"GuC ctx=%u debug enable requested\n" , q->guc->id); +} +static void register_exec_queue (struct xe_exec_queue *q,int ctx_type) {struct xe_guc *guc =exec_queue_to_guc (q);
@@ -1084,6 +1115,9 @@ static void register_exec_queue(struct xe_exec_queue *q, int ctx_type)if (xe_exec_queue_is_multi_queue_secondary (q))guc_exec_queue_send_cgp_sync (q,CGP_SYNC_REGISTRATION ); + +if (xe_exec_queue_is_debuggable (q)) +set_eu_kernel_debug (q); }static u32 wq_space_until_wrap (struct xe_exec_queue *q)
drivers/gpu/drm/xe/xe_wa_oob.rules +2 -0
@@ -78,3 +78,5 @@ MEDIA_VERSION_RANGE(1301, 3503), FUNC(xe_rtp_match_not_sriov_vf) 16030224309 GRAPHICS_VERSION_RANGE(3510, 3511) 14028709524 GRAPHICS_VERSION(3510) +14022766366 GRAPHICS_VERSION_RANGE(2001, 2004) + GRAPHICS_VERSION_RANGE(3000, 3005)
include/uapi/drm/xe_drm.h +3 -2
@@ -1404,8 +1404,9 @@ struct drm_xe_vm_get_property {* %DRM_XE_VM_CREATE_FLAG_FAULT_MODE, * not combined with %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE or * %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP. Fails with -* -EOPNOTSUPP if the kernel is built without CONFIG_DRM_XE_EUDEBUG, -* and with -EPERM if eudebug is not enabled through sysfs. +* -EOPNOTSUPP if the kernel is built without CONFIG_DRM_XE_EUDEBUG +* or the GuC does not support debug contexts, and with -EPERM if +* eudebug is not enabled through sysfs. * * The example below shows how to use &struct drm_xe_exec_queue_create to create * a simple exec_queue (no parallel submission) of class
Signature · 1 line
2.53.0
PATCH 10/20 drm/xe: Introduce ADD_DEBUG_DATA and REMOVE_DEBUG_DATA vm bind ops
In reply to Mika KuoppalaFrom: Christoph Manszewski <[email protected]>
Make it possible to add and remove per vm debug data, which can be used to annotate vm ranges (using pseudopaths) or to associate them with a file which can carry arbitrary debug data (e.g. binary instruction to code line mapping). The debug data is kept separate from the vmas. Each address can be associated with only one debug data entry i.e. debug data entries cannot overlap. Each entry is atomic, so the creation address and range have to be passed in order to remove it.
For debug data manipulation only the 'op' and 'extensions' fields from 'struct drm_xe_vm_bind_op' are used. All required parameters are passed through 'struct drm_xe_vm_bind_op_ext_debug_data' and a valid instance should be present in the extension chain pointed to by the 'extensions' field.
Debug data will be accessible through the eudebug event interface, introduced in the following patch. An alternative way to access debug data using debugfs, without relying on eudebug, will be proposed as a follow-up to the eudebug series.
v2: enforce empty path on unmap (Joonas, Mika)
v3: - fix overflow, deny zero ranges, null str for empty check (Sashiko)
- fix TOCTOUs and list handling issues (Sashiko)
v4: - check full path for zero, overflow check (Sashiko)
- don't unwind failed extensions, use op commit (Sashiko)
- restore removes by relink, remove fallible alloc (Sashiko)
--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_debug_data.c | 388 +++++++++++++++++++++++ drivers/gpu/drm/xe/xe_debug_data.h | 22 ++ drivers/gpu/drm/xe/xe_debug_data_types.h | 26 ++ drivers/gpu/drm/xe/xe_vm.c | 226 ++++++++++++- drivers/gpu/drm/xe/xe_vm_types.h | 31 ++ include/uapi/drm/xe_drm.h | 88 ++++- 7 files changed, 777 insertions(+), 5 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_debug_data.c create mode 100644 drivers/gpu/drm/xe/xe_debug_data.h create mode 100644 drivers/gpu/drm/xe/xe_debug_data_types.h
drivers/gpu/drm/xe/Makefile +1 -0
@@ -36,6 +36,7 @@ xe-y += xe_bb.o \ xe_bo.o \ xe_bo_evict.o \ xe_cpu_bind.o \ + xe_debug_data.o \ xe_dep_scheduler.o \ xe_devcoredump.o \ xe_device.o \
drivers/gpu/drm/xe/xe_debug_data.c new file +388 -0
388 lines not on this page · raw message
drivers/gpu/drm/xe/xe_debug_data.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2025 Intel Corporation +*/ + +#ifndef _XE_DEBUG_DATA_H_ +#define _XE_DEBUG_DATA_H_ + +#include <linux/types.h> + +struct drm_gpuva_ops ; +struct xe_vm ; +struct xe_vma_op ; + +const char *xe_debug_data_pseudo_path_to_string (u64 pseudopath); +int xe_debug_data_check_extension (struct xe_vm *vm,u32 operation,u64 extension); +int xe_debug_data_process_extension (struct xe_vm *vm,struct drm_gpuva_ops *ops,u32 operation, +u64 extension); +int xe_debug_data_op_unwind (struct xe_vm *vm,struct xe_vma_op *vma_op); +void xe_debug_data_destroy (struct xe_vm *vm); + +#endif /* _XE_DEBUG_DATA_H_ */
drivers/gpu/drm/xe/xe_debug_data_types.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ + +#ifndef _XE_DEBUG_DATA_TYPES_H_ +#define _XE_DEBUG_DATA_TYPES_H_ + +#include <linux/list.h> +#include <linux/stddef.h> +#include <linux/types.h> + +struct xe_debug_data { +struct list_head link; +u64 addr; +u64 range; +u64 flags; +u64 offset; +union { +u64 pseudopath; +/* NUL terminated, allocated to the length of the path */ + DECLARE_FLEX_ARRAY(char, pathname); + }; +}; + +#endif /* _XE_DEBUG_DATA_TYPES_H_ */
drivers/gpu/drm/xe/xe_vm.c +223 -3
372 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm_types.h +31 -0
@@ -15,6 +15,7 @@#include <linux/mmu_notifier.h> #include <linux/scatterlist.h> +#include "xe_debug_data_types.h" #include "xe_device_types.h" #include "xe_pt_types.h" #include "xe_range_fence.h"
@@ -423,6 +424,15 @@ struct xe_vm {bool batch_invalidate_tlb;/** @xef: Xe file handle for tracking this VM's drm client */ struct xe_file *xef; + +/** @debug_data: track debug_data mapped to vm */ +struct { +/** @list: list of debug data items for this vm */ +struct list_head list; + +/** @lock: guards access to the debug data list */ +struct mutex lock; + } debug_data; };/** struct xe_vma_op_map - VMA map operation */
@@ -496,6 +506,21 @@ struct xe_vma_op_prefetch_range {struct drm_pagemap *dpagemap; }; +/** struct xe_vma_op_modify_debug_data - debug data altering operation */ +struct xe_vma_op_modify_debug_data { +/** +* @added: entry published on vm->debug_data.list, owned by the +* list and only borrowed here. Cleared once unwind frees it. +*/ +struct xe_debug_data *added; + +/** +* @removed: detached from the list. Relinked if the ioctl is unwound, +* freed with the op otherwise. +*/ +struct xe_debug_data *removed; +}; +/** enum xe_vma_op_flags - flags for VMA operation */ enum xe_vma_op_flags {/** @XE_VMA_OP_COMMITTED: VMA operation committed */
@@ -512,6 +537,10 @@ enum xe_vma_subop {XE_VMA_SUBOP_MAP_RANGE ,/** @XE_VMA_SUBOP_UNMAP_RANGE: Unmap range */ XE_VMA_SUBOP_UNMAP_RANGE , +/** @XE_VMA_SUBOP_ADD_DEBUG_DATA: Add debug data to vm */ +XE_VMA_SUBOP_ADD_DEBUG_DATA , +/** @XE_VMA_SUBOP_REMOVE_DEBUG_DATA: Remove debug data from vm */ + XE_VMA_SUBOP_REMOVE_DEBUG_DATA, };/** struct xe_vma_op - VMA operation */
@@ -540,6 +569,8 @@ struct xe_vma_op {struct xe_vma_op_unmap_range unmap_range;/** @prefetch_range: VMA prefetch range operation specific data */ struct xe_vma_op_prefetch_range prefetch_range; +/** @modify_debug_data: debug_data operation specific data */ +struct xe_vma_op_modify_debug_data modify_debug_data; }; };
include/uapi/drm/xe_drm.h +86 -2
124 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 11/20 drm/xe/eudebug: Introduce vm bind and vm bind debug data events
In reply to Mika KuoppalaFrom: Christoph Manszewski <[email protected]>
Add events to track the bind ioctl and associated debug data add and remove operations, as a single bind can involve multiple operations and may fail mid-process.
Add a bind event to signal to the debugger when a bind operation is executed. Further add debug data add and remove operations so the debugger can keep track of regions where they reside. The bind event is important as we will want to include the ufence event later in the series and tie it to this bind.
Only deliver bind+operations to the debugger if the vm bind op execution chain succeeds.
v2: - avoid sending bind if there are no operations (Mika)
- documentation (Christoph, Mika)
v3: - use removed field dd for removing
v4: - fix potential null deref (Sashiko)
v5: - skip non lr vms in discovery (Sashiko)
v6: - look up the debugger under a spinlock of its own instead of
eudebug.lock, which the vm bind cannot take under the reservation once eudebug enable checks for OA streams (lockdep) (Mika)
v7: - async disconnect under the debugger lock, wq moved here (Mika)
v8: - document the async disconnect window (Sashiko)
--- Documentation/gpu/xe/xe_eudebug.rst | 6 + drivers/gpu/drm/xe/xe_device.c | 1 + drivers/gpu/drm/xe/xe_device_types.h | 11 + drivers/gpu/drm/xe/xe_eudebug.c | 344 +++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_eudebug.h | 7 + drivers/gpu/drm/xe/xe_eudebug_types.h | 12 +- drivers/gpu/drm/xe/xe_vm.c | 4 + include/uapi/drm/xe_drm_eudebug.h | 98 +++++++- 8 files changed, 470 insertions(+), 13 deletions(-)
Documentation/gpu/xe/xe_eudebug.rst +6 -0
@@ -68,3 +68,9 @@ Resource Event Types .. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h :identifiers: drm_xe_eudebug_event_exec_queue + +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_event_vm_bind + +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_event_vm_bind_op_debug_data
drivers/gpu/drm/xe/xe_device.c +1 -0
@@ -119,6 +119,7 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG )init_rwsem (&xef->eudebug.ioctl_lock); +spin_lock_init (&xef->eudebug.lock);#endif file->driver_priv = xef;
drivers/gpu/drm/xe/xe_device_types.h +11 -0
@@ -639,6 +639,9 @@ struct xe_device {/** @eudebug.lock: protects the eudebug state of this device */ struct mutex lock; + +/** @eudebug.wq: used for the async session disconnect */ + struct workqueue_struct *wq; } eudebug;#endif
@@ -736,6 +739,14 @@ struct xe_file {/** @eudebug.debugger: the debugger connection into this xe_file */ struct xe_eudebug *debugger; +/** +* @eudebug.lock: protects @eudebug.debugger. Writers hold +* xe->eudebug.lock as well, lookups take only this, so that +* they nest inside any lock the caller holds, the vm +* reservation of a vm bind included. +*/ +spinlock_t lock; +/** * @eudebug.ioctl_lock: excludes the ioctls that mutate the * eudebug visible resources of this client, so that a writer
drivers/gpu/drm/xe/xe_eudebug.c +333 -11
455 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +7 -0
@@ -11,10 +11,14 @@struct drm_device ;struct drm_file ; +struct xe_debug_data ;struct xe_device ;struct xe_file ;struct xe_vm ;struct xe_exec_queue ; +struct xe_vma ; +struct xe_vma_ops ; +struct xe_user_fence ;struct xe_eudebug ;#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG )
@@ -53,6 +57,8 @@ 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_bind_execute (struct xe_vm *vm,struct xe_vma_ops *ops); +#else static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
@@ -71,6 +77,7 @@ 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_bind_execute (struct xe_vm *vm,struct xe_vma_ops *ops) { }#endif /* CONFIG_DRM_XE_EUDEBUG */ #endif /* _XE_EUDEBUG_H_ */
drivers/gpu/drm/xe/xe_eudebug_types.h +11 -1
@@ -12,6 +12,7 @@#include <linux/rhashtable.h> #include <linux/sizes.h> #include <linux/wait.h> +#include <linux/workqueue.h> #include <linux/xarray.h> #include <uapi/drm/xe_drm_eudebug.h>
@@ -31,7 +32,7 @@ enum xe_eudebug_cap_state { XE_EUDEBUG_CAP_ENABLED, }; -#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_EXEC_QUEUE +#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_VM_BIND_OP_DEBUG_DATA/** * struct xe_eudebug_handle - eudebug resource handle
@@ -111,6 +112,15 @@ struct xe_eudebug {/** @session: session number for this connection (for logs) */ u64 session; +/** +* @disconnect_work: detaches the session for a producer that cannot +* take xe->eudebug.lock, see xe_eudebug_disconnect_async() +*/ +struct work_struct disconnect_work; + +/** @disconnect_err: error @disconnect_work detaches with, first one wins */ +int disconnect_err; +/** @events: kfifo queue of to-be-delivered events */ struct {#define XE_EUDEBUG_EVENT_MAX_SIZE SZ_64K
drivers/gpu/drm/xe/xe_vm.c +4 -0
@@ -3839,6 +3839,10 @@ static struct dma_fence *vm_bind_ioctl_ops_execute(struct xe_vm *vm,xe_vm_set_validation_exec (vm, &exec); fence =ops_execute (vm, vops);xe_vm_set_validation_exec (vm,NULL ); + +if (!IS_ERR (fence) ||PTR_ERR (fence) == -ENODATA ) +xe_eudebug_vm_bind_execute (vm, vops); +if (IS_ERR (fence)) {if (PTR_ERR (fence) == -ENODATA )vm_bind_ioctl_ops_fini (vm, vops,NULL );
include/uapi/drm/xe_drm_eudebug.h +97 -1
121 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 11/20] drm/xe/eudebug: Introduce vm bind and vm bind debug data events
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/xe/eudebug: missed bind events in xe_vm_bind_ioctl() on prefetch -ENODATA --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/xe/eudebug: missed bind events in xe_vm_bind_ioctl() on prefetch -ENODATA
--
commit cd195b3b0e2ac13dc8ba630c0ab3fbbd171bde93
Author: Christoph Manszewski <[email protected]>
drm/xe/eudebug: Introduce vm bind and vm bind debug data events
This commit adds eudebug VM bind and debug data operation events to notify an attached debugger when VM bind debug data operations are executed or discovered.
Quoted 5 lines
drivers/gpu/drm/xe/xe_vm.c +0
-0
drivers/gpu/drm/xe/xe_vm.c static struct dma_fence *vm_bind_ioctl_ops_execute(struct xe_vm *vm, · line 3819
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +4
-0@@ -3810,6 +3810,10 @@ static struct dma_fence *vm_bind_ioctl_ops_execute(struct xe_vm *vm,xe_vm_set_validation_exec (vm, &exec); fence =ops_execute (vm, vops);xe_vm_set_validation_exec (vm,NULL ); + +if (!IS_ERR (fence) ||PTR_ERR (fence) == -ENODATA ) +xe_eudebug_vm_bind_execute (vm, vops); +if (IS_ERR (fence)) {if (PTR_ERR (fence) == -ENODATA )vm_bind_ioctl_ops_fini (vm, vops,NULL );
[Severity: Medium]
Can a multi-operation VM bind skip xe_eudebug_vm_bind_execute() while still leaving debug data changes committed?
In xe_vm_bind_ioctl(), debug data add and remove operations are committed to vm->debug_data.list during vm_bind_ioctl_process_user_extensions(). If the same bind array also includes an SVM prefetch operation and vm_bind_ioctl_ops_prefetch_ranges() returns -ENODATA (for example, when prefetch_thread_func() hits a VRAM allocation failure or xe_svm_range_get_pages() returns -EFAULT), xe_vm_bind_ioctl() jumps to unwind_ops without calling vm_bind_ioctl_ops_execute():
drivers/gpu/drm/xe/xe_vm.c:xe_vm_bind_ioctl() {
...
err = vm_bind_ioctl_ops_prefetch_ranges(vm, &vops);
if (err)
goto unwind_ops;
fence = vm_bind_ioctl_ops_execute(vm, &vops);
...
unwind_ops:
if (err && err != -ENODATA)
vm_bind_ioctl_ops_unwind(vm, ops, args->num_binds);
xe_vma_ops_fini(&vops);
...
free_syncs:
if (err == -ENODATA)
err = vm_bind_ioctl_signal_fences(vm, q, syncs, num_syncs);
...
}Because -ENODATA skips vm_bind_ioctl_ops_unwind(), signals the out-fences, and returns 0 to userspace, the debug data changes stay on vm->debug_data.list without delivering the bind and debug data events to the debugger.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
PATCH 12/20 drm/xe/eudebug: Add ufence events with acks
In reply to Mika KuoppalaWhen the vma is in place, the debugger needs to intercept before userspace proceeds with the workload, for example to install a breakpoint in an EU shader.
If the ufence is part of a bind sequence, attach the debugger in xe_user_fence. When the ufence signal is about to be delivered, check if this ufence needs to be tracked by the debugger. If so, stall the delivery of the ufence signal until the debugger has acked the ufence (event), with the ack ioctl.
v2: - return err instead of 0 to guarantee signalling (Dominik)
- checkpatch (Tilak)
- Kconfig (Mika, Andrzej)
- use lock instead of cmpxchg (Mika)
v4: - improve ref handling and no ufences nodebug binds
v5: - remove overzealous warn_on on bind_ref_seqno (Christoph)
- remove superfluous signalled (Mika)
- fix double free on bind sequence (Mika)
- Don't fill op fields if no debugger (Maciej)
v6: - rework to align with xe_eudebug_bind_execute()
v7: - fix setting signalled before debugger acks (Jan)
v8: - explicit debugger set and clears (Mika)
- take reference for tracking check (Mika)
- fix leak of ref in handle_ack (Mika)
v9: - enforce mbz on user_arg.type (Sashiko)
v10: - avoid double signal if not tracked (Sashiko)
- clear bind ref seqno if no debugger (Sashiko)
- add reserved field
- avoid referencing ack after dropping lock (Claude)
- clear bind ref if tracking fails (Claude)
- use GFP_KERNEL for ack allocation
- don't starve discovery wq (Claude)
v11: - clear bind ref if detached late (Sashiko)
v12: - drop the debugger ref when not tracking (review-prompts)
v13: - ack tree under the debugger lock (Mika)
v14: - ack and its event added under one lock (Sashiko)
--- Documentation/gpu/xe/xe_eudebug.rst | 9 + drivers/gpu/drm/xe/xe_eudebug.c | 391 +++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_eudebug.h | 9 + drivers/gpu/drm/xe/xe_eudebug_types.h | 9 +- drivers/gpu/drm/xe/xe_sync.c | 47 ++-- drivers/gpu/drm/xe/xe_sync.h | 3 + drivers/gpu/drm/xe/xe_sync_types.h | 29 +- include/uapi/drm/xe_drm_eudebug.h | 117 +++++++- 8 files changed, 573 insertions(+), 41 deletions(-)
Documentation/gpu/xe/xe_eudebug.rst +9 -0
@@ -74,3 +74,12 @@ Resource Event Types .. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h :identifiers: drm_xe_eudebug_event_vm_bind_op_debug_data + +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_event_vm_bind_ufence + +Acknowledging Events +-------------------- + +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_ack
drivers/gpu/drm/xe/xe_eudebug.c +387 -4
487 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +9 -0
@@ -59,6 +59,10 @@ void xe_eudebug_exec_queue_destroy(struct xe_file *xef, struct xe_exec_queue *q)void xe_eudebug_vm_bind_execute (struct xe_vm *vm,struct xe_vma_ops *ops); +void xe_eudebug_ufence_init (struct xe_user_fence *ufence); +void xe_eudebug_ufence_fini (struct xe_user_fence *ufence); +bool xe_eudebug_ufence_track (struct xe_user_fence *ufence); +#else static inline int xe_eudebug_connect_ioctl(struct drm_device *dev,
@@ -78,6 +82,11 @@ static inline void xe_eudebug_exec_queue_create(struct xe_file *xef, struct xe_estatic inline void xe_eudebug_exec_queue_destroy (struct xe_file *xef,struct xe_exec_queue *q) { }static inline void xe_eudebug_vm_bind_execute (struct xe_vm *vm,struct xe_vma_ops *ops) { } + +static inline void xe_eudebug_ufence_init (struct xe_user_fence *ufence) { } +static inline void xe_eudebug_ufence_fini (struct xe_user_fence *ufence) { } +static inline bool xe_eudebug_ufence_track (struct xe_user_fence *ufence) {return false; } +#endif /* CONFIG_DRM_XE_EUDEBUG */ #endif /* _XE_EUDEBUG_H_ */
drivers/gpu/drm/xe/xe_eudebug_types.h +8 -1
@@ -9,6 +9,7 @@#include <linux/kfifo.h> #include <linux/kref.h> #include <linux/mutex.h> +#include <linux/rbtree.h> #include <linux/rhashtable.h> #include <linux/sizes.h> #include <linux/wait.h>
@@ -32,7 +33,7 @@ enum xe_eudebug_cap_state { XE_EUDEBUG_CAP_ENABLED, }; -#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_VM_BIND_OP_DEBUG_DATA +#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE/** * struct xe_eudebug_handle - eudebug resource handle
@@ -175,6 +176,12 @@ struct xe_eudebug {*/ atomic64_t seqno; } events; + +/** @acks: user fence acks tracked by this debugger */ +struct { +/** @acks.tree: pending acks by seqnos */ +struct rb_root tree; + } acks; };#endif /* _XE_EUDEBUG_TYPES_H_ */
drivers/gpu/drm/xe/xe_sync.c +28 -19
87 lines not on this page · raw message
drivers/gpu/drm/xe/xe_sync.h +3 -0
@@ -8,7 +8,9 @@#include "xe_sync_types.h" +struct dma_fence ;struct drm_syncobj ; +struct drm_xe_sync ;struct xe_device ;struct xe_exec_queue ;struct xe_file ;
@@ -45,5 +47,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 +24 -5
@@ -6,13 +6,32 @@ #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 { + /** @lock: guards access to eudebug struct members */ + 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;
include/uapi/drm/xe_drm_eudebug.h +105 -12
172 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 12/20] drm/xe/eudebug: Add ufence events with acks
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/xe/eudebug: use of destroyed eudebug.lock in xe_eudebug_detach() - [Low] drm/xe/eudebug…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/xe/eudebug: use of destroyed eudebug.lock in xe_eudebug_detach()
- [Low] drm/xe/eudebug: TOCTOU race in xe_eudebug_ack_event_ioctl() on detach
--
commit b38d3ecda4b8b7ae85aedf3b0af41c39cf303abb
Author: Mika Kuoppala <[email protected]>
drm/xe/eudebug: Add ufence events with acks
This commit adds DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE events and the DRM_XE_EUDEBUG_IOCTL_ACK_EVENT ioctl so that a debugger can stall user fence signalling on a VM bind with debug data until the event is acknowledged.
Quoted 4 lines
drivers/gpu/drm/xe/xe_eudebug.c +0
-0
[ ... ]
Quoted 3 lines
drivers/gpu/drm/xe/xe_eudebug.c +0
-0@@ -1199,6 +1330,191 @@ static int vm_bind_op_event(struct xe_eudebug *d,return err; }
[ ... ]
Quoted 5 lines
drivers/gpu/drm/xe/xe_eudebug.c +5
-0+static int track_ufence (struct xe_eudebug *d, +struct xe_user_fence *ufence, +u64 bind_ref_seqno, +bool *tracked) +{
[ ... ]
Quoted 28 lines
drivers/gpu/drm/xe/xe_eudebug.c +28
-0+/* +* The ack and the event asking for it go in under one lock, so the +* debugger cannot ack a fence it has not been told about. Once the +* lock is dropped the ack may already be gone, so it is not touched +* after that. +*/ +mutex_lock (&d->lock); + old =rb_find_add (&ack->rb_node, &d->acks.tree, ack_insert_cmp); +if (old) { +mutex_unlock (&d->lock); +xe_sync_ufence_put (ufence); +kfree (ack); +return -EEXIST ; + } + + *tracked = true; + + event =xe_eudebug_prepare_event (d,DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE , + seqno, flags, sz); + + e =cast_event (e, event); + e->vm_bind_ref_seqno = bind_ref_seqno; + + ret =xe_eudebug_queue_event (d, event); +mutex_unlock (&d->lock); + +return ret; +}
[ ... ]
Quoted 6 lines
drivers/gpu/drm/xe/xe_eudebug.c +6
-0+bool xe_eudebug_ufence_track (struct xe_user_fence *ufence) +{ +struct xe_eudebug *d; +u64 bind_ref_seqno; +bool tracked = false; +int ret;
[ ... ]
Quoted 13 lines
drivers/gpu/drm/xe/xe_eudebug.c +13
-0+if (xe_eudebug_is_detached (d)) { +/* Nothing will ack this fence any more */ +ufence_drop_debugger (ufence); +xe_eudebug_put (d); +return false; + } + + ret =track_ufence (d, ufence, bind_ref_seqno, &tracked); +if (ret) { +/* +* If we failed before the ack made it into the tree, the +* disconnect below has nothing to release for this fence. +*/
drivers/gpu/drm/xe/xe_eudebug.c static int vm_bind_op_event(struct xe_eudebug *d, · line 1516
Quoted 10 lines
drivers/gpu/drm/xe/xe_eudebug.c +10
-0+if (!tracked) +ufence_drop_debugger (ufence); + +xe_eudebug_disconnect (d, ret); + } + +xe_eudebug_put (d); + +return tracked; +}
[Severity: Medium]
Can xe_eudebug_ufence_track() lock a destroyed d->xe->eudebug.lock in xe_eudebug_detach()?
As noted above kick_ufence_worker(), user_fence_worker() runs on xe->ordered_wq, which xe_device_destroy() drains only after the drmm actions registered in xe_device_probe() have already run. One of those actions is xe_eudebug_lock_fini(), which destroys xe->eudebug.lock:
drivers/gpu/drm/xe/xe_eudebug.c:xe_eudebug_lock_fini() {
mutex_destroy(&to_xe_device(dev)->eudebug.lock);
}A user fence holds a reference to struct xe_eudebug in ufence->eudebug.debugger, but not a drm_device reference:
CPU0 (user_fence_worker) CPU1xe_eudebug_ufence_track()
xe_eudebug_is_detached(d)
-> false
xe_eudebug_release()
xe_eudebug_disconnect(d, 0)
drm_dev_put(&d->xe->drm)
...
xe_eudebug_lock_fini()
mutex_destroy(&xe->eudebug.lock)
xe_device_destroy()
destroy_workqueue(xe->ordered_wq)
track_ufence()
xe_eudebug_queue_event()
-> -ENOTCONN
xe_eudebug_disconnect(d, ret)
xe_eudebug_detach()
mutex_lock(&d->xe->eudebug.lock) <-- destroyed mutexWith lock debugging enabled, mutex_lock() warns on the destroyed mutex. If track_ufence() checked __xe_eudebug_is_detached(d) under d->lock before inserting ack into d->acks.tree, a racing detach would not need a second xe_eudebug_disconnect() call.
[ ... ]
Quoted 8 lines
drivers/gpu/drm/xe/xe_eudebug.c +4
-0@@ -1691,6 +2032,42 @@ static long xe_eudebug_read_event(struct xe_eudebug *d,return ret; } +static long +xe_eudebug_ack_event_ioctl (struct xe_eudebug *d, +const u64 arg) +{
[ ... ]
drivers/gpu/drm/xe/xe_eudebug.c static long xe_eudebug_read_event(struct xe_eudebug *d, · line 2069
Quoted 11 lines
drivers/gpu/drm/xe/xe_eudebug.c +11
-0+if (XE_IOCTL_DBG (xe,xe_eudebug_is_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 ; +}
[Severity: Low]
Can xe_eudebug_ack_event_ioctl() return -EINVAL instead of -ENOTCONN when racing with xe_eudebug_detach()?
xe_eudebug_is_detached() and remove_ack() take d->lock in separate critical sections. If xe_eudebug_detach() runs in between, it clears d->target.xef and empties d->acks.tree under d->lock, so remove_ack() finds nothing and the ioctl returns -EINVAL for a valid seqno instead of the documented -ENOTCONN. Checking __xe_eudebug_is_detached(d) inside remove_ack() under d->lock would avoid the race.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
PATCH 13/20 drm/xe/eudebug: Add vm open/pread/pwrite
In reply to Mika KuoppalaThe debugger needs access to the client's vm to read and write, for example to inspect ISA/ELF and set up breakpoints.
Add an ioctl to open the target vm with the debugger client and vm_handle, and hook up pread/pwrite support.
Open will take a 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 the 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)
- don't try to copy to user on zero bytes (Mika)
v4: - offset as unsigned long (Thomas)
- check XE_VMA_DESTROYED
v5: - drm_dev_put before releasing debugger (Mika)
v6: - stop flushing on first error (Mika)
v7: - deny access on debugger disconnect (Andrzej)
v8: - correct offset calc in ttm_bo_access (Sashiko)
- overzealous warn removed (Sashiko)
- check param.extensions (Sashiko)
- avoid hitting assert (Sashiko)
- fix detach race on open (Claude)
- build assert on ioctl cmd (Claude)
- reject >u32 on vm lookup (Claude)
- allow smaller vmallocs before fail
v9: - take runtime pm (Sashiko)
v10: - bound the fsync timeout (Sashiko)
v11: - no -EBUSY on discovery, lookup needs no eudebug.lock (Mika)
v12: - reject imported dma-bufs with -EINVAL (Sashiko)
--- Documentation/gpu/xe/xe_eudebug.rst | 6 + drivers/gpu/drm/xe/Makefile | 2 +- drivers/gpu/drm/xe/regs/xe_gt_regs.h | 23 + drivers/gpu/drm/xe/xe_device_types.h | 7 + drivers/gpu/drm/xe/xe_eudebug.c | 74 +++- drivers/gpu/drm/xe/xe_eudebug.h | 11 + drivers/gpu/drm/xe/xe_eudebug_vm.c | 610 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_eudebug_vm.h | 13 + drivers/gpu/drm/xe/xe_hw_engine.h | 5 + include/uapi/drm/xe_drm_eudebug.h | 69 ++- 10 files changed, 810 insertions(+), 10 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_eudebug_vm.c create mode 100644 drivers/gpu/drm/xe/xe_eudebug_vm.h
Documentation/gpu/xe/xe_eudebug.rst +6 -0
@@ -83,3 +83,9 @@ Acknowledging Events .. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h :identifiers: drm_xe_eudebug_ack + +VM Access +========= + +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_vm_open
drivers/gpu/drm/xe/Makefile +1 -1
@@ -165,7 +165,7 @@ xe-$(CONFIG_DRM_XE_GPUSVM) += xe_svm.o xe-$(CONFIG_DRM_GPUSVM) += xe_userptr.o # debugging shaders with gdb (eudebug) support -xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o +xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o xe_eudebug_vm.o # graphics hardware monitoring (HWMON) support xe-$(CONFIG_HWMON) += xe_hwmon.o
drivers/gpu/drm/xe/regs/xe_gt_regs.h +23 -0
@@ -657,6 +657,29 @@#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_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 FORCEWAKE_ACK_GT XE_REG(0x130044)/* Applicable for all FORCEWAKE_DOMAIN and FORCEWAKE_ACK_DOMAIN regs */
drivers/gpu/drm/xe/xe_device_types.h +7 -0
@@ -640,6 +640,13 @@ struct xe_device {/** @eudebug.lock: protects the eudebug state of this device */ struct mutex lock; +/** +* @eudebug.flush_lock: serializes the vm fsync() cache flushes, +* which share RCU_ASYNC_FLUSH and save and restore the engine +* idle messaging around it +*/ +struct mutex flush_lock; +/** @eudebug.wq: used for the async session disconnect */ struct workqueue_struct *wq; } eudebug;
drivers/gpu/drm/xe/xe_eudebug.c +69 -5
122 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +11 -0
@@ -37,10 +37,15 @@ struct xe_eudebug; ##__VA_ARGS__); \ } while (0) +#define eu_warn (d, fmt, ...) __eu_print(d, drm_warn, fmt, ##__VA_ARGS__)#define eu_dbg (d, fmt, ...) __eu_print(d, drm_dbg, fmt, ##__VA_ARGS__)#define xe_eudebug_assert (d, ...) xe_assert((d)->xe, ##__VA_ARGS__) +#define xe_eudebug_for_each_hw_engine (__hwe, __gt, __id) \ + for_each_hw_engine(__hwe, __gt, __id) \ + for_each_if(xe_hw_engine_has_eudebug(__hwe)) +int xe_eudebug_connect_ioctl (struct drm_device *dev,void *data,struct drm_file *file);
@@ -54,6 +59,12 @@ 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); +bool xe_eudebug_is_detached (struct xe_eudebug *d); + +void xe_eudebug_put (struct xe_eudebug *d); + +struct xe_vm *xe_eudebug_vm_get (struct xe_eudebug *d,u32 vm_id); +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);
drivers/gpu/drm/xe/xe_eudebug_vm.c new file +610 -0
610 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug_vm.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023-2025 Intel Corporation +*/ + +#ifndef _XE_EUDEBUG_VM_H_ +#define _XE_EUDEBUG_VM_H_ + +struct xe_eudebug ; + +long xe_eudebug_vm_open_ioctl (struct xe_eudebug *d,unsigned long arg); + +#endif /* _XE_EUDEBUG_VM_H_ */
drivers/gpu/drm/xe/xe_hw_engine.h +5 -0
@@ -87,4 +87,9 @@ static inline bool xe_engine_supports_eudebug(const enum xe_engine_class ec) return false; } +static inline bool xe_hw_engine_has_eudebug (const struct xe_hw_engine *hwe) +{ +return xe_engine_supports_eudebug (hwe->class); +} +#endif
include/uapi/drm/xe_drm_eudebug.h +65 -4
87 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 13/20] drm/xe/eudebug: Add vm open/pread/pwrite
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/xe/eudebug: unlocked vm->size reads in __xe_eudebug_vm_access() - [Low] drm/xe/eudebug: detach…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/xe/eudebug: unlocked vm->size reads in __xe_eudebug_vm_access()
- [Low] drm/xe/eudebug: detach race in __xe_eudebug_vm_access() returns -EINVAL
--
commit a3a16f65fbfea0ccc25672bcf54427e90a80cace
Author: Mika Kuoppala <[email protected]>
drm/xe/eudebug: Add vm open/pread/pwrite
This commit adds the DRM_XE_EUDEBUG_IOCTL_VM_OPEN ioctl and file operations for reading, writing, and syncing a target client's BO-backed VM mappings.
Quoted 5 lines
drivers/gpu/drm/xe/xe_eudebug_vm.c new file +0
-0
[ ... ]
Quoted 16 lines
drivers/gpu/drm/xe/xe_eudebug_vm.c new file +16
-0+static ssize_t __xe_eudebug_vm_access (struct file *file, +char __user *r_buffer, +const char __user *w_buffer, +size_t count,loff_t *__pos) +{ +struct vm_file *vmf = file->private_data; +struct xe_eudebug *const d = vmf->debugger; +struct xe_device *const xe = d->xe; +const bool write = !!w_buffer; +struct xe_vm *vm; +ssize_t copied =0 ; +ssize_t bytes_left; +ssize_t ret; +unsigned long alloc_len; +loff_t pos = *__pos; +void *k_buffer;
drivers/gpu/drm/xe/xe_eudebug_vm.c line 227
Quoted 10 lines
drivers/gpu/drm/xe/xe_eudebug_vm.c new file +10
-0+ +if (XE_IOCTL_DBG (d->xe,xe_eudebug_is_detached (d))) +return -ENOTCONN ; + +if (XE_IOCTL_DBG (xe, write && r_buffer)) +return -EINVAL ; + + vm =xe_eudebug_vm_get (d, vmf->vm_handle); +if (XE_IOCTL_DBG (xe, !vm)) +return -EINVAL ;
[Severity: Low]
Can __xe_eudebug_vm_access() return -EINVAL instead of -ENOTCONN if the target detaches between xe_eudebug_is_detached() and xe_eudebug_vm_get()?
CPU0 CPU1__xe_eudebug_vm_access()
xe_eudebug_is_detached(d)
-> false
xe_eudebug_detach()
d->target.xef = NULL
xe_eudebug_resources_clear(d)
xe_eudebug_vm_get(d, ...)
-> NULL return -EINVAL; <-- expected -ENOTCONN
Checking xe_eudebug_is_detached(d) when !vm, as xe_eudebug_vm_open_ioctl() does, would return -ENOTCONN as documented in the UAPI header.
Quoted 15 lines
drivers/gpu/drm/xe/xe_eudebug_vm.c new file +15
-0+ +if (XE_IOCTL_DBG (xe, vm != vmf->vm)) { +eu_warn (d,"vm_access(%s): vm handle mismatch vm_handle=%llu, flags=0x%llx, pos=%llu, count=%zu\n" , +str_write_read (write), + vmf->vm_handle, vmf->flags, pos, count); +xe_vm_put (vm); +return -EINVAL ; + } + +if (!count) { +xe_vm_put (vm); +return 0 ; + } + +if (pos >= vm->size) {
drivers/gpu/drm/xe/xe_eudebug_vm.c line 252
Quoted 10 lines
drivers/gpu/drm/xe/xe_eudebug_vm.c new file +10
-0+xe_vm_put (vm); +return write ? -ENOSPC :0 ; + } + + count =min_t (u64, count, vm->size - pos); + bytes_left = count; + + alloc_len = min_t(unsigned long, ALIGN(count, PAGE_SIZE), 64 * SZ_1M); + do { + k_buffer = __vmalloc(alloc_len, GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
[Severity: Medium]
Can reading vm->size twice without holding vm->lock race with xe_vm_close() zeroing vm->size?
drivers/gpu/drm/xe/xe_vm.c:xe_vm_close() {
down_write(&vm->lock);
xe_vm_lock(vm, false);
if (xe_vm_in_fault_mode(vm))
xe_svm_notifier_lock(vm);
vm->size = 0;
...
}CPU0 CPU1__xe_eudebug_vm_access()
vm = xe_eudebug_vm_get(...)
xe_vm_close(vm)
down_write(&vm->lock)
if (pos >= vm->size)
-> false (pos == 0)
vm->size = 0
up_write(&vm->lock)
count = min_t(u64, count,
vm->size - pos)
-> 0 alloc_len = 0
__vmalloc(0, ...) <-- hits WARN_ON_ONCE(!size)
If pos > 0 when vm->size becomes 0 between the two reads, vm->size - pos underflows u64; if vm->size is already 0 at the first read, pread() returns 0 (EOF) and pwrite() returns -ENOSPC instead of -EINVAL for a closed VM.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
PATCH 14/20 drm/xe/eudebug: Add userptr vm pread/pwrite
In reply to Mika KuoppalaImplement debugger vm access for userptrs.
When bind is done, take a ref to the 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 Simona, Thomas and Joonas.
v2: need to add offset into vma (Dominik)
v3: move code into xe_userptr.c (Mika)
v4: check that task mm has not changed (Claude)
--- drivers/gpu/drm/xe/xe_eudebug_vm.c | 52 ++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_userptr.c | 4 +++ drivers/gpu/drm/xe/xe_userptr.h | 34 +++++++++++++++++++ include/uapi/drm/xe_drm_eudebug.h | 2 ++ 4 files changed, 92 insertions(+)
drivers/gpu/drm/xe/xe_eudebug_vm.c +52 -0
@@ -8,6 +8,7 @@#include <linux/anon_inodes.h> #include <linux/dma-resv.h> #include <linux/fs.h> +#include <linux/sched/mm.h> #include <linux/string_choices.h> #include <linux/vmalloc.h>
@@ -106,6 +107,57 @@ 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 mm_struct *mm; +int ret; + +if (XE_WARN_ON (!userptr->eudebug.task)) +return -EINVAL ; + +/* +* XXX FIXME: access_remote_vm() on userptr->notifier.mm would +* fit better, as the notifier already holds a reference on the +* mm and no task reference would be needed at all. It is not +* exported though, so go through the task with +* access_process_vm(), which is. +* +* Going through the task means the address space is resolved +* from it on every access, and the task outlives its mm: after +* an execve the same task carries a different address space, +* and after the thread exits it carries none at all even +* though the process and this mapping are still alive. +* +* Confirm the mm the userptr was bound against is still the +* one the task holds, so that a replaced address space is +* refused instead of handing the debugger bytes from an +* unrelated program. access_process_vm() resolves the mm +* again on its own, so this narrows that window rather than +* closing it. Keying the access on the mm instead, with +* get_user_pages_remote() on userptr->notifier.mm, would +* remove the task from the picture entirely. +*/ + mm =get_task_mm (userptr->eudebug.task); +if (!mm) +return -ESRCH ; + + ret = mm == userptr->notifier.mm ?0 : -ESRCH ; +mmput (mm); +if (ret) +return ret; + +/* +* access_process_vm() reports a failure to reach even the +* first byte as 0, not as an errno. Turn that into -EIO, as +* /proc/pid/mem does, so that a read does not look like the +* end of the vm and a write does not return 0. +*/ + ret =access_process_vm (userptr->eudebug.task, +xe_vma_userptr (vma) + offset_in_vma, + buf, bytes, + write ?FOLL_WRITE :0 ); + +return ret ?: -EIO ; }return -EINVAL ;
drivers/gpu/drm/xe/xe_userptr.c +4 -0
@@ -421,6 +421,8 @@ int xe_userptr_setup(struct xe_userptr_vma *uvma, unsigned long start,if (err)return err; +xe_eudebug_track_userptr_task (userptr); +return 0 ; }
@@ -429,6 +431,8 @@ void xe_userptr_remove(struct xe_userptr_vma *uvma)struct xe_vm *vm =xe_vma_vm (&uvma->vma);struct xe_userptr *userptr = &uvma->userptr; +xe_eudebug_untrack_userptr_task (userptr); +drm_gpusvm_free_pages (&vm->svm.gpusvm, &uvma->userptr.pages,xe_vma_size (&uvma->vma) >>PAGE_SHIFT );
drivers/gpu/drm/xe/xe_userptr.h +34 -0
@@ -9,6 +9,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/notifier.h> +#include <linux/sched/task.h> #include <linux/scatterlist.h> #include <linux/spinlock.h>
@@ -95,6 +96,17 @@ struct xe_userptr {#if IS_ENABLED (CONFIG_DRM_XE_USERPTR_INVAL_INJECT )u32 divisor;#endif + +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +/** @eudebug: eudebug state of the userptr */ +struct { +/** +* @eudebug.task: task that bound the userptr, see +* xe_eudebug_vma_access() +*/ +struct task_struct *task; + } eudebug; +#endif };#if IS_ENABLED (CONFIG_DRM_GPUSVM )
@@ -133,4 +145,26 @@ static inline void xe_vma_userptr_force_invalidate(struct xe_userptr_vma *uvma) { }#endif + +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +static inline void xe_eudebug_track_userptr_task (struct xe_userptr *userptr) +{ +/* See xe_eudebug_vma_access() for why this is a task, not the mm */ + 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
include/uapi/drm/xe_drm_eudebug.h +2 -0
@@ -371,6 +371,8 @@ struct drm_xe_eudebug_ack {* marked purgeable (DONTNEED) or the kernel already purged. * - -EINTR if the wait for the backing store to be ready was interrupted. * - -ENOTCONN if the debug target is gone. +* - -ESRCH if the mapping is a userptr whose address space can no longer +* be reached. * - -ENOSPC from pwrite() at an offset at or past the end of the vm. * pread() returns 0 there. * - -ENOMEM, -EFAULT, -EIO or -ENODATA if a bounce buffer could not be
Signature · 1 line
2.53.0
Re: [PATCH 14/20] drm/xe/eudebug: Add userptr vm pread/pwrite
Quoted 8 lines · Mika Kuoppala
Implement debugger vm access for userptrs.
When bind is done, take a ref to the 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 Simona, Thomas and Joonas.
At AMD we had a legthly discussion if such an interface would be necessary for AMDs debugger interface and came to the conclusion that it is *NOT* a good idea to have this.
process_vm_readv() and process_vm_writev() interfaces already allow a debugger to access userptr resources completely without the need of PTRACE_ATTACH.
Especially since this interface here allows to bypass all the extra security checks otherwise applied to such an action it should probably not be something allowed upstream.
Regards,
Christian.
Quoted 181 lines
v2: need to add offset into vma (Dominik)
v3: move code intoxe_userptr.c(Mika)
v4: check that task mm has not changed (Claude)Cc Simona Vetter <[email protected]>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]>Signed-off-by Mika Kuoppala <[email protected]>--- drivers/gpu/drm/xe/xe_eudebug_vm.c | 52 ++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_userptr.c | 4 +++ drivers/gpu/drm/xe/xe_userptr.h | 34 +++++++++++++++++++ include/uapi/drm/xe_drm_eudebug.h | 2 ++ 4 files changed, 92 insertions(+)drivers/gpu/drm/xe/xe_eudebug_vm.c +52
-0@@ -8,6 +8,7 @@#include <linux/anon_inodes.h> #include <linux/dma-resv.h> #include <linux/fs.h> +#include <linux/sched/mm.h> #include <linux/string_choices.h> #include <linux/vmalloc.h> @@ -106,6 +107,57 @@ 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 mm_struct *mm; +int ret; + +if (XE_WARN_ON (!userptr->eudebug.task)) +return -EINVAL ; + +/* +* XXX FIXME: access_remote_vm() on userptr->notifier.mm would +* fit better, as the notifier already holds a reference on the +* mm and no task reference would be needed at all. It is not +* exported though, so go through the task with +* access_process_vm(), which is. +* +* Going through the task means the address space is resolved +* from it on every access, and the task outlives its mm: after +* an execve the same task carries a different address space, +* and after the thread exits it carries none at all even +* though the process and this mapping are still alive. +* +* Confirm the mm the userptr was bound against is still the +* one the task holds, so that a replaced address space is +* refused instead of handing the debugger bytes from an +* unrelated program. access_process_vm() resolves the mm +* again on its own, so this narrows that window rather than +* closing it. Keying the access on the mm instead, with +* get_user_pages_remote() on userptr->notifier.mm, would +* remove the task from the picture entirely. +*/ + mm =get_task_mm (userptr->eudebug.task); +if (!mm) +return -ESRCH ; + + ret = mm == userptr->notifier.mm ?0 : -ESRCH ; +mmput (mm); +if (ret) +return ret; + +/* +* access_process_vm() reports a failure to reach even the +* first byte as 0, not as an errno. Turn that into -EIO, as +* /proc/pid/mem does, so that a read does not look like the +* end of the vm and a write does not return 0. +*/ + ret =access_process_vm (userptr->eudebug.task, +xe_vma_userptr (vma) + offset_in_vma, + buf, bytes, + write ?FOLL_WRITE :0 ); + +return ret ?: -EIO ; }return -EINVAL ;drivers/gpu/drm/xe/xe_userptr.c +4
-0@@ -421,6 +421,8 @@ int xe_userptr_setup(struct xe_userptr_vma *uvma, unsigned long start,if (err)return err; +xe_eudebug_track_userptr_task (userptr); +return 0 ; }@@ -429,6 +431,8 @@ void xe_userptr_remove(struct xe_userptr_vma *uvma)struct xe_vm *vm =xe_vma_vm (&uvma->vma);struct xe_userptr *userptr = &uvma->userptr; +xe_eudebug_untrack_userptr_task (userptr); +drm_gpusvm_free_pages (&vm->svm.gpusvm, &uvma->userptr.pages,xe_vma_size (&uvma->vma) >>PAGE_SHIFT );drivers/gpu/drm/xe/xe_userptr.h +34
-0@@ -9,6 +9,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/notifier.h> +#include <linux/sched/task.h> #include <linux/scatterlist.h> #include <linux/spinlock.h> @@ -95,6 +96,17 @@ struct xe_userptr {#if IS_ENABLED (CONFIG_DRM_XE_USERPTR_INVAL_INJECT )u32 divisor;#endif + +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +/** @eudebug: eudebug state of the userptr */ +struct { +/** +* @eudebug.task: task that bound the userptr, see +* xe_eudebug_vma_access() +*/ +struct task_struct *task; + } eudebug; +#endif };#if IS_ENABLED (CONFIG_DRM_GPUSVM )@@ -133,4 +145,26 @@ static inline void xe_vma_userptr_force_invalidate(struct xe_userptr_vma *uvma) { }#endif + +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +static inline void xe_eudebug_track_userptr_task (struct xe_userptr *userptr) +{ +/* See xe_eudebug_vma_access() for why this is a task, not the mm */ + 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 include/uapi/drm/xe_drm_eudebug.h +2
-0@@ -371,6 +371,8 @@ struct drm_xe_eudebug_ack {* marked purgeable (DONTNEED) or the kernel already purged. * - -EINTR if the wait for the backing store to be ready was interrupted. * - -ENOTCONN if the debug target is gone. +* - -ESRCH if the mapping is a userptr whose address space can no longer +* be reached. * - -ENOSPC from pwrite() at an offset at or past the end of the vm. * pread() returns 0 there. * - -ENOMEM, -EFAULT, -EIO or -ENODATA if a bounce buffer could not be
Re: [PATCH 14/20] drm/xe/eudebug: Add userptr vm pread/pwrite
Quoting Christian König (2026-11-16 15:17:02)
Quoted 11 lines · Mika Kuoppala
Quoted 8 lines
Implement debugger vm access for userptrs.
When bind is done, take a ref to the 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 Simona, Thomas and Joonas.
At AMD we had a legthly discussion if such an interface would be necessary for AMDs debugger interface and came to the conclusion that it is *NOT* a good idea to have this.
I'd like to refer to our 2024 December discussion on review of v3 of this series[1].
Quoting myself from the end:
"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."
Then from same series review, we took Sima's suggestions[2] to be implemented. About one year later in 2025 December we got your review comments[3] for series v6:
"But from a ten mile high view it looks sane to me now."
And quoting myself:
"Understandable and thanks for the high level check, we'll continue with the current direction then."
So given v4 (which you gave above "looks sane to me" included pretty much exactly this patch [4], I'm bit surprised to be starting to reiterate what feels like our discussion from [1].
I'm hoping we can agree to a disagree here. ROCm maybe doesn't need interface like this due to requirement of ptrace_attach(), GPU address == CPU address and no kernel initiated core dumps. We want to avoid those limitations in our architecture as discussed in [1].
After you very much seemed to agree in the direction on [3], we've spent 2 years incrementally addressing all the other comments in 7 new series versions. Thus I'm not really a big fan of reiterating the original discussion, so excuse me for being bit irritated here.
Quoted 1 line
process_vm_readv()andprocess_vm_writev()interfaces already allow a debugger to access userptr resources completely without the need ofPTRACE_ATTACH.
That is correct. However as discussed earlier the access implemented here is for reading memory from ppGTT, not the CPU address space. For readv/writev userspace driver would have to maintain all ppGTT layouts in CPU address space and that'll simply not fit as discussed in [1] amongst the other reasons.
This exact same access will be needed when doing core dumps and capturing the ppGTT contents during crash by kernel, when there is no GDB involved. I don't see any value in diverging the memory access path for interactive debug and core dumps.
I don't know if ROCm has plans for supporting core dumps without GDB involved, but we definitely want to have that ability. And in [1] we seemed to agree on the usefulness.
Quoted 1 line
Especially since this interface here allows to bypass all the extra security checks otherwise applied to such an action it should probably not be something allowed upstream.
To recap. No security is bypassed, access happens as if GPU did the access. If the address is not in ppGTT, there's no access to it. So access given here is equal to access gained submitting a blitter copy command to copy the data using a context with the same ppGTT. Code comments were added to explain to eliminate Sashiko false positives.
Unfortunately, we can't actually rely on the RCS/CCS/BCS engines making forward progress on current gen hardware as hardware may be stalled due to numerous pending page-faults. Especially when doing core dumps.
Regards, Joonas
[1] https://lore.kernel.org/intel-xe/173392197322.40386.12252741494998606453@jlahtine-mobl.ger.corp.intel.com/
[2] https://lore.kernel.org/intel-xe/[email protected]/
[3] https://lore.kernel.org/intel-xe/176520185138.24350.8954844301177099832@jlahtine-mobl/
[4] https://lore.kernel.org/intel-xe/[email protected]/
PATCH 15/20 drm/xe/eudebug: Add hw enablement
In reply to Mika KuoppalaFrom: Dominik Grzegorzek <[email protected]>
In order to turn on debug capabilities (i.e. breakpoints), TD_CTL and some other registers need 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 registers we do later in the series.
v3: get rid of undefining XE_MCR_REG (Mika)
v4: return if dss_mask is all 0.
v5: remove unused GLOBAL_DEBUG_ENABLE (Sashiko)
v6: - don't leak fw ref, check for zero dss_mask (Sashiko)
- hold runtime for hw access (Sashiko)
- make iter size check byte granularity for safety (Claude)
- simplify xe_reg_sr_add with overwrite (Claude)
- check that bitmap size is aligned to hw (4) (Claude)
v7: - assert attention bitmap size granularity (Sashiko)
- overwrite fix (Claude)
v8: - drop duplicate STALL_DOP_GATING_DISABLE (Sashiko)
v9: - refuse eudebug on graphics versions without known debug
register layouts (review-prompts)
v10: - cap_state under eudebug.lock (Mika)
v11: - no empty #else in xe_eudebug_hw.h (Sashiko)
--- drivers/gpu/drm/xe/Makefile | 2 +- drivers/gpu/drm/xe/regs/xe_gt_regs.h | 18 ++ drivers/gpu/drm/xe/xe_eudebug.c | 9 +- drivers/gpu/drm/xe/xe_eudebug_hw.c | 71 ++++++++ drivers/gpu/drm/xe/xe_eudebug_hw.h | 21 +++ drivers/gpu/drm/xe/xe_gt_debug.c | 228 ++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_gt_debug.h | 31 ++++ drivers/gpu/drm/xe/xe_oa.c | 1 + drivers/gpu/drm/xe/xe_reg_sr.c | 19 ++- drivers/gpu/drm/xe/xe_reg_sr.h | 4 +- drivers/gpu/drm/xe/xe_reg_whitelist.c | 2 +- drivers/gpu/drm/xe/xe_rtp.c | 2 +- drivers/gpu/drm/xe/xe_wa_oob.rules | 2 + 13 files changed, 402 insertions(+), 8 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_eudebug_hw.c create mode 100644 drivers/gpu/drm/xe/xe_eudebug_hw.h 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 -1
@@ -165,7 +165,7 @@ xe-$(CONFIG_DRM_XE_GPUSVM) += xe_svm.o xe-$(CONFIG_DRM_GPUSVM) += xe_userptr.o # debugging shaders with gdb (eudebug) support -xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o xe_eudebug_vm.o +xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o xe_eudebug_vm.o xe_eudebug_hw.o xe_gt_debug.o # graphics hardware monitoring (HWMON) support xe-$(CONFIG_HWMON) += xe_hwmon.o
drivers/gpu/drm/xe/regs/xe_gt_regs.h +18 -0
@@ -553,10 +553,20 @@#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) +#define EU_ATT (reg, row) XE_REG_MCR((reg ? 0xe478 : 0xe470) + (row) * 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)
@@ -566,6 +576,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 EU_ATT_CLR (reg, row) XE_REG_MCR((reg ? 0xe698 : 0xe490) + (row) * 4) +#define ROW_CHICKEN3 XE_REG_MCR(0xe49c, XE_REG_OPTION_MASKED)#define XE2_EUPEND_CHK_FLUSH_DIS REG_BIT(14)#define DIS_EU_GRF_POISON_TO_LSC REG_BIT(13)
@@ -589,6 +601,7 @@#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)
@@ -680,6 +693,11 @@ 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) +#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_eudebug.c +8 -1
@@ -2402,7 +2402,14 @@ void xe_eudebug_init_early(struct xe_device *xe)if (drmm_add_action (&xe->drm, xe_eudebug_lock_fini,NULL ))drm_dbg (&xe->drm,"eudebug lock will not be destroyed\n" ); - xe->eudebug.cap_state =XE_EUDEBUG_CAP_DISABLED ; +if (GRAPHICS_VER (xe) >=35 ) { +/* debug register layouts are only known up to Xe3 */ +drm_dbg (&xe->drm,"eudebug not supported on graphics version %u\n" , +GRAPHICS_VER (xe)); + xe->eudebug.cap_state =XE_EUDEBUG_CAP_NOT_SUPPORTED ; + }else { + xe->eudebug.cap_state =XE_EUDEBUG_CAP_DISABLED ; + } }void xe_eudebug_init (struct xe_device *xe)
drivers/gpu/drm/xe/xe_eudebug_hw.c new file +71 -0
71 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug_hw.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023-2025 Intel Corporation +*/ + +#ifndef _XE_EUDEBUG_HW_H_ +#define _XE_EUDEBUG_HW_H_ + +#include <linux/types.h> + +struct xe_eudebug ; +struct xe_hw_engine ; +struct xe_gt ; + +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) + +void xe_eudebug_init_hw_engine (struct xe_hw_engine *hwe,bool enable); + +#endif /* CONFIG_DRM_XE_EUDEBUG */ + +#endif /* _XE_EUDEBUG_HW_H_ */
drivers/gpu/drm/xe/xe_gt_debug.c new file +228 -0
228 lines not on this page · raw message
drivers/gpu/drm/xe/xe_gt_debug.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef _XE_GT_DEBUG_H_ +#define _XE_GT_DEBUG_H_ + +#include <linux/bits.h> +#include <linux/math.h> + +struct xe_gt ; + +#define XE_GT_EU_ATT_ROWS 2u + +unsigned int xe_gt_eu_att_regs (struct xe_gt *gt); + +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, +bool present), +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, +unsigned int bitmap_size); + +#endif
drivers/gpu/drm/xe/xe_oa.c +1 -0
@@ -27,6 +27,7 @@#include "xe_bb.h" #include "xe_bo.h" #include "xe_device.h" +#include "xe_eudebug.h" #include "xe_exec_queue.h" #include "xe_force_wake.h" #include "xe_gt.h"
drivers/gpu/drm/xe/xe_reg_sr.c +16 -3
@@ -105,7 +105,8 @@ static struct xe_reg sanitize_mcr(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);
@@ -115,15 +116,27 @@ int xe_reg_sr_add(struct xe_reg_sr *sr, reg =sanitize_mcr (sr, e, gt);if (pentry) { -if (!compatible_entries (pentry, e)) { +if (!overwrite && !compatible_entries (pentry, e)) { ret = -EINVAL ; goto fail; } pentry->clr_bits |= e->clr_bits; - pentry->set_bits |= e->set_bits; pentry->read_mask |= e->read_mask; +/* +* Overwrite replaces the bits this entry owns instead of +* accumulating them, so a caller can lower bits it raised +* earlier. Same result as the plain or for a caller whose +* set_bits and clr_bits are the same mask, but it also holds +* when set_bits is a subset of clr_bits. +*/ +if (overwrite) + pentry->set_bits = (pentry->set_bits & ~e->clr_bits) | + e->set_bits; +else + pentry->set_bits |= e->set_bits; +return 0 ; }
drivers/gpu/drm/xe/xe_reg_sr.h +3 -1
@@ -6,6 +6,8 @@#ifndef _XE_REG_SR_H_#define _XE_REG_SR_H_ +#include <linux/types.h> +/* * Reg save/restore bookkeeping */
@@ -28,7 +30,7 @@ void xe_reg_sr_lrc_check(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_reg_whitelist.c +1 -1
@@ -193,7 +193,7 @@ static int whitelist_apply_to_hwe(struct xe_hw_engine *hwe, struct xe_reg_sr *in }xe_reg_whitelist_print_entry (&p,0 , reg, entry); -xe_reg_sr_add (out, &hwe_entry, hwe->gt); +xe_reg_sr_add (out, &hwe_entry, hwe->gt, false); slot++; }
drivers/gpu/drm/xe/xe_rtp.c +1 -1
@@ -244,7 +244,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,
drivers/gpu/drm/xe/xe_wa_oob.rules +2 -0
@@ -80,3 +80,5 @@ 14028709524 GRAPHICS_VERSION(3510) 14022766366 GRAPHICS_VERSION_RANGE(2001, 2004) GRAPHICS_VERSION_RANGE(3000, 3005) +18022722726 GRAPHICS_VERSION_RANGE(1250, 1274) +14015474168 PLATFORM(PVC)
Signature · 1 line
2.53.0
PATCH 16/20 drm/xe/eudebug: Track debuggable exec queues
In reply to Mika KuoppalaAttention handling, added with the EU control interface later in the series, has to find the exec queue that raised attention. Track the debuggable exec queues in a device wide list instead of walking the exec queues of every client with a debugger attached.
v2: - enabled check under eudebug.lock, document return (Mika)
--- .../ABI/testing/sysfs-driver-intel-xe-eudebug | 8 ++- drivers/gpu/drm/xe/xe_device_types.h | 3 + drivers/gpu/drm/xe/xe_eudebug.c | 66 +++++++++++++++++++ drivers/gpu/drm/xe/xe_eudebug.h | 5 ++ drivers/gpu/drm/xe/xe_exec_queue.c | 20 ++++++ drivers/gpu/drm/xe/xe_exec_queue_types.h | 8 +++ 6 files changed, 107 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug +5 -3
@@ -12,8 +12,8 @@ Description: RW. Controls whether the EU debugger interface is armed for While disabled, DRM_IOCTL_XE_EUDEBUG_CONNECT fails with -EOPNOTSUPP. - Writing 0 while any debugger connection is still attached - fails with -EBUSY. + Writing 0 while any debugger connection is still attached, + or any debuggable exec queue still exists, fails with -EBUSY. Once enabled, connecting needs no privilege beyond access to the render node: a client may attach to any DRM file it holds
@@ -32,7 +32,9 @@ Description: RW. Controls whether the EU debugger interface is armed for (runalone), and as its preemption timeout is infinite it is not reset if it does not yield the engine when preempted. Work from other clients on those engines can therefore be - held off for as long as such a queue keeps running. + held off for as long as such a queue keeps running. Such a + queue also keeps the interface from being disabled until it + is destroyed. Each connection allocates about 4 MiB of kernel memory for its event queue, held until the connection is closed. The
drivers/gpu/drm/xe/xe_device_types.h +3 -0
@@ -637,6 +637,9 @@ struct xe_device {/** @eudebug.attached: number of debuggers currently attached */ unsigned int attached; +/** @eudebug.targets: exec queues that are debuggable */ +struct list_head targets; +/** @eudebug.lock: protects the eudebug state of this device */ struct mutex lock;
drivers/gpu/drm/xe/xe_eudebug.c +66 -0
84 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +5 -0
@@ -54,6 +54,9 @@ void xe_eudebug_init(struct xe_device *xe);void xe_eudebug_init_early (struct xe_device *xe);bool xe_eudebug_is_enabled (struct xe_device *xe); +int xe_eudebug_track_exec_queue (struct xe_exec_queue *q); +void xe_eudebug_untrack_exec_queue (struct xe_exec_queue *q); +void xe_eudebug_file_close (struct xe_file *xef);void xe_eudebug_vm_create (struct xe_file *xef,struct xe_vm *vm);
@@ -83,6 +86,8 @@ 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_init_early (struct xe_device *xe) { }static inline bool xe_eudebug_is_enabled (struct xe_device *xe) {return false; } +static inline int xe_eudebug_track_exec_queue (struct xe_exec_queue *q) {return 0 ; } +static inline void xe_eudebug_untrack_exec_queue (struct xe_exec_queue *q) { }static inline void xe_eudebug_file_close (struct xe_file *xef) { }
drivers/gpu/drm/xe/xe_exec_queue.c +20 -0
@@ -232,6 +232,9 @@ static struct xe_exec_queue *__xe_exec_queue_alloc(struct xe_device *xe,INIT_LIST_HEAD (&q->vm_exec_queue_link);INIT_LIST_HEAD (&q->hw_engine_group_link);INIT_LIST_HEAD (&q->pxp.link); +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +INIT_LIST_HEAD (&q->eudebug.target_link); +#endif spin_lock_init (&q->multi_queue.lock);spin_lock_init (&q->lrc_lookup_lock); q->multi_queue.priority =XE_MULTI_QUEUE_PRIORITY_NORMAL ;
@@ -514,6 +517,17 @@ struct xe_exec_queue *xe_exec_queue_create(struct xe_device *xe, struct xe_vm *v goto err_post_init; } +/* +* Same reasoning as for the PXP list above: the attention lookup walks +* xe->eudebug.targets and dereferences q->lrc[], which is only filled +* in by __xe_exec_queue_init(), so the queue must not be published +* there while it is half-initialized, nor ahead of anything that can +* still fail, as the error paths free the queue bypassing its kref. +*/ + err =xe_eudebug_track_exec_queue (q); +if (err) + goto err_post_init; +/* * Publish the LRC BO back-pointers last: past this point the queue can * only be destroyed through xe_exec_queue_destroy(), so a concurrent
@@ -684,6 +698,12 @@ void xe_exec_queue_fini(struct xe_exec_queue *q)if (q->xef &&atomic_dec_and_test (&q->xef->exec_queue.pending_removal))wake_up_var (&q->xef->exec_queue.pending_removal); +/* +* Not untracked at kill: a killed queue can still sit on the engine +* with halted threads, and the attention lookup has to resolve it. +*/ +xe_eudebug_untrack_exec_queue (q); +__xe_exec_queue_fini (q);__xe_exec_queue_free (q); }
drivers/gpu/drm/xe/xe_exec_queue_types.h +8 -0
@@ -284,6 +284,14 @@ struct xe_exec_queue {u64 tlb_flush_seqno;/** @hw_engine_group_link: link into exec queues in the same hw engine group */ struct list_head hw_engine_group_link; + +#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +/** @eudebug: eudebug specifics */ +struct { +/** @eudebug.target_link: link into xe_device.eudebug.targets */ +struct list_head target_link; + } eudebug; +#endif /** * @lrc_lookup_lock: Lock for protecting lrc array access. Only used when * running in parallel to queue creation is possible.
Signature · 1 line
2.53.0
PATCH 17/20 drm/xe/eudebug: Introduce EU control interface
In reply to Mika KuoppalaFrom: Dominik Grzegorzek <[email protected]>
Introduce EU control functionality, which allows the EU debugger to interrupt, resume, and inform about the current state of EU threads during execution. Provide an abstraction layer, so that in the future the GuC will only need to provide appropriate callbacks.
Based on an implementation created by the authors and others in the 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)
- attention register naming
v4: - fused off handling (Dominik)
- squash xe3 parts and ptl attentions (Mika)
v5: - s/ioctl_lock/exec_queue.lock to avoid wrong lock order (Mika)
v6: - require seqno MBZ (Mika)
v7: - error return consistency (Mika)
v8: - consolidate boilerplate and lrc sanity check (Mika)
v9: - keep FEE when setting FEH, user_arg reserved (Sashiko)
v10: - take runtime pm for hw access (Sashiko)
- gate sriov (Sashiko)
- more careful logging (Sashiko)
- proper teardown if no runtime active
- don't warn on wrong context (Claude)
- documentation fixes (Claude)
- byte size iter size check for safety (Claude)
v11: - interrupt on the engine the queue runs on (Sashiko)
v12: - don't reset media gts on enable (review-prompts)
v13: - no -EBUSY on discovery, OA reads cap_state under its gt_lock (Mika)
--- .../ABI/testing/sysfs-driver-intel-xe-eudebug | 9 + Documentation/gpu/xe/xe_eudebug.rst | 6 + drivers/gpu/drm/xe/regs/xe_engine_regs.h | 1 + drivers/gpu/drm/xe/xe_device_types.h | 5 +- drivers/gpu/drm/xe/xe_eudebug.c | 162 +++- drivers/gpu/drm/xe/xe_eudebug.h | 5 + drivers/gpu/drm/xe/xe_eudebug_hw.c | 735 ++++++++++++++++++ drivers/gpu/drm/xe/xe_eudebug_hw.h | 7 + drivers/gpu/drm/xe/xe_eudebug_types.h | 25 + drivers/gpu/drm/xe/xe_oa.c | 60 ++ drivers/gpu/drm/xe/xe_oa.h | 1 + include/uapi/drm/xe_drm_eudebug.h | 68 ++ 12 files changed, 1081 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug +9 -0
@@ -15,6 +15,15 @@ Description: RW. Controls whether the EU debugger interface is armed for Writing 0 while any debugger connection is still attached, or any debuggable exec queue still exists, fails with -EBUSY. + Changing the setting resets each gt that has render or + compute engines, so that the debug registers take effect. + Exec queues with jobs in flight on that gt are banned by the + reset. + + Writing 1 while an OA stream is open fails with -EBUSY, and + while the interface is enabled opening an OA stream fails + with -EBUSY. + Once enabled, connecting needs no privilege beyond access to the render node: a client may attach to any DRM file it holds a descriptor for, including its own. Any such client can
Documentation/gpu/xe/xe_eudebug.rst +6 -0
@@ -89,3 +89,9 @@ VM Access .. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h :identifiers: drm_xe_eudebug_vm_open + +EU/HW Control +============= + +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_eu_control
drivers/gpu/drm/xe/regs/xe_engine_regs.h +1 -0
@@ -171,6 +171,7 @@#define IDLE_DELAY REG_GENMASK(20, 0)#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_PXP_ENABLE REG_BIT(10)
drivers/gpu/drm/xe/xe_device_types.h +3 -2
@@ -629,8 +629,9 @@ struct xe_device {u64 session_count;/** -* @eudebug.cap_state: eudebug capability state, protected by -* @eudebug.lock +* @eudebug.cap_state: eudebug capability state. Written +* under @eudebug.lock and the OA gt_lock of every gt, read +* under either, see set_cap_state() */ enum xe_eudebug_cap_state cap_state;
drivers/gpu/drm/xe/xe_eudebug.c +161 -1
224 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +5 -0
@@ -14,6 +14,7 @@ struct drm_file;struct xe_debug_data ;struct xe_device ;struct xe_file ; +struct xe_gt ;struct xe_vm ;struct xe_exec_queue ;struct xe_vma ;
@@ -53,6 +54,7 @@ int xe_eudebug_connect_ioctl(struct drm_device *dev,void xe_eudebug_init (struct xe_device *xe);void xe_eudebug_init_early (struct xe_device *xe);bool xe_eudebug_is_enabled (struct xe_device *xe); +bool xe_eudebug_is_enabled_oa (struct xe_gt *gt);int xe_eudebug_track_exec_queue (struct xe_exec_queue *q);void xe_eudebug_untrack_exec_queue (struct xe_exec_queue *q);
@@ -70,6 +72,8 @@ struct xe_vm *xe_eudebug_vm_get(struct xe_eudebug *d, u32 vm_id);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); +struct xe_exec_queue *xe_eudebug_exec_queue_get (struct xe_eudebug *d,u32 id); +struct xe_lrc *xe_eudebug_find_lrc (struct xe_eudebug *d,u32 id);void xe_eudebug_vm_bind_execute (struct xe_vm *vm,struct xe_vma_ops *ops);
@@ -86,6 +90,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_init_early (struct xe_device *xe) { }static inline bool xe_eudebug_is_enabled (struct xe_device *xe) {return false; } +static inline bool xe_eudebug_is_enabled_oa (struct xe_gt *gt) {return false; }static inline int xe_eudebug_track_exec_queue (struct xe_exec_queue *q) {return 0 ; }static inline void xe_eudebug_untrack_exec_queue (struct xe_exec_queue *q) { }
drivers/gpu/drm/xe/xe_eudebug_hw.c +735 -0
746 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug_hw.h +7 -0
@@ -14,8 +14,15 @@ struct xe_gt;#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG ) +void xe_eudebug_hw_init (struct xe_eudebug *d);void xe_eudebug_init_hw_engine (struct xe_hw_engine *hwe,bool enable); +long xe_eudebug_eu_control (struct xe_eudebug *d,const u64 arg); + +struct xe_exec_queue *xe_gt_runalone_active_queue_get (struct xe_gt *gt, +struct xe_hw_engine **active_hwe, +int *lrc_idx); +#endif /* CONFIG_DRM_XE_EUDEBUG */ #endif /* _XE_EUDEBUG_HW_H_ */
drivers/gpu/drm/xe/xe_eudebug_types.h +25 -0
@@ -19,6 +19,10 @@#include <uapi/drm/xe_drm_eudebug.h> struct xe_device ; +struct xe_eudebug ; +struct xe_hw_engine ; +struct xe_exec_queue ; +struct xe_lrc ;/** * enum xe_eudebug_cap_state - eudebug capability state
@@ -68,6 +72,24 @@ struct xe_eudebug_resource {#define XE_EUDEBUG_RES_TYPE_LRC 2#define XE_EUDEBUG_RES_TYPE_COUNT (XE_EUDEBUG_RES_TYPE_LRC + 1) +/** +* 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_hw_engine *hwe,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 */
@@ -182,6 +204,9 @@ struct xe_eudebug {/** @acks.tree: pending acks by seqnos */ struct rb_root tree; } acks; + +/** @ops: operations for eu_control */ +const struct xe_eudebug_eu_control_ops *ops; };#endif /* _XE_EUDEBUG_TYPES_H_ */
drivers/gpu/drm/xe/xe_oa.c +60 -0
78 lines not on this page · raw message
drivers/gpu/drm/xe/xe_oa.h +1 -0
@@ -17,6 +17,7 @@ struct xe_hw_engine;int xe_oa_init (struct xe_device *xe);int xe_oa_register (struct xe_device *xe);int xe_oa_stream_open_ioctl (struct drm_device *dev,u64 data,struct drm_file *file); +bool xe_oa_stream_active (struct xe_device *xe);int xe_oa_add_config_ioctl (struct drm_device *dev,u64 data,struct drm_file *file);int xe_oa_remove_config_ioctl (struct drm_device *dev,u64 data,struct drm_file *file);u32 xe_oa_timestamp_frequency (struct xe_gt *gt);
include/uapi/drm/xe_drm_eudebug.h +68 -0
80 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 17/20] drm/xe/eudebug: Introduce EU control interface
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/xe/eudebug: missing wedged and unplug guards in do_eu_control() It also noticed 1 related…
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/xe/eudebug: missing wedged and unplug guards in do_eu_control()
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] drm/xe/oa: unbalanced de-whitelisting in xe_oa_stream_open_ioctl_locked() [1]
--
commit c12aefb410d72e1670863e0bab5fd107ad1622e4
Author: Dominik Grzegorzek <[email protected]>
drm/xe/eudebug: Introduce EU control interface
This commit adds the DRM_XE_EUDEBUG_IOCTL_EU_CONTROL ioctl to let an EU debugger interrupt, query, and resume EU threads on debuggable execution queues, and makes eudebug and OA streams mutually exclusive.
Quoted 4 lines
drivers/gpu/drm/xe/xe_eudebug_hw.c +0
-0
[ ... ]
Quoted 4 lines
drivers/gpu/drm/xe/xe_eudebug_hw.c +4
-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) +{
[ ... ]
Quoted 6 lines
drivers/gpu/drm/xe/xe_eudebug_hw.c +6
-0+ lrc =xe_eudebug_find_lrc (d, arg->lrc_handle); +if (XE_IOCTL_DBG (xe, !lrc)) { + ret = -EINVAL ; + goto queue_put; + } +
drivers/gpu/drm/xe/xe_eudebug_hw.c void xe_eudebug_init_hw_engine(struct xe_hw_engine *hwe, bool enable) · line 434
Quoted 10 lines
drivers/gpu/drm/xe/xe_eudebug_hw.c +10
-0+if (!xe_pm_runtime_get_if_active (xe)) { + ret = -EIO ; + goto queue_put; + } + + active =xe_gt_runalone_active_queue_get (q->gt, &active_hwe, &lrc_idx); +if (XE_IOCTL_DBG (xe,IS_ERR (active))) { + ret =PTR_ERR (active); + goto out_pm; + }
[Severity: Medium]
Can do_eu_control() race with PCI device unbind or run on a wedged device to dereference a NULL hwe->gt or access unmapped MMIO registers?
Unlike DRM character device ioctls, DRM_XE_EUDEBUG_IOCTL_EU_CONTROL is dispatched directly on the anonymous [xe_eudebug] file, which holds a drm_dev_get() reference that keeps struct xe_device alive after PCI unbind. xe_pm_runtime_get_if_active(xe) does not stop callers during or after unbind because xe_pm_runtime_fini() calls pm_runtime_get_sync() and pm_runtime_forbid(), leaving runtime PM active while devres tears down the device:
CPU0 CPU1do_eu_control()
xe_pm_runtime_get_if_active(xe)
...
memdup_user() / usleep_range()
xe_pci_remove()
drm_dev_unplug(&xe->drm)
...
devres_release_all()
hw_engine_fini()
hwe->gt = NULL
pcim_iomap_release()
check_lrc_active(active_hwe, lrc)
read_hw_lrca(hwe, &lrc_hw)
gt_to_fw(hwe->gt) <-- NULL pointer dereferenceIf hwe->gt is instead cleared during get_runalone_active_hw_engine(), engine_status() dereferences hwe->gt as well, and after mmio_fini() clears xe->mmio.regs, MMIO accesses trigger device warnings. Sibling anonymous fd callbacks in drivers/gpu/drm/xe/xe_eudebug_vm.c guard against both cases via vm_file_enter(), which checks xe_wedged(xe) and wraps hardware accesses in drm_dev_enter() / drm_dev_exit().
Quoted 4 lines
drivers/gpu/drm/xe/xe_oa.c +0
-0
[ ... ]
Quoted 8 lines
drivers/gpu/drm/xe/xe_oa.c +4
-0@@ -1880,6 +1914,21 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa, goto exit; } +/* +* eudebug and OA both change EU and engine state that the other +* relies on, such as the debug registers and workarounds eudebug +* keeps in hwe->reg_sr and the settings OA changes and restores
drivers/gpu/drm/xe/xe_oa.c static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa, · line 1930
Quoted 10 lines
drivers/gpu/drm/xe/xe_oa.c +10
-0+* around a stream. They do not have to run at the same time, so +* refuse rather than interleave. xe_eudebug_enable() checks the +* other direction with xe_oa_stream_active(), under the same +* gt_lock held here. +*/ +if (xe_eudebug_is_enabled_oa (param->hwe->gt)) { +drm_dbg (&oa->xe->drm,"OA not available while eudebug is enabled\n" ); + ret = -EBUSY ; + goto exit; + }
[Severity: High]
This problem wasn't introduced by this patch, but can xe_oa_stream_open_ioctl_locked() cause an unbalanced xe_reg_dewhitelist_oa_regs() call [1] when opening a stream with DRM_XE_OA_PROPERTY_SAMPLE_OA fails?
xe_oa_stream_init() sets stream->sample = param->sample, but xe_reg_whitelist_oa_regs() is only called after xe_oa_enable_locked() and anon_inode_getfd() both succeed:
drivers/gpu/drm/xe/xe_oa.c:xe_oa_stream_open_ioctl_locked() {
...
if (!param->disabled) {
ret = xe_oa_enable_locked(stream);
if (ret)
goto err_destroy;
}
stream_fd = anon_inode_getfd("[xe_oa]", &xe_oa_fops, stream, 0);
if (stream_fd < 0) {
ret = stream_fd;
goto err_disable;
}
if (stream->sample)
xe_reg_whitelist_oa_regs(stream->gt);
...
err_disable:
if (!param->disabled)
xe_oa_disable_locked(stream);
err_destroy:
xe_oa_stream_destroy(stream);
...
}If anon_inode_getfd() fails (for example with -EMFILE) or xe_oa_enable_locked() fails, xe_oa_stream_destroy() sees stream->sample set and calls xe_reg_dewhitelist_oa_regs(stream->gt) without a matching xe_reg_whitelist_oa_regs(). That triggers xe_assert() and underflows gt->oa.whitelist_count from 0 to U32_MAX (or drops another active OA unit's whitelist reference on the same GT).
[1] https://sashiko.dev/#/bug/linux-44e618e3-ff9f-4811-9ea1-86af519616cc
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
PATCH 18/20 drm/xe/eudebug: Introduce per device attention scan worker
In reply to Mika KuoppalaFrom: 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 50 times slower when there are no debuggable exec queues and no debugger connection open. Send an attention event whenever we see attention with a debugger present.
Based on work by the authors and others who worked on 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)
v4: - attention register naming (Dominik)
v5: - free event on error (Mika)
v6: - annotate data race on extending the poll interval (Mika)
v7: - sysfs race fix, return error instead of XA_WARN_ON (Sashiko)
- attention_poll_stop to async to avoid deadlock (lockdep)
v8: - don't send if there are no attentions
- stop before cancel (Claude)
- use a device workqueue instead of system_dfl_wq (Maciej, Claude)
v9: - use mem_is_zero for the attention bitmap (Sashiko)
v10: - assert attention bitmask alignment (Sashiko)
- static align the attention bitmap
v11: - adapt to runalone queue get signature (Sashiko)
v12: - resolve the attention owner once, bail out early without a
debugger and don't log it as an error (Mika)
- dont disconnect on destroy race (Claude)
v13: - poll state under eudebug.lock, no discovery special case (Mika)
v14: - stamp attention seqno before the handle lookups, document why an
in-flight poll round outliving a disable is harmless (Sashiko)
--- Documentation/gpu/xe/xe_eudebug.rst | 3 + drivers/gpu/drm/xe/xe_device_types.h | 12 + drivers/gpu/drm/xe/xe_eudebug.c | 492 +++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_eudebug.h | 1 + drivers/gpu/drm/xe/xe_eudebug_hw.c | 16 +- drivers/gpu/drm/xe/xe_eudebug_hw.h | 2 + drivers/gpu/drm/xe/xe_eudebug_types.h | 2 +- include/uapi/drm/xe_drm_eudebug.h | 41 +++ 8 files changed, 553 insertions(+), 16 deletions(-)
Documentation/gpu/xe/xe_eudebug.rst +3 -0
@@ -78,6 +78,9 @@ Resource Event Types .. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h :identifiers: drm_xe_eudebug_event_vm_bind_ufence +.. kernel-doc:: include/uapi/drm/xe_drm_eudebug.h + :identifiers: drm_xe_eudebug_event_eu_attention + Acknowledging Events --------------------
drivers/gpu/drm/xe/xe_device_types.h +12 -0
@@ -653,6 +653,18 @@ struct xe_device {/** @eudebug.wq: used for the async session disconnect */ struct workqueue_struct *wq; + +/** @eudebug.attention_wq: used for the attention poll work */ +struct workqueue_struct *attention_wq; + +/** @eudebug.attention_dwork: attention poll work */ +struct delayed_work attention_dwork; + +/** +* @eudebug.send_attentions: handle attentions or ignore, +* protected by @eudebug.lock +*/ + bool send_attentions; } eudebug;#endif
drivers/gpu/drm/xe/xe_eudebug.c +485 -7
565 lines not on this page · raw message
drivers/gpu/drm/xe/xe_eudebug.h +1 -0
@@ -66,6 +66,7 @@ void xe_eudebug_vm_destroy(struct xe_file *xef, struct xe_vm *vm);bool xe_eudebug_is_detached (struct xe_eudebug *d); +struct xe_eudebug *xe_eudebug_get_nolock (struct xe_file *xef);void xe_eudebug_put (struct xe_eudebug *d);struct xe_vm *xe_eudebug_vm_get (struct xe_eudebug *d,u32 vm_id);
drivers/gpu/drm/xe/xe_eudebug_hw.c +8 -8
@@ -354,13 +354,13 @@ static int check_lrc_sanity(const struct xe_exec_queue *q, }/* -* The active context was sampled before the bitmask was copied in from -* userspace and before eudebug.lock was taken, and the hardware may have -* switched since. EU_ATT and EU_ATT_CLR are gt wide, so check again just -* before touching them, as xe_eu_control_interrupt_all() does for TD_CTL, -* rather than report or clear attention of some other context. +* The active context is sampled once, and the hardware may switch away +* from it any time after. EU_ATT and EU_ATT_CLR are gt wide, so check +* again right before clearing them, or right after reading them, as +* xe_eu_control_interrupt_all() does for TD_CTL, rather than report or +* clear attention of some other context. */ -static int check_lrc_active (struct xe_hw_engine *hwe,struct xe_lrc *lrc) +int xe_eudebug_check_lrc_active (struct xe_hw_engine *hwe,struct xe_lrc *lrc) {u32 lrc_hw;int err;
@@ -498,12 +498,12 @@ static int do_eu_control(struct xe_eudebug *d, ret = -EINVAL ;break ;case DRM_XE_EUDEBUG_EU_CONTROL_CMD_STOPPED : - ret =check_lrc_active (active_hwe, lrc); + ret =xe_eudebug_check_lrc_active (active_hwe, lrc);if (!ret) ret = d->ops->stopped (d, active, lrc, bits, attn_size);break ;case DRM_XE_EUDEBUG_EU_CONTROL_CMD_RESUME : - ret =check_lrc_active (active_hwe, lrc); + ret =xe_eudebug_check_lrc_active (active_hwe, lrc);if (!ret) ret = d->ops->resume (d, active, lrc, bits, attn_size);break ;
drivers/gpu/drm/xe/xe_eudebug_hw.h +2 -0
@@ -11,6 +11,7 @@struct xe_eudebug ;struct xe_hw_engine ;struct xe_gt ; +struct xe_lrc ;#if IS_ENABLED (CONFIG_DRM_XE_EUDEBUG )
@@ -22,6 +23,7 @@ long xe_eudebug_eu_control(struct xe_eudebug *d, const u64 arg);struct xe_exec_queue *xe_gt_runalone_active_queue_get (struct xe_gt *gt,struct xe_hw_engine **active_hwe,int *lrc_idx); +int xe_eudebug_check_lrc_active (struct xe_hw_engine *hwe,struct xe_lrc *lrc);#endif /* CONFIG_DRM_XE_EUDEBUG */
drivers/gpu/drm/xe/xe_eudebug_types.h +1 -1
@@ -37,7 +37,7 @@ enum xe_eudebug_cap_state { XE_EUDEBUG_CAP_ENABLED, }; -#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_VM_BIND_UFENCE +#define XE_EUDEBUG_MAX_EVENT_TYPE DRM_XE_EUDEBUG_EVENT_EU_ATTENTION/** * struct xe_eudebug_handle - eudebug resource handle
include/uapi/drm/xe_drm_eudebug.h +41 -0
53 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 18/20] drm/xe/eudebug: Introduce per device attention scan worker
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/xe/eudebug: attention seqno race with discover_client() queue create --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/xe/eudebug: attention seqno race with discover_client() queue create
--
commit 9b3fd09a4bd67b0862bac3d3c0bc36809193f44f
Author: Dominik Grzegorzek <[email protected]>
drm/xe/eudebug: Introduce per device attention scan worker
This commit introduces a periodic per-device delayed worker to scan for EU debugging attention bits and send DRM_XE_EUDEBUG_EVENT_EU_ATTENTION events when an attached debugger is present, or reset the GT if no debugger will service the halted threads.
Quoted 4 lines
drivers/gpu/drm/xe/xe_eudebug.c +0
-0
[ ... ]
Quoted 65 lines
drivers/gpu/drm/xe/xe_eudebug.c +61
-0@@ -2218,6 +2233,362 @@ static const struct file_operations fops = { .compat_ioctl = compat_ptr_ioctl, }; +/* +* The uapi tells userspace the attention bitmask sits 8 byte aligned within +* the event, so it may be scanned as u32 or u64 words. That holds today +* because the preceding members are u64, but a field added ahead of the +* array could quietly break it, so pin it down here. Only the offset can +* be: plain __u64 members are 4 byte aligned on i386. +*/ +static_assert (offsetof(struct drm_xe_eudebug_event_eu_attention , bitmask) % +sizeof (__u64) ==0 ); + +static int send_attention_event (struct xe_eudebug *d,struct xe_exec_queue *q, +int lrc_idx,void *bitmap,unsigned int size, +u64 seqno) +{ +struct drm_xe_eudebug_event_eu_attention *e; +struct drm_xe_eudebug_event *event; +const u32 sz =struct_size (e, bitmask, size); +int h_queue, h_lrc; +int ret; + +if (lrc_idx <0 || lrc_idx >= q->width) +return -EINVAL ; + + h_queue =find_handle (d,XE_EUDEBUG_RES_TYPE_EXEC_QUEUE , q); +if (h_queue <0 ) +return h_queue; + + h_lrc =find_handle (d,XE_EUDEBUG_RES_TYPE_LRC , q->lrc[lrc_idx]); +if (h_lrc <0 ) +return h_lrc; + +mutex_lock (&d->lock); + event =xe_eudebug_prepare_event (d,DRM_XE_EUDEBUG_EVENT_EU_ATTENTION , + seqno,DRM_XE_EUDEBUG_EVENT_STATE_CHANGE , + sz); + + e =cast_event (e, event); + e->exec_queue_handle = h_queue; + e->lrc_handle = h_lrc; + e->bitmask_size = size; + +memcpy (e->bitmask, bitmap, size); + ret =xe_eudebug_queue_event (d, event); +mutex_unlock (&d->lock); + +return ret; +} + +static int relay_gt_attention (struct xe_eudebug *d,struct xe_exec_queue *q, +struct xe_hw_engine *hwe,int lrc_idx) +{ +const u32 size =xe_gt_eu_attention_bitmap_size (q->gt); +void *bitmask; +u64 seqno; +int ret; + +/* If we fail at this time, assume we manage to send eventually */ + bitmask =kvzalloc (size,GFP_KERNEL ); +if (!bitmask) +return 0 ; +
drivers/gpu/drm/xe/xe_eudebug.c static const struct file_operations fops = { · line 2306
Quoted 10 lines
drivers/gpu/drm/xe/xe_eudebug.c +10
-0+/* +* Attention is state, so the event is stamped where that state is +* observed: as the bits are read. That is also before the handle +* lookups in send_attention_event(), so a handle still found there is +* destroyed with a later seqno. A round that ends up sending nothing +* leaves a gap in the numbering, which the uapi allows. +*/ + seqno =atomic64_inc_return (&d->events.seqno); + + ret =xe_gt_eu_attention_bitmap (q->gt, bitmask, size);
[Severity: Medium]
Can relay_gt_attention() send a DRM_XE_EUDEBUG_EVENT_EU_ATTENTION event with a smaller seqno than the queue's DRM_XE_EUDEBUG_EVENT_CREATE event when racing with discover_client()?
In xe_eudebug_attach(), add_debugger() publishes xef->eudebug.debugger before discover_client() runs, and handle_gt_attention() looks up the debugger via xe_eudebug_get_nolock() without holding xef->eudebug.ioctl_lock:
CPU0 (attention_wq) CPU1 (connect ioctl)handle_gt_attention() xe_eudebug_attach()
d = xe_eudebug_get_nolock(...) discover_client()
relay_gt_attention() ...
seqno = atomic64_inc_return() exec_queue_create_event()
--> S1 _xe_eudebug_add_handle(LRC)
xe_gt_eu_attention_bitmap() mutex_lock(&d->lock)
__handle_insert(EXEC_QUEUE)
--> seqno = S2 (S2 > S1)
mutex_unlock(&d->lock)
send_attention_event()
find_handle(EXEC_QUEUE)
find_handle(LRC)
mutex_lock(&d->lock)
xe_eudebug_queue_event(S1)
mutex_unlock(&d->lock)
send_exec_queue_event(S2)The attention event for q is stamped with seqno S1 < S2 and can also be queued into d->events.fifo ahead of the EXEC_QUEUE CREATE event because exec_queue_create_event() drops d->lock between __handle_insert() and send_exec_queue_event(), so userspace sees an attention event for handles that have not been created yet.
Looking up h_queue and h_lrc before stamping seqno in relay_gt_attention() (and re-checking that the handles still exist before queueing, or holding xef->eudebug.ioctl_lock) would ensure discovery has already assigned the CREATE seqno first.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
PATCH 19/20 drm/xe/eudebug_test: Introduce eudebug live tests
In reply to Mika KuoppalaFrom: Christoph Manszewski <[email protected]>
Introduce a 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)
v4: enforce kunit rules and naming (Michal)
v5: restore hw state if enable error (Sashiko)
drop XE_MCR_REG def (Claude)
fail if hw state can't be restored (Claude)
v6: read cap_state under eudebug.lock (Mika)
v7: - check all forcewake domains, VF comment to the SR-IOV patch (Sashiko)
--- drivers/gpu/drm/xe/tests/xe_eudebug_test.c | 241 ++++++++++++++++++++ drivers/gpu/drm/xe/tests/xe_live_test_mod.c | 5 + drivers/gpu/drm/xe/xe_eudebug.c | 4 + 3 files changed, 250 insertions(+) create mode 100644 drivers/gpu/drm/xe/tests/xe_eudebug_test.c
drivers/gpu/drm/xe/tests/xe_eudebug_test.c new file +241 -0
@@ -0,0 +1,241 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* +* Copyright © 2026 Intel Corporation +*/ + +#include <kunit/visibility.h> +#include <linux/string_choices.h> + +#include "regs/xe_gt_regs.h" +#include "xe_force_wake.h" +#include "xe_gt_mcr.h" +#include "xe_mmio.h" +#include "tests/xe_kunit_helpers.h" +#include "tests/xe_pci_test.h" +#include "tests/xe_test.h" + +static const char *reg_to_str (struct xe_reg reg) +{ +if (reg.raw ==TD_CTL .__reg.raw) +return "TD_CTL" ; +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) +{ +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 ==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_FAIL (test,"Invalid register selection: 0x%x\n" , reg.raw); + } + +return val; +} + +static u32 get_reg_expected (struct xe_device *xe,struct xe_reg reg, +bool enable_eudebug,struct kunit *test) +{ +const u32 reg_mask =get_reg_mask (xe, reg, test); +u32 reg_bits =0 ; + +/* +* XXX ROW_CHICKEN3 is expected set either way, and it is the odd one +* out here: xe_eudebug_init_hw_engine() programs ROW_CHICKEN, +* ROW_CHICKEN2 and TD_CTL, but never ROW_CHICKEN3. +* XE2_EUPEND_CHK_FLUSH_DIS is set by WA 14020338487 in xe_wa.c on all +* Xe2 render and compute engines, with no reference to eudebug, so as +* written this arm asserts that an unrelated workaround is applied. +* +* Pending a check against the hardware documentation on whether +* eupend flush checking has to stay disabled for eudebug. +*/ +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) +{ +struct xe_device *xe =gt_to_xe (gt); +const u32 reg_bits_expected =get_reg_expected (xe, reg, enable_eudebug, test); +const u32 reg_mask =get_reg_mask (xe, reg, test); +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 (>->mmio, reg); + + reg_bits &= reg_mask; + +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 kunit *test) +{ +struct xe_device *xe =gt_to_xe (gt); + +if (GRAPHICS_VERx100 (xe) >=1200 ) +check_reg (gt, enable_eudebug,TD_CTL .__reg, test); + +if (GRAPHICS_VERx100 (xe) >=1250 &&GRAPHICS_VERx100 (xe) <=1274 ) +check_reg (gt, enable_eudebug,ROW_CHICKEN .__reg, test); + +if (xe->info.platform ==XE_PVC ) +check_reg (gt, enable_eudebug,ROW_CHICKEN2 .__reg, test); + +/* The range of Wa_14020338487, which sets the bit checked */ +if (GRAPHICS_VERx100 (xe) >=2001 &&GRAPHICS_VERx100 (xe) <=2004 ) +check_reg (gt, enable_eudebug,ROW_CHICKEN3 .__reg, test); +} + +static void check_regs (struct xe_device *xe,bool enable_eudebug,struct kunit *test) +{ +struct xe_gt *gt; +unsigned int fw_ref; +u8 id; + +kunit_printk (KERN_DEBUG , test,"Check regs for eudebug %s\n" , +str_enabled_disabled (enable_eudebug)); + +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 ); +if (!xe_force_wake_ref_has_domain (fw_ref,XE_FORCEWAKE_ALL )) { +/* Aborting does not return, so put the partial ref first */ +xe_force_wake_put (gt_to_fw (gt), fw_ref); +KUNIT_FAIL_AND_ABORT (test,"Forcewake failed.\n" ); + } + +__check_regs (gt, enable_eudebug, test); + +xe_force_wake_put (gt_to_fw (gt), fw_ref); + } +} + +struct eudebug_state_restore { +struct xe_device *xe; +struct kunit *test; +bool enabled; +}; + +static void restore_eudebug_state (void *arg) +{ +struct eudebug_state_restore *r = arg; + +KUNIT_EXPECT_EQ_MSG (r->test,0 ,xe_eudebug_enable (r->xe, r->enabled), +"Failed to restore eudebug to %s\n" , +str_enabled_disabled (r->enabled)); +} + +static void toggle_reg (struct kunit *test) +{ +struct xe_device *xe = test->priv; +const bool enable_eudebug =xe_eudebug_is_enabled (xe); +struct eudebug_state_restore *restore; +bool supported; +int ret; + +scoped_guard (mutex, &xe->eudebug.lock) + supported = xe->eudebug.cap_state != XE_EUDEBUG_CAP_NOT_SUPPORTED; + +/* Covers an SR-IOV VF too, xe_eudebug_init() marks one unsupported */ +if (!supported) +kunit_skip (test,"eudebug not supported\n" ); + +/* +* An open OA stream keeps eudebug from being enabled, and sets bits +* of its own in the registers checked below. +*/ +if (!enable_eudebug &&xe_oa_stream_active (xe)) +kunit_skip (test,"OA stream open\n" ); + +kunit_printk (KERN_DEBUG , test,"Test eudebug WAs for graphics version: %u\n" , +GRAPHICS_VERx100 (xe)); + +check_regs (xe, enable_eudebug, test); + +/* Nothing to restore until the first toggle below */ + restore =kunit_kzalloc (test,sizeof (*restore),GFP_KERNEL ); +KUNIT_ASSERT_NOT_NULL (test, restore); + restore->xe = xe; + restore->test = test; + restore->enabled = enable_eudebug; +KUNIT_ASSERT_EQ (test,0 , +kunit_add_action_or_reset (test, restore_eudebug_state, + restore)); + + ret =xe_eudebug_enable (xe, !enable_eudebug); +if (ret == -EBUSY ) +kunit_skip (test,"eudebug toggle busy\n" ); +KUNIT_ASSERT_EQ (test,0 , ret); + +check_regs (xe, !enable_eudebug, test); + + ret =xe_eudebug_enable (xe, enable_eudebug); +KUNIT_ASSERT_EQ (test,0 , ret); +check_regs (xe, enable_eudebug, test); +} + +static bool xe_eudebug_has_regs (struct xe_device *xe) +{ +return GRAPHICS_VERx100 (xe) >=1200 ; +} + +static int xe_eudebug_test_init (struct kunit *test) +{ +struct xe_device *xe; +int ret; + + ret =xe_kunit_helper_xe_device_live_test_init (test); +if (ret) +return ret; + + xe = test->priv; +kunit_info (test,"running on graphics version: %u\n" ,GRAPHICS_VERx100 (xe)); + +if (!xe_eudebug_has_regs (xe)) +kunit_skip (test,"hardware not supported: 0x%x\n" ,GRAPHICS_VERx100 (xe)); + +return 0 ; +} + +static struct kunit_case xe_eudebug_tests[] = { +KUNIT_CASE_PARAM (toggle_reg, 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_eudebug_test_init, +}; +EXPORT_SYMBOL_IF_KUNIT (xe_eudebug_test_suite);
drivers/gpu/drm/xe/tests/xe_live_test_mod.c +5 -0
@@ -25,6 +25,11 @@ kunit_test_suite(xe_guc_g2g_test_suite);kunit_test_suite (xe_bo_page_size_alloc_suite);#endif +#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
@@ -3190,3 +3190,7 @@ int xe_eudebug_connect_ioctl(struct drm_device *dev,return xe_eudebug_connect (xe, file, param); } + +#if IS_ENABLED (CONFIG_DRM_XE_KUNIT_TEST ) +#include "tests/xe_eudebug_test.c" +#endif
Signature · 1 line
2.53.0
PATCH 20/20 drm/xe: Add xe_client_debugfs and introduce debug_data file
In reply to Mika KuoppalaFrom: Christoph Manszewski <[email protected]>
Create a debug_data file for each xe file/client. It lists all mapped debug data and mimics '/proc/pid/maps'.
Each line represents a single mapping and has the following format:
<vm id> <begin>-<end> <flags> <offset> <pathname>
v2: trim len in debug_data_read() (Sashiko)
v3: - fix return len, avoid rewind (Sashiko)
- use guard, kdoc, cleanups (Michal)
- drop client ref after seq_file is done (Claude)
--- drivers/gpu/drm/xe/Makefile | 3 +- drivers/gpu/drm/xe/xe_client_debugfs.c | 134 +++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_client_debugfs.h | 17 ++++ drivers/gpu/drm/xe/xe_device.c | 3 + 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/xe/xe_client_debugfs.c create mode 100644 drivers/gpu/drm/xe/xe_client_debugfs.h
drivers/gpu/drm/xe/Makefile +2 -1
@@ -366,7 +366,8 @@ ifeq ($(CONFIG_DRM_FBDEV_EMULATION),y) endif ifeq ($(CONFIG_DEBUG_FS),y) - xe-y += xe_debugfs.o \ + xe-y += xe_client_debugfs.o \ + xe_debugfs.o \ xe_gt_debugfs.o \ xe_gt_sriov_vf_debugfs.o \ xe_gt_stats.o \
drivers/gpu/drm/xe/xe_client_debugfs.c new file +134 -0
134 lines not on this page · raw message
drivers/gpu/drm/xe/xe_client_debugfs.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2026 Intel Corporation +*/ + +#ifndef _XE_CLIENT_DEBUGFS_H_ +#define _XE_CLIENT_DEBUGFS_H_ + +struct xe_file ; + +#ifdef CONFIG_DEBUG_FS +void xe_client_debugfs_register (struct xe_file *xef); +#else +static inline void xe_client_debugfs_register (struct xe_file *xef) { } +#endif + +#endif
drivers/gpu/drm/xe/xe_device.c +3 -0
@@ -25,6 +25,7 @@#include "regs/xe_regs.h" #include "xe_bo.h" #include "xe_bo_evict.h" +#include "xe_client_debugfs.h" #include "xe_configfs.h" #include "xe_debugfs.h" #include "xe_cpu_bind.h"
@@ -132,6 +133,8 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)put_task_struct (task); } +xe_client_debugfs_register (xef); +return 0 ; }
Signature · 1 line
2.53.0