* [PATCH] x86/build: Do not allow X86_NATIVE_CPU to be enabled on non-x86_64 hosts
@ 2026-11-14 0:31 Nathan Chancellor
2026-11-14 20:25 ` Borislav Petkov
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Chancellor @ 2026-11-14 0:31 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: x86, H. Peter Anvin, Nick Desaulniers, Bill Wendling,
Justin Stitt, linux-kernel, llvm, stable, Nathan Chancellor
When cross compiling x86_64 from an aarch64 machine using clang with
CONFIG_X86_NATIVE_CPU enabled, there may be a slew of warnings from each
.c file, which makes it nearly impossible to find real issues.
'+crc' is not a recognized feature for this target (ignoring feature)
'+fp-armv8' is not a recognized feature for this target (ignoring feature)
'+lse' is not a recognized feature for this target (ignoring feature)
'+neon' is not a recognized feature for this target (ignoring feature)
'+sha2' is not a recognized feature for this target (ignoring feature)
'+sha3' is not a recognized feature for this target (ignoring feature)
'-rand' is not a recognized feature for this target (ignoring feature)
'-sme' is not a recognized feature for this target (ignoring feature)
'-sme2' is not a recognized feature for this target (ignoring feature)
'-sve' is not a recognized feature for this target (ignoring feature)
Internally, clang expands '-march=native' into a list of target features
to enable based on the detected CPU. The x86 part of the clang driver
notes
// FIXME: Reject attempts to use -march=native unless the target matches
// the host.
which was first added by the initial '-march=native' support in clang in
2009 [1] (other architecture drivers appear to have a similar problem).
Due to the lack of validation that the host CPU is an x86_64 CPU,
'-march=native' is expanded using the aarch64 host CPU's target
features, which are unrecognized by the x86 backend.
While this should obviously be fixed in the compiler, this does not help
currently released toolchains that have this issue. As a simple
workaround, only allow CONFIG_X86_NATIVE_CPU to be enabled when
targeting and running on an x86_64 host.
Cc: stable@vger.kernel.org
Fixes: ea1dcca1de12 ("x86/kbuild/64: Add the CONFIG_X86_NATIVE_CPU option to locally optimize the kernel with '-march=native'")
Link: https://github.com/llvm/llvm-project/commit/e13ada6a3b236f505b24501d456dec2518e4944c [1]
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/x86/Kconfig.cpu | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 6e7a366f0798..4043b7227e36 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -216,7 +216,7 @@ config RUSTC_HAS_APXF
config X86_NATIVE_CPU
bool "Build and optimize for local/native CPU"
- depends on X86_64
+ depends on X86_64 && $(success,test "$(shell,uname -m)" = "x86_64")
depends on CC_HAS_MARCH_NATIVE
depends on !RUST || RUSTC_HAS_APXF
help
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
change-id: 20261113-x86-no-march-native-on-non-x86_64-88233b48a7d7
Best regards,
--
Cheers,
Nathan
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] x86/build: Do not allow X86_NATIVE_CPU to be enabled on non-x86_64 hosts
2026-11-14 0:31 [PATCH] x86/build: Do not allow X86_NATIVE_CPU to be enabled on non-x86_64 hosts Nathan Chancellor
@ 2026-11-14 20:25 ` Borislav Petkov
2026-11-14 20:46 ` Nathan Chancellor
0 siblings, 1 reply; 4+ messages in thread
From: Borislav Petkov @ 2026-11-14 20:25 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Nick Desaulniers, Bill Wendling, Justin Stitt, linux-kernel,
llvm, stable
On Fri, Nov 13, 2026 at 05:31:34PM -0700, Nathan Chancellor wrote:
> When cross compiling x86_64 from an aarch64 machine using clang with
> CONFIG_X86_NATIVE_CPU enabled, there may be a slew of warnings from each
> .c file, which makes it nearly impossible to find real issues.
>
> '+crc' is not a recognized feature for this target (ignoring feature)
> '+fp-armv8' is not a recognized feature for this target (ignoring feature)
> '+lse' is not a recognized feature for this target (ignoring feature)
> '+neon' is not a recognized feature for this target (ignoring feature)
> '+sha2' is not a recognized feature for this target (ignoring feature)
> '+sha3' is not a recognized feature for this target (ignoring feature)
> '-rand' is not a recognized feature for this target (ignoring feature)
> '-sme' is not a recognized feature for this target (ignoring feature)
> '-sme2' is not a recognized feature for this target (ignoring feature)
> '-sve' is not a recognized feature for this target (ignoring feature)
>
> Internally, clang expands '-march=native' into a list of target features
> to enable based on the detected CPU. The x86 part of the clang driver
> notes
>
> // FIXME: Reject attempts to use -march=native unless the target matches
> // the host.
>
> which was first added by the initial '-march=native' support in clang in
> 2009 [1] (other architecture drivers appear to have a similar problem).
>
> Due to the lack of validation that the host CPU is an x86_64 CPU,
> '-march=native' is expanded using the aarch64 host CPU's target
> features, which are unrecognized by the x86 backend.
>
> While this should obviously be fixed in the compiler, this does not help
> currently released toolchains that have this issue. As a simple
> workaround, only allow CONFIG_X86_NATIVE_CPU to be enabled when
> targeting and running on an x86_64 host.
>
> Cc: stable@vger.kernel.org
> Fixes: ea1dcca1de12 ("x86/kbuild/64: Add the CONFIG_X86_NATIVE_CPU option to locally optimize the kernel with '-march=native'")
> Link: https://github.com/llvm/llvm-project/commit/e13ada6a3b236f505b24501d456dec2518e4944c [1]
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> arch/x86/Kconfig.cpu | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
> index 6e7a366f0798..4043b7227e36 100644
> --- a/arch/x86/Kconfig.cpu
> +++ b/arch/x86/Kconfig.cpu
> @@ -216,7 +216,7 @@ config RUSTC_HAS_APXF
>
> config X86_NATIVE_CPU
> bool "Build and optimize for local/native CPU"
> - depends on X86_64
> + depends on X86_64 && $(success,test "$(shell,uname -m)" = "x86_64")
> depends on CC_HAS_MARCH_NATIVE
> depends on !RUST || RUSTC_HAS_APXF
> help
This looks like a whack-a-mole-y fix to me. Especially if the other arches
would have the same problem.
So wouldn't a more generic fix checking
native arch == target arch
somewhere in the makefile be better?
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] x86/build: Do not allow X86_NATIVE_CPU to be enabled on non-x86_64 hosts
2026-11-14 20:25 ` Borislav Petkov
@ 2026-11-14 20:46 ` Nathan Chancellor
2026-11-14 20:58 ` Borislav Petkov
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Chancellor @ 2026-11-14 20:46 UTC (permalink / raw)
To: Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Nick Desaulniers, Bill Wendling, Justin Stitt, linux-kernel,
llvm, stable
On Sat, Nov 14, 2026 at 12:25:24PM -0800, Borislav Petkov wrote:
> This looks like a whack-a-mole-y fix to me. Especially if the other arches
> would have the same problem.
I made that comment more about the different architecture
implementations in the clang driver but I guess it could apply to the
kernel as well. However...
> So wouldn't a more generic fix checking
>
> native arch == target arch
>
> somewhere in the makefile be better?
No other architectures provide an option to turn on '-march=native' like
x86 does. It all lives within arch/x86, so I would just be adding a
check to arch/x86/Makefile instead of arch/x86/Kconfig.cpu. Making the
option unselectable seems like a better option. If other architectures
did want to add this option, I agree generically abstacting this check
would be reasonable.
--
Cheers,
Nathan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/build: Do not allow X86_NATIVE_CPU to be enabled on non-x86_64 hosts
2026-11-14 20:46 ` Nathan Chancellor
@ 2026-11-14 20:58 ` Borislav Petkov
0 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2026-11-14 20:58 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Nick Desaulniers, Bill Wendling, Justin Stitt, linux-kernel,
llvm, stable
On Sat, Nov 14, 2026 at 01:46:05PM -0700, Nathan Chancellor wrote:
> No other architectures provide an option to turn on '-march=native' like
> x86 does. It all lives within arch/x86, so I would just be adding a
> check to arch/x86/Makefile instead of arch/x86/Kconfig.cpu. Making the
> option unselectable seems like a better option. If other architectures
> did want to add this option, I agree generically abstacting this check
> would be reasonable.
Are you going to move it somewhere generic when other arches decide all of
a sudden they love the native thing?
(If it were me, I'd simply whack that native thing. It is such a waste of
energy).
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-14 20:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 0:31 [PATCH] x86/build: Do not allow X86_NATIVE_CPU to be enabled on non-x86_64 hosts Nathan Chancellor
2026-11-14 20:25 ` Borislav Petkov
2026-11-14 20:46 ` Nathan Chancellor
2026-11-14 20:58 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®