public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jakub Kicinski <kuba@kernel.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	"H. Peter Anvin (Intel)" <hpa@zytor.com>,
	Michael Kelley <mhklinux@outlook.com>,
	"Xin Li (Intel)" <xin@zytor.com>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	Nikolay Borisov <nik.borisov@suse.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] x86: don't re-generate cpufeaturemasks.h so eagerly
Date: Tue, 1 Apr 2025 09:00:06 +0200	[thread overview]
Message-ID: <Z-uO9kK0QLuKfczo@gmail.com> (raw)
In-Reply-To: <CAHk-=wi8h2fNpPBYakOMGhCk=pBSAQoLv=YG4KiTy45SZSQe7w@mail.gmail.com>


* Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Fri, 28 Mar 2025 at 17:14, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > So I think the real fix is something like this ENTIRELY UNTESTED
> > patch.  Whitespace-damaged again to make sure people don't apply this
> > mindlessly, it needs more thought:
> 
> .. and that ended up being even more whitespace-damaged than I meant
> to make it, because it also line-wrapped.
> 
> Oh well. Not pretty, but I hope people still get the idea.
> 
> And I just actually tried doing a build after touching the .config
> file, and it did seem to work.
> 
> But since I had _also_ messed with the config file on purpose earlier,
> I'm not sure I'm actually testing the thing the networking builds
> trigger. So I might be entirely missing something.
> 
> Adding Masahiro to the cc, so that somebody competent can actually
> check my thinking.
> 
> Masahiro, see the complaint (and my reply) in
> 
>     https://lore.kernel.org/all/20250328162311.08134fa6@kernel.org/
> 
> for background...

Just an update: Linus applied the fix below directly, which should 
resolve the problem. Thanks Linus!

Thanks,

	Ingo

==============>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Mon, 31 Mar 2025 14:19:55 -0700
Subject: [PATCH] x86: don't re-generate cpufeaturemasks.h so eagerly

It turns out the code to generate the x86 cpufeaturemasks.h header was
way too aggressive, and would re-generate it whenever the timestamp on
the kernel config file changed.

Now, the regular 'make *config' tools are fairly careful to not rewrite
the kernel config file unless the contents change, but other usecases
aren't that careful.

Michael Kelley reports that 'make-kpkg' ends up doing "make syncconfig"
multiple times in prepping to build, and will modify the config file in
the process (and then modify it back, but by then the timestamps have
changed).

Jakub Kicinski reports that the netdev CI does something similar in how
it generates the config file in multiple steps.

In both cases, the config file timestamp updates then cause the
cpufeaturemasks.h file to be regenerated, and that in turn then causes
lots of unnecessary rebuilds due to all the normal dependencies.

Fix it by using our 'filechk' infrastructure in the Makefile to generate
the header file.  That will only write a new version of the file if the
contents of the file have actually changed.

Fixes: 841326332bcb ("x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> header based on build config")
Reported-by: Michael Kelley <mhklinux@outlook.com>
Reported-by: Jakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/all/SN6PR02MB415756D1829740F6E8AC11D1D4D82@SN6PR02MB4157.namprd02.prod.outlook.com/
Link: https://lore.kernel.org/all/20250328162311.08134fa6@kernel.org/
Cc: Peter Anvin <hpa@zytor.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 arch/x86/Makefile | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 0fc7e8fd1a2e..27efe2dc2aa8 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -277,12 +277,11 @@ cpufeaturemasks.hdr := arch/x86/include/generated/asm/cpufeaturemasks.h
 cpufeaturemasks.awk := $(srctree)/arch/x86/tools/cpufeaturemasks.awk
 cpufeatures_hdr := $(srctree)/arch/x86/include/asm/cpufeatures.h
 targets += $(cpufeaturemasks.hdr)
-quiet_cmd_gen_featuremasks = GEN     $@
-      cmd_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) > $@
+      filechk_gen_featuremasks = $(AWK) -f $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG)
 
 $(cpufeaturemasks.hdr): $(cpufeaturemasks.awk) $(cpufeatures_hdr) $(KCONFIG_CONFIG) FORCE
 	$(shell mkdir -p $(dir $@))
-	$(call if_changed,gen_featuremasks)
+	$(call filechk,gen_featuremasks)
 archprepare: $(cpufeaturemasks.hdr)
 
 ###


  parent reply	other threads:[~2025-04-01  7:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05 18:47 [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 1/4] x86/cpufeatures: Add {required,disabled} feature configs Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 2/4] x86/cpufeatures: Generate a feature mask header based on build config Xin Li (Intel)
2025-03-10  8:18   ` [tip: x86/cpu] x86/cpufeatures: Generate the <asm/cpufeaturemasks.h> " tip-bot2 for H. Peter Anvin (Intel)
2025-03-19 11:03   ` [tip: x86/core] " tip-bot2 for H. Peter Anvin (Intel)
2025-03-20 16:23     ` Michael Kelley
2025-03-20 16:56       ` Linus Torvalds
2025-03-23 18:06         ` Michael Kelley
2025-03-28 23:23           ` Jakub Kicinski
2025-03-29  0:14             ` Linus Torvalds
2025-03-29  0:22               ` Linus Torvalds
2025-03-29  0:56                 ` Jakub Kicinski
2025-04-01  7:00                 ` Ingo Molnar [this message]
2025-03-29  0:56               ` H. Peter Anvin
2025-03-05 18:47 ` [PATCH v7 3/4] x86/cpufeatures: Remove {disabled,required}-features.h Xin Li (Intel)
2025-03-10  8:18   ` [tip: x86/cpu] " tip-bot2 for Xin Li (Intel)
2025-03-19 11:03   ` [tip: x86/core] " tip-bot2 for Xin Li (Intel)
2025-03-05 18:47 ` [PATCH v7 4/4] x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET Xin Li (Intel)
2025-03-07 18:28 ` [PATCH v7 0/4] x86/cpufeatures: Automatically generate required and disabled feature masks Xin Li
2025-03-07 19:18   ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z-uO9kK0QLuKfczo@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=nik.borisov@suse.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    --cc=xin@zytor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox