* [PATCH] scsi: core: include scsi_lib KUnit tests in modular builds
@ 2026-12-04 2:03 Pengpeng Hou
2026-12-04 2:16 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-12-04 2:03 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, Pengpeng Hou, Geert Uytterhoeven, Bart Van Assche,
linux-kselftest
The SCSI library tests are included from scsi_lib.c rather than built as
a separate module. Selecting the test as m therefore defines the module
form of the option, which the existing ifdef ignores.
Use IS_REACHABLE at the inclusion site. This enables the tests for a
modular SCSI host with modular tests without making built-in SCSI
reference module-only tests.
The issue was found by our static-analysis tool and manually reviewed.
Fixes: 25a1f7a0a1fe ("scsi: core: Add kunit tests for scsi_check_passthrough()")
Fixes: f7c7190f49b8 ("scsi: core: Really include kunit tests with SCSI_LIB_KUNIT_TEST")
Signed-off-by: Pengpeng Hou <hppiscas@163.com>
---
Geert previously proposed a separate SCSI test module. This fix keeps
the tests in scsi_lib and needs no exported SCSI helper. It does not
enable independent loading of these tests.
https://lore.kernel.org/r/48ca5e827ca420bbdbabb1643e2179dc95c9e0b7.1710849638.git.geert@linux-m68k.org
The patch was prepared with Gemini and revised with Codex assistance
(Assisted-by: gpt 5).
Built scsi_lib.o on x86-64 with GCC 11.4 and W=1, with KUNIT=m and
SCSI_LIB_KUNIT_TEST=m. With SCSI=m the suite was absent before and
present after the change. With SCSI=y it remained excluded after the
change. The suite was not executed.
drivers/scsi/scsi_lib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ab39514cc0c6bd485e424f103619c692e710ca7b..948918803831907488f0ccf68b741f4b2f902f0a 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3611,6 +3611,6 @@ void scsi_set_sense(struct scsi_cmnd *scmd, int desc, u8 key, u16 code)
}
EXPORT_SYMBOL_GPL(scsi_set_sense);
-#ifdef CONFIG_SCSI_LIB_KUNIT_TEST
+#if IS_REACHABLE(CONFIG_SCSI_LIB_KUNIT_TEST)
#include "scsi_lib_test.c"
#endif
base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] scsi: core: include scsi_lib KUnit tests in modular builds
2026-12-04 2:03 [PATCH] scsi: core: include scsi_lib KUnit tests in modular builds Pengpeng Hou
@ 2026-12-04 2:16 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 2:16 UTC (permalink / raw)
To: Pengpeng Hou; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: embedding scsi_lib_test.c couples scsi_mod.ko to
kunit.ko and taints
--
commit 62bce85f8688e7b2497edd8565cef82538ee735c
Author: Pengpeng Hou <hppiscas@163.com>
scsi: core: include scsi_lib KUnit tests in modular builds
This commit changes the guard around including scsi_lib_test.c in
drivers/scsi/scsi_lib.c from #ifdef to IS_REACHABLE() so the KUnit tests
are included when both SCSI and SCSI_LIB_KUNIT_TEST are built as modules.
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index ab39514cc0c6b..9489188038319 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -3611,6 +3611,6 @@ void scsi_set_sense(struct scsi_cmnd *scmd, int desc, u8 key, u16 code)
> }
> EXPORT_SYMBOL_GPL(scsi_set_sense);
>
> -#ifdef CONFIG_SCSI_LIB_KUNIT_TEST
> +#if IS_REACHABLE(CONFIG_SCSI_LIB_KUNIT_TEST)
> #include "scsi_lib_test.c"
> #endif
[Severity: Medium]
Does embedding scsi_lib_test.c into scsi_mod.ko couple core SCSI to
kunit.ko?
With CONFIG_SCSI=m and CONFIG_KUNIT_ALL_TESTS=m, CONFIG_SCSI_LIB_KUNIT_TEST
defaults to m, compiling scsi_lib_test.c into scsi_mod.ko. Its
KUNIT_EXPECT_EQ() calls reference __kunit_do_failed_assertion from kunit.ko,
preventing scsi_mod.ko from loading if an initramfs omits kunit.ko.
Loading scsi_mod.ko also triggers kunit_module_notify() to run
scsi_lib_test_suite during normal boot, tainting the kernel with TAINT_TEST
and keeping the suite's debugfs entries until scsi_mod.ko is unloaded. The
tests also cannot be loaded or re-run independently of scsi_mod.ko.
Marking scsi_check_passthrough() with VISIBLE_IF_KUNIT and
EXPORT_SYMBOL_IF_KUNIT() and building scsi_lib_test.o as a separate module
via obj-$(CONFIG_SCSI_LIB_KUNIT_TEST) in drivers/scsi/Makefile would avoid
both issues and also support CONFIG_SCSI=y.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179634982482.74470.2785930501744791630@163.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 2:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 2:03 [PATCH] scsi: core: include scsi_lib KUnit tests in modular builds Pengpeng Hou
2026-12-04 2:16 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox