From: Jeevan B <jeevan.b@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: karthik.b.s@intel.com, jani.nikula@intel.com,
Jeevan B <jeevan.b@intel.com>
Subject: [PATCH i-g-t 2/4] lib/igt_kmod: Handle the dedicated intel_display module
Date: Tue, 24 Nov 2026 10:15:57 +0530 [thread overview]
Message-ID: <20261124044559.897167-3-jeevan.b@intel.com> (raw)
In-Reply-To: <20261124044559.897167-1-jeevan.b@intel.com>
With display built as intel-display.ko, loading i915/xe pulls it in as a
dependency but unloading the GPU driver leaves it loaded, which leaks
state into following tests.
Unload intel_display after the GPU driver once nothing else holds it,
both in __igt_intel_driver_unload() and igt_xe_driver_unload(); the GPU
driver always goes first, as it calls into display.
Add helpers for tests that need to control the module explicitly:
igt_intel_display_load()/igt_intel_display_unload() to load it alone and
to unload it together with its holders, igt_intel_display_try_unload()
to attempt a direct removal, igt_intel_driver_unload_keep_display() to
remove only the GPU driver, and igt_intel_display_has_holders().
The module file is intel-display.ko but the kernel registers it as
intel_display; document that and the unload ordering.
The dedicated module needs a kernel that builds display as
intel-display.ko; on older kernels the new helpers fail or are no-ops.
Signed-off-by: Jeevan B <jeevan.b@intel.com>
---
lib/igt_kmod.c | 209 +++++++++++++++++++++++++++++++++++++++++++++++--
lib/igt_kmod.h | 7 ++
2 files changed, 210 insertions(+), 6 deletions(-)
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 76680fca5..276ea0c89 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -585,19 +585,129 @@ int igt_audio_driver_load(char **who)
return ret;
}
-int __igt_intel_driver_unload(char **who, const char *driver)
+/*
+ * The module file is intel-display.ko, but the kernel registers module names
+ * with underscores (/sys/module, /proc/modules), which is what
+ * igt_kmod_is_loaded() matches against. modprobe/libkmod accept either form.
+ *
+ * Dependency order is always intel_display -> i915/xe: the core drivers call
+ * into display, so display can only be removed once every GPU driver holding
+ * it is gone. modprobe loads intel_display automatically as a dependency, but
+ * unloading a module does not remove its dependencies, hence the explicit
+ * unload below.
+ */
+#define INTEL_DISPLAY_MODULE "intel_display"
+
+/**
+ * igt_intel_display_has_holders:
+ *
+ * Returns: true if any module (i915, xe, ...) still depends on intel_display,
+ * as listed in /sys/module/intel_display/holders.
+ */
+bool igt_intel_display_has_holders(void)
+{
+ DIR *d = opendir("/sys/module/" INTEL_DISPLAY_MODULE "/holders");
+ struct dirent *de;
+ bool held = false;
+
+ if (!d)
+ return false;
+
+ while ((de = readdir(d))) {
+ if (de->d_name[0] != '.') {
+ held = true;
+ break;
+ }
+ }
+ closedir(d);
+
+ return held;
+}
+
+/**
+ * igt_intel_display_load:
+ * @opts: options to pass to the intel_display module, or NULL
+ *
+ * Loads the dedicated intel_display module. This is a no-op returning 0 if
+ * the module is already loaded. Returns a negative errno if the module
+ * does not exist, e.g. on kernels with display built into the GPU driver.
+ */
+int igt_intel_display_load(const char *opts)
+{
+ if (igt_kmod_is_loaded(INTEL_DISPLAY_MODULE))
+ return 0;
+
+ return igt_kmod_load(INTEL_DISPLAY_MODULE, opts);
+}
+
+/**
+ * igt_intel_display_unload:
+ *
+ * Unloads the dedicated intel_display module. Any GPU driver (i915 and/or xe)
+ * holding it is unloaded first. Returns 0 if the module is not loaded.
+ */
+int igt_intel_display_unload(void)
+{
+ if (!igt_kmod_is_loaded(INTEL_DISPLAY_MODULE))
+ return 0;
+
+ return igt_kmod_unload(INTEL_DISPLAY_MODULE);
+}
+
+/**
+ * igt_intel_display_try_unload:
+ *
+ * Attempts to remove the intel_display module directly, without first
+ * unloading the modules that hold it. This is expected to fail while i915 or
+ * xe is loaded, as the core drivers call into display: with -EWOULDBLOCK when
+ * other modules depend on it (libkmod removes modules non-blocking), or
+ * -EBUSY when the module is otherwise in use.
+ *
+ * Returns: 0 on success or a negative errno.
+ */
+int igt_intel_display_try_unload(void)
+{
+ struct kmod_module *kmod;
+ int err;
+
+ err = kmod_module_new_from_name(kmod_ctx(), INTEL_DISPLAY_MODULE, &kmod);
+ if (err < 0)
+ return err;
+
+ err = kmod_module_remove_module(kmod, 0);
+ kmod_module_unref(kmod);
+
+ return err;
+}
+
+/*
+ * Unload intel_display once the GPU driver using it is gone. Leave it alone
+ * while another GPU driver still holds it.
+ */
+static int intel_display_unload_if_unused(char **who)
{
int ret;
+ if (!igt_kmod_is_loaded(INTEL_DISPLAY_MODULE) ||
+ igt_intel_display_has_holders())
+ return 0;
+
+ ret = igt_kmod_unload(INTEL_DISPLAY_MODULE);
+ if (ret && who)
+ *who = strdup_realloc(*who, INTEL_DISPLAY_MODULE);
+
+ return ret;
+}
+
+/* Unload modules that only have a soft dependency on the GPU driver */
+static int unload_aux_modules(char **who)
+{
const char *aux[] = {
/* gen5: ips uses symbol_get() so only a soft module dependency */
"intel_ips",
NULL,
};
-
- ret = igt_audio_driver_unload(who);
- if (ret)
- return ret;
+ int ret;
for (const char **m = aux; *m; m++) {
if (!igt_kmod_is_loaded(*m))
@@ -612,6 +722,90 @@ int __igt_intel_driver_unload(char **who, const char *driver)
}
}
+ return 0;
+}
+
+/**
+ * igt_intel_driver_unload_keep_display:
+ * @driver: GPU driver module to unload, e.g. "i915" or "xe"
+ *
+ * Unloads only the GPU driver, leaving intel_display loaded. Like
+ * igt_intel_driver_unload() it first unloads the audio driver and the
+ * auxiliary modules (e.g. intel_ips) and unbinds @driver from its devices.
+ * Tests use this to check the removal order i915/xe first, intel_display
+ * second, step by step. Regular tests should use igt_intel_driver_unload(),
+ * which also removes an unused intel_display.
+ *
+ * Returns: 0 on success or a negative errno.
+ */
+int igt_intel_driver_unload_keep_display(const char *driver)
+{
+ int ret;
+
+ ret = igt_audio_driver_unload(NULL);
+ if (ret)
+ return ret;
+
+ ret = unload_aux_modules(NULL);
+ if (ret)
+ return ret;
+
+ if (!igt_kmod_is_loaded(driver))
+ return 0;
+
+ igt_kmod_unbind(driver, NULL);
+ ret = igt_kmod_unload(driver);
+
+ return igt_kmod_is_loaded(driver) ? (ret ?: -EBUSY) : 0;
+}
+
+/**
+ * igt_intel_display_prepare_alone:
+ *
+ * Test helper: starts from a state with intel_display loaded on its own, i.e.
+ * without i915 or xe. Any GPU driver still holding the module is unloaded
+ * first, so callers should unload their driver beforehand with the matching
+ * helper. Skips the test if intel_display cannot be unloaded, or if there is
+ * no dedicated intel_display module (kernels with display built into the GPU
+ * driver).
+ */
+void igt_intel_display_prepare_alone(void)
+{
+ int ret;
+
+ igt_require_f(!igt_intel_display_unload(),
+ "Could not unload intel_display\n");
+
+ ret = igt_intel_display_load(NULL);
+ igt_skip_on_f(ret, "No dedicated intel_display module (%d)\n", ret);
+ igt_assert(igt_kmod_is_loaded(INTEL_DISPLAY_MODULE));
+}
+
+/**
+ * igt_assert_intel_driver_and_display_unloaded:
+ * @driver: GPU driver module, e.g. "i915" or "xe"
+ *
+ * Asserts that neither @driver nor intel_display is loaded.
+ */
+void igt_assert_intel_driver_and_display_unloaded(const char *driver)
+{
+ igt_assert_f(!igt_kmod_is_loaded(driver), "%s still loaded\n", driver);
+ igt_assert_f(!igt_kmod_is_loaded(INTEL_DISPLAY_MODULE),
+ "%s still loaded\n", INTEL_DISPLAY_MODULE);
+}
+
+int __igt_intel_driver_unload(char **who, const char *driver)
+{
+ int ret;
+
+ ret = igt_audio_driver_unload(who);
+ if (ret)
+ return ret;
+
+ ret = unload_aux_modules(who);
+ if (ret)
+ return ret;
+
if (igt_kmod_is_loaded(driver)) {
igt_kmod_unbind(driver, NULL);
@@ -624,7 +818,7 @@ int __igt_intel_driver_unload(char **who, const char *driver)
}
}
- return 0;
+ return intel_display_unload_if_unused(who);
}
static char *kmod_pci_driver_from_module_alloc(const char *mod_name)
@@ -763,6 +957,9 @@ int igt_xe_driver_unload(void)
if (igt_kmod_is_loaded("xe"))
return IGT_EXIT_FAILURE;
+ if (intel_display_unload_if_unused(NULL))
+ return IGT_EXIT_FAILURE;
+
return IGT_EXIT_SUCCESS;
}
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index f6c17ff73..141582f15 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -55,6 +55,13 @@ int igt_audio_driver_load(char **whom);
int igt_intel_driver_load(const char *opts, const char *driver);
int igt_intel_driver_unload(const char *driver);
int __igt_intel_driver_unload(char **who, const char *driver);
+int igt_intel_display_load(const char *opts);
+int igt_intel_display_unload(void);
+int igt_intel_display_try_unload(void);
+bool igt_intel_display_has_holders(void);
+int igt_intel_driver_unload_keep_display(const char *driver);
+void igt_intel_display_prepare_alone(void);
+void igt_assert_intel_driver_and_display_unloaded(const char *driver);
static inline int igt_i915_driver_load(const char *opts)
{
--
2.43.0
next prev parent reply other threads:[~2026-11-24 4:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 4:45 [PATCH i-g-t 0/4] RFC: Add intel_display module support to module load tests Jeevan B
2026-11-24 4:45 ` [PATCH i-g-t 1/4] lib/igt_params: Fall back to intel_display module parameters Jeevan B
2026-11-24 4:45 ` Jeevan B [this message]
2026-11-24 4:45 ` [PATCH i-g-t 3/4] tests/intel/i915_module_load: Add intel_display module subtests Jeevan B
2026-11-24 4:45 ` [PATCH i-g-t 4/4] tests/intel/xe_module_load: " Jeevan B
2026-11-24 5:28 ` ✓ Xe.CI.BAT: success for RFC: Add intel_display module support to module load tests (rev2) Patchwork
2026-11-24 5:47 ` ✗ i915.CI.BAT: failure " Patchwork
2026-11-24 8:36 ` ✗ Xe.CI.FULL: " 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=20261124044559.897167-3-jeevan.b@intel.com \
--to=jeevan.b@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jani.nikula@intel.com \
--cc=karthik.b.s@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.