Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] lib/igt_kmod: remove devcoredump before a PCI module unload
@ 2024-01-30 22:37 Rodrigo Vivi
  2024-01-30 23:32 ` ✓ Fi.CI.BAT: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Rodrigo Vivi @ 2024-01-30 22:37 UTC (permalink / raw)
  To: igt-dev; +Cc: Rodrigo Vivi

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@linux.intel.com>
Cc: José Roberto de Souza <jose.souza@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-08 22:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-30 22:37 [RFC] lib/igt_kmod: remove devcoredump before a PCI module unload Rodrigo Vivi
2024-01-30 23:32 ` ✓ Fi.CI.BAT: success for " Patchwork
2024-01-31  0:38 ` ✗ Fi.CI.IGT: failure " Patchwork
2024-01-31  1:07 ` ✓ CI.xeBAT: success " Patchwork
2024-02-01 23:14 ` [RFC] " Lucas De Marchi
2024-03-08 22:20   ` Rodrigo Vivi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox