From: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>,
Kamil Konieczny <kamil.konieczny@linux.intel.com>,
Francois Dugast <francois.dugast@intel.com>,
Lukasz Laguna <lukasz.laguna@intel.com>
Subject: [PATCH v3 i-g-t 4/7] lib/igt_kmod: Fix PCI bind/unbind for module/driver name mismatch
Date: Wed, 4 Feb 2026 17:32:07 +0100 [thread overview]
Message-ID: <20260204163217.121305-5-marcin.bernatowicz@linux.intel.com> (raw)
In-Reply-To: <20260204163217.121305-1-marcin.bernatowicz@linux.intel.com>
igt_kmod_bind() and igt_kmod_unbind() assumed that the PCI
driver name was identical to the module name, which is not true
for drivers such as xe_vfio_pci (module) vs xe-vfio-pci (driver).
Resolve the registered PCI driver name via
/sys/module/<module>/drivers/pci:* and forward bind/unbind operations
to the generic PCI driver helpers.
Mark these helpers as deprecated, as bind/unbind are fundamentally
driver-level operations. New code should prefer the igt_pci_driver_*
APIs, while these wrappers remain for backwards compatibility and
“unbind before module unload” workflows.
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Francois Dugast <francois.dugast@intel.com>
Reviewed-by: Lukasz Laguna <lukasz.laguna@intel.com>
---
lib/igt_kmod.c | 90 ++++++++++++++++++++++++++++----------------------
1 file changed, 51 insertions(+), 39 deletions(-)
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index d1d7a3840..008752f29 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -44,6 +44,7 @@
#include "igt_hook.h"
#include "igt_kmod.h"
#include "igt_ktap.h"
+#include "igt_pci.h"
#include "igt_sysfs.h"
#include "igt_taints.h"
@@ -598,43 +599,58 @@ int __igt_intel_driver_unload(char **who, const char *driver)
return 0;
}
+static char *kmod_pci_driver_from_module_alloc(const char *mod_name)
+{
+ char dirpath[PATH_MAX];
+ struct dirent *de;
+ DIR *d;
+
+ snprintf(dirpath, sizeof(dirpath), "/sys/module/%s/drivers", mod_name);
+ d = opendir(dirpath);
+ if (!d)
+ return NULL;
+
+ while ((de = readdir(d))) {
+ if (!strncmp(de->d_name, "pci:", 4)) {
+ char *drv = strdup(de->d_name + 4);
+
+ closedir(d);
+ return drv;
+ }
+ }
+
+ closedir(d);
+ return NULL;
+}
+
/**
* igt_kmod_unbind: Unbind driver from devices. Currently supports only PCI bus
* @mod_name: name of the module to unbind
* @pci_device: if provided, unbind only this device, otherwise unbind all devices
+ *
+ * Deprecated: bind/unbind is a driver operation. Prefer using:
+ * - igt_pci_driver_unbind()/igt_pci_driver_unbind_all()
+ * - igt_pci_device_unbind()
+ *
+ * This helper remains for backwards compatibility and for “unbind before
+ * module unload” workflows.
*/
int igt_kmod_unbind(const char *mod_name, const char *pci_device)
{
struct igt_hook *igt_hook = NULL;
- char path[PATH_MAX];
- struct dirent *de;
- int dirlen;
- DIR *dir;
-
- dirlen = snprintf(path, sizeof(path), "/sys/module/%s/drivers/pci:%s/",
- mod_name, mod_name);
- igt_assert(dirlen < sizeof(path));
-
- dir = opendir(path);
-
- /* Module not loaded, nothing to unbind */
- if (!dir)
- return 0;
-
- while ((de = readdir(dir))) {
- bool ret;
-
- if (de->d_type != DT_LNK || !isdigit(de->d_name[0]))
- continue;
+ char *driver;
+ int ret;
- if (pci_device && strcmp(pci_device, de->d_name) != 0)
- continue;
+ driver = kmod_pci_driver_from_module_alloc(mod_name);
+ if (!driver)
+ return 0; /* module not loaded / no pci driver */
- ret = igt_sysfs_set(dirfd(dir), "unbind", de->d_name);
- igt_assert(ret);
- }
+ if (pci_device)
+ ret = igt_pci_driver_unbind(driver, pci_device);
+ else
+ ret = igt_pci_driver_unbind_all(driver);
- closedir(dir);
+ free(driver);
igt_hook = igt_core_get_igt_hook();
igt_hook_event_notify(igt_hook, &(struct igt_hook_evt){
@@ -642,7 +658,7 @@ int igt_kmod_unbind(const char *mod_name, const char *pci_device)
.target_name = mod_name,
});
- return 0;
+ return ret;
}
/**
@@ -651,25 +667,21 @@ int igt_kmod_unbind(const char *mod_name, const char *pci_device)
* @pci_device: device to bind
*
* Module should already be loaded
+ *
+ * Deprecated: prefer igt_pci_driver_bind().
*/
int igt_kmod_bind(const char *mod_name, const char *pci_device)
{
- char path[PATH_MAX];
- int dirlen, dirfd;
+ char *driver;
int ret;
- dirlen = snprintf(path, sizeof(path), "/sys/module/%s/drivers/pci:%s/",
- mod_name, mod_name);
- igt_assert(dirlen < sizeof(path));
-
- dirfd = open(path, O_RDONLY | O_CLOEXEC);
- if (dirfd < 0)
- return dirfd;
-
- ret = igt_sysfs_set(dirfd, "bind", pci_device);
+ driver = kmod_pci_driver_from_module_alloc(mod_name);
+ if (!driver)
+ return -ENOENT;
- close(dirfd);
+ ret = igt_pci_driver_bind(driver, pci_device);
+ free(driver);
return ret;
}
--
2.43.0
next prev parent reply other threads:[~2026-02-04 16:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-04 16:32 [PATCH v3 i-g-t 0/7] PCI driver helpers and xe-vfio-pci FLR improvement Marcin Bernatowicz
2026-02-04 16:32 ` [PATCH v3 i-g-t 1/7] lib/igt_sriov_device: Add helper to get VF PCI slot address Marcin Bernatowicz
2026-02-04 16:32 ` [PATCH v3 i-g-t 2/7] lib/igt_pci: Add generic PCI driver override and bind/unbind helpers Marcin Bernatowicz
2026-02-09 10:16 ` Laguna, Lukasz
2026-02-10 10:19 ` Bernatowicz, Marcin
2026-02-11 6:39 ` Laguna, Lukasz
2026-02-11 11:21 ` Bernatowicz, Marcin
2026-02-04 16:32 ` [PATCH v3 i-g-t 3/7] tests/intel/xe_sriov_flr: Attach VFs to xe-vfio-pci before initiating FLR Marcin Bernatowicz
2026-02-09 10:17 ` Laguna, Lukasz
2026-02-04 16:32 ` Marcin Bernatowicz [this message]
2026-02-04 16:32 ` [PATCH v3 i-g-t 5/7] tests/intel/xe_sriov_flr: Add --wait-flr-ms option Marcin Bernatowicz
2026-02-09 10:18 ` Laguna, Lukasz
2026-02-04 16:32 ` [PATCH v3 i-g-t 6/7] tests/intel/xe_sriov_flr: Add --no-xe-vfio-pci option Marcin Bernatowicz
2026-02-09 10:18 ` Laguna, Lukasz
2026-02-04 16:32 ` [PATCH v3 i-g-t 7/7] tests/intel/xe_sriov_flr: Skip xe-vfio-pci load/bind when IOMMU is off Marcin Bernatowicz
2026-02-09 10:42 ` Laguna, Lukasz
2026-02-10 11:23 ` Bernatowicz, Marcin
2026-02-11 6:43 ` Laguna, Lukasz
2026-02-04 18:27 ` ✓ Xe.CI.BAT: success for PCI driver helpers and xe-vfio-pci FLR improvement (rev3) Patchwork
2026-02-04 18:41 ` ✓ i915.CI.BAT: " Patchwork
2026-02-05 5:02 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-02-05 10:13 ` Bernatowicz, Marcin
2026-02-05 8:13 ` ✓ i915.CI.Full: success " 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=20260204163217.121305-5-marcin.bernatowicz@linux.intel.com \
--to=marcin.bernatowicz@linux.intel.com \
--cc=francois.dugast@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=lukasz.laguna@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