After I did: make kselftest-all in top level of kernel source tree, top
level Makefile was overwritten by auto generated contents by
filechk_makefile:
[root@emr: /home/shiyu.dzl/linux-next]$ cat Makefile
export KBUILD_OUTPUT = .
export KBUILD_EXTMOD = /home/shiyu.dzl/linux-next
export KBUILD_EXTMOD_OUTPUT = /home/shiyu.dzl/linux-next
include /home/shiyu.dzl/linux-next/Makefile

Top-level Makefile export sub_make_done=1, leaks into unrelated re-invocations
of the top-level Makefile when recursive descent through selftests -
building test_module of livepatch. That causes KBUILD_EXTMOD setup to be
skipped, which leads to a relative/absolute path mismatch in srcroot vs
CURDIR, falsely setting building_out_of_srctree, and ultimately overwriting
the source tree's Makefile with a generated stub.

Clear sub_make_done before re-invoking the kernel Makefile.

Fixes: c4bbe83d27c2 ("livepatch: Move tests from lib/livepatch to 
selftests/livepatch")
Signed-off-by: Zelin Deng <[email protected]>
---
 tools/testing/selftests/livepatch/test_modules/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/livepatch/test_modules/Makefile 
b/tools/testing/selftests/livepatch/test_modules/Makefile
index a13d398585dc..b78657089ab7 100644
--- a/tools/testing/selftests/livepatch/test_modules/Makefile
+++ b/tools/testing/selftests/livepatch/test_modules/Makefile
@@ -19,11 +19,11 @@ obj-m += test_klp_atomic_replace.o \
 # Ensure that KDIR exists, otherwise skip the compilation
 modules:
 ifneq ("$(wildcard $(KDIR))", "")
-       $(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
+       $(Q)unset sub_make_done && $(MAKE) -C $(KDIR) modules 
KBUILD_EXTMOD=$(TESTMODS_DIR)
 endif
 
 # Ensure that KDIR exists, otherwise skip the clean target
 clean:
 ifneq ("$(wildcard $(KDIR))", "")
-       $(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
+       $(Q)unset sub_make_done && $(MAKE) -C $(KDIR) clean 
KBUILD_EXTMOD=$(TESTMODS_DIR)
 endif
-- 
2.43.7


Reply via email to