Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp573236rwb; Thu, 6 Oct 2022 01:06:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OzB5BmVABbwu7WZgt75fCpJ+JOoejGIk3W5NLiuGPWtNkn6wDBq3j0UnPRs2Wq4XqRxlr X-Received: by 2002:a17:90a:3989:b0:205:e4c2:e09b with SMTP id z9-20020a17090a398900b00205e4c2e09bmr3960483pjb.190.1665043564215; Thu, 06 Oct 2022 01:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665043564; cv=none; d=google.com; s=arc-20160816; b=sF8QS+ZbCMT/lIyW9TrVFVPIR7nrJIBa2vjMOTYNO2BNxmG7fHJQl1iKfv9hfO1X6W T5Cg4XgSIUN393925LxN2lC1D81wdze6PPj268IEWaS3eeLeXM/IbqNzjNeGidDD7Tpk pj9zJ9TESXlskoNLQcp+mrrB1PZ4cDdf7djq1EjwKQPAQeoiPSY4zW3tK2muH+YVTXJo NneSs0TTyvYlYPqCwotLlgUQurp2MF4vuCk1/idGpNbZ2dD+aGKpsjhjbFgJjJiKMHF1 MkdymXshTW5EB115Isf5osThBsIpdQNnu3cvX4SgWhJYrNIIzX6iBI7/LHpP8DWkRGat 4hHA== 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:dkim-signature; bh=ueHVxaIyRbZ1gS7nusWjaz4B0O4PHKoECZ/FEWpHOLw=; b=A+yViySPQhz4gAokYgvTHUDazurIOiFK6CiDowyJuPsl33gLUpE5rXiCHnV+DSbgPq 2Fz9cqPh5NHOIDuHIAiSIk6eubDdBZbT4SVvhMEPZiBgYuPO2soUBjdtiBUnR3Aov+hP uK9PEzpLS6tWEycYLgIiKo1UfiL7nib1fyYnM4HRv0S1pcaRQhF89g5XRlcFfVZUeoem 3tWTJxZgUfYAzw221JDLY3NT4H+L1fbi7s08MdbWn1G0TK6VjY0aMqUPyS5nG2iheG8i eW6kiLCvopGSONdmBetPqJfAKhVCYYNFMxks6O2uMhi6TnrPt/BvMUNC9KPxGQELzL9z wxXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Tff/cDKp"; 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 e184-20020a6369c1000000b004519a9e15d5si9909539pgc.517.2022.10.06.01.05.38; Thu, 06 Oct 2022 01:06:04 -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="Tff/cDKp"; 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 S230228AbiJFHRy (ORCPT + 99 others); Thu, 6 Oct 2022 03:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbiJFHRx (ORCPT ); Thu, 6 Oct 2022 03:17:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 200E54AD58 for ; Thu, 6 Oct 2022 00:17:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2B3DD61840 for ; Thu, 6 Oct 2022 07:17:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 683D1C433C1; Thu, 6 Oct 2022 07:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665040670; bh=WNXmYjwN1rHUu/M3HLQ1TTrTsskFX86T4eU0bZFneQM=; h=From:To:Cc:Subject:Date:From; b=Tff/cDKpkitEOwG+wbPBfQtl6wMHqCnclaEC6GGgjKtuQd/rA1V8kliapr7w1rHlB WeUkCO+/gfZx92hgNxuXUDI87ge2OBowNoaflvRYfFPWHsXmRgifK1vX74PmBCuOoZ 3VqnVy/vciUHKFLC4Jnqhj9SmZCjBFV6+WJH5MOzcMmuYG/u3VFSOPPWMICgsNV7ey SDn+hMv7eAi+VC865LGADpTBnbo4Ua5sPCSwil8IAor2e0YXull3q/t2OZgCPHBW2m Ylov5M7AlfDK482i6+ol6E7NSNXrzzuaSxyJRY2VcIwu5ztJaW9cJQ8EWCryiGl2Yq PGgyCq7wBcKGw== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/8] riscv: improve boot time isa extensions handling Date: Thu, 6 Oct 2022 15:08:10 +0800 Message-Id: <20221006070818.3616-1-jszhang@kernel.org> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 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 Generally, riscv ISA extensions are fixed for any specific hardware platform, that's to say, the hart features won't change any more after booting, this chacteristic make it straightforward to use static branch to check one specific ISA extension is supported or not to optimize performance. However, some ISA extensions such as SVPBMT and ZICBOM are handled via. the alternative sequences. Basically, for ease of maintenance, we prefer to use static branches in C code, but recently, Samuel found that the static branch usage in cpu_relax() breaks building with CONFIG_CC_OPTIMIZE_FOR_SIZE[1]. As Samuel pointed out, "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." Samuel's findings pointed out one of a few downsides of static branches usage in C code to handle ISA extensions detected at boot time: static branch's metadata in the __jump_table section, which is not discarded after ISA extensions are finalized, wastes some space. I want to try to solve the issue for all possible dynamic handling of ISA extensions at boot time. Inspired by Mark[2], this patch introduces riscv_has_extension_*() helpers, which work like static branches but are patched using alternatives, thus the metadata can be freed after patching. [1]https://lore.kernel.org/linux-riscv/20220922060958.44203-1-samuel@sholland.org/ [2]https://lore.kernel.org/linux-arm-kernel/20220912162210.3626215-8-mark.rutland@arm.com/ Jisheng Zhang (8): riscv: move riscv_noncoherent_supported() out of ZICBOM probe riscv: cpufeature: detect RISCV_ALTERNATIVES_EARLY_BOOT earlier riscv: hwcap: make ISA extension ids can be used in asm riscv: cpufeature: extend riscv_cpufeature_patch_func to all ISA extensions riscv: introduce riscv_has_extension_[un]likely() riscv: fpu: switch has_fpu() to riscv_has_extension_likely() riscv: cpu_relax: switch to riscv_has_extension_likely() riscv: remove riscv_isa_ext_keys[] array and related usage arch/riscv/include/asm/errata_list.h | 9 +-- arch/riscv/include/asm/hwcap.h | 94 ++++++++++++++----------- arch/riscv/include/asm/switch_to.h | 3 +- arch/riscv/include/asm/vdso/processor.h | 2 +- arch/riscv/kernel/cpufeature.c | 78 +++----------------- arch/riscv/kernel/setup.c | 4 ++ 6 files changed, 71 insertions(+), 119 deletions(-) -- 2.37.2