On Fri, May 13, 2022 at 11:38 PM Luis Chamberlain mcgrof@kernel.org wrote:
On Fri, May 13, 2022 at 04:32:13PM +0800, David Gow wrote:
Make any kselftest test module (using the kselftest_module framework) taint the kernel with TAINT_TEST on module load.
Note that several selftests use kernel modules which are not based on the kselftest_module framework, and so will not automatically taint the kernel. These modules will have to be manually modified if they should taint the kernel this way.
Similarly, selftests which do not load modules into the kernel generally should not taint the kernel (or possibly should only do so on failure), as it's assumed that testing from user-space should be safe. Regardless, they can write to /proc/sys/kernel/tainted if required.
Signed-off-by: David Gow davidgow@google.com
Not all selftest modules use KSTM_MODULE_LOADERS() so I'd like to see a modpost target as well, otherwise this just covers a sliver of selftests.
My personal feeling is that the ideal way of solving this is actually to port those modules which aren't using KSTM_MODULE_LOADERS() (or KUnit, or some other system) to do so, or to otherwise manually tag them as selftests and/or make them taint the kernel.
That being said, we can gain a bit my making the module-loading helpers in kselftest/module.sh manually taint the kernel with /proc/sys/kernel/tainted, which will catch quite a few of them (even if tainting from userspace before they're loaded is suboptimal).
I've also started experimenting with a "test" MODULE_INFO field, which modpost would add with the -t option. That still requires sprinkling MODULE_INFO() everwhere, or the '-t' option to a bunch of makefiles, or doing something more drastic to set it automatically for modules in a given directory / makefile. Or the staging thing of checking the directory / prefix in modpost.
I'll play around some more and have something to show in v4. (If we have a MODULE_INFO field, we should use it for KUnit modules, but we'd still have to taint the kernel manually for built-in tests anyway, so it'd be redundant...)
-- David