Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2641090imw; Sun, 10 Jul 2022 11:24:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLte5ycF7jFYZdcuIqcKEGfUqX4+AQ6aKcun4quvHbvdlQHLsbyCJDBAbZGpI4R2Kt/l1H X-Received: by 2002:a17:902:6503:b0:16a:4db1:8d5a with SMTP id b3-20020a170902650300b0016a4db18d5amr15024831plk.133.1657477439884; Sun, 10 Jul 2022 11:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657477439; cv=none; d=google.com; s=arc-20160816; b=iQMxbq4S/WWCmN+OJKBm9xxflvHwJeDroacuz+nLtUwdBmu8aZUDPVRXVtsMrWhoZl AHxjXMt1ktIRCyUQOg1f5LdLsFAkKiyR8Zd856ctMRYBmyw1BgQfRntBFagSQJJ4KXn7 l4FmH68kIEYpkhg90T03iEm110fHQMYJrfhE5uADo/anbVpEff5x4ZXqWJVv/zaYGL4M D86LjbTktXDSc++3TfQyWY2F1Z4gHfUIqxl3bRGMOi3vCvRpZcnH179oGJivm6WBnOd8 fEATxanwUKGTD3OgN1oVGjInhz4/5f4ZCJMHo/+Qi1juU28KpUaWjee/11B/XFvwbhdA Gi5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=JKQ+IGYVVp93K06ZOvhG+ELj8JO8kpSYqTnGJSJsvYI=; b=dQe9yBs/DZhHnAg3NzxKIPIZoJSjIIQBFnXcFgSyTpyMv6lGIGftSvrjPq7dOti8zh MOso32qLddbL6uSm14QteQsLyL71Zl1wh2finaJrGpKhwDIbpTNAjsIRdl4oG7+9RMjj vLGyBYsjMkcuod6fA7zeU8DObF0aN6xISHG77HMRXx3Ipz5EdwyKlHZQpp1G2Ll8wP95 dmSGtdZfiafesjwMX4iCUQbPe/TxkDiKX7f1rAtwghjImy0k5bH39f/ocWk0Qx1HGipH /Csuh/A5lVG2KI7szt9bE+227lV5LvBW966/LrirXReoh5zdboL7EAcDqRXyZ7aB/mUN ui9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lmszXVeT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020a63720f000000b00412a9f59dbdsi7047684pgc.541.2022.07.10.11.23.47; Sun, 10 Jul 2022 11:23:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lmszXVeT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbiGJSLj (ORCPT + 99 others); Sun, 10 Jul 2022 14:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiGJSLi (ORCPT ); Sun, 10 Jul 2022 14:11:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DC11A188 for ; Sun, 10 Jul 2022 11:11:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D659EB80BED for ; Sun, 10 Jul 2022 18:11:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23376C3411E; Sun, 10 Jul 2022 18:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657476694; bh=2rUroKv3Ty3cfwJx41D/ngUb3zqOyDNmBVI9meqIhfg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lmszXVeTvpw0cB3sWABvUNFfqRUEjsAlTvjtVdojovZ7tppiDKouiLttjFH9SZCgo rKzPeMYfQ+Zkwk3/02ykZEX+KSiUW9/2cxFyhHWnVlBOOGBKCLLio71lQlxUnytohy ykCxA94UZ5KPzwz44wWdDCHe/i5/eZ8XL8VPVrrwAWYeBINVJNmRirY0TkO43HqpU6 B0S+Z+wdZQacnKaWrmK6AhPA74CkHDnEYJpG0PIyB7CVC6G4ZEV9TEdss6FGI6eCDF 7ZQBiY+b+o0x9LfP3yNLWbUzvnYxVG7EuOF3U57w+rmRcYRT+pw3uZTAi/WVKIpKQX npwJSj1ktrt6g== Received: by pali.im (Postfix) id 29DB2792; Sun, 10 Jul 2022 20:11:31 +0200 (CEST) Date: Sun, 10 Jul 2022 20:11:31 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Christophe Leroy Cc: Michael Ellerman , Nicholas Piggin , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Arnd Bergmann , Segher Boessenkool Subject: Re: [PATCH] powerpc/32: Don't always pass -mcpu=powerpc to the compiler Message-ID: <20220710181131.n6zbw4wot374cn7x@pali> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sunday 10 July 2022 19:36:58 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. > > Reported-by: Pali Rohár > Cc: Arnd Bergmann > Cc: Segher Boessenkool > Signed-off-by: Christophe Leroy Tested-by: Pali Rohár Works fine with SPE-based gcc for e500v2 platform Freescale P2020. I have small suggestion for naming convention, see below. > --- > arch/powerpc/Makefile | 26 +------------------------- > arch/powerpc/platforms/Kconfig.cputype | 24 ++++++++++++++++++++---- > 2 files changed, 21 insertions(+), 29 deletions(-) > > diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile > index a0cd70712061..d54e1fe03551 100644 > --- a/arch/powerpc/Makefile > +++ b/arch/powerpc/Makefile > @@ -15,23 +15,6 @@ HAS_BIARCH := $(call cc-option-yn, -m32) > # Set default 32 bits cross compilers for vdso and boot wrapper > CROSS32_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 := $(shell uname -m) > @@ -183,6 +166,7 @@ endif > endif > > CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call cc-option,-mcpu=$(CONFIG_TARGET_CPU)) > +AFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call cc-option,-mcpu=$(CONFIG_TARGET_CPU)) > > # Altivec option not allowed with e500mc64 in GCC. > ifdef CONFIG_ALTIVEC > @@ -193,14 +177,6 @@ endif > CFLAGS-$(CONFIG_E5500_CPU) += $(E5500_CPU) > CFLAGS-$(CONFIG_E6500_CPU) += $(call cc-option,-mcpu=e6500,$(E5500_CPU)) > > -ifdef CONFIG_PPC32 > -ifdef CONFIG_PPC_E500MC > -CFLAGS-y += $(call cc-option,-mcpu=e500mc,-mcpu=powerpc) > -else > -CFLAGS-$(CONFIG_E500) += $(call cc-option,-mcpu=8540 -msoft-float,-mcpu=powerpc) > -endif > -endif > - > asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1) > > KBUILD_CPPFLAGS += -I $(srctree)/arch/$(ARCH) $(asinstr) > diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype > index 383ed4fe6013..197653442d9f 100644 > --- a/arch/powerpc/platforms/Kconfig.cputype > +++ b/arch/powerpc/platforms/Kconfig.cputype > @@ -117,7 +117,8 @@ endchoice > > choice > prompt "CPU selection" > - default GENERIC_CPU > + default GENERIC_CPU if PPC64 > + default POWERPC_CPU if PPC32 > help > This will create a kernel which is optimised for a particular CPU. > The resulting kernel may not run on other CPUs, so use this with care. > @@ -135,9 +136,13 @@ config GENERIC_CPU > select ARCH_HAS_FAST_MULTIPLIER > select PPC_64S_HASH_MMU > > -config GENERIC_CPU > +config POWERPC_CPU > bool "Generic 32 bits powerpc" > - depends on PPC32 && !PPC_8xx > + depends on PPC32 && !PPC_8xx && !E500 > + > +config TOOLCHAIN_DEFAULT_CPU > + bool "Rely on the toolchain's implicit default CPU" > + depends on PPC32 > > config CELL_CPU > bool "Cell Broadband Engine" > @@ -196,11 +201,19 @@ config G4_CPU > depends on PPC_BOOK3S_32 > select ALTIVEC > > +config 8540_CPU > + bool "8540" > + depends on PPC_85xx && !PPC_E500MC MPC8540 is name of the first (Motorola) SoC which had e500(v1) core. e500 cores are used also in new Freescale P1/P2 series and also in BSC913x and C29x products. So I would suggest to call this 'config E500_CPU' with description 'bool "e500 (8540)"' because all other *_CPU options are named by the CPU core, not by the SoC product which core contains. There is e.g. E5500_CPU, E300C2_CPU or E500MC_CPU. It is confusing that gcc named this option "-mcpu=8540" and not "-mcpu=e500". For example GNU AS call this option "-me500" and I read somewhere that clang/llvm wanted to add "-mcpu=e500" as an alias. For example with this change: diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index 6c2b2d2c8bfc..8c8dd3c066f9 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -202,8 +202,8 @@ config G4_CPU depends on PPC_BOOK3S_32 select ALTIVEC -config 8540_CPU - bool "8540" +config E500_CPU + bool "e500 (8540)" depends on PPC_85xx && !PPC_E500MC config E500MC_CPU @@ -229,7 +229,7 @@ config TARGET_CPU default "e300c2" if E300C2_CPU default "e300c3" if E300C3_CPU default "G4" if G4_CPU - default "8540" if 8540_CPU + default "8540" if E500_CPU default "e500mc" if E500MC_CPU default "powerpc" if POWERPC_CPU > + > +config E500MC_CPU > + bool "e500mc" > + depends on PPC_85xx && PPC_E500MC > + > endchoice > > config TARGET_CPU_BOOL > bool > - default !GENERIC_CPU > + default !GENERIC_CPU && !TOOLCHAIN_DEFAULT_CPU > > config TARGET_CPU > string > @@ -215,6 +228,9 @@ config TARGET_CPU > default "e300c2" if E300C2_CPU > default "e300c3" if E300C3_CPU > default "G4" if G4_CPU > + default "8540" if 8540_CPU > + default "e500mc" if E500MC_CPU > + default "powerpc" if POWERPC_CPU > > config PPC_BOOK3S > def_bool y > -- > 2.36.1 >