* [PATCH v10 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection
2026-11-26 21:32 [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
@ 2026-11-26 21:32 ` Guodong Xu
2026-11-26 21:32 ` [PATCH v10 2/4] riscv: cpu: Output isa bases lines in cpuinfo Guodong Xu
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Guodong Xu @ 2026-11-26 21:32 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,
Icenowy Zheng, Guodong Xu, Andrew Jones
Introduce a per-hart and host-wide bitmap of conformant ISA "bases"
(named profiles such as RVA23U64, plus the IMA base), 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.
Consider this as the cache that consumers such as /proc/cpuinfo's "isa
bases" lines read without recomputing.
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>
---
v10:
- Reword the commit message and the arch_initcall comment: the bitmap
feeds /proc/cpuinfo; hwprobe derives RVA23U64 from its own keys.
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 | 106 ++++++++++++++++++++++++++++++++++++
2 files changed, 119 insertions(+)
diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h
index 99799cc6c1984..2ce1a1e212c9d 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 72bce616491f1..d63a70c387019 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,86 @@ 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_*.
+ */
+arch_initcall(riscv_init_isa_bases);
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v10 2/4] riscv: cpu: Output isa bases lines in cpuinfo
2026-11-26 21:32 [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
2026-11-26 21:32 ` [PATCH v10 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection Guodong Xu
@ 2026-11-26 21:32 ` Guodong Xu
2026-11-26 21:32 ` [PATCH v10 3/4] riscv: hwprobe: Introduce rva23u64 base behavior Guodong Xu
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Guodong Xu @ 2026-11-26 21:32 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,
Icenowy Zheng, 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>
---
v10: No change.
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 af84b97af3a19..75761fc9f09ab 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 [flat|nested] 6+ messages in thread* [PATCH v10 3/4] riscv: hwprobe: Introduce rva23u64 base behavior
2026-11-26 21:32 [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
2026-11-26 21:32 ` [PATCH v10 1/4] riscv: cpufeature: Introduce ISA bases bitmap and rva23u64 detection Guodong Xu
2026-11-26 21:32 ` [PATCH v10 2/4] riscv: cpu: Output isa bases lines in cpuinfo Guodong Xu
@ 2026-11-26 21:32 ` Guodong Xu
2026-11-26 21:32 ` [PATCH v10 4/4] riscv: hwprobe: Document that keys describe the user-mode environment Guodong Xu
2026-12-01 18:10 ` [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Frédéric Mahé
4 siblings, 0 replies; 6+ messages in thread
From: Guodong Xu @ 2026-11-26 21:32 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,
Icenowy Zheng, 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 PMLEN=7 is selectable and
all RVA23U64 mandatory extensions are reported for them in the
IMA_EXT_0 and IMA_EXT_1 keys (I, M and A are the IMA base; Zicsr is
implied by F). Any host-wide decision behind those keys, such as F,
D, C and V being disabled when one hart lacks them, therefore applies
to the RVA23U64 hwprobe bit as well.
Suggested-by: Radim Krcmar <rkrcmar@qti.qualcomm.com>
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>
---
v10:
- Add Suggested-by for Radim.
- Report RVA23U64 as a function of the IMA_EXT_0 and IMA_EXT_1 bits
plus PMLEN=7, instead of the isa_bases bitmap. The separate
host-wide gate is no longer needed: the keys already apply it
(Radim).
- hwprobe_ext0_has() takes a mask; add hwprobe_ext1_has().
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 | 54 ++++++++++++++++++++--
tools/testing/selftests/riscv/hwprobe/which-cpus.c | 2 +-
4 files changed, 60 insertions(+), 7 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..f9c1abcb7139e 100644
--- a/arch/riscv/kernel/sys_hwprobe.c
+++ b/arch/riscv/kernel/sys_hwprobe.c
@@ -29,6 +29,31 @@
missing |= RISCV_HWPROBE_EXT_##ext; \
} while (false)
+/*
+ * Together with the IMA base (I, M and A), these masks list every
+ * RVA23U64 mandatory extension. Zicsr has no hwprobe bit; the RISC-V
+ * Profiles specification, commit 0273f3c921b6 ("rva23/rvb23 ratified"),
+ * notes it is implied by F. Supm needs PMLEN=7 on top, see
+ * hwprobe_has_rva23u64().
+ */
+#define RVA23U64_EXT0 (RISCV_HWPROBE_IMA_FD | RISCV_HWPROBE_IMA_C | \
+ RISCV_HWPROBE_EXT_ZICNTR | RISCV_HWPROBE_EXT_ZIHPM | \
+ RISCV_HWPROBE_EXT_ZIHINTPAUSE | \
+ RISCV_HWPROBE_EXT_ZICBOM | RISCV_HWPROBE_EXT_ZICBOP | \
+ RISCV_HWPROBE_EXT_ZICBOZ | RISCV_HWPROBE_EXT_ZFHMIN | \
+ RISCV_HWPROBE_EXT_ZKT | RISCV_HWPROBE_IMA_V | \
+ RISCV_HWPROBE_EXT_ZVFHMIN | RISCV_HWPROBE_EXT_ZVBB | \
+ RISCV_HWPROBE_EXT_ZVKT | RISCV_HWPROBE_EXT_ZIHINTNTL | \
+ RISCV_HWPROBE_EXT_ZICOND | RISCV_HWPROBE_EXT_ZIMOP | \
+ RISCV_HWPROBE_EXT_ZCMOP | RISCV_HWPROBE_EXT_ZCB | \
+ RISCV_HWPROBE_EXT_ZFA | RISCV_HWPROBE_EXT_ZAWRS | \
+ RISCV_HWPROBE_EXT_SUPM)
+#define RVA23U64_EXT1 (RISCV_HWPROBE_EXT_B | RISCV_HWPROBE_EXT_ZICCIF | \
+ RISCV_HWPROBE_EXT_ZICCRSE | \
+ RISCV_HWPROBE_EXT_ZICCAMOA | \
+ RISCV_HWPROBE_EXT_ZICCLSM | RISCV_HWPROBE_EXT_ZA64RS | \
+ RISCV_HWPROBE_EXT_ZIC64B)
+
static void hwprobe_arch_id(struct riscv_hwprobe *pair,
const struct cpumask *cpus)
{
@@ -215,12 +240,29 @@ static void hwprobe_isa_ext1(struct riscv_hwprobe *pair,
pair->value &= ~missing;
}
-static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext)
+/* Return true iff every extension in @exts is reported for @cpus. */
+static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 exts)
{
struct riscv_hwprobe pair;
hwprobe_isa_ext0(&pair, cpus);
- return (pair.value & ext);
+ return (pair.value & exts) == exts;
+}
+
+/* Same, for the IMA_EXT_1 key. */
+static bool hwprobe_ext1_has(const struct cpumask *cpus, u64 exts)
+{
+ struct riscv_hwprobe pair;
+
+ hwprobe_isa_ext1(&pair, cpus);
+ return (pair.value & exts) == exts;
+}
+
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+ return riscv_have_user_pmlen(7) &&
+ hwprobe_ext0_has(cpus, RVA23U64_EXT0) &&
+ hwprobe_ext1_has(cpus, RVA23U64_EXT1);
}
#if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS)
@@ -309,12 +351,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_rva23u64(cpus))
+ 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 [flat|nested] 6+ messages in thread* [PATCH v10 4/4] riscv: hwprobe: Document that keys describe the user-mode environment
2026-11-26 21:32 [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
` (2 preceding siblings ...)
2026-11-26 21:32 ` [PATCH v10 3/4] riscv: hwprobe: Introduce rva23u64 base behavior Guodong Xu
@ 2026-11-26 21:32 ` Guodong Xu
2026-12-01 18:10 ` [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Frédéric Mahé
4 siblings, 0 replies; 6+ messages in thread
From: Guodong Xu @ 2026-11-26 21:32 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,
Icenowy Zheng, Guodong Xu, Andrew Jones
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>
---
v10: No change.
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 c24630c672c43..30dbbbc274775 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 [flat|nested] 6+ messages in thread* Re: [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior
2026-11-26 21:32 [PATCH v10 0/4] riscv: hwprobe: Expose RVA23U64 base behavior Guodong Xu
` (3 preceding siblings ...)
2026-11-26 21:32 ` [PATCH v10 4/4] riscv: hwprobe: Document that keys describe the user-mode environment Guodong Xu
@ 2026-12-01 18:10 ` Frédéric Mahé
4 siblings, 0 replies; 6+ messages in thread
From: Frédéric Mahé @ 2026-12-01 18:10 UTC (permalink / raw)
To: Guodong Xu
Cc: Frédéric Mahé,
Jonathan Corbet, Shuah Khan, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Radim Krcmar, Andrew Jones,
Aurelien Jarno, linux-kselftest, linux-riscv, linux-kernel
Hi Guodong,
Tested v10 on a Banana Pi BPI-F3 (SpacemiT K1, RVA22 with V), v7.4-rc5:
/proc/cpuinfo shows "isa bases: rv64ima" and hwprobe BASE_BEHAVIOR
returns IMA only, without RVA23U64, as expected for this SoC. The riscv
hwprobe selftests pass.
Testing done with the help of Claude (AI assistant).
Tested-by: Frédéric Mahé <frederic.mahe@cirad.fr> # BPI-F3
Frédéric
^ permalink raw reply [flat|nested] 6+ messages in thread