From: Christoph Manszewski <christoph.manszewski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Piotr Rudnicki" <piotr.rudnicki@intel.com>,
"Dominik Karol Piątkowski" <dominik.karol.piatkowski@intel.com>,
"Jan Sokolowski" <jan.sokolowski@intel.com>
Subject: [PATCH i-g-t v5 4/5] lib/xe/xe_eudebug: Track active debugger sessions and close when disabling
Date: Wed, 11 Mar 2026 12:06:41 +0100 [thread overview]
Message-ID: <20260311110636.798120-11-christoph.manszewski@intel.com> (raw)
In-Reply-To: <20260311110636.798120-7-christoph.manszewski@intel.com>
Active debugger sessions prevent disabling EU Debug via the sysfs
toggle. As a result when a test fails the igt_fixture will fail to
disable EU Debug if the worker threads have open debugger fds.
Introduce active debugger session (debugger fd) tracking and use it to
close leftover sessions before attempting to disable eudebug. The kernel
'struct drm_driver.postclose' handler which removes the debugger
sessions tracked by Xe EU Debug runs asynchronously to 'close' so retry
disabling in a loop on '-EBUSY'.
Signed-off-by: Dominik Karol Piątkowski <dominik.karol.piatkowski@intel.com>
Reviewed-by: Piotr Rudnicki <piotr.rudnicki@intel.com>
Link: https://lore.kernel.org/r/20260220153748.210381-11-christoph.manszewski@intel.com
Signed-off-by: Christoph Manszewski <christoph.manszewski@intel.com>
---
lib/xe/xe_eudebug.c | 73 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 72 insertions(+), 1 deletion(-)
diff --git a/lib/xe/xe_eudebug.c b/lib/xe/xe_eudebug.c
index 7a641d2bd..c722a968a 100644
--- a/lib/xe/xe_eudebug.c
+++ b/lib/xe/xe_eudebug.c
@@ -18,6 +18,57 @@
#include "xe_ioctl.h"
#include "xe/xe_query.h"
+struct debugger_fd_entry {
+ int fd;
+ struct igt_list_head link;
+};
+
+static IGT_LIST_HEAD(active_debugger_fds);
+static pthread_mutex_t active_debugger_fds_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static void register_debugger_fd(int fd)
+{
+ struct debugger_fd_entry *entry;
+
+ entry = calloc(1, sizeof(*entry));
+ igt_assert(entry);
+ entry->fd = fd;
+ IGT_INIT_LIST_HEAD(&entry->link);
+
+ pthread_mutex_lock(&active_debugger_fds_lock);
+ igt_list_add(&entry->link, &active_debugger_fds);
+ pthread_mutex_unlock(&active_debugger_fds_lock);
+}
+
+static void unregister_debugger_fd(int fd)
+{
+ struct debugger_fd_entry *entry, *tmp;
+
+ pthread_mutex_lock(&active_debugger_fds_lock);
+ igt_list_for_each_entry_safe(entry, tmp, &active_debugger_fds, link) {
+ if (entry->fd == fd) {
+ igt_list_del(&entry->link);
+ free(entry);
+ break;
+ }
+ }
+ pthread_mutex_unlock(&active_debugger_fds_lock);
+}
+
+static void close_all_debugger_fds(void)
+{
+ struct debugger_fd_entry *entry, *tmp;
+
+ pthread_mutex_lock(&active_debugger_fds_lock);
+ igt_list_for_each_entry_safe(entry, tmp, &active_debugger_fds, link) {
+ igt_debug("closing leftover debugger fd %d\n", entry->fd);
+ close(entry->fd);
+ igt_list_del(&entry->link);
+ free(entry);
+ }
+ pthread_mutex_unlock(&active_debugger_fds_lock);
+}
+
struct event_trigger {
xe_eudebug_trigger_fn fn;
int type;
@@ -1270,6 +1321,8 @@ static int __xe_eudebug_debugger_attach(struct xe_eudebug_debugger *d, pid_t pid
d->fd = ret;
d->target_pid = pid;
+ register_debugger_fd(d->fd);
+
return 0;
}
@@ -1323,6 +1376,7 @@ int xe_eudebug_debugger_attach(struct xe_eudebug_debugger *d,
void xe_eudebug_debugger_detach(struct xe_eudebug_debugger *d)
{
igt_assert(d->target_pid);
+ unregister_debugger_fd(d->fd);
close(d->fd);
d->target_pid = 0;
d->fd = -1;
@@ -1909,7 +1963,24 @@ bool xe_eudebug_enable(int fd, bool enable)
{
char sysfs_path[PATH_MAX];
bool old = false;
- int ret = __xe_eudebug_enable_getset(fd, &old, &enable);
+ int ret = 0;
+
+ /* When disabling eudebug, close all active debugger sessions first. */
+ if (!enable)
+ close_all_debugger_fds();
+
+ /* 'struct drm_driver.postclose' runs asynchronously to 'close', wait for it to complete */
+ for (int i = 0; i < 10; ++i) {
+ ret = __xe_eudebug_enable_getset(fd, &old, &enable);
+
+ if (ret != -EBUSY)
+ break;
+
+ if (i < 9) {
+ igt_debug("xe_eudebug_enable: Failed (%d), retrying...\n", ret);
+ sleep(1);
+ }
+ }
if (ret == -ENOENT) {
igt_assert(igt_sysfs_path(fd, sysfs_path, sizeof(sysfs_path)));
--
2.47.1
next prev parent reply other threads:[~2026-03-11 11:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 11:06 [PATCH i-g-t v5 0/5] Improve eudebug test cleanup Christoph Manszewski
2026-03-11 11:06 ` [PATCH i-g-t v5 1/5] tests/xe/xe_eudebug: Change pthread_join to pthread_timedjoin_np Christoph Manszewski
2026-03-11 11:06 ` [PATCH i-g-t v5 2/5] lib/xe/xe_eudebug: Modify toggle error handling Christoph Manszewski
2026-03-11 11:06 ` [PATCH i-g-t v5 3/5] xe/xe_eudebug: Add reattach function and make plain connect private Christoph Manszewski
2026-03-11 11:06 ` Christoph Manszewski [this message]
2026-03-11 11:06 ` [PATCH i-g-t v5 5/5] lib/xe/xe_eudebug: Get drm card sysfs path Christoph Manszewski
2026-03-12 0:04 ` ✓ Xe.CI.BAT: success for Improve eudebug test cleanup (rev5) Patchwork
2026-03-12 0:07 ` ✓ i915.CI.BAT: " Patchwork
2026-03-12 19:08 ` ✓ i915.CI.Full: " Patchwork
2026-03-12 19:10 ` ✗ Xe.CI.FULL: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260311110636.798120-11-christoph.manszewski@intel.com \
--to=christoph.manszewski@intel.com \
--cc=dominik.karol.piatkowski@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jan.sokolowski@intel.com \
--cc=piotr.rudnicki@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox