* [PATCH] kbuild: serialize scripts after scripts_unifdef
@ 2026-12-03 19:18 HONG Yifan
2026-12-04 18:39 ` Nicolas Schier
2026-12-04 19:18 ` sashiko-bot
0 siblings, 2 replies; 4+ messages in thread
From: HONG Yifan @ 2026-12-03 19:18 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier
Cc: Masahiro Yamada, linux-kbuild, linux-kernel, kernel-team,
HONG Yifan, stable
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")
Cc: stable@vger.kernel.org
Signed-off-by: HONG Yifan <elsk@google.com>
---
Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/Makefile b/Makefile
index 5aac6f1b011e..787e041b5d7e 100644
--- a/Makefile
+++ b/Makefile
@@ -1518,6 +1518,7 @@ endif
ifdef CONFIG_HEADERS_INSTALL
prepare: headers
+scripts: scripts_unifdef
endif
PHONY += scripts_gen_init_cpio
base-commit: 63fdb511c27afcebce797e3db580b3534ddfa639
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] kbuild: serialize scripts after scripts_unifdef
2026-12-03 19:18 [PATCH] kbuild: serialize scripts after scripts_unifdef HONG Yifan
@ 2026-12-04 18:39 ` Nicolas Schier
2026-12-04 19:18 ` sashiko-bot
1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Schier @ 2026-12-04 18:39 UTC (permalink / raw)
To: HONG Yifan
Cc: Nathan Chancellor, Masahiro Yamada, linux-kbuild, linux-kernel,
kernel-team, stable
On Thu, Dec 03, 2026 at 07:18:20PM +0000, HONG Yifan wrote:
> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: HONG Yifan <elsk@google.com>
> ---
> Makefile | 1 +
> 1 file changed, 1 insertion(+)
>
Reviewed-by: Nicolas Schier <n.schier@fritz.com>
--
Nicolas
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] kbuild: serialize scripts after scripts_unifdef
2026-12-03 19:18 [PATCH] kbuild: serialize scripts after scripts_unifdef HONG Yifan
2026-12-04 18:39 ` Nicolas Schier
@ 2026-12-04 19:18 ` sashiko-bot
2026-12-04 23:07 ` Hong, Yifan
1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 19:18 UTC (permalink / raw)
To: HONG Yifan, Nathan Chancellor, Nicolas Schier
Cc: Masahiro Yamada, linux-kbuild, kernel-team
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 <elsk@google.com>
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.
> diff --git a/Makefile b/Makefile
> index 5aac6f1b011e1..787e041b5d7e3 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203191820.2576904-1-elsk@google.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] kbuild: serialize scripts after scripts_unifdef
2026-12-04 19:18 ` sashiko-bot
@ 2026-12-04 23:07 ` Hong, Yifan
0 siblings, 0 replies; 4+ messages in thread
From: Hong, Yifan @ 2026-12-04 23:07 UTC (permalink / raw)
To: sashiko-reviews
Cc: Nathan Chancellor, Nicolas Schier, Masahiro Yamada, linux-kbuild,
kernel-team
On Fri, Dec 4, 2026 at 11:18 AM <sashiko-bot@kernel.org> 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 <elsk@google.com>
>
> 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.
>
> > diff --git a/Makefile b/Makefile
> > index 5aac6f1b011e1..787e041b5d7e3 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -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?
Short answer: yes.
>
> 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.
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.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261203191820.2576904-1-elsk@google.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 23:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 19:18 [PATCH] kbuild: serialize scripts after scripts_unifdef HONG Yifan
2026-12-04 18:39 ` Nicolas Schier
2026-12-04 19:18 ` sashiko-bot
2026-12-04 23:07 ` Hong, Yifan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox