Commit 0e00a8c9fd92 ("powerpc: Allow CPU selection also on PPC32")
enlarged the CPU selection logic to PPC32 by removing depend to
PPC64, and failed to restrict that depend to E5500_CPU and E6500_CPU.
Fortunately that got unnoticed because -mcpu=8540 will override the
-mcpu=e500mc64 or -mpcu=e6500 as they are ealier, but that's
fragile and may no be right in the future.
Add back the depend PPC64 on E5500_CPU and E6500_CPU.
Fixes: 0e00a8c9fd92 ("powerpc: Allow CPU selection also on PPC32")
Signed-off-by: Christophe Leroy <redacted>
---
arch/powerpc/platforms/Kconfig.cputype | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Since commit 4bf4f42a2feb ("powerpc/kbuild: Set default generic
machine type for 32-bit compile"), when building a 32 bits kernel
with a bi-arch version of GCC, or when building a book3s/32 kernel,
the option -mcpu=powerpc is passed to GCC at all time, relying on it
being eventually overriden by a subsequent -mcpu=xxxx.
But when building the same kernel with a 32 bits only version of GCC,
that is not done, relying on gcc being built with the expected default
CPU.
This logic has two problems. First, it is a bit fragile to rely on
whether the GCC version is bi-arch or not, because today we can have
bi-arch versions of GCC configured with a 32 bits default. Second,
there are some versions of GCC which don't support -mcpu=powerpc,
for instance for e500 SPE-only versions.
So, stop relying on this approximative logic and allow the user to
decide whether he/she wants to use the toolchain's default CPU or if
he/she wants to set one, and allow only possible CPUs based on the
selected target.
Reported-by: Pali Rohár <pali@kernel.org>
Tested-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Cc: Segher Boessenkool <redacted>
Signed-off-by: Christophe Leroy <redacted>
---
arch/powerpc/Makefile | 26 +-------------------------
arch/powerpc/platforms/Kconfig.cputype | 21 ++++++++++++++++++---
2 files changed, 19 insertions(+), 28 deletions(-)
@@ -15,23 +15,6 @@ HAS_BIARCH := $(call cc-option-yn, -m32)# Set default 32 bits cross compilers for vdso and boot wrapperCROSS32_COMPILE?=-ifeq ($(HAS_BIARCH),y)-ifeq ($(CROSS32_COMPILE),)-ifdef CONFIG_PPC32-# These options will be overridden by any -mcpu option that the CPU-# or platform code sets later on the command line, but they are needed-# to set a sane 32-bit cpu target for the 64-bit cross compiler which-# may default to the wrong ISA.-KBUILD_CFLAGS+=-mcpu=powerpc-KBUILD_AFLAGS+=-mcpu=powerpc-endif-endif-endif--ifdef CONFIG_PPC_BOOK3S_32-KBUILD_CFLAGS+=-mcpu=powerpc-endif-# If we're on a ppc/ppc64/ppc64le machine use that defconfig, otherwise just use# ppc64_defconfig because we have nothing better to go on.uname:=$(shelluname-m)
@@ -183,6 +166,7 @@ endifendifCFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))+AFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))# Altivec option not allowed with e500mc64 in GCC.ifdef CONFIG_ALTIVEC
@@ -168,13 +168,7 @@ endifCFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))AFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))-# Altivec option not allowed with e500mc64 in GCC.-ifdef CONFIG_ALTIVEC-E5500_CPU:=-mcpu=powerpc64-else-E5500_CPU:=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)-endif-CFLAGS-$(CONFIG_E5500_CPU)+=$(E5500_CPU)+CFLAGS-$(CONFIG_E5500_CPU)+=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)CFLAGS-$(CONFIG_E6500_CPU)+=$(callcc-option,-mcpu=e6500,$(E5500_CPU))asinstr:=$(callas-instr,lis9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
On Mon, Jul 11, 2022 at 4:19 PM Christophe Leroy
[off-list ref] wrote:
quoted hunk
@@ -183,6 +183,18 @@ config 405_CPU bool "40x family" depends on 40x+config 440_CPU+ bool "440 (44x family)"+ depends on 44x++config 464_CPU+ bool "464 (44x family)"+ depends on 44x++config 476_CPU+ bool "476 (47x family)"+ depends on PPC_47x
Is there any value in building for -mcpu=440 or -mcpu=464 when targeting a 476?
Maybe add another !PPC_47x dependency for the first two. Ideally we would also
enforce that 440/464 based boards cannot be selected together with 476, though
I guess that is a separate issue.
Is there a practical difference between 440 and 464 when building kernels?
gcc seems to treat them the same way, so maybe one option for both is enough
here.
Arnd
Oops, I wanted to include Pali and Segher when I sent the series, I
prepared a script including them but used the wrong script at the end.
Le 11/07/2022 à 17:05, Arnd Bergmann a écrit :
On Mon, Jul 11, 2022 at 4:19 PM Christophe Leroy
[off-list ref] wrote:
quoted
@@ -183,6 +183,18 @@ config 405_CPU bool "40x family" depends on 40x+config 440_CPU+ bool "440 (44x family)"+ depends on 44x++config 464_CPU+ bool "464 (44x family)"+ depends on 44x++config 476_CPU+ bool "476 (47x family)"+ depends on PPC_47x
Is there any value in building for -mcpu=440 or -mcpu=464 when targeting a 476?
No idea, maybe not.
Maybe add another !PPC_47x dependency for the first two. Ideally we would also
enforce that 440/464 based boards cannot be selected together with 476, though
I guess that is a separate issue.
Yes can do that.
By the way, 440/464 boards get excluded from kernel/cputable.c when 47x
is selected
Is there a practical difference between 440 and 464 when building kernels?
gcc seems to treat them the same way, so maybe one option for both is enough
here.
Hi!
On Mon, Jul 11, 2022 at 04:19:29PM +0200, Christophe Leroy wrote:
Commit 0e00a8c9fd92 ("powerpc: Allow CPU selection also on PPC32")
enlarged the CPU selection logic to PPC32 by removing depend to
PPC64, and failed to restrict that depend to E5500_CPU and E6500_CPU.
Fortunately that got unnoticed because -mcpu=8540 will override the
-mcpu=e500mc64 or -mpcu=e6500 as they are ealier, but that's
fragile and may no be right in the future.
A later -mcpu= always overrides an earlier one. This is the same as
with all other GCC option flags, and will not change in the future.
Segher
On Mon, Jul 11, 2022 at 04:19:30PM +0200, Christophe Leroy wrote:
Since commit 4bf4f42a2feb ("powerpc/kbuild: Set default generic
machine type for 32-bit compile"), when building a 32 bits kernel
with a bi-arch version of GCC, or when building a book3s/32 kernel,
the option -mcpu=powerpc is passed to GCC at all time, relying on it
being eventually overriden by a subsequent -mcpu=xxxx.
But when building the same kernel with a 32 bits only version of GCC,
that is not done, relying on gcc being built with the expected default
CPU.
This logic has two problems. First, it is a bit fragile to rely on
whether the GCC version is bi-arch or not, because today we can have
bi-arch versions of GCC configured with a 32 bits default. Second,
there are some versions of GCC which don't support -mcpu=powerpc,
for instance for e500 SPE-only versions.
More fundamentally, the *only* thing you should check biarch for is
for determining if you can use both -m32 and -m64 with the same
compiler. Everything behaves identically in a biarch and a non-biarch
compiler, other than the latter screams bloody murder if you try to
change the architecture from 32 to 64 bit or vice versa.
So, stop relying on this approximative logic and allow the user to
decide whether he/she wants to use the toolchain's default CPU or if
he/she wants to set one, and allow only possible CPUs based on the
selected target.
Reported-by: Pali Rohár <pali@kernel.org>
Tested-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Cc: Segher Boessenkool <redacted>
Signed-off-by: Christophe Leroy <redacted>
Reviewed-by: Segher Boessenkool <redacted>
Looks good to me. This untangles/demystifies quite some code :-)
Segher
On Mon, Jul 11, 2022 at 05:05:04PM +0200, Arnd Bergmann wrote:
Is there any value in building for -mcpu=440 or -mcpu=464 when targeting a 476?
The original 440 had a very short pipeline. Later IBM 4xx have a longer
pipeline. Getting this right (with -mtune=, or just with -mcpu=) is
important for performance. So, no?
Maybe add another !PPC_47x dependency for the first two. Ideally we would also
enforce that 440/464 based boards cannot be selected together with 476, though
I guess that is a separate issue.
Is there a practical difference between 440 and 464 when building kernels?
gcc seems to treat them the same way, so maybe one option for both is enough
here.
-mcpu= is used as the default for -mtune=, so that is always a
consideration. PPC464 is treated the same as PPC440 in binutils as
well, so I don't think there is any issue there.
Segher
Le 11/07/2022 à 18:39, Segher Boessenkool a écrit :
Hi!
On Mon, Jul 11, 2022 at 04:19:29PM +0200, Christophe Leroy wrote:
quoted
Commit 0e00a8c9fd92 ("powerpc: Allow CPU selection also on PPC32")
enlarged the CPU selection logic to PPC32 by removing depend to
PPC64, and failed to restrict that depend to E5500_CPU and E6500_CPU.
Fortunately that got unnoticed because -mcpu=8540 will override the
-mcpu=e500mc64 or -mpcu=e6500 as they are ealier, but that's
fragile and may no be right in the future.
A later -mcpu= always overrides an earlier one. This is the same as
with all other GCC option flags, and will not change in the future.
By "future" I meant after patch 2.
At the time being, if you select PPC32 and MPC_85xx and E6500_CPU, you
get -mcpu=e6500 -mcpu=8540.
After patch 2, if you select PPC32 and MPC_85xx and E6500_CPU, you get
-mcpu=e6500
Christophe
From: Michael Ellerman <hidden> Date: 2022-07-29 13:11:52
On Mon, 11 Jul 2022 16:19:29 +0200, Christophe Leroy wrote:
Commit 0e00a8c9fd92 ("powerpc: Allow CPU selection also on PPC32")
enlarged the CPU selection logic to PPC32 by removing depend to
PPC64, and failed to restrict that depend to E5500_CPU and E6500_CPU.
Fortunately that got unnoticed because -mcpu=8540 will override the
-mcpu=e500mc64 or -mpcu=e6500 as they are ealier, but that's
fragile and may no be right in the future.
[...]
On Monday 11 July 2022 16:19:30 Christophe Leroy wrote:
Since commit 4bf4f42a2feb ("powerpc/kbuild: Set default generic
machine type for 32-bit compile"), when building a 32 bits kernel
with a bi-arch version of GCC, or when building a book3s/32 kernel,
the option -mcpu=powerpc is passed to GCC at all time, relying on it
being eventually overriden by a subsequent -mcpu=xxxx.
But when building the same kernel with a 32 bits only version of GCC,
that is not done, relying on gcc being built with the expected default
CPU.
This logic has two problems. First, it is a bit fragile to rely on
whether the GCC version is bi-arch or not, because today we can have
bi-arch versions of GCC configured with a 32 bits default. Second,
there are some versions of GCC which don't support -mcpu=powerpc,
for instance for e500 SPE-only versions.
So, stop relying on this approximative logic and allow the user to
decide whether he/she wants to use the toolchain's default CPU or if
he/she wants to set one, and allow only possible CPUs based on the
selected target.
Hello! Exactly same issue is still in file arch/powerpc/boot/Makefile:
ifdef CONFIG_PPC64_BOOT_WRAPPER
ifdef CONFIG_CPU_LITTLE_ENDIAN
BOOTCFLAGS += -m64 -mcpu=powerpc64le
else
BOOTCFLAGS += -m64 -mcpu=powerpc64
endif
else
BOOTCFLAGS += -m32 -mcpu=powerpc
endif
It cause compile error:
make ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnuspe- mpc85xx_smp_defconfig uImage
...
BOOTAS arch/powerpc/boot/crt0.o
powerpc-linux-gnuspe-gcc: error: unrecognized argument in option ‘-mcpu=powerpc’
powerpc-linux-gnuspe-gcc: note: valid arguments to ‘-mcpu=’ are: 8540 8548 native
make[1]: *** [arch/powerpc/boot/Makefile:231: arch/powerpc/boot/crt0.o] Error 1
On Thursday 18 August 2022 19:46:34 Pali Rohár wrote:
On Monday 11 July 2022 16:19:30 Christophe Leroy wrote:
quoted
Since commit 4bf4f42a2feb ("powerpc/kbuild: Set default generic
machine type for 32-bit compile"), when building a 32 bits kernel
with a bi-arch version of GCC, or when building a book3s/32 kernel,
the option -mcpu=powerpc is passed to GCC at all time, relying on it
being eventually overriden by a subsequent -mcpu=xxxx.
But when building the same kernel with a 32 bits only version of GCC,
that is not done, relying on gcc being built with the expected default
CPU.
This logic has two problems. First, it is a bit fragile to rely on
whether the GCC version is bi-arch or not, because today we can have
bi-arch versions of GCC configured with a 32 bits default. Second,
there are some versions of GCC which don't support -mcpu=powerpc,
for instance for e500 SPE-only versions.
So, stop relying on this approximative logic and allow the user to
decide whether he/she wants to use the toolchain's default CPU or if
he/she wants to set one, and allow only possible CPUs based on the
selected target.
Hello! Exactly same issue is still in file arch/powerpc/boot/Makefile:
ifdef CONFIG_PPC64_BOOT_WRAPPER
ifdef CONFIG_CPU_LITTLE_ENDIAN
BOOTCFLAGS += -m64 -mcpu=powerpc64le
else
BOOTCFLAGS += -m64 -mcpu=powerpc64
endif
else
BOOTCFLAGS += -m32 -mcpu=powerpc
endif
It cause compile error:
make ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnuspe- mpc85xx_smp_defconfig uImage
...
BOOTAS arch/powerpc/boot/crt0.o
powerpc-linux-gnuspe-gcc: error: unrecognized argument in option ‘-mcpu=powerpc’
powerpc-linux-gnuspe-gcc: note: valid arguments to ‘-mcpu=’ are: 8540 8548 native
make[1]: *** [arch/powerpc/boot/Makefile:231: arch/powerpc/boot/crt0.o] Error 1
@@ -168,13 +168,7 @@ endifCFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))AFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))-# Altivec option not allowed with e500mc64 in GCC.-ifdef CONFIG_ALTIVEC-E5500_CPU:=-mcpu=powerpc64-else-E5500_CPU:=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)-endif-CFLAGS-$(CONFIG_E5500_CPU)+=$(E5500_CPU)+CFLAGS-$(CONFIG_E5500_CPU)+=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)CFLAGS-$(CONFIG_E6500_CPU)+=$(callcc-option,-mcpu=e6500,$(E5500_CPU))
Hello! I think that there is an issue. After removal of E5500_CPU
variable few line above, it cannot be used in CFLAGS-$(CONFIG_E6500_CPU)
assignment, because it is empty.
@@ -168,13 +168,7 @@ endifCFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))AFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))-# Altivec option not allowed with e500mc64 in GCC.-ifdef CONFIG_ALTIVEC-E5500_CPU:=-mcpu=powerpc64-else-E5500_CPU:=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)-endif-CFLAGS-$(CONFIG_E5500_CPU)+=$(E5500_CPU)+CFLAGS-$(CONFIG_E5500_CPU)+=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)CFLAGS-$(CONFIG_E6500_CPU)+=$(callcc-option,-mcpu=e6500,$(E5500_CPU))
Hello! I think that there is an issue. After removal of E5500_CPU
variable few line above, it cannot be used in CFLAGS-$(CONFIG_E6500_CPU)
assignment, because it is empty.
@@ -168,13 +168,7 @@ endifCFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))AFLAGS-$(CONFIG_TARGET_CPU_BOOL)+=$(callcc-option,-mcpu=$(CONFIG_TARGET_CPU))-# Altivec option not allowed with e500mc64 in GCC.-ifdef CONFIG_ALTIVEC-E5500_CPU:=-mcpu=powerpc64-else-E5500_CPU:=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)-endif-CFLAGS-$(CONFIG_E5500_CPU)+=$(E5500_CPU)+CFLAGS-$(CONFIG_E5500_CPU)+=$(callcc-option,-mcpu=e500mc64,-mcpu=powerpc64)CFLAGS-$(CONFIG_E6500_CPU)+=$(callcc-option,-mcpu=e6500,$(E5500_CPU))
Hello! I think that there is an issue. After removal of E5500_CPU
variable few line above, it cannot be used in CFLAGS-$(CONFIG_E6500_CPU)
assignment, because it is empty.