From patchwork Tue May 7 01:40:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656159 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 4B445C25B5F for ; Tue, 7 May 2024 01:43:04 +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=cL72r1COQoj+4YMilbgl+wWpxA2cgRJ6X10hvjezyaM=; b=KMu8Qm6sAJ1TeL aI8KJ6guw9JJf7KvSXpzGGv8qUxObD0okPAyhrUgUJfCJnMG9V0s2KTEr/+OqPJS/o/a4wiZR0UME Vsyf/ZObSYmIffu3jZKTeG8IudfRvvSojE5JVCqeuUcwLU6Sn8AQ4PxihD7V3NKFqZ2bB3SbmXzHJ YOYJsAdwnBuRzz9FCluvqS6pFAbdta/Ev/v22+fIdWi0ah8DyMdbY+rmLJLBWRXQ+uCAdzdSYwSA3 OqHW7XtZpcQwqtwNM7pJfd7uOtF/fLqkLKZJsG1AOx03/7nXbxuJi6XEh1QWnXlg1sjbrW0/UNJmx tiREqhFCss7i8oVt7LWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49r7-00000009H6k-3oZA; Tue, 07 May 2024 01:42:57 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49qz-00000009H0h-3In7 for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:53 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2b537cd50f9so1335331a91.3 for ; Mon, 06 May 2024 18:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046161; x=1715650961; 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=gF8qGaJ1aJzNvgYvOCba3skq1TjRznxQuNnEFWLH5Zw=; b=NSRDT9uucBn3xDhOrNHID40yFgiGK4M5JQR069vf5bQUzIk7HjoL3u4PacdShtNBO/ Apdh/FOg5yw/pO9IO5PFSoAx859ubcfnl6SPapEIC40GwODDonLpqS/RNzldlmmFDrl1 ecYv3jM/6wDS4F3Ph7BmeMaWW1jpnHKpThkUAiqnLGiAnpBtHkvBsXFVqCN8eFRz89iS 71T/hknoSfc7WqFl6TUOl02UVV3g25Kr0I5YPfVU7XN21jUJ0V1gqSu9/71Ri1SRUvad /MZB7u5Zu5QDqSlKqCIqw1E2UVNh251Sm7dV1k0Fn8e9eAd5P88yK+Clbup7zpM1Xt8d MRbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046161; x=1715650961; 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=gF8qGaJ1aJzNvgYvOCba3skq1TjRznxQuNnEFWLH5Zw=; b=r/H8xYdnEYiM7G4vvCP9I2mkM6mPCMLc9CL2eHo6RhZzTAq3QUCBF5N84xetVjfPuw er/KkUIl1j3EP5D8JcGw7MOsdlyYL1IcUXiKQPS1C+5EKoX/QV9lvSxIo8VLRzL1z9Ys UFtJJPaSACYEsB8/SohwHtqDy/KtREvjKfr7wu880tlHqvuuUCbLvU/CDQM3hV0Ji0UF 2pP8iAZ/jCzrpF4tjYIhmH/PSUc46VbPfq7Hu+DULYfEJQmhCtSHbDkKXw5zx6C4GTd7 +9IfTyr4A1DDvZ0gOYhkkj7Kh6EGs8NMVEdQ/N27Du6f2hToSKTd7/Ii4JQqt/QllyXB Pd1g== X-Gm-Message-State: AOJu0Yx5pRrz0C2k5ZUSKDrQ8Epp/qCVBBvxUNVNV3hPd5SSB/n1GGDb ZUvS0/ph+KIAhMC4yAfw2M+x9ZPws+5nVrwQGPxJLKk9C07FusB8AKw+phie+nU= X-Google-Smtp-Source: AGHT+IGpzHifmpGiAxjTcocbBFK+V7WiJThQ/SJeU/Miqz5kdTjCFTH4LwBRLMK2doOE8zu4aQNSJA== X-Received: by 2002:a17:90b:350e:b0:2b2:7855:da05 with SMTP id ls14-20020a17090b350e00b002b27855da05mr10460825pjb.26.1715046161112; Mon, 06 May 2024 18:42:41 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:40 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:42 -0700 Subject: [PATCH 1/8] riscv: Add PLATFORM_MAY_SUPPORT_RISCV_ISA_C Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-1-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=5775; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=9E+2LlRyJf3rtGlOBhbopLxrTNkU6Xw7Fp6ra7sa6aw=; b=k/qKiLIMvmJ90rd1YTXngnEJRwKO8kGBQZf+APAC5CZ1sloS8A25+YytARmKTTvmNP+IkLjri cazABYZHlYsDSt+hvd03k1xMjto5tOexlRaM5aKXwgjWVr3MEZAkbVA 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-20240506_184250_285833_6A0612DD X-CRM114-Status: GOOD ( 23.24 ) 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. 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 Tue May 7 01:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656165 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 77CA7C25B5F for ; Tue, 7 May 2024 01:43:07 +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=DlegbwowrLuehBaYRzsE5ae05hyP6z8oCO/ZpHyrcbg=; b=AdEEo7a//7mTgK +XHGWjxkf8I3qPv8WkD9O7J/TMoE7lw3H0b0ZaVkbLK8N+NrA8xOUk/8ONruZIsBvIryXCQ2z3CmP xvN4mjXVvkGMozLWt9plmpd6vLxF4Mld9/pyO97b9W1kzHXQqmyPtwbPLDR6HFalvBmV3TJSa/1tg B4emi4halwLup58FnRhmH8duMju8Xu1kNYz/l4Kf2Cr1i+zKut1CSaXVrdQgYLKX5/CfGmov3vUZC gdGMbTv7gYWdEAQDeqErwzLa59UIhNAKkLfXYgla3NFssVQvM061jD/FtYO1QHoAF+evnH4BXSQAR uhAtMAEVG6w7AoyMu8cA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49rB-00000009H8c-1523; Tue, 07 May 2024 01:43:01 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49qz-00000009H0o-3FPX for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:54 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1e65a1370b7so23561935ad.3 for ; Mon, 06 May 2024 18:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046163; x=1715650963; 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=H1SlwHEQve3XGtUzt1D2PtY9mRWz0p9lvDMiT9rqTMQ=; b=chplnBD0W54SV5bqdSerQ7fkZ7BXXb1x9PkgH4yCGlrkkKB1nKapje8cTBRsbq85P0 lq0rIbnUGL1Yw4q/x979ezQmZIIcQ/Z6lAjqd+n8PHKUmYcM/czY8NK+KQnk6JyL8uju ws1k/74zoJ2R3Ohhy4yCEWvaKt6LA/I9NHMxaaRvbfENCNTd7bPmgPWcTlEGw8ke+r1M n8lMbhoL5CMqarfJPSI2Hc0UU3zAgNqQIswgrbG+yQKTAKP8K8tokMn921MlNhurIsx0 1Q8Wul4ppXRw3liNFC1vVPBkKDKeyvPXJLAA8BmisYrRbAQWJ7IGZduwl9vSONeiAUeJ Ae1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046163; x=1715650963; 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=H1SlwHEQve3XGtUzt1D2PtY9mRWz0p9lvDMiT9rqTMQ=; b=CpRVTqIE6XkiVK7uYl63QZxvfrLGY9opRBpw9Pi5vnIHRfWJrRjbdm/da4d3pa8+mG FQBKXLE0ZBbB3BuPfhTUCsnPdAxzfBsxQzJ38mQjBVcI6aJpcR6JvzgniVC3RhidSopV 8/1UBfuOXmcAcok1G8BSKWGhyZqquwr60CP77iRMRWGjKYiOnzjJfPxqF71jd9dE2u7x dWtRc4712lzyzJFbeIDfsT66GCI7vQoU1BxgDegpyyvC0nH4fjQ/26aV3iXc8CRI01Yd HK55VAobqzUwlpTO4GeQhuy+f4k6m86KWqS+Hwl/zPw1RypXwSNgt/8oqYqZgrYyqxDY v9uA== X-Gm-Message-State: AOJu0YxZIskw9sPqJF7JYnvUFfdbzESWcYHB8JVCwQ/Qsc2R94wNTcmC viYxfNKJR/nFazrLVDl7STks2HvGAFkNGyA2LuTI040iV37uflLYw/Gfm4IBaMg= X-Google-Smtp-Source: AGHT+IE+kH2E8eCWhpfbYai+ib3XAIvK3eLPva3AMWLlSeK8GjCXQfE9rI3kRhkOuiQ/InWmIFNnZw== X-Received: by 2002:a17:90a:bb92:b0:2b5:258c:5f10 with SMTP id v18-20020a17090abb9200b002b5258c5f10mr5030446pjr.30.1715046162600; Mon, 06 May 2024 18:42:42 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:41 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:43 -0700 Subject: [PATCH 2/8] riscv: Add PLATFORM_MAY_SUPPORT_RISCV_ISA_V Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-2-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=16227; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=agm7J56cL8mYhZaFD22IJKlosZSuCxUEk3BLHORDVBc=; b=rfsxkrzyXrHGtjN9yY8m4rOIS5Sh7mt/xLFcnNyakq5WIfAzBHPdwdXqbH1hC4dJHymFnq47R xuqKc/7KojFDXXUhuVt4LTbmOoJ0K2avl8lJ/Y0iOMS46DWdRuOwt0k 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-20240506_184250_295676_45C05014 X-CRM114-Status: GOOD ( 28.70 ) 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 and "v" is added to the kernel march. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 54 ------------------------- arch/riscv/Kconfig.isa | 85 ++++++++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 7 +--- 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 | 14 +++---- 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, 124 insertions(+), 78 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..f2120db6ed92 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -66,7 +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_RISCV_ISA_V) := $(riscv-march-y)v +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_V) := $(riscv-march-y)v ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS += -Wa,-misa-spec=2.2 @@ -78,10 +78,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..af10715a63f7 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -163,14 +163,14 @@ void flush_thread(void) fstate_off(current, task_pt_regs(current)); memset(¤t->thread.fstate, 0, sizeof(current->thread.fstate)); #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); -#endif + 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); + } } void arch_release_task_struct(struct task_struct *tsk) 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 Tue May 7 01:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656158 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 D31A3C25B10 for ; Tue, 7 May 2024 01:43: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=ccMOj+RzHwAB4UpwUothJJvZ2ioWRFyD69IMK0xczLM=; b=eoa4E5mwp0+3Ws xjilUG+tZfvqaUnPLypTLHorDsO+EPFi6obCWJ2R4L7Y+vvLwIbOgLtCjkD4GuqlGLbnAvf84xRf7 HCY5R40W5/E9N0AdYuNqUTnl/lIkLRcjHSw/4PyLY/jkjeCLBj5uskD7o72Q8zKye+OCcN63nZC92 KZIvYadExrw8VLVQSejCbBSF/3XBDR+IeB0PN1bzNKkhkm9gkq3yB8sbXHv3dvH7wqUMdlmSz3xjD /0Uj2on89Jri8OP40QuOvDc1MkmoJSJVit4B/RbtQk2FpKnEzBqAwF2HWDvFF0LPzWXXuJX/CFIum lh0sKbynUiDkVl5xTqSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49r2-00000009H44-3s4n; Tue, 07 May 2024 01:42:52 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49qz-00000009H0s-3DTI for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:51 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2b38f2e95aeso3374566a91.0 for ; Mon, 06 May 2024 18:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046164; x=1715650964; 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=WABN/DyVMubZMdulfTheMLTH5TZr96UUGzB/KSHHr2M=; b=OWO207AwNpG9C0Lt/JtJVmxqa8yeLR5+we8MrZg+iVgpvDEyv6Mhem+25hm26vLhqK IvAz0KrqqoDHYxRbl24rzNiAA50+nVr+E8FM/pE6oEEtAS1AgRHNr5QkwIJ0W4RAB65/ 0at3r6c+8+tRNFtAjxybSo1bYDkV1wy8L6Nzo+ikiJGNXAy/2mYSNiEEQt0rhutnV+C2 Q7VY1islM8Wp52X82q7tN4Un8omsin4ep2HFpFrQikJ7xnWuCR5ncWfm3xeGRoSpoUEY d0xuu2JfEDxvL2bLnt44FWltFeeikm+rLGTdaiKIF1gU6T2P8Of7dcavz9V4zONEEHjb 1JAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046164; x=1715650964; 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=WABN/DyVMubZMdulfTheMLTH5TZr96UUGzB/KSHHr2M=; b=M9UNZVo4+V4winDn6WpJXTGsefGMLRr41uFg6w1sPqtBNcUuesQ+JsXvCGnH84EiSW p6tJnKmy4o56ClcHcc+LPWPUGzDl1ZjmlZJt+v6cdCLPm7JdGvDEd5OdystSmiaPLVWd YfmAfq1N7DWyl3sgJQrLRKsHjusmbusXLYbUXcWb2d5vSoutq2UTku/kyEV8XRZR5v5D WvGrkbnpeUyLMjhxSmIWFYDDWYLfo0Suszlp350yffRAKebarpzKMRpVnpgMuHRF+w01 KsVonRcV6wvcVsG/M5ePIAn5pVkZDXq4nlBL/qEtJ0BVZ8rlGadQjTUaq918cYwUQ3P/ uE6A== X-Gm-Message-State: AOJu0YzP0Lp1zyJzkwKbE2eiXK1hHhrUXWih3sghde1Hdm/3zlbFDk9O 3GO632Z0JziDz45LkhB4YijfbbhlNeTi6g7fC1/UA7s6XMd2YLz7ichMtOtI1Ck= X-Google-Smtp-Source: AGHT+IFZ1scUzbuEqN66Ol90xyUVgNHeMyyZi+HIv5KQYsgIR1rnTKs0egQjffSyS6hOuZPi2utSfQ== X-Received: by 2002:a17:90b:94f:b0:2b0:9544:59e7 with SMTP id 98e67ed59e1d1-2b5bc2c9156mr1704507a91.23.1715046164132; Mon, 06 May 2024 18:42:44 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:43 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:44 -0700 Subject: [PATCH 3/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-3-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=4952; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=qAYZSJKQfo6KGBAG143+WCG6TYn1nYEXzCXt3LEyG3U=; b=AvAZPB6bKKxnhol7r99rPIU1Pp2DEmoyg2c6T9E0ATto3yAcQP2LL90sm7dlTt4exCfuHixAo ntqpY+6BJPTD2LRKfeuz9WcTRYfwxclkgO17m1GznmGptTENuDnO/53 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-20240506_184250_271086_DF6246D5 X-CRM114-Status: GOOD ( 19.42 ) 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 previously supported config RISCV_ISA_SVNAPOT has been renamed to PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT and the config PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT has been introduced to compile a kernel that will use svnapot by default. Both of these configs select a hidden CONFIG_RISCV_ISA_SVNAPOT that can be used to determin if SVNAPOT is allowed to be used. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 21 +------------------ arch/riscv/Kconfig.isa | 44 ++++++++++++++++++++++++++++++++++++++++ arch/riscv/include/asm/pgtable.h | 3 ++- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c2e9eded0a7d..9c3a4347953b 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -63,7 +63,7 @@ config RISCV select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH if SMP && MMU select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_FRAME_POINTERS - select ARCH_WANT_GENERAL_HUGETLB if !RISCV_ISA_SVNAPOT + select ARCH_WANT_GENERAL_HUGETLB if !PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT select ARCH_WANT_HUGE_PMD_SHARE if 64BIT select ARCH_WANT_LD_ORPHAN_WARN if !XIP_KERNEL select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP @@ -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 Tue May 7 01:40:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656163 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 1465AC25B75 for ; Tue, 7 May 2024 01:43: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=g91jZt8yERTqeM2BTva+TPAEl1G4QS73mnsji9WDO3g=; b=Q8RX8mHlmz2uXn C0sfVgWFJPHq9NPBOLM/sXmocDruP8JznltxaFDvogu7tF81nbn3NPzmCzhqYZhApoSGOz+CSB+tv wNrergl91762mPNVG83PD1DX0BXXnN1ovv6Tu+qzKDVasr91ZU7ZcTmFIwlup0xoAytYSXuPJaei/ abhvGUSqPGx72Ahh+94Zf8bt4N2GND1pzheY4Z3WJ0XBO0U2nljliK+yQEByduMoJMk3nScGTbD7f xXB9nTJasJkdZ+BxF9FVBkIwOz2K4dHXuMLY+dX8cUexMCVoHmBxuM77G/3QjEyLpVHFUbKtdEGcC xXPwfB5ve/R0J1Pqn+zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49rA-00000009H83-1Yud; Tue, 07 May 2024 01:43:00 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49r1-00000009H1A-0RhZ for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:53 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1ee42b97b32so9312355ad.2 for ; Mon, 06 May 2024 18:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046166; x=1715650966; 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=t1rtoP2W5LhxJ+J8dI0kYwFURphSK1JVHizOP2fywoc=; b=0zqR/RIzG5QvGcJgG2sWn2kBSFvoBwZiEKog8oLlHw5y9BuJ5UyLbJkWK3wA2zQ4aX /ig9VoK6TnI56KwYrDUQWm2i+SPK3i0jlLfzxDlg7Yd/nK+dHI4pkHkY9/d0ZZue/L2o bs4uKnGHVq7DuRXRxHe69De+HGxpJGKSPL0iaqmoPK+7vEWvEf3qh5Hf0HRvYoSH4aFG gorFansHBSmMRi59W+f8hekMNv0FoSZwW9AZBUPTEkd18ezaGA8V8bdVd53Nr6LPXov8 qUG1SMM8MFAG9XjPo+uDh4dLqEw9zfi/Wdw3G6BoZLyy/qAyKGbMKnhgScoFgG42Ycz6 cuYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046166; x=1715650966; 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=t1rtoP2W5LhxJ+J8dI0kYwFURphSK1JVHizOP2fywoc=; b=BNpR05c6OCwyoG8kpIMzkUVAHPUARQ376cbxhdzdcAJdHS+vKz1H9H7pfXYpmn50Qd IZjcCVyBvABCpf/ULAxj49zGvrZgnzjUU22WS7rLVOg9ZXc3bZwJJOF8wvOYpqGZ4z7b J74m/MiMRPiDCD3LxB20HH5ySI7gPmnAmsuEFM+ryQVCBP6I3RNbGPVzAyvyASNIB9Jm cbchmIu+L113gkoRMgcmFoKmrh5ZT6DWg3sKJSpNEVizfCylg1kLdJAL0yt5LGxlbXj/ 13CHIbHwwaDi8U7LBcs86z5sTerLCsAmto90ditvbWesvS3Kmg7TQdSinECAXeZK1VeQ L+QA== X-Gm-Message-State: AOJu0YzpHPnS7x8fvWPlDQ/VPpxR8PPoJ3vmz8V372XZCr0vOnipqVaQ Zmi5r37iH1nBkABPl4J4r3OolsjhsUdpcBOKzgShYHMRdGwKJ4L57SWYn53F8Mo= X-Google-Smtp-Source: AGHT+IEvpciP1sfAIndVjOWdRz7vLHFzpcSQrwQgsqgVau2eSxQs0m4E49rHQF2sOcXRyHJSXo6dDQ== X-Received: by 2002:a17:90a:6fc7:b0:2aa:b57c:b178 with SMTP id e65-20020a17090a6fc700b002aab57cb178mr12019684pjk.34.1715046165806; Mon, 06 May 2024 18:42:45 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:44 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:45 -0700 Subject: [PATCH 4/8] riscv: Add PLATFORM_MAY_SUPPORT_RISCV_ISA_SVPBMT Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-4-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=2246; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=a5uHrD6/CgdRcxiHblwyx5kXSDkE21WZp1cyzlXEWj4=; b=bnTpAsp3Zw5Pq5X+mO5DVW5pxHHKVy8FUw83Bk2bzxERC5XixN3igHc8XRzJzdAfFDd6F0ZpQ qURkHGNHFlyCgGYDPobEFSDYFLG17QZXDtd4VvfBloYF51Nv4e0BVtE 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-20240506_184251_183080_9C6EA0B0 X-CRM114-Status: GOOD ( 14.12 ) 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 rename RISCV_ISA_SVPBMT to PLATFORM_MAY_SUPPORT_RISCV_ISA_SVPBMT and move the definition 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 9c3a4347953b..22303a3ab59e 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 Tue May 7 01:40:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656164 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 A9029C25B77 for ; Tue, 7 May 2024 01:43:06 +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=Mtlb16Yw8+XWxydbqYb7aWvZLt/07vAKOfLeB8R8DU8=; b=a9prGq869YGofy cKmHD9NPXCPrKSZE0CH5cQeQlzEHrZRzhRc72bhx5mCRNjk7uTAlhITxHt2tu8N6c9MnH31pMnhi9 wEIJuFkmB9OXjlFUVeQf5CKFE/AlaAjGz7WMI0PWmjGqpn7/Gotqf4Nf4PrI7vhRm+Ad5UwXNNuaq vNGNh/ELu/RrJ2lIkunnhgjbX1Aq48Ffq/XkblLJRhGrKcxu/iA1LwRcPedKIGQ+O46XoibIhS9yP IKZuPMBYGZ8WzfNxcvUcKB46wB/PZ2gYVBmoWFaNpKdkdhUGj0K8hgU8l8N3YhTn83DzskoXCKurq n6SJNHeIRB0fAhyt2gbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49rC-00000009HA2-3af0; Tue, 07 May 2024 01:43:02 +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 1s49r1-00000009H1K-27Z3 for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:56 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2b36232fa48so1830646a91.1 for ; Mon, 06 May 2024 18:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046168; x=1715650968; 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=DQ7EdBQ/6M4rSNFMLjyTKcQvY5gDVj45XBOC4QQu44U=; b=V273lKbIsFeFIORwFIyj0JrjSFK0Rd7fUdujcabVfZyBNI8XRphaegOa/Tnv4zLxai h1nboPKJ/+3L0L7wMeFEZ59ixtjSpFVh7K1xbP/lazRzqh8pKpYRAgbW8tkYQwoIOxVa qYKuozrqufvPA3u4Rx4RgRrpHJ4NLJGT+Yc3Nb1HHWhkmlB5kVX4IbrPqVAB/6JcOG4K 2gQs4XombHFd5KmRkdNHLGq8qwncpLN9Zn7/DlbVI2YJo1yrMf+O0MMITxDj8n3JVgz5 TLxWzGV+tZ+ecjE32mRfCXYbuM+efq/XGajcnmByp5z4OH6Uw8PqdbEiVNwKI+4AzapN tU1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046168; x=1715650968; 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=DQ7EdBQ/6M4rSNFMLjyTKcQvY5gDVj45XBOC4QQu44U=; b=C+DsW2y6VX5hy5a2HDGvVXsvT09dn8vmPgWO/ZvGWfei+Kbsxw5gp8DSE43cHKqe3C /jJwnC3tw8Pphk9WnWc1GnGXnXuMNxENaI287VGdjMX4mohJ7+cpMX/xLkEj/5TkzP/X 2Ba2tgoDNgyoAtbKSbng/7QxBcg1AzCC4l3dvHHqI+WjXbr70SLA4/zGeOON36dvNxKi ARL+ErCnQU8FjfzKcDspCETTC5Wn5RrbDpE0ZV1btiAuHzrKL6SU2y5Qa6hnOdyn9Fvv Dg1gCiByjIee2/ZIhKX+iIpRgkvEYFS5f4t1WLwdekB08pnTCa5tN10YFLQ5IoBNWA0y 67rw== X-Gm-Message-State: AOJu0Yx150h93R5yKfJyl58mxI1Wp4jGqkgGFOPWt2ZFlBGsNL7ukgwd X/ZdYEVpNLaPol5FZuy0rK3GfUNMqzDtsEwc3xJfNv6Jy7GBwMSxR2IEH0Nh4MQ= X-Google-Smtp-Source: AGHT+IG74efm7SCihJUa+3UxSqiFR7Y+JP/oI05ti3saBVyRnzR7LLXjViia41Gnlo5YIxHxcbAIsw== X-Received: by 2002:a17:90a:c506:b0:2a7:398:c943 with SMTP id k6-20020a17090ac50600b002a70398c943mr10034219pjt.5.1715046167251; Mon, 06 May 2024 18:42:47 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:46 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:46 -0700 Subject: [PATCH 5/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBB Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-5-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=13922; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=Gpo8hfh/9+N/iqKYe3MCveS+qLzCuqVg4e2wcSoQx+U=; b=m8/HF7kazTy7o4ZfgsZjhlNqH+CvzkHBhbQ+vWX/D63rJN6F8KOeV0tLeTu497v9kqzLOE4qJ 0adciAodBPdBtQs+DNs794X9bZdrWBWPzNc44KflkwEKvt4SQqMaFeM 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-20240506_184251_594823_BE106EA3 X-CRM114-Status: GOOD ( 23.40 ) 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. 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 22303a3ab59e..685092045447 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 f2120db6ed92..934e20de576b 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -67,6 +67,7 @@ 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_V) := $(riscv-march-y)v +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 Tue May 7 01:40:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656160 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 D32F9C41513 for ; Tue, 7 May 2024 01:43: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=FITktW2B+CzHd2xNaO/nDJ7RvZhUNlijqsDobvPahrg=; b=V1tMFNdJBpbDQE 7GhelhVK9j+Hr5y++LZBQIiUk09D+xQu7g8MdqpAzRXCnhR81y8yy+iPS7VdMcnCZBzl9pe4EvVv3 Ez3w1H5k83EJyiqLs+MECRqU80mQOgSgjsgCJCcPVlDN0PaOyVJxvdIpaHrVCrcttCdfZBiY8Cfwp gL3Wm/gkRSXQfjGhQQGOoBUY5w1kgunf64esHf6cs7tXgKrlD+QXsm4A4xAcnbu+v2qu9VjAKf1wQ fEdTR8/04b0YmC3mOaxWtRJ6+ClRRUFy9KnIGzoCAiOjDLSkNZBf4JMhY1vgu23IMdtW8nQjq8O+5 7ZJKaQNB5u0mIUcKEqjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49r8-00000009H79-2KkR; Tue, 07 May 2024 01:42:58 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49qz-00000009H1Q-3k6J for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:53 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1edfc57ac0cso12948155ad.3 for ; Mon, 06 May 2024 18:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046169; x=1715650969; 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=QXKXTMdz9nysIbdQG1zSA/joXoCHsq9b8pUEu+GCNMk=; b=wsTc15kHVcM/bgagqQCheYYSD+1X0IZa88OGCoQ3bET6rD5GLR+wwH/3Lf17tYCuj5 7WQcM4R6eBT5FTxm8dSX+hc+7XnjL0pNvmulinIaGdf0TlqQt7zLsmtuty29rTaCWWfW WhCcQBu8U9djgLMoTgRQm3sAC9EqZLf41c9p66PJYuMgER6AZ9cuDyfzU+PfZ+rbJAgm ble3GwBvr476cCZtthR7XEHYaReyHTll0bYqru27Xa5KpFCagccgQukFnfj9n8H6ormM VgghxW+t+fqhnbiajtcwPX1MFuBZSxUOnZRfydn1En9QsTihaNbPD5End28TBju9X6Gj DTUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046169; x=1715650969; 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=QXKXTMdz9nysIbdQG1zSA/joXoCHsq9b8pUEu+GCNMk=; b=KDevqHJgJqLMcB2S3MxsroLF8ppuKFNq52BxHYtrkgG5Graoq9o/+YSXxtFazOUYz5 YlDjvZJ7i/90fHRec1KAo1I+yXDfYMqEAzlD/KIjupU1qKTYparOZ/R1I4lrTh92BI6J tRbhygjJyHs2njU8+xX2q8XPNG1ukUqIghoLymxhpr8UeHYCIbGkGoN9e0a/RgScwLrq nCUnZjFnBlxDGCBvX3msdle7biD/GlORvjnjeDIDcrjNjgTX25dJ0OSHG1HbL1u2SJ4N oGQJdZfnxXtZvxAjCDo1iGpM3XMfmqIJvHXIKhSRQLAojTnaZ7jlhX1U+JqgPNQa3jN3 ca+A== X-Gm-Message-State: AOJu0YwyIDeu0DO8NzEGjTTm/F/1PzE3zMHI8A6XuHPFn7/baRFq0uWU wfEERhibD2p+iMEto2gx2CSQ0mAqjGQ+DFqs/rmMuQxVglQ9CpYgy4zaJzERHdY= X-Google-Smtp-Source: AGHT+IF6/gGCNdZiWcJ7b5sARR/Cl9CrTBBYDbYOTX+T8auqpQE7eGTz774kKNo5c4AGtbXQtPQoWA== X-Received: by 2002:a17:903:2344:b0:1ec:2bca:5aa8 with SMTP id c4-20020a170903234400b001ec2bca5aa8mr15677736plh.6.1715046168896; Mon, 06 May 2024 18:42:48 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:48 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:47 -0700 Subject: [PATCH 6/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBA Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-6-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=3133; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=eQ/auliW0EgsQFJFA6Mf9gTsQnbW6DmSQUwyvcEerUY=; b=vVbDWRSZVIHXc2jHg45d5wTT9RTY8XfHDD54NysNRPTWOX9vMbhQ8oCTTttPVmWoqwt9Opkb6 cUbZF8aoSHaB+t6aIHAZdk7a8PV5YfPobXzlJvvLJWdyZ9gtfm0r4tO 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-20240506_184250_509817_B3343659 X-CRM114-Status: GOOD ( 13.95 ) 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. 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 934e20de576b..0ab4cc5dfffb 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -67,6 +67,7 @@ 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_V) := $(riscv-march-y)v +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 Tue May 7 01:40:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656161 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 C5F79C25B10 for ; Tue, 7 May 2024 01:43: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=hs6EznmB2BSB8uh82NRk8ciQUPonBDzfEEMwDaCBsFM=; b=sdsQdR3sbuTcJo P99aWpLfntI37X/90u92bRiOinraGCde+qgZkx3dK3uOk5GrHa+gVDUN1ohDCFoSRWO0PtgNShL7W D3bLPSVFMuga3xY8nlI7iazT1VTG1Dlcq0mUxQFuzLoAFnVg9ca3Gr+3dklku6UZ6SZDbaQCm9Dg1 Kq299R3f3o9qpxpJi1V4ip3vero2gMzWZvgcuHdDiPQvt1yXRE2uE64OpnbtBHkjfLWlppp6UyXB4 5CSw9XqeOPlXTj4/xXU9VJIXoYNARlRBpxuakGf9fOHRXs2OG8fDAwOH7hdel+uvDVc6Y/ii3XtMJ JA81r/umyY1CrEvdlf6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49r9-00000009H7f-1QWz; Tue, 07 May 2024 01:42:59 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49r1-00000009H2e-0oZe for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:53 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1eb0e08bfd2so13746045ad.1 for ; Mon, 06 May 2024 18:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046171; x=1715650971; 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=xCTzqIps+ZkkY2OB8nLwr+KIJ7vqS249dCWRcdyLtRQ=; b=cXiHlch/N5S9rkmlvrbEjJCaiUlJccGmaetS7gA4F9A0bXg5UW73tyN6RUwJDjWmRl OVDaHO4yw0iukOnUZ5Fy+vwa76nYc9KAhGN/z4gGGPpAggfJYB/UUQTsQWFsXZYD0fpX zIk4GBV87kmLeYIQJTcPH+uft+i2m2z3/qmLqBAay2fYtyYgiMzBXxB3AgjYsU3zlNE3 VK0JYN5ypeJdG7NZB2GjCqWlQcDwL0dHarPJ3ycartAQUhL6x7J1CBqdqxsG80BXPRi+ B2xbTip57q3xwTjWtquN/tz1Cb28jASanejGHHyO4Ldh+5/Knlp9cIaj1HzYrZwdfthJ SGJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046171; x=1715650971; 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=xCTzqIps+ZkkY2OB8nLwr+KIJ7vqS249dCWRcdyLtRQ=; b=vRSNHFQ0AbrqZi0y2qkwgdzjV3C83tcqnrgwaVbTCB3MNGi2GlKsQwSnwanmIJXJMl H76uodDcCDEdL/muCO7cIq/nk50cFHEOOVRHgdPD/R1Fxj32jAb7TGY80ImYY+fVa4SF XBEcDNDSfFvy9N/5X6mW3SPEitm7kH6ejpTRBxT4uauvTR9W8dqclxrEMH2S55ZwuOA/ EL8F2gErOs+OSTln80QnFrALxSAw89xC86z/8Q5oNvRmLkdXz96d6eEL4c0UU0JTrtzO Lr683y7c/qsNeGEArQC8cYv3N6tocfDCiftDW7BTGslF/CN43twGPUqLEZ1ucfDh9MlS mFXw== X-Gm-Message-State: AOJu0YwelcP/1WIOv01PRNtKz9fy1Cj32hQcfkHo7gr0OkBAI3Dih7de o2c8yvzSJBBTvIph+yTBHKLmRCwaNVIfiDlaa+HWeHvcGZxAxpDvozqLJnKTtEs= X-Google-Smtp-Source: AGHT+IFcNj1lxhLTwHPlCK4GlMUj4Rw8hbj32zTfxKPPgwKugeGp2LOBvsLjEjT1lRXdW+vSCTVKLw== X-Received: by 2002:a17:903:2b07:b0:1e4:c8b3:dbaf with SMTP id mc7-20020a1709032b0700b001e4c8b3dbafmr13911614plb.33.1715046170305; Mon, 06 May 2024 18:42:50 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:49 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:48 -0700 Subject: [PATCH 7/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBC Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-7-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=3081; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=yS+zKcRdHLA3uaeN6uPi5O7/8wOCzM0M3jPlowSQyzw=; b=xjEaBxuq9R3saXEJW38LF+s1vw2phgumpvArnblkck0B5vgdDCTA1Fh0JjuHtzXSFyGm8yXBo S623mMD7ghMCkD+Oo1IlBznEsB7pihM0BXEqJS/GNaia3IW3xpzsUVf 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-20240506_184251_275379_D1B6D4BC X-CRM114-Status: GOOD ( 13.18 ) 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. 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 0ab4cc5dfffb..30be0fec976a 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_V) := $(riscv-march-y)v 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 Tue May 7 01:40:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13656162 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 68755C25B5C for ; Tue, 7 May 2024 01:43:06 +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=uj8e15UR7pweCsOH3MWOLs0tuR2A+XI1nZ8eTDgC7ak=; b=eu9yYbkmtFumGt WASFMnid+Om4fC1GmfIR5qpys51yTcD/zXsL70kb2BG84zQ/qlHUL+I4wkFG8u8vp59zsRpNWO77S nCEjJN7N/tml45/5NrPpqaz+1DE/MURISCBpk7du8REGcrfAN5jBCh6IK+uQ8i5Jr9CFbNsrZuALx ZpROuWP/cB96Vx+d6ynlNqu1gxVjzsq2oKZVC1vi83MBiuPV79rMyDs22qVkdkuX9D0G3Ckm1letg uEuKbXI2Q8Hp32X9farGDWIJJjeldqQAbxwwRfbGTkKMsLj9yDhhy6cVR34tBCFqW00lms2S6Qlcs zxc2GJgCEqaGNsgPwHjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49rC-00000009H9E-0AbN; Tue, 07 May 2024 01:43:02 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s49r2-00000009H3r-3F3M for linux-riscv@lists.infradead.org; Tue, 07 May 2024 01:42:55 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1ee42b97b32so9312705ad.2 for ; Mon, 06 May 2024 18:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715046172; x=1715650972; 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=Mrbuhf8lERW/x3AUUGdC3eD15JM+519sglQ52hQ7AhA=; b=YUOpVyFis4qV4q3g/83KuwRqHBwX1uXz4deGbDNGMc/lif+BFDLOWf2UfVwkiCiFEb 2YIlY5ot8I7ifVqqGSLlVCv/ySoejgBmIyTfv2CoOBNjfJ3uX/nqEYKkmN+zDy0An7Ij cp0E7Tr5bbUNKoC2QdqumfV7uDOUQsQXSMNf/jr7t/elGS053EZrmXrw9Y9vZFydT7aK GYWWAw64OhhySkfMdZzI24489up09Lz2SXPErOU6Kwa5c64gp8D5IliHhAkVAeD6O8FU fHTZ5oPVrkfiIOGfy78PKmmdgybfh7DhXLzeaLKfsyvOdnDw7IX+Rk04lQOWaQyVZK8H vl6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715046172; x=1715650972; 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=Mrbuhf8lERW/x3AUUGdC3eD15JM+519sglQ52hQ7AhA=; b=qSutI7k7eBc4Cx/GfJSPaFYXrChMLMKcpqRXXbmLFCerjMrzlB0ZZ5D3qOZ8xhqNDm gzTQ8o8bdtaUq156/uczf9VgyiVWsn0Ku0Vw7OXNf3wNO3TeMrZbJWUuoZ4uSGP2fvO6 w0P6ZBHc/EnNE6sGW8igUApdkGDOYqscURQZ54x+D68zwJsRxewCe3jr7ugGDlTVUtxG 7j+8txEJ//jJJWsvKFfIWvMDfDWwK1YI66OxDyYRJTfIxde5ld4t4AYyGcgOUbP+BcvO eifN+hDBJLOhF/iAdAh2Sh07c2OeBTWNhEztiEPabYkrbGjML6vLOGnSl6wfJGA93zl4 SwGg== X-Gm-Message-State: AOJu0YwwIXTxhL2AKN5UHA/tUak9tGURsZS9xe/lpp1636QWtKG0UVeK DFdUXFNvq2+FdR+UNk2g52y8rOGdz99UdNkgVvt6OcC0dMA5R5PurLC/vQJJhKE= X-Google-Smtp-Source: AGHT+IGF+LSyNFek/MjWREJIb2DvsG1B8cdEZTM4HWcwxV91ymmqopcN94RSVuM+E6tI2esVsff8YA== X-Received: by 2002:a17:902:e548:b0:1e5:5ccd:30e1 with SMTP id n8-20020a170902e54800b001e55ccd30e1mr13723687plf.65.1715046171913; Mon, 06 May 2024 18:42:51 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001eb3f705ddasm8915311plx.255.2024.05.06.18.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 18:42:51 -0700 (PDT) From: Charlie Jenkins Date: Mon, 06 May 2024 18:40:49 -0700 Subject: [PATCH 8/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBS Kconfig option MIME-Version: 1.0 Message-Id: <20240506-compile_kernel_with_extensions-v1-8-5c25c134c097@rivosinc.com> References: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@rivosinc.com> In-Reply-To: <20240506-compile_kernel_with_extensions-v1-0-5c25c134c097@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?= 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=1715046158; l=3086; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=VSGPqebqjCkV+Jce+IU74T8AjKJ/iHF/vPW/Bia4uwk=; b=PDnuVsyyK0HUPATpcCiqShVPqzG7qsmDrxcNZxQQptU20Eb8nLdqbPfj2AbCgNK4RPsM26oGZ gmZwE2MylTPC4jC6xpkZtKachs4HLLUOAvrnLkA+xKmCeSbzFLq0q8f 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-20240506_184252_970321_64099B13 X-CRM114-Status: GOOD ( 13.37 ) 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. 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 30be0fec976a..7519b68c3bd5 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -70,6 +70,7 @@ riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_V) := $(riscv-march-y)v 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