[PATCH v4 1/4] selftests/livepatch: skip the tests on kernels without livepatch
From: Sasha Levin
Date: Tue Nov 10 2026 - 11:19:35 EST
The test modules can only be built against a kernel configured with
CONFIG_LIVEPATCH, but the selftests try to build them for any kernel.
KernelCI builds the selftests for many kernel configurations, most of
which do not enable livepatch. On mainline from November 8, 36 of its
69 kselftest builds fail to compile the test modules, for example:
test_klp_callbacks_demo2.c:23:16: error: invalid use of undefined type 'struct klp_object'
These are arm and riscv kernels, which do not support livepatch, and
x86, arm64, powerpc and loongarch configurations that do not enable it.
Do not build the test modules when the kernel in KDIR was configured
without CONFIG_LIVEPATCH, and skip the tests when the running kernel has
no /sys/kernel/livepatch.
Fixes: c4bbe83d27c2 ("livepatch: Move tests from lib/livepatch to selftests/livepatch")
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
tools/testing/selftests/livepatch/functions.sh | 1 +
.../selftests/livepatch/test_modules/Makefile | 14 ++++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index 429fce1f31431..8b26b70f92d8c 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -150,6 +150,7 @@ function cleanup() {
# the ftrace_enabled sysctl.
function setup_config() {
is_root
+ [[ -d "$SYSFS_KLP_DIR" ]] || skip "livepatch is not available"
has_kdir
push_config
set_dynamic_debug
diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile b/tools/testing/selftests/livepatch/test_modules/Makefile
index a13d398585dcb..eddfb420db320 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -16,9 +16,19 @@ obj-m += test_klp_atomic_replace.o \
test_klp_state3.o \
test_klp_syscall.o
-# Ensure that KDIR exists, otherwise skip the compilation
-modules:
+# Build the modules only if KDIR exists and its kernel was configured with
+# CONFIG_LIVEPATCH, as recorded in include/config/auto.conf. If that cannot
+# be read, still try the build, so that a KDIR that is not a kernel build
+# directory fails the build instead of being skipped.
+KDIR_CONFIG := $(KDIR)/include/config/auto.conf
ifneq ("$(wildcard $(KDIR))", "")
+ifneq ($(shell [ -r "$(KDIR_CONFIG)" ] && ! grep -qx 'CONFIG_LIVEPATCH=y' "$(KDIR_CONFIG)" && echo n),n)
+BUILD_TEST_MODS := y
+endif
+endif
+
+modules:
+ifdef BUILD_TEST_MODS
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
--
2.53.0