From patchwork Wed May 8 01:36:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658006 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DEB7AC25B4F for ; Wed, 8 May 2024 01:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MC/KzMTqPPaOIwRkXemyzdqefLvtJGrr6zMXqZapRB8=; b=RZwpTRLpxNseEa o2kov3t77mJ+ARw1R+VbSFeHpjCzceqFCyz1e3IclPqDosUiz37s+hRf9oT48qzxcHg4zmFumbXxC fMIT8RgVAJUchB68vOuy4MXQVkH5gZbNu9Aolmu6xXG5lYvzw2I88fO6d1cfdsyxNtOBQL3krM2n9 0CxCTPAak5sg79pRr2pD8COfG4/dciV8YSfTUjn1yfmImiECNDEOzo0fhRrcZXBWBhm6KPF2uzP+z nzob5GybzYy5/5YELUm4DrnvWeCzt1/cIFbLeTBr2MrKWegs3XxaWH2b+KqGezYE8J8WB319K3QvZ stSIEH2WchAUSxtyW+6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEk-0000000DezN-1S3V; Wed, 08 May 2024 01:36:50 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEg-0000000DexL-3S83 for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:48 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2b346712919so2883965a91.2 for ; Tue, 07 May 2024 18:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132202; x=1715737002; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W9yTxfWOtF5boAkE9/9YrcfOh3vEqeNnQBOu8ePUP3A=; b=BSmAPgLz8JztHzspuxtwRWhKJRsXF0UL3jmRPbu/tR+Kz8zjcWt7NUQzc2vb/7cUti XHtgZ23QHfvT7DAp5K3gKGChQhsXWS/xmqKWGAkE9MnDhySpkTmXmZ0Fpg7/iUg2ZR4R Ru4FpBrsNdCtABpjyNK99wt3xPsOFcOXjQxka0bX3E/C5BddBaGsqQHWxGQlUPtAzfry ndISu3ouPDhk7aFbEKJ3Xmyjod+vpuCx9d3im+skHu3/GTFjk1Ds+DUlCPjDBfJQQlci hlSVS2+WXtrcDIDZumfLa5mMssuPBPKY0Aqhj55R3sj21CKlclCNocbNC64OonTeSjiW j8PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132202; x=1715737002; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W9yTxfWOtF5boAkE9/9YrcfOh3vEqeNnQBOu8ePUP3A=; b=MvUQ8PeW3GryeDQUh+n8EuLhFIWegO7LVhlC7XC1druFiUKH+Tdz5fxFavZZCj+OYv dVSJlZ/bfEhsgTesQHXT/cP3QPDyVOYb9/Uw/nCzBIiy8YxYlLmmz4cWBgdfvxLm+xI3 n3Xqq/m5ue2xXio3g6CKtD6alhdCCDutmFmfdavguKxi1k7vjSELfbklUcPtMl5B7vtl 2UP/gzyCZsqih7d004fqH1vicn4bcysUprdlQlfKhAF6Ky3rffDSBLPhPldqJq1H8nPA Pt8XTgs5UMzQev8iMtTX3CG+lysPFsGC7010slfJ7tqDeD8RDQ6ZPZORnr1yhfZU8bEZ yPiA== X-Gm-Message-State: AOJu0Yw3GnkPxOdif2PDvxuqORXym/8DyQgt3JfabuUd/ZEMPpHOFzwN LQRv+/UaomjxrCIIBio2l9/hxx4XZn5i+uw/p/Mh4naGQTPjEf8bKmNE9AKYmwA= X-Google-Smtp-Source: AGHT+IG1y+2SksOJ5/iFT/Z5fKQTo1Zf9NVG2qfabMXNk0GuZoWNzylHq8ETlUv78rTnGDNbEMlqHg== X-Received: by 2002:a17:90a:fd0c:b0:2ac:23ec:6a57 with SMTP id 98e67ed59e1d1-2b6169db571mr1212359a91.39.1715132201989; Tue, 07 May 2024 18:36:41 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:41 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:27 -0700 Subject: [PATCH v2 1/8] riscv: Add PLATFORM_MAY_SUPPORT_RISCV_ISA_C Kconfig option MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-1-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=5960; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=j9swSxT8d2fDA4kDGEnqoj8fqzKxNkC+d4MpaFY3y4k=; b=7HgrUjF7yNqvZHKoMqkfNlOf3VFDhBOLsI3MIl5rTg6+kqCvct+IvjzRfsRPpeygmRzDbM6zH UvjMdMc28OiCM/Bc16GtdVCvODCU5QyePqQ0aq1o9XFlS1lGoN15AbV X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183646_950250_87B39AA9 X-CRM114-Status: GOOD ( 24.27 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Introduce a "Kernel ISA" menu and migrate the compressed instruction support options into a new file Kconfig.isa. Add a new option "PLATFORM_MAY_SUPPORT_RISCV_ISA_C" that can be used to conditionally emit C extensions if the hardware supports it. The existing "RISCV_ISA_C" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_C or PLATFORM_SUPPORTS_RISCV_ISA_C has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 19 +++++++----------- arch/riscv/Kconfig.isa | 41 ++++++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 4 ++-- arch/riscv/kernel/probes/uprobes.c | 2 +- arch/riscv/net/bpf_jit.h | 4 +++- 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c8bdfd33abf4..c2a4f5364707 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -369,6 +369,12 @@ config ARCH_RV64I endchoice +menu "Kernel ISA" + +source "arch/riscv/Kconfig.isa" + +endmenu + # We must be able to map all physical memory into the kernel, but the compiler # is still a bit more efficient when generating code if it's setup in a manner # such that it can only map 2GiB of memory. @@ -478,17 +484,6 @@ config RISCV_ALTERNATIVE_EARLY help Allows early patching of the kernel for special errata -config RISCV_ISA_C - bool "Emit compressed instructions when building Linux" - default y - help - Adds "C" to the ISA subsets that the toolchain is allowed to emit - when building Linux, which results in compressed instructions in the - Linux binary. This option produces a kernel that will not run on - systems that do not support compressed instructions. - - If you don't know what to do here, say Y. - config RISCV_ISA_SVNAPOT bool "Svnapot extension support for supervisor mode NAPOT pages" depends on 64BIT && MMU @@ -937,6 +932,7 @@ config EFI bool "UEFI runtime support" depends on OF && !XIP_KERNEL depends on MMU + depends on PLATFORM_SUPPORTS_RISCV_ISA_C default y select ARCH_SUPPORTS_ACPI if 64BIT select EFI_GENERIC_STUB @@ -944,7 +940,6 @@ config EFI select EFI_RUNTIME_WRAPPERS select EFI_STUB select LIBFDT - select RISCV_ISA_C select UCS2_STRING help This option provides support for runtime services provided diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa new file mode 100644 index 000000000000..08b7af5aabb0 --- /dev/null +++ b/arch/riscv/Kconfig.isa @@ -0,0 +1,41 @@ +config RISCV_ISA_C + bool + +choice + prompt "Compressed instruction support" + default PLATFORM_SUPPORTS_RISCV_ISA_C + help + This selects the level of support for compressed instructions to be + built into the Linux Kernel. This does not impact whether compressed + instructions are allowed to be emitted by user-space code. + +config PROHIBIT_RISCV_ISA_C + bool "Prohibit compressed instructions" + depends on NONPORTABLE + help + Regardless of if the platform supports compressed instructions, + prohibit the kernel from emitting compressed instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_C + bool "Allow compressed instructions sequences if supported" + depends on FPU + depends on NONPORTABLE + select RISCV_ISA_C + help + Only allow compressed instructions to be emitted if "C" is present in + the device tree or ACPI table. No compressed instructions will be + emitted if the platform does not support them. + +config PLATFORM_SUPPORTS_RISCV_ISA_C + bool "Emit compressed instructions when building Linux" + depends on FPU + select RISCV_ISA_C + help + Adds "C" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in compressed instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support compressed instructions. + + If you don't know what to do here, say Y. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 5b3115a19852..e1be36004097 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -14,7 +14,7 @@ endif ifeq ($(CONFIG_DYNAMIC_FTRACE),y) LDFLAGS_vmlinux += --no-relax KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY -ifeq ($(CONFIG_RISCV_ISA_C),y) +ifeq ($(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C),y) CC_FLAGS_FTRACE := -fpatchable-function-entry=4 else CC_FLAGS_FTRACE := -fpatchable-function-entry=2 @@ -65,7 +65,7 @@ endif riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd -riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) := $(riscv-march-y)c riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probes/uprobes.c index 4b3dc8beaf77..a468689a6f6d 100644 --- a/arch/riscv/kernel/probes/uprobes.c +++ b/arch/riscv/kernel/probes/uprobes.c @@ -11,7 +11,7 @@ bool is_swbp_insn(uprobe_opcode_t *insn) { -#ifdef CONFIG_RISCV_ISA_C +#ifdef CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C return (*insn & 0xffff) == UPROBE_SWBP_INSN; #else return *insn == UPROBE_SWBP_INSN; diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h index f4b6b3b9edda..259294bdbc3a 100644 --- a/arch/riscv/net/bpf_jit.h +++ b/arch/riscv/net/bpf_jit.h @@ -15,7 +15,9 @@ static inline bool rvc_enabled(void) { - return IS_ENABLED(CONFIG_RISCV_ISA_C); + return IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) || + (IS_ENABLED(CONFIG_PLATFORM_MAY_SUPPORT_RISCV_ISA_C) && + riscv_has_extension_likely(RISCV_ISA_EXT_c)); } static inline bool rvzbb_enabled(void) From patchwork Wed May 8 01:36:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8DA55C19F4F for ; Wed, 8 May 2024 01:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/bkKBcJW6GVHgq6IS8omc1qqDWD/XsAJm7ioa/rt3bs=; b=SNhSvKBPRVaQUP lBsBF1yNVVI5KCPW9Hzo/hm191J17DFUS6tOVwJ3j8Aw+N0i5Rfh5shWvpVbHbLUQGmPA/6scgN1e 8yUCiBOIo1hOpM6Wa+WEecwDL0AusjhoAyYaUDpExBJLjsctDKitGZh/CMdEJaoi2P5UKALmA1aoJ ptP0wwPNdsG8DnfsoL8X9NkZHQWcoOSfol6wO8/64/e+BZOy83xtwkFXvu/1TCjzw7jGHv9UljcOj t4vWDHLa0+/Nr3PO3WBO8ju3bWLDJmxPk0YGIDlnVyOd0N9kiqzivq6E/CC/1oBfpCva9fAUPJUNo yGJ6Q3iAJyPsPhYDr3pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEn-0000000Df15-11Ba; Wed, 08 May 2024 01:36:53 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEh-0000000Dexh-20nc for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:49 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6f44ed6e82fso3511993b3a.3 for ; Tue, 07 May 2024 18:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132204; x=1715737004; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QsWvdiflsnWwGCusk/V+w219I8PirWa/ozpvjoDvtCY=; b=BzeB6K/f0LLcTqxLtVJ0nRopylDz2EbBXfzqYeczWrQvxRmcwMY76KlfRxCwT+tivG TyCqXq9EDRqnFZxuwfeWVwzC0gUVMbfba7xZxbFc0SS5g2WalqWaGC4qL2kLoNQ8wO05 4mQvZVzF53PFlXmG87WvbikgjP9t5XBDUud4T0mkzmHdz3aHNDd5gd6H6EJWz7M7HdDQ G/3O1Fg4migAUtGqEaPhgdt6j/4LTG8Hdou7kMKpU4EWInkxzQ2bF0bwQJHy3LbvdDzo lfI72zzW+YmuklBcddTAqP25sFx1VSX8U2Z74YABALfXyYFrh/iGzOs3SsLKgWjC7Ydy ag1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132204; x=1715737004; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QsWvdiflsnWwGCusk/V+w219I8PirWa/ozpvjoDvtCY=; b=uKGJSmMpzTvIqAI9BxEn6Rn/wnEnwWrKkf6rTXgxCTTTD29uGx1BS5zkhaCTE1ipbo XQPTvqhGHIKPlpkaFGSqgvPO7OAi6WxlYGFUUmNajOVbA+5Tm3TDHtS4xXDtHZ749IIA 6EsDNwefOJqtJL/TtS6DPDWDAZhxRvUGO39TuMjxieLV1EOk7G3zh45kT8rTc3rU4a8y 0vmveN4UKtYtsrrnNUfT/oERxsw5kjPFxHxSvl4svqRPjLGuEMcNNnUX21GZPOejkPs5 73uvpJXPV656/YpQKsSL/Ff2NUNG6V8yQcHQYOZ9Rz3Z0zeL9GS5cDkoZlpHdpjcjqGs ZG4A== X-Gm-Message-State: AOJu0Ywtx8K/fyHim8uTtrhxF8h6uvGrwoEviuSl3UoSAV62oDJ7+qvM 6Dcu6haoWq0djTUyJobQ7joFzrxXRg16VN42zzlz0wuHsgQvHrI2DFex6dKctq4= X-Google-Smtp-Source: AGHT+IHnbYWaPgyfBvsooFp5nm4cy6R66eKw9IW9Ae2xxUroArGaGCo9hfmYeJJ/Lsc9/W9mM29X7Q== X-Received: by 2002:a05:6a21:2782:b0:1ac:c455:c126 with SMTP id adf61e73a8af0-1afc8d266famr1254554637.19.1715132203783; Tue, 07 May 2024 18:36:43 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:42 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:28 -0700 Subject: [PATCH v2 2/8] riscv: Add PLATFORM_MAY_SUPPORT_RISCV_ISA_V Kconfig option MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-2-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=16103; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=W4jHdZN/kCsCwkDu00hJrCLOm+euMvrei2YBsQUCfLQ=; b=Po3uOpS8qy3hDavCm7BAc4KyH9f/ISmzzk0Eli8vAsMDCAJhx2yoQJ5x2SaBTpoHvNd2vCNya c6Uj3tJG8RvCO5SM1Et9LXsKrr4DWMGYfT32EXVMKKrZVzPdBeblh6P X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183647_588171_F4385683 X-CRM114-Status: GOOD ( 29.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Current versions of the kernel add "v" to the march and then immeidately filter it out such that "v" is not passed to CFLAGS. Instead of doing this filtering, code blocks in the kernel that want to use vector assembly have been changed to locally enable vector (using ".option arch, +v"). To support kernels that can run on hardware that may support vector, the config option PLATFORM_MAY_SUPPORT_RISCV_ISA_V is added, and the previous behavior of RISCV_ISA_V is retained with the option CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_V. When the hardware is assumed to support vector, has_vector() unconditionally returns true. "v" is not added to the toolchain march even when the hardware is assumed to support vector because kernel vector code must be guarded by kernel_vector_begin/end. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 54 ------------------------- arch/riscv/Kconfig.isa | 85 ++++++++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 6 +-- arch/riscv/crypto/Kconfig | 14 +++---- arch/riscv/include/asm/simd.h | 3 ++ arch/riscv/include/asm/vector.h | 3 +- arch/riscv/kernel/cpufeature.c | 3 +- arch/riscv/kernel/head.S | 8 +++- arch/riscv/kernel/process.c | 12 +++--- arch/riscv/kernel/ptrace.c | 6 +++ arch/riscv/lib/riscv_v_helpers.c | 1 - arch/riscv/lib/uaccess_vector.S | 2 + arch/riscv/lib/xor.S | 2 + 13 files changed, 123 insertions(+), 76 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c2a4f5364707..c2e9eded0a7d 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -520,60 +520,6 @@ config RISCV_ISA_SVPBMT If you don't know what to do here, say Y. -config TOOLCHAIN_HAS_V - bool - default y - depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64iv) - depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32iv) - depends on LLD_VERSION >= 140000 || LD_VERSION >= 23800 - depends on AS_HAS_OPTION_ARCH - -config RISCV_ISA_V - bool "Vector extension support" - depends on TOOLCHAIN_HAS_V - depends on FPU - select DYNAMIC_SIGFRAME - default y - help - Add support for the Vector extension when it is detected at boot. - When this option is disabled, neither the kernel nor userspace may - use vector procedures. - - If you don't know what to do here, say Y. - -config RISCV_ISA_V_DEFAULT_ENABLE - bool "Enable userspace Vector by default" - depends on RISCV_ISA_V - default y - help - Say Y here if you want to enable Vector in userspace by default. - Otherwise, userspace has to make explicit prctl() call to enable - Vector, or enable it via the sysctl interface. - - If you don't know what to do here, say Y. - -config RISCV_ISA_V_UCOPY_THRESHOLD - int "Threshold size for vectorized user copies" - depends on RISCV_ISA_V - default 768 - help - Prefer using vectorized copy_to_user()/copy_from_user() when the - workload size exceeds this value. - -config RISCV_ISA_V_PREEMPTIVE - bool "Run kernel-mode Vector with kernel preemption" - depends on PREEMPTION - depends on RISCV_ISA_V - default y - help - Usually, in-kernel SIMD routines are run with preemption disabled. - Functions which envoke long running SIMD thus must yield core's - vector unit to prevent blocking other tasks for too long. - - This config allows kernel to run SIMD without explicitly disable - preemption. Enabling this config will result in higher memory - consumption due to the allocation of per-task's kernel Vector context. - config TOOLCHAIN_HAS_ZBB bool default y diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index 08b7af5aabb0..0663c98b5b17 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -39,3 +39,88 @@ config PLATFORM_SUPPORTS_RISCV_ISA_C If you don't know what to do here, say Y. endchoice + +config TOOLCHAIN_HAS_V + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64iv) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32iv) + depends on LLD_VERSION >= 140000 || LD_VERSION >= 23800 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_V + bool + +choice + prompt "Vector extension support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_V + help + This selects the level of support for vector instructions to be + built into the Linux Kernel. This does not impact whether vector + instructions are allowed to be emitted by user-space code. + +config PROHIBIT_RISCV_ISA_V + bool "Prohibit vector instructions" + depends on NONPORTABLE + help + Regardless of if the platform supports vector instructions, + prohibit the kernel from emitting vector instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_V + bool "Allow vector instruction sequences if supported" + depends on TOOLCHAIN_HAS_V + depends on FPU + select DYNAMIC_SIGFRAME + select RISCV_ISA_V + help + Only allow vector instructions to be emitted if "V" is present in + the device tree or ACPI table. No vector instructions will be + emitted if the platform does not support them. + +config PLATFORM_SUPPORTS_RISCV_ISA_V + bool "Emit vector instructions when building Linux" + depends on TOOLCHAIN_HAS_V + depends on FPU + depends on NONPORTABLE + select DYNAMIC_SIGFRAME + select RISCV_ISA_V + help + Adds "V" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in vector instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support vector instructions. + +endchoice + +config RISCV_ISA_V_DEFAULT_ENABLE + bool "Enable userspace Vector by default" + depends on RISCV_ISA_V + default y + help + Say Y here if you want to enable Vector in userspace by default. + Otherwise, userspace has to make explicit prctl() call to enable + Vector, or enable it via the sysctl interface. + + If you don't know what to do here, say Y. + +config RISCV_ISA_V_UCOPY_THRESHOLD + int "Threshold size for vectorized user copies" + depends on RISCV_ISA_V + default 768 + help + Prefer using vectorized copy_to_user()/copy_from_user() when the + workload size exceeds this value. + +config RISCV_ISA_V_PREEMPTIVE + bool "Run kernel-mode Vector with kernel preemption" + depends on PREEMPTION + depends on RISCV_ISA_V + default y + help + Usually, in-kernel SIMD routines are run with preemption disabled. + Functions which envoke long running SIMD thus must yield core's + vector unit to prevent blocking other tasks for too long. + + This config allows kernel to run SIMD without explicitly disable + preemption. Enabling this config will result in higher memory + consumption due to the allocation of per-task's kernel Vector context. diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index e1be36004097..e1111e62ca20 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -66,7 +66,6 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) := $(riscv-march-y)c -riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS += -Wa,-misa-spec=2.2 @@ -78,10 +77,7 @@ endif # Check if the toolchain supports Zihintpause extension riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause -# Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by -# matching non-v and non-multi-letter extensions out with the filter ([^v_]*) -KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/') - +KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y)) KBUILD_AFLAGS += -march=$(riscv-march-y) KBUILD_CFLAGS += -mno-save-restore diff --git a/arch/riscv/crypto/Kconfig b/arch/riscv/crypto/Kconfig index ad58dad9a580..5f7ea675a8cf 100644 --- a/arch/riscv/crypto/Kconfig +++ b/arch/riscv/crypto/Kconfig @@ -4,7 +4,7 @@ menu "Accelerated Cryptographic Algorithms for CPU (riscv)" config CRYPTO_AES_RISCV64 tristate "Ciphers: AES, modes: ECB, CBC, CTS, CTR, XTS" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + depends on 64BIT && PLATFORM_SUPPORTS_RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_ALGAPI select CRYPTO_LIB_AES select CRYPTO_SKCIPHER @@ -20,7 +20,7 @@ config CRYPTO_AES_RISCV64 config CRYPTO_CHACHA_RISCV64 tristate "Ciphers: ChaCha" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + depends on 64BIT && PLATFORM_SUPPORTS_RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_SKCIPHER select CRYPTO_LIB_CHACHA_GENERIC help @@ -31,7 +31,7 @@ config CRYPTO_CHACHA_RISCV64 config CRYPTO_GHASH_RISCV64 tristate "Hash functions: GHASH" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + depends on 64BIT && PLATFORM_SUPPORTS_RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_GCM help GCM GHASH function (NIST SP 800-38D) @@ -41,7 +41,7 @@ config CRYPTO_GHASH_RISCV64 config CRYPTO_SHA256_RISCV64 tristate "Hash functions: SHA-224 and SHA-256" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + depends on 64BIT && PLATFORM_SUPPORTS_RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_SHA256 help SHA-224 and SHA-256 secure hash algorithm (FIPS 180) @@ -52,7 +52,7 @@ config CRYPTO_SHA256_RISCV64 config CRYPTO_SHA512_RISCV64 tristate "Hash functions: SHA-384 and SHA-512" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + depends on 64BIT && PLATFORM_SUPPORTS_RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_SHA512 help SHA-384 and SHA-512 secure hash algorithm (FIPS 180) @@ -63,7 +63,7 @@ config CRYPTO_SHA512_RISCV64 config CRYPTO_SM3_RISCV64 tristate "Hash functions: SM3 (ShangMi 3)" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + depends on 64BIT && PLATFORM_SUPPORTS_RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_HASH select CRYPTO_SM3 help @@ -75,7 +75,7 @@ config CRYPTO_SM3_RISCV64 config CRYPTO_SM4_RISCV64 tristate "Ciphers: SM4 (ShangMi 4)" - depends on 64BIT && RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO + depends on 64BIT && PLATFORM_SUPPORTS_RISCV_ISA_V && TOOLCHAIN_HAS_VECTOR_CRYPTO select CRYPTO_ALGAPI select CRYPTO_SM4 help diff --git a/arch/riscv/include/asm/simd.h b/arch/riscv/include/asm/simd.h index adb50f3ec205..81508325fd51 100644 --- a/arch/riscv/include/asm/simd.h +++ b/arch/riscv/include/asm/simd.h @@ -26,6 +26,9 @@ */ static __must_check inline bool may_use_simd(void) { + if (!has_vector()) + return false; + /* * RISCV_KERNEL_MODE_V is only set while preemption is disabled, * and is clear whenever preemption is enabled. diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 731dcd0ed4de..a08c4bf92ecd 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -37,7 +37,8 @@ static inline u32 riscv_v_flags(void) static __always_inline bool has_vector(void) { - return riscv_has_extension_unlikely(RISCV_ISA_EXT_v); + return IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_V) || + riscv_has_extension_likely(RISCV_ISA_EXT_v); } static inline void __riscv_v_vstate_clean(struct pt_regs *regs) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 3ed2359eae35..7cb365714855 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -683,7 +683,6 @@ void __init riscv_fill_hwcap(void) } if (elf_hwcap & COMPAT_HWCAP_ISA_V) { - riscv_v_setup_vsize(); /* * ISA string in device tree might have 'v' flag, but * CONFIG_RISCV_ISA_V is disabled in kernel. @@ -691,6 +690,8 @@ void __init riscv_fill_hwcap(void) */ if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) elf_hwcap &= ~COMPAT_HWCAP_ISA_V; + else + riscv_v_setup_vsize(); } memset(print_str, 0, sizeof(print_str)); diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 4236a69c35cb..b027be82bbb3 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -428,17 +428,20 @@ SYM_CODE_START_LOCAL(reset_regs) .Lreset_regs_done_fpu: #endif /* CONFIG_FPU */ -#ifdef CONFIG_RISCV_ISA_V +#if defined(CONFIG_PLATFORM_MAY_SUPPORT_RISCV_ISA_V) csrr t0, CSR_MISA li t1, COMPAT_HWCAP_ISA_V and t0, t0, t1 beqz t0, .Lreset_regs_done_vector - +#endif +#ifdef CONFIG_RISCV_ISA_V /* * Clear vector registers and reset vcsr * VLMAX has a defined value, VLEN is a constant, * and this form of vsetvli is defined to set vl to VLMAX. */ + .option push + .option arch, +v li t1, SR_VS csrs CSR_STATUS, t1 csrs CSR_VCSR, x0 @@ -447,6 +450,7 @@ SYM_CODE_START_LOCAL(reset_regs) vmv.v.i v8, 0 vmv.v.i v16, 0 vmv.v.i v24, 0 + .option pop /* note that the caller must clear SR_VS */ .Lreset_regs_done_vector: #endif /* CONFIG_RISCV_ISA_V */ diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index e4bc61c4e58a..3ba7bf63ccb2 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -165,11 +165,13 @@ void flush_thread(void) #endif #ifdef CONFIG_RISCV_ISA_V /* Reset vector state */ - riscv_v_vstate_ctrl_init(current); - riscv_v_vstate_off(task_pt_regs(current)); - kfree(current->thread.vstate.datap); - memset(¤t->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); - clear_tsk_thread_flag(current, TIF_RISCV_V_DEFER_RESTORE); + if (has_vector()) { + riscv_v_vstate_ctrl_init(current); + riscv_v_vstate_off(task_pt_regs(current)); + kfree(current->thread.vstate.datap); + memset(¤t->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); + clear_tsk_thread_flag(current, TIF_RISCV_V_DEFER_RESTORE); + } #endif } diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c index 92731ff8c79a..bdfaed2a4023 100644 --- a/arch/riscv/kernel/ptrace.c +++ b/arch/riscv/kernel/ptrace.c @@ -92,6 +92,9 @@ static int riscv_vr_get(struct task_struct *target, struct __riscv_v_ext_state *vstate = &target->thread.vstate; struct __riscv_v_regset_state ptrace_vstate; + if (!has_vector()) + return 0; + if (!riscv_v_vstate_query(task_pt_regs(target))) return -EINVAL; @@ -127,6 +130,9 @@ static int riscv_vr_set(struct task_struct *target, struct __riscv_v_ext_state *vstate = &target->thread.vstate; struct __riscv_v_regset_state ptrace_vstate; + if (!has_vector()) + return 0; + if (!riscv_v_vstate_query(task_pt_regs(target))) return -EINVAL; diff --git a/arch/riscv/lib/riscv_v_helpers.c b/arch/riscv/lib/riscv_v_helpers.c index be38a93cedae..661c77fdd7f7 100644 --- a/arch/riscv/lib/riscv_v_helpers.c +++ b/arch/riscv/lib/riscv_v_helpers.c @@ -21,7 +21,6 @@ asmlinkage int enter_vector_usercopy(void *dst, void *src, size_t n) { size_t remain, copied; - /* skip has_vector() check because it has been done by the asm */ if (!may_use_simd()) goto fallback; diff --git a/arch/riscv/lib/uaccess_vector.S b/arch/riscv/lib/uaccess_vector.S index 7c45f26de4f7..4de37a3a2163 100644 --- a/arch/riscv/lib/uaccess_vector.S +++ b/arch/riscv/lib/uaccess_vector.S @@ -5,6 +5,8 @@ #include #include +.option arch, +v + #define pDst a0 #define pSrc a1 #define iNum a2 diff --git a/arch/riscv/lib/xor.S b/arch/riscv/lib/xor.S index b28f2430e52f..9a3e2c19efc9 100644 --- a/arch/riscv/lib/xor.S +++ b/arch/riscv/lib/xor.S @@ -6,6 +6,8 @@ #include #include +.option arch, +v + SYM_FUNC_START(xor_regs_2_) vsetvli a3, a0, e8, m8, ta, ma vle8.v v0, (a1) From patchwork Wed May 8 01:36:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68B9EC10F1A for ; Wed, 8 May 2024 01:36:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0abM4E+HsaHHeHf0ysk5eJiN2iu+gzf1YSYgpUzsyFg=; b=RgJNPIc2T4t2Ft ujHvSyXkxUCu1EQhgmKj8fOjsYrDL3Hxj/nXjpbFS0SIn3wvFxaUV6c85LGqZqFWIWSSg9UBy6BfO kOPg3mkYKJStdsLKWAKy/Gv2zRbu3GqSQHCK49bYE0KGh/eBz7nKqJWYbMH5jbyQIt33zav0gK8tr VTS7oVjQniDus9aiX//SMKqoBQJgwA4/g+VKp7kLy4QNpZVh97Bw9wXQn4RCSA7tqlnjvB8LTPDP0 tRCbd1SSZ5Gww4oLm2twOxFO710hqG0mF+3EUwfEqdzPe85sbrBzivlYqUaz0wu1CE1HjqORfjFbg YWncDZhZrLj3DUm2jmDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEl-0000000Dezy-0MF0; Wed, 08 May 2024 01:36:51 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEh-0000000Dexo-21KO for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:49 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2b38f2e95aeso263506a91.0 for ; Tue, 07 May 2024 18:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132205; x=1715737005; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZyAjbp499S4E60gPGPnq8+Il/FcfjFcaiJmSSEoBy08=; b=L2JIIij2IPwgM8+kg9llGTnalPMVVrDP01ngt+CYkuUSa/8sWbPazxLgG3tlnX+el0 K9u0jLQ5FikHUWIMOVy4wcTV9oHROdHGIIALvoKg/X5JvTOAMOZP3xqApaecBU1fkBs4 EzSpqcSCS5jMloonmtcucHkp8wbcQ1RiFIt9Zba6KAGufwbsMNWcHdLMeT0eZC5Xe5qq vZXo2ac4kxXmm+SAkGZZsHFCqpZlyKxutodb8lJq0jxe8nE/FpnUSsVEsRwwXt0YFpHv YavRHoOU0L+p846QsVVZMwF0ZGz/k7uCiCEtUCgaddcmG5jDic4i84XXdX/TZlzsUd9Y 0Lww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132205; x=1715737005; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZyAjbp499S4E60gPGPnq8+Il/FcfjFcaiJmSSEoBy08=; b=RxiHgWwlXwyJf2gKqHwjaodEtPLAXYBclwd299am1MFoazRgrF98LGbb9r+S6ZJt89 lGivNYS2FA5OboInAiQomHSvVK+iKvREpEu2OhHwa/gZFbenXyp9pERg8zeoRQSSZg9v q5/vlX7LpLnrRuVXwLswNGsC6YFD9ZwgU5N5jnC7cnj7BZZiY+waF7yyrrUTcJA88tS2 R+i6GH5/BkAD2gEK+Heql9gL9fK91SDumEp0wTkR4C8ZXGUUJyBGoIlY9SwDV2xJeUEN DLlpZoVKK0LKioo8hTzaO5tw+IJaRDHa+nG4vmHeXPLeYD0q4wczmk42s2IOScoioPLR 6x3g== X-Gm-Message-State: AOJu0YxCoXdA7P8JOipV2RKEND8+P6T937LbOYIEijXqZyR34IVOlNjf QqimHXeChF3MoVfmPUcJJf+gOor+EXiziwux2CrLzXiZMD6/0UY3xh1Pxzt5sdk= X-Google-Smtp-Source: AGHT+IHwXlXHG/dkLoF/6u+zxBIvilwus9SDgdbrJPGXciSar+3njjYMfgBvflCo8Xus0Cl4AWNAgQ== X-Received: by 2002:a17:90a:1001:b0:2ad:f3c3:540d with SMTP id 98e67ed59e1d1-2b611aecf9amr1982459a91.21.1715132205449; Tue, 07 May 2024 18:36:45 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:44 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:29 -0700 Subject: [PATCH v2 3/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT Kconfig option MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-3-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=4526; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=gHdAyzxOSw9+j0qkNaNh5cV4dO8gj7MOepOEM8Ai+S4=; b=n798W2bBPAkZ1DxRbCdpbApDgPYqiZBBEqfBDG7kgws2qQjYG55u+NOtwPJkJ2zwoa3y5JfGj 1/3Q87QUPqFCAhtwHtP01IYlaKmSvNxxzdLntEkAIGs00uPQ9WLzkTG X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183647_575767_ED969A29 X-CRM114-Status: GOOD ( 19.22 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The existing "RISCV_ISA_SVNAPOT" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT or PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT has been set. PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT will check if the hardware supports Svnapot before using it, while PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT will assume that the hardware supports Svnapot. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 19 ----------------- arch/riscv/Kconfig.isa | 44 ++++++++++++++++++++++++++++++++++++++++ arch/riscv/include/asm/pgtable.h | 3 ++- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c2e9eded0a7d..3c1960e8cd7c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -484,25 +484,6 @@ config RISCV_ALTERNATIVE_EARLY help Allows early patching of the kernel for special errata -config RISCV_ISA_SVNAPOT - bool "Svnapot extension support for supervisor mode NAPOT pages" - depends on 64BIT && MMU - depends on RISCV_ALTERNATIVE - default y - help - Add support for the Svnapot ISA-extension in the kernel when it - is detected at boot. - - The Svnapot extension is used to mark contiguous PTEs as a range - of contiguous virtual-to-physical translations for a naturally - aligned power-of-2 (NAPOT) granularity larger than the base 4KB page - size. When HUGETLBFS is also selected this option unconditionally - allocates some memory for each NAPOT page size supported by the kernel. - When optimizing for low memory consumption and for platforms without - the Svnapot extension, it may be better to say N here. - - If you don't know what to do here, say Y. - config RISCV_ISA_SVPBMT bool "Svpbmt extension support for supervisor mode page-based memory types" depends on 64BIT && MMU diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index 0663c98b5b17..37585bcd763e 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -124,3 +124,47 @@ config RISCV_ISA_V_PREEMPTIVE This config allows kernel to run SIMD without explicitly disable preemption. Enabling this config will result in higher memory consumption due to the allocation of per-task's kernel Vector context. + +config RISCV_ISA_SVNAPOT + bool + +choice + prompt "Svnapot extension support for supervisor mode NAPOT pages" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT + help + This selects the level of support for Svnapot in the Linux Kernel. + + The Svnapot extension is used to mark contiguous PTEs as a range + of contiguous virtual-to-physical translations for a naturally + aligned power-of-2 (NAPOT) granularity larger than the base 4KB page + size. When HUGETLBFS is also selected this option unconditionally + allocates some memory for each NAPOT page size supported by the kernel. + When optimizing for low memory consumption and for platforms without + the Svnapot extension, it may be better to prohibit Svnapot. + +config PROHIBIT_RISCV_ISA_SVNAPOT + bool "Prohibit Svnapot extension" + help + Regardless of if the platform supports Svnapot, prohibit the kernel + from using Svnapot. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT + bool "Allow Svnapot extension if supported" + depends on 64BIT && MMU + depends on RISCV_ALTERNATIVE + select RISCV_ISA_SVNAPOT + help + Add support for the Svnapot ISA-extension in the kernel when it + is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT + bool "Emit Svnapot mappings when building Linux" + depends on 64BIT && MMU + depends on NONPORTABLE + select RISCV_ISA_SVNAPOT + help + Compile a kernel that assumes that the platform supports Svnapot. + This option produces a kernel that will not run on systems that do + not support Svnapot. + +endchoice diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 6afd6bb4882e..432be9691b78 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -289,7 +289,8 @@ static inline pte_t pud_pte(pud_t pud) static __always_inline bool has_svnapot(void) { - return riscv_has_extension_likely(RISCV_ISA_EXT_SVNAPOT); + return IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT) || + riscv_has_extension_likely(RISCV_ISA_EXT_SVNAPOT); } static inline unsigned long pte_napot(pte_t pte) From patchwork Wed May 8 01:36:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 064EBC25B4F for ; Wed, 8 May 2024 01:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8raYk5GLIU/oPkpOOMGGJ9K97V7hTWNr7aKk5eEPzfM=; b=qeTCzuZZVf/XgD 3bLlvQVSL3pwMEkJVvq+aBZsxWRG6pcOPqFYQNjrm8ou9rhzVbE9zMGyAtA40T5tiEBWBdGCH++5z AsNQn8wZofFDeIZapE/1nlcu3ayET0+MBppB+yBY1oG5klCUV5okoABJ9Pw0cFIuFeXXAR5tlpCHA jBoOjbw4/5rzkFmieRAfmm2aFYIbRKFWeUNIlGaPc4MdUguAMUJPhsWDe5xEhK5RpLkKrPJwFYwSw VL9usfUpy6Lybti/9VrmCPIGoZAdOJNK5vy2qgHoD3g3ig6fflJ6WMUjOD8F089jBzZi44fXXvLHx 0Odo7M+14Ap6984Dk1/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEo-0000000Df2m-2x2G; Wed, 08 May 2024 01:36:54 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEk-0000000DeyC-2vkS for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:52 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f28bb6d747so2756280b3a.3 for ; Tue, 07 May 2024 18:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132207; x=1715737007; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vFSJQnmxYmfjoFDImtU4VL6iWxbfob1tPsjHMgxh4E4=; b=efRJos3A0Mj3RQ3DqpaX9+9CRy8NIprmCxfVXI9cIS0RzdFYNMyzG7FQftQTIVGTtw iEa1PvjZGGZEM/yYIiX8OPDYjwX8lofeKt214P/JBsvAX8QsOPUxilNKjEfHYTnoiaXD jM+HRHGafGB6eG/ySonK0vjiJWKq045WVtLTby9SnQJbt+sT6lXaCDspUPFbxbtVnSD3 DJGMTIwkXXd67Tn0UiNkQGhtB5kDIDw31pYGQmwqfSl6mLVAIXqpdhR5jbTFn5w7BzD4 yNUO1Vwgs476oD+NF1xY65ZFhuds+ZA7Mf5KaGYbXYIZdSX2hb9KV8fN1kuRICWGCPPy I2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132207; x=1715737007; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vFSJQnmxYmfjoFDImtU4VL6iWxbfob1tPsjHMgxh4E4=; b=amHEPMglQFyzQQX8USF0cNNe705NlYL8PLCT8mPSOzGwJKfP5xxVKjD8KUw1VLvLvb mRliza++QVpub3HWY9KEvr69Fz94tFesZlYO6nso9CRyHfJLuPMamgbr6Oi8kUu0zaSS EWJUK0N4QW8Pf3X2A1OWFy3uZ9skDCoG9sW+ySIpF02ZqV+LuhCmVCcuycfAu4vVul0U YN3+chqn3t57XvGbiFF2E2p/p+GR12+bjYo6khXtvU2u/ZIwvSCfzzFZapnYHCt1T/RG TrtUX1DH6K1TWwKXPB9a7TqAt8Mep6go8yqGCztzNbaXT8T6emRIG6MB2XWs0KAg/13n mXXQ== X-Gm-Message-State: AOJu0YxL8cgTvdAhfi3uHdXeabNMi88IVHbjDDaxDDZMhXvoFj00a/Bi pyFySN7gBCcW8FuMZUJfWp4Qcsl/pogF4S6t2pvu1fK+A2ClGoeybVMk2duvYbE= X-Google-Smtp-Source: AGHT+IGyPdvmy6aV3B3L4umYWWDDY8xIoU7bUJV2TUBvLWRK8ohQMMF3SW0DKxfoVvgynUcDHsYrOA== X-Received: by 2002:a05:6a21:2715:b0:1a9:5b1e:4f06 with SMTP id adf61e73a8af0-1afc8e045e8mr1232295637.52.1715132207095; Tue, 07 May 2024 18:36:47 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:46 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:30 -0700 Subject: [PATCH v2 4/8] riscv: Move RISCV_ISA_SVPBMT to Kconfig.isa MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-4-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=2196; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=hN6gBReRWF4tyaALzLlv0FO1iXf71FwbEQWuRR1cn6U=; b=rwmUivRGvDcoS+kvi09gdGx7PVj/grlp+Tad0aawkK1yi6IcKtZer2CtyNjel3SZbguaXYzst 2GPHvUxb7LyAOvNrFFBjRTs73lBl91FO/UMmx/qaiWyoJ8A6E4MRt+T X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183650_808501_EA859B8F X-CRM114-Status: GOOD ( 14.51 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Svpbmt would not benefit from having PLATFORM_SUPPORTS_RISCV_ISA_SVPBMT so just move the definition of RISCV_ISA_SVPBMT to Kconfig.isa. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 17 ----------------- arch/riscv/Kconfig.isa | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 3c1960e8cd7c..47a1d28bbb64 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -484,23 +484,6 @@ config RISCV_ALTERNATIVE_EARLY help Allows early patching of the kernel for special errata -config RISCV_ISA_SVPBMT - bool "Svpbmt extension support for supervisor mode page-based memory types" - depends on 64BIT && MMU - depends on RISCV_ALTERNATIVE - default y - help - Add support for the Svpbmt ISA-extension (Supervisor-mode: - page-based memory types) in the kernel when it is detected at boot. - - The memory type for a page contains a combination of attributes - that indicate the cacheability, idempotency, and ordering - properties for access to that page. - - The Svpbmt extension is only available on 64-bit cpus. - - If you don't know what to do here, say Y. - config TOOLCHAIN_HAS_ZBB bool default y diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index 37585bcd763e..50e217dc5719 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -168,3 +168,20 @@ config PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT not support Svnapot. endchoice + +config RISCV_ISA_SVPBMT + bool "Svpbmt extension support for supervisor mode page-based memory types" + depends on 64BIT && MMU + depends on RISCV_ALTERNATIVE + default y + help + Add support for the Svpbmt ISA-extension (Supervisor-mode: + page-based memory types) in the kernel when it is detected at boot. + + The memory type for a page contains a combination of attributes + that indicate the cacheability, idempotency, and ordering + properties for access to that page. + + The Svpbmt extension is only available on 64-bit cpus. + + If you don't know what to do here, say Y. From patchwork Wed May 8 01:36:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A76E7C25B74 for ; Wed, 8 May 2024 01:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3D5lx+cGqFPwfzcDnbaVaVTqQLSoQxjiSBV4kaOIjAQ=; b=R7VwH7tVg5qPh/ JEeTLiO4Qfz7jdLZtOFSu8TXKScbIiadGOOgnyZE0AQKzxeqN03CRiZFHldSIKJKmsN/Y2iNJv4Bc 1hzwdQUAuFs8jTWMuoq+aYxCm2kQcG2d4z1V2yOdb1VZgIchAnylBuD2gqKQTESFuJtEayzZwKpSz 7uIXQjBu7NgBNdiO9QenOXr/WCitqF1eeKPAKK9zrAXsPCBJ36UU+vntHwcVieqyqFUIJIGs8c1xr XBrSwbY/yy2e7ZhmQbTDFFCHSXWP20V5/X5zIegem+6HpR4eNLNprpkR1CTCsaMXrz/rQP02uSfjq bfBfvsWY11OKG2ydk6tQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEq-0000000Df3R-09Mk; Wed, 08 May 2024 01:36:56 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEk-0000000DezB-3skn for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:52 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2b27c532e50so2628699a91.2 for ; Tue, 07 May 2024 18:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132209; x=1715737009; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=th9kOuU1e9CFgMoeHZSK9oNWtH0aPnkCZu5MPXoJ/hI=; b=epUjdZoWLkwpqMqeFKJfhTVLoZQn6/uxJjtxVyzeVEGwJaaLNP6gHi+h7YLV0KXXMh 9dnqQaz8h+gim2XJZckSJEP3bjWDTMO9+0KlP10To+n4WXesUbx04xQ9E2zOeLwKQuE0 HhVhl3pRfxoTq0Tg2+WVvqc2LBav7a/DaWVJSgM6SbXnpNKwIZKSiAzOM5cW4E1zLU8k WVjLh/ORh/ITi26x6WgYuhclsYfui8cEJydQ2LcmZO4VW1rmcA+xaYPpFKu+9aN5ZurS dQUJtmiJ2z6RKOwEmE/MYKRc3bOXrlO+4PeGdKcf8QtZJXP5MyS+mDcV5jlscROAWWGS htvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132209; x=1715737009; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=th9kOuU1e9CFgMoeHZSK9oNWtH0aPnkCZu5MPXoJ/hI=; b=LGeFlSsAQ8RlpYjtTWFcMY0x6ZzwV38NIavggdVEbsDAkr2OBsSYcB0I8nJ3L7d+Fd WDe+n1UfSAmdwDtw6lgwtqfJQ7CJRhkAS1uSxnaaYhyCYPEHq2R45MfOeeczbzm6wDHo JftDlzxjP+6TibIyDMnTWXCrr5dhFNxkSd13DWBTlJJYSfSvWBSDY/2GjkX9piayc2Cv eEMvjybgPeyzWqt0VLsO4Nfj1A4rt0bjB6poxuUk1RWmJnr3e0aWyLpOJuONdaZB16XO gfp6AohJcG9MWzHnYbdyHp0YumdHfx/Zrxq2VXcPNTAZQ/Ja2oocLZt5dz1MO1lEuTyE Nc4w== X-Gm-Message-State: AOJu0Yyia46N7Krrrf9yMALQCsrug8Wt+5/93YA2zrYxQ4f6TA7rbDm1 PAa5XVsC8DAV/17sVeOZLnubraIpXfu58qP/Rx+foQBKZXAeP6Qkxsic6470IHc= X-Google-Smtp-Source: AGHT+IFXoQ5QrGUnjsqJOFF8ILEziuw2R/JwNz2AA0yMtAfuMkwguJG5FDUdd+JLIhNLXY8MnpekNA== X-Received: by 2002:a17:90a:6581:b0:2b2:c6f8:70b0 with SMTP id 98e67ed59e1d1-2b6165a4d0dmr1314326a91.11.1715132208778; Tue, 07 May 2024 18:36:48 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:48 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:31 -0700 Subject: [PATCH v2 5/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBB Kconfig option MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-5-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=14084; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=cOJgPTsZER0QYbl0huXDzsEpoo6FnPUGzH8hvF+KHqU=; b=ama9tCwHrUazEXquTbnZAxNqCYykgl/D7s4mQyJl2bwHPMJO1TKXiGVKJBZJCxYEciqIl5MoE pLyQxwfvk5LAV3FUe7c3WxRmXxBOBLnme26x/X+JygB1MhlaYlKAdB+ X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183651_086842_AACDAC7C X-CRM114-Status: GOOD ( 23.64 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Zbb can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBB that allows arbitrary Zbb instruction sequences to be emitted by the compiler. This assumption also allows the alternatives to become evaluated at compile time for Zbb. The existing "RISCV_ISA_ZBB" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB or PLATFORM_SUPPORTS_RISCV_ISA_ZBB has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 24 ---------------- arch/riscv/Kconfig.isa | 54 ++++++++++++++++++++++++++++++++++- arch/riscv/Makefile | 1 + arch/riscv/include/asm/arch_hweight.h | 33 ++++++++++----------- arch/riscv/include/asm/checksum.h | 18 ++++++------ arch/riscv/lib/csum.c | 48 +++++++++++++++---------------- arch/riscv/lib/strcmp.S | 4 +-- arch/riscv/lib/strlen.S | 4 +-- arch/riscv/lib/strncmp.S | 4 +-- arch/riscv/net/bpf_jit.h | 4 ++- 10 files changed, 113 insertions(+), 81 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 47a1d28bbb64..df620e534b3f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -484,14 +484,6 @@ config RISCV_ALTERNATIVE_EARLY help Allows early patching of the kernel for special errata -config TOOLCHAIN_HAS_ZBB - bool - default y - depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb) - depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb) - depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 - depends on AS_HAS_OPTION_ARCH - # This symbol indicates that the toolchain supports all v1.0 vector crypto # extensions, including Zvk*, Zvbb, and Zvbc. LLVM added all of these at once. # binutils added all except Zvkb, then added Zvkb. So we just check for Zvkb. @@ -499,22 +491,6 @@ config TOOLCHAIN_HAS_VECTOR_CRYPTO def_bool $(as-instr, .option arch$(comma) +v$(comma) +zvkb) depends on AS_HAS_OPTION_ARCH -config RISCV_ISA_ZBB - bool "Zbb extension support for bit manipulation instructions" - depends on TOOLCHAIN_HAS_ZBB - depends on MMU - depends on RISCV_ALTERNATIVE - default y - help - Add support for enabling optimisations in the kernel when the - Zbb extension is detected at boot. - - The Zbb extension provides instructions to accelerate a number - of bit-specific operations (count bit population, sign extending, - bitrotation, etc). - - If you don't know what to do here, say Y. - config RISCV_ISA_ZICBOM bool "Zicbom extension support for non-coherent DMA operation" depends on MMU diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index 50e217dc5719..49bed8c75263 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -169,7 +169,7 @@ config PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT endchoice -config RISCV_ISA_SVPBMT +config PLATFORM_MAY_SUPPORT_RISCV_ISA_SVPBMT bool "Svpbmt extension support for supervisor mode page-based memory types" depends on 64BIT && MMU depends on RISCV_ALTERNATIVE @@ -185,3 +185,55 @@ config RISCV_ISA_SVPBMT The Svpbmt extension is only available on 64-bit cpus. If you don't know what to do here, say Y. + +config TOOLCHAIN_HAS_ZBB + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBB + bool + +choice + prompt "Zbb extension for bit manipulation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB + help + This selects the level of support for Zbb instructions to be + built into the Linux Kernel. This does not impact whether Zbb + instructions are allowed to be emitted by user-space code. + + The Zbb extension provides instructions to accelerate a number + of bit-specific operations (count bit population, sign extending, + bitrotation, etc). + +config PROHIBIT_RISCV_ISA_ZBB + bool "Prohibit Zbb instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zbb instructions, + prohibit the kernel from emitting Zbb instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB + bool "Allow Zbb instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBB + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBB + help + Add support for enabling optimisations in the kernel when the + Zbb extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBB + bool "Emit Zbb instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBB + depends on NONPORTABLE + select RISCV_ISA_ZBB + help + Adds "zbb" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zbb instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zbb extension. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index e1111e62ca20..6b0c3a782f99 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -66,6 +66,7 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) := $(riscv-march-y)c +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) := $(riscv-march-y)_zbb ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS += -Wa,-misa-spec=2.2 diff --git a/arch/riscv/include/asm/arch_hweight.h b/arch/riscv/include/asm/arch_hweight.h index 85b2c443823e..d89a18d5104f 100644 --- a/arch/riscv/include/asm/arch_hweight.h +++ b/arch/riscv/include/asm/arch_hweight.h @@ -19,21 +19,20 @@ static __always_inline unsigned int __arch_hweight32(unsigned int w) { -#ifdef CONFIG_RISCV_ISA_ZBB - asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, - RISCV_ISA_EXT_ZBB, 1) - : : : : legacy); - - asm (".option push\n" - ".option arch,+zbb\n" - CPOPW "%0, %0\n" - ".option pop\n" - : "+r" (w) : :); - - return w; + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB)) { + if (!IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB)) + asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, + RISCV_ISA_EXT_ZBB, 1) + : : : : legacy); + asm (".option push\n" + ".option arch,+zbb\n" + CPOPW "%0, %0\n" + ".option pop\n" + : "+r" (w) : :); + return w; + } legacy: -#endif return __sw_hweight32(w); } @@ -50,11 +49,12 @@ static inline unsigned int __arch_hweight8(unsigned int w) #if BITS_PER_LONG == 64 static __always_inline unsigned long __arch_hweight64(__u64 w) { -# ifdef CONFIG_RISCV_ISA_ZBB +#ifdef CONFIG_PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, RISCV_ISA_EXT_ZBB, 1) : : : : legacy); - +#endif +#ifdef CONFIG_RISCV_ISA_ZBB asm (".option push\n" ".option arch,+zbb\n" "cpop %0, %0\n" @@ -62,7 +62,8 @@ static __always_inline unsigned long __arch_hweight64(__u64 w) : "+r" (w) : :); return w; - +#endif +#ifdef CONFIG_PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB legacy: # endif return __sw_hweight64(w); diff --git a/arch/riscv/include/asm/checksum.h b/arch/riscv/include/asm/checksum.h index 88e6f1499e88..2fe92abf5525 100644 --- a/arch/riscv/include/asm/checksum.h +++ b/arch/riscv/include/asm/checksum.h @@ -2,7 +2,7 @@ /* * Checksum routines * - * Copyright (C) 2023 Rivos Inc. + * Copyright (C) 2023-2024 Rivos Inc. */ #ifndef __ASM_RISCV_CHECKSUM_H #define __ASM_RISCV_CHECKSUM_H @@ -49,16 +49,16 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) * ZBB only saves three instructions on 32-bit and five on 64-bit so not * worth checking if supported without Alternatives. */ - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB)) { unsigned long fold_temp; - asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, - RISCV_ISA_EXT_ZBB, 1) - : - : - : - : no_zbb); + if (!IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB)) + asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, + RISCV_ISA_EXT_ZBB, 1) + : + : + : + : no_zbb); if (IS_ENABLED(CONFIG_32BIT)) { asm(".option push \n\ diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c index 7fb12c59e571..5ea2bf71c963 100644 --- a/arch/riscv/lib/csum.c +++ b/arch/riscv/lib/csum.c @@ -44,8 +44,7 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr, * Zbb support saves 4 instructions, so not worth checking without * alternatives if supported */ - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB)) { unsigned long fold_temp; /* @@ -53,12 +52,13 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr, * support, so nop when Zbb is available and jump when Zbb is * not available. */ - asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, - RISCV_ISA_EXT_ZBB, 1) - : - : - : - : no_zbb); + if (!IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB)) + asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, + RISCV_ISA_EXT_ZBB, 1) + : + : + : + : no_zbb); asm(".option push \n\ .option arch,+zbb \n\ rori %[fold_temp], %[sum], 32 \n\ @@ -161,8 +161,7 @@ do_csum_with_alignment(const unsigned char *buff, int len) * Zbb support saves 6 instructions, so not worth checking without * alternatives if supported */ - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB)) { unsigned long fold_temp; /* @@ -170,12 +169,13 @@ do_csum_with_alignment(const unsigned char *buff, int len) * support, so nop when Zbb is available and jump when Zbb is * not available. */ - asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, - RISCV_ISA_EXT_ZBB, 1) - : - : - : - : no_zbb); + if (!IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB)) + asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, + RISCV_ISA_EXT_ZBB, 1) + : + : + : + : no_zbb); #ifdef CONFIG_32BIT asm_goto_output(".option push \n\ @@ -248,8 +248,7 @@ do_csum_no_alignment(const unsigned char *buff, int len) * Zbb support saves 6 instructions, so not worth checking without * alternatives if supported */ - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB)) { unsigned long fold_temp; /* @@ -257,12 +256,13 @@ do_csum_no_alignment(const unsigned char *buff, int len) * support, so nop when Zbb is available and jump when Zbb is * not available. */ - asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, - RISCV_ISA_EXT_ZBB, 1) - : - : - : - : no_zbb); + if (!IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB)) + asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0, + RISCV_ISA_EXT_ZBB, 1) + : + : + : + : no_zbb); #ifdef CONFIG_32BIT asm (".option push \n\ diff --git a/arch/riscv/lib/strcmp.S b/arch/riscv/lib/strcmp.S index 687b2bea5c43..5798ef7e73fc 100644 --- a/arch/riscv/lib/strcmp.S +++ b/arch/riscv/lib/strcmp.S @@ -7,7 +7,7 @@ /* int strcmp(const char *cs, const char *ct) */ SYM_FUNC_START(strcmp) - +#ifndef CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB ALTERNATIVE("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB) /* @@ -37,7 +37,7 @@ SYM_FUNC_START(strcmp) */ sub a0, t0, t1 ret - +#endif /* !CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB */ /* * Variant of strcmp using the ZBB extension if available. * The code was published as part of the bitmanip manual diff --git a/arch/riscv/lib/strlen.S b/arch/riscv/lib/strlen.S index 8ae3064e45ff..b63b91f74084 100644 --- a/arch/riscv/lib/strlen.S +++ b/arch/riscv/lib/strlen.S @@ -7,7 +7,7 @@ /* int strlen(const char *s) */ SYM_FUNC_START(strlen) - +#ifndef CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB ALTERNATIVE("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB) /* @@ -29,7 +29,7 @@ SYM_FUNC_START(strlen) 2: sub a0, t1, a0 ret - +#endif /* !CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB */ /* * Variant of strlen using the ZBB extension if available */ diff --git a/arch/riscv/lib/strncmp.S b/arch/riscv/lib/strncmp.S index aba5b3148621..3a1330d7d4a2 100644 --- a/arch/riscv/lib/strncmp.S +++ b/arch/riscv/lib/strncmp.S @@ -7,7 +7,7 @@ /* int strncmp(const char *cs, const char *ct, size_t count) */ SYM_FUNC_START(strncmp) - +#ifndef CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB ALTERNATIVE("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB) /* @@ -42,7 +42,7 @@ SYM_FUNC_START(strncmp) */ sub a0, t0, t1 ret - +#endif /* !CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB */ /* * Variant of strncmp using the ZBB extension if available */ diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h index 259294bdbc3a..61892044124e 100644 --- a/arch/riscv/net/bpf_jit.h +++ b/arch/riscv/net/bpf_jit.h @@ -22,7 +22,9 @@ static inline bool rvc_enabled(void) static inline bool rvzbb_enabled(void) { - return IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBB); + return IS_ENABLED(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) || + (IS_ENABLED(CONFIG_PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB) && + riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)); } enum { From patchwork Wed May 8 01:36:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C831C19F4F for ; Wed, 8 May 2024 01:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TF2M/Rf9ssSw8WItbUQtIhLBCFDYWYfhTj7l009lJo0=; b=SZVaratQX01OwG qSLQbbRwIvHhy9kITiHmiveAzhy1wXWtbx8JvS8mM3MsoAR4rXkEkYIltlUq5Qz7og5vW2D/Tajqa tvRaPXwygNndblgmqYa37lq3TNPqnwDistTcz7V9xpoThoCErjcst7/8LJocqWwixJfHVA9YnITlI +Sti/rUG6OAWhtoxHRmA+lIFrUYFiyPMdj5+mr7BilSRH2yJ43bGsPQ6u/zKZ0cH2Ksyz5ISVytR3 fjxFGIgyk5nXAQm89uxrbfF9Mb7GhjpphaD95DtoUm713nGPI+iFlcQ7UGuUKXV1VdNKQyobtMqGw HvGI+3rDz96pz+0XjvDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEs-0000000Df5A-3emj; Wed, 08 May 2024 01:36:58 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEm-0000000Dezi-1Ohd for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:54 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6f4551f2725so3643753b3a.1 for ; Tue, 07 May 2024 18:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132210; x=1715737010; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=myHzOOjViF8S4NmNBR6ubwFIqcNqWX5HRrdoX2U4mxE=; b=lSJfZMtDTjr0UyAPS9XS23MGqeCPxYLQj7yPo1OaRqzgH0Dp3NgXHzVnV/47JI+S/M KUEW+yAXyR/xoNq3K+4l3d4S42qSBeRHn24ao5iQyeUdG6Ftoz8mkz1vNDn2kRAT7IzX xKoNsxposO4Foy9tW72F5MQnw6rj5VmAj6w7q+FS40/1331I06kLNGOhyJU2TDzsofzN jlh+ZvbbargB6g33HEbHX9b8f4KGZy1Dt8QiUfrS4i/B0M1z4bdoGMahm4t6CdFdX39e iObg5RNWSIUOjnMLnwl+rXkeBcJDiCzG58/UyB6OwMR4XqFLx09t4UhS9Lp4hkDM0eES sQyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132210; x=1715737010; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=myHzOOjViF8S4NmNBR6ubwFIqcNqWX5HRrdoX2U4mxE=; b=agBwBpBU6hvXmp+XftzEi84wU8cv/aYTMbhZkl79or1bUcNvdfPiMGOe+mXyZVhpN6 Mxva58KPWcpDGdT6IXEN4kxffvComzyh5n2r9aY3KnNkpbxwhVZcLkK865CdhUWOr3T9 oE50pA898LTZNaZS3ngm3O8A84ZbnFn34Ose6bXNwgXQDKI1aUWTWpmk67ZFwlUcotbj 9GHXe1qJvhlpiayJnBV0yq3d/AsOpF/B585PSUc4NKaBDBCJFCO5PWa/aBQzdfbmSHs5 dipf5+JBff12UKBooi0cs9/bPXHEW/Y5SfDAS4X5zRJLmNKezQB+TRqZL0BoJSa64kaz Gc9g== X-Gm-Message-State: AOJu0YzEHy9dME47Pd9cHHgz9i0jtfqvkdAF6s8zi3NhISkkaoeQD4BJ hx5tastZuE7k5gCnSApEgsm2PfIKFt1/5c+NI8FHTNBBeOF4iMKiDyZbXFcvK+8= X-Google-Smtp-Source: AGHT+IHmyiekyum4bwoOJjosIJw7Z4DfDemwOXxUCyVbwuXuMPDsZBlduhwLXl3Z+XO6EPfAoMsxiA== X-Received: by 2002:a05:6a21:191:b0:1a7:2ceb:e874 with SMTP id adf61e73a8af0-1afc8d5b8fcmr1553729637.37.1715132210381; Tue, 07 May 2024 18:36:50 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:49 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:32 -0700 Subject: [PATCH v2 6/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBA Kconfig option MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-6-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=3295; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=Ue5TDLMRl4Jg133jL9t6n44Efl7WVoijxTwvOh6lOb4=; b=VPIFtHfzr8Xor7UIxI0uyPtvmdLuA5naS2Aa3xz4lMr3TZ261O7CupIAtnVu2wEleN1W4S7jL MeRK4vLEM5jDcGk96yhQiSL1n+P1wTsp6mS9ZW8caczG/bll99sxiRn X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183652_492195_DCFF7A42 X-CRM114-Status: GOOD ( 15.36 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Zba can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBA that allows arbitrary Zba instruction sequences to be emitted by the compiler. The existing "RISCV_ISA_ZBA" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBA or PLATFORM_SUPPORTS_RISCV_ISA_ZBA has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.isa | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 1 + 2 files changed, 53 insertions(+) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index 49bed8c75263..e7f28dc44137 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -186,6 +186,58 @@ config PLATFORM_MAY_SUPPORT_RISCV_ISA_SVPBMT If you don't know what to do here, say Y. + +config TOOLCHAIN_HAS_ZBA + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zba) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zba) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBA + bool + +choice + prompt "Zba extension for address generation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBA + help + This selects the level of support for Zba instructions to be + built into the Linux Kernel. This does not impact whether Zba + instructions are allowed to be emitted by user-space code. + + The Zba extension provides instructions to accelerate a number + of address generation instruction sequences. + +config PROHIBIT_RISCV_ISA_ZBA + bool "Prohibit Zba instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zba instructions, + prohibit the kernel from emitting Zba instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBA + bool "Allow Zba instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBB + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBA + help + Add support for enabling optimisations in the kernel when the + Zba extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBA + bool "Emit Zba instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBB + depends on NONPORTABLE + select RISCV_ISA_ZBA + help + Adds "zba" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zba instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zba extension. + +endchoice + config TOOLCHAIN_HAS_ZBB bool default y diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 6b0c3a782f99..c8ec38b9880a 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -66,6 +66,7 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) := $(riscv-march-y)c +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBA) := $(riscv-march-y)_zba riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) := $(riscv-march-y)_zbb ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC From patchwork Wed May 8 01:36:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3797C19F4F for ; Wed, 8 May 2024 01:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Cbi+StZ93cu4fYOJHUE5VyTmQYfikcHP/N9iJ1d9gYs=; b=oFlh4DzMHO7YXc L6fRJrrgOu7fP9LMKHQJbRObmzzopZluw3FqVuW5RZL1GzJ3zpsuz6PYbU0WgDWBzVP7RwGaKTi0x /eaCDBE64t/whqP3zfLU9cEeuHbr0kel1jwGCIpC/xIvoRCP69++xtModIuVjZ8qXg7PIyaXZqGjt 6DO/dHFuLVgyz0BsCuloi1oX1gw4RG73efXF9oI0nenfyDAnTqRbmbieZn0WsMJQkJv8lSiuodnTT cr01vmgK7sXCOhKcXshOekjpWHAI9NcTcEgodo1P9xj8Gmi+3bM+RvrBWGuKJZep7nZjk5wTuARRj yZA3SdxMd/Yj5jVhochw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEt-0000000Df5X-3CaR; Wed, 08 May 2024 01:36:59 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEo-0000000Df0g-0Blc for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:56 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2b4a7671abaso2593231a91.0 for ; Tue, 07 May 2024 18:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132212; x=1715737012; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=G63nKFkjY3qHnS0X1QIzt6sf9vbSpbh90Xj2nxjAK3E=; b=IChYqDQqs0DVbwJnxOMrOAHEx6suurBzUq1N9HXLWRh3B7wZ7CAJLv3ppJqTcsfIf7 DHQL9f23Yic+6AE1yWoUeBs03bd2/QVv9QM237Hnc+WMR1fYsQHL9uLj4z0ukRDIf/mW /Q8FnIW03cxdCJ3flv76oTKGwzGPFbgZjxlfcb2H/nDMsQbSdPdsY0/ILDctKjJFjgWW rMGMl4T+JHCdpztnrVXk1VkOwODJb/1uDHe8QX/Va8FdA5KWlj/JBAllGK0QdPDKSvJQ rARngbmVnoB2oJ+yglcn57Y21elNOUrK8L7xoVVZ4VTplGaZDjCJCtAaIFmHWRUYNETl ZRGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132212; x=1715737012; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G63nKFkjY3qHnS0X1QIzt6sf9vbSpbh90Xj2nxjAK3E=; b=QKZzhAQe7sLbZmS33sgcvB9JeVC1RYQhebYQ3jXuZhABxBllZZJ4yN9kz7AhmuLaKX OpKG54G/E9SEI1WkIxueZ5/UfpuPrb+l5KMmpi38tDFd3yn8Aqf6MbJRYhC+LIn2bpZ0 Z2kYERQfKEBsUVX7x+RGxrPVvWb2EVtdVrf42ea3cTMbB0HWfaRx8LY/4wUdgdtLgwE2 UUVXjGkKENzVnWjJIcpG0O3QWuEGbCifipyyOfK4D1ehQp+Fz++/QmFQm66C9IUNJtia v6hPBdlGlzYFToW50233wsIIzGvrOJDal4eEhNG+DdCPYjTsri4GlO7iqDFHfgYakdYX gnig== X-Gm-Message-State: AOJu0Yx6JR0DL9qCopl7qT4kxDgaJZO5OdHTRSVukcUWel14eLViFX63 YVgr2lvosn74CJ3MSEXZqa/0ycco/fxHby65dr5ZOqF4ycRm1sJ01nOecQbs/DRJi+KoWdJw7L8 A X-Google-Smtp-Source: AGHT+IFiGPyl3zNyE/SYLjw5BlcdAyzafc6IKgnN2PalwWvftlru0VCVPMVwGkF+0UEGKI78AFsrvQ== X-Received: by 2002:a17:90a:5d06:b0:2b2:7c42:bf6e with SMTP id 98e67ed59e1d1-2b6165aa078mr1175508a91.12.1715132211950; Tue, 07 May 2024 18:36:51 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:51 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:33 -0700 Subject: [PATCH v2 7/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBC Kconfig option MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-7-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=3248; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=mhWqJj1RP0LVjsRT3VtWySRs+UTs7hL4pCht9UF8zQ0=; b=sOz5JQJkzaPJCxTxqkvkSdeiQG9Ioekkp/cr6I56ZbEo4JJzatL3p2LLjxH4sfk9h/40qVxWB OEQki4PEQ2ECjcdqQ6LE0ponkjrcIiw/2Oy+cAKFQ+URoJ4CqY/pRsA X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183654_426661_D8C42A11 X-CRM114-Status: GOOD ( 14.56 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Zbc can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBC that allows arbitrary Zbc instruction sequences to be emitted by the compiler. The existing "RISCV_ISA_ZBC" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC or PLATFORM_SUPPORTS_RISCV_ISA_ZBC has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.isa | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 1 + 2 files changed, 52 insertions(+) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index e7f28dc44137..b7399f236bba 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -289,3 +289,54 @@ config PLATFORM_SUPPORTS_RISCV_ISA_ZBB systems that do not support the Zbb extension. endchoice + +config TOOLCHAIN_HAS_ZBC + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbc) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbc) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBC + bool + +choice + prompt "Zbc extension for bit manipulation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC + help + This selects the level of support for Zbc instructions to be + built into the Linux Kernel. This does not impact whether Zbc + instructions are allowed to be emitted by user-space code. + + The Zbc extension provides instructions to accelerate carry-less + multiplication. + +config PROHIBIT_RISCV_ISA_ZBC + bool "Prohibit Zbc instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zbc instructions, + prohibit the kernel from emitting Zbc instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC + bool "Allow Zbc instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBC + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBC + help + Add support for enabling optimisations in the kernel when the + Zbc extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBC + bool "Emit Zbc instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBC + depends on NONPORTABLE + select RISCV_ISA_ZBC + help + Adds "zbc" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zbc instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zbc extension. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index c8ec38b9880a..57457d15e9a4 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -68,6 +68,7 @@ riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) := $(riscv-march-y)c riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBA) := $(riscv-march-y)_zba riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) := $(riscv-march-y)_zbb +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBC) := $(riscv-march-y)_zbc ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS += -Wa,-misa-spec=2.2 From patchwork Wed May 8 01:36:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13658013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E4BEC41513 for ; Wed, 8 May 2024 01:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BJcyeyAlX7IAwyCY8z9UM+PUfCvhzZzuTZStquvGHsk=; b=PiG5JidfZQt3zc /6YK7Co8cv3KvxyhO/5dmya+XGov9tp6KeFYoR61WT6S9qdYEGlu6WznHjJaudKWQn9J+8/Xy5s5O fF/MnLqm9bS8dOzke4aCrmdgMb91sOw5PWu7aa0hg+hNxMZwySYhJeg+gKpLxeldBQDqpCywSrE6q 5vemOKABHZBiKaKj9bBE6ViA5g3vBORun4ekyOiYWe1kPrgH7R3r5m879d4NAzNEbKk0yM5zXw8py z4c33MVGd8q22q0y+MAwpY2Sr6x9kjOQH77nHZn2rxJbiQGapyTyDTZ+A/Xi2exIlwvrzpZHda557 X1uuHJxw24hQoH8iX1Gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEu-0000000Df6O-2G4F; Wed, 08 May 2024 01:37:00 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4WEq-0000000Df2L-2Y5i for linux-riscv@lists.infradead.org; Wed, 08 May 2024 01:36:58 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6f4a817f1e5so97103b3a.2 for ; Tue, 07 May 2024 18:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132213; x=1715737013; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HSebZNH2K21s8abZJ+EPitFsmRQfB0232RHZtpEHlvw=; b=Kl4v4DxPlg44EVRi9BWLU1VgYZlzn3ud+mOaqYCw+yJ1TEOWg7Nc5Q3ELenH6NQpfu cRLmAnvy2Uc4XJY5wsjpS0mIzy5kkO7hdvHlzyNs9M0d074chqYeSEJEezE2L7y3YCCp G8X0eODTTOkjITRVzqh9IRL4oSh3xmwpsVsAuYBH4qHf44KXGHAwFShdRWml1pyjQE/m uRsPfJMhlKcGMSxxCyKMiTFhvrxr2GShbscTUpGYS+rcX0Q45JLp650Tl+4SkNknoSTt Mr0zP8jukY9Ezk19pLu1fi2NaL63wS80XNDjJH/4joHXkpjUf9oG8KCVl3g6sVkh0E+Y 8DDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132213; x=1715737013; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HSebZNH2K21s8abZJ+EPitFsmRQfB0232RHZtpEHlvw=; b=JLsJdur6kx+2L02ejzaqU8lLFQMol086+Y2L5mM0wDSDAWdA/fuAOWs3V34M9iE6SS 35w+qt+usUyO1jBi/CzPr3x2Onw124f7g63x9Ip+gjZ/M7JvkJ8JgSZ3VkgtpZoGDEFS hxIi7KSuGTvn2m8Rw3MlnSFjnsTlWiSA5eGQ1JtPWUk0+lf8G5IJNwWa42SNKpkyf59Y hA1qvegDT4K05jKO3x3uXnO8hYrYmvpgqANQJLFOi5/VCXHqyNRa4XfobE+wg4tMRSla YkUOA/lTwnb7biOI65hcm+8PoZg+y54EnhE2artrQgYpdYn5a8ao9oo+XAz559oGc8VS 7kTw== X-Gm-Message-State: AOJu0YwngQGvXjgAP73Mjj4WH5HoyfAu8fV0gOleHAOtYb5qBVIZytxE cczDBi+YWmUBNXnK+B0J23+H+Nlq2So4IIIBzF7/1XxhpXvmYBGw0z5Q0Pu7vrk= X-Google-Smtp-Source: AGHT+IHg6ptW80TJdWpfJCJXopHCGmFJ2iuPtPmC3dzzLoosh6XalLDn4t3j0emDTqeCUhoduvuo/g== X-Received: by 2002:a05:6a20:1001:b0:1a9:c80a:c152 with SMTP id adf61e73a8af0-1afc8d763c8mr1324536637.21.1715132213554; Tue, 07 May 2024 18:36:53 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:52 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:34 -0700 Subject: [PATCH v2 8/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBS Kconfig option MIME-Version: 1.0 Message-Id: <20240507-compile_kernel_with_extensions-v2-8-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=3277; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=7B3II1X/5OVe4Mrr/uSiLQQPEgDk0UMK2lq4VVxpgKM=; b=BOORKVGo69HF+7q44TCG43/RRTkpsAJGBawNHVFpF9jkZ7wAN2u8vXOHTvuJ13Qg1B+/ol51J 6rief9SvltyDHEUzuVdcAQrC2MGCzumWPDi5HvHzyzoB8a1cNpdR4Vo X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_183656_780519_15BF3EB8 X-CRM114-Status: GOOD ( 14.49 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Zbs can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBS that allows arbitrary Zbs instruction sequences to be emitted by the compiler. The existing "RISCV_ISA_ZBS" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBS or PLATFORM_SUPPORTS_RISCV_ISA_ZBS has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.isa | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 1 + 2 files changed, 52 insertions(+) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index b7399f236bba..60ae1bf71c70 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -340,3 +340,54 @@ config PLATFORM_SUPPORTS_RISCV_ISA_ZBC systems that do not support the Zbc extension. endchoice + +config TOOLCHAIN_HAS_ZBS + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbs) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbs) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBS + bool + +choice + prompt "Zbs extension for bit manipulation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBS + help + This selects the level of support for Zbs instructions to be + built into the Linux Kernel. This does not impact whether Zbs + instructions are allowed to be emitted by user-space code. + + The Zbs extension provides instructions to accelerate carry-less + multiplication. + +config PROHIBIT_RISCV_ISA_ZBS + bool "Prohibit Zbs instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zbs instructions, + prohibit the kernel from emitting Zbs instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBS + bool "Allow Zbs instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBS + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBS + help + Add support for enabling optimisations in the kernel when the + Zbs extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBS + bool "Emit Zbs instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBS + depends on NONPORTABLE + select RISCV_ISA_ZBS + help + Adds "zbs" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zbs instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zbs extension. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 57457d15e9a4..80ff8503196a 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -69,6 +69,7 @@ riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) := $(riscv-march-y)c riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBA) := $(riscv-march-y)_zba riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) := $(riscv-march-y)_zbb riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBC) := $(riscv-march-y)_zbc +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBS) := $(riscv-march-y)_zbs ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS += -Wa,-misa-spec=2.2