[RFC] lib/igt_kmod: remove devcoredump before a PCI module unload
Rodrigo Vivi
rodrigo.vivi at intel.com
Tue Jan 30 22:37:02 UTC 2024
devcoredump holds a module reference, blocking the module removal.
It is intentional from the devcoredump perspective to keep the
log available even after the unbind/unprobe. However it blocks
our module removal here.
Cc: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
Cc: José Roberto de Souza <jose.souza at intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi at intel.com>
---
lib/igt_kmod.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 250ab2107..da44a7bca 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -323,6 +323,58 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags)
return err;
}
+#define MAX_PATH 256
+
+static void _igt_remove_devcoredump(const char *driver)
+{
+ char sysfspath[MAX_PATH];
+ DIR *dir;
+ char devcoredump[MAX_PATH];
+ FILE *data;
+ struct dirent *entry;
+
+ snprintf(sysfspath, sizeof(sysfspath),
+ "/sys/module/%s/drivers/pci:%s/", driver, driver);
+
+ /* Not a PCI module */
+ if(access(sysfspath, F_OK) == -1)
+ return;
+
+ dir = opendir(sysfspath);
+ igt_assert(dir);
+
+ while ((entry = readdir(dir)) != NULL) {
+ if (entry->d_type == DT_LNK && strcmp(entry->d_name, ".") != 0
+ && strcmp(entry->d_name, "..") != 0) {
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-truncation"
+ snprintf(devcoredump, sizeof(devcoredump),
+ "%s/%s/devcoredump", sysfspath, entry->d_name);
+#pragma GCC diagnostic pop
+
+ igt_info("%s\n", devcoredump);
+
+ if (access(devcoredump, F_OK) != -1) {
+ igt_info("Removing devcoredump before module unload: %s\n",
+ devcoredump);
+
+ strcat(devcoredump, "/data");
+ data = fopen(devcoredump, "w");
+ igt_assert(data);
+
+ /*
+ * Write anything to devcoredump/data to
+ * force its deletion
+ */
+ fprintf(data, "1\n");
+ fclose(data);
+ }
+ }
+ }
+ closedir(dir);
+}
+
/**
* igt_kmod_unload:
* @mod_name: Module name.
@@ -341,6 +393,8 @@ igt_kmod_unload(const char *mod_name, unsigned int flags)
struct kmod_module *kmod;
int err;
+ _igt_remove_devcoredump(mod_name);
+
err = kmod_module_new_from_name(ctx, mod_name, &kmod);
if (err < 0) {
igt_debug("Could not use module %s (%s)\n", mod_name,
--
2.43.0
More information about the igt-dev
mailing list