From nobody Sun Dec 14 12:13:39 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9939C8C0E for ; Fri, 18 Apr 2025 00:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744934925; cv=none; b=JBiXA/XP5c5kIWmQyvEgJ4qtP430bylA2nGHFAjw4rBjWHowBon2YHjNwKxOPvdmJ+HSZTwWf3lpkXNDFqSy0q+dsNcMRrB9sX7VOJv3G6QDcGOxXoZgwoYK6PVuOiKOpICIKudrzvrjODEF2dyfRDcUR+uhd1M96dr9gjE4YcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744934925; c=relaxed/simple; bh=d3zUhAt6ZxhNWHUaQxYASbqcpVSU8kmMhoZu6xLa01g=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uh6oUx3UslLfuIoclTy8qmV1Xu6sXPUJErEQhqEgFBlr2x7DBbIU10isAt81HpKbyaz8A/tZkp/OSt2GEK+wdYMWVoIxUXI+6tYv23pNptkdx9AYEKTjQOaKf8vRTUixiM1AYqua91lZ+SU/aYaMtq+eynYJzX3FQ3PCGdqzU5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d12JgMEb; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d12JgMEb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744934922; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=oLP/T1BBLrBIBaDPOF+hXYj8/NW65np6KEHHWIeq7uY=; b=d12JgMEbpt+HwMkc009pOr0S54iHaFgQsvtDuH2ZZO+NupXj3uSWNw1uvziiZzkUjI71SS sy/debVrpuKYn6sfAYzzXDgJZyYfp3YLdEq9V6UZraJgXdivpJ4nqI+GM3DF1GWDcs91Lx NM8s2vBNLlUrq7FLVnYZs1gQ2PViq1E= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-Qe2XVx0rOg6VXe7iVNV7kQ-1; Thu, 17 Apr 2025 20:08:39 -0400 X-MC-Unique: Qe2XVx0rOg6VXe7iVNV7kQ-1 X-Mimecast-MFC-AGG-ID: Qe2XVx0rOg6VXe7iVNV7kQ_1744934917 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3BC4E1800360; Fri, 18 Apr 2025 00:08:37 +0000 (UTC) Received: from redhat.com (unknown [10.96.134.19]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C836B19560A3; Fri, 18 Apr 2025 00:08:35 +0000 (UTC) From: "Herton R. Krzesinski" To: linux-modules@vger.kernel.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, mcgrof@kernel.org, petr.pavlu@suse.com, samitolvanen@google.com, da.gomez@samsung.com, herton@redhat.com Subject: [PATCH] lib/test_kmod: do not hardcode/depend on any filesystem Date: Thu, 17 Apr 2025 21:08:34 -0300 Message-ID: <20250418000834.672343-1-herton@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Herton R. Krzesinski Reviewed-by: Luis Chamberlain --- lib/Kconfig.debug | 6 ----- lib/test_kmod.c | 64 +++++++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 9fe4d8dfe578..1e0f8cbf0365 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2983,13 +2983,7 @@ config TEST_DYNAMIC_DEBUG config TEST_KMOD tristate "kmod stress tester" depends on m - depends on NETDEVICES && NET_CORE && INET # for TUN - depends on BLOCK - depends on PAGE_SIZE_LESS_THAN_256KB # for BTRFS select TEST_LKM - select XFS_FS - select TUN - select BTRFS_FS help Test the kernel's module loading mechanism: kmod. kmod implements support to load modules using the Linux kernel's usermode helper. diff --git a/lib/test_kmod.c b/lib/test_kmod.c index 064ed0fce75a..f0dd092860ea 100644 --- a/lib/test_kmod.c +++ b/lib/test_kmod.c @@ -28,14 +28,20 @@ =20 #define TEST_START_NUM_THREADS 50 #define TEST_START_DRIVER "test_module" -#define TEST_START_TEST_FS "xfs" #define TEST_START_TEST_CASE TEST_KMOD_DRIVER =20 - static bool force_init_test =3D false; -module_param(force_init_test, bool_enable_only, 0644); +module_param(force_init_test, bool_enable_only, 0444); MODULE_PARM_DESC(force_init_test, "Force kicking a test immediately after driver loads"); +static char *start_driver; +module_param(start_driver, charp, 0444); +MODULE_PARM_DESC(start_driver, + "Module/driver to use for the testing after driver loads"); +static char *start_test_fs; +module_param(start_test_fs, charp, 0444); +MODULE_PARM_DESC(start_test_fs, + "File system to use for the testing after driver loads"); =20 /* * For device allocation / registration @@ -508,6 +514,11 @@ static int __trigger_config_run(struct kmod_test_devic= e *test_dev) case TEST_KMOD_DRIVER: return run_test_driver(test_dev); case TEST_KMOD_FS_TYPE: + if (!config->test_fs) { + dev_warn(test_dev->dev, + "No fs type specified, can't run the test\n"); + return -EINVAL; + } return run_test_fs_type(test_dev); default: dev_warn(test_dev->dev, @@ -721,26 +732,20 @@ static ssize_t config_test_fs_show(struct device *dev, static DEVICE_ATTR_RW(config_test_fs); =20 static int trigger_config_run_type(struct kmod_test_device *test_dev, - enum kmod_test_case test_case, - const char *test_str) + enum kmod_test_case test_case) { - int copied =3D 0; struct test_config *config =3D &test_dev->config; =20 mutex_lock(&test_dev->config_mutex); =20 switch (test_case) { case TEST_KMOD_DRIVER: - kfree_const(config->test_driver); - config->test_driver =3D NULL; - copied =3D config_copy_test_driver_name(config, test_str, - strlen(test_str)); break; case TEST_KMOD_FS_TYPE: - kfree_const(config->test_fs); - config->test_fs =3D NULL; - copied =3D config_copy_test_fs(config, test_str, - strlen(test_str)); + if (!config->test_fs) { + mutex_unlock(&test_dev->config_mutex); + return 0; + } break; default: mutex_unlock(&test_dev->config_mutex); @@ -751,11 +756,6 @@ static int trigger_config_run_type(struct kmod_test_de= vice *test_dev, =20 mutex_unlock(&test_dev->config_mutex); =20 - if (copied <=3D 0 || copied !=3D strlen(test_str)) { - test_dev->test_is_oom =3D true; - return -ENOMEM; - } - test_dev->test_is_oom =3D false; =20 return trigger_config_run(test_dev); @@ -800,19 +800,24 @@ static unsigned int kmod_init_test_thread_limit(void) static int __kmod_config_init(struct kmod_test_device *test_dev) { struct test_config *config =3D &test_dev->config; + const char *test_start_driver =3D start_driver ? start_driver : + TEST_START_DRIVER; int ret =3D -ENOMEM, copied; =20 __kmod_config_free(config); =20 - copied =3D config_copy_test_driver_name(config, TEST_START_DRIVER, - strlen(TEST_START_DRIVER)); - if (copied !=3D strlen(TEST_START_DRIVER)) + copied =3D config_copy_test_driver_name(config, test_start_driver, + strlen(test_start_driver)); + if (copied !=3D strlen(test_start_driver)) goto err_out; =20 - copied =3D config_copy_test_fs(config, TEST_START_TEST_FS, - strlen(TEST_START_TEST_FS)); - if (copied !=3D strlen(TEST_START_TEST_FS)) - goto err_out; + + if (start_test_fs) { + copied =3D config_copy_test_fs(config, start_test_fs, + strlen(start_test_fs)); + if (copied !=3D strlen(start_test_fs)) + goto err_out; + } =20 config->num_threads =3D kmod_init_test_thread_limit(); config->test_result =3D 0; @@ -1178,12 +1183,11 @@ static int __init test_kmod_init(void) * lowering the init level for more fun. */ if (force_init_test) { - ret =3D trigger_config_run_type(test_dev, - TEST_KMOD_DRIVER, "tun"); + ret =3D trigger_config_run_type(test_dev, TEST_KMOD_DRIVER); if (WARN_ON(ret)) return ret; - ret =3D trigger_config_run_type(test_dev, - TEST_KMOD_FS_TYPE, "btrfs"); + + ret =3D trigger_config_run_type(test_dev, TEST_KMOD_FS_TYPE); if (WARN_ON(ret)) return ret; } --=20 2.47.1