Skip to content

Commit 4774848

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: Add a custom ISA extension for the [ms]envcfg CSR
The [ms]envcfg CSR was added in version 1.12 of the RISC-V privileged ISA (aka S[ms]1p12). However, bits in this CSR are defined by several other extensions which may be implemented separately from any particular version of the privileged ISA (for example, some unrelated errata may prevent an implementation from claiming conformance with Ss1p12). As a result, Linux cannot simply use the privileged ISA version to determine if the CSR is present. It must also check if any of these other extensions are implemented. It also cannot probe the existence of the CSR at runtime, because Linux does not require Sstrict, so (in the absence of additional information) it cannot know if a CSR at that address is [ms]envcfg or part of some non-conforming vendor extension. Since there are several standard extensions that imply the existence of the [ms]envcfg CSR, it becomes unwieldy to check for all of them wherever the CSR is accessed. Instead, define a custom Xlinuxenvcfg ISA extension bit that is implied by the other extensions and denotes that the CSR exists as defined in the privileged ISA, containing at least one of the fields common between menvcfg and senvcfg. This extension does not need to be parsed from the devicetree or ISA string because it can only be implemented as a subset of some other standard extension. Cc: <stable@vger.kernel.org> # v6.7+ Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/20240228065559.3434837-3-samuel.holland@sifive.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 3fb3f71 commit 4774848

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

arch/riscv/include/asm/hwcap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
#define RISCV_ISA_EXT_ZTSO 72
8282
#define RISCV_ISA_EXT_ZACAS 73
8383

84+
#define RISCV_ISA_EXT_XLINUXENVCFG 127
85+
8486
#define RISCV_ISA_EXT_MAX 128
8587
#define RISCV_ISA_EXT_INVALID U32_MAX
8688

arch/riscv/kernel/cpufeature.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ static const unsigned int riscv_zvbb_exts[] = {
201201
RISCV_ISA_EXT_ZVKB
202202
};
203203

204+
/*
205+
* While the [ms]envcfg CSRs were not defined until version 1.12 of the RISC-V
206+
* privileged ISA, the existence of the CSRs is implied by any extension which
207+
* specifies [ms]envcfg bit(s). Hence, we define a custom ISA extension for the
208+
* existence of the CSR, and treat it as a subset of those other extensions.
209+
*/
210+
static const unsigned int riscv_xlinuxenvcfg_exts[] = {
211+
RISCV_ISA_EXT_XLINUXENVCFG
212+
};
213+
204214
/*
205215
* The canonical order of ISA extension names in the ISA string is defined in
206216
* chapter 27 of the unprivileged specification.
@@ -250,8 +260,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
250260
__RISCV_ISA_EXT_DATA(c, RISCV_ISA_EXT_c),
251261
__RISCV_ISA_EXT_DATA(v, RISCV_ISA_EXT_v),
252262
__RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_h),
253-
__RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM),
254-
__RISCV_ISA_EXT_DATA(zicboz, RISCV_ISA_EXT_ZICBOZ),
263+
__RISCV_ISA_EXT_SUPERSET(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts),
264+
__RISCV_ISA_EXT_SUPERSET(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts),
255265
__RISCV_ISA_EXT_DATA(zicntr, RISCV_ISA_EXT_ZICNTR),
256266
__RISCV_ISA_EXT_DATA(zicond, RISCV_ISA_EXT_ZICOND),
257267
__RISCV_ISA_EXT_DATA(zicsr, RISCV_ISA_EXT_ZICSR),

0 commit comments

Comments
 (0)