Skip to contentSkip to conversation

riscv: hwprobe: Introduce rva23u64 base behavior

RFC PATCH In review Andrew Jones 5 participants 36 messages Feb 6 – Mar 6

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover riscv: hwprobe: Introduce rva23u64 base behavior

Users need a way determine that their harts conform to rva23u64 that isn't error-prone. While patches 2 and 6 make it possible to determine, it requires a bunch of probes and checks themselves (see patch9 for the recipe). This RFC proposes adding an RVA23U64 hwprobe base behavior (patch8) allowing easy determination. It also proposes adding the bases to /proc/cpuinfo (patches 10 and 11) -- but those two patches are probably even more RFCy than the hwprobe proposal...

The first three patches have been posted previously by their respective authors and are currently under active review (except patch2 which appears to have gotten lost in the shuffle). I've collected these patches into the series since they're necessary for the base and because I wanted to repost patch2 and patch3 with some changes. patch4 and patch6 expose more extensions to userspace. patch9 adds a consistency test for the new hwprobe base behavior bit.

Thanks,
drew

Andrew Jones (8):
riscv: Add B to hwcap
riscv: hwprobe.rst: Replace tabs with spaces
riscv: Add Ziccamoa, Ziccif, Ziccrse, and Za64rs to hwprobe
riscv: Export have_user_pmlen* booleans
riscv: hwprobe: Introduce rva23u64 base behavior
riscv: selftests: hwprobe: Check rva23u64 consistency
riscv: /proc/cpuinfo: Add rva23 bases to output
riscv: /proc/cpuinfo: Also output rva20 and rva22 isa bases

Charlie Jenkins (1):
riscv: Standardize extension capitilization

Jesse Taube (1):
RISC-V: Add Zicclsm to cpufeature and hwprobe

Paul Walmsley (1):
riscv: hwprobe: add support for RISCV_HWPROBE_KEY_IMA_EXT_1

 Documentation/arch/riscv/hwprobe.rst          |  42 ++-
 arch/riscv/include/asm/cpufeature.h           |  14 +
 arch/riscv/include/asm/hwcap.h                |  23 +-
 arch/riscv/include/asm/hwprobe.h              |   3 +-
 arch/riscv/include/asm/switch_to.h            |   4 +-
 arch/riscv/include/uapi/asm/hwcap.h           |   1 +
 arch/riscv/include/uapi/asm/hwprobe.h         |   9 +-
 arch/riscv/kernel/cpu.c                       |  38 +++
 arch/riscv/kernel/cpufeature.c                | 168 ++++++++++--
 arch/riscv/kernel/process.c                   |  12 +-
 arch/riscv/kernel/sys_hwprobe.c               | 249 +++++++++++++-----
 arch/riscv/kvm/main.c                         |   2 +-
 arch/riscv/kvm/vcpu_fp.c                      |  28 +-
 arch/riscv/kvm/vcpu_onereg.c                  |  22 +-
 arch/riscv/kvm/vcpu_vector.c                  |  14 +-
 .../testing/selftests/riscv/hwprobe/hwprobe.c | 112 +++++++-
 .../selftests/riscv/hwprobe/which-cpus.c      |  20 +-
 17 files changed, 610 insertions(+), 151 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/11 riscv: hwprobe: add support for RISCV_HWPROBE_KEY_IMA_EXT_1

From: Paul Walmsley <[email protected]>

We've run out of bits to describe RISC-V ISA extensions in our initial hwprobe key, RISCV_HWPROBE_KEY_IMA_EXT_0. So, let's add RISCV_HWPROBE_KEY_IMA_EXT_1, along with the framework to set the appropriate hwprobe tuple, and add testing for it.

---
 Documentation/arch/riscv/hwprobe.rst          |   4 +
 arch/riscv/include/asm/hwprobe.h              |   3 +-
 arch/riscv/include/uapi/asm/hwprobe.h         |   1 +
 arch/riscv/kernel/sys_hwprobe.c               | 169 +++++++++++-------
 .../selftests/riscv/hwprobe/which-cpus.c      |  18 +-
 5 files changed, 120 insertions(+), 75 deletions(-)
Documentation/arch/riscv/hwprobe.rst +4 -0
index 641ec4abb906..03484a2546da 100644
@@ -387,3 +387,7 @@ The following keys are defined:
 
 * :c:macro:`RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE`: An unsigned int which
   represents the size of the Zicbop block in bytes.
+
+* :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_1`: A bitmask containing additional
+  extensions that are compatible with the
+  :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`: base system behavior.
arch/riscv/include/asm/hwprobe.h +2 -1
index 8c572a464719..8b9f5e1cf4cb 100644
@@ -8,7 +8,7 @@
 
 #include <uapi/asm/hwprobe.h>
 
-#define RISCV_HWPROBE_MAX_KEY 15
+#define RISCV_HWPROBE_MAX_KEY		16
 
 static inline bool riscv_hwprobe_key_is_valid(__s64 key)
 {
@@ -20,6 +20,7 @@ static inline bool hwprobe_key_is_bitmask(__s64 key)
 	switch (key) {
 	case RISCV_HWPROBE_KEY_BASE_BEHAVIOR:
 	case RISCV_HWPROBE_KEY_IMA_EXT_0:
+	case RISCV_HWPROBE_KEY_IMA_EXT_1:
 	case RISCV_HWPROBE_KEY_CPUPERF_0:
 	case RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0:
 	case RISCV_HWPROBE_KEY_VENDOR_EXT_MIPS_0:
arch/riscv/include/uapi/asm/hwprobe.h +1 -0
index cd3c126730c3..ed2621a5a47d 100644
@@ -113,6 +113,7 @@ struct riscv_hwprobe {
 #define RISCV_HWPROBE_KEY_VENDOR_EXT_SIFIVE_0	13
 #define RISCV_HWPROBE_KEY_VENDOR_EXT_MIPS_0	14
 #define RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE	15
+#define RISCV_HWPROBE_KEY_IMA_EXT_1		16
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
 /* Flags */
arch/riscv/kernel/sys_hwprobe.c +100 -69

202 lines not on this page · raw message

tools/testing/selftests/riscv/hwprobe/which-cpus.c +13 -5
index 3ab53067e8dd..587feb198c04 100644
@@ -83,9 +83,9 @@ static void do_which_cpus(int argc, char **argv, cpu_set_t *cpus)
 
 int main(int argc, char **argv)
 {
-	struct riscv_hwprobe pairs[2];
+	struct riscv_hwprobe pairs[3];
 	cpu_set_t cpus_aff, cpus;
-	__u64 ext0_all;
+	__u64 ext0_all, ext1_all;
 	long rc;
 
 	rc = sched_getaffinity(0, sizeof(cpu_set_t), &cpus_aff);
@@ -112,6 +112,11 @@ int main(int argc, char **argv)
 	assert(rc == 0 && pairs[0].key == RISCV_HWPROBE_KEY_IMA_EXT_0);
 	ext0_all = pairs[0].value;
 
+	pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, };
+	rc = riscv_hwprobe(pairs, 1, 0, NULL, 0);
+	assert(rc == 0 && pairs[0].key == RISCV_HWPROBE_KEY_IMA_EXT_1);
+	ext1_all = pairs[0].value;
+
 	pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, .value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA, };
 	CPU_ZERO(&cpus);
 	rc = riscv_hwprobe(pairs, 1, 0, (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
@@ -134,20 +139,23 @@ int main(int argc, char **argv)
 
 	pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, .value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA, };
 	pairs[1] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, .value = ext0_all, };
+	pairs[2] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, .value = ext1_all, };
 	CPU_ZERO(&cpus);
-	rc = riscv_hwprobe(pairs, 2, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
+	rc = riscv_hwprobe(pairs, 3, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
 	ksft_test_result(rc == 0 && CPU_COUNT(&cpus) == sysconf(_SC_NPROCESSORS_ONLN), "set all cpus\n");
 
 	pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, .value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA, };
 	pairs[1] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, .value = ext0_all, };
+	pairs[2] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, .value = ext1_all, };
 	memcpy(&cpus, &cpus_aff, sizeof(cpu_set_t));
-	rc = riscv_hwprobe(pairs, 2, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
+	rc = riscv_hwprobe(pairs, 3, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
 	ksft_test_result(rc == 0 && CPU_EQUAL(&cpus, &cpus_aff), "set all affinity cpus\n");
 
 	pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, .value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA, };
 	pairs[1] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, .value = ~ext0_all, };
+	pairs[2] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, .value = ~ext1_all, };
 	memcpy(&cpus, &cpus_aff, sizeof(cpu_set_t));
-	rc = riscv_hwprobe(pairs, 2, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
+	rc = riscv_hwprobe(pairs, 3, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
 	ksft_test_result(rc == 0 && CPU_COUNT(&cpus) == 0, "clear all cpus\n");
 
 	ksft_finished();
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH 2/11 RISC-V: Add Zicclsm to cpufeature and hwprobe

In reply to Andrew Jones

From: Jesse Taube <[email protected]>

Zicclsm requires misaligned support for all regular load and store instructions, both scalar and vector, but not AMOs or other specialized forms of memory access, to main memory regions with both the cacheability and coherence PMAs, as defined in the profiles spec. Even though mandated, misaligned loads and stores might execute extremely slowly. Standard software distributions should assume their existence only for correctness, not for performance.

---
 Documentation/arch/riscv/hwprobe.rst  | 4 ++++
 arch/riscv/include/asm/hwcap.h        | 1 +
 arch/riscv/include/uapi/asm/hwprobe.h | 1 +
 arch/riscv/kernel/cpufeature.c        | 1 +
 arch/riscv/kernel/sys_hwprobe.c       | 1 +
 5 files changed, 8 insertions(+)
Documentation/arch/riscv/hwprobe.rst +4 -0
index 03484a2546da..0598c9ddd73f 100644
@@ -289,6 +289,10 @@ The following keys are defined:
        defined in the RISC-V ISA manual starting from commit f88abf1 ("Integrating
        load/store pair for RV32 with the main manual") of the riscv-isa-manual.
 
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCLSM`: The Zicclsm extension is supported,
+       as defined in the RISC-V Profiles specification starting from commit
+       b1d80660 ("Updated to ratified state.")
+
 * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated.  Returns similar values to
      :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
      mistakenly classified as a bitmask rather than a value.
arch/riscv/include/asm/hwcap.h +1 -0
index 4369a2338541..496694d3e182 100644
@@ -110,6 +110,7 @@
 #define RISCV_ISA_EXT_ZALASR		101
 #define RISCV_ISA_EXT_ZILSD		102
 #define RISCV_ISA_EXT_ZCLSD		103
+#define RISCV_ISA_EXT_ZICCLSM		104
 
 #define RISCV_ISA_EXT_XLINUXENVCFG	127
 
arch/riscv/include/uapi/asm/hwprobe.h +1 -0
index ed2621a5a47d..6a0163b54718 100644
@@ -86,6 +86,7 @@ struct riscv_hwprobe {
 #define		RISCV_HWPROBE_EXT_ZICBOP	(1ULL << 60)
 #define		RISCV_HWPROBE_EXT_ZILSD		(1ULL << 61)
 #define		RISCV_HWPROBE_EXT_ZCLSD		(1ULL << 62)
+#define		RISCV_HWPROBE_EXT_ZICCLSM	(1ULL << 63)
 
 #define RISCV_HWPROBE_KEY_CPUPERF_0	5
 #define		RISCV_HWPROBE_MISALIGNED_UNKNOWN	(0 << 0)
arch/riscv/kernel/cpufeature.c +1 -0
index fa591aff9d33..cf27b7a2547f 100644
@@ -481,6 +481,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate),
 	__RISCV_ISA_EXT_DATA_VALIDATE(zicbop, RISCV_ISA_EXT_ZICBOP, riscv_ext_zicbop_validate),
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate),
+	__RISCV_ISA_EXT_DATA(zicclsm, RISCV_ISA_EXT_ZICCLSM),
 	__RISCV_ISA_EXT_DATA(ziccrse, RISCV_ISA_EXT_ZICCRSE),
 	__RISCV_ISA_EXT_DATA(zicntr, RISCV_ISA_EXT_ZICNTR),
 	__RISCV_ISA_EXT_DATA(zicond, RISCV_ISA_EXT_ZICOND),
arch/riscv/kernel/sys_hwprobe.c +1 -0
index 53731ace7984..1423b447fe9a 100644
@@ -126,6 +126,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,
 		EXT_KEY(isainfo->isa, ZICBOM, pair->value, missing);
 		EXT_KEY(isainfo->isa, ZICBOP, pair->value, missing);
 		EXT_KEY(isainfo->isa, ZICBOZ, pair->value, missing);
+		EXT_KEY(isainfo->isa, ZICCLSM, pair->value, missing);
 		EXT_KEY(isainfo->isa, ZICNTR, pair->value, missing);
 		EXT_KEY(isainfo->isa, ZICOND, pair->value, missing);
 		EXT_KEY(isainfo->isa, ZIHINTNTL, pair->value, missing);
Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH 3/11 riscv: Standardize extension capitilization

In reply to Andrew Jones

From: Charlie Jenkins <[email protected]>

The base extensions are often lowercase and were written as lowercase in hwcap, but other references to these extensions in the kernel are uppercase. Standardize the case to make it easier to handle macro expansion.

[Apply KVM_ISA_EXT_ARR(), fixup all KVM use.]
---
 arch/riscv/include/asm/hwcap.h     | 18 ++++++++---------
 arch/riscv/include/asm/switch_to.h |  4 ++--
 arch/riscv/kernel/cpufeature.c     | 32 +++++++++++++++---------------
 arch/riscv/kernel/sys_hwprobe.c    |  4 ++--
 arch/riscv/kvm/main.c              |  2 +-
 arch/riscv/kvm/vcpu_fp.c           | 28 +++++++++++++-------------
 arch/riscv/kvm/vcpu_onereg.c       | 22 ++++++++++----------
 arch/riscv/kvm/vcpu_vector.c       | 14 ++++++-------
 8 files changed, 62 insertions(+), 62 deletions(-)
arch/riscv/include/asm/hwcap.h +9 -9
index 496694d3e182..03acd22bbbaa 100644
@@ -10,15 +10,15 @@
 
 #include <uapi/asm/hwcap.h>
 
-#define RISCV_ISA_EXT_a		('a' - 'a')
-#define RISCV_ISA_EXT_c		('c' - 'a')
-#define RISCV_ISA_EXT_d		('d' - 'a')
-#define RISCV_ISA_EXT_f		('f' - 'a')
-#define RISCV_ISA_EXT_h		('h' - 'a')
-#define RISCV_ISA_EXT_i		('i' - 'a')
-#define RISCV_ISA_EXT_m		('m' - 'a')
-#define RISCV_ISA_EXT_q		('q' - 'a')
-#define RISCV_ISA_EXT_v		('v' - 'a')
+#define RISCV_ISA_EXT_A		('a' - 'a')
+#define RISCV_ISA_EXT_C		('c' - 'a')
+#define RISCV_ISA_EXT_D		('d' - 'a')
+#define RISCV_ISA_EXT_F		('f' - 'a')
+#define RISCV_ISA_EXT_H		('h' - 'a')
+#define RISCV_ISA_EXT_I		('i' - 'a')
+#define RISCV_ISA_EXT_M		('m' - 'a')
+#define RISCV_ISA_EXT_Q		('q' - 'a')
+#define RISCV_ISA_EXT_V		('v' - 'a')
 
 /*
  * These macros represent the logical IDs of each multi-letter RISC-V ISA
arch/riscv/include/asm/switch_to.h +2 -2
index 0e71eb82f920..ff35a4d04f85 100644
@@ -60,8 +60,8 @@ static inline void __switch_to_fpu(struct task_struct *prev,
 
 static __always_inline bool has_fpu(void)
 {
-	return riscv_has_extension_likely(RISCV_ISA_EXT_f) ||
-		riscv_has_extension_likely(RISCV_ISA_EXT_d);
+	return riscv_has_extension_likely(RISCV_ISA_EXT_F) ||
+		riscv_has_extension_likely(RISCV_ISA_EXT_D);
 }
 #else
 static __always_inline bool has_fpu(void) { return false; }
arch/riscv/kernel/cpufeature.c +16 -16
index cf27b7a2547f..25ed1d6958d7 100644
@@ -83,7 +83,7 @@ EXPORT_SYMBOL_GPL(__riscv_isa_extension_available);
 static int riscv_ext_f_depends(const struct riscv_isa_ext_data *data,
 			       const unsigned long *isa_bitmap)
 {
-	if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_f))
+	if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_F))
 		return 0;
 
 	return -EPROBE_DEFER;
@@ -145,7 +145,7 @@ static int riscv_ext_f_validate(const struct riscv_isa_ext_data *data,
 	 * Due to extension ordering, d is checked before f, so no deferral
 	 * is required.
 	 */
-	if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_d)) {
+	if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_D)) {
 		pr_warn_once("This kernel does not support systems with F but not D\n");
 		return -EINVAL;
 	}
@@ -188,7 +188,7 @@ static int riscv_ext_vector_float_validate(const struct riscv_isa_ext_data *data
 	 * Since this function validates vector only, and v/Zve* are probed
 	 * after f/d, there's no need for a deferral here.
 	 */
-	if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_d))
+	if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_D))
 		return -EINVAL;
 
 	return 0;
@@ -223,7 +223,7 @@ static int riscv_ext_zcd_validate(const struct riscv_isa_ext_data *data,
 				  const unsigned long *isa_bitmap)
 {
 	if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZCA) &&
-	    __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_d))
+	    __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_D))
 		return 0;
 
 	return -EPROBE_DEFER;
@@ -236,7 +236,7 @@ static int riscv_ext_zcf_validate(const struct riscv_isa_ext_data *data,
 		return -EINVAL;
 
 	if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZCA) &&
-	    __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_f))
+	    __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_F))
 		return 0;
 
 	return -EPROBE_DEFER;
@@ -469,15 +469,15 @@ static const unsigned int riscv_c_exts[] = {
  * New entries to this struct should follow the ordering rules described above.
  */
 const struct riscv_isa_ext_data riscv_isa_ext[] = {
-	__RISCV_ISA_EXT_DATA(i, RISCV_ISA_EXT_i),
-	__RISCV_ISA_EXT_DATA(m, RISCV_ISA_EXT_m),
-	__RISCV_ISA_EXT_SUPERSET(a, RISCV_ISA_EXT_a, riscv_a_exts),
-	__RISCV_ISA_EXT_DATA_VALIDATE(f, RISCV_ISA_EXT_f, riscv_ext_f_validate),
-	__RISCV_ISA_EXT_DATA_VALIDATE(d, RISCV_ISA_EXT_d, riscv_ext_d_validate),
-	__RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_q),
-	__RISCV_ISA_EXT_SUPERSET(c, RISCV_ISA_EXT_c, riscv_c_exts),
-	__RISCV_ISA_EXT_SUPERSET_VALIDATE(v, RISCV_ISA_EXT_v, riscv_v_exts, riscv_ext_vector_float_validate),
-	__RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_h),
+	__RISCV_ISA_EXT_DATA(i, RISCV_ISA_EXT_I),
+	__RISCV_ISA_EXT_DATA(m, RISCV_ISA_EXT_M),
+	__RISCV_ISA_EXT_SUPERSET(a, RISCV_ISA_EXT_A, riscv_a_exts),
+	__RISCV_ISA_EXT_DATA_VALIDATE(f, RISCV_ISA_EXT_F, riscv_ext_f_validate),
+	__RISCV_ISA_EXT_DATA_VALIDATE(d, RISCV_ISA_EXT_D, riscv_ext_d_validate),
+	__RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_Q),
+	__RISCV_ISA_EXT_SUPERSET(c, RISCV_ISA_EXT_C, riscv_c_exts),
+	__RISCV_ISA_EXT_SUPERSET_VALIDATE(v, RISCV_ISA_EXT_V, riscv_v_exts, riscv_ext_vector_float_validate),
+	__RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_H),
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate),
 	__RISCV_ISA_EXT_DATA_VALIDATE(zicbop, RISCV_ISA_EXT_ZICBOP, riscv_ext_zicbop_validate),
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate),
@@ -873,8 +873,8 @@ static void __init riscv_fill_hwcap_from_isa_string(unsigned long *isa2hwcap)
 		 * marchid.
 		 */
 		if (acpi_disabled && boot_vendorid == THEAD_VENDOR_ID && boot_archid == 0x0) {
-			this_hwcap &= ~isa2hwcap[RISCV_ISA_EXT_v];
-			clear_bit(RISCV_ISA_EXT_v, source_isa);
+			this_hwcap &= ~isa2hwcap[RISCV_ISA_EXT_V];
+			clear_bit(RISCV_ISA_EXT_V, source_isa);
 		}
 
 		riscv_resolve_isa(source_isa, isainfo->isa, &this_hwcap, isa2hwcap);
arch/riscv/kernel/sys_hwprobe.c +2 -2
index 1423b447fe9a..76e673ab42a5 100644
@@ -88,10 +88,10 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,
 	if (has_fpu())
 		pair->value |= RISCV_HWPROBE_IMA_FD;
 
-	if (riscv_isa_extension_available(NULL, c))
+	if (riscv_isa_extension_available(NULL, C))
 		pair->value |= RISCV_HWPROBE_IMA_C;
 
-	if (has_vector() && riscv_isa_extension_available(NULL, v))
+	if (has_vector() && riscv_isa_extension_available(NULL, V))
 		pair->value |= RISCV_HWPROBE_IMA_V;
 
 	/*
arch/riscv/kvm/main.c +1 -1
index 45536af521f0..4d8c6e04aa7e 100644
@@ -85,7 +85,7 @@ static int __init riscv_kvm_init(void)
 	char slist[64];
 	const char *str;
 
-	if (!riscv_isa_extension_available(NULL, h)) {
+	if (!riscv_isa_extension_available(NULL, H)) {
 		kvm_info("hypervisor extension not available\n");
 		return -ENODEV;
 	}
arch/riscv/kvm/vcpu_fp.c +14 -14
index 030904d82b58..5cb6b04f6f96 100644
@@ -19,8 +19,8 @@ void kvm_riscv_vcpu_fp_reset(struct kvm_vcpu *vcpu)
 	struct kvm_cpu_context *cntx = &vcpu->arch.guest_context;
 
 	cntx->sstatus &= ~SR_FS;
-	if (riscv_isa_extension_available(vcpu->arch.isa, f) ||
-	    riscv_isa_extension_available(vcpu->arch.isa, d))
+	if (riscv_isa_extension_available(vcpu->arch.isa, F) ||
+	    riscv_isa_extension_available(vcpu->arch.isa, D))
 		cntx->sstatus |= SR_FS_INITIAL;
 	else
 		cntx->sstatus |= SR_FS_OFF;
@@ -36,9 +36,9 @@ void kvm_riscv_vcpu_guest_fp_save(struct kvm_cpu_context *cntx,
 				  const unsigned long *isa)
 {
 	if ((cntx->sstatus & SR_FS) == SR_FS_DIRTY) {
-		if (riscv_isa_extension_available(isa, d))
+		if (riscv_isa_extension_available(isa, D))
 			__kvm_riscv_fp_d_save(cntx);
-		else if (riscv_isa_extension_available(isa, f))
+		else if (riscv_isa_extension_available(isa, F))
 			__kvm_riscv_fp_f_save(cntx);
 		kvm_riscv_vcpu_fp_clean(cntx);
 	}
@@ -48,9 +48,9 @@ void kvm_riscv_vcpu_guest_fp_restore(struct kvm_cpu_context *cntx,
 				     const unsigned long *isa)
 {
 	if ((cntx->sstatus & SR_FS) != SR_FS_OFF) {
-		if (riscv_isa_extension_available(isa, d))
+		if (riscv_isa_extension_available(isa, D))
 			__kvm_riscv_fp_d_restore(cntx);
-		else if (riscv_isa_extension_available(isa, f))
+		else if (riscv_isa_extension_available(isa, F))
 			__kvm_riscv_fp_f_restore(cntx);
 		kvm_riscv_vcpu_fp_clean(cntx);
 	}
@@ -59,17 +59,17 @@ void kvm_riscv_vcpu_guest_fp_restore(struct kvm_cpu_context *cntx,
 void kvm_riscv_vcpu_host_fp_save(struct kvm_cpu_context *cntx)
 {
 	/* No need to check host sstatus as it can be modified outside */
-	if (riscv_isa_extension_available(NULL, d))
+	if (riscv_isa_extension_available(NULL, D))
 		__kvm_riscv_fp_d_save(cntx);
-	else if (riscv_isa_extension_available(NULL, f))
+	else if (riscv_isa_extension_available(NULL, F))
 		__kvm_riscv_fp_f_save(cntx);
 }
 
 void kvm_riscv_vcpu_host_fp_restore(struct kvm_cpu_context *cntx)
 {
-	if (riscv_isa_extension_available(NULL, d))
+	if (riscv_isa_extension_available(NULL, D))
 		__kvm_riscv_fp_d_restore(cntx);
-	else if (riscv_isa_extension_available(NULL, f))
+	else if (riscv_isa_extension_available(NULL, F))
 		__kvm_riscv_fp_f_restore(cntx);
 }
 #endif
@@ -87,7 +87,7 @@ int kvm_riscv_vcpu_get_reg_fp(struct kvm_vcpu *vcpu,
 	void *reg_val;
 
 	if ((rtype == KVM_REG_RISCV_FP_F) &&
-	    riscv_isa_extension_available(vcpu->arch.isa, f)) {
+	    riscv_isa_extension_available(vcpu->arch.isa, F)) {
 		if (KVM_REG_SIZE(reg->id) != sizeof(u32))
 			return -EINVAL;
 		if (reg_num == KVM_REG_RISCV_FP_F_REG(fcsr))
@@ -98,7 +98,7 @@ int kvm_riscv_vcpu_get_reg_fp(struct kvm_vcpu *vcpu,
 		else
 			return -ENOENT;
 	} else if ((rtype == KVM_REG_RISCV_FP_D) &&
-		   riscv_isa_extension_available(vcpu->arch.isa, d)) {
+		   riscv_isa_extension_available(vcpu->arch.isa, D)) {
 		if (reg_num == KVM_REG_RISCV_FP_D_REG(fcsr)) {
 			if (KVM_REG_SIZE(reg->id) != sizeof(u32))
 				return -EINVAL;
@@ -132,7 +132,7 @@ int kvm_riscv_vcpu_set_reg_fp(struct kvm_vcpu *vcpu,
 	void *reg_val;
 
 	if ((rtype == KVM_REG_RISCV_FP_F) &&
-	    riscv_isa_extension_available(vcpu->arch.isa, f)) {
+	    riscv_isa_extension_available(vcpu->arch.isa, F)) {
 		if (KVM_REG_SIZE(reg->id) != sizeof(u32))
 			return -EINVAL;
 		if (reg_num == KVM_REG_RISCV_FP_F_REG(fcsr))
@@ -143,7 +143,7 @@ int kvm_riscv_vcpu_set_reg_fp(struct kvm_vcpu *vcpu,
 		else
 			return -ENOENT;
 	} else if ((rtype == KVM_REG_RISCV_FP_D) &&
-		   riscv_isa_extension_available(vcpu->arch.isa, d)) {
+		   riscv_isa_extension_available(vcpu->arch.isa, D)) {
 		if (reg_num == KVM_REG_RISCV_FP_D_REG(fcsr)) {
 			if (KVM_REG_SIZE(reg->id) != sizeof(u32))
 				return -EINVAL;
arch/riscv/kvm/vcpu_onereg.c +11 -11
index 865dae903aa0..901dca0edcb9 100644
@@ -26,14 +26,14 @@
 /* Mapping between KVM ISA Extension ID & guest ISA extension ID */
 static const unsigned long kvm_isa_ext_arr[] = {
 	/* Single letter extensions (alphabetically sorted) */
-	[KVM_RISCV_ISA_EXT_A] = RISCV_ISA_EXT_a,
-	[KVM_RISCV_ISA_EXT_C] = RISCV_ISA_EXT_c,
-	[KVM_RISCV_ISA_EXT_D] = RISCV_ISA_EXT_d,
-	[KVM_RISCV_ISA_EXT_F] = RISCV_ISA_EXT_f,
-	[KVM_RISCV_ISA_EXT_H] = RISCV_ISA_EXT_h,
-	[KVM_RISCV_ISA_EXT_I] = RISCV_ISA_EXT_i,
-	[KVM_RISCV_ISA_EXT_M] = RISCV_ISA_EXT_m,
-	[KVM_RISCV_ISA_EXT_V] = RISCV_ISA_EXT_v,
+	KVM_ISA_EXT_ARR(A),
+	KVM_ISA_EXT_ARR(C),
+	KVM_ISA_EXT_ARR(D),
+	KVM_ISA_EXT_ARR(F),
+	KVM_ISA_EXT_ARR(H),
+	KVM_ISA_EXT_ARR(I),
+	KVM_ISA_EXT_ARR(M),
+	KVM_ISA_EXT_ARR(V),
 	/* Multi letter extensions (alphabetically sorted) */
 	KVM_ISA_EXT_ARR(SMNPM),
 	KVM_ISA_EXT_ARR(SMSTATEEN),
@@ -986,7 +986,7 @@ static inline unsigned long num_fp_f_regs(const struct kvm_vcpu *vcpu)
 {
 	const struct kvm_cpu_context *cntx = &vcpu->arch.guest_context;
 
-	if (riscv_isa_extension_available(vcpu->arch.isa, f))
+	if (riscv_isa_extension_available(vcpu->arch.isa, F))
 		return sizeof(cntx->fp.f) / sizeof(u32);
 	else
 		return 0;
@@ -1015,7 +1015,7 @@ static inline unsigned long num_fp_d_regs(const struct kvm_vcpu *vcpu)
 {
 	const struct kvm_cpu_context *cntx = &vcpu->arch.guest_context;
 
-	if (riscv_isa_extension_available(vcpu->arch.isa, d))
+	if (riscv_isa_extension_available(vcpu->arch.isa, D))
 		return sizeof(cntx->fp.d.f) / sizeof(u64) + 1;
 	else
 		return 0;
@@ -1094,7 +1094,7 @@ static inline unsigned long num_sbi_regs(struct kvm_vcpu *vcpu)
 
 static inline unsigned long num_vector_regs(const struct kvm_vcpu *vcpu)
 {
-	if (!riscv_isa_extension_available(vcpu->arch.isa, v))
+	if (!riscv_isa_extension_available(vcpu->arch.isa, V))
 		return 0;
 
 	/* vstart, vl, vtype, vcsr, vlenb and 32 vector regs */
arch/riscv/kvm/vcpu_vector.c +7 -7
index 05f3cc2d8e31..8bc85593e1d4 100644
@@ -25,7 +25,7 @@ void kvm_riscv_vcpu_vector_reset(struct kvm_vcpu *vcpu)
 
 	cntx->vector.vlenb = riscv_v_vsize / 32;
 
-	if (riscv_isa_extension_available(isa, v)) {
+	if (riscv_isa_extension_available(isa, V)) {
 		cntx->sstatus |= SR_VS_INITIAL;
 		WARN_ON(!cntx->vector.datap);
 		memset(cntx->vector.datap, 0, riscv_v_vsize);
@@ -44,7 +44,7 @@ void kvm_riscv_vcpu_guest_vector_save(struct kvm_cpu_context *cntx,
 				      unsigned long *isa)
 {
 	if ((cntx->sstatus & SR_VS) == SR_VS_DIRTY) {
-		if (riscv_isa_extension_available(isa, v))
+		if (riscv_isa_extension_available(isa, V))
 			__kvm_riscv_vector_save(cntx);
 		kvm_riscv_vcpu_vector_clean(cntx);
 	}
@@ -54,7 +54,7 @@ void kvm_riscv_vcpu_guest_vector_restore(struct kvm_cpu_context *cntx,
 					 unsigned long *isa)
 {
 	if ((cntx->sstatus & SR_VS) != SR_VS_OFF) {
-		if (riscv_isa_extension_available(isa, v))
+		if (riscv_isa_extension_available(isa, V))
 			__kvm_riscv_vector_restore(cntx);
 		kvm_riscv_vcpu_vector_clean(cntx);
 	}
@@ -63,13 +63,13 @@ void kvm_riscv_vcpu_guest_vector_restore(struct kvm_cpu_context *cntx,
 void kvm_riscv_vcpu_host_vector_save(struct kvm_cpu_context *cntx)
 {
 	/* No need to check host sstatus as it can be modified outside */
-	if (riscv_isa_extension_available(NULL, v))
+	if (riscv_isa_extension_available(NULL, V))
 		__kvm_riscv_vector_save(cntx);
 }
 
 void kvm_riscv_vcpu_host_vector_restore(struct kvm_cpu_context *cntx)
 {
-	if (riscv_isa_extension_available(NULL, v))
+	if (riscv_isa_extension_available(NULL, V))
 		__kvm_riscv_vector_restore(cntx);
 }
 
@@ -149,7 +149,7 @@ int kvm_riscv_vcpu_get_reg_vector(struct kvm_vcpu *vcpu,
 	void *reg_addr;
 	int rc;
 
-	if (!riscv_isa_extension_available(isa, v))
+	if (!riscv_isa_extension_available(isa, V))
 		return -ENOENT;
 
 	rc = kvm_riscv_vcpu_vreg_addr(vcpu, reg_num, reg_size, &reg_addr);
@@ -175,7 +175,7 @@ int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu,
 	void *reg_addr;
 	int rc;
 
-	if (!riscv_isa_extension_available(isa, v))
+	if (!riscv_isa_extension_available(isa, V))
 		return -ENOENT;
 
 	if (reg_num == KVM_REG_RISCV_VECTOR_CSR_REG(vlenb)) {
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH 4/11 riscv: Add B to hwcap

In reply to Andrew Jones

Add B to hwcap and ensure when B is present that Zba, Zbb, and Zbs are all set.

---
 arch/riscv/include/asm/hwcap.h      | 1 +
 arch/riscv/include/uapi/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpufeature.c      | 8 ++++++++
 3 files changed, 10 insertions(+)
arch/riscv/include/asm/hwcap.h +1 -0
index 03acd22bbbaa..c17e11caca83 100644
@@ -11,6 +11,7 @@
 #include <uapi/asm/hwcap.h>
 
 #define RISCV_ISA_EXT_A		('a' - 'a')
+#define RISCV_ISA_EXT_B		('b' - 'a')
 #define RISCV_ISA_EXT_C		('c' - 'a')
 #define RISCV_ISA_EXT_D		('d' - 'a')
 #define RISCV_ISA_EXT_F		('f' - 'a')
arch/riscv/include/uapi/asm/hwcap.h +1 -0
index c52bb7bbbabe..96b7cf854e09 100644
@@ -21,6 +21,7 @@
 #define COMPAT_HWCAP_ISA_F	(1 << ('F' - 'A'))
 #define COMPAT_HWCAP_ISA_D	(1 << ('D' - 'A'))
 #define COMPAT_HWCAP_ISA_C	(1 << ('C' - 'A'))
+#define COMPAT_HWCAP_ISA_B	(1 << ('B' - 'A'))
 #define COMPAT_HWCAP_ISA_V	(1 << ('V' - 'A'))
 
 #endif /* _UAPI_ASM_RISCV_HWCAP_H */
arch/riscv/kernel/cpufeature.c +8 -0
index 25ed1d6958d7..ca7a34f66738 100644
@@ -429,6 +429,12 @@ static const unsigned int riscv_c_exts[] = {
 	RISCV_ISA_EXT_ZCD,
 };
 
+static const unsigned int riscv_b_exts[] = {
+	RISCV_ISA_EXT_ZBA,
+	RISCV_ISA_EXT_ZBB,
+	RISCV_ISA_EXT_ZBS,
+};
+
 /*
  * The canonical order of ISA extension names in the ISA string is defined in
  * chapter 27 of the unprivileged specification.
@@ -476,6 +482,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
 	__RISCV_ISA_EXT_DATA_VALIDATE(d, RISCV_ISA_EXT_D, riscv_ext_d_validate),
 	__RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_Q),
 	__RISCV_ISA_EXT_SUPERSET(c, RISCV_ISA_EXT_C, riscv_c_exts),
+	__RISCV_ISA_EXT_SUPERSET(b, RISCV_ISA_EXT_B, riscv_b_exts),
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(v, RISCV_ISA_EXT_V, riscv_v_exts, riscv_ext_vector_float_validate),
 	__RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_H),
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate),
@@ -1089,6 +1096,7 @@ void __init riscv_fill_hwcap(void)
 	isa2hwcap['f' - 'a'] = COMPAT_HWCAP_ISA_F;
 	isa2hwcap['d' - 'a'] = COMPAT_HWCAP_ISA_D;
 	isa2hwcap['c' - 'a'] = COMPAT_HWCAP_ISA_C;
+	isa2hwcap['b' - 'a'] = COMPAT_HWCAP_ISA_B;
 	isa2hwcap['v' - 'a'] = COMPAT_HWCAP_ISA_V;
 
 	if (!acpi_disabled) {
Signature · 1 line
2.43.0
#5 lore raw

Re: [RFC PATCH v1 04/11] riscv: Add B to hwcap

Hi, Drew

Quoted 10 lines · Andrew Jones

Add B to hwcap and ensure when B is present that Zba, Zbb, and Zbs are all set.

---
 arch/riscv/include/asm/hwcap.h      | 1 +
 arch/riscv/include/uapi/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpufeature.c      | 8 ++++++++
 3 files changed, 10 insertions(+)

I saw you chose not to add B to hwprobe in this series, per your review of my patch [1]. I have a different opinion.

As you said, FD, C, and V are all exported through both hwcap and hwprobe. Adding B to hwprobe too keeps things consistent, users can query all the single-letter extensions from one interface without needing to know that B is missing in hwprobe and that they'd have to check Zba/Zbb/Zbs to infer B support.

Relying on the rva23u64 base bit to imply B also doesn't cover chips that implement B without being rva23u64 compliant. Eg. my patchset [2] adds support for existing (non-rva23u64) SoCs.

Thanks,
Guodong

Guodong

Quoted 61 lines
arch/riscv/include/asm/hwcap.h +1 -0
index 03acd22bbbaa..c17e11caca83 100644
@@ -11,6 +11,7 @@
 #include <uapi/asm/hwcap.h>
 
 #define RISCV_ISA_EXT_A                ('a' - 'a')
+#define RISCV_ISA_EXT_B                ('b' - 'a')
 #define RISCV_ISA_EXT_C                ('c' - 'a')
 #define RISCV_ISA_EXT_D                ('d' - 'a')
 #define RISCV_ISA_EXT_F                ('f' - 'a')
arch/riscv/include/uapi/asm/hwcap.h +1 -0
index c52bb7bbbabe..96b7cf854e09 100644
@@ -21,6 +21,7 @@
 #define COMPAT_HWCAP_ISA_F     (1 << ('F' - 'A'))
 #define COMPAT_HWCAP_ISA_D     (1 << ('D' - 'A'))
 #define COMPAT_HWCAP_ISA_C     (1 << ('C' - 'A'))
+#define COMPAT_HWCAP_ISA_B     (1 << ('B' - 'A'))
 #define COMPAT_HWCAP_ISA_V     (1 << ('V' - 'A'))
 
 #endif /* _UAPI_ASM_RISCV_HWCAP_H */
arch/riscv/kernel/cpufeature.c +8 -1
index 25ed1d6958d7..ca7a34f66738 100644
@@ -429,6 +429,12 @@ static const unsigned int riscv_c_exts[] = {
        RISCV_ISA_EXT_ZCD,
 };
 
+static const unsigned int riscv_b_exts[] = {
+       RISCV_ISA_EXT_ZBA,
+       RISCV_ISA_EXT_ZBB,
+       RISCV_ISA_EXT_ZBS,
+};
+
 /*
  * The canonical order of ISA extension names in the ISA string is defined in
  * chapter 27 of the unprivileged specification.
@@ -476,6 +482,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
        __RISCV_ISA_EXT_DATA_VALIDATE(d, RISCV_ISA_EXT_D, riscv_ext_d_validate),
        __RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_Q),
        __RISCV_ISA_EXT_SUPERSET(c, RISCV_ISA_EXT_C, riscv_c_exts),
+       __RISCV_ISA_EXT_SUPERSET(b, RISCV_ISA_EXT_B, riscv_b_exts),
        __RISCV_ISA_EXT_SUPERSET_VALIDATE(v, RISCV_ISA_EXT_V, riscv_v_exts, riscv_ext_vector_float_validate),
        __RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_H),
        __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate),
@@ -1089,6 +1096,7 @@ void __init riscv_fill_hwcap(void)
        isa2hwcap['f' - 'a'] = COMPAT_HWCAP_ISA_F;
        isa2hwcap['d' - 'a'] = COMPAT_HWCAP_ISA_D;
        isa2hwcap['c' - 'a'] = COMPAT_HWCAP_ISA_C;
+       isa2hwcap['b' - 'a'] = COMPAT_HWCAP_ISA_B;
        isa2hwcap['v' - 'a'] = COMPAT_HWCAP_ISA_V;
 
        if (!acpi_disabled) {
--

2.43.0

#6 lore raw

Re: [RFC PATCH v1 04/11] riscv: Add B to hwcap

Quoted 24 lines · Guodong Xu

Hi, Drew

Quoted 10 lines · Andrew Jones

Add B to hwcap and ensure when B is present that Zba, Zbb, and Zbs are all set.

---
 arch/riscv/include/asm/hwcap.h      | 1 +
 arch/riscv/include/uapi/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpufeature.c      | 8 ++++++++
 3 files changed, 10 insertions(+)

I saw you chose not to add B to hwprobe in this series, per your review of my patch [1]. I have a different opinion.

As you said, FD, C, and V are all exported through both hwcap and hwprobe. Adding B to hwprobe too keeps things consistent, users can query all the single-letter extensions from one interface without needing to know that B is missing in hwprobe and that they'd have to check Zba/Zbb/Zbs to infer B support.

Quoted 4 lines

Relying on the rva23u64 base bit to imply B also doesn't cover chips that implement B without being rva23u64 compliant. Eg. my patchset [2] adds support for existing (non-rva23u64) SoCs.

I think we need to come up with some sort of policy as to what goes to hwprobe and what doesn't. IMO, hwcap is easy. If RISC-V defines a single letter extension, such as V or B, then we should add it to hwcap. However, for hwprobe, we can go two ways:

1. Add every extension, including 'bundle' extensions, which are nothing more than an alias for a collection of extensions. This includes single letter bundle extensions like B.

2. Add only unique extensions, i.e. no purely bundle extensions get added.

If we go with (2), then userspace will need to use the base behaviors (profiles) in order to get any sort of bundling, but I think most people agree that userspace will target profiles, so (2) seems sufficient. I'm not sure about applications that won't target profiles but will want to check for bundle extensions rather than individual extensions. Should we take on the maintenance burden of adding each bundle extension to hwprobe for those? In particular, I'm not sure about B, because it's already available independently of a base behavior (profile) through hwcap.

Thanks,
drew

#7 lore raw

Re: [RFC PATCH v1 04/11] riscv: Add B to hwcap

Quoted 26 lines · Andrew Jones
Quoted 24 lines · Guodong Xu

Hi, Drew

Quoted 10 lines · Andrew Jones

Add B to hwcap and ensure when B is present that Zba, Zbb, and Zbs are all set.

---
 arch/riscv/include/asm/hwcap.h      | 1 +
 arch/riscv/include/uapi/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpufeature.c      | 8 ++++++++
 3 files changed, 10 insertions(+)

I saw you chose not to add B to hwprobe in this series, per your review of my patch [1]. I have a different opinion.

As you said, FD, C, and V are all exported through both hwcap and hwprobe. Adding B to hwprobe too keeps things consistent, users can query all the single-letter extensions from one interface without needing to know that B is missing in hwprobe and that they'd have to check Zba/Zbb/Zbs to infer B support.

Quoted 8 lines
Quoted 4 lines

Relying on the rva23u64 base bit to imply B also doesn't cover chips that implement B without being rva23u64 compliant. Eg. my patchset [2] adds support for existing (non-rva23u64) SoCs.

I think we need to come up with some sort of policy as to what goes to hwprobe and what doesn't. IMO, hwcap is easy. If RISC-V defines a single letter extension, such as V or B, then we should add it to hwcap. However,

When we export an extension through hwcap but it cannot be queried through hwprobe, we create an inconsistency:
the same extension is discoverable through one interface but not the other.

The current kernel already exposes other single-letter extensions through both interfaces:

F+D: RISCV_HWPROBE_IMA_FD + COMPAT_HWCAP_ISA_F/_D

  C:   RISCV_HWPROBE_IMA_C  + COMPAT_HWCAP_ISA_C
  V:   RISCV_HWPROBE_IMA_V  + COMPAT_HWCAP_ISA_V

(I/M/A are folded into RISCV_HWPROBE_BASE_BEHAVIOR_IMA, so they are a separate case.)

F, D, C, and V are consistent between hwcap and hwprobe. Why should B be different?

Quoted 6 lines

for hwprobe, we can go two ways:

1. Add every extension, including 'bundle' extensions, which are nothing more than an alias for a collection of extensions. This includes single letter bundle extensions like B.

Quoted 6 lines

2. Add only unique extensions, i.e. no purely bundle extensions get added.

If we go with (2), then userspace will need to use the base behaviors (profiles) in order to get any sort of bundling, but I think most people agree that userspace will target profiles, so (2) seems sufficient. I'm

Looking at existing code, cpufeature.c follows option (2) for bundle extensions. Zk has no hwprobe bit. The community settled on this in 2023 [1], and I respect that decision.

The kernel has two families of bundles today: the Zk series (Zk, Zkn, Zks) and the Zvk series (Zvkn, Zvknc, Zvkng, Zvks, Zvksc, Zvksg). All use __RISCV_ISA_EXT_BUNDLE(). Two things to note:

1) They are all multi-letter extensions.
2) Bundle extensions have no valid ext id, so userspace cannot query them through hwprobe. To determine "Zk" support, a user must check all 8 sub-extensions individually.

B is different.

In your patch and mine, we both define B as a superset, not a bundle:

+ __RISCV_ISA_EXT_SUPERSET(b, RISCV_ISA_EXT_B, riscv_b_exts),

From a spec perspective, B adds no new functionality beyond Zba + Zbb + Zbs. The only thing B adds is a misa bit (m-mode CSR 0x301, not visible to S-mode or U-mode). So functionally it looks like a bundle.

But can we change B to __RISCV_ISA_EXT_BUNDLE()? I do not think so. A bundle has id = RISCV_ISA_EXT_INVALID, which means no bit in the ISA bitmap. The isa2hwcap[] mapping in riscv_fill_hwcap() requires a valid ext id to set COMPAT_HWCAP_ISA_B into elf_hwcap. Without it, AT_HWCAP support for B breaks, and we would need a special hack. That is unnecessary complexity.

The existing Zk/Zvk bundles work as bundles because they are multi-letter extensions with no AT_HWCAP presence. B lives in both worlds.

[1] https://lore.kernel.org/all/20231012-darkness-neutron-fc1843ff05ff@spud/

Quoted 6 lines

not sure about applications that won't target profiles but will want to check for bundle extensions rather than individual extensions. Should we take on the maintenance burden of adding each bundle extension to hwprobe for those? In particular, I'm not sure about B, because it's already available independently of a base behavior (profile) through hwcap.

In summary, my comments are:

1. F, D, C, and V are detectable from both hwcap and hwprobe. B should follow the same pattern. Dropping B from hwprobe while keeping it in hwcap creates a gap that will confuse users.

2. B is functionally a bundle (the misa B bit at 0x301 is m-mode only, not visible to S-mode or U-mode), yet we declare it as __RISCV_ISA_EXT_SUPERSET() because it needs a valid ext id for AT_HWCAP. I suggest we document this with a comment in cpufeature.c:

+ /*

+  * B is functionally a bundle (Zba + Zbb + Zbs,
+  * no additional instructions). We use SUPERSET
+  * instead of BUNDLE because B needs a valid ext
+  * id for isa2hwcap[] to set COMPAT_HWCAP_ISA_B.
+  */

+ __RISCV_ISA_EXT_SUPERSET(b, RISCV_ISA_EXT_B, riscv_b_exts),

3. Should we also document in .rst or (in cpufeature.c) about when to use _BUNDLE() and when to use _SUPERSET(), and what's the implication when using them, to echo what you stated above "... Add only unique extensions, i.e. no purely bundle extensions getadded."

BR,
Guodong

Quoted 2 lines

Thanks,
drew

#8 lore raw

Re: [RFC PATCH v1 04/11] riscv: Add B to hwcap

Quoted 46 lines · Guodong Xu
Quoted 26 lines · Andrew Jones
Quoted 24 lines · Guodong Xu

Hi, Drew

Quoted 10 lines · Andrew Jones

Add B to hwcap and ensure when B is present that Zba, Zbb, and Zbs are all set.

---
 arch/riscv/include/asm/hwcap.h      | 1 +
 arch/riscv/include/uapi/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpufeature.c      | 8 ++++++++
 3 files changed, 10 insertions(+)

I saw you chose not to add B to hwprobe in this series, per your review of my patch [1]. I have a different opinion.

As you said, FD, C, and V are all exported through both hwcap and hwprobe. Adding B to hwprobe too keeps things consistent, users can query all the single-letter extensions from one interface without needing to know that B is missing in hwprobe and that they'd have to check Zba/Zbb/Zbs to infer B support.

Quoted 8 lines
Quoted 4 lines

Relying on the rva23u64 base bit to imply B also doesn't cover chips that implement B without being rva23u64 compliant. Eg. my patchset [2] adds support for existing (non-rva23u64) SoCs.

I think we need to come up with some sort of policy as to what goes to hwprobe and what doesn't. IMO, hwcap is easy. If RISC-V defines a single letter extension, such as V or B, then we should add it to hwcap. However,

When we export an extension through hwcap but it cannot be queried through hwprobe, we create an inconsistency:
the same extension is discoverable through one interface but not the other.

The current kernel already exposes other single-letter extensions through both interfaces:

F+D: RISCV_HWPROBE_IMA_FD + COMPAT_HWCAP_ISA_F/_D

Quoted 8 lines
  C:   RISCV_HWPROBE_IMA_C  + COMPAT_HWCAP_ISA_C
  V:   RISCV_HWPROBE_IMA_V  + COMPAT_HWCAP_ISA_V

(I/M/A are folded into RISCV_HWPROBE_BASE_BEHAVIOR_IMA, so they are a separate case.)

F, D, C, and V are consistent between hwcap and hwprobe. Why should B be different?

Ok, you've sold me. The obvious advantage to applications is that they don't need to know anything about hwcap at all. hwprobe can be a one- stop shop.

Quoted 80 lines
Quoted 7 lines

for hwprobe, we can go two ways:

1. Add every extension, including 'bundle' extensions, which are nothing more than an alias for a collection of extensions. This includes single letter bundle extensions like B.

Quoted 6 lines

2. Add only unique extensions, i.e. no purely bundle extensions get added.

If we go with (2), then userspace will need to use the base behaviors (profiles) in order to get any sort of bundling, but I think most people agree that userspace will target profiles, so (2) seems sufficient. I'm

Looking at existing code, cpufeature.c follows option (2) for bundle extensions. Zk has no hwprobe bit. The community settled on this in 2023 [1], and I respect that decision.

The kernel has two families of bundles today: the Zk series (Zk, Zkn, Zks) and the Zvk series (Zvkn, Zvknc, Zvkng, Zvks, Zvksc, Zvksg). All use __RISCV_ISA_EXT_BUNDLE(). Two things to note:

1) They are all multi-letter extensions.
2) Bundle extensions have no valid ext id, so userspace cannot query them through hwprobe. To determine "Zk" support, a user must check all 8 sub-extensions individually.

B is different.

In your patch and mine, we both define B as a superset, not a bundle:

+ __RISCV_ISA_EXT_SUPERSET(b, RISCV_ISA_EXT_B, riscv_b_exts),

From a spec perspective, B adds no new functionality beyond Zba + Zbb + Zbs. The only thing B adds is a misa bit (m-mode CSR 0x301, not visible to S-mode or U-mode). So functionally it looks like a bundle.

But can we change B to __RISCV_ISA_EXT_BUNDLE()? I do not think so. A bundle has id = RISCV_ISA_EXT_INVALID, which means no bit in the ISA bitmap. The isa2hwcap[] mapping in riscv_fill_hwcap() requires a valid ext id to set COMPAT_HWCAP_ISA_B into elf_hwcap. Without it, AT_HWCAP support for B breaks, and we would need a special hack. That is unnecessary complexity.

The existing Zk/Zvk bundles work as bundles because they are multi-letter extensions with no AT_HWCAP presence. B lives in both worlds.

[1] https://lore.kernel.org/all/20231012-darkness-neutron-fc1843ff05ff@spud/

Quoted 6 lines

not sure about applications that won't target profiles but will want to check for bundle extensions rather than individual extensions. Should we take on the maintenance burden of adding each bundle extension to hwprobe for those? In particular, I'm not sure about B, because it's already available independently of a base behavior (profile) through hwcap.

In summary, my comments are:

1. F, D, C, and V are detectable from both hwcap and hwprobe. B should follow the same pattern. Dropping B from hwprobe while keeping it in hwcap creates a gap that will confuse users.

2. B is functionally a bundle (the misa B bit at 0x301 is m-mode only, not visible to S-mode or U-mode), yet we declare it as __RISCV_ISA_EXT_SUPERSET() because it needs a valid ext id for AT_HWCAP. I suggest we document this with a comment in cpufeature.c:

+ /*

Review

Quoted 6 lines
(quoted diff) +6 -0
+  * B is functionally a bundle (Zba + Zbb + Zbs,
+  * no additional instructions). We use SUPERSET
+  * instead of BUNDLE because B needs a valid ext
+  * id for isa2hwcap[] to set COMPAT_HWCAP_ISA_B.
+  */
+   __RISCV_ISA_EXT_SUPERSET(b, RISCV_ISA_EXT_B, riscv_b_exts),

Looks good.

Quoted 5 lines

3. Should we also document in .rst or (in cpufeature.c) about when to use _BUNDLE() and when to use _SUPERSET(), and what's the implication when using them, to echo what you stated above "... Add only unique extensions, i.e. no purely bundle extensions getadded."

We're probably OK with the comments already in cpufeature.h

/* Used to declare pure "lasso" extension (Zk for instance) */
BUNDLE...
/* Used to declare extensions that are a superset of other extensions (Zvbb for instance) */ SUPERSET...

And your proposed comment above B will also help explain things.

Thanks,
drew

#9 lore raw

Re: [RFC PATCH v1 04/11] riscv: Add B to hwcap

Quoted 7 lines · Andrew Jones

Review

Quoted 5 lines · Guodong Xu

+ /*

(quoted diff) +4 -0
+  * B is functionally a bundle (Zba + Zbb + Zbs,
+  * no additional instructions). We use SUPERSET
+  * instead of BUNDLE because B needs a valid ext
+  * id for isa2hwcap[] to set COMPAT_HWCAP_ISA_B.

What's the actual rationale for it working like that?
Why shouldn't bundles appear in cpuinfo etc, I forget entirely why we did it this way. Feels like it'd be easier for users, no?

2023 me might disagree, but 2026 me doesn't see the value in hiding these extensions. All I can think of was me being very negative, and hedging against bad software checking for zkn and not checking for the subsets, and breaking if the dt listed the entire subset but not zkn. That, or not wanting to implement code that looked for subset extensions and populated the relevant bundle if the bundle itself was missing but all components were there.

#10 lore raw

Re: [RFC PATCH v1 04/11] riscv: Add B to hwcap

Quoted 13 lines · Conor Dooley
Quoted 7 lines · Andrew Jones

Review

Quoted 5 lines · Guodong Xu

+ /*

(quoted diff) +4 -0
+  * B is functionally a bundle (Zba + Zbb + Zbs,
+  * no additional instructions). We use SUPERSET
+  * instead of BUNDLE because B needs a valid ext
+  * id for isa2hwcap[] to set COMPAT_HWCAP_ISA_B.

What's the actual rationale for it working like that?
Why shouldn't bundles appear in cpuinfo etc, I forget entirely why we did it this way. Feels like it'd be easier for users, no?

Quoted 7 lines

2023 me might disagree, but 2026 me doesn't see the value in hiding these extensions. All I can think of was me being very negative, and hedging against bad software checking for zkn and not checking for the subsets, and breaking if the dt listed the entire subset but not zkn. That, or not wanting to implement code that looked for subset extensions and populated the relevant bundle if the bundle itself was missing but all components were there.

I also can't remember and the 2026 me doesn't want to google 2023 me's thoughts. I think we may have opted not to publish bundles because we didn't believe publishing them would help reduce much confusion, as the concept of a bundle itself was a bit confusing...

Thanks,
drew

#11 lore raw

RFC PATCH 5/11 riscv: hwprobe.rst: Replace tabs with spaces

In reply to Andrew Jones
---
 Documentation/arch/riscv/hwprobe.rst | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/arch/riscv/hwprobe.rst +5 -5
index 0598c9ddd73f..4484f2a7f798 100644
@@ -362,7 +362,7 @@ The following keys are defined:
 
     * :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR`: The xtheadvector vendor
         extension is supported in the T-Head ISA extensions spec starting from
-	commit a18c801634 ("Add T-Head VECTOR vendor extension. ").
+        commit a18c801634 ("Add T-Head VECTOR vendor extension. ").
 
 * :c:macro:`RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE`: An unsigned int which
   represents the size of the Zicbom block in bytes.
@@ -375,19 +375,19 @@ The following keys are defined:
 
     * :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVQMACCDOD`: The Xsfqmaccdod vendor
         extension is supported in version 1.1 of SiFive Int8 Matrix Multiplication
-	Extensions Specification.
+        Extensions Specification.
 
     * :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVQMACCQOQ`: The Xsfqmaccqoq vendor
         extension is supported in version 1.1 of SiFive Int8 Matrix Multiplication
-	Instruction Extensions Specification.
+        Instruction Extensions Specification.
 
     * :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVFNRCLIPXFQF`: The Xsfvfnrclipxfqf
         vendor extension is supported in version 1.0 of SiFive FP32-to-int8 Ranged
-	Clip Instructions Extensions Specification.
+        Clip Instructions Extensions Specification.
 
     * :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVFWMACCQQQ`: The Xsfvfwmaccqqq
         vendor extension is supported in version 1.0 of Matrix Multiply Accumulate
-	Instruction Extensions Specification.
+        Instruction Extensions Specification.
 
 * :c:macro:`RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE`: An unsigned int which
   represents the size of the Zicbop block in bytes.
Signature · 1 line
2.43.0
#12 lore raw

RFC PATCH 6/11 riscv: Add Ziccamoa, Ziccif, Ziccrse, and Za64rs to hwprobe

In reply to Andrew Jones

Ziccrse is already present in cpufeature.

---
 Documentation/arch/riscv/hwprobe.rst  | 16 ++++++++++++++++
 arch/riscv/include/asm/hwcap.h        |  3 +++
 arch/riscv/include/uapi/asm/hwprobe.h |  4 ++++
 arch/riscv/kernel/cpufeature.c        |  3 +++
 arch/riscv/kernel/sys_hwprobe.c       |  7 +++++--
 5 files changed, 31 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +16 -0
index 4484f2a7f798..97226b7c5936 100644
@@ -395,3 +395,19 @@ The following keys are defined:
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_1`: A bitmask containing additional
   extensions that are compatible with the
   :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`: base system behavior.
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCAMOA`: The Ziccamoa extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCIF`: The Ziccif extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCRSE`: The Ziccrse extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZA64RS`: The Za64rs extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
arch/riscv/include/asm/hwcap.h +3 -0
index c17e11caca83..8e764dbc7413 100644
@@ -112,6 +112,9 @@
 #define RISCV_ISA_EXT_ZILSD		102
 #define RISCV_ISA_EXT_ZCLSD		103
 #define RISCV_ISA_EXT_ZICCLSM		104
+#define RISCV_ISA_EXT_ZICCAMOA		105
+#define RISCV_ISA_EXT_ZICCIF		106
+#define RISCV_ISA_EXT_ZA64RS		107
 
 #define RISCV_ISA_EXT_XLINUXENVCFG	127
 
arch/riscv/include/uapi/asm/hwprobe.h +4 -0
index 6a0163b54718..fed9ea6fd2b5 100644
@@ -115,6 +115,10 @@ struct riscv_hwprobe {
 #define RISCV_HWPROBE_KEY_VENDOR_EXT_MIPS_0	14
 #define RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE	15
 #define RISCV_HWPROBE_KEY_IMA_EXT_1		16
+#define		RISCV_HWPROBE_EXT_ZICCAMOA	(1 << 0)
+#define		RISCV_HWPROBE_EXT_ZICCIF	(1 << 1)
+#define		RISCV_HWPROBE_EXT_ZICCRSE	(1 << 2)
+#define		RISCV_HWPROBE_EXT_ZA64RS	(1 << 3)
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
 /* Flags */
arch/riscv/kernel/cpufeature.c +3 -0
index ca7a34f66738..b001e78eecf6 100644
@@ -488,6 +488,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate),
 	__RISCV_ISA_EXT_DATA_VALIDATE(zicbop, RISCV_ISA_EXT_ZICBOP, riscv_ext_zicbop_validate),
 	__RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate),
+	__RISCV_ISA_EXT_DATA(ziccamoa, RISCV_ISA_EXT_ZICCAMOA),
+	__RISCV_ISA_EXT_DATA(ziccif, RISCV_ISA_EXT_ZICCIF),
 	__RISCV_ISA_EXT_DATA(zicclsm, RISCV_ISA_EXT_ZICCLSM),
 	__RISCV_ISA_EXT_DATA(ziccrse, RISCV_ISA_EXT_ZICCRSE),
 	__RISCV_ISA_EXT_DATA(zicntr, RISCV_ISA_EXT_ZICNTR),
@@ -498,6 +500,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
 	__RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE),
 	__RISCV_ISA_EXT_DATA(zihpm, RISCV_ISA_EXT_ZIHPM),
 	__RISCV_ISA_EXT_DATA(zimop, RISCV_ISA_EXT_ZIMOP),
+	__RISCV_ISA_EXT_DATA(za64rs, RISCV_ISA_EXT_ZA64RS),
 	__RISCV_ISA_EXT_DATA(zaamo, RISCV_ISA_EXT_ZAAMO),
 	__RISCV_ISA_EXT_DATA(zabha, RISCV_ISA_EXT_ZABHA),
 	__RISCV_ISA_EXT_DATA(zacas, RISCV_ISA_EXT_ZACAS),
arch/riscv/kernel/sys_hwprobe.c +5 -2
index 76e673ab42a5..31d222301bf0 100644
@@ -196,7 +196,7 @@ static void hwprobe_isa_ext1(struct riscv_hwprobe *pair,
 	 * doesn't have.
 	 */
 	for_each_cpu(cpu, cpus) {
-		/* struct riscv_isainfo *isainfo = &hart_isa[cpu]; */
+		struct riscv_isainfo *isainfo = &hart_isa[cpu];
 
 		/*
 		 * Only use EXT_KEY() for extensions which can be
@@ -204,7 +204,10 @@ static void hwprobe_isa_ext1(struct riscv_hwprobe *pair,
 		 * configuration, as no other checks, besides presence
 		 * in the hart_isa bitmap, are made.
 		 */
-		/* Nothing here yet */
+		EXT_KEY(isainfo->isa, ZICCAMOA, pair->value, missing);
+		EXT_KEY(isainfo->isa, ZICCIF, pair->value, missing);
+		EXT_KEY(isainfo->isa, ZICCRSE, pair->value, missing);
+		EXT_KEY(isainfo->isa, ZA64RS, pair->value, missing);
 	}
 
 	/* Now turn off reporting features if any CPU is missing it. */
Signature · 1 line
2.43.0
#13 lore raw

Re: [RFC PATCH v1 06/11] riscv: Add Ziccamoa, Ziccif, Ziccrse, and Za64rs to hwprobe

Quoted 70 lines · Andrew Jones

Ziccrse is already present in cpufeature.

---
 Documentation/arch/riscv/hwprobe.rst  | 16 ++++++++++++++++
 arch/riscv/include/asm/hwcap.h        |  3 +++
 arch/riscv/include/uapi/asm/hwprobe.h |  4 ++++
 arch/riscv/kernel/cpufeature.c        |  3 +++
 arch/riscv/kernel/sys_hwprobe.c       |  7 +++++--
 5 files changed, 31 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +16 -0
index 4484f2a7f798..97226b7c5936 100644
@@ -395,3 +395,19 @@ The following keys are defined:
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_1`: A bitmask containing additional
   extensions that are compatible with the
   :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`: base system behavior.
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCAMOA`: The Ziccamoa extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCIF`: The Ziccif extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCRSE`: The Ziccrse extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZA64RS`: The Za64rs extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
arch/riscv/include/asm/hwcap.h +3 -0
index c17e11caca83..8e764dbc7413 100644
@@ -112,6 +112,9 @@
 #define RISCV_ISA_EXT_ZILSD            102
 #define RISCV_ISA_EXT_ZCLSD            103
 #define RISCV_ISA_EXT_ZICCLSM          104
+#define RISCV_ISA_EXT_ZICCAMOA         105
+#define RISCV_ISA_EXT_ZICCIF           106
+#define RISCV_ISA_EXT_ZA64RS           107
 
 #define RISCV_ISA_EXT_XLINUXENVCFG     127
 
arch/riscv/include/uapi/asm/hwprobe.h +4 -0
index 6a0163b54718..fed9ea6fd2b5 100644
@@ -115,6 +115,10 @@ struct riscv_hwprobe {
 #define RISCV_HWPROBE_KEY_VENDOR_EXT_MIPS_0    14
 #define RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE    15
 #define RISCV_HWPROBE_KEY_IMA_EXT_1            16
+#define                RISCV_HWPROBE_EXT_ZICCAMOA      (1 << 0)
+#define                RISCV_HWPROBE_EXT_ZICCIF        (1 << 1)
+#define                RISCV_HWPROBE_EXT_ZICCRSE       (1 << 2)
+#define                RISCV_HWPROBE_EXT_ZA64RS        (1 << 3)
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
 /* Flags */
arch/riscv/kernel/cpufeature.c +0 -0
index ca7a34f66738..b001e78eecf6 100644

arch/riscv/kernel/cpufeature.c const struct riscv_isa_ext_data riscv_isa_ext[] = { · line 491

Quoted 4 lines
arch/riscv/kernel/cpufeature.c +1 -0
@@ -488,6 +488,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
        __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate),
        __RISCV_ISA_EXT_DATA_VALIDATE(zicbop, RISCV_ISA_EXT_ZICBOP, riscv_ext_zicbop_validate),
        __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate),
+       __RISCV_ISA_EXT_DATA(ziccamoa, RISCV_ISA_EXT_ZICCAMOA),

It might be good to also enforce extension dependencies here:
Za64rs depends on Zalrsc, and Ziccamoa depends on Zaamo. I did something similar in my series [1]. Like this:

+ __RISCV_ISA_EXT_DATA_VALIDATE(ziccamoa, RISCV_ISA_EXT_ZICCAMOA, riscv_ext_zaamo_depends),

If you agree, I can prepare a standalone patch adding these dependency checks and send it your way.

arch/riscv/kernel/cpufeature.c const struct riscv_isa_ext_data riscv_isa_ext[] = { · line 503

Quoted 9 lines
arch/riscv/kernel/cpufeature.c +2 -0
+       __RISCV_ISA_EXT_DATA(ziccif, RISCV_ISA_EXT_ZICCIF),
        __RISCV_ISA_EXT_DATA(zicclsm, RISCV_ISA_EXT_ZICCLSM),
        __RISCV_ISA_EXT_DATA(ziccrse, RISCV_ISA_EXT_ZICCRSE),
        __RISCV_ISA_EXT_DATA(zicntr, RISCV_ISA_EXT_ZICNTR),
@@ -498,6 +500,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
        __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE),
        __RISCV_ISA_EXT_DATA(zihpm, RISCV_ISA_EXT_ZIHPM),
        __RISCV_ISA_EXT_DATA(zimop, RISCV_ISA_EXT_ZIMOP),
+       __RISCV_ISA_EXT_DATA(za64rs, RISCV_ISA_EXT_ZA64RS),

And add dependency here for za64rs:
+ __RISCV_ISA_EXT_DATA_VALIDATE(za64rs, RISCV_ISA_EXT_ZA64RS,
riscv_ext_zalrsc_depends),

BR,
Guodong

Guodong

Quoted 31 lines
arch/riscv/kernel/cpufeature.c +0 -0
        __RISCV_ISA_EXT_DATA(zaamo, RISCV_ISA_EXT_ZAAMO),
        __RISCV_ISA_EXT_DATA(zabha, RISCV_ISA_EXT_ZABHA),
        __RISCV_ISA_EXT_DATA(zacas, RISCV_ISA_EXT_ZACAS),
arch/riscv/kernel/sys_hwprobe.c +5 -3
index 76e673ab42a5..31d222301bf0 100644
@@ -196,7 +196,7 @@ static void hwprobe_isa_ext1(struct riscv_hwprobe *pair,
         * doesn't have.
         */
        for_each_cpu(cpu, cpus) {
-               /* struct riscv_isainfo *isainfo = &hart_isa[cpu]; */
+               struct riscv_isainfo *isainfo = &hart_isa[cpu];
 
                /*
                 * Only use EXT_KEY() for extensions which can be
@@ -204,7 +204,10 @@ static void hwprobe_isa_ext1(struct riscv_hwprobe *pair,
                 * configuration, as no other checks, besides presence
                 * in the hart_isa bitmap, are made.
                 */
-               /* Nothing here yet */
+               EXT_KEY(isainfo->isa, ZICCAMOA, pair->value, missing);
+               EXT_KEY(isainfo->isa, ZICCIF, pair->value, missing);
+               EXT_KEY(isainfo->isa, ZICCRSE, pair->value, missing);
+               EXT_KEY(isainfo->isa, ZA64RS, pair->value, missing);
        }
 
        /* Now turn off reporting features if any CPU is missing it. */
--

2.43.0

#14 lore raw

Re: [RFC PATCH v1 06/11] riscv: Add Ziccamoa, Ziccif, Ziccrse, and Za64rs to hwprobe

Quoted 66 lines · Guodong Xu
Quoted 64 lines · Andrew Jones

Ziccrse is already present in cpufeature.

---
 Documentation/arch/riscv/hwprobe.rst  | 16 ++++++++++++++++
 arch/riscv/include/asm/hwcap.h        |  3 +++
 arch/riscv/include/uapi/asm/hwprobe.h |  4 ++++
 arch/riscv/kernel/cpufeature.c        |  3 +++
 arch/riscv/kernel/sys_hwprobe.c       |  7 +++++--
 5 files changed, 31 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +16 -0
index 4484f2a7f798..97226b7c5936 100644
@@ -395,3 +395,19 @@ The following keys are defined:
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_1`: A bitmask containing additional
   extensions that are compatible with the
   :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`: base system behavior.
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCAMOA`: The Ziccamoa extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCIF`: The Ziccif extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZICCRSE`: The Ziccrse extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
+
+  * :c:macro:`RISCV_HWPROBE_EXT_ZA64RS`: The Za64rs extension is supported,
+    as defined in the RISC-V Profiles specification starting from commit
+    b1d80660 ("Updated to ratified state.")
arch/riscv/include/asm/hwcap.h +3 -0
index c17e11caca83..8e764dbc7413 100644
@@ -112,6 +112,9 @@
 #define RISCV_ISA_EXT_ZILSD            102
 #define RISCV_ISA_EXT_ZCLSD            103
 #define RISCV_ISA_EXT_ZICCLSM          104
+#define RISCV_ISA_EXT_ZICCAMOA         105
+#define RISCV_ISA_EXT_ZICCIF           106
+#define RISCV_ISA_EXT_ZA64RS           107
 
 #define RISCV_ISA_EXT_XLINUXENVCFG     127
 
arch/riscv/include/uapi/asm/hwprobe.h +4 -0
index 6a0163b54718..fed9ea6fd2b5 100644
@@ -115,6 +115,10 @@ struct riscv_hwprobe {
 #define RISCV_HWPROBE_KEY_VENDOR_EXT_MIPS_0    14
 #define RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE    15
 #define RISCV_HWPROBE_KEY_IMA_EXT_1            16
+#define                RISCV_HWPROBE_EXT_ZICCAMOA      (1 << 0)
+#define                RISCV_HWPROBE_EXT_ZICCIF        (1 << 1)
+#define                RISCV_HWPROBE_EXT_ZICCRSE       (1 << 2)
+#define                RISCV_HWPROBE_EXT_ZA64RS        (1 << 3)
 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
 
Quoted 13 lines

arch/riscv/kernel/cpufeature.c const struct riscv_isa_ext_data riscv_isa_ext[] = { · line 491

Quoted 10 lines
arch/riscv/include/uapi/asm/hwprobe.h +0 -0
 /* Flags */
arch/riscv/kernel/cpufeature.c +1 -0
index ca7a34f66738..b001e78eecf6 100644
@@ -488,6 +488,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
        __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts, riscv_ext_zicbom_validate),
        __RISCV_ISA_EXT_DATA_VALIDATE(zicbop, RISCV_ISA_EXT_ZICBOP, riscv_ext_zicbop_validate),
        __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate),
+       __RISCV_ISA_EXT_DATA(ziccamoa, RISCV_ISA_EXT_ZICCAMOA),

It might be good to also enforce extension dependencies here:
Za64rs depends on Zalrsc, and Ziccamoa depends on Zaamo.

There's certainly a practical "dependency". Za64rs wouldn't make much sense to support without instructions that need a reservation set. And similarly Ziccamoa doesn't make much sense without Zaamo. However, I'm not aware of anything that explicitly states Ziccamoa implies Zaamo or Za64rs implies Zalrsc. So, in the absence of any rules, I vote we leave them independent.

Thanks,
drew

#15 lore raw

RFC PATCH 7/11 riscv: Export have_user_pmlen* booleans

In reply to Andrew Jones

A following patch will need to access have_user_pmlen_7 from another file.

---
 arch/riscv/kernel/process.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/riscv/kernel/process.c +6 -6
index 31a392993cb4..4fa14aff7f8d 100644
@@ -274,8 +274,8 @@ enum {
 	PMLEN_16 = 16,
 };
 
-static bool have_user_pmlen_7;
-static bool have_user_pmlen_16;
+bool riscv_have_user_pmlen_7;
+bool riscv_have_user_pmlen_16;
 
 /*
  * Control the relaxed ABI allowing tagged user addresses into the kernel.
@@ -306,10 +306,10 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg)
 	pmlen = FIELD_GET(PR_PMLEN_MASK, arg);
 	if (pmlen == PMLEN_0) {
 		pmm = ENVCFG_PMM_PMLEN_0;
-	} else if (pmlen <= PMLEN_7 && have_user_pmlen_7) {
+	} else if (pmlen <= PMLEN_7 && riscv_have_user_pmlen_7) {
 		pmlen = PMLEN_7;
 		pmm = ENVCFG_PMM_PMLEN_7;
-	} else if (pmlen <= PMLEN_16 && have_user_pmlen_16) {
+	} else if (pmlen <= PMLEN_16 && riscv_have_user_pmlen_16) {
 		pmlen = PMLEN_16;
 		pmm = ENVCFG_PMM_PMLEN_16;
 	} else {
@@ -407,8 +407,8 @@ static int __init tagged_addr_init(void)
 	 * Assume the supported PMLEN values are the same on all harts.
 	 */
 	csr_clear(CSR_ENVCFG, ENVCFG_PMM);
-	have_user_pmlen_7 = try_to_set_pmm(ENVCFG_PMM_PMLEN_7);
-	have_user_pmlen_16 = try_to_set_pmm(ENVCFG_PMM_PMLEN_16);
+	riscv_have_user_pmlen_7 = try_to_set_pmm(ENVCFG_PMM_PMLEN_7);
+	riscv_have_user_pmlen_16 = try_to_set_pmm(ENVCFG_PMM_PMLEN_16);
 
 	if (!register_sysctl("abi", tagged_addr_sysctl_table))
 		return -EINVAL;
Signature · 1 line
2.43.0
#16 lore raw

Re: [RFC PATCH v1 07/11] riscv: Export have_user_pmlen* booleans

Quoted 3 lines · Andrew Jones

A following patch will need to access have_user_pmlen_7 from another file.

The variables are made non-static here but without an extern declaration in a header.

How about adding the declarations to asm/processor.h, inside the protection of the CONFIG_RISCV_ISA_SUPM block?

sys_hwprobe.c already includes asm/processor.h, so no new includes would be needed.

PS: I spotted one more of your patch [10/11] refers to it, which adds another bare extern in cpufeature.c.

BR,
Guodong

Quoted 48 lines
---
 arch/riscv/kernel/process.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/riscv/kernel/process.c +6 -7
index 31a392993cb4..4fa14aff7f8d 100644
@@ -274,8 +274,8 @@ enum {
        PMLEN_16 = 16,
 };
 
-static bool have_user_pmlen_7;
-static bool have_user_pmlen_16;
+bool riscv_have_user_pmlen_7;
+bool riscv_have_user_pmlen_16;
 
 /*
  * Control the relaxed ABI allowing tagged user addresses into the kernel.
@@ -306,10 +306,10 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg)
        pmlen = FIELD_GET(PR_PMLEN_MASK, arg);
        if (pmlen == PMLEN_0) {
                pmm = ENVCFG_PMM_PMLEN_0;
-       } else if (pmlen <= PMLEN_7 && have_user_pmlen_7) {
+       } else if (pmlen <= PMLEN_7 && riscv_have_user_pmlen_7) {
                pmlen = PMLEN_7;
                pmm = ENVCFG_PMM_PMLEN_7;
-       } else if (pmlen <= PMLEN_16 && have_user_pmlen_16) {
+       } else if (pmlen <= PMLEN_16 && riscv_have_user_pmlen_16) {
                pmlen = PMLEN_16;
                pmm = ENVCFG_PMM_PMLEN_16;
        } else {
@@ -407,8 +407,8 @@ static int __init tagged_addr_init(void)
         * Assume the supported PMLEN values are the same on all harts.
         */
        csr_clear(CSR_ENVCFG, ENVCFG_PMM);
-       have_user_pmlen_7 = try_to_set_pmm(ENVCFG_PMM_PMLEN_7);
-       have_user_pmlen_16 = try_to_set_pmm(ENVCFG_PMM_PMLEN_16);
+       riscv_have_user_pmlen_7 = try_to_set_pmm(ENVCFG_PMM_PMLEN_7);
+       riscv_have_user_pmlen_16 = try_to_set_pmm(ENVCFG_PMM_PMLEN_16);
 
        if (!register_sysctl("abi", tagged_addr_sysctl_table))
                return -EINVAL;
--

2.43.0

#17 lore raw

Re: [RFC PATCH v1 07/11] riscv: Export have_user_pmlen* booleans

Quoted 11 lines · Guodong Xu
Quoted 3 lines · Andrew Jones

A following patch will need to access have_user_pmlen_7 from another file.

The variables are made non-static here but without an extern declaration in a header.

How about adding the declarations to asm/processor.h, inside the protection of the CONFIG_RISCV_ISA_SUPM block?

Yes, I guess asm/processor.h is a random enough collection of stuff that have_user_pmlen_7 fits in there as well as anywhere else. Maybe I'll add a getter function instead, though

bool riscv_have_user_pmlen(u32 len)

Thanks,
drew

Quoted 60 lines

sys_hwprobe.c already includes asm/processor.h, so no new includes would be needed.

PS: I spotted one more of your patch [10/11] refers to it, which adds another bare extern in cpufeature.c.

BR,
Guodong

Quoted 48 lines
---
 arch/riscv/kernel/process.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/riscv/kernel/process.c +6 -7
index 31a392993cb4..4fa14aff7f8d 100644
@@ -274,8 +274,8 @@ enum {
        PMLEN_16 = 16,
 };
 
-static bool have_user_pmlen_7;
-static bool have_user_pmlen_16;
+bool riscv_have_user_pmlen_7;
+bool riscv_have_user_pmlen_16;
 
 /*
  * Control the relaxed ABI allowing tagged user addresses into the kernel.
@@ -306,10 +306,10 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg)
        pmlen = FIELD_GET(PR_PMLEN_MASK, arg);
        if (pmlen == PMLEN_0) {
                pmm = ENVCFG_PMM_PMLEN_0;
-       } else if (pmlen <= PMLEN_7 && have_user_pmlen_7) {
+       } else if (pmlen <= PMLEN_7 && riscv_have_user_pmlen_7) {
                pmlen = PMLEN_7;
                pmm = ENVCFG_PMM_PMLEN_7;
-       } else if (pmlen <= PMLEN_16 && have_user_pmlen_16) {
+       } else if (pmlen <= PMLEN_16 && riscv_have_user_pmlen_16) {
                pmlen = PMLEN_16;
                pmm = ENVCFG_PMM_PMLEN_16;
        } else {
@@ -407,8 +407,8 @@ static int __init tagged_addr_init(void)
         * Assume the supported PMLEN values are the same on all harts.
         */
        csr_clear(CSR_ENVCFG, ENVCFG_PMM);
-       have_user_pmlen_7 = try_to_set_pmm(ENVCFG_PMM_PMLEN_7);
-       have_user_pmlen_16 = try_to_set_pmm(ENVCFG_PMM_PMLEN_16);
+       riscv_have_user_pmlen_7 = try_to_set_pmm(ENVCFG_PMM_PMLEN_7);
+       riscv_have_user_pmlen_16 = try_to_set_pmm(ENVCFG_PMM_PMLEN_16);
 
        if (!register_sysctl("abi", tagged_addr_sysctl_table))
                return -EINVAL;
--

2.43.0

#18 lore raw

RFC PATCH 8/11 riscv: hwprobe: Introduce rva23u64 base behavior

In reply to Andrew Jones

Provide a bit to conveniently determine when RVA23U64 is supported. While it's already possible to determine RVA23U64 support with five hwprobe calls and four prctl calls it would be error-prone to require anything (and we presume eventually almost everything) that needs to check for RVA23U64 support to all implement those calls and specific checks. And, while RVA23U64 is the IMA base with mandated extensions, most software will consider it a new base. For these reasons, add the RVA23U64 bit as a base behavior bit.

---
 Documentation/arch/riscv/hwprobe.rst          |  8 +++
 arch/riscv/include/uapi/asm/hwprobe.h         |  3 +-
 arch/riscv/kernel/sys_hwprobe.c               | 72 +++++++++++++++++++
 .../selftests/riscv/hwprobe/which-cpus.c      |  2 +-
 4 files changed, 83 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +8 -0
index 97226b7c5936..6d915e7ba58a 100644
@@ -67,6 +67,14 @@ The following keys are defined:
       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 b1d80660 ("Updated to ratified state.")
+
+    The RVA23U64 base is based upon the IMA base and therefore IMA extension
+    keys (e.g. :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`:) may be used to probe
+    optional extensions.
+
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`: A bitmask containing the extensions
   that are compatible with the :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`:
   base system behavior.
arch/riscv/include/uapi/asm/hwprobe.h +2 -1
index fed9ea6fd2b5..72d2a4d0b733 100644
@@ -21,7 +21,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	(1 << 0)
+#define		RISCV_HWPROBE_BASE_BEHAVIOR_IMA		(1 << 0)
+#define		RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64	(1 << 1)
 #define RISCV_HWPROBE_KEY_IMA_EXT_0	4
 #define		RISCV_HWPROBE_IMA_FD		(1 << 0)
 #define		RISCV_HWPROBE_IMA_C		(1 << 1)
arch/riscv/kernel/sys_hwprobe.c +72 -0

90 lines not on this page · raw message

tools/testing/selftests/riscv/hwprobe/which-cpus.c +1 -1
index 587feb198c04..f8c797b1d0fd 100644
@@ -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);
Signature · 1 line
2.43.0
#19 lore raw
kernel test robot noticed the following build errors:

Hi Andrew,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on shuah-kselftest/fixes]
[also build test ERROR on linus/master v6.19-rc8]
[cannot apply to shuah-kselftest/next next-20260205]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andrew-Jones/riscv-hwprobe-add-support-for-RISCV_HWPROBE_KEY_IMA_EXT_1/20260206-082824
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git fixes
patch link:    https://lore.kernel.org/r/20260206002349.96740-9-andrew.jones%40oss.qualcomm.com
patch subject: [RFC PATCH v1 08/11] riscv: hwprobe: Introduce rva23u64 base behavior
config: riscv-allnoconfig (https://download.01.org/0day-ci/archive/20260207/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260207/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

riscv64-linux-ld: arch/riscv/kernel/sys_hwprobe.o: in function `hwprobe_isa_ext1':

>> sys_hwprobe.c:(.text+0xb1a): undefined reference to `riscv_have_user_pmlen_7'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#20 lore raw
In reply to Andrew Jones

On Thu, Feb 05, 2026 at 06:23:46PM -0600, Andrew Jones wrote:
...

Quoted 4 lines
(quoted diff) +4 -0
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+	struct riscv_hwprobe pair;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	if (!IS_ENABLED(CONFIG_64BIT))
+		return false;
+
+	/* Additional mandates for Zic64b and Supm */
+	if (riscv_cbom_block_size != 64 ||
+	    riscv_cbop_block_size != 64 ||
+	    riscv_cboz_block_size != 64 ||
+	    !riscv_have_user_pmlen_7)
+		return false;
+

Thanks to kernel test robot's report I'll fix the compilation of this for configs without RISCV_ISA_SUPM with the following change and something similar for patch10.

Thanks,
drew

arch/riscv/kernel/sys_hwprobe.c +1 -1
index 4b9981b15ebe..3fd63ac7dd60 100644
@@ -278,7 +278,7 @@ static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
        if (riscv_cbom_block_size != 64 ||
            riscv_cbop_block_size != 64 ||
            riscv_cboz_block_size != 64 ||
-           !riscv_have_user_pmlen_7)
+           !IS_ENABLED(CONFIG_RISCV_ISA_SUPM) || !riscv_have_user_pmlen_7)
                return false;
 
        hwprobe_isa_ext0(&pair, cpus);
#21 lore raw
In reply to Andrew Jones

Hi, Drew

Quoted 23 lines · Andrew Jones

Provide a bit to conveniently determine when RVA23U64 is supported. While it's already possible to determine RVA23U64 support with five hwprobe calls and four prctl calls it would be error-prone to require anything (and we presume eventually almost everything) that needs to check for RVA23U64 support to all implement those calls and specific checks. And, while RVA23U64 is the IMA base with mandated extensions, most software will consider it a new base. For these reasons, add the RVA23U64 bit as a base behavior bit.

---
 Documentation/arch/riscv/hwprobe.rst          |  8 +++
 arch/riscv/include/uapi/asm/hwprobe.h         |  3 +-
 arch/riscv/kernel/sys_hwprobe.c               | 72 +++++++++++++++++++
 .../selftests/riscv/hwprobe/which-cpus.c      |  2 +-
 4 files changed, 83 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +0 -0
index 97226b7c5936..6d915e7ba58a 100644

Documentation/arch/riscv/hwprobe.rst The following keys are defined: · line 72

Quoted 6 lines
Documentation/arch/riscv/hwprobe.rst +3 -0
@@ -67,6 +67,14 @@ The following keys are defined:
       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 b1d80660 ("Updated to ratified state.")

Should we reference the commit which ratifies RVA23 to its 1.0 version? I mean commit 0273f3c9 ("rva23/rvb23 ratified"), Oct 2024.

At commit b1d80660, rva23-profile.adoc exists and covers RVA23U64, however, it is still at revnumber 0.1-draft ("Development stage"). As its evolving nature, the content revolves from 0.1 to 1.0. I believe it's more useful to people to point them to a ratified version, instead of introducing history to them.

Another suggestion, how about just referring to the ratified 1.0 document itself, which can be found at RISC-V International's official website [1], following the link "Ratified Profiles Specification".

Quoted 27 lines
Documentation/arch/riscv/hwprobe.rst +5 -0
+
+    The RVA23U64 base is based upon the IMA base and therefore IMA extension
+    keys (e.g. :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`:) may be used to probe
+    optional extensions.
+
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`: A bitmask containing the extensions
   that are compatible with the :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`:
   base system behavior.
arch/riscv/include/uapi/asm/hwprobe.h +2 -1
index fed9ea6fd2b5..72d2a4d0b733 100644
@@ -21,7 +21,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 (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_IMA         (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64    (1 << 1)
 #define RISCV_HWPROBE_KEY_IMA_EXT_0    4
 #define                RISCV_HWPROBE_IMA_FD            (1 << 0)
 #define                RISCV_HWPROBE_IMA_C             (1 << 1)
arch/riscv/kernel/sys_hwprobe.c +0 -0
index 31d222301bf0..4b9981b15ebe 100644

arch/riscv/kernel/sys_hwprobe.c line 26

Quoted 4 lines
arch/riscv/kernel/sys_hwprobe.c +1 -0
@@ -23,6 +23,7 @@
 #include <asm/vendor_extensions/thead_hwprobe.h>
 #include <vdso/vsyscall.h>
 
+extern bool riscv_have_user_pmlen_7;

Suggest to put this in a header, like <asm/processor.h>

Quoted 80 lines
arch/riscv/kernel/sys_hwprobe.c +69 -0
 #define EXT_KEY(isa_arg, ext, pv, missing)                                     \
        do {                                                                            \
@@ -222,6 +223,75 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext)
        return (pair.value & ext);
 }
 
+#define HWPROBE_EXT0_RVA23U64 (                                        \
+       /* IMA is always supported */                           \
+       RISCV_HWPROBE_IMA_FD                            |       \
+       RISCV_HWPROBE_IMA_C                             |       \
+       /* B is Zba, Zbb and Zbs */                             \
+       RISCV_HWPROBE_EXT_ZBA                           |       \
+       RISCV_HWPROBE_EXT_ZBB                           |       \
+       RISCV_HWPROBE_EXT_ZBS                           |       \
+       /* ZICSR is always supported */                         \
+       RISCV_HWPROBE_EXT_ZICNTR                        |       \
+       RISCV_HWPROBE_EXT_ZIHPM                         |       \
+       /* ZICCIF is in EXT1 */                                 \
+       /* ZICCRSE is in EXT1 */                                \
+       /* ZICCAMOA is in EXT1 */                               \
+       RISCV_HWPROBE_EXT_ZICCLSM                       |       \
+       /* ZA64RS is in EXT1 */                                 \
+       RISCV_HWPROBE_EXT_ZIHINTPAUSE                   |       \
+       /* ZIC64B (check block sizes are 64b) */                \
+       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 /* (check PMLEN=7 support) */    \
+)
+
+#define HWPROBE_EXT1_RVA23U64 (                                        \
+       RISCV_HWPROBE_EXT_ZICCIF                        |       \
+       RISCV_HWPROBE_EXT_ZICCRSE                       |       \
+       RISCV_HWPROBE_EXT_ZICCAMOA                      |       \
+       RISCV_HWPROBE_EXT_ZA64RS                                \
+)
+
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+       struct riscv_hwprobe pair;
+
+       if (!IS_ENABLED(CONFIG_64BIT))
+               return false;
+
+       /* Additional mandates for Zic64b and Supm */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return false;
+
+       hwprobe_isa_ext0(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT0_RVA23U64) != HWPROBE_EXT0_RVA23U64)
+               return false;
+
+       hwprobe_isa_ext1(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT1_RVA23U64) != HWPROBE_EXT1_RVA23U64)
+               return false;
+
+       return true;
+}
+
 #if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS)
 static u64 hwprobe_misaligned(const struct cpumask *cpus)
 {

arch/riscv/kernel/sys_hwprobe.c static void hwprobe_one_pair(struct riscv_hwprobe *pair, · line 386

Quoted 5 lines
arch/riscv/kernel/sys_hwprobe.c +2 -0
@@ -312,6 +382,8 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
         */
        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;

There are two separate implementations of RVA23U64 detection in your patchset:
1. In this patch: hwprobe_has_rva23u64(), which checks against RISCV_HWPROBE_EXT_* bits.
2. In [Patch 10/11]: riscv_set_isa_bases(), which checks against RISCV_ISA_EXT_*.

I'm not sure I fully understand your reasoning behind this duplication (it's too obvious for me not to doubt myself). At least for now, I think the hwprobe version is not good from an architecture viewpoint.

My logic is this: RVA23U64 is a hardware implementation feature. It exists no matter whether you export its sub-components (those mandatory extensions required by RVA23 Profile) through hwprobe or not. Profile conformance vs. per-extension export should stay independent.

DT/ACPI -> RISCV_ISA_EXT_*: these are ground truth. RISCV_HWPROBE_EXT_*: these are a filtered subset.

We shouldn't be pushed to export (hwprobe) an extension just to make the RVA23U64 calculation correct. The criteria for exporting an extension through hwprobe should be based on whether there is a userspace consumer who needs it individually.

BR,
Guodong

Quoted 19 lines
arch/riscv/kernel/sys_hwprobe.c +0 -0
                break;
 
        case RISCV_HWPROBE_KEY_IMA_EXT_0:
tools/testing/selftests/riscv/hwprobe/which-cpus.c +1 -2
index 587feb198c04..f8c797b1d0fd 100644
@@ -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

#22 lore raw
Quoted 43 lines · Guodong Xu

Hi, Drew

Quoted 23 lines · Andrew Jones

Provide a bit to conveniently determine when RVA23U64 is supported. While it's already possible to determine RVA23U64 support with five hwprobe calls and four prctl calls it would be error-prone to require anything (and we presume eventually almost everything) that needs to check for RVA23U64 support to all implement those calls and specific checks. And, while RVA23U64 is the IMA base with mandated extensions, most software will consider it a new base. For these reasons, add the RVA23U64 bit as a base behavior bit.

---
 Documentation/arch/riscv/hwprobe.rst          |  8 +++
 arch/riscv/include/uapi/asm/hwprobe.h         |  3 +-
 arch/riscv/kernel/sys_hwprobe.c               | 72 +++++++++++++++++++
 .../selftests/riscv/hwprobe/which-cpus.c      |  2 +-
 4 files changed, 83 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +0 -0
index 97226b7c5936..6d915e7ba58a 100644

Documentation/arch/riscv/hwprobe.rst The following keys are defined: · line 72

Quoted 6 lines
Documentation/arch/riscv/hwprobe.rst +3 -0
@@ -67,6 +67,14 @@ The following keys are defined:
       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 b1d80660 ("Updated to ratified state.")

Should we reference the commit which ratifies RVA23 to its 1.0 version? I mean commit 0273f3c9 ("rva23/rvb23 ratified"), Oct 2024.

At commit b1d80660, rva23-profile.adoc exists and covers RVA23U64, however, it is still at revnumber 0.1-draft ("Development stage"). As its evolving nature, the content revolves from 0.1 to 1.0. I believe it's more useful to people to point them to a ratified version, instead of introducing history to them.

Quoted 5 lines

Another suggestion, how about just referring to the ratified 1.0 document itself, which can be found at RISC-V International's official website [1], following the link "Ratified Profiles Specification".

I prefer a commit, like we do for the extensions, but the commit you point out looks like the correct one according to the Oct 2024 date, which matches the PDF date on the web page.

Quoted 128 lines
Quoted 28 lines
Documentation/arch/riscv/hwprobe.rst +5 -0
+
+    The RVA23U64 base is based upon the IMA base and therefore IMA extension
+    keys (e.g. :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`:) may be used to probe
+    optional extensions.
+
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`: A bitmask containing the extensions
   that are compatible with the :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`:
   base system behavior.
arch/riscv/include/uapi/asm/hwprobe.h +2 -1
index fed9ea6fd2b5..72d2a4d0b733 100644
@@ -21,7 +21,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 (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_IMA         (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64    (1 << 1)
 #define RISCV_HWPROBE_KEY_IMA_EXT_0    4
 #define                RISCV_HWPROBE_IMA_FD            (1 << 0)
 #define                RISCV_HWPROBE_IMA_C             (1 << 1)
arch/riscv/kernel/sys_hwprobe.c +0 -0
index 31d222301bf0..4b9981b15ebe 100644

arch/riscv/kernel/sys_hwprobe.c line 26

Quoted 4 lines
arch/riscv/kernel/sys_hwprobe.c +1 -0
@@ -23,6 +23,7 @@
 #include <asm/vendor_extensions/thead_hwprobe.h>
 #include <vdso/vsyscall.h>
 
+extern bool riscv_have_user_pmlen_7;

Suggest to put this in a header, like <asm/processor.h>

Quoted 80 lines
arch/riscv/kernel/sys_hwprobe.c +69 -0
 #define EXT_KEY(isa_arg, ext, pv, missing)                                     \
        do {                                                                            \
@@ -222,6 +223,75 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext)
        return (pair.value & ext);
 }
 
+#define HWPROBE_EXT0_RVA23U64 (                                        \
+       /* IMA is always supported */                           \
+       RISCV_HWPROBE_IMA_FD                            |       \
+       RISCV_HWPROBE_IMA_C                             |       \
+       /* B is Zba, Zbb and Zbs */                             \
+       RISCV_HWPROBE_EXT_ZBA                           |       \
+       RISCV_HWPROBE_EXT_ZBB                           |       \
+       RISCV_HWPROBE_EXT_ZBS                           |       \
+       /* ZICSR is always supported */                         \
+       RISCV_HWPROBE_EXT_ZICNTR                        |       \
+       RISCV_HWPROBE_EXT_ZIHPM                         |       \
+       /* ZICCIF is in EXT1 */                                 \
+       /* ZICCRSE is in EXT1 */                                \
+       /* ZICCAMOA is in EXT1 */                               \
+       RISCV_HWPROBE_EXT_ZICCLSM                       |       \
+       /* ZA64RS is in EXT1 */                                 \
+       RISCV_HWPROBE_EXT_ZIHINTPAUSE                   |       \
+       /* ZIC64B (check block sizes are 64b) */                \
+       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 /* (check PMLEN=7 support) */    \
+)
+
+#define HWPROBE_EXT1_RVA23U64 (                                        \
+       RISCV_HWPROBE_EXT_ZICCIF                        |       \
+       RISCV_HWPROBE_EXT_ZICCRSE                       |       \
+       RISCV_HWPROBE_EXT_ZICCAMOA                      |       \
+       RISCV_HWPROBE_EXT_ZA64RS                                \
+)
+
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+       struct riscv_hwprobe pair;
+
+       if (!IS_ENABLED(CONFIG_64BIT))
+               return false;
+
+       /* Additional mandates for Zic64b and Supm */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return false;
+
+       hwprobe_isa_ext0(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT0_RVA23U64) != HWPROBE_EXT0_RVA23U64)
+               return false;
+
+       hwprobe_isa_ext1(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT1_RVA23U64) != HWPROBE_EXT1_RVA23U64)
+               return false;
+
+       return true;
+}
+
 #if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS)
 static u64 hwprobe_misaligned(const struct cpumask *cpus)
 {

arch/riscv/kernel/sys_hwprobe.c static void hwprobe_one_pair(struct riscv_hwprobe *pair, · line 386

Quoted 5 lines
arch/riscv/kernel/sys_hwprobe.c +2 -0
@@ -312,6 +382,8 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
         */
        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;

There are two separate implementations of RVA23U64 detection in your patchset:
1. In this patch: hwprobe_has_rva23u64(), which checks against RISCV_HWPROBE_EXT_* bits.
2. In [Patch 10/11]: riscv_set_isa_bases(), which checks against RISCV_ISA_EXT_*.

Quoted 2 lines

I'm not sure I fully understand your reasoning behind this duplication (it's too obvious for me not to doubt myself).

We purposely use hwprobe bits in hwprobe since we want to ensure consistency. We use the isa bits everywhere else as that's the typical place to check.

Quoted 10 lines

At
least for now, I think the hwprobe version is not good from an architecture viewpoint.

My logic is this: RVA23U64 is a hardware implementation feature. It exists no matter whether you export its sub-components (those mandatory extensions required by RVA23 Profile) through hwprobe or not. Profile conformance vs. per-extension export should stay independent.

Quoted 8 lines

DT/ACPI -> RISCV_ISA_EXT_*: these are ground truth. RISCV_HWPROBE_EXT_*: these are a filtered subset.

We shouldn't be pushed to export (hwprobe) an extension just to make the RVA23U64 calculation correct. The criteria for exporting an extension through hwprobe should be based on whether there is a userspace consumer who needs it individually.

I agree with the "only publish stuff in hwprobe that users care about" approach and we do have precedent for not publishing extensions covered by the base already (I, M, and A are not individually in hwprobe -- although they are in hwcap).

For this series I could drop any extensions that people are unlikely to care about individually from hwprobe. Anyway, they can always be added later when needed. I was fond of my hwprobe consistency selftest though...

Thanks,
drew

Signature · 3 lines
kvm-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kvm-riscv
#23 lore raw
Quoted 131 lines · Andrew Jones
Quoted 103 lines · Guodong Xu

Hi, Drew

Quoted 86 lines · Andrew Jones

Provide a bit to conveniently determine when RVA23U64 is supported. While it's already possible to determine RVA23U64 support with five hwprobe calls and four prctl calls it would be error-prone to require anything (and we presume eventually almost everything) that needs to check for RVA23U64 support to all implement those calls and specific checks. And, while RVA23U64 is the IMA base with mandated extensions, most software will consider it a new base. For these reasons, add the RVA23U64 bit as a base behavior bit.

---

arch/riscv/kernel/sys_hwprobe.c +69 -0
+#define HWPROBE_EXT0_RVA23U64 (                                        \
+       /* IMA is always supported */                           \
+       RISCV_HWPROBE_IMA_FD                            |       \
+       RISCV_HWPROBE_IMA_C                             |       \
+       /* B is Zba, Zbb and Zbs */                             \
+       RISCV_HWPROBE_EXT_ZBA                           |       \
+       RISCV_HWPROBE_EXT_ZBB                           |       \
+       RISCV_HWPROBE_EXT_ZBS                           |       \
+       /* ZICSR is always supported */                         \
+       RISCV_HWPROBE_EXT_ZICNTR                        |       \
+       RISCV_HWPROBE_EXT_ZIHPM                         |       \
+       /* ZICCIF is in EXT1 */                                 \
+       /* ZICCRSE is in EXT1 */                                \
+       /* ZICCAMOA is in EXT1 */                               \
+       RISCV_HWPROBE_EXT_ZICCLSM                       |       \
+       /* ZA64RS is in EXT1 */                                 \
+       RISCV_HWPROBE_EXT_ZIHINTPAUSE                   |       \
+       /* ZIC64B (check block sizes are 64b) */                \
+       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 /* (check PMLEN=7 support) */    \
+)
+
+#define HWPROBE_EXT1_RVA23U64 (                                        \
+       RISCV_HWPROBE_EXT_ZICCIF                        |       \
+       RISCV_HWPROBE_EXT_ZICCRSE                       |       \
+       RISCV_HWPROBE_EXT_ZICCAMOA                      |       \
+       RISCV_HWPROBE_EXT_ZA64RS                                \
+)
+
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+       struct riscv_hwprobe pair;
+
+       if (!IS_ENABLED(CONFIG_64BIT))
+               return false;
+
+       /* Additional mandates for Zic64b and Supm */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return false;
+
+       hwprobe_isa_ext0(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT0_RVA23U64) != HWPROBE_EXT0_RVA23U64)
+               return false;
+
+       hwprobe_isa_ext1(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT1_RVA23U64) != HWPROBE_EXT1_RVA23U64)
+               return false;
+
+       return true;
+}
+
 #if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS)
 static u64 hwprobe_misaligned(const struct cpumask *cpus)
 {

arch/riscv/kernel/sys_hwprobe.c static void hwprobe_one_pair(struct riscv_hwprobe *pair, · line 386

Quoted 5 lines
arch/riscv/kernel/sys_hwprobe.c +2 -0
@@ -312,6 +382,8 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
         */
        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;

There are two separate implementations of RVA23U64 detection in your patchset:
1. In this patch: hwprobe_has_rva23u64(), which checks against RISCV_HWPROBE_EXT_* bits.
2. In [Patch 10/11]: riscv_set_isa_bases(), which checks against RISCV_ISA_EXT_*.

Quoted 2 lines

I'm not sure I fully understand your reasoning behind this duplication (it's too obvious for me not to doubt myself).

We purposely use hwprobe bits in hwprobe since we want to ensure consistency. We use the isa bits everywhere else as that's the typical place to check.

Quoted 10 lines

At
least for now, I think the hwprobe version is not good from an architecture viewpoint.

My logic is this: RVA23U64 is a hardware implementation feature. It exists no matter whether you export its sub-components (those mandatory extensions required by RVA23 Profile) through hwprobe or not. Profile conformance vs. per-extension export should stay independent.

Quoted 8 lines

DT/ACPI -> RISCV_ISA_EXT_*: these are ground truth. RISCV_HWPROBE_EXT_*: these are a filtered subset.

We shouldn't be pushed to export (hwprobe) an extension just to make the RVA23U64 calculation correct. The criteria for exporting an extension through hwprobe should be based on whether there is a userspace consumer who needs it individually.

Quoted 6 lines

I agree with the "only publish stuff in hwprobe that users care about" approach and we do have precedent for not publishing extensions covered by the base already (I, M, and A are not individually in hwprobe -- although they are in hwcap).

For this series I could drop any extensions that people are unlikely to

I am not sure I understand you correctly. If any of the HWPROBE_EXT_ id is dropped, that will make your check in hwprobe_has_rva23u64() fail.

And that will cause a mismatch, where /proc/cpuinfo (ie. riscv_set_isa_bases()) reports 'rva23u64', but hwprobe reports no 'rva23u64'.

Is that what you intend, or do you mean something different?

Quoted 1 line

care about individually from hwprobe. Anyway, they can always be added

In my patchset [1] cover letter, I explained that I prefer not to export via hwprobe Za64rs and Ziccamoa. Because, unlike others such as Zicclsm and Ziccif, I didn't see any user space usage of Za64rs and Ziccamoa.

But again, removing them from hwprobe will cause a rva23u64 report mismatch.

[1]: https://lore.kernel.org/all/[email protected]/
BR,
Guodong

Quoted 4 lines

later when needed. I was fond of my hwprobe consistency selftest though...

Thanks,
drew

#24 lore raw
Quoted 140 lines · Guodong Xu
Quoted 131 lines · Andrew Jones
Quoted 103 lines · Guodong Xu

Hi, Drew

Quoted 86 lines · Andrew Jones

Provide a bit to conveniently determine when RVA23U64 is supported. While it's already possible to determine RVA23U64 support with five hwprobe calls and four prctl calls it would be error-prone to require anything (and we presume eventually almost everything) that needs to check for RVA23U64 support to all implement those calls and specific checks. And, while RVA23U64 is the IMA base with mandated extensions, most software will consider it a new base. For these reasons, add the RVA23U64 bit as a base behavior bit.

---

arch/riscv/kernel/sys_hwprobe.c +69 -0
+#define HWPROBE_EXT0_RVA23U64 (                                        \
+       /* IMA is always supported */                           \
+       RISCV_HWPROBE_IMA_FD                            |       \
+       RISCV_HWPROBE_IMA_C                             |       \
+       /* B is Zba, Zbb and Zbs */                             \
+       RISCV_HWPROBE_EXT_ZBA                           |       \
+       RISCV_HWPROBE_EXT_ZBB                           |       \
+       RISCV_HWPROBE_EXT_ZBS                           |       \
+       /* ZICSR is always supported */                         \
+       RISCV_HWPROBE_EXT_ZICNTR                        |       \
+       RISCV_HWPROBE_EXT_ZIHPM                         |       \
+       /* ZICCIF is in EXT1 */                                 \
+       /* ZICCRSE is in EXT1 */                                \
+       /* ZICCAMOA is in EXT1 */                               \
+       RISCV_HWPROBE_EXT_ZICCLSM                       |       \
+       /* ZA64RS is in EXT1 */                                 \
+       RISCV_HWPROBE_EXT_ZIHINTPAUSE                   |       \
+       /* ZIC64B (check block sizes are 64b) */                \
+       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 /* (check PMLEN=7 support) */    \
+)
+
+#define HWPROBE_EXT1_RVA23U64 (                                        \
+       RISCV_HWPROBE_EXT_ZICCIF                        |       \
+       RISCV_HWPROBE_EXT_ZICCRSE                       |       \
+       RISCV_HWPROBE_EXT_ZICCAMOA                      |       \
+       RISCV_HWPROBE_EXT_ZA64RS                                \
+)
+
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+       struct riscv_hwprobe pair;
+
+       if (!IS_ENABLED(CONFIG_64BIT))
+               return false;
+
+       /* Additional mandates for Zic64b and Supm */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return false;
+
+       hwprobe_isa_ext0(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT0_RVA23U64) != HWPROBE_EXT0_RVA23U64)
+               return false;
+
+       hwprobe_isa_ext1(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT1_RVA23U64) != HWPROBE_EXT1_RVA23U64)
+               return false;
+
+       return true;
+}
+
 #if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS)
 static u64 hwprobe_misaligned(const struct cpumask *cpus)
 {

arch/riscv/kernel/sys_hwprobe.c static void hwprobe_one_pair(struct riscv_hwprobe *pair, · line 386

Quoted 5 lines
arch/riscv/kernel/sys_hwprobe.c +2 -0
@@ -312,6 +382,8 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
         */
        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;

There are two separate implementations of RVA23U64 detection in your patchset:
1. In this patch: hwprobe_has_rva23u64(), which checks against RISCV_HWPROBE_EXT_* bits.
2. In [Patch 10/11]: riscv_set_isa_bases(), which checks against RISCV_ISA_EXT_*.

Quoted 2 lines

I'm not sure I fully understand your reasoning behind this duplication (it's too obvious for me not to doubt myself).

We purposely use hwprobe bits in hwprobe since we want to ensure consistency. We use the isa bits everywhere else as that's the typical place to check.

Quoted 10 lines

At
least for now, I think the hwprobe version is not good from an architecture viewpoint.

My logic is this: RVA23U64 is a hardware implementation feature. It exists no matter whether you export its sub-components (those mandatory extensions required by RVA23 Profile) through hwprobe or not. Profile conformance vs. per-extension export should stay independent.

Quoted 8 lines

DT/ACPI -> RISCV_ISA_EXT_*: these are ground truth. RISCV_HWPROBE_EXT_*: these are a filtered subset.

We shouldn't be pushed to export (hwprobe) an extension just to make the RVA23U64 calculation correct. The criteria for exporting an extension through hwprobe should be based on whether there is a userspace consumer who needs it individually.

Quoted 6 lines

I agree with the "only publish stuff in hwprobe that users care about" approach and we do have precedent for not publishing extensions covered by the base already (I, M, and A are not individually in hwprobe -- although they are in hwcap).

For this series I could drop any extensions that people are unlikely to

Quoted 8 lines

I am not sure I understand you correctly. If any of the HWPROBE_EXT_ id is dropped, that will make your check in hwprobe_has_rva23u64() fail.

And that will cause a mismatch, where /proc/cpuinfo (ie. riscv_set_isa_bases()) reports 'rva23u64', but hwprobe reports no 'rva23u64'.

Is that what you intend, or do you mean something different?

The implementation of hwprobe_has_rva23u64() would have to change and all my consistency stuff, including the selftest, would be dropped.

Thanks,
drew

#25 lore raw
In reply to Andrew Jones

Hi, Drew

Quoted 66 lines · Andrew Jones

Provide a bit to conveniently determine when RVA23U64 is supported. While it's already possible to determine RVA23U64 support with five hwprobe calls and four prctl calls it would be error-prone to require anything (and we presume eventually almost everything) that needs to check for RVA23U64 support to all implement those calls and specific checks. And, while RVA23U64 is the IMA base with mandated extensions, most software will consider it a new base. For these reasons, add the RVA23U64 bit as a base behavior bit.

---
 Documentation/arch/riscv/hwprobe.rst          |  8 +++
 arch/riscv/include/uapi/asm/hwprobe.h         |  3 +-
 arch/riscv/kernel/sys_hwprobe.c               | 72 +++++++++++++++++++
 .../selftests/riscv/hwprobe/which-cpus.c      |  2 +-
 4 files changed, 83 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +8 -0
index 97226b7c5936..6d915e7ba58a 100644
@@ -67,6 +67,14 @@ The following keys are defined:
       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 b1d80660 ("Updated to ratified state.")
+
+    The RVA23U64 base is based upon the IMA base and therefore IMA extension
+    keys (e.g. :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`:) may be used to probe
+    optional extensions.
+
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`: A bitmask containing the extensions
   that are compatible with the :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`:
   base system behavior.
arch/riscv/include/uapi/asm/hwprobe.h +2 -1
index fed9ea6fd2b5..72d2a4d0b733 100644
@@ -21,7 +21,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 (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_IMA         (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64    (1 << 1)
 #define RISCV_HWPROBE_KEY_IMA_EXT_0    4
 #define                RISCV_HWPROBE_IMA_FD            (1 << 0)
 #define                RISCV_HWPROBE_IMA_C             (1 << 1)
arch/riscv/kernel/sys_hwprobe.c +1 -0
index 31d222301bf0..4b9981b15ebe 100644
@@ -23,6 +23,7 @@
 #include <asm/vendor_extensions/thead_hwprobe.h>
 #include <vdso/vsyscall.h>
 
+extern bool riscv_have_user_pmlen_7;
 
 #define EXT_KEY(isa_arg, ext, pv, missing)                                     \
        do {                                                                            \
@@ -222,6 +223,75 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext)
        return (pair.value & ext);
 }

arch/riscv/kernel/sys_hwprobe.c static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext) · line 234

Quoted 10 lines
arch/riscv/kernel/sys_hwprobe.c +9 -0
 
+#define HWPROBE_EXT0_RVA23U64 (                                        \
+       /* IMA is always supported */                           \
+       RISCV_HWPROBE_IMA_FD                            |       \
+       RISCV_HWPROBE_IMA_C                             |       \
+       /* B is Zba, Zbb and Zbs */                             \
+       RISCV_HWPROBE_EXT_ZBA                           |       \
+       RISCV_HWPROBE_EXT_ZBB                           |       \
+       RISCV_HWPROBE_EXT_ZBS                           |       \
+       /* ZICSR is always supported */                         \

About Zicsr always?
It is not rigorous compared to the other extensions that are checked explicitly.

With the deprecated 'riscv,isa' DT string (ACPI doesn't do this), "i" implies zicsr (along with zicntr, zifencei, zihpm). But with 'riscv,isa-extensions', zicsr must be listed explicitly, it is not automatically derived from "i". (see cputfeature.c)

BTW, this also serves as an example where:
- RISCV_ISA_EXT_ZICSR exists, (your patch 10 checked it)
- but no corresponding hwprobe export RISCV_HWPROBE_EXT_ZICSR.

So, as I suggested, it's better we detect rva23u64 as a combination of RISCV_ISA_EXT_...; instead of using RISCV_HWPROBE_EXT_...

Quoted 49 lines
arch/riscv/kernel/sys_hwprobe.c +49 -0
+       RISCV_HWPROBE_EXT_ZICNTR                        |       \
+       RISCV_HWPROBE_EXT_ZIHPM                         |       \
+       /* ZICCIF is in EXT1 */                                 \
+       /* ZICCRSE is in EXT1 */                                \
+       /* ZICCAMOA is in EXT1 */                               \
+       RISCV_HWPROBE_EXT_ZICCLSM                       |       \
+       /* ZA64RS is in EXT1 */                                 \
+       RISCV_HWPROBE_EXT_ZIHINTPAUSE                   |       \
+       /* ZIC64B (check block sizes are 64b) */                \
+       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 /* (check PMLEN=7 support) */    \
+)
+
+#define HWPROBE_EXT1_RVA23U64 (                                        \
+       RISCV_HWPROBE_EXT_ZICCIF                        |       \
+       RISCV_HWPROBE_EXT_ZICCRSE                       |       \
+       RISCV_HWPROBE_EXT_ZICCAMOA                      |       \
+       RISCV_HWPROBE_EXT_ZA64RS                                \
+)
+
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+       struct riscv_hwprobe pair;
+
+       if (!IS_ENABLED(CONFIG_64BIT))
+               return false;
+
+       /* Additional mandates for Zic64b and Supm */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return false;
+

arch/riscv/kernel/sys_hwprobe.c static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext) · line 293

Quoted 10 lines
arch/riscv/kernel/sys_hwprobe.c +10 -0
+       hwprobe_isa_ext0(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT0_RVA23U64) != HWPROBE_EXT0_RVA23U64)
+               return false;
+
+       hwprobe_isa_ext1(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT1_RVA23U64) != HWPROBE_EXT1_RVA23U64)
+               return false;
+
+       return true;
+}

For record purpose, I double checked the above list and function:
all 33 mandatory extensions required by RVA23U64 are checked in this patch, none missing.

BR,
Guodong

Quoted 29 lines
arch/riscv/kernel/sys_hwprobe.c +3 -0
+
 #if defined(CONFIG_RISCV_PROBE_UNALIGNED_ACCESS)
 static u64 hwprobe_misaligned(const struct cpumask *cpus)
 {
@@ -312,6 +382,8 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
         */
        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:
tools/testing/selftests/riscv/hwprobe/which-cpus.c +1 -2
index 587feb198c04..f8c797b1d0fd 100644
@@ -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

#26 lore raw
Quoted 90 lines · Guodong Xu

Hi, Drew

Quoted 66 lines · Andrew Jones

Provide a bit to conveniently determine when RVA23U64 is supported. While it's already possible to determine RVA23U64 support with five hwprobe calls and four prctl calls it would be error-prone to require anything (and we presume eventually almost everything) that needs to check for RVA23U64 support to all implement those calls and specific checks. And, while RVA23U64 is the IMA base with mandated extensions, most software will consider it a new base. For these reasons, add the RVA23U64 bit as a base behavior bit.

---
 Documentation/arch/riscv/hwprobe.rst          |  8 +++
 arch/riscv/include/uapi/asm/hwprobe.h         |  3 +-
 arch/riscv/kernel/sys_hwprobe.c               | 72 +++++++++++++++++++
 .../selftests/riscv/hwprobe/which-cpus.c      |  2 +-
 4 files changed, 83 insertions(+), 2 deletions(-)
Documentation/arch/riscv/hwprobe.rst +8 -0
index 97226b7c5936..6d915e7ba58a 100644
@@ -67,6 +67,14 @@ The following keys are defined:
       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 b1d80660 ("Updated to ratified state.")
+
+    The RVA23U64 base is based upon the IMA base and therefore IMA extension
+    keys (e.g. :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`:) may be used to probe
+    optional extensions.
+
 * :c:macro:`RISCV_HWPROBE_KEY_IMA_EXT_0`: A bitmask containing the extensions
   that are compatible with the :c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`:
   base system behavior.
arch/riscv/include/uapi/asm/hwprobe.h +2 -1
index fed9ea6fd2b5..72d2a4d0b733 100644
@@ -21,7 +21,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 (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_IMA         (1 << 0)
+#define                RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64    (1 << 1)
 #define RISCV_HWPROBE_KEY_IMA_EXT_0    4
 #define                RISCV_HWPROBE_IMA_FD            (1 << 0)
 #define                RISCV_HWPROBE_IMA_C             (1 << 1)
arch/riscv/kernel/sys_hwprobe.c +1 -0
index 31d222301bf0..4b9981b15ebe 100644
@@ -23,6 +23,7 @@
 #include <asm/vendor_extensions/thead_hwprobe.h>
 #include <vdso/vsyscall.h>
 
+extern bool riscv_have_user_pmlen_7;
 
 #define EXT_KEY(isa_arg, ext, pv, missing)                                     \
        do {                                                                            \
@@ -222,6 +223,75 @@ static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext)
        return (pair.value & ext);
 }

arch/riscv/kernel/sys_hwprobe.c static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext) · line 234

Quoted 10 lines
arch/riscv/kernel/sys_hwprobe.c +9 -0
 
+#define HWPROBE_EXT0_RVA23U64 (                                        \
+       /* IMA is always supported */                           \
+       RISCV_HWPROBE_IMA_FD                            |       \
+       RISCV_HWPROBE_IMA_C                             |       \
+       /* B is Zba, Zbb and Zbs */                             \
+       RISCV_HWPROBE_EXT_ZBA                           |       \
+       RISCV_HWPROBE_EXT_ZBB                           |       \
+       RISCV_HWPROBE_EXT_ZBS                           |       \
+       /* ZICSR is always supported */                         \

About Zicsr always?
It is not rigorous compared to the other extensions that are checked explicitly.

With the deprecated 'riscv,isa' DT string (ACPI doesn't do this), "i" implies zicsr (along with zicntr, zifencei, zihpm). But with 'riscv,isa-extensions', zicsr must be listed explicitly, it is not automatically derived from "i". (see cputfeature.c)

Quoted 6 lines

BTW, this also serves as an example where:
- RISCV_ISA_EXT_ZICSR exists, (your patch 10 checked it)
- but no corresponding hwprobe export RISCV_HWPROBE_EXT_ZICSR.

So, as I suggested, it's better we detect rva23u64 as a combination of RISCV_ISA_EXT_...; instead of using RISCV_HWPROBE_EXT_...

Indeed, zicsr makes a good case for that.

Quoted 56 lines
Quoted 56 lines
arch/riscv/kernel/sys_hwprobe.c +55 -0
+       RISCV_HWPROBE_EXT_ZICNTR                        |       \
+       RISCV_HWPROBE_EXT_ZIHPM                         |       \
+       /* ZICCIF is in EXT1 */                                 \
+       /* ZICCRSE is in EXT1 */                                \
+       /* ZICCAMOA is in EXT1 */                               \
+       RISCV_HWPROBE_EXT_ZICCLSM                       |       \
+       /* ZA64RS is in EXT1 */                                 \
+       RISCV_HWPROBE_EXT_ZIHINTPAUSE                   |       \
+       /* ZIC64B (check block sizes are 64b) */                \
+       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 /* (check PMLEN=7 support) */    \
+)
+
+#define HWPROBE_EXT1_RVA23U64 (                                        \
+       RISCV_HWPROBE_EXT_ZICCIF                        |       \
+       RISCV_HWPROBE_EXT_ZICCRSE                       |       \
+       RISCV_HWPROBE_EXT_ZICCAMOA                      |       \
+       RISCV_HWPROBE_EXT_ZA64RS                                \
+)
+
+static bool hwprobe_has_rva23u64(const struct cpumask *cpus)
+{
+       struct riscv_hwprobe pair;
+
+       if (!IS_ENABLED(CONFIG_64BIT))
+               return false;
+
+       /* Additional mandates for Zic64b and Supm */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return false;
+
+       hwprobe_isa_ext0(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT0_RVA23U64) != HWPROBE_EXT0_RVA23U64)
+               return false;
+
+       hwprobe_isa_ext1(&pair, cpus);
+       if ((pair.value & HWPROBE_EXT1_RVA23U64) != HWPROBE_EXT1_RVA23U64)
Quoted 8 lines

arch/riscv/kernel/sys_hwprobe.c static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext) · line 293

Quoted 4 lines
arch/riscv/kernel/sys_hwprobe.c +4 -0
+               return false;
+
+       return true;
+}

For record purpose, I double checked the above list and function:
all 33 mandatory extensions required by RVA23U64 are checked in this patch, none missing.

Thanks!
drew

#27 lore raw

RFC PATCH 9/11 riscv: selftests: hwprobe: Check rva23u64 consistency

In reply to Andrew Jones

When the rva23u64 base behavior is advertised ensure all its mandated extensions are also advertised. The prctl calls are necessary to ensure PMLEN=0 and PMLEN=7 are supported, as that's also mandated by the profiles spec for rva23u64.

---
 .../testing/selftests/riscv/hwprobe/hwprobe.c | 112 +++++++++++++++++-
 1 file changed, 111 insertions(+), 1 deletion(-)
tools/testing/selftests/riscv/hwprobe/hwprobe.c +111 -1
index 54c435af9923..780658867313 100644
@@ -1,7 +1,115 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <assert.h>
+#include <uapi/linux/prctl.h>
+#include <sys/auxv.h>
+#include <sys/prctl.h>
+
 #include "hwprobe.h"
 #include "kselftest.h"
 
+#define RVA23U64_HWCAP ( \
+	(1 << ('I' - 'A')) | \
+	(1 << ('M' - 'A')) | \
+	(1 << ('A' - 'A')) | \
+	(1 << ('F' - 'A')) | \
+	(1 << ('D' - 'A')) | \
+	(1 << ('C' - 'A')) | \
+	(1 << ('B' - 'A')) | \
+	(1 << ('V' - 'A')) \
+)
+
+#define RVA23U64_EXT0 ( \
+	RISCV_HWPROBE_IMA_FD | \
+	RISCV_HWPROBE_IMA_C | \
+	RISCV_HWPROBE_IMA_V | \
+	RISCV_HWPROBE_EXT_ZBA | \
+	RISCV_HWPROBE_EXT_ZBB | \
+	RISCV_HWPROBE_EXT_ZBS | \
+	RISCV_HWPROBE_EXT_ZICBOZ | \
+	RISCV_HWPROBE_EXT_ZKT | \
+	RISCV_HWPROBE_EXT_ZVBB | \
+	RISCV_HWPROBE_EXT_ZVKT | \
+	RISCV_HWPROBE_EXT_ZFHMIN | \
+	RISCV_HWPROBE_EXT_ZIHINTNTL | \
+	RISCV_HWPROBE_EXT_ZVFHMIN | \
+	RISCV_HWPROBE_EXT_ZFA | \
+	RISCV_HWPROBE_EXT_ZICNTR | \
+	RISCV_HWPROBE_EXT_ZICOND | \
+	RISCV_HWPROBE_EXT_ZIHINTPAUSE | \
+	RISCV_HWPROBE_EXT_ZIHPM | \
+	RISCV_HWPROBE_EXT_ZIMOP | \
+	RISCV_HWPROBE_EXT_ZCB | \
+	RISCV_HWPROBE_EXT_ZCMOP | \
+	RISCV_HWPROBE_EXT_ZAWRS | \
+	RISCV_HWPROBE_EXT_SUPM | \
+	RISCV_HWPROBE_EXT_ZICBOM | \
+	RISCV_HWPROBE_EXT_ZICBOP | \
+	RISCV_HWPROBE_EXT_ZICCLSM \
+)
+
+#define RVA23U64_EXT1 ( \
+	RISCV_HWPROBE_EXT_ZICCAMOA | \
+	RISCV_HWPROBE_EXT_ZICCIF | \
+	RISCV_HWPROBE_EXT_ZICCRSE | \
+	RISCV_HWPROBE_EXT_ZA64RS \
+)
+
+static void check_rva23u64(unsigned long *cpus, size_t cpusetsize)
+{
+	struct riscv_hwprobe pairs[] = {
+		{ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, },
+		{ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, },
+		{ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, },
+		{ .key = RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE, },
+		{ .key = RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE, },
+		{ .key = RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE, },
+	};
+	long ret, pmlen0, pmlen7;
+	unsigned long hwcap;
+
+	ret = riscv_hwprobe(pairs, ARRAY_SIZE(pairs), cpusetsize, cpus, 0);
+	assert(ret == 0);
+	assert(pairs[0].key == RISCV_HWPROBE_KEY_BASE_BEHAVIOR);
+	assert(pairs[1].key == RISCV_HWPROBE_KEY_IMA_EXT_0);
+	assert(pairs[3].key == RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE);
+	assert(pairs[4].key == RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE);
+	assert(pairs[5].key == RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE);
+
+	if (!(pairs[0].value & RISCV_HWPROBE_BASE_BEHAVIOR_RVA23U64)) {
+		ksft_test_result_skip("rva23u64 check, no RVA23U64 base behavior\n");
+		return;
+	}
+
+	assert(pairs[2].key == RISCV_HWPROBE_KEY_IMA_EXT_1);
+	assert(pairs[0].value & RISCV_HWPROBE_BASE_BEHAVIOR_IMA);
+
+	if (prctl(PR_SET_TAGGED_ADDR_CTRL, 0 << PR_PMLEN_SHIFT, 0, 0, 0)) {
+		ksft_test_result_skip("rva23u64 check, failed PR_SET_TAGGED_ADDR_CTRL\n");
+		return;
+	}
+	ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
+	if (ret < 0) {
+		ksft_test_result_skip("rva23u64 check, failed PR_GET_TAGGED_ADDR_CTRL\n");
+		return;
+	}
+	pmlen0 = (ret & PR_PMLEN_MASK) >> PR_PMLEN_SHIFT;
+
+	ret = prctl(PR_SET_TAGGED_ADDR_CTRL, 7 << PR_PMLEN_SHIFT, 0, 0, 0);
+	assert(ret == 0);
+	ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);
+	assert(ret >= 0);
+	pmlen7 = (ret & PR_PMLEN_MASK) >> PR_PMLEN_SHIFT;
+
+	hwcap = getauxval(AT_HWCAP);
+
+	ksft_test_result((pairs[1].value & RVA23U64_EXT0) == RVA23U64_EXT0 &&
+			 (pairs[2].value & RVA23U64_EXT1) == RVA23U64_EXT1 &&
+			 pairs[3].value == 64 && pairs[4].value == 64 && pairs[5].value == 64 &&
+			 pmlen0 == 0 && pmlen7 == 7 &&
+			 (hwcap & RVA23U64_HWCAP) == RVA23U64_HWCAP,
+			 "rva23u64 is consistent\n");
+}
+
 int main(int argc, char **argv)
 {
 	struct riscv_hwprobe pairs[8];
@@ -9,7 +117,7 @@ int main(int argc, char **argv)
 	long out;
 
 	ksft_print_header();
-	ksft_set_plan(5);
+	ksft_set_plan(6);
 
 	/* Fake the CPU_SET ops. */
 	cpus = -1;
@@ -62,5 +170,7 @@ int main(int argc, char **argv)
 			 pairs[1].key == 1 && pairs[1].value != 0xAAAA,
 			 "Unknown key overwritten with -1 and doesn't block other elements\n");
 
+	check_rva23u64(&cpus, 1);
+
 	ksft_finished();
 }
Signature · 1 line
2.43.0
#28 lore raw

RFC PATCH 10/11 riscv: /proc/cpuinfo: Add rva23 bases to output

In reply to Andrew Jones

Output the rva23(u|s)64 ISA bases that the ISA extensions provide on new 'isa bases' lines both for the LCD of all harts and per hart, as shown in the example output below when booting qemu with -cpu rva23s64,sv39=on,pmp=on:

processor : 0
hart : 4
isa bases : rv64ima rva23u64
isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt
mmu : sv39
mvendorid : 0x0
marchid : 0x0
mimpid : 0x0
hart isa bases : rv64ima rva23u64
hart isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt

---
 arch/riscv/include/asm/cpufeature.h | 10 ++++
 arch/riscv/kernel/cpu.c             | 34 ++++++++++++
 arch/riscv/kernel/cpufeature.c      | 83 +++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
arch/riscv/include/asm/cpufeature.h +10 -0
index 62837fa981e8..e750735c5686 100644
@@ -25,7 +25,15 @@ struct riscv_cpuinfo {
 	unsigned long mimpid;
 };
 
+enum {
+	RISCV_ISA_BASE_IMA,
+	RISCV_ISA_BASE_RVA23U64,
+	RISCV_ISA_BASE_RVA23S64,
+	RISCV_NR_ISA_BASES,
+};
+
 struct riscv_isainfo {
+	DECLARE_BITMAP(isa_bases, RISCV_NR_ISA_BASES);
 	DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
 };
 
@@ -152,4 +160,6 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi
 	return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
 }
 
+void riscv_set_isa_bases(unsigned long *isa_bases, const unsigned long *isa_bitmap);
+
 #endif
arch/riscv/kernel/cpu.c +34 -0
index 3dbc8cc557dd..228867d7dc00 100644
@@ -305,6 +305,34 @@ static void print_mmu(struct seq_file *f)
 	seq_printf(f, "mmu\t\t: %s\n", sv_type);
 }
 
+static DECLARE_BITMAP(riscv_isa_bases, RISCV_NR_ISA_BASES);
+
+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",
+	[RISCV_ISA_BASE_RVA23S64] = "rva23s64",
+};
+
+static void print_isa_bases(struct seq_file *m,
+			    const unsigned long *isa_bases,
+			    const unsigned long *isa)
+{
+	unsigned int i;
+
+	if (bitmap_empty(isa_bases, RISCV_NR_ISA_BASES))
+		riscv_set_isa_bases((unsigned long *)isa_bases, isa);
+
+	for (i = 0; i < RISCV_NR_ISA_BASES; i++) {
+		if (test_bit(i, isa_bases))
+			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 +364,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, riscv_isa_bases, 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 +391,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, hart_isa[cpu_id].isa);
+
 	/*
 	 * Print the ISA extensions specific to this hart, which may show
 	 * additional extensions not present across all harts.
arch/riscv/kernel/cpufeature.c +83 -0

86 lines not on this page · raw message

Signature · 1 line
2.43.0
#29 lore raw

Re: [RFC PATCH v1 10/11] riscv: /proc/cpuinfo: Add rva23 bases to output

kernel test robot noticed the following build errors:

Hi Andrew,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on shuah-kselftest/fixes]
[also build test ERROR on linus/master v6.19-rc8]
[cannot apply to shuah-kselftest/next next-20260205]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andrew-Jones/riscv-hwprobe-add-support-for-RISCV_HWPROBE_KEY_IMA_EXT_1/20260206-082824
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git fixes
patch link:    https://lore.kernel.org/r/20260206002349.96740-11-andrew.jones%40oss.qualcomm.com
patch subject: [RFC PATCH v1 10/11] riscv: /proc/cpuinfo: Add rva23 bases to output
config: riscv-allnoconfig (https://download.01.org/0day-ci/archive/20260207/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260207/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

riscv64-linux-ld: arch/riscv/kernel/cpufeature.o: in function `riscv_ext_vector_crypto_validate':

>> cpufeature.c:(.text+0x632): undefined reference to `riscv_have_user_pmlen_7'

riscv64-linux-ld: arch/riscv/kernel/sys_hwprobe.o: in function `hwprobe_isa_ext1':
sys_hwprobe.c:(.text+0xb1a): undefined reference to `riscv_have_user_pmlen_7'

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#30 lore raw

Re: [RFC PATCH v1 10/11] riscv: /proc/cpuinfo: Add rva23 bases to output

In reply to Andrew Jones
Quoted 115 lines · Andrew Jones

Output the rva23(u|s)64 ISA bases that the ISA extensions provide on new 'isa bases' lines both for the LCD of all harts and per hart, as shown in the example output below when booting qemu with -cpu rva23s64,sv39=on,pmp=on:

processor : 0
hart : 4
isa bases : rv64ima rva23u64
isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt
mmu : sv39
mvendorid : 0x0
marchid : 0x0
mimpid : 0x0
hart isa bases : rv64ima rva23u64
hart isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt

---
 arch/riscv/include/asm/cpufeature.h | 10 ++++
 arch/riscv/kernel/cpu.c             | 34 ++++++++++++
 arch/riscv/kernel/cpufeature.c      | 83 +++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
arch/riscv/include/asm/cpufeature.h +10 -0
index 62837fa981e8..e750735c5686 100644
@@ -25,7 +25,15 @@ struct riscv_cpuinfo {
        unsigned long mimpid;
 };
 
+enum {
+       RISCV_ISA_BASE_IMA,
+       RISCV_ISA_BASE_RVA23U64,
+       RISCV_ISA_BASE_RVA23S64,
+       RISCV_NR_ISA_BASES,
+};
+
 struct riscv_isainfo {
+       DECLARE_BITMAP(isa_bases, RISCV_NR_ISA_BASES);
        DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
 };
 
@@ -152,4 +160,6 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi
        return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
 }
 
+void riscv_set_isa_bases(unsigned long *isa_bases, const unsigned long *isa_bitmap);
+
 #endif
arch/riscv/kernel/cpu.c +34 -0
index 3dbc8cc557dd..228867d7dc00 100644
@@ -305,6 +305,34 @@ static void print_mmu(struct seq_file *f)
        seq_printf(f, "mmu\t\t: %s\n", sv_type);
 }
 
+static DECLARE_BITMAP(riscv_isa_bases, RISCV_NR_ISA_BASES);
+
+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",
+       [RISCV_ISA_BASE_RVA23S64] = "rva23s64",
+};
+
+static void print_isa_bases(struct seq_file *m,
+                           const unsigned long *isa_bases,
+                           const unsigned long *isa)
+{
+       unsigned int i;
+
+       if (bitmap_empty(isa_bases, RISCV_NR_ISA_BASES))
+               riscv_set_isa_bases((unsigned long *)isa_bases, isa);
+
+       for (i = 0; i < RISCV_NR_ISA_BASES; i++) {
+               if (test_bit(i, isa_bases))
+                       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 +364,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, riscv_isa_bases, 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 +391,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, hart_isa[cpu_id].isa);
+
        /*
         * Print the ISA extensions specific to this hart, which may show
         * additional extensions not present across all harts.
arch/riscv/kernel/cpufeature.c +0 -0
index b001e78eecf6..07a42545e9e0 100644

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1268

Quoted 7 lines
arch/riscv/kernel/cpufeature.c +4 -0
@@ -1262,3 +1262,86 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
        }
 }
 #endif
+
+extern bool riscv_have_user_pmlen_7;
+
+void riscv_set_isa_bases(unsigned long *bases, const unsigned long *isa_bitmap)

I have no objection to the implementation of this function. My concern is that, from looking at the patch, the only way to trigger it is by cat /proc/cpuinfo, i.e., from print_isa_bases().

Shouldn't this be computed during init (e.g., in riscv_fill_hwcap()) so the result is available to other consumers like hwprobe?

Quoted 56 lines
arch/riscv/kernel/cpufeature.c +56 -0
+{
+       const unsigned long *isa = isa_bitmap ? isa_bitmap : riscv_isa;
+       DECLARE_BITMAP(ext_mask, RISCV_ISA_EXT_MAX) = { 0 };
+       DECLARE_BITMAP(tmp, RISCV_ISA_EXT_MAX);
+
+       /* IMA */
+       set_bit(RISCV_ISA_EXT_I, ext_mask);
+       set_bit(RISCV_ISA_EXT_M, ext_mask);
+       set_bit(RISCV_ISA_EXT_A, ext_mask);
+
+       if (bitmap_andnot(tmp, ext_mask, isa, RISCV_ISA_EXT_MAX))
+               return;
+
+       set_bit(RISCV_ISA_BASE_IMA, bases);
+
+       /* RVA23U64 */
+
+       /* Zic64b and Supm with PMLEN=7 */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return;
+
+       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_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_andnot(tmp, ext_mask, isa, RISCV_ISA_EXT_MAX))

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1334

Quoted 10 lines
arch/riscv/kernel/cpufeature.c +10 -0
+               return;
+
+       set_bit(RISCV_ISA_BASE_RVA23U64, bases);
+
+       /* RVA23S64 */
+       set_bit(RISCV_ISA_EXT_ZIFENCEI, ext_mask);
+       /* TODO: Ss1p13 */
+       /* Svbare, Sv39 -- assumed */
+       set_bit(RISCV_ISA_EXT_SVADE, ext_mask);
+       /* TODO: Ssccptr, Sstvecd, Sstvala, Sscounterenw */

For this,

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1342

Quoted 8 lines
arch/riscv/kernel/cpufeature.c +8 -0
+       set_bit(RISCV_ISA_EXT_SVPBMT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVINVAL, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVNAPOT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSTC, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSCOFPMF, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSNPM, ext_mask);
+       /* TODO: Ssu64xl */
+       /* TODO: Sha = Ssstateen, Shcounterenw, Shvstvala, Shtvala, Shvstvecd, Shvsatpa, Shgatpa */

And this, these TODOs, I'd be happy if my patches 7 and 8 [1] can be useful here.

BR,
Guodong

Quoted 8 lines
arch/riscv/kernel/cpufeature.c +5 -1
+       set_bit(RISCV_ISA_EXT_H, ext_mask);
+
+       if (/*TODO*/ false && !bitmap_andnot(tmp, ext_mask, isa, RISCV_ISA_EXT_MAX))
+               set_bit(RISCV_ISA_BASE_RVA23S64, bases);
+}
--

2.43.0

#31 lore raw

Re: [RFC PATCH v1 10/11] riscv: /proc/cpuinfo: Add rva23 bases to output

Quoted 129 lines · Guodong Xu
Quoted 115 lines · Andrew Jones

Output the rva23(u|s)64 ISA bases that the ISA extensions provide on new 'isa bases' lines both for the LCD of all harts and per hart, as shown in the example output below when booting qemu with -cpu rva23s64,sv39=on,pmp=on:

processor : 0
hart : 4
isa bases : rv64ima rva23u64
isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt
mmu : sv39
mvendorid : 0x0
marchid : 0x0
mimpid : 0x0
hart isa bases : rv64ima rva23u64
hart isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt

---
 arch/riscv/include/asm/cpufeature.h | 10 ++++
 arch/riscv/kernel/cpu.c             | 34 ++++++++++++
 arch/riscv/kernel/cpufeature.c      | 83 +++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
arch/riscv/include/asm/cpufeature.h +10 -0
index 62837fa981e8..e750735c5686 100644
@@ -25,7 +25,15 @@ struct riscv_cpuinfo {
        unsigned long mimpid;
 };
 
+enum {
+       RISCV_ISA_BASE_IMA,
+       RISCV_ISA_BASE_RVA23U64,
+       RISCV_ISA_BASE_RVA23S64,
+       RISCV_NR_ISA_BASES,
+};
+
 struct riscv_isainfo {
+       DECLARE_BITMAP(isa_bases, RISCV_NR_ISA_BASES);
        DECLARE_BITMAP(isa, RISCV_ISA_EXT_MAX);
 };
 
@@ -152,4 +160,6 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi
        return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
 }
 
+void riscv_set_isa_bases(unsigned long *isa_bases, const unsigned long *isa_bitmap);
+
 #endif
arch/riscv/kernel/cpu.c +34 -0
index 3dbc8cc557dd..228867d7dc00 100644
@@ -305,6 +305,34 @@ static void print_mmu(struct seq_file *f)
        seq_printf(f, "mmu\t\t: %s\n", sv_type);
 }
 
+static DECLARE_BITMAP(riscv_isa_bases, RISCV_NR_ISA_BASES);
+
+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",
+       [RISCV_ISA_BASE_RVA23S64] = "rva23s64",
+};
+
+static void print_isa_bases(struct seq_file *m,
+                           const unsigned long *isa_bases,
+                           const unsigned long *isa)
+{
+       unsigned int i;
+
+       if (bitmap_empty(isa_bases, RISCV_NR_ISA_BASES))
+               riscv_set_isa_bases((unsigned long *)isa_bases, isa);
+
+       for (i = 0; i < RISCV_NR_ISA_BASES; i++) {
+               if (test_bit(i, isa_bases))
+                       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 +364,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, riscv_isa_bases, 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 +391,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, hart_isa[cpu_id].isa);
+
        /*
         * Print the ISA extensions specific to this hart, which may show
         * additional extensions not present across all harts.
arch/riscv/kernel/cpufeature.c +0 -0
index b001e78eecf6..07a42545e9e0 100644

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1268

Quoted 7 lines
arch/riscv/kernel/cpufeature.c +4 -0
@@ -1262,3 +1262,86 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
        }
 }
 #endif
+
+extern bool riscv_have_user_pmlen_7;
+
+void riscv_set_isa_bases(unsigned long *bases, const unsigned long *isa_bitmap)

I have no objection to the implementation of this function. My concern is that, from looking at the patch, the only way to trigger it is by cat /proc/cpuinfo, i.e., from print_isa_bases().

Quoted 3 lines

Shouldn't this be computed during init (e.g., in riscv_fill_hwcap()) so the result is available to other consumers like hwprobe?

Yes, particularly if we drop some stuff from hwprobe making it impossible to compute rva23 from hwprobe bits.

Quoted 79 lines
Quoted 57 lines
arch/riscv/kernel/cpufeature.c +56 -0
+{
+       const unsigned long *isa = isa_bitmap ? isa_bitmap : riscv_isa;
+       DECLARE_BITMAP(ext_mask, RISCV_ISA_EXT_MAX) = { 0 };
+       DECLARE_BITMAP(tmp, RISCV_ISA_EXT_MAX);
+
+       /* IMA */
+       set_bit(RISCV_ISA_EXT_I, ext_mask);
+       set_bit(RISCV_ISA_EXT_M, ext_mask);
+       set_bit(RISCV_ISA_EXT_A, ext_mask);
+
+       if (bitmap_andnot(tmp, ext_mask, isa, RISCV_ISA_EXT_MAX))
+               return;
+
+       set_bit(RISCV_ISA_BASE_IMA, bases);
+
+       /* RVA23U64 */
+
+       /* Zic64b and Supm with PMLEN=7 */
+       if (riscv_cbom_block_size != 64 ||
+           riscv_cbop_block_size != 64 ||
+           riscv_cboz_block_size != 64 ||
+           !riscv_have_user_pmlen_7)
+               return;
+
+       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_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_andnot(tmp, ext_mask, isa, RISCV_ISA_EXT_MAX))

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1334

Quoted 10 lines
arch/riscv/kernel/cpufeature.c +10 -0
+               return;
+
+       set_bit(RISCV_ISA_BASE_RVA23U64, bases);
+
+       /* RVA23S64 */
+       set_bit(RISCV_ISA_EXT_ZIFENCEI, ext_mask);
+       /* TODO: Ss1p13 */
+       /* Svbare, Sv39 -- assumed */
+       set_bit(RISCV_ISA_EXT_SVADE, ext_mask);
+       /* TODO: Ssccptr, Sstvecd, Sstvala, Sscounterenw */

For this,

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1342

Quoted 8 lines
arch/riscv/kernel/cpufeature.c +8 -0
+       set_bit(RISCV_ISA_EXT_SVPBMT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVINVAL, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVNAPOT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSTC, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSCOFPMF, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSNPM, ext_mask);
+       /* TODO: Ssu64xl */
+       /* TODO: Sha = Ssstateen, Shcounterenw, Shvstvala, Shtvala, Shvstvecd, Shvsatpa, Shgatpa */
Quoted 5 lines

And this, these TODOs, I'd be happy if my patches 7 and 8 [1] can be useful here.

Absolutely!

Thanks,
drew

#32 lore raw

Re: [RFC PATCH v1 10/11] riscv: /proc/cpuinfo: Add rva23 bases to output

Quoted 32 lines · Andrew Jones
Quoted 30 lines · Guodong Xu
Quoted 19 lines · Andrew Jones

Output the rva23(u|s)64 ISA bases that the ISA extensions provide on new 'isa bases' lines both for the LCD of all harts and per hart, as shown in the example output below when booting qemu with -cpu rva23s64,sv39=on,pmp=on:

processor : 0
hart : 4
isa bases : rv64ima rva23u64
isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt
mmu : sv39
mvendorid : 0x0
marchid : 0x0
mimpid : 0x0
hart isa bases : rv64ima rva23u64
hart isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt

---

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1334

Quoted 6 lines
arch/riscv/kernel/cpufeature.c +6 -0
+       /* RVA23S64 */
+       set_bit(RISCV_ISA_EXT_ZIFENCEI, ext_mask);
+       /* TODO: Ss1p13 */
+       /* Svbare, Sv39 -- assumed */
+       set_bit(RISCV_ISA_EXT_SVADE, ext_mask);
+       /* TODO: Ssccptr, Sstvecd, Sstvala, Sscounterenw */

For this,

Quoted 8 lines
Quoted 8 lines

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1342

Quoted 8 lines
arch/riscv/kernel/cpufeature.c +8 -0
+       set_bit(RISCV_ISA_EXT_SVPBMT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVINVAL, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVNAPOT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSTC, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSCOFPMF, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSNPM, ext_mask);
+       /* TODO: Ssu64xl */
+       /* TODO: Sha = Ssstateen, Shcounterenw, Shvstvala, Shtvala, Shvstvecd, Shvsatpa, Shgatpa */

Hi, drew

About 'Sha', your reading of the profile/spec, do you prefer to define Sha as a _BUNDLE or as a _SUPERSET() which has its own id?

I defined it as _SUPERSET() in my patch 8/8 [1], but with today's code review, I guess bundle is a better fit. What do you think?

BTW, Sha = H + 7 others. It includes H.

BR,
Guodong

Quoted 11 lines
Quoted 6 lines

And this, these TODOs, I'd be happy if my patches 7 and 8 [1] can be useful here.

Absolutely!

Thanks,
drew

#33 lore raw

Re: [RFC PATCH v1 10/11] riscv: /proc/cpuinfo: Add rva23 bases to output

Quoted 45 lines · Guodong Xu
Quoted 32 lines · Andrew Jones
Quoted 30 lines · Guodong Xu
Quoted 19 lines · Andrew Jones

Output the rva23(u|s)64 ISA bases that the ISA extensions provide on new 'isa bases' lines both for the LCD of all harts and per hart, as shown in the example output below when booting qemu with -cpu rva23s64,sv39=on,pmp=on:

processor : 0
hart : 4
isa bases : rv64ima rva23u64
isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt
mmu : sv39
mvendorid : 0x0
marchid : 0x0
mimpid : 0x0
hart isa bases : rv64ima rva23u64
hart isa : rv64imafdcbvh_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintntl_zihintpause_zihpm_zimop_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_smaia_smnpm_smstateen_ssaia_sscofpmf_ssnpm_sstc_svade_svinval_svnapot_svpbmt

---

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1334

Quoted 6 lines
arch/riscv/kernel/cpufeature.c +6 -0
+       /* RVA23S64 */
+       set_bit(RISCV_ISA_EXT_ZIFENCEI, ext_mask);
+       /* TODO: Ss1p13 */
+       /* Svbare, Sv39 -- assumed */
+       set_bit(RISCV_ISA_EXT_SVADE, ext_mask);
+       /* TODO: Ssccptr, Sstvecd, Sstvala, Sscounterenw */

For this,

Quoted 8 lines
Quoted 8 lines

arch/riscv/kernel/cpufeature.c void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, · line 1342

Quoted 8 lines
arch/riscv/kernel/cpufeature.c +8 -0
+       set_bit(RISCV_ISA_EXT_SVPBMT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVINVAL, ext_mask);
+       set_bit(RISCV_ISA_EXT_SVNAPOT, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSTC, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSCOFPMF, ext_mask);
+       set_bit(RISCV_ISA_EXT_SSNPM, ext_mask);
+       /* TODO: Ssu64xl */
+       /* TODO: Sha = Ssstateen, Shcounterenw, Shvstvala, Shtvala, Shvstvecd, Shvsatpa, Shgatpa */

Hi, drew

Quoted 7 lines

About 'Sha', your reading of the profile/spec, do you prefer to define Sha as a _BUNDLE or as a _SUPERSET() which has its own id?

I defined it as _SUPERSET() in my patch 8/8 [1], but with today's code review, I guess bundle is a better fit. What do you think?

BTW, Sha = H + 7 others. It includes H.

I agree a bundle is more suitable for Sha.

Thanks,
drew

#34 lore raw

RFC PATCH 11/11 riscv: /proc/cpuinfo: Also output rva20 and rva22 isa bases

In reply to Andrew Jones

Include rva(20|22)(u|s)64 isa bases in the output when they are detected.

---
 arch/riscv/include/asm/cpufeature.h |  4 ++
 arch/riscv/kernel/cpu.c             |  4 ++
 arch/riscv/kernel/cpufeature.c      | 65 +++++++++++++++++++++++------
 3 files changed, 61 insertions(+), 12 deletions(-)
arch/riscv/include/asm/cpufeature.h +4 -0
index e750735c5686..41431e89bb3b 100644
@@ -27,6 +27,10 @@ struct riscv_cpuinfo {
 
 enum {
 	RISCV_ISA_BASE_IMA,
+	RISCV_ISA_BASE_RVA20U64,
+	RISCV_ISA_BASE_RVA20S64,
+	RISCV_ISA_BASE_RVA22U64,
+	RISCV_ISA_BASE_RVA22S64,
 	RISCV_ISA_BASE_RVA23U64,
 	RISCV_ISA_BASE_RVA23S64,
 	RISCV_NR_ISA_BASES,
arch/riscv/kernel/cpu.c +4 -0
index 228867d7dc00..007958744ae5 100644
@@ -313,6 +313,10 @@ static const char * const riscv_isa_base_names[] = {
 #else
 	[RISCV_ISA_BASE_IMA] = "rv64ima",
 #endif
+	[RISCV_ISA_BASE_RVA20U64] = "rva20u64",
+	[RISCV_ISA_BASE_RVA20S64] = "rva20s64",
+	[RISCV_ISA_BASE_RVA22U64] = "rva22u64",
+	[RISCV_ISA_BASE_RVA22S64] = "rva22s64",
 	[RISCV_ISA_BASE_RVA23U64] = "rva23u64",
 	[RISCV_ISA_BASE_RVA23S64] = "rva23s64",
 };
arch/riscv/kernel/cpufeature.c +53 -12

86 lines not on this page · raw message

Signature · 1 line
2.43.0
#35 lore raw
In reply to Andrew Jones
Quoted 8 lines · Andrew Jones

Users need a way determine that their harts conform to rva23u64 that isn't error-prone. While patches 2 and 6 make it possible to determine, it requires a bunch of probes and checks themselves (see patch9 for the recipe). This RFC proposes adding an RVA23U64 hwprobe base behavior (patch8) allowing easy determination. It also proposes adding the bases to /proc/cpuinfo (patches 10 and 11) -- but those two patches are probably even more RFCy than the hwprobe proposal...

Quoted 7 lines

The first three patches have been posted previously by their respective authors and are currently under active review (except patch2 which appears to have gotten lost in the shuffle). I've collected these patches into the series since they're necessary for the base and because I wanted to repost patch2 and patch3 with some changes. patch4 and patch6 expose more extensions to userspace. patch9 adds a consistency test for the new hwprobe base behavior bit.

Great series! Thanks for pulling these all together, I like this direction. We had dropped patch2 because we were using it for some misaligned access optimizations but then realized that the extension wasn't useful for that so then the patches got lost.

In Linux 7.0, patch 1 got applied along with CFI using the first flags of the second key so there is some rebasing to do.

I think putting the compatibility info in /proc/cpuinfo is a good idea. There is always hesitance around /proc/cpuinfo because some ill-advised programs try to parse information from it, but it is nice to have an easy way for users to see the compatility and since you also added the hwprobe interface for it this seems reasonable.

- Charlie

Quoted 46 lines

Thanks,
drew

Andrew Jones (8):
riscv: Add B to hwcap
riscv: hwprobe.rst: Replace tabs with spaces
riscv: Add Ziccamoa, Ziccif, Ziccrse, and Za64rs to hwprobe
riscv: Export have_user_pmlen* booleans
riscv: hwprobe: Introduce rva23u64 base behavior
riscv: selftests: hwprobe: Check rva23u64 consistency
riscv: /proc/cpuinfo: Add rva23 bases to output
riscv: /proc/cpuinfo: Also output rva20 and rva22 isa bases

Charlie Jenkins (1):
riscv: Standardize extension capitilization

Jesse Taube (1):
RISC-V: Add Zicclsm to cpufeature and hwprobe

Paul Walmsley (1):
riscv: hwprobe: add support for RISCV_HWPROBE_KEY_IMA_EXT_1

 Documentation/arch/riscv/hwprobe.rst          |  42 ++-
 arch/riscv/include/asm/cpufeature.h           |  14 +
 arch/riscv/include/asm/hwcap.h                |  23 +-
 arch/riscv/include/asm/hwprobe.h              |   3 +-
 arch/riscv/include/asm/switch_to.h            |   4 +-
 arch/riscv/include/uapi/asm/hwcap.h           |   1 +
 arch/riscv/include/uapi/asm/hwprobe.h         |   9 +-
 arch/riscv/kernel/cpu.c                       |  38 +++
 arch/riscv/kernel/cpufeature.c                | 168 ++++++++++--
 arch/riscv/kernel/process.c                   |  12 +-
 arch/riscv/kernel/sys_hwprobe.c               | 249 +++++++++++++-----
 arch/riscv/kvm/main.c                         |   2 +-
 arch/riscv/kvm/vcpu_fp.c                      |  28 +-
 arch/riscv/kvm/vcpu_onereg.c                  |  22 +-
 arch/riscv/kvm/vcpu_vector.c                  |  14 +-
 .../testing/selftests/riscv/hwprobe/hwprobe.c | 112 +++++++-
 .../selftests/riscv/hwprobe/which-cpus.c      |  20 +-
 17 files changed, 610 insertions(+), 151 deletions(-)
Signature · 1 line
2.43.0