From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B143379EA for ; Wed, 8 May 2024 01:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132204; cv=none; b=QaaEIC1j7kb8wVGGhpO1KVFIKojVxFgtZav4GAxFHrLAeBmy0BfSsQfUG2O6D3txvusMPEt5Uo7QYJBAzWVqQkIFQ123PejxF92qgNpBxgCj4pKbJDdEqOJkQ4t+YVT1Icfb00SipxPuKQ2N5mNJA+HoTnqN3bo6R1HIj/GphRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132204; c=relaxed/simple; bh=j9swSxT8d2fDA4kDGEnqoj8fqzKxNkC+d4MpaFY3y4k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o2bOmiceuw7n/XnGbvHPdHPO6tPRCkKw8y1TPGPihJIRyuI4yE63bRSAjWEQFK+b6EF9XrBjK+75M9BLGmQqKgKz3SS/bXOkeSxAISghW7/9bQMjV5BqGzvdArDZgAvEbKLDHUmgWArA5p/LADv/eNJ57qVIYP7kMI1JX4hzBJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=N7yDtre1; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="N7yDtre1" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2ad8fb779d2so2898664a91.0 for ; Tue, 07 May 2024 18:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132202; x=1715737002; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W9yTxfWOtF5boAkE9/9YrcfOh3vEqeNnQBOu8ePUP3A=; b=N7yDtre1cHDBY2/PkKzxOyT/cJnehOHXyml0RTrBZ2mjtYZJYhek7WiP71M8wPI78n nfJJqKRj6+12kktbBvmLhVjt7Ooa4iziFMdEFseF5mjs84qWw2/MescDMmWchqLkwOFt maFifA9Z5Dt3Wq0JzYuyUjLgBiw6EtG1ms25+587uats9Bcp8L473rvjTpa9lQ0zhxG8 /ybtj1S+5tHWfsqI3RSb07l4+K3s5xbDVyvlxN1glkr5doBig2a8BbhsEG+p/Sjshm6y 1iHNj5jV9TS9930gv719NEMWdpL+dIxXzZM3vHhr0nhqn7FFHmiu01qHwaSCtnQYdweM GKPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132202; x=1715737002; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W9yTxfWOtF5boAkE9/9YrcfOh3vEqeNnQBOu8ePUP3A=; b=erokPvuzrEr+6i+D8pmgEHRej944PtDm7TRGZ2flbFXQFAoj67fXFwzzu4BJNtl4ZF aVXJM3w0n33Wr5XBBq5C6t6tzpxDGv6b8mriNOa3UNCbNyWmQdFA6+TNq3gt1eTDG58A Xr2UYyf1zUifnIk7XA2UMfPokAo1maQwYG81375+O4kF4aUNidNksPZhXdGVTutPZNAC 4tYAn17gp+7fVDw+X7HdTnp3FAxqlCSLwJr3i/d/GVndjgXrG8ytjtA+6CEmCxS9HFZV naUxvBP42g1KeU/72CI8bn5jtidT2MNUZgvookfrh0WfQUuUwAjpAOa10N5TWNQJ+Uxu IPpQ== X-Forwarded-Encrypted: i=1; AJvYcCVJppIOmoNdBUlqCMCUJhQ5WIpNrMHbI6cmxDIAOdJ2OUb7w7AX3eFo2/ukQF45B2EjcylC60uPkDr/9ro5ZerhMNQApMhVNv33JM7p X-Gm-Message-State: AOJu0YzZ1vkIbqvNSFDh0ZJyOPgiuF5Jza2Wouk8XSN1etUTgM234avp fss/LSqYslq3+2BUJTowI9kOgO0/Eb8XvrM3RgK3g3LxqKZf2s+wBIELcUhfYmY= X-Google-Smtp-Source: AGHT+IG1y+2SksOJ5/iFT/Z5fKQTo1Zf9NVG2qfabMXNk0GuZoWNzylHq8ETlUv78rTnGDNbEMlqHg== X-Received: by 2002:a17:90a:fd0c:b0:2ac:23ec:6a57 with SMTP id 98e67ed59e1d1-2b6169db571mr1212359a91.39.1715132201989; Tue, 07 May 2024 18:36:41 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:41 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:27 -0700 Subject: [PATCH v2 1/8] riscv: Add PLATFORM_MAY_SUPPORT_RISCV_ISA_C Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-1-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=5960; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=j9swSxT8d2fDA4kDGEnqoj8fqzKxNkC+d4MpaFY3y4k=; b=7HgrUjF7yNqvZHKoMqkfNlOf3VFDhBOLsI3MIl5rTg6+kqCvct+IvjzRfsRPpeygmRzDbM6zH UvjMdMc28OiCM/Bc16GtdVCvODCU5QyePqQ0aq1o9XFlS1lGoN15AbV X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Introduce a "Kernel ISA" menu and migrate the compressed instruction support options into a new file Kconfig.isa. Add a new option "PLATFORM_MAY_SUPPORT_RISCV_ISA_C" that can be used to conditionally emit C extensions if the hardware supports it. The existing "RISCV_ISA_C" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_C or PLATFORM_SUPPORTS_RISCV_ISA_C has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 19 +++++++----------- arch/riscv/Kconfig.isa | 41 ++++++++++++++++++++++++++++++++++= ++++ arch/riscv/Makefile | 4 ++-- arch/riscv/kernel/probes/uprobes.c | 2 +- arch/riscv/net/bpf_jit.h | 4 +++- 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c8bdfd33abf4..c2a4f5364707 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -369,6 +369,12 @@ config ARCH_RV64I =20 endchoice =20 +menu "Kernel ISA" + +source "arch/riscv/Kconfig.isa" + +endmenu + # We must be able to map all physical memory into the kernel, but the comp= iler # is still a bit more efficient when generating code if it's setup in a ma= nner # 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 =20 -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 prese= nt 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 +=3D --no-relax KBUILD_CPPFLAGS +=3D -DCC_USING_PATCHABLE_FUNCTION_ENTRY -ifeq ($(CONFIG_RISCV_ISA_C),y) +ifeq ($(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C),y) CC_FLAGS_FTRACE :=3D -fpatchable-function-entry=3D4 else CC_FLAGS_FTRACE :=3D -fpatchable-function-entry=3D2 @@ -65,7 +65,7 @@ endif riscv-march-$(CONFIG_ARCH_RV32I) :=3D rv32ima riscv-march-$(CONFIG_ARCH_RV64I) :=3D rv64ima riscv-march-$(CONFIG_FPU) :=3D $(riscv-march-y)fd -riscv-march-$(CONFIG_RISCV_ISA_C) :=3D $(riscv-march-y)c +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) :=3D $(riscv-march-y)c riscv-march-$(CONFIG_RISCV_ISA_V) :=3D $(riscv-march-y)v =20 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 @@ =20 bool is_swbp_insn(uprobe_opcode_t *insn) { -#ifdef CONFIG_RISCV_ISA_C +#ifdef CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C return (*insn & 0xffff) =3D=3D UPROBE_SWBP_INSN; #else return *insn =3D=3D 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 @@ =20 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)); } =20 static inline bool rvzbb_enabled(void) --=20 2.44.0 From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0F7CAD5B for ; Wed, 8 May 2024 01:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132206; cv=none; b=acgglvxCmknRAntGRHmeHaDvuv/ZCl6mQNSPxX4EBEw9ViEaJ4K588VS46Qmr5ky+i9yi2p3D4IR0rx9Rvk1q02o1nyHcVcD1bDBLxR50eJVssrDmSBH1UfaVTihjJ6tF8DPQAWnvRtA45AW2ozwfJG5P8sVsSYP9dZh/UouUjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132206; c=relaxed/simple; bh=W4jHdZN/kCsCwkDu00hJrCLOm+euMvrei2YBsQUCfLQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XGSjKd7KEJjualD0R+B1ZbEkVIXmKQEvA7hCXWgjc1X9s9dYWZlMwFw+kS6vmQCUo0eDII3TWda1MebUEe00huDunGQxGSfqHhBNpkpGHU8UnTCXvP3kMGf72VRKKdfEST4Mlq8diW7Na2LWD3bOuA82pxY/HJ0m9Zjl2SyumMI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=PGcUSzsX; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="PGcUSzsX" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6edc61d0ff6so3564379b3a.2 for ; Tue, 07 May 2024 18:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132204; x=1715737004; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QsWvdiflsnWwGCusk/V+w219I8PirWa/ozpvjoDvtCY=; b=PGcUSzsXziERMexGov1lvADymqJBFRCOOOzZy+GR5+5Iq96fLj1JKOtnHrwfyl9Vhl TpTywh3IfncfqRD461xt97JgFS61LKco0OJxwU1BxmmsC5LJnNUDwdNvOM6uSOLnej7q g1PuOObO0i2wgoYM/n/IGjzdXe3IKB7y7Qa2dPz6Ksgrmw8e5KrPEq83CUUomPIBRIo6 PuYeIcgfLht4HN/+ZaqCLFyVjPWcoqs/HORa/PmNwDTnSrbJULLca3PL2WEI+iCJrUee aeEWVV7zL+iBsjuPLJYNJg18dvWG49IgyhX2XLGYFWzidHppJO9Cm+XVXwh9OmKwgtVD vU1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132204; x=1715737004; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QsWvdiflsnWwGCusk/V+w219I8PirWa/ozpvjoDvtCY=; b=NVviBNP+lwIO4WoGOR43eriFVTTH5ZhHVdDjaDs+L/id5kAbHazFCkpNwX/MpMjdGH aBsjqaZeKXRgR1wjczEfx6f+UDgZ2IxLATz93R/KBKyGBg7/I3g6b/wQ6yj91/xTuq70 tnYsqwat77E7ZgnF6vpTjevlF8hjiOgCm0/G1NzdF0P8Aseydb1StDplq8sSuWcbVnXZ TBRf8tzJSjUpizN+RgrdVutC6iw6VzScpzpk+CByMq9ajrJyy+MJPiLcuDZqqkPAJFph 1RU3lUxV4W8jak9UaN940a2Hf6htFP9yVWqdjga6tpeyaBNTJ3ZjI9fm8llBpihpFdbX 74Jw== X-Forwarded-Encrypted: i=1; AJvYcCVO4SWuhTrPY8zw3l9P3yjJAuAMzT/Qtnfz2kcQW0gzngzNCCETC0wu9o6sbU2IfqibW5j3k9ASV01SP5t4q7/NDbgxQrJGCbksJaX2 X-Gm-Message-State: AOJu0YxpNfe6L6TBtwsshvf7o2ecQVVOggpsl0worCLE6eKOm+DdnJFl 8hpnJfowZvdFulQw31s/WTSbgxc1cT5mtG1ZCasn5FtDnrwM4DQnBoauXpQnfnQ= X-Google-Smtp-Source: AGHT+IHnbYWaPgyfBvsooFp5nm4cy6R66eKw9IW9Ae2xxUroArGaGCo9hfmYeJJ/Lsc9/W9mM29X7Q== X-Received: by 2002:a05:6a21:2782:b0:1ac:c455:c126 with SMTP id adf61e73a8af0-1afc8d266famr1254554637.19.1715132203783; Tue, 07 May 2024 18:36:43 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:42 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:28 -0700 Subject: [PATCH v2 2/8] riscv: Add PLATFORM_MAY_SUPPORT_RISCV_ISA_V Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-2-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=16103; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=W4jHdZN/kCsCwkDu00hJrCLOm+euMvrei2YBsQUCfLQ=; b=Po3uOpS8qy3hDavCm7BAc4KyH9f/ISmzzk0Eli8vAsMDCAJhx2yoQJ5x2SaBTpoHvNd2vCNya c6Uj3tJG8RvCO5SM1Et9LXsKrr4DWMGYfT32EXVMKKrZVzPdBeblh6P X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Current versions of the kernel add "v" to the march and then immeidately filter it out such that "v" is not passed to CFLAGS. Instead of doing this filtering, code blocks in the kernel that want to use vector assembly have been changed to locally enable vector (using ".option arch, +v"). To support kernels that can run on hardware that may support vector, the config option PLATFORM_MAY_SUPPORT_RISCV_ISA_V is added, and the previous behavior of RISCV_ISA_V is retained with the option CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_V. When the hardware is assumed to support vector, has_vector() unconditionally returns true. "v" is not added to the toolchain march even when the hardware is assumed to support vector because kernel vector code must be guarded by kernel_vector_begin/end. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 54 ------------------------- arch/riscv/Kconfig.isa | 85 ++++++++++++++++++++++++++++++++++++= ++++ arch/riscv/Makefile | 6 +-- arch/riscv/crypto/Kconfig | 14 +++---- arch/riscv/include/asm/simd.h | 3 ++ arch/riscv/include/asm/vector.h | 3 +- arch/riscv/kernel/cpufeature.c | 3 +- arch/riscv/kernel/head.S | 8 +++- arch/riscv/kernel/process.c | 12 +++--- arch/riscv/kernel/ptrace.c | 6 +++ arch/riscv/lib/riscv_v_helpers.c | 1 - arch/riscv/lib/uaccess_vector.S | 2 + arch/riscv/lib/xor.S | 2 + 13 files changed, 123 insertions(+), 76 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c2a4f5364707..c2e9eded0a7d 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -520,60 +520,6 @@ config RISCV_ISA_SVPBMT =20 If you don't know what to do here, say Y. =20 -config TOOLCHAIN_HAS_V - bool - default y - depends on !64BIT || $(cc-option,-mabi=3Dlp64 -march=3Drv64iv) - depends on !32BIT || $(cc-option,-mabi=3Dilp32 -march=3Drv32iv) - depends on LLD_VERSION >=3D 140000 || LD_VERSION >=3D 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. =20 endchoice + +config TOOLCHAIN_HAS_V + bool + default y + depends on !64BIT || $(cc-option,-mabi=3Dlp64 -march=3Drv64iv) + depends on !32BIT || $(cc-option,-mabi=3Dilp32 -march=3Drv32iv) + depends on LLD_VERSION >=3D 140000 || LD_VERSION >=3D 23800 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_V + bool + +choice + prompt "Vector extension support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_V + help + This selects the level of support for vector instructions to be + built into the Linux Kernel. This does not impact whether vector + instructions are allowed to be emitted by user-space code. + +config PROHIBIT_RISCV_ISA_V + bool "Prohibit vector instructions" + depends on NONPORTABLE + help + Regardless of if the platform supports vector instructions, + prohibit the kernel from emitting vector instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_V + bool "Allow vector instruction sequences if supported" + depends on TOOLCHAIN_HAS_V + depends on FPU + select DYNAMIC_SIGFRAME + select RISCV_ISA_V + help + Only allow vector instructions to be emitted if "V" is present in + the device tree or ACPI table. No vector instructions will be + emitted if the platform does not support them. + +config PLATFORM_SUPPORTS_RISCV_ISA_V + bool "Emit vector instructions when building Linux" + depends on TOOLCHAIN_HAS_V + depends on FPU + depends on NONPORTABLE + select DYNAMIC_SIGFRAME + select RISCV_ISA_V + help + Adds "V" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in vector instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support vector instructions. + +endchoice + +config RISCV_ISA_V_DEFAULT_ENABLE + bool "Enable userspace Vector by default" + depends on RISCV_ISA_V + default y + help + Say Y here if you want to enable Vector in userspace by default. + Otherwise, userspace has to make explicit prctl() call to enable + Vector, or enable it via the sysctl interface. + + If you don't know what to do here, say Y. + +config RISCV_ISA_V_UCOPY_THRESHOLD + int "Threshold size for vectorized user copies" + depends on RISCV_ISA_V + default 768 + help + Prefer using vectorized copy_to_user()/copy_from_user() when the + workload size exceeds this value. + +config RISCV_ISA_V_PREEMPTIVE + bool "Run kernel-mode Vector with kernel preemption" + depends on PREEMPTION + depends on RISCV_ISA_V + default y + help + Usually, in-kernel SIMD routines are run with preemption disabled. + Functions which envoke long running SIMD thus must yield core's + vector unit to prevent blocking other tasks for too long. + + This config allows kernel to run SIMD without explicitly disable + preemption. Enabling this config will result in higher memory + consumption due to the allocation of per-task's kernel Vector context. diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index e1be36004097..e1111e62ca20 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -66,7 +66,6 @@ riscv-march-$(CONFIG_ARCH_RV32I) :=3D rv32ima riscv-march-$(CONFIG_ARCH_RV64I) :=3D rv64ima riscv-march-$(CONFIG_FPU) :=3D $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) :=3D $(riscv-march-y)c -riscv-march-$(CONFIG_RISCV_ISA_V) :=3D $(riscv-march-y)v =20 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS +=3D -Wa,-misa-spec=3D2.2 @@ -78,10 +77,7 @@ endif # Check if the toolchain supports Zihintpause extension riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) :=3D $(riscv-march-y)_zihi= ntpause =20 -# 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 +=3D -march=3D$(shell echo $(riscv-march-y) | sed -E 's/(rv3= 2ima|rv64ima)fd([^v_]*)v?/\1\2/') - +KBUILD_CFLAGS +=3D -march=3D$(subst fd,,$(riscv-march-y)) KBUILD_AFLAGS +=3D -march=3D$(riscv-march-y) =20 KBUILD_CFLAGS +=3D -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)" =20 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 =20 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 =20 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 =20 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 =20 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 =20 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 =20 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/vecto= r.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) =20 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); } =20 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) } =20 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 &=3D ~COMPAT_HWCAP_ISA_V; + else + riscv_v_setup_vsize(); } =20 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 */ =20 -#ifdef CONFIG_RISCV_ISA_V +#if defined(CONFIG_PLATFORM_MAY_SUPPORT_RISCV_ISA_V) csrr t0, CSR_MISA li t1, COMPAT_HWCAP_ISA_V and t0, t0, t1 beqz t0, .Lreset_regs_done_vector - +#endif +#ifdef CONFIG_RISCV_ISA_V /* * Clear vector registers and reset vcsr * VLMAX has a defined value, VLEN is a constant, * and this form of vsetvli is defined to set vl to VLMAX. */ + .option push + .option arch, +v li t1, SR_VS csrs CSR_STATUS, t1 csrs CSR_VCSR, x0 @@ -447,6 +450,7 @@ SYM_CODE_START_LOCAL(reset_regs) vmv.v.i v8, 0 vmv.v.i v16, 0 vmv.v.i v24, 0 + .option pop /* note that the caller must clear SR_VS */ .Lreset_regs_done_vector: #endif /* CONFIG_RISCV_ISA_V */ diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index e4bc61c4e58a..3ba7bf63ccb2 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -165,11 +165,13 @@ void flush_thread(void) #endif #ifdef CONFIG_RISCV_ISA_V /* Reset vector state */ - riscv_v_vstate_ctrl_init(current); - riscv_v_vstate_off(task_pt_regs(current)); - kfree(current->thread.vstate.datap); - memset(¤t->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); - clear_tsk_thread_flag(current, TIF_RISCV_V_DEFER_RESTORE); + if (has_vector()) { + riscv_v_vstate_ctrl_init(current); + riscv_v_vstate_off(task_pt_regs(current)); + kfree(current->thread.vstate.datap); + memset(¤t->thread.vstate, 0, sizeof(struct __riscv_v_ext_state)); + clear_tsk_thread_flag(current, TIF_RISCV_V_DEFER_RESTORE); + } #endif } =20 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 =3D &target->thread.vstate; struct __riscv_v_regset_state ptrace_vstate; =20 + if (!has_vector()) + return 0; + if (!riscv_v_vstate_query(task_pt_regs(target))) return -EINVAL; =20 @@ -127,6 +130,9 @@ static int riscv_vr_set(struct task_struct *target, struct __riscv_v_ext_state *vstate =3D &target->thread.vstate; struct __riscv_v_regset_state ptrace_vstate; =20 + if (!has_vector()) + return 0; + if (!riscv_v_vstate_query(task_pt_regs(target))) return -EINVAL; =20 diff --git a/arch/riscv/lib/riscv_v_helpers.c b/arch/riscv/lib/riscv_v_help= ers.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; =20 - /* skip has_vector() check because it has been done by the asm */ if (!may_use_simd()) goto fallback; =20 diff --git a/arch/riscv/lib/uaccess_vector.S b/arch/riscv/lib/uaccess_vecto= r.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 =20 +.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 =20 +.option arch, +v + SYM_FUNC_START(xor_regs_2_) vsetvli a3, a0, e8, m8, ta, ma vle8.v v0, (a1) --=20 2.44.0 From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90687C2C6 for ; Wed, 8 May 2024 01:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132208; cv=none; b=YFmiFmCIR9p0Lp9b/AZyy30f6KSAyCt1WIOHoJB7AjEQwFHbhflO+SEbHjH1sqXI+uGeAM9qTR8cj0GbCkiO7hiizhIe+0e2YA6LRfaZTtxtK0oUo/bP/jozg3ExIijMhzt/BZhIyrc+DsG/LcAVV/5i4ovPHxs/5Cg+gsTL0fk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132208; c=relaxed/simple; bh=gHdAyzxOSw9+j0qkNaNh5cV4dO8gj7MOepOEM8Ai+S4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L+qyLSyurDITnaluGnlcY++1YNikM1bdOfD5F3V/PIVcVoN/KaCGU/5zyoM1IAHRU1URkCLv+KaDFmGq7MmcFWj62erJ9hd/YgGkxbv2i1vhQ6ka+LMIi6TEV33MP3rs8vr18W2kzvbPizFlEd//94WTfPBH42jfKB3uIJ1Ju0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=rnyj1WR6; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="rnyj1WR6" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2b33d011e5dso262887a91.0 for ; Tue, 07 May 2024 18:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132205; x=1715737005; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZyAjbp499S4E60gPGPnq8+Il/FcfjFcaiJmSSEoBy08=; b=rnyj1WR6yOr+oOtaZZf0feZ3/HhH0rkXv+F49VpifOnHWQfkrvO/BKBRMiuCjqzb5T gY2SAtMOytdTX4PGWvPWMWvS0et7xCunvJadK1sy5ICAc+eI4Qcw6B8dL8VL0Qhm2TiD x8tI6lW9glij/nu8eEonYjvMBZGDcSb5oEgZYel6wi8iPbR5fE3lXkuY8Ub2hMsgRUIQ ahh3f+JuAPWTWygFtOG26PcpakZ3QZN7SWwutSZyDpaZ5HPf6SUD+R04C8nsjlj2RRml q3N0zQjhw10XIAsGR4cIrHhMz27N/hyF8s5xk9eNX6Khi+Ome1D8w6iC2gzuKa5rfgRg r4Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132205; x=1715737005; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZyAjbp499S4E60gPGPnq8+Il/FcfjFcaiJmSSEoBy08=; b=h+hQfeozmop0wpPXkdbprXUdeHakdnOa+EBOK8nKZAaKE1OCYFNYYrmdP20zkIj9k3 HkNfFSmalLtR7o33pLmGCBbgk2eI0aYBxtOCDhawaHJMXgFKs78M9EQyOcjfYPuuNnhi fYqNCJMSYV5uxzaKWFYB82azXvPTCM+tjMu2k6PzmopQvUiYhwcR7Cnr0e/gIxNBNMpb Qd9jAf3VZ6NBOAyH7fTMaCTvnpuZUd3xKJXBsXchgTSgcDXV3C9qjq46dh7w9TBaYPN8 tUG8dIZrH2SMedRwg41XFRVVEFTLeGO84Tcn1b17fdwTpzxzHd591kBcPKVhIsoRlygb Gi6g== X-Forwarded-Encrypted: i=1; AJvYcCVNd+ZkCbHO4bzXQ0X/WXnIaBT7vfBnL/mZ6XzX3CQ/67iTRTSMPAPlPw/8clRo/x01rUgIkj/strA5aW13z+x17TUtC1kEI/LXhUJi X-Gm-Message-State: AOJu0YzLGevrSRgAIAoM3L16BNwSnrFfgf+3LzhDDZfiUOJYfrKmwKW1 QjmjKeaPXHYFTyngMZo17NEmozdAIu7m0sdWS9MBKkN5SMW0dJKjdH2lSZj6t6g= X-Google-Smtp-Source: AGHT+IHwXlXHG/dkLoF/6u+zxBIvilwus9SDgdbrJPGXciSar+3njjYMfgBvflCo8Xus0Cl4AWNAgQ== X-Received: by 2002:a17:90a:1001:b0:2ad:f3c3:540d with SMTP id 98e67ed59e1d1-2b611aecf9amr1982459a91.21.1715132205449; Tue, 07 May 2024 18:36:45 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:44 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:29 -0700 Subject: [PATCH v2 3/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-3-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=4526; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=gHdAyzxOSw9+j0qkNaNh5cV4dO8gj7MOepOEM8Ai+S4=; b=n798W2bBPAkZ1DxRbCdpbApDgPYqiZBBEqfBDG7kgws2qQjYG55u+NOtwPJkJ2zwoa3y5JfGj 1/3Q87QUPqFCAhtwHtP01IYlaKmSvNxxzdLntEkAIGs00uPQ9WLzkTG X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= The existing "RISCV_ISA_SVNAPOT" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT or PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT has been set. PLATFORM_MAY_SUPPORT_RISCV_ISA_SVNAPOT will check if the hardware supports Svnapot before using it, while PLATFORM_SUPPORTS_RISCV_ISA_SVNAPOT will assume that the hardware supports Svnapot. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 19 ----------------- arch/riscv/Kconfig.isa | 44 ++++++++++++++++++++++++++++++++++++= ++++ arch/riscv/include/asm/pgtable.h | 3 ++- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c2e9eded0a7d..3c1960e8cd7c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -484,25 +484,6 @@ config RISCV_ALTERNATIVE_EARLY help Allows early patching of the kernel for special errata =20 -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 type= s" 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/pgta= ble.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) =20 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); } =20 static inline unsigned long pte_napot(pte_t pte) --=20 2.44.0 From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6772D524 for ; Wed, 8 May 2024 01:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132209; cv=none; b=DevhTLaq2G9PVfGudu5db/tdhwN4IFsMw9BbP+nW3MeYzZKKMPBEsgIh23z6BD8yZEROaD3Wkl/vcIY+1Zxxf4BUR05fX6js20VVllI9yng4iid3cg1HjHjnuQMnQQi6tHzXUmqNIltPMG0WwH0yV63s2s57pbl9YlQW+cIvr3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132209; c=relaxed/simple; bh=hN6gBReRWF4tyaALzLlv0FO1iXf71FwbEQWuRR1cn6U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uWnQ6xivFbCWe5z5dZtoPlGGqP8hRBUKDY612zkkouUkxyqI/15q1QNkRlGp02yc7ELkoGWAxlv1fzcaSo5pY23evEfvcGa723lsuBSrhkJ8Jlhp+EsfCyt+oay9HzinAdSdCIpTiCCAQkCJrtanQNA5grfMBJuIejKcGnGkWQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=hC9xZOH8; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="hC9xZOH8" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6f4a817f1e5so97058b3a.2 for ; Tue, 07 May 2024 18:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132207; x=1715737007; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vFSJQnmxYmfjoFDImtU4VL6iWxbfob1tPsjHMgxh4E4=; b=hC9xZOH8ijF3CnS3r0NotAGEhR/x1LruMi9LSeeLhdesfs7YUDJVVc1CdtqHhMXziL mFaeYYi+BJrx7YewtPx6bMMtPEcXGvcvWuk8+V4LO9sLp0ERek6dZSUaX2llZiBHn9tG JnAGkW0rvYE/fCvb90Qz/cOshGUEy8a7PrOhrLOYzOfl4HdMXwPh4/8bi2nAPAZHJ8J4 d0osYqAkU5a4gAL47LOu2VHE2lAop69ieASqAVfLx0xZ/c4lg2os6Qh+VsJPYjHbLfsf P80C3IuixnXXUS0bhY9aN7Umm7m/qur3RDxOtJG87Icm+5W+qAZhkbl3d7ubWzfkvzv0 uReQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132207; x=1715737007; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vFSJQnmxYmfjoFDImtU4VL6iWxbfob1tPsjHMgxh4E4=; b=PDMGW9mr+wC2Kjs31xA1uF/WzxRTdvifLXaAQe9A7h5kzE9FB7sdGccouc2R5vN9yd Iz7sSOmHn7ZchJEiMsyGIvQjquJmgUOgdZ4jfMU/hvT7zBtbL7hEfCBjjNJ0Vub1wcwb a+a4zcMLQQPf2/lPpha4YLjA0EDNzc2T6yuqpO5+JkM9KVvO1Wwk8FIaDJ+4/S0IvtNw oXyF4d+ZWdQrgzuBdmBg0s+csXEA1LJ6xfmLQzbZQWFz5xQeAp2ysAN1F+G4RG9+OSvG NUlNos/uF1M+dsFwFm1ru1tNzg3Pc8KQECE+sMRCq/X9rO9lvxfMILxskNkUIqW11b91 1bJQ== X-Forwarded-Encrypted: i=1; AJvYcCWKnusdEhYCERFUwVJ568HhdihV+mwzFO8ddtKYdzYtLrmAN6/9H5xkRVuT1Mqqvj35tfEkgr1cRLdxbm3rZhzVQqI+pPk61HTbKPQQ X-Gm-Message-State: AOJu0YwFgHWSexJn0efoHGgStxJu7aalGw7wCpPlK77Fl+/zibKPH5Up UohGIL05EnK8Mq7EAe4VjhJUAhkOtxc1nz+KXuP0ETMnLwLttz93zX1MfG9yPkg= X-Google-Smtp-Source: AGHT+IGyPdvmy6aV3B3L4umYWWDDY8xIoU7bUJV2TUBvLWRK8ohQMMF3SW0DKxfoVvgynUcDHsYrOA== X-Received: by 2002:a05:6a21:2715:b0:1a9:5b1e:4f06 with SMTP id adf61e73a8af0-1afc8e045e8mr1232295637.52.1715132207095; Tue, 07 May 2024 18:36:47 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:46 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:30 -0700 Subject: [PATCH v2 4/8] riscv: Move RISCV_ISA_SVPBMT to Kconfig.isa Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-4-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=2196; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=hN6gBReRWF4tyaALzLlv0FO1iXf71FwbEQWuRR1cn6U=; b=rwmUivRGvDcoS+kvi09gdGx7PVj/grlp+Tad0aawkK1yi6IcKtZer2CtyNjel3SZbguaXYzst 2GPHvUxb7LyAOvNrFFBjRTs73lBl91FO/UMmx/qaiWyoJ8A6E4MRt+T X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Svpbmt would not benefit from having PLATFORM_SUPPORTS_RISCV_ISA_SVPBMT so just move the definition of RISCV_ISA_SVPBMT to Kconfig.isa. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 17 ----------------- arch/riscv/Kconfig.isa | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 3c1960e8cd7c..47a1d28bbb64 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -484,23 +484,6 @@ config RISCV_ALTERNATIVE_EARLY help Allows early patching of the kernel for special errata =20 -config RISCV_ISA_SVPBMT - bool "Svpbmt extension support for supervisor mode page-based memory type= s" - 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. =20 endchoice + +config RISCV_ISA_SVPBMT + bool "Svpbmt extension support for supervisor mode page-based memory type= s" + 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. --=20 2.44.0 From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97BA7EADC for ; Wed, 8 May 2024 01:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132211; cv=none; b=AUxMLOacc4sG34s+1xWJZSY92BLV4O05EmrmdQ4E0EUZialb6XQQN6i2GKeFgg/a1QDwyEBEqcnhK1fywLsD1sjYP6nLg+0xfBui5tDy7faSboo2xMBlOaT2Sx8mRGw0cyBfZR51XA15rgtIZR5I+8McSJRQyV/cLo2BSdhtpxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132211; c=relaxed/simple; bh=cOJgPTsZER0QYbl0huXDzsEpoo6FnPUGzH8hvF+KHqU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o69I4Zj1wWolA4thm/gvy31ps1UJGXulx6pA5v/hK8QFlstLFZiJGvktazf+XbvPWX9igt9uKJdo83YR9GkB8OyEG4nNNvgLnBXbxN/mXidAkQjYBe9y3tEPo3fy2RjsFeg73Z4vYbVdKMMaTXqVoxG51EbSQY6ThaJhAxu4LCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=hSP/IXnH; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="hSP/IXnH" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2b4348fa971so2634092a91.1 for ; Tue, 07 May 2024 18:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132209; x=1715737009; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=th9kOuU1e9CFgMoeHZSK9oNWtH0aPnkCZu5MPXoJ/hI=; b=hSP/IXnHFAyfKVhcKEdHo00ygFvFODIV5lvaQG7wEibl0+PGA59nKgdjGYAeNsj1uN w4+/A0Eo/0U7qPU+7cDq5Fk8xJnJrgz4/iTOZOl49xrqmLcIOPDETX373MX3FIKjbiI6 Ro4DFVEmdUGeTTeVpAu1u9lA2zPTozDqi0UF7LfaZj6xlGvpk2WOKPE/yBvD2vF63Lfo +L00+bHKjJpELkSjNXHnZ+BZbfF8gsfiBokb6MQQJRp5N6w8SZLBhQW88778gU1Kk4Ah BUyG0+z5aT6O0ZfS80HLoVsGQ63rQ0u4SOm8whMjcldGLOKCw2OPrZR29nFqEn4GFhDS oRAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132209; x=1715737009; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=th9kOuU1e9CFgMoeHZSK9oNWtH0aPnkCZu5MPXoJ/hI=; b=CVCrQDU4WzAPjrtc0qHj9lHbXdanFAqwT3mNnR6F+81MhGS+jfboKynHCoJISdkZX+ VbJzp+4neIxWbYXR2wwJ86qsUjGPulsjXQ/xQqljgtd6exXRx8rksepUffAYOT9tCDsA TZ9q5Jycsy0jLcg+l2f0vrbE2mhsKIoUB7KnV5JOLcQGk5CXE8oPS6wP9zkHDpPkAfQl v5LJdvZfZlnhEKSCLjSPfRgIUfyJRnlw+FedqG2v0ef/dHxKyNHzP9Rakdd1ZsCeI3Zd T2oTpRnMXVGMfCcPspxlBtpGO26Ns4Ln+CqarbfKH/VzUb7MILQebiqGgY44nfeMM2O2 1lpQ== X-Forwarded-Encrypted: i=1; AJvYcCUwNMJrmkWjNdOCz83QWPwkS2uSIhFuma9rn+8Rt5iBYSMBflX2Wxb9wnB60HpDf1NUKT1g9fxFrmSr4z2W1lz/dTxq/wPWtVLaRJO8 X-Gm-Message-State: AOJu0Yx6mKsMKspQGuS91xPQqIC0jSta8L6+R43aiipBV8SDVNtXarDF I5iKUAlNygl4mp1xVL0rHAMQ251CkDIOy2HA832aSqRfE2fy55SE+IpJJvSu+6A= X-Google-Smtp-Source: AGHT+IFXoQ5QrGUnjsqJOFF8ILEziuw2R/JwNz2AA0yMtAfuMkwguJG5FDUdd+JLIhNLXY8MnpekNA== X-Received: by 2002:a17:90a:6581:b0:2b2:c6f8:70b0 with SMTP id 98e67ed59e1d1-2b6165a4d0dmr1314326a91.11.1715132208778; Tue, 07 May 2024 18:36:48 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:48 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:31 -0700 Subject: [PATCH v2 5/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBB Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-5-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=14084; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=cOJgPTsZER0QYbl0huXDzsEpoo6FnPUGzH8hvF+KHqU=; b=ama9tCwHrUazEXquTbnZAxNqCYykgl/D7s4mQyJl2bwHPMJO1TKXiGVKJBZJCxYEciqIl5MoE pLyQxwfvk5LAV3FUe7c3WxRmXxBOBLnme26x/X+JygB1MhlaYlKAdB+ X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Zbb can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBB that allows arbitrary Zbb instruction sequences to be emitted by the compiler. This assumption also allows the alternatives to become evaluated at compile time for Zbb. The existing "RISCV_ISA_ZBB" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB or PLATFORM_SUPPORTS_RISCV_ISA_ZBB has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig | 24 ---------------- arch/riscv/Kconfig.isa | 54 +++++++++++++++++++++++++++++++= +++- arch/riscv/Makefile | 1 + arch/riscv/include/asm/arch_hweight.h | 33 ++++++++++----------- arch/riscv/include/asm/checksum.h | 18 ++++++------ arch/riscv/lib/csum.c | 48 +++++++++++++++---------------- arch/riscv/lib/strcmp.S | 4 +-- arch/riscv/lib/strlen.S | 4 +-- arch/riscv/lib/strncmp.S | 4 +-- arch/riscv/net/bpf_jit.h | 4 ++- 10 files changed, 113 insertions(+), 81 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 47a1d28bbb64..df620e534b3f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -484,14 +484,6 @@ config RISCV_ALTERNATIVE_EARLY help Allows early patching of the kernel for special errata =20 -config TOOLCHAIN_HAS_ZBB - bool - default y - depends on !64BIT || $(cc-option,-mabi=3Dlp64 -march=3Drv64ima_zbb) - depends on !32BIT || $(cc-option,-mabi=3Dilp32 -march=3Drv32ima_zbb) - depends on LLD_VERSION >=3D 150000 || LD_VERSION >=3D 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 Z= vkb. @@ -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 =20 -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 =20 endchoice =20 -config RISCV_ISA_SVPBMT +config PLATFORM_MAY_SUPPORT_RISCV_ISA_SVPBMT bool "Svpbmt extension support for supervisor mode page-based memory type= s" 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. =20 If you don't know what to do here, say Y. + +config TOOLCHAIN_HAS_ZBB + bool + default y + depends on !64BIT || $(cc-option,-mabi=3Dlp64 -march=3Drv64ima_zbb) + depends on !32BIT || $(cc-option,-mabi=3Dilp32 -march=3Drv32ima_zbb) + depends on LLD_VERSION >=3D 150000 || LD_VERSION >=3D 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBB + bool + +choice + prompt "Zbb extension for bit manipulation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB + help + This selects the level of support for Zbb instructions to be + built into the Linux Kernel. This does not impact whether Zbb + instructions are allowed to be emitted by user-space code. + + The Zbb extension provides instructions to accelerate a number + of bit-specific operations (count bit population, sign extending, + bitrotation, etc). + +config PROHIBIT_RISCV_ISA_ZBB + bool "Prohibit Zbb instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zbb instructions, + prohibit the kernel from emitting Zbb instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBB + bool "Allow Zbb instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBB + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBB + help + Add support for enabling optimisations in the kernel when the + Zbb extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBB + bool "Emit Zbb instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBB + depends on NONPORTABLE + select RISCV_ISA_ZBB + help + Adds "zbb" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zbb instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zbb extension. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index e1111e62ca20..6b0c3a782f99 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -66,6 +66,7 @@ riscv-march-$(CONFIG_ARCH_RV32I) :=3D rv32ima riscv-march-$(CONFIG_ARCH_RV64I) :=3D rv64ima riscv-march-$(CONFIG_FPU) :=3D $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) :=3D $(riscv-march-y)c +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) :=3D $(riscv-march-y= )_zbb =20 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS +=3D -Wa,-misa-spec=3D2.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 @@ =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) : :); =20 + return w; + } legacy: -#endif return __sw_hweight32(w); } =20 @@ -50,11 +49,12 @@ static inline unsigned int __arch_hweight8(unsigned int= w) #if BITS_PER_LONG =3D=3D 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(__u= 64 w) : "+r" (w) : :); =20 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/che= cksum.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, uns= igned 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; =20 - 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); =20 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; =20 /* @@ -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 l= en) * 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; =20 /* @@ -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); =20 #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; =20 /* @@ -257,12 +256,13 @@ do_csum_no_alignment(const unsigned char *buff, int l= en) * 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); =20 #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 @@ =20 /* 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) =20 /* @@ -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 @@ =20 /* 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) =20 /* @@ -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 @@ =20 /* 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_IS= A_ZBB) =20 /* @@ -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) =20 static inline bool rvzbb_enabled(void) { - return IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && riscv_has_extension_likely(RIS= CV_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)); } =20 enum { --=20 2.44.0 From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02BFB10A11 for ; Wed, 8 May 2024 01:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132213; cv=none; b=iPAlLii0PIS45wx4VaTzQ91B/FfQakn8ZirltyBSh7RVi5OAL71Dq78A3EPHs/CppDiuGALiODgmOjHJEjde76gXrOX+S6df5QlU4/G8uJ81yjFQyTWpufdj9yzL1iQu9O+LYteZx/2LihlouPm++iG5BwV8mtCI0uTE6HE+sGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132213; c=relaxed/simple; bh=Ue5TDLMRl4Jg133jL9t6n44Efl7WVoijxTwvOh6lOb4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cTDBNDAoBctsmsRb2LCo8lvwtNqvNfRsSKC21M7ZEr75+VQfuOI0GRVlb5WjurJxrxxAIBziy/r1Ejyfw4LmlU7yHHES2YOUl/1KQFdmlHVsLWQieZVs5g876j5dPwP0mYrQPxRK+YgHSdzu440C5x3c/heGfuwQyT4xlLw9g0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=SzIfMXP+; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="SzIfMXP+" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6f453d2c5a1so3548580b3a.2 for ; Tue, 07 May 2024 18:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132210; x=1715737010; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=myHzOOjViF8S4NmNBR6ubwFIqcNqWX5HRrdoX2U4mxE=; b=SzIfMXP+Ut2Uyuq8ATXD7KKrRnjj8Jjy97yT5RSKljbxhrqL2qwfZlTSs6p8tRthUe Q9ZrgxpA97wG06n98KgVPWgKZ/FxxVSU/Dfu3FMlmRlq02rV09b5USPnO1aZQffK4T23 brEEIL1L9Cf/zYV/+PUu3Zt4xJpUkBsWvVdPjzXNhVd1YBcowTX4327HTAzk0Bkjmh1+ 14pGQqlU2SC3Lwji4tPdAntZewtrZOHwnG/hI8se3pblL7g5MRRtcSz+WNxJoTSnVBWW gCY8RyaoujoFShki4JH6XGuNk+Sda2kWKM727varxAowybOHArdssKt1aN6G/39hQXjE WxEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132210; x=1715737010; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=myHzOOjViF8S4NmNBR6ubwFIqcNqWX5HRrdoX2U4mxE=; b=ltp29XkuqlhUq01t8pj0xB0vDa3LQhN4P5+WhOTcAVmDMWDb0S7AI/5Mqp054+N3Wd /VtQtoXvYoH2Ot7t2jAO0AKmwSpEgcRlmyAcCerCbK6yqozmyOF6EzNcm5mMtJ6rdVtn D2jNwXu5D6s4GmfDbMEWXamU6wFzC7Kai6Apoj19UPew9YkSHai1mfEUWBmirck6sYKc 6IHa/SgQhPqHN96Bytlt2Am8fa5Y42s93/zhCXmgmqLPdqZUeE538Zq6MBUDiD/mqebZ gjiNmKup3nEepRBYV4HzZyYW/bWGNnjz8wbjkpMF6y8P4rN/K7DA2kKQi8tvVlKI2xbl YEQQ== X-Forwarded-Encrypted: i=1; AJvYcCUcKbpZ0IGLoEbd0703q3xvrqLX+Y8naDwYj8ZkhpJ+Ng/+kpn4iV4UcVzN9LdaoDpQzN9b4rHq2w0HIi6Evy4MYnQt2NQum2TAoT3v X-Gm-Message-State: AOJu0Yzxxgp52GRJjY7O7MKgDnZfrLW2l8ADNp22Bj5yoaX3K4U67Pej Qwaozpv5rl97N9UrqtszVZzG+rTOoUHG407U//a+XiyP5pZjNTbI2xY3UTk6YIE= X-Google-Smtp-Source: AGHT+IHmyiekyum4bwoOJjosIJw7Z4DfDemwOXxUCyVbwuXuMPDsZBlduhwLXl3Z+XO6EPfAoMsxiA== X-Received: by 2002:a05:6a21:191:b0:1a7:2ceb:e874 with SMTP id adf61e73a8af0-1afc8d5b8fcmr1553729637.37.1715132210381; Tue, 07 May 2024 18:36:50 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:49 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:32 -0700 Subject: [PATCH v2 6/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBA Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-6-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=3295; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=Ue5TDLMRl4Jg133jL9t6n44Efl7WVoijxTwvOh6lOb4=; b=VPIFtHfzr8Xor7UIxI0uyPtvmdLuA5naS2Aa3xz4lMr3TZ261O7CupIAtnVu2wEleN1W4S7jL MeRK4vLEM5jDcGk96yhQiSL1n+P1wTsp6mS9ZW8caczG/bll99sxiRn X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Zba can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBA that allows arbitrary Zba instruction sequences to be emitted by the compiler. The existing "RISCV_ISA_ZBA" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBA or PLATFORM_SUPPORTS_RISCV_ISA_ZBA has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.isa | 52 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ arch/riscv/Makefile | 1 + 2 files changed, 53 insertions(+) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index 49bed8c75263..e7f28dc44137 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -186,6 +186,58 @@ config PLATFORM_MAY_SUPPORT_RISCV_ISA_SVPBMT =20 If you don't know what to do here, say Y. =20 + +config TOOLCHAIN_HAS_ZBA + bool + default y + depends on !64BIT || $(cc-option,-mabi=3Dlp64 -march=3Drv64ima_zba) + depends on !32BIT || $(cc-option,-mabi=3Dilp32 -march=3Drv32ima_zba) + depends on LLD_VERSION >=3D 150000 || LD_VERSION >=3D 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBA + bool + +choice + prompt "Zba extension for address generation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBA + help + This selects the level of support for Zba instructions to be + built into the Linux Kernel. This does not impact whether Zba + instructions are allowed to be emitted by user-space code. + + The Zba extension provides instructions to accelerate a number + of address generation instruction sequences. + +config PROHIBIT_RISCV_ISA_ZBA + bool "Prohibit Zba instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zba instructions, + prohibit the kernel from emitting Zba instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBA + bool "Allow Zba instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBB + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBA + help + Add support for enabling optimisations in the kernel when the + Zba extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBA + bool "Emit Zba instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBB + depends on NONPORTABLE + select RISCV_ISA_ZBA + help + Adds "zba" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zba instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zba extension. + +endchoice + config TOOLCHAIN_HAS_ZBB bool default y diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 6b0c3a782f99..c8ec38b9880a 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -66,6 +66,7 @@ riscv-march-$(CONFIG_ARCH_RV32I) :=3D rv32ima riscv-march-$(CONFIG_ARCH_RV64I) :=3D rv64ima riscv-march-$(CONFIG_FPU) :=3D $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) :=3D $(riscv-march-y)c +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBA) :=3D $(riscv-march-y= )_zba riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) :=3D $(riscv-march-y= )_zbb =20 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC --=20 2.44.0 From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A76B811CB4 for ; Wed, 8 May 2024 01:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132214; cv=none; b=TGhtX4fWk8y+ab+zhB9mjU/fZIV3yFkeuYEscc2VMx/NqedkU00WYt0AlSrTV2KlciwxoxWP+xcvPogJv1R7jYz/n1cAglml//lm//bP9CsmtHCnxUl/9X8FUqFA1U6tv+yqrC4og7uWki4b/GCyY1tZpEPfImx1lADxUJtskq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132214; c=relaxed/simple; bh=mhWqJj1RP0LVjsRT3VtWySRs+UTs7hL4pCht9UF8zQ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bmjvBWIjxaVcKZ4vzsDiDWXvUK7me6wPW7yw+BY+t73eT/SmYvNNCG9euO/02VIWzdHC+kg3mvg67l/xQGtYMzwngCiuLBJSBH3Oll8CkmmL9tqKerGa1IBE+NzCA2u4nrHHyiQrikPclaR0CVZ9njpNq5Oj4j6KLngdZzHleNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=tapD0THj; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="tapD0THj" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ac9b225a91so2707638a91.2 for ; Tue, 07 May 2024 18:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132212; x=1715737012; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=G63nKFkjY3qHnS0X1QIzt6sf9vbSpbh90Xj2nxjAK3E=; b=tapD0THj+sAOFGVZM/hZBlylZnmyshZjORu+OQca3qCaz08VtS40b8BFFqBtFygGb1 dUqMI3LSmXdsA9SmfyJ84V72cbwBGrCZj4LaDBFeL5iS0PBmZnTXLqUTzrIr3cb9qo8F 7YaJi82P/lm5VgoWl5ayeGe7LA990PgNQV2X39Z8G1KNumkbnOuXUoKE4MiDiKZuZLJi u7gNB8F3bqZduw07dj86HZf9RN/KdGmP+laZYuKz6Az4sXfPQOpCoxssL0u+wesw4SwU PE/PAQ4ip+DE5E/OZO1yFu5K8Uc8malwDEilU1GC/97dLFoKmv/5OuOrllUwuLyJKqxU IZ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132212; x=1715737012; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G63nKFkjY3qHnS0X1QIzt6sf9vbSpbh90Xj2nxjAK3E=; b=EsgoaBgRqLkApd0alMM7FwTJWzbj3BlMilwAlXW4esVYN1SSWLnzgiDkmZCT7/gnRI uOxrs0vs7G/5zt5X3XCEx2Ge8qJ7LOsPa5y2q36HMTQJAv8RVOUwby1e8Jnuw0u6ssJO x8NbKzKKm1t1epX/2tYa8Xirf/OM4B5mb3F1/YYefzBycnjyaX1ZulviqhPzpzvBJ/rA TTiU9O7yczXkzVLPk9WdWKWpOHFcIuY372gmyGrAxL08qLagOwKqnvcp8c8zSNv/4T4P 4f3pAbMzg9ief62oFJMpn6sidzdtwJFohH7NJxpOR/6UdBr/zRCzlZ7hv2ka59EXLvJG l6qQ== X-Forwarded-Encrypted: i=1; AJvYcCUFW84qqYumgjvSFMMCULgimbOeb+0/CGKVgDjTkhVF/wMncnVR8/tYUh4iDyBegRBgwOR12pRsF+I5e0L9jxL1sQPysUoy3BT4eaUQ X-Gm-Message-State: AOJu0Yx3UBZGfiN1aEjLoNzohyiklOGOZkKefvcuEJ0CxuX995qGUg6F rupuDNzZWBvx1zsoyIWbmK2e/W5UJDlqFqbllXeyVsrICXbxqZywAGeUQkE6Rwg= X-Google-Smtp-Source: AGHT+IFiGPyl3zNyE/SYLjw5BlcdAyzafc6IKgnN2PalwWvftlru0VCVPMVwGkF+0UEGKI78AFsrvQ== X-Received: by 2002:a17:90a:5d06:b0:2b2:7c42:bf6e with SMTP id 98e67ed59e1d1-2b6165aa078mr1175508a91.12.1715132211950; Tue, 07 May 2024 18:36:51 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:51 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:33 -0700 Subject: [PATCH v2 7/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBC Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-7-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=3248; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=mhWqJj1RP0LVjsRT3VtWySRs+UTs7hL4pCht9UF8zQ0=; b=sOz5JQJkzaPJCxTxqkvkSdeiQG9Ioekkp/cr6I56ZbEo4JJzatL3p2LLjxH4sfk9h/40qVxWB OEQki4PEQ2ECjcdqQ6LE0ponkjrcIiw/2Oy+cAKFQ+URoJ4CqY/pRsA X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Zbc can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBC that allows arbitrary Zbc instruction sequences to be emitted by the compiler. The existing "RISCV_ISA_ZBC" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC or PLATFORM_SUPPORTS_RISCV_ISA_ZBC has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.isa | 51 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ arch/riscv/Makefile | 1 + 2 files changed, 52 insertions(+) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index e7f28dc44137..b7399f236bba 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -289,3 +289,54 @@ config PLATFORM_SUPPORTS_RISCV_ISA_ZBB systems that do not support the Zbb extension. =20 endchoice + +config TOOLCHAIN_HAS_ZBC + bool + default y + depends on !64BIT || $(cc-option,-mabi=3Dlp64 -march=3Drv64ima_zbc) + depends on !32BIT || $(cc-option,-mabi=3Dilp32 -march=3Drv32ima_zbc) + depends on LLD_VERSION >=3D 150000 || LD_VERSION >=3D 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBC + bool + +choice + prompt "Zbc extension for bit manipulation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC + help + This selects the level of support for Zbc instructions to be + built into the Linux Kernel. This does not impact whether Zbc + instructions are allowed to be emitted by user-space code. + + The Zbc extension provides instructions to accelerate carry-less + multiplication. + +config PROHIBIT_RISCV_ISA_ZBC + bool "Prohibit Zbc instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zbc instructions, + prohibit the kernel from emitting Zbc instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC + bool "Allow Zbc instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBC + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBC + help + Add support for enabling optimisations in the kernel when the + Zbc extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBC + bool "Emit Zbc instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBC + depends on NONPORTABLE + select RISCV_ISA_ZBC + help + Adds "zbc" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zbc instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zbc extension. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index c8ec38b9880a..57457d15e9a4 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -68,6 +68,7 @@ riscv-march-$(CONFIG_FPU) :=3D $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) :=3D $(riscv-march-y)c riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBA) :=3D $(riscv-march-y= )_zba riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) :=3D $(riscv-march-y= )_zbb +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBC) :=3D $(riscv-march-y= )_zbc =20 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS +=3D -Wa,-misa-spec=3D2.2 --=20 2.44.0 From nobody Wed Dec 17 05:50:57 2025 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F0AE12E70 for ; Wed, 8 May 2024 01:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132215; cv=none; b=bMJBVx6kOCa54Xvhnt9qteqBkYOulC3c1M1Ex68MDxUrL+hkZEh1cgLEVYK6nQTKSjoXBBDOz4up9BprU8ci89yPyG74EUl8IsBL8LvMrbztp3QapV5/z3qhARb14KyZr/JWUSM6fWqyeWN6BiJ3AODkhnMM8H6PZl+svLSw928= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132215; c=relaxed/simple; bh=7B3II1X/5OVe4Mrr/uSiLQQPEgDk0UMK2lq4VVxpgKM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JUpTFuXJMYYmeoa1gY52W5QKB+HBe+1GkaMscfaOorvkyrW+2saEFtKTKdZ2GwYaWaENZW1x97UiG+gmdrS9lxzCCImJoXBtXld3FFQaLW65qEdt0nhi8GiG7287pHwmgLMb6JkshX+EpEf4qOmINB4TStNPzzh7zTYR79ICX5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=vQ1Ztv9e; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="vQ1Ztv9e" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6f28bb6d747so2756322b3a.3 for ; Tue, 07 May 2024 18:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132213; x=1715737013; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HSebZNH2K21s8abZJ+EPitFsmRQfB0232RHZtpEHlvw=; b=vQ1Ztv9eid0UwJLSrsbdU0A4oB1CdmH2XL6L9wz1mVyY3eELA/EnF8oZfw4qaWrwVi 5kucwQdvN2h2LfATn4shur9HNhW0uM0l5H65ep960r3Mwik7Z/bGfReZekjIXp1zQR08 DZm4YNzljYb0R+5IYc+IzfC9RWvjriCTMU6LEiDA96wEga7a+wdAJ65gA0MJB4tQeXlw z+h0QdhCUmTMzTQ03Tz7FyNJW+FNFINvhTx+rt8XWb3IS84GAH/tO2oSWihI90aaFVCN kDfnH88GTmWH2J3uDGgBeJW2jL3xq3ZkAtVunsgOWe6n7rT/LaZ418iZf0+70BqxHxKy 1EAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132213; x=1715737013; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HSebZNH2K21s8abZJ+EPitFsmRQfB0232RHZtpEHlvw=; b=WAmZp/VxJy8cUEpV1nnJaji6t352Y+/fmi83Awr1jnxNz1kh9zyTPgFuw6Yy2plG0L DBxk/T3jjzhAz+R0TlkLG9ILXXW5i6/cI75NAImbqBvIYNvDSn7KUfHwt9F65l9r1UVR EvWYAAtKKCobIsItUdkwV4w07HqvLoGkgzY0By+MslqrEgu2p/jJPuhHc0Wiy37lrLb8 IJvWB6fDI7dZxjKouGwza2EbAX+1epsdMhjz9Tkvne4v17zK1dC3H5pH981h/Q9yY0/Z VpCgluyXyTQ1qCK3j87zQgxjlSIgRNGzl+rTzdQsLMORPi7HivbB9xrgxULDgs3UlG36 raBQ== X-Forwarded-Encrypted: i=1; AJvYcCVwXRShZGVQriDtkeF+freaBXhMDDhOmVjgOZktzIxHxhqNRCkKw4Z7qJBui6n+lW+ceMvN74zDYbao6kMQGoK6FU5UytynS79rW5p9 X-Gm-Message-State: AOJu0YwXtOPUwrE4fGKe9avm/pujzLFMFGjR8B9ZEIocX9QK3lcRN8SE ky3LaMc+yPBZ0Lq8in+uDXBXsMEnZE+++zSS39eSU14ole4aHNysuiHuN7Gy/zg= X-Google-Smtp-Source: AGHT+IHg6ptW80TJdWpfJCJXopHCGmFJ2iuPtPmC3dzzLoosh6XalLDn4t3j0emDTqeCUhoduvuo/g== X-Received: by 2002:a05:6a20:1001:b0:1a9:c80a:c152 with SMTP id adf61e73a8af0-1afc8d763c8mr1324536637.21.1715132213554; Tue, 07 May 2024 18:36:53 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:52 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:34 -0700 Subject: [PATCH v2 8/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBS Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240507-compile_kernel_with_extensions-v2-8-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=3277; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=7B3II1X/5OVe4Mrr/uSiLQQPEgDk0UMK2lq4VVxpgKM=; b=BOORKVGo69HF+7q44TCG43/RRTkpsAJGBawNHVFpF9jkZ7wAN2u8vXOHTvuJ13Qg1B+/ol51J 6rief9SvltyDHEUzuVdcAQrC2MGCzumWPDi5HvHzyzoB8a1cNpdR4Vo X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Zbs can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBS that allows arbitrary Zbs instruction sequences to be emitted by the compiler. The existing "RISCV_ISA_ZBS" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBS or PLATFORM_SUPPORTS_RISCV_ISA_ZBS has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.isa | 51 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ arch/riscv/Makefile | 1 + 2 files changed, 52 insertions(+) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index b7399f236bba..60ae1bf71c70 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -340,3 +340,54 @@ config PLATFORM_SUPPORTS_RISCV_ISA_ZBC systems that do not support the Zbc extension. =20 endchoice + +config TOOLCHAIN_HAS_ZBS + bool + default y + depends on !64BIT || $(cc-option,-mabi=3Dlp64 -march=3Drv64ima_zbs) + depends on !32BIT || $(cc-option,-mabi=3Dilp32 -march=3Drv32ima_zbs) + depends on LLD_VERSION >=3D 150000 || LD_VERSION >=3D 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBS + bool + +choice + prompt "Zbs extension for bit manipulation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBS + help + This selects the level of support for Zbs instructions to be + built into the Linux Kernel. This does not impact whether Zbs + instructions are allowed to be emitted by user-space code. + + The Zbs extension provides instructions to accelerate carry-less + multiplication. + +config PROHIBIT_RISCV_ISA_ZBS + bool "Prohibit Zbs instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zbs instructions, + prohibit the kernel from emitting Zbs instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBS + bool "Allow Zbs instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBS + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBS + help + Add support for enabling optimisations in the kernel when the + Zbs extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBS + bool "Emit Zbs instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBS + depends on NONPORTABLE + select RISCV_ISA_ZBS + help + Adds "zbs" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zbs instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zbs extension. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 57457d15e9a4..80ff8503196a 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -69,6 +69,7 @@ riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) :=3D = $(riscv-march-y)c riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBA) :=3D $(riscv-march-y= )_zba riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) :=3D $(riscv-march-y= )_zbb riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBC) :=3D $(riscv-march-y= )_zbc +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBS) :=3D $(riscv-march-y= )_zbs =20 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS +=3D -Wa,-misa-spec=3D2.2 --=20 2.44.0