Attention 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) Signed-off-by: Mika Kuoppala <[email protected]> --- .../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(-) diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug b/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug index 50ab7db1f811..237dea4c6699 100644 --- a/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug +++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-eudebug @@ -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 diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index 73b576547193..354b258f4ca6 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -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; diff --git a/drivers/gpu/drm/xe/xe_eudebug.c b/drivers/gpu/drm/xe/xe_eudebug.c index bf4d3ac4e092..03ac45653172 100644 --- a/drivers/gpu/drm/xe/xe_eudebug.c +++ b/drivers/gpu/drm/xe/xe_eudebug.c @@ -2296,6 +2296,13 @@ static int __xe_eudebug_enable(struct xe_device *xe, bool enable, if (!enable && xe->eudebug.attached) return -EBUSY; + /* + * A debuggable queue keeps its runalone and debug state for as long + * as it lives, so do not drop the interface from under it. + */ + if (!enable && !list_empty(&xe->eudebug.targets)) + return -EBUSY; + if (enable == __xe_eudebug_is_enabled(xe)) return 0; @@ -2391,6 +2398,8 @@ static void xe_eudebug_lock_fini(struct drm_device *dev, void *__unused) void xe_eudebug_init_early(struct xe_device *xe) { + INIT_LIST_HEAD(&xe->eudebug.targets); + /* * Not drmm_mutex_init(), which can fail and leave the lock destroyed: * the state is read under it from here on. Nothing can reach the @@ -2466,6 +2475,63 @@ void xe_eudebug_init(struct xe_device *xe) set_cap_state(xe, XE_EUDEBUG_CAP_NOT_SUPPORTED); } +/** + * xe_eudebug_track_exec_queue - Make an exec queue findable on attention + * @q: The exec queue + * + * Adds a debuggable exec queue into the device wide target list, so that + * the attention handling can resolve the hardware context that raised + * attention back to the exec queue owning it. Membership does not depend + * on a debugger being attached to the owning client. + * + * Must be called only after the queue is fully initialized, as the lookup + * dereferences the lrc array of every queue it walks. + * + * Return: 0 on success, -EPERM if eudebug got disabled since the queue was + * made debuggable. + */ +int xe_eudebug_track_exec_queue(struct xe_exec_queue *q) +{ + struct xe_device *xe = gt_to_xe(q->gt); + + if (!xe_exec_queue_is_debuggable(q)) + return 0; + + guard(mutex)(&xe->eudebug.lock); + + /* + * The property checked the enabled state, but a disable may have run + * since. That refuses while queues are tracked, so look again under + * the lock it checks under, or this one would slip in behind it. + */ + if (!__xe_eudebug_is_enabled(xe)) + return -EPERM; + + if (list_empty(&q->eudebug.target_link)) + list_add_tail(&q->eudebug.target_link, &xe->eudebug.targets); + + return 0; +} + +/** + * xe_eudebug_untrack_exec_queue - Remove an exec queue from the target list + * @q: The exec queue + * + * Reverses xe_eudebug_track_exec_queue(). Safe to call on a queue that was + * never tracked, and safe to repeat. + */ +void xe_eudebug_untrack_exec_queue(struct xe_exec_queue *q) +{ + struct xe_device *xe = gt_to_xe(q->gt); + + if (!xe_exec_queue_is_debuggable(q)) + return; + + guard(mutex)(&xe->eudebug.lock); + + list_del_init(&q->eudebug.target_link); +} + /** * xe_eudebug_connect_ioctl - Connect to eudebug interface * @dev : DRM device diff --git a/drivers/gpu/drm/xe/xe_eudebug.h b/drivers/gpu/drm/xe/xe_eudebug.h index dc92cdbbf75e..ce61537a596e 100644 --- a/drivers/gpu/drm/xe/xe_eudebug.h +++ b/drivers/gpu/drm/xe/xe_eudebug.h @@ -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) { } diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c index 870abbf08d2e..5f39b9cf06c0 100644 --- a/drivers/gpu/drm/xe/xe_exec_queue.c +++ b/drivers/gpu/drm/xe/xe_exec_queue.c @@ -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); } diff --git a/drivers/gpu/drm/xe/xe_exec_queue_types.h b/drivers/gpu/drm/xe/xe_exec_queue_types.h index 32893341287d..4e987f73cd1a 100644 --- a/drivers/gpu/drm/xe/xe_exec_queue_types.h +++ b/drivers/gpu/drm/xe/xe_exec_queue_types.h @@ -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. -- 2.53.0
