Skip to contentSkip to conversation

kbuild: serialize scripts after scripts_unifdef

PATCH In review HONG Yifan 3 participants 4 messages Dec 3 – Dec 4

Subsystems (2)
lore
Share & tools
lore

HONG Yifan

author
#0 lore raw

PATCH 1/1 kbuild: serialize scripts after scripts_unifdef

When CONFIG_HEADERS_INSTALL is enabled, the prepare target depends on both prepare0 -> archprepare -> scripts and headers -> scripts_unifdef with no ordering between scripts and scripts_unifdef. Both targets invoke $(MAKE) $(build)=scripts concurrently:

  scripts:         $(MAKE) $(build)=scripts
  scripts_unifdef: $(MAKE) $(build)=scripts scripts/unifdef

Because scripts/Makefile lists unifdef in hostprogs, scripts/Makefile.host adds scripts/unifdef to targets, causing scripts/Makefile.build to include scripts/.unifdef.cmd as soon as scripts/unifdef exists. If scripts reads scripts/.unifdef.cmd while scripts_unifdef is still writing it via fixdep, make aborts with:

scripts/.unifdef.cmd:1: *** missing separator. Stop. make[2]: *** [Makefile:1400: scripts] Error 2

Make scripts depend on scripts_unifdef under CONFIG_HEADERS_INSTALL so scripts_unifdef finishes before scripts enters scripts/. Keeping the dependency under CONFIG_HEADERS_INSTALL avoids building scripts/unifdef when it is not needed and preserves "make headers" without a .config.

Bug triage, instrumented reproduction, and patch drafting were assisted by Gemini.

Fixes e949f4c2d6a3 ("kbuild: add CONFIG_HEADERS_INSTALL and loosen the dependency of samples")
---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 5aac6f1b011e..787e041b5d7e 100644
@@ -1518,6 +1518,7 @@ endif
 
 ifdef CONFIG_HEADERS_INSTALL
 prepare: headers
+scripts: scripts_unifdef
 endif
 
 PHONY += scripts_gen_init_cpio

base-commit: 63fdb511c27afcebce797e3db580b3534ddfa639

Signature · 1 line
2.56.1.915.g69d5ec7298-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · HONG Yifan

When CONFIG_HEADERS_INSTALL is enabled, the prepare target depends on both prepare0 -> archprepare -> scripts and headers -> scripts_unifdef with no ordering between scripts and scripts_unifdef. Both targets invoke $(MAKE) $(build)=scripts concurrently:

  scripts:         $(MAKE) $(build)=scripts
  scripts_unifdef: $(MAKE) $(build)=scripts scripts/unifdef

Because scripts/Makefile lists unifdef in hostprogs, scripts/Makefile.host adds scripts/unifdef to targets, causing scripts/Makefile.build to include scripts/.unifdef.cmd as soon as scripts/unifdef exists. If scripts reads scripts/.unifdef.cmd while scripts_unifdef is still writing it via fixdep, make aborts with:

scripts/.unifdef.cmd:1: *** missing separator. Stop. make[2]: *** [Makefile:1400: scripts] Error 2

Make scripts depend on scripts_unifdef under CONFIG_HEADERS_INSTALL so scripts_unifdef finishes before scripts enters scripts/. Keeping the dependency under CONFIG_HEADERS_INSTALL avoids building scripts/unifdef when it is not needed and preserves "make headers" without a .config.

Bug triage, instrumented reproduction, and patch drafting were assisted by Gemini.

Quoted 7 lines
Fixes e949f4c2d6a3 ("kbuild: add CONFIG_HEADERS_INSTALL and loosen the dependency of samples")
---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Signature · 1 line
Nicolas
#2 lore raw
In reply to HONG Yifan
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] kbuild: scripts and recursive scripts_unifdef still race on ARCH=um --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] kbuild: scripts and recursive scripts_unifdef still race on ARCH=um
--

commit 4bf37da0ae8b1fb30389763a88c140890a30608d
Author: HONG Yifan <[email protected]>

kbuild: serialize scripts after scripts_unifdef

This commit adds scripts_unifdef as a prerequisite of scripts under CONFIG_HEADERS_INSTALL to serialize the two targets during parallel builds.

Makefile endif · line 1524

Quoted 12 lines
Makefile +1 -0
index 5aac6f1b011e1..787e041b5d7e3 100644
@@ -1518,6 +1518,7 @@ endif
 
 ifdef CONFIG_HEADERS_INSTALL
 prepare: headers
+scripts: scripts_unifdef
 endif
 
 PHONY += scripts_gen_init_cpio

[Severity: Medium]
Can scripts still race with scripts_unifdef on ARCH=um?

Adding scripts: scripts_unifdef orders scripts after the outer scripts_unifdef, but not after headers. On ARCH=um with CONFIG_HEADERS_INSTALL=y, arch/um/Makefile defines HEADER_ARCH, so headers spawns a recursive make headers that runs scripts_unifdef again:

scripts headers
$(MAKE) $(build)=scripts $(MAKE) ... SRCARCH=$(HEADER_ARCH) headers

                                scripts_unifdef
                                  $(MAKE) $(build)=scripts scripts/unifdef

cmd_and_fixdep writes -include scripts/.*.cmd
scripts/.*.cmd <-- missing separator

Both $(build)=scripts invocations include .cmd files for all existing hostprogs in scripts/ via scripts/Makefile.build, while cmd_and_fixdep writes them non-atomically via shell redirection. The recursive scripts_unifdef can read a partial .cmd file and fail with missing separator.

With CONFIG_WERROR=y (such as ARCH=um allmodconfig), the recursive headers sub-make skips auto.conf and drops -Werror and -Wl,--fatal-warnings, so recursive scripts_unifdef also recompiles scripts/unifdef and rewrites scripts/.unifdef.cmd concurrently with scripts.

Ordering scripts after headers under CONFIG_HEADERS_INSTALL would serialize both invocations.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw
Quoted 26 lines · On Fri, Dec 4, 2026 at 11:18 AM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] kbuild: scripts and recursive scripts_unifdef still race on ARCH=um
--

commit 4bf37da0ae8b1fb30389763a88c140890a30608d
Author: HONG Yifan <[email protected]>

kbuild: serialize scripts after scripts_unifdef

This commit adds scripts_unifdef as a prerequisite of scripts under CONFIG_HEADERS_INSTALL to serialize the two targets during parallel builds.

Quoted 11 lines
Makefile +1 -0
index 5aac6f1b011e1..787e041b5d7e3 100644
@@ -1518,6 +1518,7 @@ endif
 
 ifdef CONFIG_HEADERS_INSTALL
 prepare: headers
+scripts: scripts_unifdef
 endif
 
Quoted 4 lines

Makefile endif · line 1524

Quoted 1 line
Makefile +0 -0
 PHONY += scripts_gen_init_cpio

[Severity: Medium]
Can scripts still race with scripts_unifdef on ARCH=um?

Short answer: yes.

Quoted 18 lines

Adding scripts: scripts_unifdef orders scripts after the outer scripts_unifdef, but not after headers. On ARCH=um with CONFIG_HEADERS_INSTALL=y, arch/um/Makefile defines HEADER_ARCH, so headers spawns a recursive make headers that runs scripts_unifdef again:

scripts headers
$(MAKE) $(build)=scripts $(MAKE) ... SRCARCH=$(HEADER_ARCH) headers

                                scripts_unifdef
                                  $(MAKE) $(build)=scripts scripts/unifdef

cmd_and_fixdep writes -include scripts/.*.cmd
scripts/.*.cmd <-- missing separator

Both $(build)=scripts invocations include .cmd files for all existing hostprogs in scripts/ via scripts/Makefile.build, while cmd_and_fixdep writes them non-atomically via shell redirection. The recursive scripts_unifdef can read a partial .cmd file and fail with missing separator.

Quoted 7 lines

With CONFIG_WERROR=y (such as ARCH=um allmodconfig), the recursive headers sub-make skips auto.conf and drops -Werror and -Wl,--fatal-warnings, so recursive scripts_unifdef also recompiles scripts/unifdef and rewrites scripts/.unifdef.cmd concurrently with scripts.

Ordering scripts after headers under CONFIG_HEADERS_INSTALL would serialize both invocations.

Problems with ordering scripts: headers:

- It serializes scripts behind installing ~1,000 UAPI headers on all architectures when CONFIG_HEADERS_INSTALL=y.
- Running make scripts standalone with CONFIG_HEADERS_INSTALL=y would install UAPI headers.
- It leaves the redundant recursive make headers on ARCH=um (and the CONFIG_WERROR scripts/unifdef recompile) unfixed.

IMHO a cleaner fix for ARCH=um is to stop headers from recursing into top-level headers when HEADER_ARCH is set, and invoke $(hdr-inst) directly with SRCARCH=$(or $(HEADER_ARCH),$(SRCARCH)) (since arch/um/Makefile's archheaders already generates the HEADER_ARCH UAPI headers).

I will send that as an independent patch targeting commit 268d191abc57 ("kbuild: implement CONFIG_HEADERS_INSTALL for Usermode Linux"), and keep this patch standalone for e949f4c2d6a3 for non-UM architectures.

Quoted 3 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1