All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [Patch v2 0/4] tst_kconfig: automatic module load/unload for CONFIG_*=m
@ 2026-10-08  5:21 Li Wang
  2026-10-08  5:21 ` [LTP] [Patch v2 1/4] lib: add module is loaded check Li Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Li Wang @ 2026-10-08  5:21 UTC (permalink / raw)
  To: ltp

Tests that depend on a config set to =m currently load the module
themselves, and may fail with misleading errors when it is missing,
e.g. bind() returning EADDRNOTAVAIL for AF_VSOCK without vsock_loopback.

This series makes tst_kconfig record the module for every
config_module_maps[] entry seen as =m, load them once the kernel
config check passes, and unload them at cleanup time.

Changes in v2:

- Add tst_module_is_loaded() helper.
- Only load/unload modules that are not already loaded.
- Skip automatic loading when KCONFIG_SKIP_CHECK=1, keeping the
  semantics consistent with skipping the config check.
- Document the KCONFIG_SKIP_CHECK=1 behaviour for keyctl29/keyctl30
  and the vsock/vsock_loopback mapping.

Li Wang (4):
  lib: add module is loaded check
  tst_kconfig: load and unload kernel modules for CONFIG_*=m
  tst_kconfig: add module mappings for vsock/vsock_loopback
  testcases: drop manual tst_modprobe() now handled by tst_kconfig

 include/tst_kconfig.h                       | 28 +++++++
 include/tst_module.h                        |  1 +
 lib/tst_kconfig.c                           | 81 +++++++++++++++++++++
 lib/tst_module.c                            | 39 ++++++++++
 lib/tst_test.c                              | 11 ++-
 testcases/cve/cve-2025-21756.c              |  6 ++
 testcases/cve/cve-2026-46331.c              |  7 --
 testcases/cve/sctphantom.c                  |  3 -
 testcases/kernel/syscalls/keyctl/keyctl29.c |  3 -
 testcases/kernel/syscalls/keyctl/keyctl30.c |  3 -
 10 files changed, 164 insertions(+), 18 deletions(-)

-- 
2.56.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [LTP] [PATCH v3 1/4] lib: add module is loaded check
@ 2026-10-10  3:36 Li Wang
  2026-10-10  9:38 ` [LTP] " linuxtestproject.agent
  0 siblings, 1 reply; 8+ messages in thread
From: Li Wang @ 2026-10-10  3:36 UTC (permalink / raw)
  To: ltp

Add a helper that checks whether a kernel module is loaded by
looking it up in /proc/modules. Module names are normalized so that
hyphens match the underscores used by the kernel.

Signed-off-by: Li Wang <li.wang@linux.dev>
---
 include/tst_module.h |  1 +
 lib/tst_module.c     | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/tst_module.h b/include/tst_module.h
index e55321d19..9b789e289 100644
--- a/include/tst_module.h
+++ b/include/tst_module.h
@@ -49,5 +49,6 @@ static inline void tst_requires_module_signature_disabled(void)
 
 void tst_modprobe(const char *mod_name, char *const argv[]);
 void tst_module_reload(const char *mod_name, char *const argv[]);
+bool tst_module_is_loaded(const char *mod_name);
 
 #endif /* TST_MODULE_H */
diff --git a/lib/tst_module.c b/lib/tst_module.c
index cbd2415d5..db341ec57 100644
--- a/lib/tst_module.c
+++ b/lib/tst_module.c
@@ -21,6 +21,7 @@
  */
 
 #define _GNU_SOURCE
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -174,3 +175,41 @@ void tst_module_reload(const char *mod_name, char *const argv[])
 	tst_module_unload_(NULL, mod_name);
 	tst_modprobe(mod_name, argv);
 }
+
+bool tst_module_is_loaded(const char *mod_name)
+{
+	char line[4096];
+	size_t mod_len = strlen(mod_name);
+	FILE *file;
+
+	file = fopen("/proc/modules", "r");
+	if (!file)
+		return false;
+
+	while (fgets(line, sizeof(line), file)) {
+		char *p = line;
+		size_t i;
+
+		while (*p && !isspace(*p))
+			p++;
+
+		if ((size_t)(p - line) != mod_len)
+			continue;
+
+		for (i = 0; i < mod_len; i++) {
+			char a = (line[i] == '-') ? '_' : line[i];
+			char b = (mod_name[i] == '-') ? '_' : mod_name[i];
+
+			if (a != b)
+				break;
+		}
+
+		if (i == mod_len) {
+			fclose(file);
+			return true;
+		}
+	}
+
+	fclose(file);
+	return false;
+}
-- 
2.56.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2026-10-10  9:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08  5:21 [LTP] [Patch v2 0/4] tst_kconfig: automatic module load/unload for CONFIG_*=m Li Wang
2026-10-08  5:21 ` [LTP] [Patch v2 1/4] lib: add module is loaded check Li Wang
2026-10-08 10:14   ` [LTP] " linuxtestproject.agent
2026-10-10  1:43     ` Li Wang
2026-10-08  5:21 ` [LTP] [Patch v2 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m Li Wang
2026-10-08  5:21 ` [LTP] [Patch v2 3/4] tst_kconfig: add module mappings for vsock/vsock_loopback Li Wang
2026-10-08  5:21 ` [LTP] [Patch v2 4/4] testcases: drop manual tst_modprobe() now handled by tst_kconfig Li Wang
  -- strict thread matches above, loose matches on Subject: below --
2026-10-10  3:36 [LTP] [PATCH v3 1/4] lib: add module is loaded check Li Wang
2026-10-10  9:38 ` [LTP] " linuxtestproject.agent

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.