Re: [PATCH v4 3/4] selftests/livepatch: build the test modules against the kernel in O=

From
sashiko-bot@kernel.org
Date
2026-11-10 16:53:02
Reply to
Sasha Levin, 2026-11-10
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/livepatch: KDIR fallback ignores builds without
  Module.symvers
--

commit 62f70537bbca33262ec62f1273becbdf534f58fc
Author: Sasha Levin [off-list ref]

selftests/livepatch: build the test modules against the kernel in O=

This commit selects KDIR from O= or KBUILD_OUTPUT (or the kernel source
tree) before falling back to the running kernel's build directory, and
strips O= and KBUILD_OUTPUT when invoking the kernel Makefile for the
livepatch test modules.
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/livepatch/Makefile b/tools/testing/selftests/livepatch/Makefile
index a080eb54a215d..97478ef90945c 100644
--- a/tools/testing/selftests/livepatch/Makefile
+++ b/tools/testing/selftests/livepatch/Makefile
@@ -1,5 +1,31 @@
 # SPDX-License-Identifier: GPL-2.0
 
+# The test modules are built against the kernel in KDIR. When KDIR is not
+# set, use the output directory given with O= or KBUILD_OUTPUT if a kernel
+# was built there, as with
+#   make O=/tmp/kselftest TARGETS=livepatch kselftest
+# otherwise the kernel source tree if the kernel was built in it, as with
+#   cd tools/testing/selftests/livepatch; make
+# and otherwise the build directory of the running kernel, which its
+# devel files provide. A kernel was built in a directory if it has a
+# Module.symvers.
+ifndef KDIR
+KBUILD_DIR := $(firstword $(O) $(KBUILD_OUTPUT))
+ifneq ($(and $(KBUILD_DIR),$(wildcard $(KBUILD_DIR)/Module.symvers)),)
+KDIR := $(KBUILD_DIR)
+else ifneq ($(wildcard ../../../../Module.symvers),)
+KDIR := ../../../..
+else
+KDIR := /lib/modules/$(shell uname -r)/build
+endif
+endif
[Severity: Medium]
Does checking only for Module.symvers cause KDIR to fall back to the host's
/lib/modules/$(uname -r)/build when the target kernel in O= or the source
tree was built with CONFIG_MODULES=n or an image-only target (which
produces vmlinux.symvers instead of Module.symvers)?

When that happens and the host has kernel headers with CONFIG_LIVEPATCH=y,
test_modules/Makefile reads the host's include/config/auto.conf and builds
the test modules against the running host kernel instead of skipping them
for the target kernel, which breaks cross-compiled builds or builds where
the in-tree test modules use newer kernel APIs than the host.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110161050.2451750-1-sashal@kernel.org?part=3
Thread (7 messages) 7 messages, 2 authors, last reply 6d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help