[LTP] [PATCH v7 2/4] tst_kconfig: load and unload kernel modules for CONFIG_*=m

Cyril Hrubis chrubis@suse.cz
Fri Nov 6 13:50:40 CET 2026


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


More information about the ltp mailing list