selftests: livepatch: unset sub_make_done in case top level Makefile be overwritten
Subsystems (3)
PATCH 1/1 selftests: livepatch: unset sub_make_done in case top level Makefile be overwritten
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.
--- tools/testing/selftests/livepatch/test_modules/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/livepatch/test_modules/Makefile +2 -2
@@ -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
Signature · 1 line
2.43.7
Miroslav Benes
maintainerQuoted 16 lines · Zelin Deng
After I did: make kselftest-all in top level of kernel source tree, top level
Makefilewas overwritten by auto generated contents byfilechk_makefile:
[root@emr: /home/shiyu.dzl/linux-next]$ catMakefile
exportKBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-next
exportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/MakefileTop-level
Makefileexport sub_make_done=1, leaks into unrelated re-invocations of the top-levelMakefilewhen recursive descent through selftests - buildingtest_moduleof livepatch. That causesKBUILD_EXTMODsetup to be skipped, which leads to a relative/absolute path mismatch in srcroot vs CURDIR, falsely settingbuilding_out_of_srctree, and ultimately overwriting the source tree'sMakefilewith a generated stub.
Quoted 4 lines
Clear
sub_make_donebefore re-invoking the kernelMakefile.Fixes c4bbe83d27c2 ("livepatch: Move tests from lib/livepatch to selftests/livepatch")Signed-off-by Zelin Deng <[email protected]>
Adding Marcos and KLP ML.
I cannot reproduce and I do not understand it much from the changelog (I am by far not a Kbuild expert). Could you share the exact steps to reproduce please? If I just run 'make kselftest-all' in the top level, it passes and livepatch test_modules are not even touched.
Miroslav
Quoted 22 lines · Miroslav Benes
Quoted 16 lines · Zelin Deng
After I did: make kselftest-all in top level of kernel source tree, top level
Makefilewas overwritten by auto generated contents byfilechk_makefile:
[root@emr: /home/shiyu.dzl/linux-next]$ catMakefile
exportKBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-next
exportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/MakefileTop-level
Makefileexport sub_make_done=1, leaks into unrelated re-invocations of the top-levelMakefilewhen recursive descent through selftests - buildingtest_moduleof livepatch. That causesKBUILD_EXTMODsetup to be skipped, which leads to a relative/absolute path mismatch in srcroot vs CURDIR, falsely settingbuilding_out_of_srctree, and ultimately overwriting the source tree'sMakefilewith a generated stub.Quoted 4 lines
Clear
sub_make_donebefore re-invoking the kernelMakefile.Fixes c4bbe83d27c2 ("livepatch: Move tests from lib/livepatch to selftests/livepatch")Signed-off-by Zelin Deng <[email protected]>
Quoted 8 lines
Adding Marcos and KLP ML.
I cannot reproduce and I do not understand it much from the changelog (I am by far not a
Kbuildexpert). Could you share the exact steps to reproduce please? If I just run 'make kselftest-all' in the top level, it passes and livepatchtest_modulesare not even touched.Miroslav
Thank you for replying.
Per my understanding, to build livepatch test_modules KDIR must be either set explicitly when doing 'make kselftest-all KDIR=<path-to-kernel-build-dir>' or have the kernel devel package installed. Otherwise the compilation could be skipped. (see tools/testing/selftests/livepatch/test_modules/Makefile)
KDIR ?= /lib/modules/$(shell uname -r)/build
...
# Ensure that KDIR exists, otherwise skip the compilation modules:
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR) endif
...
Here're how I reproduce the issue:
1. pull linux-next, reset to HEAD, for example 3ce97bd3c4f18608335e709c24d6a40e7036cab8 (tag next-20260619)
2. at linux-next tree: make all -j$(nproc) && make modules_install headers_install -j$(nproc) && make install && reboot
3. at linux-next tree: make kselftest-all
4. top level Makefile in linux-next has been overwritten by
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
it is a stub generated by filechk_makefile.
I'm not quite sure that it could be related to my toolchain (like make version ?), I briefed analysis the root cause on my environment (KDIR '/lib/modules/7.1.0-next-20260619/build' which actually a symbol link to my kernel source -> '/home/shiyu.dzl/linux-next'):
1. sub_make_done leaks via environment. The top-level Makefile sets export sub_make_done := 1 after its first-pass initialization. Because it is exported, every child make process inherits it.
2. livepatch test_modules re-invokes the top-level Makefile. The call chain is: top-level Makefile → kselftest-% pattern rule → tools/testing/selftests/ → livepatch test_modules/Makefile → $(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=..., which re-enters the top-level Makefile to build an external module.
3. The inherited sub_make_done=1 skips critical initialization. The top-level Makefile's first-pass block (ifneq ($(sub_make_done),1)) is skipped entirely. This block is responsible for correctly parsing command-line variables and setting up KBUILD_EXTMOD-related paths.
4. Path mismatch triggers false out-of-tree detection. With the initialization skipped, srcroot and CURDIR end up with mismatched values (e.g., absolute vs. relative). The comparison (ifeq ($(srcroot),$(CURDIR))) fails, so building_out_of_srctree is incorrectly set to 1.
5. outputmakefile overwrites the source tree's Makefile. Because building_out_of_srctree is set, the filechk_makefile rule fires and replaces the real top-level Makefile with a generated stub containing KBUILD_OUTPUT, KBUILD_EXTMOD, and an include directive.
Why make -C tools/testing/selftests/ all is unaffected: it enters the selftests directory directly without ever executing the top-level Makefile first, so sub_make_done is never exported into the environment. When livepatch test_modules later invokes $(MAKE) -C $(KDIR), the top-level Makefile runs its full initialization normally.
Thanks,
Zelin
Petr Mladek
maintainerAdded some people involved in "filechk_makefile" feature into Cc.
For the new people, see the whole thread at
https://lore.kernel.org/all/[email protected]/
Quoted 63 lines · Zelin Deng
Quoted 22 lines · Miroslav Benes
Quoted 16 lines · Zelin Deng
After I did: make kselftest-all in top level of kernel source tree, top level
Makefilewas overwritten by auto generated contents byfilechk_makefile:
[root@emr: /home/shiyu.dzl/linux-next]$ catMakefile
exportKBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-next
exportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/MakefileTop-level
Makefileexport sub_make_done=1, leaks into unrelated re-invocations of the top-levelMakefilewhen recursive descent through selftests - buildingtest_moduleof livepatch. That causesKBUILD_EXTMODsetup to be skipped, which leads to a relative/absolute path mismatch in srcroot vs CURDIR, falsely settingbuilding_out_of_srctree, and ultimately overwriting the source tree'sMakefilewith a generated stub.Quoted 4 lines
Clear
sub_make_donebefore re-invoking the kernelMakefile.Fixes c4bbe83d27c2 ("livepatch: Move tests from lib/livepatch to selftests/livepatch")Signed-off-by Zelin Deng <[email protected]>Quoted 8 lines
Adding Marcos and KLP ML.
I cannot reproduce and I do not understand it much from the changelog (I am by far not a
Kbuildexpert). Could you share the exact steps to reproduce please? If I just run 'make kselftest-all' in the top level, it passes and livepatchtest_modulesare not even touched.Miroslav
Thank you for replying.
Per my understanding, to build livepatch
test_modulesKDIR must be either set explicitly when doing 'make kselftest-all KDIR=<path-to-kernel-build-dir>' or have the kernel devel package installed. Otherwise the compilation could be skipped. (seetools/testing/selftests/livepatch/test_modules/Makefile)KDIR ?= /lib/modules/$(shell uname -r)/build
...
# Ensure that KDIR exists, otherwise skip the compilation modules:
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR) endif...
Here're how I reproduce the issue:
1. pull linux-next, reset to HEAD, for example
3ce97bd3c4f18608335e709c24d6a40e7036cab8(tag next-20260619)2. at linux-next tree: make all -j$(nproc) && make
modules_installheaders_install-j$(nproc) && make install && reboot3. at linux-next tree: make kselftest-all
Quoted 8 lines
4. top level
Makefilein linux-next has been overwritten byexport
KBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-nextexportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/Makefileit is a stub generated by
filechk_makefile.
It seems that "filechk_makefile" has reached mainline in v7.1-rc1, see the commit c9bb03ac2c66bc5aa81b ("kbuild: reduce output spam when building out of tree").
The commit message says:
<paste>
The Makefile is now created even if the build is aborted due to an unclean working tree. That should not make a difference in practice.
</paste>
It seems that is actually makes a difference in the livepatch selftest case.
Sigh, the Makefile rules are a maze to me. It is possible that we do something wrong in tools/testing/selftests/livepatch/test_modules/Makefile. Namely with:
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
endif
But I see "$(MAKE) -C ..." called in many other makefiles.
Best Regards,
Petr
Quoted 39 lines
I'm not quite sure that it could be related to my toolchain (like make version ?), I briefed analysis the root cause on my environment (KDIR '
/lib/modules/7.1.0-next-20260619/build' which actually a symbol link to my kernel source -> '/home/shiyu.dzl/linux-next'):1.
sub_make_doneleaks via environment. The top-levelMakefilesets exportsub_make_done:= 1 after its first-pass initialization.
Because it is exported, every child make process inherits it.
2. livepatchtest_modulesre-invokes the top-levelMakefile. The call chain is: top-levelMakefile→ kselftest-% pattern rule →tools/testing/selftests/→ livepatch test_modules/Makefile → $(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=..., which re-enters the top-levelMakefileto build an external module.
3. The inherited sub_make_done=1 skips critical initialization. The top-level Makefile's first-pass block (ifneq ($(sub_make_done),1)) is skipped entirely. This block is responsible for correctly parsing command-line variables and setting up KBUILD_EXTMOD-related paths.
4. Path mismatch triggers false out-of-tree detection. With the initialization skipped, srcroot and CURDIR end up with mismatched values (e.g.,
absolute vs. relative). The comparison (ifeq ($(srcroot),$(CURDIR))) fails, sobuilding_out_of_srctreeis incorrectly set to 1.
5. outputmakefile overwrites the source tree'sMakefile. Becausebuilding_out_of_srctreeis set, thefilechk_makefilerule fires and replaces the
real top-levelMakefilewith a generated stub containingKBUILD_OUTPUT,KBUILD_EXTMOD, and an include directive.Why make -C
tools/testing/selftests/all is unaffected: it enters the selftests directory directly without ever executing the top-levelMakefilefirst, sosub_make_doneis never exported into the environment. When livepatchtest_moduleslater invokes $(MAKE) -C $(KDIR), the top-levelMakefile
runs its full initialization normally.Thanks,
Zelin
Hi Zelin,
Quoted 4 lines · Petr Mladek
Added some people involved in "
filechk_makefile" feature into Cc.For the new people, see the whole thread at
https://lore.kernel.org/all/[email protected]/
Thanks for the report and forwarding it.
Quoted 92 lines · Zelin Deng
Quoted 63 lines · Miroslav Benes
Quoted 22 lines · Zelin Deng
Quoted 17 lines
After I did: make kselftest-all in top level of kernel source tree, top level
Makefilewas overwritten by auto generated contents byfilechk_makefile:
[root@emr: /home/shiyu.dzl/linux-next]$ catMakefile
exportKBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-next
exportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/MakefileTop-level
Makefileexport sub_make_done=1, leaks into unrelated re-invocations of the top-levelMakefilewhen recursive descent through selftests - buildingtest_moduleof livepatch. That causesKBUILD_EXTMODsetup to be skipped, which leads to a relative/absolute path mismatch in srcroot vs CURDIR, falsely settingbuilding_out_of_srctree, and ultimately overwriting the source tree'sMakefilewith a generated stub.Quoted 4 lines
Clear
sub_make_donebefore re-invoking the kernelMakefile.Fixes c4bbe83d27c2 ("livepatch: Move tests from lib/livepatch to selftests/livepatch")Signed-off-by Zelin Deng <[email protected]>Quoted 8 lines
Adding Marcos and KLP ML.
I cannot reproduce and I do not understand it much from the changelog (I am by far not a
Kbuildexpert). Could you share the exact steps to reproduce please? If I just run 'make kselftest-all' in the top level, it passes and livepatchtest_modulesare not even touched.Miroslav
Thank you for replying.
Per my understanding, to build livepatch
test_modulesKDIR must be either set explicitly when doing 'make kselftest-all KDIR=<path-to-kernel-build-dir>' or have the kernel devel package installed. Otherwise the compilation could be skipped. (seetools/testing/selftests/livepatch/test_modules/Makefile)KDIR ?= /lib/modules/$(shell uname -r)/build
...
# Ensure that KDIR exists, otherwise skip the compilation modules:
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR) endif...
Here're how I reproduce the issue:
1. pull linux-next, reset to HEAD, for example
3ce97bd3c4f18608335e709c24d6a40e7036cab8(tag next-20260619)2. at linux-next tree: make all -j$(nproc) && make
modules_installheaders_install-j$(nproc) && make install && reboot3. at linux-next tree: make kselftest-all
Quoted 8 lines
4. top level
Makefilein linux-next has been overwritten byexport
KBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-nextexportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/Makefileit is a stub generated by
filechk_makefile.It seems that "
filechk_makefile" has reached mainline in v7.1-rc1, see the commitc9bb03ac2c66bc5aa81b("kbuild: reduce output spam when building out of tree").The commit message says:
<paste>
TheMakefileis now created even if the build is aborted due to an unclean working tree. That should not make a difference in practice.
</paste>It seems that is actually makes a difference in the livepatch selftest case.
Sigh, the
Makefilerules are a maze to me. It is possible that we do something wrong intools/testing/selftests/livepatch/test_modules/Makefile. Namely with:
Quoted 43 lines
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)endif
But I see "$(MAKE) -C ..." called in many other makefiles.
Best Regards,
PetrQuoted 34 lines
I'm not quite sure that it could be related to my toolchain (like make version ?), I briefed analysis the root cause on my environment (KDIR '
/lib/modules/7.1.0-next-20260619/build' which actually a symbol link to my kernel source -> '/home/shiyu.dzl/linux-next'):1.
sub_make_doneleaks via environment. The top-levelMakefilesets exportsub_make_done:= 1 after its first-pass initialization.
Because it is exported, every child make process inherits it.
2. livepatchtest_modulesre-invokes the top-levelMakefile. The call chain is: top-levelMakefile→ kselftest-% pattern rule →tools/testing/selftests/→ livepatch test_modules/Makefile → $(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=..., which re-enters the top-levelMakefileto build an external module.
3. The inherited sub_make_done=1 skips critical initialization. The top-level Makefile's first-pass block (ifneq ($(sub_make_done),1)) is skipped entirely. This block is responsible for correctly parsing command-line variables and setting up KBUILD_EXTMOD-related paths.
4. Path mismatch triggers false out-of-tree detection. With the initialization skipped, srcroot and CURDIR end up with mismatched values (e.g.,
absolute vs. relative). The comparison (ifeq ($(srcroot),$(CURDIR))) fails, sobuilding_out_of_srctreeis incorrectly set to 1.
5. outputmakefile overwrites the source tree'sMakefile. Becausebuilding_out_of_srctreeis set, thefilechk_makefilerule fires and replaces the
real top-levelMakefilewith a generated stub containingKBUILD_OUTPUT,KBUILD_EXTMOD, and an include directive.Why make -C
tools/testing/selftests/all is unaffected: it enters the selftests directory directly without ever executing the top-levelMakefilefirst, sosub_make_doneis never exported into the environment. When livepatchtest_moduleslater invokes $(MAKE) -C $(KDIR), the top-levelMakefile
runs its full initialization normally.
Can you try this:
Makefile +2 -2
@@ -1591,10 +1591,10 @@ tools/%: FORCE PHONY += kselftest kselftest: headers - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests kselftest-%: headers FORCE - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $* PHONY += kselftest-merge kselftest-merge:
The same is done for cmd_install.
Thomas
Quoted 105 lines · Thomas Weißschuh
Hi Zelin,
Quoted 4 lines · Petr Mladek
Added some people involved in "
filechk_makefile" feature into Cc.For the new people, see the whole thread at
https://lore.kernel.org/all/[email protected]/Thanks for the report and forwarding it.
Quoted 42 lines · Zelin Deng
Quoted 13 lines · Miroslav Benes
Quoted 1 line · Zelin Deng
Here're how I reproduce the issue:
1. pull linux-next, reset to HEAD, for example
3ce97bd3c4f18608335e709c24d6a40e7036cab8(tag next-20260619)2. at linux-next tree: make all -j$(nproc) && make
modules_installheaders_install-j$(nproc) && make install && reboot3. at linux-next tree: make kselftest-all
Quoted 8 lines
4. top level
Makefilein linux-next has been overwritten byexport
KBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-nextexportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/Makefileit is a stub generated by
filechk_makefile.It seems that "
filechk_makefile" has reached mainline in v7.1-rc1, see the commitc9bb03ac2c66bc5aa81b("kbuild: reduce output spam when building out of tree").The commit message says:
<paste>
TheMakefileis now created even if the build is aborted due to an unclean working tree. That should not make a difference in practice.
</paste>It seems that is actually makes a difference in the livepatch selftest case.
Sigh, the
Makefilerules are a maze to me. It is possible that we do something wrong intools/testing/selftests/livepatch/test_modules/Makefile. Namely with:Quoted 43 lines
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)endif
But I see "$(MAKE) -C ..." called in many other makefiles.
Best Regards,
PetrQuoted 34 lines
I'm not quite sure that it could be related to my toolchain (like make version ?), I briefed analysis the root cause on my environment (KDIR '
/lib/modules/7.1.0-next-20260619/build' which actually a symbol link to my kernel source -> '/home/shiyu.dzl/linux-next'):1.
sub_make_doneleaks via environment. The top-levelMakefilesets exportsub_make_done:= 1 after its first-pass initialization.
Because it is exported, every child make process inherits it.
2. livepatchtest_modulesre-invokes the top-levelMakefile. The call chain is: top-levelMakefile→ kselftest-% pattern rule →tools/testing/selftests/→ livepatch test_modules/Makefile → $(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=..., which re-enters the top-levelMakefileto build an external module.
3. The inherited sub_make_done=1 skips critical initialization. The top-level Makefile's first-pass block (ifneq ($(sub_make_done),1)) is skipped entirely. This block is responsible for correctly parsing command-line variables and setting up KBUILD_EXTMOD-related paths.
4. Path mismatch triggers false out-of-tree detection. With the initialization skipped, srcroot and CURDIR end up with mismatched values (e.g.,
absolute vs. relative). The comparison (ifeq ($(srcroot),$(CURDIR))) fails, sobuilding_out_of_srctreeis incorrectly set to 1.
5. outputmakefile overwrites the source tree'sMakefile. Becausebuilding_out_of_srctreeis set, thefilechk_makefilerule fires and replaces the
real top-levelMakefilewith a generated stub containingKBUILD_OUTPUT,KBUILD_EXTMOD, and an include directive.Why make -C
tools/testing/selftests/all is unaffected: it enters the selftests directory directly without ever executing the top-levelMakefilefirst, sosub_make_doneis never exported into the environment. When livepatchtest_moduleslater invokes $(MAKE) -C $(KDIR), the top-levelMakefile
runs its full initialization normally.Can you try this:
Makefile +0
-0@@ -1591,10 +1591,10 @@ tools/%: FORCE PHONY += kselftest
Makefile tools/%: FORCE · line 1600
Quoted 10 lines
Makefile +2
-2kselftest: headers - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests kselftest-%: headers FORCE - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $* PHONY += kselftest-merge kselftest-merge:
Heh, this is exactly the same change which Zelin Deng proposed as well, see
https://lore.kernel.org/all/[email protected]/
Quoted 1 line
The same is done for
cmd_install.
I guess that this is related to the commit 14ccc638b02f9ec ("kbuild:
cancel sub_make_done for the install target to fix DKMS"). Which is related to the commit bcf637f54f6d2515d ("kbuild: parse C= and M= before changing the working directory").
Honestly, it all looks like a wild magic to me. I would need much better understanding of the Makefile maze to get on top of it.
But it seems that it is a reasonable fix after all. It solves the original problem. It does not break my workflow. So, I tend to add:
Best Regards,
Petr
Quoted 114 lines · Petr Mladek
Quoted 113 lines · Thomas Weißschuh
Hi Zelin,
Quoted 4 lines · Petr Mladek
Added some people involved in "
filechk_makefile" feature into Cc.For the new people, see the whole thread at
https://lore.kernel.org/all/[email protected]/Thanks for the report and forwarding it.
Quoted 42 lines · Zelin Deng
Quoted 13 lines · Miroslav Benes
Quoted 1 line · Zelin Deng
Here're how I reproduce the issue:
1. pull linux-next, reset to HEAD, for example
3ce97bd3c4f18608335e709c24d6a40e7036cab8(tag next-20260619)2. at linux-next tree: make all -j$(nproc) && make
modules_installheaders_install-j$(nproc) && make install && reboot3. at linux-next tree: make kselftest-all
Quoted 8 lines
4. top level
Makefilein linux-next has been overwritten byexport
KBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-nextexportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/Makefileit is a stub generated by
filechk_makefile.It seems that "
filechk_makefile" has reached mainline in v7.1-rc1, see the commitc9bb03ac2c66bc5aa81b("kbuild: reduce output spam when building out of tree").The commit message says:
<paste>
TheMakefileis now created even if the build is aborted due to an unclean working tree. That should not make a difference in practice.
</paste>It seems that is actually makes a difference in the livepatch selftest case.
Sigh, the
Makefilerules are a maze to me. It is possible that we do something wrong intools/testing/selftests/livepatch/test_modules/Makefile. Namely with:Quoted 43 lines
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)endif
But I see "$(MAKE) -C ..." called in many other makefiles.
Best Regards,
PetrQuoted 34 lines
I'm not quite sure that it could be related to my toolchain (like make version ?), I briefed analysis the root cause on my environment (KDIR '
/lib/modules/7.1.0-next-20260619/build' which actually a symbol link to my kernel source -> '/home/shiyu.dzl/linux-next'):1.
sub_make_doneleaks via environment. The top-levelMakefilesets exportsub_make_done:= 1 after its first-pass initialization.
Because it is exported, every child make process inherits it.
2. livepatchtest_modulesre-invokes the top-levelMakefile. The call chain is: top-levelMakefile→ kselftest-% pattern rule →tools/testing/selftests/→ livepatch test_modules/Makefile → $(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=..., which re-enters the top-levelMakefileto build an external module.
3. The inherited sub_make_done=1 skips critical initialization. The top-level Makefile's first-pass block (ifneq ($(sub_make_done),1)) is skipped entirely. This block is responsible for correctly parsing command-line variables and setting up KBUILD_EXTMOD-related paths.
4. Path mismatch triggers false out-of-tree detection. With the initialization skipped, srcroot and CURDIR end up with mismatched values (e.g.,
absolute vs. relative). The comparison (ifeq ($(srcroot),$(CURDIR))) fails, sobuilding_out_of_srctreeis incorrectly set to 1.
5. outputmakefile overwrites the source tree'sMakefile. Becausebuilding_out_of_srctreeis set, thefilechk_makefilerule fires and replaces the
real top-levelMakefilewith a generated stub containingKBUILD_OUTPUT,KBUILD_EXTMOD, and an include directive.Why make -C
tools/testing/selftests/all is unaffected: it enters the selftests directory directly without ever executing the top-levelMakefilefirst, sosub_make_doneis never exported into the environment. When livepatchtest_moduleslater invokes $(MAKE) -C $(KDIR), the top-levelMakefile
runs its full initialization normally.Can you try this:
Makefile +2
-2@@ -1591,10 +1591,10 @@ tools/%: FORCE PHONY += kselftest kselftest: headers - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests kselftest-%: headers FORCE - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $*
Quoted 6 lines
Makefile tools/%: FORCE · line 1600
Quoted 2 lines
Makefile +0
-0PHONY += kselftest-merge kselftest-merge:Heh, this is exactly the same change which Zelin Deng proposed as well, see
https://lore.kernel.org/all/[email protected]/
The difference is that my proposal is in the toplevel Makefile while Zelin's is in the selftest one. The toplevel one should fix all selftests at the same time.
Quoted 9 lines
Quoted 1 line
The same is done for
cmd_install.I guess that this is related to the commit
14ccc638b02f9ec("kbuild:
cancelsub_make_donefor the install target to fix DKMS"). Which is related to the commitbcf637f54f6d2515d("kbuild: parse C= and M= before changing the working directory").Honestly, it all looks like a wild magic to me. I would need much better understanding of the
Makefilemaze to get on top of it.
I was not able to reproduce the issue yet. My proposal is just a guess. We'll need feedback from Zelin.
Quoted 4 lines
But it seems that it is a reasonable fix after all. It solves the original problem. It does not break my workflow. So, I tend to add:
Acked-by Petr Mladek <[email protected]>
Thomas
Quoted 111 lines · Thomas Weißschuh
Quoted 110 lines · Petr Mladek
Quoted 109 lines · Thomas Weißschuh
Hi Zelin,
Quoted 4 lines · Petr Mladek
Added some people involved in "
filechk_makefile" feature into Cc.For the new people, see the whole thread at
https://lore.kernel.org/all/[email protected]/Thanks for the report and forwarding it.
Quoted 40 lines · Zelin Deng
Quoted 12 lines · Miroslav Benes
Quoted 1 line · Zelin Deng
Here're how I reproduce the issue:
1. pull linux-next, reset to HEAD, for example
3ce97bd3c4f18608335e709c24d6a40e7036cab8(tag next-20260619)2. at linux-next tree: make all -j$(nproc) && make
modules_installheaders_install-j$(nproc) && make install && reboot3. at linux-next tree: make kselftest-all
Quoted 8 lines
4. top level
Makefilein linux-next has been overwritten byexport
KBUILD_OUTPUT= .
exportKBUILD_EXTMOD=/home/shiyu.dzl/linux-nextexportKBUILD_EXTMOD_OUTPUT=/home/shiyu.dzl/linux-nextinclude/home/shiyu.dzl/linux-next/Makefileit is a stub generated by
filechk_makefile.It seems that "
filechk_makefile" has reached mainline in v7.1-rc1, see the commitc9bb03ac2c66bc5aa81b("kbuild: reduce output spam when building out of tree").The commit message says:
<paste>
TheMakefileis now created even if the build is aborted due to an unclean working tree. That should not make a difference in practice.
</paste>It seems that is actually makes a difference in the livepatch selftest case.
Sigh, the
Makefilerules are a maze to me. It is possible that we do something wrong intools/testing/selftests/livepatch/test_modules/Makefile. Namely with:Quoted 43 lines
ifneq ("$(wildcard $(KDIR))", "")
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)endif
But I see "$(MAKE) -C ..." called in many other makefiles.
Best Regards,
PetrQuoted 34 lines
I'm not quite sure that it could be related to my toolchain (like make version ?), I briefed analysis the root cause on my environment (KDIR '
/lib/modules/7.1.0-next-20260619/build' which actually a symbol link to my kernel source -> '/home/shiyu.dzl/linux-next'):1.
sub_make_doneleaks via environment. The top-levelMakefilesets exportsub_make_done:= 1 after its first-pass initialization.
Because it is exported, every child make process inherits it.
2. livepatchtest_modulesre-invokes the top-levelMakefile. The call
chain is: top-levelMakefile→ kselftest-% pattern rule →
tools/testing/selftests/→ livepatch test_modules/Makefile → $(MAKE) -C
$(KDIR) modules KBUILD_EXTMOD=..., which re-enters the top-levelMakefileto
build an external module.
3. The inherited sub_make_done=1 skips critical initialization. The
top-level Makefile's first-pass block (ifneq ($(sub_make_done),1)) is
skipped entirely. This block is responsible for correctly parsing
command-line variables and setting up KBUILD_EXTMOD-related paths.
4. Path mismatch triggers false out-of-tree detection. With the
initialization skipped, srcroot and CURDIR end up with mismatched values (e.g.,
absolute vs. relative). The comparison (ifeq ($(srcroot),$(CURDIR)))
fails, sobuilding_out_of_srctreeis incorrectly set to 1.
5. outputmakefile overwrites the source tree'sMakefile. Becausebuilding_out_of_srctreeis set, thefilechk_makefilerule fires and replaces the
real top-levelMakefilewith a generated stub containingKBUILD_OUTPUT,KBUILD_EXTMOD, and an include directive.Why make -C
tools/testing/selftests/all is unaffected: it enters the
selftests directory directly without ever executing the top-levelMakefile
first, sosub_make_doneis never exported into the environment. When
livepatchtest_moduleslater invokes $(MAKE) -C $(KDIR), the top-levelMakefile
runs its full initialization normally.Can you try this:
Makefile +2
-2@@ -1591,10 +1591,10 @@ tools/%: FORCE PHONY += kselftest kselftest: headers - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests kselftest-%: headers FORCE - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $*
Quoted 8 lines
Quoted 5 lines
Makefile tools/%: FORCE · line 1600
Quoted 2 lines
Makefile +0
-0PHONY += kselftest-merge kselftest-merge:Heh, this is exactly the same change which Zelin Deng proposed as well, see
https://lore.kernel.org/all/[email protected]/The difference is that my proposal is in the toplevel
Makefilewhile Zelin's is in the selftest one. The toplevel one should fix all selftests at the same time.
Thank you Petr. Yeah, Thomas's proposal is in top-level Makefile - if any other selftest also re-invokes the top-level Makefile with KBUILD_EXTMOD, it'd be covered too.
Quoted 11 lines
Quoted 9 lines
Quoted 2 lines
The same is done for
cmd_install.I guess that this is related to the commit
14ccc638b02f9ec("kbuild:
cancelsub_make_donefor the install target to fix DKMS"). Which is related to the commitbcf637f54f6d2515d("kbuild: parse C= and M= before changing the working directory").Honestly, it all looks like a wild magic to me. I would need much better understanding of the
Makefilemaze to get on top of it.I was not able to reproduce the issue yet. My proposal is just a guess. We'll need feedback from Zelin.
I had verify your proposal, it worked well - liveupatch kmod was built successfully and top-level Makefile wasn't overwritten any more.
Petr thank you for your Ack, I think Thomas's proposal is better than mine, we don't have to do the quirk everytime when new selftest kmod is added.
Thomas, so do I have to send a updated patch or you will do it by youself?
Quoted 7 lines
Quoted 5 lines
But it seems that it is a reasonable fix after all. It solves the original problem. It does not break my workflow. So, I tend to add:
Acked-by Petr Mladek <[email protected]>Thomas
Quoted 1 line · Zelin Deng
在 2026/7/1 23:19, Thomas Weißschuh 写道:
(...)
Quoted 2 lines
I had verify your proposal, it worked well - liveupatch kmod was built successfully and top-level
Makefilewasn't overwritten any more.
Thanks for testing!
Quoted 4 lines
Petr thank you for your Ack, I think Thomas's proposal is better than mine, we don't have to do the quirk everytime when new selftest kmod is added.
Thomas, so do I have to send a updated patch or you will do it by youself?
Your choice. You did most of the work, so should be credited as author. If you don't want I can do it, too.
Thomas
Quoted 3 lines · Thomas Weißschuh
Quoted 1 line · Zelin Deng
在 2026/7/1 23:19, Thomas Weißschuh 写道:
(...)
:) Now client language has changed.
Quoted 10 lines
Quoted 2 lines
I had verify your proposal, it worked well - liveupatch kmod was built successfully and top-level
Makefilewasn't overwritten any more.Thanks for testing!
Quoted 4 lines
Petr thank you for your Ack, I think Thomas's proposal is better than mine, we don't have to do the quirk everytime when new selftest kmod is added.
Thomas, so do I have to send a updated patch or you will do it by youself?
Your choice. You did most of the work, so should be credited as author. If you don't want I can do it, too.
Never mind, it will be good if you can do the change, so please do it thank you. I'm just glad to report the issue and get some positive feedbacks.
Quoted 2 lines
Thomas