Skip to content

Commit ac295b6

Browse files
AndybnACTpalmer-dabbelt
authored andcommitted
riscv: vector: adjust minimum Vector requirement to ZVE32X
Make has_vector() to check for ZVE32X. Every in-kernel usage of V that requires a more complicate version of V must then call out explicitly. Also, change riscv_v_first_use_handler(), and boot code that calls riscv_v_setup_vsize() to accept ZVE32X. Most kernel/user interfaces requires minimum of ZVE32X. Thus, programs compiled and run with ZVE32X should be supported by the kernel on most aspects. This includes context-switch, signal, ptrace, prctl, and hwprobe. One exception is that ELF_HWCAP returns 'V' only if full V is supported on the platform. This means that the system without a full V must not rely on ELF_HWCAP to tell whether it is allowable to execute Vector without first invoking a prctl() check. Signed-off-by: Andy Chiu <[email protected]> Acked-by: Joel Granados <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent de8f828 commit ac295b6

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

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/kernel/cpufeature.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,14 @@ void __init riscv_fill_hwcap(void)
724724
elf_hwcap &= ~COMPAT_HWCAP_ISA_F;
725725
}
726726

727-
if (elf_hwcap & COMPAT_HWCAP_ISA_V) {
727+
if (__riscv_isa_extension_available(NULL, RISCV_ISA_EXT_ZVE32X)) {
728728
/*
729729
* This cannot fail when called on the boot hart
730730
*/
731731
riscv_v_setup_vsize();
732+
}
733+
734+
if (elf_hwcap & COMPAT_HWCAP_ISA_V) {
732735
/*
733736
* ISA string in device tree might have 'v' flag, but
734737
* CONFIG_RISCV_ISA_V is disabled in kernel.

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 5 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,6 +113,10 @@ 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()) {
117121
EXT_KEY(ZVE32X);
118122
EXT_KEY(ZVE32F);

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 */

arch/riscv/lib/uaccess.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
SYM_FUNC_START(__asm_copy_to_user)
1616
#ifdef CONFIG_RISCV_ISA_V
17-
ALTERNATIVE("j fallback_scalar_usercopy", "nop", 0, RISCV_ISA_EXT_v, CONFIG_RISCV_ISA_V)
17+
ALTERNATIVE("j fallback_scalar_usercopy", "nop", 0, RISCV_ISA_EXT_ZVE32X, CONFIG_RISCV_ISA_V)
1818
REG_L t0, riscv_v_usercopy_threshold
1919
bltu a2, t0, fallback_scalar_usercopy
2020
tail enter_vector_usercopy

0 commit comments

Comments
 (0)