Skip to contentSkip to conversation

kbuild: use ARCH from compile.h in unclean source tree msg

PATCH In review Shuah Khan 4 participants 9 messages May 2, 2025 – May 7, 2025

Subsystems (2)
lore
Share & tools
lore

Shuah Khan

author maintainer
#0 lore raw

PATCH 1/1 kbuild: use ARCH from compile.h in unclean source tree msg

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

	$ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
	$ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

- Clean source tree as suggested by kbuild

	$ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
  files under arch/x86
 	arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
"undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests: it tries to build for user specified ARCH or uml as default:

	$ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_6.15
***

- Clean source tree as suggested by kbuild

	$ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
  files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

	$ ./tools/testing/kunit/kunit.py run ARCH=x86_64

"undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

	$ ./tools/testing/kunit/kunit.py run

***
*** The source tree is not clean, please run 'make ARCH=x86_64 mrproper' *** in /linux/linux_6.15
***

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 5aa9ee52a765..7ee29136b4da 100644
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
 		 -d $(srctree)/include/config -o \
 		 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
 		echo >&2 "***"; \
-		echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
+		echo >&2 "*** The source tree is not clean, please run 'make ARCH=$(shell grep UTS_MACHINE $(srctree)/include/generated/compile.h | cut -d '"' -f 2) mrproper'"; \
 		echo >&2 "*** in $(abs_srctree)";\
 		echo >&2 "***"; \
 		false; \
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 64 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

        $ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
        $ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

- Clean source tree as suggested by kbuild

        $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
  files under arch/x86
        arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
"undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests: it tries to build for user specified ARCH or uml as default:

        $ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_6.15
***

- Clean source tree as suggested by kbuild

        $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
  files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

        $ ./tools/testing/kunit/kunit.py run ARCH=x86_64

"undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

        $ ./tools/testing/kunit/kunit.py run
Quoted 7 lines

***
*** The source tree is not clean, please run 'make ARCH=x86_64 mrproper' *** in /linux/linux_6.15
***

---

Thanks very much! This is much better, and has given the right message on all of the architecture in-/out-of-tree build combinations I've thrown at it.

Cheers,
-- David

#2 lore raw
In reply to Shuah Khan
Quoted 78 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

	$ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
	$ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

- Clean source tree as suggested by kbuild

	$ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
  files under arch/x86
 	arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
"undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests: it tries to build for user specified ARCH or uml as default:

	$ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_6.15
***

- Clean source tree as suggested by kbuild

	$ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
  files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

	$ ./tools/testing/kunit/kunit.py run ARCH=x86_64

"undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

	$ ./tools/testing/kunit/kunit.py run

***
*** The source tree is not clean, please run 'make ARCH=x86_64 mrproper' *** in /linux/linux_6.15
***

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 5aa9ee52a765..7ee29136b4da 100644

Makefile ifeq ($(KBUILD_EXTMOD),) · line 677

Quoted 5 lines
Makefile +1 -1
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
 		 -d $(srctree)/include/config -o \
 		 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
 		echo >&2 "***"; \
-		echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
+		echo >&2 "*** The source tree is not clean, please run 'make ARCH=$(shell grep UTS_MACHINE $(srctree)/include/generated/compile.h | cut -d '"' -f 2) mrproper'"; \

Please 'grep' option '-s'.

There are some (rare) occassions, when there is no include/generated/compile.h but still the source tree will be considered to be dirty:

grep: ../include/generated/compile.h: No such file or directory
***
*** The source tree is not clean, please run 'make ARCH= mrproper'
...

Kind regards,
Nicolas

author maintainer
#3 lore raw
Quoted 75 lines · Nicolas Schier
Quoted 73 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

	$ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
	$ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

- Clean source tree as suggested by kbuild

	$ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86
  	arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
"undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests: it tries to build for user specified ARCH or uml as default:

	$ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

   ***
   *** The source tree is not clean, please run 'make ARCH=um mrproper'
   *** in /linux/linux_6.15
   ***

- Clean source tree as suggested by kbuild

	$ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

	$ ./tools/testing/kunit/kunit.py run ARCH=x86_64

"undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

	$ ./tools/testing/kunit/kunit.py run
   ***
   *** The source tree is not clean, please run 'make ARCH=x86_64 mrproper'
   *** in /linux/linux_6.15
   ***
---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 675

Quoted 7 lines
Makefile +0 -0
index 5aa9ee52a765..7ee29136b4da 100644
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
  		 -d $(srctree)/include/config -o \
  		 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \

Would it make sense to check for include/generated as a catch all?

Quoted 8 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 677

Quoted 3 lines
Makefile +1 -1
  		echo >&2 "***"; \
-		echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
+		echo >&2 "*** The source tree is not clean, please run 'make ARCH=$(shell grep UTS_MACHINE $(srctree)/include/generated/compile.h | cut -d '"' -f 2) mrproper'"; \

Please 'grep' option '-s'.

There are some (rare) occassions, when there is no include/generated/compile.h but still the source tree will be considered to be dirty:

I considered adding a check for not finding include/generated/compile.h and figured if include/config is found we are probably safe.

I will fix that.

Quoted 6 lines

grep: ../include/generated/compile.h: No such file or directory
***
*** The source tree is not clean, please run 'make ARCH= mrproper'
...

thanks,
-- Shuah

author maintainer
#4 lore raw
Quoted 76 lines · Shuah Khan
Quoted 75 lines · Nicolas Schier
Quoted 73 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

    $ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
    $ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

   ***
   *** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
   ***

- Clean source tree as suggested by kbuild

    $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86
      arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
   "undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests:  it tries to build for user specified ARCH or uml as default:

    $ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

   ***
   *** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_6.15
   ***

- Clean source tree as suggested by kbuild

    $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

    $ ./tools/testing/kunit/kunit.py run ARCH=x86_64

    "undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

    $ ./tools/testing/kunit/kunit.py run

   ***
   *** The source tree is not clean, please run 'make ARCH=x86_64 mrproper' *** in /linux/linux_6.15
   ***

---
  Makefile | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 9 lines
Quoted 7 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 675

Quoted 7 lines
Makefile +0 -0
index 5aa9ee52a765..7ee29136b4da 100644
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
            -d $(srctree)/include/config -o \
            -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \

Would it make sense to check for include/generated as a catch all?

Adding check is good, but it won't cover the compile.h missing. I don't know if compile.h could go missing if include/generated exists. In any case, it is good to check for compile exists or not and print appropriate message for these cases.

I have the change working. Will send it out. Thanks for the tip on the (rare) cases.

thanks,
-- Shuah

#5 lore raw
In reply to Shuah Khan
Quoted 93 lines · Shuah Khan
Quoted 75 lines · Nicolas Schier
Quoted 73 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

     $ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
     $ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

- Clean source tree as suggested by kbuild

     $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86
     arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
"undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests: it tries to build for user specified ARCH or uml as default:

     $ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

   ***
   *** The source tree is not clean, please run 'make ARCH=um mrproper'
   *** in /linux/linux_6.15
   ***

- Clean source tree as suggested by kbuild

     $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

     $ ./tools/testing/kunit/kunit.py run ARCH=x86_64

"undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

     $ ./tools/testing/kunit/kunit.py run
   ***
   *** The source tree is not clean, please run 'make ARCH=x86_64 mrproper'
   *** in /linux/linux_6.15
   ***
---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 675

Quoted 7 lines
Makefile +0 -0
index 5aa9ee52a765..7ee29136b4da 100644
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
              -d $(srctree)/include/config -o \
              -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \

Would it make sense to check for include/generated as a catch all?

Quoted 6 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 677

Quoted 3 lines
Makefile +1 -1
             echo >&2 "***"; \
-            echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
+            echo >&2 "*** The source tree is not clean, please run 'make ARCH=$(shell grep UTS_MACHINE $(srctree)/include/generated/compile.h | cut -d '"' -f 2) mrproper'"; \

Please 'grep' option '-s'.

Quoted 7 lines
Quoted 2 lines

There are some (rare) occassions, when there is no include/generated/compile.h but still the source tree will be considered to be dirty:

I considered adding a check for not finding include/generated/compile.h and figured if include/config is found we are probably safe.

I will fix that.

I do not think this patch makes sense.

Kbuild correctly detects that "the source tree is not clean enough to build with ARCH=um", and displays the following message:
***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

This is absolutely correct.

The real issue is that "make ARCH=um mrproper"
does not properly clean the source tree.

Signature · 2 lines
Best Regards
Masahiro Yamada
author maintainer
#6 lore raw
Quoted 105 lines · Masahiro Yamada
Quoted 93 lines · Shuah Khan
Quoted 75 lines · Nicolas Schier
Quoted 73 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

      $ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
      $ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

- Clean source tree as suggested by kbuild

      $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
    files under arch/x86
      arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
"undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests: it tries to build for user specified ARCH or uml as default:
$ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

    ***
    *** The source tree is not clean, please run 'make ARCH=um mrproper'
    *** in /linux/linux_6.15
    ***

- Clean source tree as suggested by kbuild

      $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
    files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

      $ ./tools/testing/kunit/kunit.py run ARCH=x86_64

"undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

      $ ./tools/testing/kunit/kunit.py run
    ***
    *** The source tree is not clean, please run 'make ARCH=x86_64 mrproper'
    *** in /linux/linux_6.15
    ***
---
   Makefile | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 675

Quoted 7 lines
Makefile +0 -0
index 5aa9ee52a765..7ee29136b4da 100644
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
               -d $(srctree)/include/config -o \
               -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \

Would it make sense to check for include/generated as a catch all?

Quoted 6 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 677

Quoted 3 lines
Makefile +1 -1
              echo >&2 "***"; \
-            echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
+            echo >&2 "*** The source tree is not clean, please run 'make ARCH=$(shell grep UTS_MACHINE $(srctree)/include/generated/compile.h | cut -d '"' -f 2) mrproper'"; \

Please 'grep' option '-s'.

Quoted 7 lines
Quoted 2 lines

There are some (rare) occassions, when there is no include/generated/compile.h but still the source tree will be considered to be dirty:

I considered adding a check for not finding include/generated/compile.h and figured if include/config is found we are probably safe.

I will fix that.

I do not think this patch makes sense.

Quoted 8 lines

Kbuild correctly detects that "the source tree is not clean enough to build with ARCH=um", and displays the following message:
***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

This is absolutely correct.

It detects it can't build um - but it doesn't detect that the source tree is not clean. The problem is once user runs 'make ARCH=um mrproper' - these checks will find the source tree clean even though it isn't - a subsequent x86_64 build could fail.

If kbuild suggests mrproper for the existing kernel build instead, the source tree will be cleaned correctly.

Quoted 5 lines

The real issue is that "make ARCH=um mrproper"
does not properly clean the source tree.

The patch you sent doesn't solve the problem I am seeing. You can find the details on the patch thread.

thanks,
-- Shuah

author maintainer
#7 lore raw
Quoted 113 lines · Shuah Khan
Quoted 112 lines · Masahiro Yamada
Quoted 93 lines · Shuah Khan
Quoted 75 lines · Nicolas Schier
Quoted 73 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

      $ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
      $ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

    ***
    *** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
    ***

- Clean source tree as suggested by kbuild

      $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
    files under arch/x86
      arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
    "undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests:  it tries to build for user specified ARCH or uml as default:

      $ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

    ***
    *** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_6.15
    ***

- Clean source tree as suggested by kbuild

      $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
    files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

      $ ./tools/testing/kunit/kunit.py run ARCH=x86_64

      "undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

      $ ./tools/testing/kunit/kunit.py run

    ***
    *** The source tree is not clean, please run 'make ARCH=x86_64 mrproper' *** in /linux/linux_6.15
    ***

---
   Makefile | 2 +-

   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 675

Quoted 7 lines
Makefile +0 -0
index 5aa9ee52a765..7ee29136b4da 100644
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
                -d $(srctree)/include/config -o \
                -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \

Would it make sense to check for include/generated as a catch all?

Quoted 6 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 677

Quoted 3 lines
Makefile +1 -1
               echo >&2 "***"; \
-            echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
+            echo >&2 "*** The source tree is not clean, please run 'make ARCH=$(shell grep UTS_MACHINE $(srctree)/include/generated/compile.h | cut -d '"' -f 2) mrproper'"; \

Please 'grep' option '-s'.

Quoted 7 lines
Quoted 2 lines

There are some (rare) occassions, when there is no include/generated/compile.h but still the source tree will be considered to be dirty:

I considered adding a check for not finding include/generated/compile.h and figured if include/config is found we are probably safe.

I will fix that.

I do not think this patch makes sense.

Kbuild correctly detects that "the source tree is not clean enough to build with ARCH=um", and displays the following message:
   ***
   *** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
   ***

Quoted 7 lines
Quoted 1 line

This is absolutely correct.

It detects it can't build um - but it doesn't detect that the source tree is not clean. The problem is once user runs 'make ARCH=um mrproper' - these checks will find the source tree clean even though it isn't - a subsequent x86_64 build could fail.

kbuild can no longer detect that the tree is unclean since mrproper um deletes files and directories kbuild checks to determine if the source tree is unclean.

These failures are hard to debug and wastes lot of time.

thanks,
-- Shuah

#8 lore raw
In reply to Shuah Khan
Quoted 93 lines · Shuah Khan
Quoted 75 lines · Nicolas Schier
Quoted 73 lines · Shuah Khan

When make finds the source tree unclean, it prints a message to run "make ARCH=x86_64 mrproper" message using the ARCH from the command line. The ARCH specified in the command line could be different from the ARCH of the existing build in the source tree.

This could cause problems in regular kernel build and kunit workflows.

Regular workflow:

- Build x86_64 kernel

     $ make ARCH=x86_64
- Try building another arch kernel out of tree with O=
     $ make ARCH=um O=/linux/build
- kbuild detects source tree is unclean

***
*** The source tree is not clean, please run 'make ARCH=um mrproper' *** in /linux/linux_srcdir
***

- Clean source tree as suggested by kbuild

     $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86
     arch/x86/realmode/rm/pasyms.h

A subsequent x86_64e build fails with
"undefined symbol sev_es_trampoline_start referenced ..."

kunit workflow runs into this issue:

- Build x86_64 kernel
- Run kunit tests: it tries to build for user specified ARCH or uml as default:

     $ ./tools/testing/kunit/kunit.py run

- kbuild detects unclean source tree

   ***
   *** The source tree is not clean, please run 'make ARCH=um mrproper'
   *** in /linux/linux_6.15
   ***

- Clean source tree as suggested by kbuild

     $ make ARCH=um mrproper
- Source clean appears to be clean, but it leaves behind generated header
   files under arch/x86

The problem shows when user tries to run tests on ARCH=x86_64:

     $ ./tools/testing/kunit/kunit.py run ARCH=x86_64

"undefined symbol sev_es_trampoline_start referenced ..."

Build trips on arch/x86/realmode/rm/pasyms.h left behind by a prior x86_64 build.

Problems related to partially cleaned source tree are hard to debug. Change Makefile to unclean source logic to use ARCH from compile.h UTS_MACHINE string. With this change kbuild prints:

     $ ./tools/testing/kunit/kunit.py run
   ***
   *** The source tree is not clean, please run 'make ARCH=x86_64 mrproper'
   *** in /linux/linux_6.15
   ***
---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 675

Quoted 7 lines
Makefile +0 -0
index 5aa9ee52a765..7ee29136b4da 100644
@@ -674,7 +674,7 @@ ifeq ($(KBUILD_EXTMOD),)
              -d $(srctree)/include/config -o \
              -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \

Would it make sense to check for include/generated as a catch all?

Quoted 6 lines

Makefile ifeq ($(KBUILD_EXTMOD),) · line 677

Quoted 3 lines
Makefile +1 -1
             echo >&2 "***"; \
-            echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
+            echo >&2 "*** The source tree is not clean, please run 'make ARCH=$(shell grep UTS_MACHINE $(srctree)/include/generated/compile.h | cut -d '"' -f 2) mrproper'"; \

Please 'grep' option '-s'.

Quoted 7 lines
Quoted 2 lines

There are some (rare) occassions, when there is no include/generated/compile.h but still the source tree will be considered to be dirty:

I considered adding a check for not finding include/generated/compile.h and figured if include/config is found we are probably safe.

I will fix that.

Does this fix your issue?

https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/

Signature · 2 lines
Best Regards
Masahiro Yamada