From: Cyril Hrubis <chrubis@suse.cz>
To: "Li Wang (Hieco)" <li.wang@linux.dev>
Cc: wakel@google.com, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v7 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m
Date: Fri, 6 Nov 2026 13:50:40 +0100 [thread overview]
Message-ID: <au3NIJatDEAIu23h@yuki.lan> (raw)
In-Reply-To: <20261103075722.181317-3-li.wang@linux.dev>
Hi!
> + 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?
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index f055c2e5f..cfa513282 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -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;
> + tst_res(TDEBUG, "Unloading module '%s'", name);
> +
> + 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;
> + 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.
> + }
> +
> + loaded_module_count = 0;
> +}
> +
> static size_t array_len(const char *const kconfigs[])
> {
> size_t i = 0;
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 10ff73397..a9e679bee 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -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();
> }
>
> --
> 2.56.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-11-06 12:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 7:57 [LTP] [PATCH v7 0/4] tst_kconfig: automatic module load/unload for CONFIG_*=m Li Wang (Hieco)
2026-11-03 7:57 ` [LTP] [PATCH v7 1/4] lib: add module is loaded check Li Wang (Hieco)
2026-11-03 10:19 ` [LTP] " linuxtestproject.agent
2026-11-06 12:42 ` [LTP] [PATCH v7 1/4] " Cyril Hrubis
2026-11-03 7:57 ` [LTP] [PATCH v7 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m Li Wang (Hieco)
2026-11-06 12:50 ` Cyril Hrubis [this message]
2026-11-03 7:57 ` [LTP] [PATCH v7 3/4] tst_kconfig: add module mappings for vsock/vsock_loopback Li Wang (Hieco)
2026-11-03 7:57 ` [LTP] [PATCH v7 4/4] testcases: drop manual tst_modprobe() now handled by tst_kconfig Li Wang (Hieco)
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=au3NIJatDEAIu23h@yuki.lan \
--to=chrubis@suse.cz \
--cc=li.wang@linux.dev \
--cc=ltp@lists.linux.it \
--cc=wakel@google.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 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.