From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>,
Jonathan Cavitt <jonathan.cavitt@intel.com>
Subject: [PATCH i-g-t v2] lib/igt_kmod: Rewrite xe unload logic
Date: Thu, 19 Sep 2024 08:11:30 -0700 [thread overview]
Message-ID: <20240919151130.1410357-1-lucas.demarchi@intel.com> (raw)
Stop trying to unload possibly-dependent modules. Loading a module and
probing a module are 2 different things, although the Linux kernel will
by default probe devices when a module is loaded (for pci, configurable
in /sys/bus/pci/drivers_autoprobe).
For the unloading part we can simplify: instead of trying to unload
the modules directly (which may complain that module is already in use)
we just unplug the HW first. For each possible device bound.
This will become part of libkmod in future, but we don't need to wait:
we can implement it in igt too as it's straightforward.
For now this only switches the unload path for xe, but if it works well,
we can switch others in future too.
v2:
- Rename function since now it works for any PCI driver
- Move function so it will be available for i915 too.
Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/2362
Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
lib/igt_kmod.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_kmod.h | 5 +----
2 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 464c0dcf4..75a0d057c 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -660,6 +660,51 @@ int __igt_intel_driver_unload(char **who, const char *driver)
return 0;
}
+/*
+ * Unbind driver from devices. Currently supports only PCI bus
+ */
+static int unbind(const char *driver)
+{
+ char path[PATH_MAX];
+ struct dirent *de;
+ int dirlen;
+ DIR *dir;
+
+ dirlen = snprintf(path, sizeof(path), "/sys/module/%s/drivers/pci:%s/",
+ driver, driver);
+ igt_assert(dirlen < sizeof(path));
+
+ dir = opendir(path);
+
+ /* Module may be loaded, but without any device bound */
+ if (!dir)
+ return 0;
+
+ while ((de = readdir(dir))) {
+ int devfd;
+ bool ret;
+
+ if (de->d_type != DT_LNK || !isdigit(de->d_name[0]))
+ continue;
+
+ devfd = openat(dirfd(dir), de->d_name, O_RDONLY | O_CLOEXEC);
+ igt_assert(devfd >= 0);
+
+ ret = igt_sysfs_set(devfd, "power/control", "auto");
+ igt_assert(ret);
+
+ ret = igt_sysfs_set(devfd, "driver/unbind", de->d_name);
+ igt_assert(ret);
+
+ close(devfd);
+ errno = 0;
+ }
+
+ igt_assert_eq(errno, 0);
+
+ return 0;
+}
+
/**
* igt_intel_driver_unload:
*
@@ -697,6 +742,17 @@ igt_intel_driver_unload(const char *driver)
return 0;
}
+int igt_xe_driver_unload(void)
+{
+ unbind("xe");
+
+ igt_kmod_unload("xe");
+ if (igt_kmod_is_loaded("xe"))
+ return IGT_EXIT_FAILURE;
+
+ return IGT_EXIT_SUCCESS;
+}
+
/**
* igt_amdgpu_driver_load:
* @opts: options to pass to amdgpu driver
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index efb46da12..ee1719a8f 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -63,10 +63,7 @@ static inline int igt_xe_driver_load(const char *opts)
}
-static inline int igt_xe_driver_unload(void)
-{
- return igt_intel_driver_unload("xe");
-}
+int igt_xe_driver_unload(void);
int igt_amdgpu_driver_load(const char *opts);
int igt_amdgpu_driver_unload(void);
--
2.46.1
next reply other threads:[~2024-09-19 15:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-19 15:11 Lucas De Marchi [this message]
2024-09-20 1:13 ` ✓ CI.xeBAT: success for lib/igt_kmod: Rewrite xe unload logic (rev2) Patchwork
2024-09-20 1:26 ` ✓ Fi.CI.BAT: " Patchwork
2024-09-20 5:35 ` ✗ CI.xeFULL: failure " Patchwork
2024-09-20 8:57 ` ✗ Fi.CI.IGT: " 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=20240919151130.1410357-1-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jonathan.cavitt@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