[PATCH 04/15] x86/kbuild: Introduce the 'x86_32' subarchitecture

Ingo Molnar posted 15 patches 7 months, 2 weeks ago
[PATCH 04/15] x86/kbuild: Introduce the 'x86_32' subarchitecture
Posted by Ingo Molnar 7 months, 2 weeks ago
These days the canonical counterpart to the x86_64 architecture
is the x86_32 architecture - except our Makefiles don't accept it
as an ARCH target.

Make it so.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Michal Marek <michal.lkml@markovi.net>
---
 Makefile                                              |  7 +++++--
 arch/x86/Kconfig                                      |  2 +-
 arch/x86/Makefile                                     | 10 +++++++---
 arch/x86/configs/{defconfig.i386 => defconfig.x86_32} |  0
 tools/scripts/Makefile.arch                           |  7 +++++--
 5 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index b29cc321ffd9..84a4912f3343 100644
--- a/Makefile
+++ b/Makefile
@@ -407,10 +407,13 @@ UTS_MACHINE 	:= $(ARCH)
 SRCARCH 	:= $(ARCH)
 
 # Additional ARCH settings for x86
-ifeq ($(ARCH),i386)
+ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
-ifeq ($(ARCH),x86_64)
+ifeq ($(ARCH),x86_32)
+        SRCARCH := x86
+endif
+ifeq ($(ARCH),i386)
         SRCARCH := x86
 endif
 
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 4b9f378e05f6..3282638072b9 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2,7 +2,7 @@
 # Select 32 or 64 bit
 config 64BIT
 	bool "64-bit kernel" if "$(ARCH)" = "x86"
-	default "$(ARCH)" != "i386"
+	default "$(ARCH)" != "i386" && "$(ARCH)" != "x86_32"
 	help
 	  Say yes to build a 64-bit kernel - formerly known as x86_64
 	  Say no to build a 32-bit kernel - formerly known as i386
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index bae2c7bbb8db..fb4f0f15d1df 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -1,15 +1,19 @@
 # SPDX-License-Identifier: GPL-2.0
-# Unified Makefile for i386 and x86_64
+# Unified Makefile for x86_64 and x86_32
 
-# select defconfig based on actual architecture
+# When in doubt, select defconfig based on host architecture:
 ifeq ($(ARCH),x86)
   ifeq ($(shell uname -m | sed -e 's/i.86/i386/'),i386)
-        KBUILD_DEFCONFIG := defconfig.i386
+        KBUILD_DEFCONFIG := defconfig.x86_32
   else
         KBUILD_DEFCONFIG := defconfig.x86_64
   endif
 else
+  ifeq ($(ARCH),i386)
+        KBUILD_DEFCONFIG := defconfig.x86_32
+  else
         KBUILD_DEFCONFIG := defconfig.$(ARCH)
+  endif
 endif
 
 ifdef CONFIG_CC_IS_GCC
diff --git a/arch/x86/configs/defconfig.i386 b/arch/x86/configs/defconfig.x86_32
similarity index 100%
rename from arch/x86/configs/defconfig.i386
rename to arch/x86/configs/defconfig.x86_32
diff --git a/tools/scripts/Makefile.arch b/tools/scripts/Makefile.arch
index eabfe9f411d9..9aedca27ac9a 100644
--- a/tools/scripts/Makefile.arch
+++ b/tools/scripts/Makefile.arch
@@ -14,10 +14,13 @@ endif
 SRCARCH := $(ARCH)
 
 # Additional ARCH settings for x86
-ifeq ($(ARCH),i386)
+ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
-ifeq ($(ARCH),x86_64)
+ifeq ($(ARCH),x86_32)
+        SRCARCH := x86
+endif
+ifeq ($(ARCH),i386)
         SRCARCH := x86
 endif
 
-- 
2.45.2
Re: [PATCH 04/15] x86/kbuild: Introduce the 'x86_32' subarchitecture
Posted by Arnd Bergmann 7 months, 2 weeks ago
On Tue, May 6, 2025, at 19:09, Ingo Molnar wrote:
> 
>  # Additional ARCH settings for x86
> -ifeq ($(ARCH),i386)
> +ifeq ($(ARCH),x86_64)
>          SRCARCH := x86
>  endif
> -ifeq ($(ARCH),x86_64)
> +ifeq ($(ARCH),x86_32)
> +        SRCARCH := x86
> +endif
> +ifeq ($(ARCH),i386)
>          SRCARCH := x86
>  endif

Would it be possible to just remove the entire SRCARCH hack
for x86? It's not clear from the changelog what the intention
was in 2007 when it was added, but my impression was that
this should be a temporary workaround to users doing
'make defconfig' on i386 would still get a 32-bit config
by default and didn't have to change there scripts.

I would guess that even in a 'setarch --32bit' environment,
most users today would want to build a 64-bit kernel, having
the special case for that seems to add more confusion that
it avoids.

Also, I don't think there are any systems that return
'x86_32' from 'uname -m', so your added special case
would never be used by default, only when cross-compiling
from some other architecture.

      Arnd
Re: [PATCH 04/15] x86/kbuild: Introduce the 'x86_32' subarchitecture
Posted by Ingo Molnar 7 months, 2 weeks ago
* Arnd Bergmann <arnd@arndb.de> wrote:

> On Tue, May 6, 2025, at 19:09, Ingo Molnar wrote:
> > 
> >  # Additional ARCH settings for x86
> > -ifeq ($(ARCH),i386)
> > +ifeq ($(ARCH),x86_64)
> >          SRCARCH := x86
> >  endif
> > -ifeq ($(ARCH),x86_64)
> > +ifeq ($(ARCH),x86_32)
> > +        SRCARCH := x86
> > +endif
> > +ifeq ($(ARCH),i386)
> >          SRCARCH := x86
> >  endif
> 
> Would it be possible to just remove the entire SRCARCH hack for x86? 
> It's not clear from the changelog what the intention was in 2007 when 
> it was added, but my impression was that this should be a temporary 
> workaround to users doing 'make defconfig' on i386 would still get a 
> 32-bit config by default and didn't have to change there scripts.

Correct, this was done during the x86 unification: a significant number 
of kernel developers were still using 32-bit x86 systems, and they 
expected the host architecture to be used by default like it was when 
it lived in arch/i386/.

Ie. it was a 'seamless x86 unification' build feature.

I'd be glad to add a tested patch for SRCARCH hack removal, which 
should simplify things a bit.

> Also, I don't think there are any systems that return 'x86_32' from 
> 'uname -m', so your added special case would never be used by 
> default, only when cross-compiling from some other architecture.

No, on most 32-bit systems 'uname -m' returns 'i686', which we cannot 
use straight away anyway. And it looked a bit silly to me for us to 
fudge over the architecture from 'i686' to 'i386', when we haven't 
supported i386 for quite some while and are now working on i486 
removal...

Let's just have x86_32 as the internal primary subarchitecture name, 
with support for historic aliases like 'i386'. That it cleans up things 
for defconfig naming is a bonus.

Thanks,

	Ingo
Re: [PATCH 04/15] x86/kbuild: Introduce the 'x86_32' subarchitecture
Posted by Arnd Bergmann 7 months, 2 weeks ago
On Wed, May 7, 2025, at 08:35, Ingo Molnar wrote:
> * Arnd Bergmann <arnd@arndb.de> wrote:
>> On Tue, May 6, 2025, at 19:09, Ingo Molnar wrote:


>> Also, I don't think there are any systems that return 'x86_32' from 
>> 'uname -m', so your added special case would never be used by 
>> default, only when cross-compiling from some other architecture.
>
> No, on most 32-bit systems 'uname -m' returns 'i686', which we cannot 
> use straight away anyway. And it looked a bit silly to me for us to 
> fudge over the architecture from 'i686' to 'i386', when we haven't 
> supported i386 for quite some while and are now working on i486 
> removal...
>
> Let's just have x86_32 as the internal primary subarchitecture name, 
> with support for historic aliases like 'i386'. That it cleans up things 
> for defconfig naming is a bonus.

If we're going to remove the ARCH=i386 stuff anyway, I wouldn't add
x86_32 now, what I suggested was to  remove both i386 and x86_64 as
identifiers here and just keep ARCH=x86 internally. It's only used
in two places anyway: the 'make defconfig' and the CONFIG_64BIT
selection.

The SUBARCH= logic is independent of that, this bit is only used
for arch/um/, though that would have to change the same way as
arch/x86

      Arnd
Re: [PATCH 04/15] x86/kbuild: Introduce the 'x86_32' subarchitecture
Posted by David Laight 7 months, 2 weeks ago
On Wed, 7 May 2025 08:35:05 +0200
Ingo Molnar <mingo@kernel.org> wrote:

...
> Let's just have x86_32 as the internal primary subarchitecture name, 
> with support for historic aliases like 'i386'. That it cleans up things 
> for defconfig naming is a bonus.

Aren't there 3 variants?
Although the 3rd x32? running ILP32 in 'long mode' isn't used much
(if at all?)

	David
Re: [PATCH 04/15] x86/kbuild: Introduce the 'x86_32' subarchitecture
Posted by H. Peter Anvin 7 months, 2 weeks ago
On May 9, 2025 5:04:38 AM PDT, David Laight <david.laight.linux@gmail.com> wrote:
>On Wed, 7 May 2025 08:35:05 +0200
>Ingo Molnar <mingo@kernel.org> wrote:
>
>...
>> Let's just have x86_32 as the internal primary subarchitecture name, 
>> with support for historic aliases like 'i386'. That it cleans up things 
>> for defconfig naming is a bonus.
>
>Aren't there 3 variants?
>Although the 3rd x32? running ILP32 in 'long mode' isn't used much
>(if at all?)
>
>	David

x32 is user space only.