Skip to content

Commit 92f3c5a

Browse files
Herton R. Krzesinskiakpm00
authored andcommitted
lib/test_kmod: do not hardcode/depend on any filesystem
Right now test_kmod has hardcoded dependencies on btrfs/xfs. That is not optimal since you end up needing to select/build them, but it is not really required since other fs could be selected for the testing. Also, we can't change the default/driver module used for testing on initialization. Thus make it more generic: introduce two module parameters (start_driver and start_test_fs), which allow to select which modules/fs to use for the testing on test_kmod initialization. Then it's up to the user to select which modules/fs to use for testing based on his config. However, keep test_module as required default. This way, config/modules becomes selectable as when the testing is done from selftests (userspace). While at it, also change trigger_config_run_type, since at module initialization we already set the defaults at __kmod_config_init and should not need to do it again in test_kmod_init(), thus we can avoid to again set test_driver/test_fs. Link: https://lkml.kernel.org/r/20250418165047.702487-1-herton@redhat.com Signed-off-by: Herton R. Krzesinski <herton@redhat.com> Reviewed-by: Luis Chambelrain <mcgrof@kernel.org> Cc: Daniel Gomez <da.gomez@samsung.com> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Petr Pavlu <petr.pavlu@suse.com> Cc: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 2a1c615 commit 92f3c5a

File tree

3 files changed

+34
-41
lines changed

3 files changed

+34
-41
lines changed

lib/Kconfig.debug

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,13 +2983,7 @@ config TEST_DYNAMIC_DEBUG
29832983
config TEST_KMOD
29842984
tristate "kmod stress tester"
29852985
depends on m
2986-
depends on NETDEVICES && NET_CORE && INET # for TUN
2987-
depends on BLOCK
2988-
depends on PAGE_SIZE_LESS_THAN_256KB # for BTRFS
29892986
select TEST_LKM
2990-
select XFS_FS
2991-
select TUN
2992-
select BTRFS_FS
29932987
help
29942988
Test the kernel's module loading mechanism: kmod. kmod implements
29952989
support to load modules using the Linux kernel's usermode helper.

lib/test_kmod.c

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@
2828

2929
#define TEST_START_NUM_THREADS 50
3030
#define TEST_START_DRIVER "test_module"
31-
#define TEST_START_TEST_FS "xfs"
3231
#define TEST_START_TEST_CASE TEST_KMOD_DRIVER
3332

34-
3533
static bool force_init_test = false;
36-
module_param(force_init_test, bool_enable_only, 0644);
34+
module_param(force_init_test, bool_enable_only, 0444);
3735
MODULE_PARM_DESC(force_init_test,
3836
"Force kicking a test immediately after driver loads");
37+
static char *start_driver;
38+
module_param(start_driver, charp, 0444);
39+
MODULE_PARM_DESC(start_driver,
40+
"Module/driver to use for the testing after driver loads");
41+
static char *start_test_fs;
42+
module_param(start_test_fs, charp, 0444);
43+
MODULE_PARM_DESC(start_test_fs,
44+
"File system to use for the testing after driver loads");
3945

4046
/*
4147
* For device allocation / registration
@@ -508,6 +514,11 @@ static int __trigger_config_run(struct kmod_test_device *test_dev)
508514
case TEST_KMOD_DRIVER:
509515
return run_test_driver(test_dev);
510516
case TEST_KMOD_FS_TYPE:
517+
if (!config->test_fs) {
518+
dev_warn(test_dev->dev,
519+
"No fs type specified, can't run the test\n");
520+
return -EINVAL;
521+
}
511522
return run_test_fs_type(test_dev);
512523
default:
513524
dev_warn(test_dev->dev,
@@ -721,26 +732,20 @@ static ssize_t config_test_fs_show(struct device *dev,
721732
static DEVICE_ATTR_RW(config_test_fs);
722733

723734
static int trigger_config_run_type(struct kmod_test_device *test_dev,
724-
enum kmod_test_case test_case,
725-
const char *test_str)
735+
enum kmod_test_case test_case)
726736
{
727-
int copied = 0;
728737
struct test_config *config = &test_dev->config;
729738

730739
mutex_lock(&test_dev->config_mutex);
731740

732741
switch (test_case) {
733742
case TEST_KMOD_DRIVER:
734-
kfree_const(config->test_driver);
735-
config->test_driver = NULL;
736-
copied = config_copy_test_driver_name(config, test_str,
737-
strlen(test_str));
738743
break;
739744
case TEST_KMOD_FS_TYPE:
740-
kfree_const(config->test_fs);
741-
config->test_fs = NULL;
742-
copied = config_copy_test_fs(config, test_str,
743-
strlen(test_str));
745+
if (!config->test_fs) {
746+
mutex_unlock(&test_dev->config_mutex);
747+
return 0;
748+
}
744749
break;
745750
default:
746751
mutex_unlock(&test_dev->config_mutex);
@@ -751,11 +756,6 @@ static int trigger_config_run_type(struct kmod_test_device *test_dev,
751756

752757
mutex_unlock(&test_dev->config_mutex);
753758

754-
if (copied <= 0 || copied != strlen(test_str)) {
755-
test_dev->test_is_oom = true;
756-
return -ENOMEM;
757-
}
758-
759759
test_dev->test_is_oom = false;
760760

761761
return trigger_config_run(test_dev);
@@ -800,19 +800,24 @@ static unsigned int kmod_init_test_thread_limit(void)
800800
static int __kmod_config_init(struct kmod_test_device *test_dev)
801801
{
802802
struct test_config *config = &test_dev->config;
803+
const char *test_start_driver = start_driver ? start_driver :
804+
TEST_START_DRIVER;
803805
int ret = -ENOMEM, copied;
804806

805807
__kmod_config_free(config);
806808

807-
copied = config_copy_test_driver_name(config, TEST_START_DRIVER,
808-
strlen(TEST_START_DRIVER));
809-
if (copied != strlen(TEST_START_DRIVER))
809+
copied = config_copy_test_driver_name(config, test_start_driver,
810+
strlen(test_start_driver));
811+
if (copied != strlen(test_start_driver))
810812
goto err_out;
811813

812-
copied = config_copy_test_fs(config, TEST_START_TEST_FS,
813-
strlen(TEST_START_TEST_FS));
814-
if (copied != strlen(TEST_START_TEST_FS))
815-
goto err_out;
814+
815+
if (start_test_fs) {
816+
copied = config_copy_test_fs(config, start_test_fs,
817+
strlen(start_test_fs));
818+
if (copied != strlen(start_test_fs))
819+
goto err_out;
820+
}
816821

817822
config->num_threads = kmod_init_test_thread_limit();
818823
config->test_result = 0;
@@ -1178,12 +1183,11 @@ static int __init test_kmod_init(void)
11781183
* lowering the init level for more fun.
11791184
*/
11801185
if (force_init_test) {
1181-
ret = trigger_config_run_type(test_dev,
1182-
TEST_KMOD_DRIVER, "tun");
1186+
ret = trigger_config_run_type(test_dev, TEST_KMOD_DRIVER);
11831187
if (WARN_ON(ret))
11841188
return ret;
1185-
ret = trigger_config_run_type(test_dev,
1186-
TEST_KMOD_FS_TYPE, "btrfs");
1189+
1190+
ret = trigger_config_run_type(test_dev, TEST_KMOD_FS_TYPE);
11871191
if (WARN_ON(ret))
11881192
return ret;
11891193
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
CONFIG_TEST_KMOD=m
22
CONFIG_TEST_LKM=m
3-
CONFIG_XFS_FS=m
4-
5-
# For the module parameter force_init_test is used
6-
CONFIG_TUN=m
7-
CONFIG_BTRFS_FS=m

0 commit comments

Comments
 (0)