Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp331690rwb; Wed, 21 Sep 2022 23:27:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59HlVi55LHCCs33ncJab0V0mm8EftC0pXqRdjrVSyuDhA/dud6vO0DpwuKxk2vwyCBUg7R X-Received: by 2002:a05:6402:249f:b0:453:eb1b:1f8b with SMTP id q31-20020a056402249f00b00453eb1b1f8bmr1651300eda.235.1663828077658; Wed, 21 Sep 2022 23:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663828077; cv=none; d=google.com; s=arc-20160816; b=AyHg3Y772tYOam4aYMbClS/DVRHbexz4qf4CfbSitBVWRsiiRTvkSqGh9x5bZT6cpS VmQnM/S8h9o0GqWyO1IL9oC4esFiyU/LuUlShJMuXKuLQTeP+kYLYI8nysLeyWkOLJap b0T+8F1eWfm668KAPo94lMyx1AstbPLpIZ4h1QFTA9QGZ5Zke/yp971/Sqve84KMyFYx N1M9pzxvSGIC996PLyGuJyXf9+f+t30xmcwneCb0FDlSz6kTagVTtVsygpj9Oqw1V8cM 5ft5TCN6qYSRYniNVxPc1INYQYO/pnelhbSUyaoHBR/kZgq0v/QlwYNSWTmFWKiWVxLU XEQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=4YJKnNXQtpUjI3Su6aVM4KgAluGM+04lJqhM6atDCbU=; b=bhzH1f6LigDdNHplLmtjL399X6SmSSUQ9ShwNeVd3Vk4YPQsaP6FYD5cqQie7PWP6z pgwrSIIZnxdD2jGOAiYPz9RzM626j9axLx+TvWuEb6BacJX/QAX6PwXV9U22S3fUl3Ir lZjlNuYz0n65c0fUaN3cE8chI53NVOqqbUiJ9FBlKBOzos34TH+OUEir1J8Sd47y/GVh CMaFNOmHvedxEu5HLI6qNLf1cU5ndGEFSc+4GFh8geSyBw18nZ4F/9r1w8fHSze595pe jZnBuVYeJ9zYE6a3E5RQryp1p7zRwhpCwoXvQo8pzrk+JdhwHHqYITZdgQZMHu9sAdtS zM7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=hXzwm9+p; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=d8yVJY90; 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=sholland.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp15-20020a170906c14f00b0073beb58e98dsi2086201ejc.276.2022.09.21.23.27.30; Wed, 21 Sep 2022 23:27:57 -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=@sholland.org header.s=fm3 header.b=hXzwm9+p; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=d8yVJY90; 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=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbiIVGKE (ORCPT + 99 others); Thu, 22 Sep 2022 02:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbiIVGKB (ORCPT ); Thu, 22 Sep 2022 02:10:01 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C714577EB2 for ; Wed, 21 Sep 2022 23:10:00 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id E12DE5C013E; Thu, 22 Sep 2022 02:09:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 22 Sep 2022 02:09:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm3; t=1663826999; x=1663913399; bh=4YJKnNXQtpUjI3Su6aVM4KgAl uGM+04lJqhM6atDCbU=; b=hXzwm9+pAbKhMJfsKdF8S1znhZzDuNklA8oMjLvaS TiMsb2MoSaH/aYZljM1BJG5h7WGGeZnj1rMPbAegz0RePzow37QH9UbojnacukP7 gI6Su762xLbs8YsAwEiL6jNfFgX9yDnNjWj+VT1VGnEzMdYvH/19mVcK3rElZXLf o+hlXUomOoNMh14EcC4fFrZ6qwKh2y7ejBLMHxecUmqdPgXUudptUBYTTdcvrW7h 7bezy3MQyc+Y7eWFteyAluhgl3ukRDCDcRNkCH4/MowR+dx2XqZEksaKdIO0Higx 9itj3fUmhsx+RTgD4rnU5XoUAgHWcZkHEXSMPElUIFBgA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1663826999; x=1663913399; bh=4YJKnNXQtpUjI3Su6aVM4KgAluGM+04lJqh M6atDCbU=; b=d8yVJY90xOtlxh5jKZn9VPtW8gAl3TH6wciASRedB8NvOy9SQG1 GQVcuQGhUsPKcL2QJjE2nRWv72hCtTWDv70bYzfyuPoEN5obKmp2S3b6muNEUMXY qT0kJsCdNvWm9ABs3dS5PGtC2lraHOQIX590JCG9p+7j3DLoeSmFhYmeziFxe2dQ 3M/kv8/yVD9mrS3t5PUCtt8qJUXJCnOZjilbLgclRRgZhYV16TLsFUstP0bdQQ51 ZZzAmLr4+xmLa1/twHg+gvp5zR+JduFc0MfwHhayzqRNFIXSh0NsbjQcrl7TSe7f go5+uCn661XuZBpZ0Iw8wb50Kb39vral6jw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeefvddguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeekveelhfejueelleetvdejvdeffeetgeelheeujeffhefgffefkeeh hffhkeekgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Sep 2022 02:09:59 -0400 (EDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: Samuel Holland , Albert Ou , Anup Patel , Atish Patra , Dao Lu , Guo Ren , Heiko Stuebner , Jisheng Zhang , Paul Walmsley , linux-kernel@vger.kernel.org Subject: [PATCH] riscv: Fix build with CONFIG_CC_OPTIMIZE_FOR_SIZE=y Date: Thu, 22 Sep 2022 01:09:58 -0500 Message-Id: <20220922060958.44203-1-samuel@sholland.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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 commit 8eb060e10185 ("arch/riscv: add Zihintpause support") broke building with CONFIG_CC_OPTIMIZE_FOR_SIZE enabled (gcc 11.1.0): CC arch/riscv/kernel/vdso/vgettimeofday.o In file included from : ./arch/riscv/include/asm/jump_label.h: In function 'cpu_relax': ././include/linux/compiler_types.h:285:33: warning: 'asm' operand 0 probably does not match constraints 285 | #define asm_volatile_goto(x...) asm goto(x) | ^~~ ./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto' 41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~ ././include/linux/compiler_types.h:285:33: error: impossible constraint in 'asm' 285 | #define asm_volatile_goto(x...) asm goto(x) | ^~~ ./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto' 41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~ make[1]: *** [scripts/Makefile.build:249: arch/riscv/kernel/vdso/vgettimeofday.o] Error 1 make: *** [arch/riscv/Makefile:128: vdso_prepare] Error 2 Having a static branch in cpu_relax() is problematic because that function is widely inlined, including in some quite complex functions like in the VDSO. A quick measurement shows this static branch is responsible by itself for around 40% of the jump table. Drop the static branch, which ends up being the same number of instructions anyway. If Zihintpause is supported, we trade the nop from the static branch for a div. If Zihintpause is unsupported, we trade the jump from the static branch for (what gets interpreted as) a nop. Fixes: 8eb060e10185 ("arch/riscv: add Zihintpause support") Signed-off-by: Samuel Holland --- arch/riscv/include/asm/hwcap.h | 3 --- arch/riscv/include/asm/vdso/processor.h | 25 ++++++++++--------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 6f59ec64175e..b21d46e68386 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -68,7 +68,6 @@ enum riscv_isa_ext_id { */ enum riscv_isa_ext_key { RISCV_ISA_EXT_KEY_FPU, /* For 'F' and 'D' */ - RISCV_ISA_EXT_KEY_ZIHINTPAUSE, RISCV_ISA_EXT_KEY_MAX, }; @@ -88,8 +87,6 @@ static __always_inline int riscv_isa_ext2key(int num) return RISCV_ISA_EXT_KEY_FPU; case RISCV_ISA_EXT_d: return RISCV_ISA_EXT_KEY_FPU; - case RISCV_ISA_EXT_ZIHINTPAUSE: - return RISCV_ISA_EXT_KEY_ZIHINTPAUSE; default: return -EINVAL; } diff --git a/arch/riscv/include/asm/vdso/processor.h b/arch/riscv/include/asm/vdso/processor.h index 1e4f8b4aef79..789bdb8211a2 100644 --- a/arch/riscv/include/asm/vdso/processor.h +++ b/arch/riscv/include/asm/vdso/processor.h @@ -4,30 +4,25 @@ #ifndef __ASSEMBLY__ -#include #include -#include static inline void cpu_relax(void) { - if (!static_branch_likely(&riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_ZIHINTPAUSE])) { #ifdef __riscv_muldiv - int dummy; - /* In lieu of a halt instruction, induce a long-latency stall. */ - __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy)); + int dummy; + /* In lieu of a halt instruction, induce a long-latency stall. */ + __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy)); #endif - } else { - /* - * Reduce instruction retirement. - * This assumes the PC changes. - */ + /* + * Reduce instruction retirement. + * This assumes the PC changes. + */ #ifdef __riscv_zihintpause - __asm__ __volatile__ ("pause"); + __asm__ __volatile__ ("pause"); #else - /* Encoding of the pause instruction */ - __asm__ __volatile__ (".4byte 0x100000F"); + /* Encoding of the pause instruction */ + __asm__ __volatile__ (".4byte 0x100000F"); #endif - } barrier(); } -- 2.35.1