Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests/livepatch: KDIR selection ignores .config without Module.symvers
--
commit ae4848cae1b2b7420ab6ac44f707bd616ad82b5a
Author: Sasha Levin [off-list ref]
selftests/livepatch: build test modules against the selected kernel
This commit updates the livepatch selftests build and test scripts to select
KDIR from O, KBUILD_OUTPUT, or the source tree before falling back to the
running kernel's build directory, stops forwarding O and KBUILD_OUTPUT to the
external module build, and skips building or running tests when
CONFIG_LIVEPATCH is disabled.
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/livepatch/Makefile b/tools/testing/selftests/livepatch/Makefile
index a080eb54a215d..5c631812575dc 100644
--- a/tools/testing/selftests/livepatch/Makefile
+++ b/tools/testing/selftests/livepatch/Makefile
@@ -1,7 +1,26 @@
# SPDX-License-Identifier: GPL-2.0
+ifndef KDIR
+LIVEPATCH_OBJTREE := $(firstword $(O) $(KBUILD_OUTPUT))
+ifneq ($(and $(LIVEPATCH_OBJTREE),$(wildcard $(LIVEPATCH_OBJTREE)/Module.symvers)),)
+KDIR := $(LIVEPATCH_OBJTREE)
+else ifneq ($(wildcard ../../../../Module.symvers),)
+KDIR := ../../../..
+else
+KDIR := /lib/modules/$(shell uname -r)/build
+endif
+endif
+override KDIR := $(abspath $(KDIR))
+export KDIR
+MAKEOVERRIDES := $(filter-out KDIR=%,$(MAKEOVERRIDES))
+
+LIVEPATCH_CONFIG := $(shell if [ -r "$(KDIR)/.config" ]; then \
+ grep -qx 'CONFIG_LIVEPATCH=y' "$(KDIR)/.config" && echo y || echo n; fi)
[Severity: Medium]
When KDIR is not explicitly set, KDIR only selects $(LIVEPATCH_OBJTREE) or
../../../.. if Module.symvers exists in that directory, falling back to
/lib/modules/$(shell uname -r)/build otherwise. Then LIVEPATCH_CONFIG checks
$(KDIR)/.config for CONFIG_LIVEPATCH=y.
If a kernel is configured and built with CONFIG_MODULES=n (so CONFIG_LIVEPATCH
is also disabled), the top-level Makefile clears KBUILD_MODULES and
scripts/Makefile.modpost sets output-symdump to vmlinux.symvers instead of
Module.symvers:
scripts/Makefile.modpost:
output-symdump := $(if $(KBUILD_MODULES), Module.symvers, vmlinux.symvers)
Because Module.symvers is never created in that build, or when running make
kselftest-all or building only a kernel image target before modules, .config
exists in $(LIVEPATCH_OBJTREE) or ../../../.. without Module.symvers.
In those cases, wouldn't KDIR ignore the target kernel directory and fall back
to /lib/modules/$(uname -r)/build, causing LIVEPATCH_CONFIG to read the
running host kernel's .config and attempt to build test_modules against the
host kernel instead of skipping or using the target kernel tree? Conversely,
if O= points to an unprepared kernel build tree configured with
CONFIG_LIVEPATCH=y, wouldn't KDIR silently fall back to ../../../.. or
/lib/modules/$(uname -r)/build instead of using O=?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103222706.1642224-1-sashal@kernel.org?part=1