Re: [PATCH v9 3/4] riscv: hwprobe: Introduce rva23u64 base behavior

From: Radim Krcmar

Date: Tue Nov 17 2026 - 08:11:09 EST


2026-11-09T07:47:36-05:00, Guodong Xu <guodong.xu@xxxxxxxxxxxxxxxx>:
> Provide a hwprobe base-behavior bit, RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64,
> so userspace can check RVA23U64 support in one call. Without it, a
> consumer has to test more than thirty extension bits across three
> hwprobe keys, and still cannot confirm that PMLEN=7 is selectable
> without prctl() calls that change the calling thread's state.
> Userspace treats RVA23U64 as a new base, so expose it as one.
>
> The bit is reported for a set of CPUs when each of them has the
> RVA23U64 mandatory extensions. F, D, C, V, Zicbom and Zicboz must in
> addition be present on every hart, as the kernel handles these across
> all harts.
>
> Co-developed-by: Andrew Jones <andrew.jones@xxxxxxxxxxxxxxxx>
> Signed-off-by: Andrew Jones <andrew.jones@xxxxxxxxxxxxxxxx>
> Signed-off-by: Guodong Xu <guodong.xu@xxxxxxxxxxxxxxxx>
> ---
> v9:
> - Report RVA23U64 only when F/D, C, V, Zicbom and Zicboz are present on
> every hart, in line with IMA_FD, IMA_C, IMA_V and the host-wide
> Zicbom/Zicboz enables (Radim).
> - Update the RVA23U64 entry in hwprobe.rst.
> - Reword the commit message.
> - Revert RISCV_HWPROBE_BASE_BEHAVIOR_IMA to hardcoded; do not compute
> it from I, M and A.
> ---
> diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c
> +static bool hwprobe_has_isa_base(const struct cpumask *cpus, unsigned int base)
> +{
> + int cpu;
> +
> + /*
> + * F, D, C, V, Zicbom and Zicboz are RVA23U64 mandatory extensions
> + * that the kernel enables for user mode only when every hart has
> + * them, partly because their enable bits (sstatus.FS/VS,
> + * senvcfg.CBCFE/CBZE) are managed across all harts rather than
> + * per hart.
> + */
> + if (base == RISCV_ISA_BASE_RVA23U64 &&
> + !(has_fpu() &&
> + riscv_isa_extension_available(NULL, C) &&
> + has_vector() && riscv_isa_extension_available(NULL, V) &&
> + riscv_isa_extension_available(NULL, ZICBOM) &&
> + riscv_isa_extension_available(NULL, ZICBOZ)))
> + return false;
> +

Looking at the condition, I feel a bit uneasy about code duplication...

> + for_each_cpu(cpu, cpus) {
> + if (!riscv_isa_base_available(hart_isa[cpu].isa_bases, base))
> + return false;
> + }

Could we avoid the isa_bases here and just report the base as a function
of other hwprobe bits (and the awkward PMLEN)?

I think something like the following would directly make use of any
fixes we apply to the detection of hwprobe features:

static bool hwprobe_has_rva23u64(const struct cpumask *cpus) {
/* IMA extensions are required by the kernel. */
return riscv_have_user_pmlen(7) &&
hwprobe_ext0_has(cpus, RVA23U64_EXT0) &&
hwprobe_ext1_has(cpus, RVA23U64_EXT1); }

Where the two RVA23U64_EXT are hardcoded bitmasks of RVA32U64 extensions
and hwprobe_ext_has is tweaked slightly to accept a bitmask and return
true iff all extensions match.

Thanks.