Skip to content

Commit 6d8e604

Browse files
Merge patch series "Support Zve32[xf] and Zve64[xfd] Vector subextensions"
Andy Chiu <[email protected]> says: The series composes of two parts. The first part Specifically, patch 1 adds a comment at a callsite of riscv_setup_vsize to clarify how vlenb is observed by the system. Patch 2 fixes the issue by failing the boot process of a secondary core if vlenb mismatches. Here is the organization of the series: - Patch 1, 2 provide a fix for mismatching vlen problem [1]. The solution is to fail secondary cores if their vlenb is not the same as the boot core. - Patch 3 is a cleanup for introducing ZVE* Vector subextensions. It gives the obsolete ISA parser the ability to expand ISA extensions for sigle letter extensions. - Patch 4, 5, 6 introduce Zve32x, Zve32f, Zve64x, Zve64f, Zve64d for isa parsing and hwprobe, and document about it. - Patch 7 makes has_vector() check against ZVE32X instead of V, so most userspace Vector supports will be available for bare ZVE32X. - Patch 8 updates the prctl test so that it runs on ZVE32X. The series is tested on a QEMU and verified that booting, Vector programs context-switch, signal, ptrace, prctl interfaces works when we only report partial V from the ISA. * b4-shazam-lts: selftest: run vector prctl test for ZVE32X riscv: vector: adjust minimum Vector requirement to ZVE32X riscv: hwprobe: add zve Vector subextensions into hwprobe interface riscv: cpufeature: add zve32[xf] and zve64[xfd] isa detection dt-bindings: riscv: add Zve32[xf] Zve64[xfd] ISA extension description riscv: cpufeature: call match_isa_ext() for single-letter extensions riscv: vector: add a comment when calling riscv_setup_vsize() riscv: smp: fail booting up smp if inconsistent vlen is detected [Palmer: reorder the first two patches so I can merge the fix, and rebase this on v6.10-rc1 so it's a little easier to manage.] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents 1613e60 + edc96a2 commit 6d8e604

File tree

12 files changed

+151
-31
lines changed

12 files changed

+151
-31
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ The following keys are defined:
192192
supported as defined in the RISC-V ISA manual starting from commit
193193
d8ab5c78c207 ("Zihintpause is ratified").
194194

195+
* :c:macro:`RISCV_HWPROBE_EXT_ZVE32X`: The Vector sub-extension Zve32x is
196+
supported, as defined by version 1.0 of the RISC-V Vector extension manual.
197+
198+
* :c:macro:`RISCV_HWPROBE_EXT_ZVE32F`: The Vector sub-extension Zve32f is
199+
supported, as defined by version 1.0 of the RISC-V Vector extension manual.
200+
201+
* :c:macro:`RISCV_HWPROBE_EXT_ZVE64X`: The Vector sub-extension Zve64x is
202+
supported, as defined by version 1.0 of the RISC-V Vector extension manual.
203+
204+
* :c:macro:`RISCV_HWPROBE_EXT_ZVE64F`: The Vector sub-extension Zve64f is
205+
supported, as defined by version 1.0 of the RISC-V Vector extension manual.
206+
207+
* :c:macro:`RISCV_HWPROBE_EXT_ZVE64D`: The Vector sub-extension Zve64d is
208+
supported, as defined by version 1.0 of the RISC-V Vector extension manual.
209+
195210
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance
196211
information about the selected set of processors.
197212

Documentation/devicetree/bindings/riscv/extensions.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,36 @@ properties:
381381
instructions, as ratified in commit 56ed795 ("Update
382382
riscv-crypto-spec-vector.adoc") of riscv-crypto.
383383

384+
- const: zve32f
385+
description:
386+
The standard Zve32f extension for embedded processors, as ratified
387+
in commit 6f702a2 ("Vector extensions are now ratified") of
388+
riscv-v-spec.
389+
390+
- const: zve32x
391+
description:
392+
The standard Zve32x extension for embedded processors, as ratified
393+
in commit 6f702a2 ("Vector extensions are now ratified") of
394+
riscv-v-spec.
395+
396+
- const: zve64d
397+
description:
398+
The standard Zve64d extension for embedded processors, as ratified
399+
in commit 6f702a2 ("Vector extensions are now ratified") of
400+
riscv-v-spec.
401+
402+
- const: zve64f
403+
description:
404+
The standard Zve64f extension for embedded processors, as ratified
405+
in commit 6f702a2 ("Vector extensions are now ratified") of
406+
riscv-v-spec.
407+
408+
- const: zve64x
409+
description:
410+
The standard Zve64x extension for embedded processors, as ratified
411+
in commit 6f702a2 ("Vector extensions are now ratified") of
412+
riscv-v-spec.
413+
384414
- const: zvfh
385415
description:
386416
The standard Zvfh extension for vectored half-precision

arch/riscv/include/asm/hwcap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
#define RISCV_ISA_EXT_ZTSO 72
8282
#define RISCV_ISA_EXT_ZACAS 73
8383
#define RISCV_ISA_EXT_XANDESPMU 74
84+
#define RISCV_ISA_EXT_ZVE32X 75
85+
#define RISCV_ISA_EXT_ZVE32F 76
86+
#define RISCV_ISA_EXT_ZVE64X 77
87+
#define RISCV_ISA_EXT_ZVE64F 78
88+
#define RISCV_ISA_EXT_ZVE64D 79
8489

8590
#define RISCV_ISA_EXT_XLINUXENVCFG 127
8691

arch/riscv/include/asm/vector.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static inline u32 riscv_v_flags(void)
3737

3838
static __always_inline bool has_vector(void)
3939
{
40-
return riscv_has_extension_unlikely(RISCV_ISA_EXT_v);
40+
return riscv_has_extension_unlikely(RISCV_ISA_EXT_ZVE32X);
4141
}
4242

4343
static inline void __riscv_v_vstate_clean(struct pt_regs *regs)
@@ -91,7 +91,7 @@ static __always_inline void __vstate_csr_restore(struct __riscv_v_ext_state *src
9191
{
9292
asm volatile (
9393
".option push\n\t"
94-
".option arch, +v\n\t"
94+
".option arch, +zve32x\n\t"
9595
"vsetvl x0, %2, %1\n\t"
9696
".option pop\n\t"
9797
"csrw " __stringify(CSR_VSTART) ", %0\n\t"
@@ -109,7 +109,7 @@ static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to,
109109
__vstate_csr_save(save_to);
110110
asm volatile (
111111
".option push\n\t"
112-
".option arch, +v\n\t"
112+
".option arch, +zve32x\n\t"
113113
"vsetvli %0, x0, e8, m8, ta, ma\n\t"
114114
"vse8.v v0, (%1)\n\t"
115115
"add %1, %1, %0\n\t"
@@ -131,7 +131,7 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_
131131
riscv_v_enable();
132132
asm volatile (
133133
".option push\n\t"
134-
".option arch, +v\n\t"
134+
".option arch, +zve32x\n\t"
135135
"vsetvli %0, x0, e8, m8, ta, ma\n\t"
136136
"vle8.v v0, (%1)\n\t"
137137
"add %1, %1, %0\n\t"
@@ -153,7 +153,7 @@ static inline void __riscv_v_vstate_discard(void)
153153
riscv_v_enable();
154154
asm volatile (
155155
".option push\n\t"
156-
".option arch, +v\n\t"
156+
".option arch, +zve32x\n\t"
157157
"vsetvli %0, x0, e8, m8, ta, ma\n\t"
158158
"vmv.v.i v0, -1\n\t"
159159
"vmv.v.i v8, -1\n\t"

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ struct riscv_hwprobe {
6060
#define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34)
6161
#define RISCV_HWPROBE_EXT_ZICOND (1ULL << 35)
6262
#define RISCV_HWPROBE_EXT_ZIHINTPAUSE (1ULL << 36)
63+
#define RISCV_HWPROBE_EXT_ZVE32X (1ULL << 37)
64+
#define RISCV_HWPROBE_EXT_ZVE32F (1ULL << 38)
65+
#define RISCV_HWPROBE_EXT_ZVE64X (1ULL << 39)
66+
#define RISCV_HWPROBE_EXT_ZVE64F (1ULL << 40)
67+
#define RISCV_HWPROBE_EXT_ZVE64D (1ULL << 41)
6368
#define RISCV_HWPROBE_KEY_CPUPERF_0 5
6469
#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)
6570
#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)

arch/riscv/kernel/cpufeature.c

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,40 @@ static const unsigned int riscv_zvbb_exts[] = {
188188
RISCV_ISA_EXT_ZVKB
189189
};
190190

191+
#define RISCV_ISA_EXT_ZVE64F_IMPLY_LIST \
192+
RISCV_ISA_EXT_ZVE64X, \
193+
RISCV_ISA_EXT_ZVE32F, \
194+
RISCV_ISA_EXT_ZVE32X
195+
196+
#define RISCV_ISA_EXT_ZVE64D_IMPLY_LIST \
197+
RISCV_ISA_EXT_ZVE64F, \
198+
RISCV_ISA_EXT_ZVE64F_IMPLY_LIST
199+
200+
#define RISCV_ISA_EXT_V_IMPLY_LIST \
201+
RISCV_ISA_EXT_ZVE64D, \
202+
RISCV_ISA_EXT_ZVE64D_IMPLY_LIST
203+
204+
static const unsigned int riscv_zve32f_exts[] = {
205+
RISCV_ISA_EXT_ZVE32X
206+
};
207+
208+
static const unsigned int riscv_zve64f_exts[] = {
209+
RISCV_ISA_EXT_ZVE64F_IMPLY_LIST
210+
};
211+
212+
static const unsigned int riscv_zve64d_exts[] = {
213+
RISCV_ISA_EXT_ZVE64D_IMPLY_LIST
214+
};
215+
216+
static const unsigned int riscv_v_exts[] = {
217+
RISCV_ISA_EXT_V_IMPLY_LIST
218+
};
219+
220+
static const unsigned int riscv_zve64x_exts[] = {
221+
RISCV_ISA_EXT_ZVE32X,
222+
RISCV_ISA_EXT_ZVE64X
223+
};
224+
191225
/*
192226
* While the [ms]envcfg CSRs were not defined until version 1.12 of the RISC-V
193227
* privileged ISA, the existence of the CSRs is implied by any extension which
@@ -245,7 +279,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
245279
__RISCV_ISA_EXT_DATA(d, RISCV_ISA_EXT_d),
246280
__RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_q),
247281
__RISCV_ISA_EXT_DATA(c, RISCV_ISA_EXT_c),
248-
__RISCV_ISA_EXT_DATA(v, RISCV_ISA_EXT_v),
282+
__RISCV_ISA_EXT_SUPERSET(v, RISCV_ISA_EXT_v, riscv_v_exts),
249283
__RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_h),
250284
__RISCV_ISA_EXT_SUPERSET(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts),
251285
__RISCV_ISA_EXT_SUPERSET(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts),
@@ -280,6 +314,11 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
280314
__RISCV_ISA_EXT_DATA(ztso, RISCV_ISA_EXT_ZTSO),
281315
__RISCV_ISA_EXT_SUPERSET(zvbb, RISCV_ISA_EXT_ZVBB, riscv_zvbb_exts),
282316
__RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC),
317+
__RISCV_ISA_EXT_SUPERSET(zve32f, RISCV_ISA_EXT_ZVE32F, riscv_zve32f_exts),
318+
__RISCV_ISA_EXT_DATA(zve32x, RISCV_ISA_EXT_ZVE32X),
319+
__RISCV_ISA_EXT_SUPERSET(zve64d, RISCV_ISA_EXT_ZVE64D, riscv_zve64d_exts),
320+
__RISCV_ISA_EXT_SUPERSET(zve64f, RISCV_ISA_EXT_ZVE64F, riscv_zve64f_exts),
321+
__RISCV_ISA_EXT_SUPERSET(zve64x, RISCV_ISA_EXT_ZVE64X, riscv_zve64x_exts),
283322
__RISCV_ISA_EXT_DATA(zvfh, RISCV_ISA_EXT_ZVFH),
284323
__RISCV_ISA_EXT_DATA(zvfhmin, RISCV_ISA_EXT_ZVFHMIN),
285324
__RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB),
@@ -468,16 +507,15 @@ static void __init riscv_parse_isa_string(unsigned long *this_hwcap, struct risc
468507

469508
if (unlikely(ext_err))
470509
continue;
510+
511+
for (int i = 0; i < riscv_isa_ext_count; i++)
512+
match_isa_ext(&riscv_isa_ext[i], ext, ext_end, isainfo);
513+
471514
if (!ext_long) {
472515
int nr = tolower(*ext) - 'a';
473516

474-
if (riscv_isa_extension_check(nr)) {
517+
if (riscv_isa_extension_check(nr))
475518
*this_hwcap |= isa2hwcap[nr];
476-
set_bit(nr, isainfo->isa);
477-
}
478-
} else {
479-
for (int i = 0; i < riscv_isa_ext_count; i++)
480-
match_isa_ext(&riscv_isa_ext[i], ext, ext_end, isainfo);
481519
}
482520
}
483521
}
@@ -686,8 +724,14 @@ void __init riscv_fill_hwcap(void)
686724
elf_hwcap &= ~COMPAT_HWCAP_ISA_F;
687725
}
688726

689-
if (elf_hwcap & COMPAT_HWCAP_ISA_V) {
727+
if (__riscv_isa_extension_available(NULL, RISCV_ISA_EXT_ZVE32X)) {
728+
/*
729+
* This cannot fail when called on the boot hart
730+
*/
690731
riscv_v_setup_vsize();
732+
}
733+
734+
if (elf_hwcap & COMPAT_HWCAP_ISA_V) {
691735
/*
692736
* ISA string in device tree might have 'v' flag, but
693737
* CONFIG_RISCV_ISA_V is disabled in kernel.

arch/riscv/kernel/head.S

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,20 @@ secondary_start_sbi:
165165
#endif
166166
call .Lsetup_trap_vector
167167
scs_load_current
168-
tail smp_callin
168+
call smp_callin
169169
#endif /* CONFIG_SMP */
170170

171+
.align 2
172+
.Lsecondary_park:
173+
/*
174+
* Park this hart if we:
175+
* - have too many harts on CONFIG_RISCV_BOOT_SPINWAIT
176+
* - receive an early trap, before setup_trap_vector finished
177+
* - fail in smp_callin(), as a successful one wouldn't return
178+
*/
179+
wfi
180+
j .Lsecondary_park
181+
171182
.align 2
172183
.Lsetup_trap_vector:
173184
/* Set trap vector to exception handler */
@@ -181,12 +192,6 @@ secondary_start_sbi:
181192
csrw CSR_SCRATCH, zero
182193
ret
183194

184-
.align 2
185-
.Lsecondary_park:
186-
/* We lack SMP support or have too many harts, so park this hart */
187-
wfi
188-
j .Lsecondary_park
189-
190195
SYM_CODE_END(_start)
191196

192197
SYM_CODE_START(_start_kernel)

arch/riscv/kernel/smpboot.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ asmlinkage __visible void smp_callin(void)
214214
struct mm_struct *mm = &init_mm;
215215
unsigned int curr_cpuid = smp_processor_id();
216216

217+
if (has_vector()) {
218+
/*
219+
* Return as early as possible so the hart with a mismatching
220+
* vlen won't boot.
221+
*/
222+
if (riscv_v_setup_vsize())
223+
return;
224+
}
225+
217226
/* All kernel threads share the same mm context. */
218227
mmgrab(mm);
219228
current->active_mm = mm;
@@ -226,11 +235,6 @@ asmlinkage __visible void smp_callin(void)
226235
numa_add_cpu(curr_cpuid);
227236
set_cpu_online(curr_cpuid, true);
228237

229-
if (has_vector()) {
230-
if (riscv_v_setup_vsize())
231-
elf_hwcap &= ~COMPAT_HWCAP_ISA_V;
232-
}
233-
234238
riscv_user_isa_enable();
235239

236240
/*

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,
6969
if (riscv_isa_extension_available(NULL, c))
7070
pair->value |= RISCV_HWPROBE_IMA_C;
7171

72-
if (has_vector())
72+
if (has_vector() && riscv_isa_extension_available(NULL, v))
7373
pair->value |= RISCV_HWPROBE_IMA_V;
7474

7575
/*
@@ -113,7 +113,16 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,
113113
EXT_KEY(ZICOND);
114114
EXT_KEY(ZIHINTPAUSE);
115115

116+
/*
117+
* All the following extensions must depend on the kernel
118+
* support of V.
119+
*/
116120
if (has_vector()) {
121+
EXT_KEY(ZVE32X);
122+
EXT_KEY(ZVE32F);
123+
EXT_KEY(ZVE64X);
124+
EXT_KEY(ZVE64F);
125+
EXT_KEY(ZVE64D);
117126
EXT_KEY(ZVBB);
118127
EXT_KEY(ZVBC);
119128
EXT_KEY(ZVKB);

arch/riscv/kernel/vector.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ bool riscv_v_first_use_handler(struct pt_regs *regs)
173173
u32 __user *epc = (u32 __user *)regs->epc;
174174
u32 insn = (u32)regs->badaddr;
175175

176+
if (!has_vector())
177+
return false;
178+
176179
/* Do not handle if V is not supported, or disabled */
177-
if (!(ELF_HWCAP & COMPAT_HWCAP_ISA_V))
180+
if (!riscv_v_vstate_ctrl_user_allowed())
178181
return false;
179182

180183
/* If V has been enabled then it is not the first-use trap */

0 commit comments

Comments
 (0)