* [PATCH v9 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection
2026-11-09 12:47 [PATCH v9 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
@ 2026-11-09 12:47 ` Guodong Xu
2026-11-09 15:56 ` Icenowy Zheng
2026-11-09 12:47 ` [PATCH v9 2/4] riscv: cpu: Output isa bases lines in cpuinfo Guodong Xu
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Guodong Xu @ 2026-11-09 12:47 UTC (permalink / raw)
To: Jonathan Corbet, Shuah Khan, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Randy Dunlap, Radim Krcmar
Cc: linux-doc, linux-riscv, linux-kernel, Paul Walmsley, Conor Dooley,
linux-kselftest, Andy Chiu, Florian Weimer, Peter Bergner,
Zihong Yao, Mark Harris, Aurelien Jarno, Guodong Xu, Andrew Jones
Introduce a per-hart and host-wide bitmap of conformant ISA "bases"
(named profile-class sets such as IMA and RVA23U64), computed at init
time by riscv_init_isa_bases().
The IMA base is set unconditionally: it is behavior the kernel always
provides, and is intentionally not derived from the I, M and A
extensions.
Register riscv_init_isa_bases() as an arch_initcall. That is late
enough that core_initcall(tagged_addr_init) has probed senvcfg.PMM and
populated have_user_pmlen_*; without that ordering,
riscv_have_user_pmlen(7) would still return its default false and the
RVA23U64 detection path would always bail. It is also early enough that
arch_initcall_sync(init_hwprobe_vdso_data) finds the bases populated
when it snapshots the hwprobe values into the vDSO data page.
Consider this as the cache that subsequent consumers (hwprobe's
RVA23U64 base behavior bit, /proc/cpuinfo's "isa bases" lines, etc.)
can read without recomputing, which keeps them consistent with
each other.
Co-developed-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
Signed-off-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
Signed-off-by: Guodong Xu <guodong.xu@oss.qualcomm.com>
---
v9: Set the IMA base unconditionally; do not derive it from I, M and A.
v8: Add Co-developed-by for Andrew Jones (Conor).
v7:
- Register riscv_init_isa_bases() at arch_initcall, ahead of the vDSO
hwprobe snapshot at arch_initcall_sync; v6 returned 0 for
RISCV_HWPROBE_KEY_BASE_BEHAVIOR through the vDSO.
- Keep riscv_isa_bases static; add riscv_isa_base_available().
v6: No change.
v5: No change.
v4:
- In riscv_set_isa_base(), reorder those __setbit(RISCV_ISA_EXT_X,m)
lines to make them conform to the order they appear in the RVA23 1.0
Profile.
v3:
- Add a blank line before the subsys_initcall() registration (Andrew).
- Set the local ext_mask with __set_bit() and test the mandate set with
!bitmap_subset() (Sashiko).
- Require the Zic64b ISA extension in the RVA23U64 mask,
instead of open-coded cache block-size check. (New, thoughts from Andrew)
v2:
- Implement riscv_init_isa_bases() that runs at system init time,
after tagged_addr_init() populates have_user_pmlen_*.
- Split RVA23S64 placeholder into a future patch.
---
arch/riscv/include/asm/cpufeature.h | 13 +++++
arch/riscv/kernel/cpufeature.c | 109 ++++++++++++++++++++++++++++++++++++
2 files changed, 122 insertions(+)
diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h
index 99799cc6c198..2ce1a1e212c9 100644
--- a/arch/riscv/include/asm/cpufeature.h
+++ b/arch/riscv/include/asm/cpufeature.h
@@ -25,8 +25,20 @@ struct riscv_cpuinfo {
unsigned long mimpid;
};
+enum {
+ RISCV_ISA_BASE_IMA,
+ RISCV_ISA_BASE_RVA23U64,
+ RISCV_NR_ISA_BASES,
+};
+
+/**
+ * struct riscv_isainfo - per-hart ISA state
+ * @isa: bitmap of ISA extensions this hart implements
+ * @isa_bases: bitmap of profile bases this hart conforms to
+ */
struct riscv_isainfo {
DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
+ DECLARE_BITMAP(isa_bases, RISCV_NR_ISA_BASES);
};
DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
@@ -134,6 +146,7 @@ extern const size_t riscv_isa_ext_count;
extern bool riscv_isa_fallback;
unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
+bool riscv_isa_base_available(const unsigned long *isa_bases, unsigned int base);
static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsigned long ext)
{
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");
diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index 72bce616491f..0377fc148785 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -41,6 +41,9 @@ unsigned long elf_hwcap __read_mostly;
/* Host ISA bitmap */
DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
+/* Host ISA bases bitmap */
+static DECLARE_BITMAP(riscv_isa_bases, RISCV_NR_ISA_BASES) __read_mostly;
+
/* Per-cpu ISA extensions. */
struct riscv_isainfo hart_isa[NR_CPUS];
@@ -81,6 +84,26 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned i
}
EXPORT_SYMBOL_GPL(__riscv_isa_extension_available);
+/**
+ * riscv_isa_base_available() - Check whether a given ISA base is
+ * available or not
+ *
+ * @isa_bases: ISA bases bitmap to use
+ * @base: bit position of the desired ISA base
+ * Return: true or false
+ *
+ * NOTE: If isa_bases is NULL then the host ISA bases bitmap will be used.
+ */
+bool riscv_isa_base_available(const unsigned long *isa_bases, unsigned int base)
+{
+ const unsigned long *bmap = isa_bases ? isa_bases : riscv_isa_bases;
+
+ if (base >= RISCV_NR_ISA_BASES)
+ return false;
+
+ return test_bit(base, bmap);
+}
+
static int riscv_ext_f_depends(const struct riscv_isa_ext_data *data,
const unsigned long *isa_bitmap)
{
@@ -1406,3 +1429,89 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
if (early)
local_flush_icache_all();
}
+
+/*
+ * Compute the set of bases a hart conforms to. Profile bases such as
+ * RVA23U64 are derived from its resolved ISA bitmap.
+ *
+ * If @isa_bitmap is NULL, the host ISA bitmap (the AND across all harts) is
+ * used.
+ */
+static void riscv_set_isa_bases(unsigned long *bases, const unsigned long *isa_bitmap)
+{
+ const unsigned long *isa = isa_bitmap ? isa_bitmap : riscv_isa;
+ DECLARE_BITMAP(ext_mask, RISCV_ISA_EXT_MAX) = { 0 };
+
+ /* The IMA base is behavior the kernel always provides. */
+ set_bit(RISCV_ISA_BASE_IMA, bases);
+
+ /* RVA23U64 */
+
+ /* Supm with PMLEN=7 */
+ if (!riscv_have_user_pmlen(7))
+ return;
+
+ __set_bit(RISCV_ISA_EXT_I, ext_mask);
+ __set_bit(RISCV_ISA_EXT_M, ext_mask);
+ __set_bit(RISCV_ISA_EXT_A, ext_mask);
+ __set_bit(RISCV_ISA_EXT_F, ext_mask);
+ __set_bit(RISCV_ISA_EXT_D, ext_mask);
+ __set_bit(RISCV_ISA_EXT_C, ext_mask);
+ __set_bit(RISCV_ISA_EXT_B, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICSR, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICNTR, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZIHPM, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICCIF, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICCRSE, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICCAMOA, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICCLSM, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZA64RS, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZIHINTPAUSE, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZIC64B, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICBOM, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICBOP, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICBOZ, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZFHMIN, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZKT, ext_mask);
+ __set_bit(RISCV_ISA_EXT_V, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZVFHMIN, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZVBB, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZVKT, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZIHINTNTL, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZICOND, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZIMOP, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZCMOP, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZCB, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZFA, ext_mask);
+ __set_bit(RISCV_ISA_EXT_ZAWRS, ext_mask);
+ __set_bit(RISCV_ISA_EXT_SUPM, ext_mask);
+
+ if (!bitmap_subset(ext_mask, isa, RISCV_ISA_EXT_MAX))
+ return;
+
+ set_bit(RISCV_ISA_BASE_RVA23U64, bases);
+}
+
+/*
+ * Populate the host ISA bases bitmap (riscv_isa_bases) and each
+ * hart's per-cpu isa_bases.
+ */
+static int __init riscv_init_isa_bases(void)
+{
+ int cpu;
+
+ for_each_possible_cpu(cpu)
+ riscv_set_isa_bases(hart_isa[cpu].isa_bases, hart_isa[cpu].isa);
+
+ riscv_set_isa_bases(riscv_isa_bases, NULL);
+ return 0;
+}
+
+/*
+ * Registered as arch_initcall: late enough that
+ * core_initcall(tagged_addr_init) has populated have_user_pmlen_*,
+ * and early enough that arch_initcall_sync(init_hwprobe_vdso_data)
+ * finds the ISA bases populated when it snapshots the hwprobe
+ * values into the vDSO data page.
+ */
+arch_initcall(riscv_init_isa_bases);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v9 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection
2026-11-09 12:47 ` [PATCH v9 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection Guodong Xu
@ 2026-11-09 15:56 ` Icenowy Zheng
0 siblings, 0 replies; 7+ messages in thread
From: Icenowy Zheng @ 2026-11-09 15:56 UTC (permalink / raw)
To: Guodong Xu, Jonathan Corbet, Shuah Khan, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Randy Dunlap,
Radim Krcmar
Cc: linux-doc, linux-riscv, linux-kernel, Paul Walmsley, Conor Dooley,
linux-kselftest, Andy Chiu, Florian Weimer, Peter Bergner,
Zihong Yao, Mark Harris, Aurelien Jarno, Andrew Jones
在 2026-11-09一的 07:47 -0500,Guodong Xu写道:
> Introduce a per-hart and host-wide bitmap of conformant ISA "bases"
> (named profile-class sets such as IMA and RVA23U64), computed at init
> time by riscv_init_isa_bases().
>
> The IMA base is set unconditionally: it is behavior the kernel always
> provides, and is intentionally not derived from the I, M and A
> extensions.
>
> Register riscv_init_isa_bases() as an arch_initcall. That is late
> enough that core_initcall(tagged_addr_init) has probed senvcfg.PMM
> and
> populated have_user_pmlen_*; without that ordering,
> riscv_have_user_pmlen(7) would still return its default false and the
> RVA23U64 detection path would always bail. It is also early enough
> that
> arch_initcall_sync(init_hwprobe_vdso_data) finds the bases populated
> when it snapshots the hwprobe values into the vDSO data page.
>
> Consider this as the cache that subsequent consumers (hwprobe's
> RVA23U64 base behavior bit, /proc/cpuinfo's "isa bases" lines, etc.)
> can read without recomputing, which keeps them consistent with
> each other.
>
> Co-developed-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
> Signed-off-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
> Signed-off-by: Guodong Xu <guodong.xu@oss.qualcomm.com>
> ---
> v9: Set the IMA base unconditionally; do not derive it from I, M and
> A.
> v8: Add Co-developed-by for Andrew Jones (Conor).
> v7:
> - Register riscv_init_isa_bases() at arch_initcall, ahead of the vDSO
> hwprobe snapshot at arch_initcall_sync; v6 returned 0 for
> RISCV_HWPROBE_KEY_BASE_BEHAVIOR through the vDSO.
> - Keep riscv_isa_bases static; add riscv_isa_base_available().
> v6: No change.
> v5: No change.
> v4:
> - In riscv_set_isa_base(), reorder those __setbit(RISCV_ISA_EXT_X,m)
> lines to make them conform to the order they appear in the RVA23
> 1.0
> Profile.
> v3:
> - Add a blank line before the subsys_initcall() registration
> (Andrew).
> - Set the local ext_mask with __set_bit() and test the mandate set
> with
> !bitmap_subset() (Sashiko).
> - Require the Zic64b ISA extension in the RVA23U64 mask,
> instead of open-coded cache block-size check. (New, thoughts from
> Andrew)
> v2:
> - Implement riscv_init_isa_bases() that runs at system init time,
> after tagged_addr_init() populates have_user_pmlen_*.
> - Split RVA23S64 placeholder into a future patch.
> ---
> arch/riscv/include/asm/cpufeature.h | 13 +++++
> arch/riscv/kernel/cpufeature.c | 109
> ++++++++++++++++++++++++++++++++++++
> 2 files changed, 122 insertions(+)
>
> diff --git a/arch/riscv/include/asm/cpufeature.h
> b/arch/riscv/include/asm/cpufeature.h
> index 99799cc6c198..2ce1a1e212c9 100644
> --- a/arch/riscv/include/asm/cpufeature.h
> +++ b/arch/riscv/include/asm/cpufeature.h
> @@ -25,8 +25,20 @@ struct riscv_cpuinfo {
> unsigned long mimpid;
> };
>
> +enum {
> + RISCV_ISA_BASE_IMA,
I may have missed something, but would it be worth to add a GC tier?
I think many Linux distros have GC defined as their baseline.
Thanks,
Icenowy
> + RISCV_ISA_BASE_RVA23U64,
> + RISCV_NR_ISA_BASES,
> +};
> +
> +/**
> + * struct riscv_isainfo - per-hart ISA state
> + * @isa: bitmap of ISA extensions this hart implements
> + * @isa_bases: bitmap of profile bases this hart conforms to
> + */
> struct riscv_isainfo {
> DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
> + DECLARE_BITMAP(isa_bases, RISCV_NR_ISA_BASES);
> };
>
> DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
> @@ -134,6 +146,7 @@ extern const size_t riscv_isa_ext_count;
> extern bool riscv_isa_fallback;
>
> unsigned long riscv_isa_extension_base(const unsigned long
> *isa_bitmap);
> +bool riscv_isa_base_available(const unsigned long *isa_bases,
> unsigned int base);
> static __always_inline bool riscv_cpu_has_extension_likely(int cpu,
> const unsigned long ext)
> {
> compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be <
> RISCV_ISA_EXT_MAX");
> diff --git a/arch/riscv/kernel/cpufeature.c
> b/arch/riscv/kernel/cpufeature.c
> index 72bce616491f..0377fc148785 100644
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c
> @@ -41,6 +41,9 @@ unsigned long elf_hwcap __read_mostly;
> /* Host ISA bitmap */
> DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
>
> +/* Host ISA bases bitmap */
> +static DECLARE_BITMAP(riscv_isa_bases, RISCV_NR_ISA_BASES)
> __read_mostly;
> +
> /* Per-cpu ISA extensions. */
> struct riscv_isainfo hart_isa[NR_CPUS];
>
> @@ -81,6 +84,26 @@ bool __riscv_isa_extension_available(const
> unsigned long *isa_bitmap, unsigned i
> }
> EXPORT_SYMBOL_GPL(__riscv_isa_extension_available);
>
> +/**
> + * riscv_isa_base_available() - Check whether a given ISA base is
> + * available or not
> + *
> + * @isa_bases: ISA bases bitmap to use
> + * @base: bit position of the desired ISA base
> + * Return: true or false
> + *
> + * NOTE: If isa_bases is NULL then the host ISA bases bitmap will be
> used.
> + */
> +bool riscv_isa_base_available(const unsigned long *isa_bases,
> unsigned int base)
> +{
> + const unsigned long *bmap = isa_bases ? isa_bases :
> riscv_isa_bases;
> +
> + if (base >= RISCV_NR_ISA_BASES)
> + return false;
> +
> + return test_bit(base, bmap);
> +}
> +
> static int riscv_ext_f_depends(const struct riscv_isa_ext_data
> *data,
> const unsigned long *isa_bitmap)
> {
> @@ -1406,3 +1429,89 @@ void __init_or_module
> riscv_cpufeature_patch_func(struct alt_entry *begin,
> if (early)
> local_flush_icache_all();
> }
> +
> +/*
> + * Compute the set of bases a hart conforms to. Profile bases such
> as
> + * RVA23U64 are derived from its resolved ISA bitmap.
> + *
> + * If @isa_bitmap is NULL, the host ISA bitmap (the AND across all
> harts) is
> + * used.
> + */
> +static void riscv_set_isa_bases(unsigned long *bases, const unsigned
> long *isa_bitmap)
> +{
> + const unsigned long *isa = isa_bitmap ? isa_bitmap :
> riscv_isa;
> + DECLARE_BITMAP(ext_mask, RISCV_ISA_EXT_MAX) = { 0 };
> +
> + /* The IMA base is behavior the kernel always provides. */
> + set_bit(RISCV_ISA_BASE_IMA, bases);
> +
> + /* RVA23U64 */
> +
> + /* Supm with PMLEN=7 */
> + if (!riscv_have_user_pmlen(7))
> + return;
> +
> + __set_bit(RISCV_ISA_EXT_I, ext_mask);
> + __set_bit(RISCV_ISA_EXT_M, ext_mask);
> + __set_bit(RISCV_ISA_EXT_A, ext_mask);
> + __set_bit(RISCV_ISA_EXT_F, ext_mask);
> + __set_bit(RISCV_ISA_EXT_D, ext_mask);
> + __set_bit(RISCV_ISA_EXT_C, ext_mask);
> + __set_bit(RISCV_ISA_EXT_B, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICSR, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICNTR, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZIHPM, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICCIF, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICCRSE, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICCAMOA, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICCLSM, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZA64RS, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZIHINTPAUSE, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZIC64B, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICBOM, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICBOP, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICBOZ, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZFHMIN, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZKT, ext_mask);
> + __set_bit(RISCV_ISA_EXT_V, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZVFHMIN, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZVBB, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZVKT, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZIHINTNTL, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZICOND, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZIMOP, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZCMOP, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZCB, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZFA, ext_mask);
> + __set_bit(RISCV_ISA_EXT_ZAWRS, ext_mask);
> + __set_bit(RISCV_ISA_EXT_SUPM, ext_mask);
> +
> + if (!bitmap_subset(ext_mask, isa, RISCV_ISA_EXT_MAX))
> + return;
> +
> + set_bit(RISCV_ISA_BASE_RVA23U64, bases);
> +}
> +
> +/*
> + * Populate the host ISA bases bitmap (riscv_isa_bases) and each
> + * hart's per-cpu isa_bases.
> + */
> +static int __init riscv_init_isa_bases(void)
> +{
> + int cpu;
> +
> + for_each_possible_cpu(cpu)
> + riscv_set_isa_bases(hart_isa[cpu].isa_bases,
> hart_isa[cpu].isa);
> +
> + riscv_set_isa_bases(riscv_isa_bases, NULL);
> + return 0;
> +}
> +
> +/*
> + * Registered as arch_initcall: late enough that
> + * core_initcall(tagged_addr_init) has populated have_user_pmlen_*,
> + * and early enough that arch_initcall_sync(init_hwprobe_vdso_data)
> + * finds the ISA bases populated when it snapshots the hwprobe
> + * values into the vDSO data page.
> + */
> +arch_initcall(riscv_init_isa_bases);
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v9 2/4] riscv: cpu: Output isa bases lines in cpuinfo
2026-11-09 12:47 [PATCH v9 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
2026-11-09 12:47 ` [PATCH v9 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection Guodong Xu
@ 2026-11-09 12:47 ` Guodong Xu
2026-11-09 12:47 ` [PATCH v9 3/4] riscv: hwprobe: Introduce rva23u64 base behavior Guodong Xu
2026-11-09 12:47 ` [PATCH v9 4/4] riscv: hwprobe: Document that keys describe the user-mode environment Guodong Xu
3 siblings, 0 replies; 7+ messages in thread
From: Guodong Xu @ 2026-11-09 12:47 UTC (permalink / raw)
To: Jonathan Corbet, Shuah Khan, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Randy Dunlap, Radim Krcmar
Cc: linux-doc, linux-riscv, linux-kernel, Paul Walmsley, Conor Dooley,
linux-kselftest, Andy Chiu, Florian Weimer, Peter Bergner,
Zihong Yao, Mark Harris, Aurelien Jarno, Guodong Xu, Andrew Jones
From: Andrew Jones <andrew.jones@oss.qualcomm.com>
The "isa" line in /proc/cpuinfo lists a hart's extensions as
concatenated string, but not which profile base it satisfies. Add two
lines that report them directly:
isa bases : <bases that all harts conform to>
hart isa bases : <bases that this specific hart conforms to>
Example output on qemu booted with -cpu rva23s64,sv39=on,pmp=on:
processor : 0
hart : 4
isa bases : rv64ima rva23u64
isa : rv64imafdcbvh_zicbom_zicbop_...
...
hart isa bases : rv64ima rva23u64
hart isa : rv64imafdcbvh_zicbom_zicbop_...
Signed-off-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
Co-developed-by: Guodong Xu <guodong.xu@oss.qualcomm.com>
Signed-off-by: Guodong Xu <guodong.xu@oss.qualcomm.com>
---
v9: No change.
v8: Andrew is the author; add my Co-developed-by (Conor).
v7: Use riscv_isa_base_available().
v6: No change.
v5: Simplified the commit message.
v4: No change.
v3: No change.
v2:
- Read from the cached riscv_isa_bases and hart_isa[cpu_id].isa_bases
bitmaps populated by riscv_init_isa_bases() at init time.
---
arch/riscv/kernel/cpu.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
index af84b97af3a1..75761fc9f09a 100644
--- a/arch/riscv/kernel/cpu.c
+++ b/arch/riscv/kernel/cpu.c
@@ -305,6 +305,26 @@ static void print_mmu(struct seq_file *f)
seq_printf(f, "mmu\t\t: %s\n", sv_type);
}
+static const char * const riscv_isa_base_names[] = {
+#ifdef CONFIG_32BIT
+ [RISCV_ISA_BASE_IMA] = "rv32ima",
+#else
+ [RISCV_ISA_BASE_IMA] = "rv64ima",
+#endif
+ [RISCV_ISA_BASE_RVA23U64] = "rva23u64",
+};
+
+static void print_isa_bases(struct seq_file *m, const unsigned long *isa_bases)
+{
+ unsigned int i;
+
+ for (i = 0; i < RISCV_NR_ISA_BASES; i++) {
+ if (riscv_isa_base_available(isa_bases, i))
+ seq_printf(m, " %s", riscv_isa_base_names[i]);
+ }
+ seq_puts(m, "\n");
+}
+
static void *c_start(struct seq_file *m, loff_t *pos)
{
if (*pos == nr_cpu_ids)
@@ -336,6 +356,9 @@ static int c_show(struct seq_file *m, void *v)
seq_printf(m, "processor\t: %lu\n", cpu_id);
seq_printf(m, "hart\t\t: %lu\n", cpuid_to_hartid_map(cpu_id));
+ seq_puts(m, "isa bases\t:");
+ print_isa_bases(m, NULL);
+
/*
* For historical raisins, the isa: line is limited to the lowest common
* denominator of extensions supported across all harts. A true list of
@@ -360,6 +383,9 @@ static int c_show(struct seq_file *m, void *v)
seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
+ seq_puts(m, "hart isa bases\t:");
+ print_isa_bases(m, hart_isa[cpu_id].isa_bases);
+
/*
* Print the ISA extensions specific to this hart, which may show
* additional extensions not present across all harts.
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v9 3/4] riscv: hwprobe: Introduce rva23u64 base behavior
2026-11-09 12:47 [PATCH v9 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
2026-11-09 12:47 ` [PATCH v9 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection Guodong Xu
2026-11-09 12:47 ` [PATCH v9 2/4] riscv: cpu: Output isa bases lines in cpuinfo Guodong Xu
@ 2026-11-09 12:47 ` Guodong Xu
2026-11-17 13:09 ` Radim Krcmar
2026-11-09 12:47 ` [PATCH v9 4/4] riscv: hwprobe: Document that keys describe the user-mode environment Guodong Xu
3 siblings, 1 reply; 7+ messages in thread
From: Guodong Xu @ 2026-11-09 12:47 UTC (permalink / raw)
To: Jonathan Corbet, Shuah Khan, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Randy Dunlap, Radim Krcmar
Cc: linux-doc, linux-riscv, linux-kernel, Paul Walmsley, Conor Dooley,
linux-kselftest, Andy Chiu, Florian Weimer, Peter Bergner,
Zihong Yao, Mark Harris, Aurelien Jarno, Guodong Xu, Andrew Jones
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@oss.qualcomm.com>
Signed-off-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
Signed-off-by: Guodong Xu <guodong.xu@oss.qualcomm.com>
---
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.
v8:
- Add Co-developed-by for Andrew Jones (Conor).
- Say in the body that the IMA bit is now computed, not hardcoded.
- Rebase onto riscv/for-next: drop the BASE_BEHAVIOR case's own
pair->value = 0; hwprobe_one_pair() zeroes it since commit
d0fc6fab2046 ("riscv: hwprobe: initialize pair->value in
hwprobe_one_pair()").
v7: Use riscv_isa_base_available().
v6: Rebase onto riscv/for-next: define
RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64 in the _BITULL() style of
commit 8da45c93dfa9.
v5: No change.
v4: No change.
v3: No change.
v2:
- Detect RVA23U64 by reading from the cached hart_isa[].isa_bases
bitmap populated by riscv_init_isa_bases() at init time, sharing
one source of truth with /proc/cpuinfo.
---
Documentation/arch/riscv/hwprobe.rst | 8 +++++
arch/riscv/include/uapi/asm/hwprobe.h | 3 +-
arch/riscv/kernel/sys_hwprobe.c | 34 ++++++++++++++++++++--
tools/testing/selftests/riscv/hwprobe/which-cpus.c | 2 +-
4 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst
index 8454a6ae6fd15..c24630c672c43 100644
--- a/Documentation/arch/riscv/hwprobe.rst
+++ b/Documentation/arch/riscv/hwprobe.rst
@@ -67,6 +67,14 @@ * :c:macro:`RISCV_HWPROBE_KEY_BASE_BEHAVIOR`: A bitmask containing the base
programs (it may still be executed in userspace via a
kernel-controlled mechanism such as the vDSO).
+ * :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64`: Support for all mandatory
+ extensions of RVA23U64, as defined in the RISC-V Profiles specification
+ starting from commit 0273f3c921b6 ("rva23/rvb23 ratified").
+
+ Each base behavior bit is reported independently of the others.
+ Hardware that implements a later profile whose mandatory set includes
+ RVA23U64 therefore reports RVA23U64 as well.
+
* :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`: A bitmask containing extensions
that are compatible with the :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`:
base system behavior.
diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h
index 9a121ee3b4369..4f5d51788c416 100644
--- a/arch/riscv/include/uapi/asm/hwprobe.h
+++ b/arch/riscv/include/uapi/asm/hwprobe.h
@@ -22,7 +22,8 @@ struct riscv_hwprobe {
#define RISCV_HWPROBE_KEY_MARCHID 1
#define RISCV_HWPROBE_KEY_MIMPID 2
#define RISCV_HWPROBE_KEY_BASE_BEHAVIOR 3
-#define RISCV_HWPROBE_BASE_BEHAVIOR_IMA _BITULL(0)
+#define RISCV_HWPROBE_BASE_BEHAVIOR_IMA _BITULL(0)
+#define RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64 _BITULL(1)
#define RISCV_HWPROBE_KEY_IMA_EXT_0 4
#define RISCV_HWPROBE_IMA_FD _BITULL(0)
#define RISCV_HWPROBE_IMA_C _BITULL(1)
diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c
index cd7cf272e6e11..5be5776b48e6e 100644
--- a/arch/riscv/kernel/sys_hwprobe.c
+++ b/arch/riscv/kernel/sys_hwprobe.c
@@ -223,6 +223,32 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext)
return (pair.value & ext);
}
+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;
+
+ for_each_cpu(cpu, cpus) {
+ if (!riscv_isa_base_available(hart_isa[cpu].isa_bases, base))
+ return false;
+ }
+ return true;
+}
+
#if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS)
static u64 hwprobe_misaligned(const struct cpumask *cpus)
{
@@ -309,12 +335,14 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
break;
/*
* The kernel already assumes that the base single-letter ISA
- * extensions are supported on all harts, and only supports the
- * IMA base, so just cheat a bit here and tell that to
- * userspace.
+ * extensions are supported on all harts, so just cheat a bit
+ * here and tell that to userspace. Other bases are reported
+ * only when detected.
*/
case RISCV_HWPROBE_KEY_BASE_BEHAVIOR:
pair->value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA;
+ if (hwprobe_has_isa_base(cpus, RISCV_ISA_BASE_RVA23U64))
+ pair->value |= RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64;
break;
case RISCV_HWPROBE_KEY_IMA_EXT_0:
diff --git a/tools/testing/selftests/riscv/hwprobe/which-cpus.c b/tools/testing/selftests/riscv/hwprobe/which-cpus.c
index 587feb198c049..f8c797b1d0fd9 100644
--- a/tools/testing/selftests/riscv/hwprobe/which-cpus.c
+++ b/tools/testing/selftests/riscv/hwprobe/which-cpus.c
@@ -105,7 +105,7 @@ int main(int argc, char **argv)
pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, };
rc = riscv_hwprobe(pairs, 1, 0, NULL, 0);
assert(rc == 0 && pairs[0].key == RISCV_HWPROBE_KEY_BASE_BEHAVIOR &&
- pairs[0].value == RISCV_HWPROBE_BASE_BEHAVIOR_IMA);
+ (pairs[0].value & RISCV_HWPROBE_BASE_BEHAVIOR_IMA));
pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, };
rc = riscv_hwprobe(pairs, 1, 0, NULL, 0);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v9 3/4] riscv: hwprobe: Introduce rva23u64 base behavior
2026-11-09 12:47 ` [PATCH v9 3/4] riscv: hwprobe: Introduce rva23u64 base behavior Guodong Xu
@ 2026-11-17 13:09 ` Radim Krcmar
0 siblings, 0 replies; 7+ messages in thread
From: Radim Krcmar @ 2026-11-17 13:09 UTC (permalink / raw)
To: Guodong Xu
Cc: Jonathan Corbet, Shuah Khan, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Randy Dunlap,
linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, Paul Walmsley, Conor Dooley,
linux-kselftest@vger.kernel.org, Andy Chiu, Florian Weimer,
Peter Bergner, Zihong Yao, Mark Harris, Aurelien Jarno,
Andrew Jones, linux-riscv
2026-11-09T07:47:36-05:00, Guodong Xu <guodong.xu@oss.qualcomm.com>:
> 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@oss.qualcomm.com>
> Signed-off-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
> Signed-off-by: Guodong Xu <guodong.xu@oss.qualcomm.com>
> ---
> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v9 4/4] riscv: hwprobe: Document that keys describe the user-mode environment
2026-11-09 12:47 [PATCH v9 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
` (2 preceding siblings ...)
2026-11-09 12:47 ` [PATCH v9 3/4] riscv: hwprobe: Introduce rva23u64 base behavior Guodong Xu
@ 2026-11-09 12:47 ` Guodong Xu
3 siblings, 0 replies; 7+ messages in thread
From: Guodong Xu @ 2026-11-09 12:47 UTC (permalink / raw)
To: Jonathan Corbet, Shuah Khan, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Randy Dunlap, Radim Krcmar
Cc: linux-doc, linux-riscv, linux-kernel, Paul Walmsley, Conor Dooley,
linux-kselftest, Andy Chiu, Florian Weimer, Peter Bergner,
Zihong Yao, Mark Harris, Aurelien Jarno, Guodong Xu
Every extension key in hwprobe.rst says the extension "is supported",
which leaves open whether hwprobe answers "does the hardware implement
it" or "can user mode use it". The two differ for extensions that need
a higher-privilege enable, such as F, D, V, Zicbom, Zicboz and Supm.
sys_hwprobe.c already gives the second answer for IMA_FD and IMA_V, and
the "do not report disabled extensions" fixes [1] bring the remaining
keys to the same reading. The base behavior keys inherit it, as
discussed with Radim on v8 [2]: a base behavior is only usable when
every extension in its set is.
State the rule once, in a note before the key list, instead of
rewording every per-key "is supported".
Link: https://lore.kernel.org/linux-riscv/20261006075303.205216-1-radim.krcmar@oss.qualcomm.com/ [1]
Link: https://lore.kernel.org/linux-riscv/DLUD4XZN9F16.2LBMTP1H5Q1VC@qti.qualcomm.com/ [2]
Signed-off-by: Guodong Xu <guodong.xu@oss.qualcomm.com>
---
v9: New patch.
Note: this patch states the rule for all hwprobe keys, but some keys
only follow it with Radim's series [1]. I am fine with this patch being
applied after [1].
---
Documentation/arch/riscv/hwprobe.rst | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst
index c24630c672c4..30dbbbc27477 100644
--- a/Documentation/arch/riscv/hwprobe.rst
+++ b/Documentation/arch/riscv/hwprobe.rst
@@ -45,6 +45,27 @@ On success 0 is returned, on failure a negative error code is returned.
The following keys are defined:
+.. note::
+ The base behavior and extension keys,
+ :c:macro:`RISCV_HWPROBE_KEY_BASE_BEHAVIOR`,
+ :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`,
+ :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_1` and the
+ ``RISCV_HWPROBE_KEY_VENDOR_EXT_*`` keys, describe the execution
+ environment the kernel provides to user mode, not the hardware as
+ such. An extension bit is set only when user-mode code can use the
+ extension on the selected CPUs: it is implemented, and the kernel
+ either has set any higher-privilege enable it controls (for example
+ in ``sstatus`` or ``senvcfg``) or leaves that choice to the user, as
+ with Zicfilp and Zicfiss. An extension the hardware implements but
+ the kernel does not make available to user mode, whether because of
+ the kernel configuration, a boot parameter, or because not every
+ hart implements it, is not reported. Conversely, an extension user
+ mode has turned off for itself is still reported: the keys describe
+ what is available to user mode, not the current state of the calling
+ task. A base behavior bit is set only when every mandatory
+ extension of that base is usable in this sense. "Supported" in the
+ descriptions of these keys is to be read accordingly.
+
* :c:macro:`RISCV_HWPROBE_KEY_MVENDORID`: Contains the value of ``mvendorid``,
as defined by the RISC-V privileged architecture specification.
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread