mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Arnd Bergmann' <arnd@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"x86@kernel.org" <x86@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	Andy Shevchenko <andy@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Sean Christopherson <seanjc@google.com>,
	Davide Ciminaghi <ciminaghi@gnudd.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: RE: [PATCH 09/11] x86: rework CONFIG_GENERIC_CPU compiler flags
Date: Fri, 6 Dec 2024 13:56:53 +0000	[thread overview]
Message-ID: <0163dae8b39b48c2b3ab9e26ed7279bc@AcuMS.aculab.com> (raw)
In-Reply-To: <20241204103042.1904639-10-arnd@kernel.org>

From: Arnd Bergmann
> Sent: 04 December 2024 10:31
> Building an x86-64 kernel with CONFIG_GENERIC_CPU is documented to
> run on all CPUs, but the Makefile does not actually pass an -march=
> argument, instead relying on the default that was used to configure
> the toolchain.
> 
> In many cases, gcc will be configured to -march=x86-64 or -march=k8
> for maximum compatibility, but in other cases a distribution default
> may be either raised to a more recent ISA, or set to -march=native
> to build for the CPU used for compilation. This still works in the
> case of building a custom kernel for the local machine.
> 
> The point where it breaks down is building a kernel for another
> machine that is older the the default target. Changing the default
> to -march=x86-64 would make it work reliable, but possibly produce
> worse code on distros that intentionally default to a newer ISA.
> 
> To allow reliably building a kernel for either the oldest x86-64
> CPUs or a more recent level, add three separate options for
> v1, v2 and v3 of the architecture as defined by gcc and clang
> and make them all turn on CONFIG_GENERIC_CPU. Based on this it
> should be possible to change runtime feature detection into
> build-time detection for things like cmpxchg16b, or possibly
> gate features that are only available on older architectures.
> 
> Link: https://lists.llvm.org/pipermail/llvm-dev/2020-July/143289.html
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  arch/x86/Kconfig.cpu | 39 ++++++++++++++++++++++++++++++++++-----
>  arch/x86/Makefile    |  6 ++++++
>  2 files changed, 40 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
> index 139db904e564..1461a739237b 100644
> --- a/arch/x86/Kconfig.cpu
> +++ b/arch/x86/Kconfig.cpu
> @@ -260,7 +260,7 @@ endchoice
>  choice
>  	prompt "x86-64 Processor family"
>  	depends on X86_64
> -	default GENERIC_CPU
> +	default X86_64_V2
>  	help
>  	  This is the processor type of your CPU. This information is
>  	  used for optimizing purposes. In order to compile a kernel
> @@ -314,15 +314,44 @@ config MSILVERMONT
>  	  early Atom CPUs based on the Bonnell microarchitecture,
>  	  such as Atom 230/330, D4xx/D5xx, D2xxx, N2xxx or Z2xxx.
> 
> -config GENERIC_CPU
> -	bool "Generic-x86-64"
> +config X86_64_V1
> +	bool "Generic x86-64"
>  	depends on X86_64
>  	help
> -	  Generic x86-64 CPU.
> -	  Run equally well on all x86-64 CPUs.
> +	  Generic x86-64-v1 CPU.
> +	  Run equally well on all x86-64 CPUs, including early Pentium-4
> +	  variants lacking the sahf and cmpxchg16b instructions as well
> +	  as the AMD K8 and Intel Core 2 lacking popcnt.

The 'equally well' text was clearly always wrong (equally badly?)
but is now just 'plain wrong'.
Perhaps:
	Runs on all x86-64 CPUs including early cpu that lack the sahf,
	cmpxchg16b and popcnt instructions.

Then for V2 (or whatever it gets called)
	Requires support for the sahf, cmpxchg16b and popcnt instructions.
	This will not run on AMD K8 or Intel before Sandy bridge.

I think someone suggested that run-time detect of AVX/AVX2/AVX512
is fine?

	David

> +
> +config X86_64_V2
> +	bool "Generic x86-64 v2"
> +	depends on X86_64
> +	help
> +	  Generic x86-64-v2 CPU.
> +	  Run equally well on all x86-64 CPUs that meet the x86-64-v2
> +	  definition as well as those that only miss the optional
> +	  SSE3/SSSE3/SSE4.1 portions.
> +	  Examples of this include Intel Nehalem and Silvermont,
> +	  AMD Bulldozer (K10) and Jaguar as well as VIA Nano that
> +	  include popcnt, cmpxchg16b and sahf.
> +
> +config X86_64_V3
> +	bool "Generic x86-64 v3"
> +	depends on X86_64
> +	help
> +	  Generic x86-64-v3 CPU.
> +	  Run equally well on all x86-64 CPUs that meet the x86-64-v3
> +	  definition as well as those that only miss the optional
> +	  AVX/AVX2 portions.
> +	  Examples of this include the Intel Haswell and AMD Excavator
> +	  microarchitectures that include the bmi1/bmi2, lzncnt, movbe
> +	  and xsave instruction set extensions.
> 
>  endchoice
> 
> +config GENERIC_CPU
> +	def_bool X86_64_V1 || X86_64_V2 || X86_64_V3
> +
>  config X86_GENERIC
>  	bool "Generic x86 support"
>  	depends on X86_32
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index 05887ae282f5..1fdc3fc6a54e 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -183,6 +183,9 @@ else
>          cflags-$(CONFIG_MPSC)		+= -march=nocona
>          cflags-$(CONFIG_MCORE2)		+= -march=core2
>          cflags-$(CONFIG_MSILVERMONT)	+= -march=silvermont
> +        cflags-$(CONFIG_MX86_64_V1)	+= -march=x86-64
> +        cflags-$(CONFIG_MX86_64_V2)	+= $(call cc-option,-march=x86-64-v2,-march=x86-64)
> +        cflags-$(CONFIG_MX86_64_V3)	+= $(call cc-option,-march=x86-64-v3,-march=x86-64)
>          cflags-$(CONFIG_GENERIC_CPU)	+= -mtune=generic
>          KBUILD_CFLAGS += $(cflags-y)
> 
> @@ -190,6 +193,9 @@ else
>          rustflags-$(CONFIG_MPSC)	+= -Ctarget-cpu=nocona
>          rustflags-$(CONFIG_MCORE2)	+= -Ctarget-cpu=core2
>          rustflags-$(CONFIG_MSILVERMONT)	+= -Ctarget-cpu=silvermont
> +        rustflags-$(CONFIG_MX86_64_V1)	+= -Ctarget-cpu=x86-64
> +        rustflags-$(CONFIG_MX86_64_V2)	+= -Ctarget-cpu=x86-64-v2
> +        rustflags-$(CONFIG_MX86_64_V3)	+= -Ctarget-cpu=x86-64-v3
>          rustflags-$(CONFIG_GENERIC_CPU)	+= -Ztune-cpu=generic
>          KBUILD_RUSTFLAGS += $(rustflags-y)
> 
> --
> 2.39.5
> 

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  parent reply	other threads:[~2024-12-06 13:57 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 10:30 [PATCH 00/11] x86: 32-bit cleanups Arnd Bergmann
2024-12-04 10:30 ` [PATCH 01/11] x86/Kconfig: Geode CPU has cmpxchg8b Arnd Bergmann
2024-12-04 10:30 ` [PATCH 02/11] x86: drop 32-bit "bigsmp" machine support Arnd Bergmann
2024-12-04 10:30 ` [PATCH 03/11] x86: Kconfig.cpu: split out 64-bit atom Arnd Bergmann
2024-12-04 13:16   ` Thomas Gleixner
2024-12-04 15:55     ` H. Peter Anvin
2024-12-04 18:21       ` Andy Shevchenko
2024-12-04 10:30 ` [PATCH 04/11] x86: split CPU selection into 32-bit and 64-bit Arnd Bergmann
2024-12-04 18:31   ` Andy Shevchenko
2024-12-04 21:18     ` Arnd Bergmann
2024-12-04 10:30 ` [PATCH 05/11] x86: remove HIGHMEM64G support Arnd Bergmann
2024-12-04 13:29   ` Brian Gerst
2024-12-04 13:43     ` Arnd Bergmann
2024-12-04 14:02       ` Brian Gerst
2024-12-04 15:00         ` Brian Gerst
2024-12-04 15:58         ` H. Peter Anvin
2024-12-04 15:53       ` H. Peter Anvin
2024-12-04 16:37     ` H. Peter Anvin
2024-12-04 16:55       ` Arnd Bergmann
2024-12-04 18:37         ` Andy Shevchenko
2024-12-04 21:14           ` Arnd Bergmann
2025-04-11 23:44   ` Dave Hansen
2025-04-12  8:39     ` Ingo Molnar
2025-04-12 10:05     ` Mike Rapoport
2025-04-12 10:44       ` Arnd Bergmann
2025-04-12 19:48       ` Ingo Molnar
2025-04-13  8:08         ` [PATCH] x86/e820: discard high memory that can't be addressed by 32-bit systems Mike Rapoport
2025-04-13  9:23           ` [tip: x86/urgent] x86/e820: Discard " tip-bot2 for Mike Rapoport (Microsoft)
2025-04-14 14:19             ` Dave Hansen
2025-04-15  7:18               ` Mike Rapoport
2025-04-15 13:43                 ` Dave Hansen
2025-04-16  7:17                   ` Ingo Molnar
2025-04-16  7:51                     ` Ingo Molnar
2025-04-16  7:24           ` tip-bot2 for Mike Rapoport (Microsoft)
2025-04-16  8:16           ` tip-bot2 for Mike Rapoport (Microsoft)
2025-04-17 16:22           ` [PATCH] x86/e820: discard " Nathan Chancellor
2025-04-18  6:33             ` Ingo Molnar
2025-04-18  9:01               ` Mike Rapoport
2025-04-18 12:59                 ` Ingo Molnar
2025-04-18 19:25                   ` Mike Rapoport
2025-04-18 19:29                     ` Dave Hansen
2025-04-18 19:49           ` Guenter Roeck
2025-04-12 10:40     ` [PATCH 05/11] x86: remove HIGHMEM64G support Arnd Bergmann
2024-12-04 10:30 ` [PATCH 06/11] x86: drop SWIOTLB and PHYS_ADDR_T_64BIT for PAE Arnd Bergmann
2024-12-04 18:41   ` Andy Shevchenko
2024-12-04 20:52     ` Arnd Bergmann
2024-12-05  7:59       ` Andy Shevchenko
2024-12-04 10:30 ` [PATCH 07/11] x86: drop support for CONFIG_HIGHPTE Arnd Bergmann
2024-12-04 10:30 ` [PATCH 08/11] x86: document X86_INTEL_MID as 64-bit-only Arnd Bergmann
2024-12-04 18:55   ` Andy Shevchenko
2024-12-04 20:38     ` Arnd Bergmann
2024-12-05  8:03       ` Andy Shevchenko
2024-12-06 11:23     ` Ferry Toth
2024-12-06 14:27       ` Arnd Bergmann
2024-12-04 10:30 ` [PATCH 09/11] x86: rework CONFIG_GENERIC_CPU compiler flags Arnd Bergmann
2024-12-04 15:36   ` Tor Vic
2024-12-04 17:51     ` Arnd Bergmann
2024-12-04 17:09   ` Nathan Chancellor
2024-12-04 17:52     ` Arnd Bergmann
2024-12-04 18:10   ` Linus Torvalds
2024-12-04 19:43     ` Arnd Bergmann
2024-12-04 23:33       ` Linus Torvalds
2024-12-05  8:13         ` Andy Shevchenko
2024-12-05 10:09           ` Arnd Bergmann
2024-12-05 11:17             ` Andy Shevchenko
2024-12-05 11:58               ` Arnd Bergmann
2024-12-05 12:35                 ` Jason A. Donenfeld
2024-12-05  9:46         ` Arnd Bergmann
2024-12-05 10:01           ` Andy Shevchenko
2024-12-05 10:47             ` Arnd Bergmann
2024-12-05  8:07       ` Andy Shevchenko
2024-12-06 13:56   ` David Laight [this message]
2024-12-04 10:30 ` [PATCH 10/11] x86: remove old STA2x11 support Arnd Bergmann
2024-12-05  7:35   ` Davide Ciminaghi
2024-12-04 10:30 ` [PATCH 11/11] x86: drop 32-bit KVM host support Arnd Bergmann
2024-12-04 15:30   ` Sean Christopherson
2024-12-04 16:33     ` Arnd Bergmann

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=0163dae8b39b48c2b3ab9e26ed7279bc@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=andy@kernel.org \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=bp@alien8.de \
    --cc=ciminaghi@gnudd.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    /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

Powered by JetHome