tst_kconfig: automatic module load/unload for CONFIG_*=m
v7 cover tst_kconfig: automatic module load/unload for CONFIG_*=m
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 v7:
- Split module_count and loaded_module_count: the former is the number of recorded modules, the latter the number successfully loaded.
- Add TERRNO to the TWARN message in tst_kconfig_module_unload().
- Fix the malformed reST bullet "* * Requires root" in keyctl23.c.
Changes in v6:
- Rename tst_kconfig_module_unload_all to tst_kconfig_module_unload.
- Unload modules with delete_module(O_NONBLOCK) instead of tst_modprobe().
- Drop the redundant modules_loaded flag.
- Reword keyctl23 root note instead of removing it.
Changes in v5:
- cve-2025-21756.c: merge drop_privileges into setup and drop cleanup.
- keyctl23.c: remove tst_modprobe() so it can run on Android.
Changes in v4:
- tst_kconfig: fold module_name_for_config() into kconfig_module_record()
- tst_kconfig: move the choice == 'm' gate into kconfig_module_record() and pass struct tst_kconfig_var * instead of the raw config name.
Changes in v3:
- Queue only configs that stay 'm' after kconfig_module_check(), so a module downgraded to 'n' does not abort an otherwise runnable test.
- Unload with "modprobe -r" instead of "rmmod" to also remove dependencies pulled in by modprobe.
- Drop the redundant geteuid() check in the unload path.
- Raise MAX_LOADED_MODULES from 16 to 32.
- cve-2025-21756: drop privileges to nobody after module loading and regain root in cleanup(), so the reproducer runs from a non-root context while the framework can still unload modules.
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 (Hieco) (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 | 21 +++++ include/tst_module.h | 1 + lib/tst_kconfig.c | 91 +++++++++++++++++++++ lib/tst_module.c | 39 +++++++++ lib/tst_test.c | 13 ++- testcases/cve/cve-2025-21756.c | 17 ++++ testcases/cve/cve-2026-46331.c | 7 -- testcases/cve/sctphantom.c | 3 - testcases/kernel/syscalls/keyctl/keyctl23.c | 6 +- testcases/kernel/syscalls/keyctl/keyctl29.c | 3 - testcases/kernel/syscalls/keyctl/keyctl30.c | 3 - 11 files changed, 181 insertions(+), 23 deletions(-)
Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v7 1/4 lib: add module is loaded check
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.
--- include/tst_module.h | 1 + lib/tst_module.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
include/tst_module.h +1 -0
@@ -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 */
lib/tst_module.c +39 -0
@@ -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; +}
Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v7 2/4 tst_kconfig: load and unload kernel modules for CONFIG_*=m
In reply to Li Wang (Hieco)Tests that depend on a config set to =m must currently load the module themselves, and may fail with misleading errors when it is not loaded, e.g. bind() returning EADDRNOTAVAIL for AF_VSOCK when vsock_loopback is missing.
Record the module for every config_module_maps[] entry seen as =m and not already loaded while parsing the kernel config. When needs_kconfigs is set, load them via tst_modprobe() after a successful tst_kconfig_check(), and unload them in reverse order from do_cleanup(). Only modules that were actually loaded are unloaded; modules still in use are skipped. Dependencies pulled in by modprobe are not unloaded.
Modules are only loaded when running as root.
--- include/tst_kconfig.h | 21 ++++++++++ lib/tst_kconfig.c | 89 +++++++++++++++++++++++++++++++++++++++++++ lib/tst_test.c | 13 +++++-- 3 files changed, 120 insertions(+), 3 deletions(-)
include/tst_kconfig.h +21 -0
@@ -105,4 +105,25 @@ void tst_kcmdline_parse(struct tst_kcmdline_var params[], size_t params_len);*/ int tst_has_slow_kconfig (void ); +/** +* tst_kconfig_module_load() - Load kernel modules for CONFIG_*=m entries. +* +* Loads the modules for CONFIG_* options found as =m in the kernel config +* that are not already loaded, in the order they were found. +* Does nothing when not running as root. +*/ +void tst_kconfig_module_load (void ); + +/** +* tst_kconfig_module_unload() - Unload modules loaded by +* tst_kconfig_module_load(). +* +* Unloads, in reverse order, only the modules that were actually loaded. +* Modules still in use are skipped silently. Dependencies pulled in by +* modprobe are not unloaded. +* +* Called from do_cleanup(), so it runs regardless of the test result. +*/ +void tst_kconfig_module_unload (void ); +#endif /* TST_KCONFIG_H__ */
lib/tst_kconfig.c +89 -0
115 lines not on this page · raw message
lib/tst_test.c +10 -3
@@ -1471,12 +1471,16 @@ static void do_setup(int argc, char *argv[])check_supported_kver (); -if (tst_test->needs_kconfigs &&tst_kconfig_check (tst_test->needs_kconfigs)) -tst_brk (TCONF ,"Aborting due to unsuitable kernel config, see above!" ); -if (tst_test->needs_root &&geteuid () !=0 )tst_brk (TCONF ,"Test needs to be run as root" ); +if (tst_test->needs_kconfigs) { +if (tst_kconfig_check (tst_test->needs_kconfigs)) +tst_brk (TCONF ,"Aborting due to unsuitable kernel config, see above!" ); + +tst_kconfig_module_load (); + } +if (tst_test->min_kver)check_kver (tst_test->min_kver,1 );
@@ -1690,6 +1694,9 @@ static void do_cleanup(void)if (tst_test->restore_wallclock)tst_wallclock_restore (); +if (tst_test->needs_kconfigs) +tst_kconfig_module_unload (); +cleanup_ipc (); }
Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v7 3/4 tst_kconfig: add module mappings for vsock/vsock_loopback
In reply to Li Wang (Hieco)Map CONFIG_VSOCKETS to "vsock" and CONFIG_VSOCKETS_LOOPBACK to "vsock_loopback" so tst_kconfig can load them on demand.
cve-2025-21756 binds to VMADDR_CID_LOCAL and therefore needs vsock_loopback. Without the module loaded, bind() fails with EADDRNOTAVAIL and the test aborts with TBROK. Declare both configs in needs_kconfigs so the modules are loaded first.
The test needs root only to load the modules; the reproducer runs as an ordinary non-root process in the initial namespace, where it can use loopback VSOCK on non-privileged ports. Drop privileges to nobody in setup() after the modules are loaded; the framework unloads the modules from its still-root context, so no restore is needed in cleanup().
--- lib/tst_kconfig.c | 2 ++ testcases/cve/cve-2025-21756.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+)
lib/tst_kconfig.c +2 -0
@@ -175,6 +175,8 @@ static struct config_module_map { {"CONFIG_NET_ACT_PEDIT", "act_pedit"}, {"CONFIG_PKCS8_PRIVATE_KEY_PARSER", "pkcs8_key_parser"}, {"CONFIG_X509_CERTIFICATE_PARSER", "x509_key_parser"}, + {"CONFIG_VSOCKETS", "vsock"}, + {"CONFIG_VSOCKETS_LOOPBACK", "vsock_loopback"}, {} };
testcases/cve/cve-2025-21756.c +17 -0
@@ -13,12 +13,22 @@* Beware, this test will crash the system. */ +#include <pwd.h> +#include "tst_test.h" #include "lapi/vm_sockets.h" #define MAX_PORT_RETRIES 24#define VMADDR_CID_NONEXISTING 42 +static void setup (void ) +{ +struct passwd *pw =SAFE_GETPWNAM ("nobody" ); + +SAFE_SETEGID (pw->pw_gid); +SAFE_SETEUID (pw->pw_uid); +} +static int vsock_bind (unsigned int cid,unsigned int port,int type) {int sock;
@@ -85,8 +95,15 @@ static void run(void) }static struct tst_test test = { + .needs_root =1 , + .setup = setup, .test_all = run, .taint_check =TST_TAINT_W |TST_TAINT_D , + .needs_kconfigs = (const char *const []) { +"CONFIG_VSOCKETS" , +"CONFIG_VSOCKETS_LOOPBACK" , +NULL + }, .tags = (const struct tst_tag []) { {"linux-git" ,"fcdd2242c0231032fc84e1404315c245ae56322a" }, {"CVE" ,"2025-21756" },
Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v7 4/4 testcases: drop manual tst_modprobe() now handled by tst_kconfig
In reply to Li Wang (Hieco)Now that tst_kconfig loads the modules for every CONFIG_*=m entry listed in config_module_maps[] and unloads them again at cleanup time, tests no longer have to call tst_modprobe() from setup().
Drop the explicit tst_modprobe() calls, and the now unused tst_module.h includes, from:
- cve-2026-46331.c: sch_ingress, cls_matchall, act_pedit
- sctphantom.c: sctp
- keyctl23.c: x509_key_parser
- keyctl29.c: x509_key_parser
- keyctl30.c: pkcs8_key_parser
All tests already declare the matching configs in .needs_kconfigs, so tst_kconfig takes care of loading the modules before setup() runs and unloading them once the test finishes.
BTW, with KCONFIG_SKIP_CHECK=1 the config check returns early, so the automatic module loading is skipped as well. Users who set that variable are expected to ensure the required modules are loaded themselves.
--- testcases/cve/cve-2026-46331.c | 7 ------- testcases/cve/sctphantom.c | 3 --- testcases/kernel/syscalls/keyctl/keyctl23.c | 6 ++---- testcases/kernel/syscalls/keyctl/keyctl29.c | 3 --- testcases/kernel/syscalls/keyctl/keyctl30.c | 3 --- 5 files changed, 2 insertions(+), 20 deletions(-)
testcases/cve/cve-2026-46331.c +0 -7
@@ -44,7 +44,6 @@#include <linux/rtnetlink.h> #include "tst_test.h" -#include "tst_module.h" #include "tst_net.h" #include "tst_netdevice.h" #include "lapi/if_ether.h"
@@ -136,12 +135,6 @@ static void setup(void) {struct sockaddr_in addr;struct passwd *pw; -static const char *const mods[] = { -"sch_ingress" ,"cls_matchall" ,"act_pedit" - }; - -for (unsigned int i =0 ; i <ARRAY_SIZE (mods); i++) -tst_modprobe (mods[i],NULL );/* Drop privileges so the reproducer runs as an unprivileged user */ pw =SAFE_GETPWNAM ("nobody" );
testcases/cve/sctphantom.c +0 -3
@@ -50,7 +50,6 @@*/ #include "tst_test.h" -#include "tst_module.h" #include "tst_checksum.h" #include "tst_safe_net.h"
@@ -205,8 +204,6 @@ static void setup(void) };const struct tst_path_val *sysctl; -tst_modprobe ("sctp" ,NULL ); -for (sysctl = sysctls; sysctl->path; sysctl++)tst_sys_conf_save (sysctl);
testcases/kernel/syscalls/keyctl/keyctl23.c +2 -4
@@ -6,7 +6,8 @@/*\ * Test ``KEYCTL_RESTRICT_KEYRING`` builtin_trusted of :manpage:`keyctl(2)`. * -* Requires root (CAP_SYS_MODULE) to load the ``x509_key_parser`` module. +* Requires root (CAP_SYS_MODULE) so that the test library can load the +* ``x509_key_parser`` module. * * [Algorithm] *
@@ -16,7 +17,6 @@*/ #include "keyctl_common.h" -#include "tst_module.h" #define PAYLOAD "payload"
@@ -89,8 +89,6 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); -tst_modprobe ("x509_key_parser" ,NULL ); - ring_builtin =SAFE_NEW_RING ("ltpkeyctl23_builtin" ); user_key = SAFE_NEW_USER_KEY("k", PAYLOAD, sizeof(PAYLOAD),
testcases/kernel/syscalls/keyctl/keyctl29.c +0 -3
@@ -23,7 +23,6 @@#include "keyctl_common.h" #include "keyctl_pkey_data.h" -#include "tst_module.h" static key_serial_t cert_key;static struct keyctl_pkey_query *query_buf;
@@ -32,8 +31,6 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); -tst_modprobe ("x509_key_parser" ,NULL ); - cert_key =add_asymmetric_key_or_tconf ("cert" , rsa2048_cert,sizeof (rsa2048_cert),"CONFIG_X509_CERTIFICATE_PARSER" );
testcases/kernel/syscalls/keyctl/keyctl30.c +0 -3
@@ -20,7 +20,6 @@#include "keyctl_common.h" #include "keyctl_pkey_data.h" -#include "tst_module.h" static key_serial_t priv_key;static struct keyctl_pkey_query *query_buf;
@@ -29,8 +28,6 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); -tst_modprobe ("pkcs8_key_parser" ,NULL ); - priv_key =add_asymmetric_key_or_tconf ("priv" , rsa2048_pkcs8,sizeof (rsa2048_pkcs8),"CONFIG_PKCS8_PRIVATE_KEY_PARSER" );
Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lib: add module is loaded check
In reply to Li Wang (Hieco)Hi Li,
Quoted 1 line · Li Wang
lib: add module is loaded check
--- [PATCH 1/4] ---
include/tst_module.h static inline void tst_requires_module_signature_disabled(void) · line 52
Quoted 9 lines
include/tst_module.h +1
-0@@ -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);
New public library functions in include/ should have a kernel-doc (/** ... */) comment describing @mod_name and Return:.
--- [PATCH 3/4] ---
testcases/cve/cve-2025-21756.c static void run(void) · line 99
Quoted 10 lines
testcases/cve/cve-2025-21756.c +2
-0@@ -85,8 +95,15 @@ static void run(void) }static struct tst_test test = { + .needs_root =1 , + .setup = setup,
The reason .needs_root = 1 is required (loading the vsock and vsock_loopback modules before dropping privileges in setup()) should also be documented in the test's /*\ ... */ doc comment.
--- [PATCH 4/4] ---
Quoted 15 lines
testcases/kernel/syscalls/keyctl/keyctl23.c +2
-1@@ -6,7 +6,8 @@/*\ * Test ``KEYCTL_RESTRICT_KEYRING`` builtin_trusted of :manpage:`keyctl(2)`. * -* Requires root (CAP_SYS_MODULE) to load the ``x509_key_parser`` module. +* Requires root (CAP_SYS_MODULE) so that the test library can load the +* ``x509_key_parser`` module. * * [Algorithm] *
testcases/kernel/syscalls/keyctl/keyctl23.c static void setup(void) · line 92
Quoted 6 lines
testcases/kernel/syscalls/keyctl/keyctl23.c +0
-2@@ -89,8 +89,6 @@ static void setup(void) {SAFE_KEYCTL (KEYCTL_JOIN_SESSION_KEYRING ,0 ,0 ,0 ,0 ); -tst_modprobe ("x509_key_parser" ,NULL ); - ring_builtin =SAFE_NEW_RING ("ltpkeyctl23_builtin" );
keyctl23.c still has "CONFIG_X509_CERTIFICATE_PARSER=y" in .needs_kconfigs instead of "CONFIG_X509_CERTIFICATE_PARSER", so tst_kconfig_check() aborts with TCONF when the option is =m before tst_kconfig_module_load() is called, and never loads a module when it is =y. Drop =y from "CONFIG_X509_CERTIFICATE_PARSER=y" in .needs_kconfigs (matching keyctl29.c) so CONFIG_X509_CERTIFICATE_PARSER=m is accepted and x509_key_parser is loaded automatically.
Verdict - Needs revision
Pre-existing issues:
- testcases/cve/sctphantom.c: the doc comment at lines 46-48 still says the test reports TCONF if the sctp module is not loaded ("run modprobe sctp first"), and the sysctls saved via tst_sys_conf_save() in setup() could now use .save_restore in struct tst_test since do_setup() loads the module before .save_restore and do_cleanup() unloads it after tst_sys_conf_restore().
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v7 1/4] lib: add module is loaded check
In reply to Li Wang (Hieco)Hi!
lib/tst_module.c void tst_module_reload(const char *mod_name, char *const argv[]) · line 207
Quoted 1 line
lib/tst_module.c +1
-0+if (i == mod_len) {
Shouldn't we check that next character is a whitespace here?
I guess that module name that is prefix of unrelated module is going to be rare but it's not impossible.
Quoted 8 lines
lib/tst_module.c +8
-0+fclose (file); +return true; + } + } + +fclose (file); +return false; +}
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v7 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m
In reply to Li Wang (Hieco)Hi!
Review
Quoted 6 lines
(quoted diff) +6
-0+ while (loaded_module_count > 0) { + snprintf(name, sizeof(name), "%s", + loaded_modules[--loaded_module_count]); + + for (p = name; (p = strchr(p, '-')); ) + *p = '_';
Wouldn't it be easier to enforce the module names to have only underscores?
lib/tst_kconfig.c +3 -0
@@ -175,6 +175,9 @@ static void kconfig_module_check(struct tst_kconfig_var *var)size_t i;for (i =0 ; config_module_maps[i].config; i++) { +if (strchr (config_module_map[i].module_name,'-' )) +tst_brk (TBROK ,"Module names must contain only '_' not '-'" ); +if (strcmp (config_module_maps[i].config, var->id))continue ;
Quoted 4 lines
(quoted diff) +4
-0+ tst_res(TDEBUG, "Unloading module '%s'", name); + + if (!syscall(__NR_delete_module, name, O_NONBLOCK)) + continue;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + switch (errno) { + case ENOENT: /* already unloaded */ + case EWOULDBLOCK: /* in use */ + case EBUSY: /* still loading or unloading */ + case ENOSYS: /* no CONFIG_MODULE_UNLOAD */ + break; + default: + tst_res(TWARN | TERRNO, "Failed to unload module '%s'", name); + }
Why not 'modprobe -r' the main difference is that 'modprobe -r' removes all unused depended modules. If anything loaded as a dependency of the module we loaded we are not going to be able to remove the module this way.
Quoted 48 lines
(quoted diff) +5
-0+ } + + loaded_module_count = 0; +} + static size_t array_len(const char *const kconfigs[]) { size_t i = 0;lib/tst_test.c +10
-3@@ -1471,12 +1471,16 @@ static void do_setup(int argc, char *argv[])check_supported_kver (); -if (tst_test->needs_kconfigs &&tst_kconfig_check (tst_test->needs_kconfigs)) -tst_brk (TCONF ,"Aborting due to unsuitable kernel config, see above!" ); -if (tst_test->needs_root &&geteuid () !=0 )tst_brk (TCONF ,"Test needs to be run as root" ); +if (tst_test->needs_kconfigs) { +if (tst_kconfig_check (tst_test->needs_kconfigs)) +tst_brk (TCONF ,"Aborting due to unsuitable kernel config, see above!" ); + +tst_kconfig_module_load (); + } +if (tst_test->min_kver)check_kver (tst_test->min_kver,1 );@@ -1690,6 +1694,9 @@ static void do_cleanup(void)if (tst_test->restore_wallclock)tst_wallclock_restore (); +if (tst_test->needs_kconfigs) +tst_kconfig_module_unload (); +cleanup_ipc (); }Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v7 1/4] lib: add module is loaded check
In reply to Cyril HrubisQuoted 7 lines
Hi!
lib/tst_module.c void tst_module_reload(const char *mod_name, char *const argv[]) · line 207
Quoted 1 line
lib/tst_module.c +1
-0+if (i == mod_len) {Shouldn't we check that next character is a whitespace here?
I guess that module name that is prefix of unrelated module is going to be rare but it's not impossible.
The length check above already guarantees this: p is advanced to the first whitespace, so (p - line) is the length of the whole module name field. If mod_name were a prefix of an unrelated module, the lengths would differ and we continue before the character comparison. By the time i == mod_len, line[mod_len] is exactly the field boundary.
if ((size_t)(p - line) != mod_len)
continue;Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v7 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m
In reply to Cyril HrubisQuoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ for (p = name; (p = strchr(p, '-')); ) + *p = '_';Wouldn't it be easier to enforce the module names to have only underscores?
Good point.
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9
-0+ if (!syscall(__NR_delete_module, name, O_NONBLOCK)) + continue; + + switch (errno) { + case ENOENT: /* already unloaded */ + case EWOULDBLOCK: /* in use */ + case EBUSY: /* still loading or unloading */ + case ENOSYS: /* no CONFIG_MODULE_UNLOAD */ + break;
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ default: + tst_res(TWARN | TERRNO, "Failed to unload module '%s'", name); + }Why not 'modprobe -r' the main difference is that 'modprobe -r' removes all unused depended modules. If anything loaded as a dependency of the module we loaded we are not going to be able to remove the module this way.
That was intentional. modprobe -r also removes unused dependencies, including ones that were already loaded before the test. E.g. if can is already loaded (but unused) and the test loads can-raw, then 'modprobe -r can-raw' removes both, i.e. cleanup would unload a module the test did not load.
With delete_module() we remove only the module we loaded ourselves. That always works, since dependencies do not hold a reference on the module that uses them. The downside is that dependencies pulled in by modprobe stay loaded after the test.
It's a trade-off: I'd rather leave a few extra modules loaded on the SUT than remove modules that were there before the test started.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v7 1/4] lib: add module is loaded check
In reply to Li WangHi!
Quoted 8 lines
The length check above already guarantees this: p is advanced to the first whitespace, so (p - line) is the length of the whole module name field. If
mod_namewere a prefix of an unrelated module, the lengths would differ and we continue before the character comparison. By the time i ==mod_len, line[mod_len] is exactly the field boundary.if ((size_t)(p - line) != mod_len) continue;
Sorry, of course it's right there, missed that.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v7 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m
In reply to Li WangHi Cyril,
Quoted 24 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9
-0+ if (!syscall(__NR_delete_module, name, O_NONBLOCK)) + continue; + + switch (errno) { + case ENOENT: /* already unloaded */ + case EWOULDBLOCK: /* in use */ + case EBUSY: /* still loading or unloading */ + case ENOSYS: /* no CONFIG_MODULE_UNLOAD */ + break;Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ default: + tst_res(TWARN | TERRNO, "Failed to unload module '%s'", name); + }Why not 'modprobe -r' the main difference is that 'modprobe -r' removes all unused depended modules. If anything loaded as a dependency of the module we loaded we are not going to be able to remove the module this way.
That was intentional. modprobe -r also removes unused dependencies, including ones that were already loaded before the test. E.g. if can is already loaded (but unused) and the test loads can-raw, then 'modprobe -r can-raw' removes both, i.e. cleanup would unload a module the test did not load.
Quoted 7 lines
With
delete_module()we remove only the module we loaded ourselves. That always works, since dependencies do not hold a reference on the module that uses them. The downside is that dependencies pulled in by modprobe stay loaded after the test.It's a trade-off: I'd rather leave a few extra modules loaded on the SUT than remove modules that were there before the test started.
Any comments on this trade-off? If not, I'll go ahead and apply the patchset.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp