Support Zve32[xf] and Zve64[xfd] Vector subextensions
Subsystems (4)
v5 cover Support Zve32[xf] and Zve64[xfd] Vector subextensions
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.
Note that the signal test was performed after applying the commit c27fa53b858b ("riscv: Fix vector state restore in rt_sigreturn()")
This patch should be able to apply on risc-v for-next branch on top of the commit 0a16a1728790 ("riscv: select ARCH_HAS_FAST_MULTIPLIER")
[1]: https://lore.kernel.org/all/20240228-vicinity-cornstalk-4b8eb5fe5730@spud/T/#u
Changes in v5:
- Rebase on top of for-next
- Update comments (1, 7)
- Reorder the documentation patch to the front of patches that it
documents about. (5->4)
- Include ZVE64D to the list, which single letter V implies (6)
- Remove ZVE32F_IMPLY_LIST (5)
- Change the semantic of has_vector() thus rewrite patch 7
- Remove the patch that fixes integer promotion as it is merged else
place (8)
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Add a patch to trigger prctl test on ZVE32X (9)
- Add a patch to fix integer promotion bug in hwprobe (8)
- Fix a build fail on !CONFIG_RISCV_ISA_V (7)
- Add more comment in the assembly code change (2)
- Link to v3: https://lore.kernel.org/r/[email protected]
Changelog v3:
- Include correct maintainers and mailing list into CC.
- Cleanup isa string parser code (3)
- Adjust extensions order and name (4, 5)
- Refine commit message (6)
Changelog v2:
- Update comments and commit messages (1, 2, 7)
- Refine isa_exts[] lists for zve extensions (4)
- Add a patch for dt-binding (5)
- Make ZVE* extensions depend on has_vector(ZVE32X) (6, 7)
---
---
Andy Chiu (8):
riscv: vector: add a comment when calling riscv_setup_vsize()
riscv: smp: fail booting up smp if inconsistent vlen is detected
riscv: cpufeature: call match_isa_ext() for single-letter extensions
dt-bindings: riscv: add Zve32[xf] Zve64[xfd] ISA extension description
riscv: cpufeature: add zve32[xf] and zve64[xfd] isa detection
riscv: hwprobe: add zve Vector subextensions into hwprobe interface
riscv: vector: adjust minimum Vector requirement to ZVE32X
selftest: run vector prctl test for ZVE32X
Documentation/arch/riscv/hwprobe.rst | 15 ++++++ .../devicetree/bindings/riscv/extensions.yaml | 30 +++++++++++ arch/riscv/include/asm/hwcap.h | 5 ++ arch/riscv/include/asm/vector.h | 10 ++-- arch/riscv/include/uapi/asm/hwprobe.h | 5 ++ arch/riscv/kernel/cpufeature.c | 60 +++++++++++++++++++--- arch/riscv/kernel/head.S | 19 ++++--- arch/riscv/kernel/smpboot.c | 14 +++-- arch/riscv/kernel/sys_hwprobe.c | 11 +++- arch/riscv/kernel/vector.c | 5 +- arch/riscv/lib/uaccess.S | 2 +- .../testing/selftests/riscv/vector/vstate_prctl.c | 6 +-- 12 files changed, 151 insertions(+), 31 deletions(-)
---
base-commit: 0a16a172879012c42f55ae8c2883e17c1e4e388f
change-id: 20240318-zve-detection-50106d2da527
Best regards,
Signature · 1 line
Andy Chiu <[email protected]>
PATCH v5 1/8 riscv: vector: add a comment when calling riscv_setup_vsize()
The function would fail when it detects the calling hart's vlen doesn't match the first one's. The boot hart is the first hart calling this function during riscv_fill_hwcap, so it is impossible to fail here. Add a comment about this behavior.
---
Changelog v2, v5:
- update the comment (Conor)
--- arch/riscv/kernel/cpufeature.c | 3 +++ 1 file changed, 3 insertions(+)
arch/riscv/kernel/cpufeature.c +3 -0
@@ -683,6 +683,9 @@ void __init riscv_fill_hwcap(void) }if (elf_hwcap &COMPAT_HWCAP_ISA_V ) { +/* +* This cannot fail when called on the boot hart +*/ riscv_v_setup_vsize ();/* * ISA string in device tree might have 'v' flag, but
Signature · 1 line
2.44.0.rc2
PATCH v5 2/8 riscv: smp: fail booting up smp if inconsistent vlen is detected
In reply to Andy ChiuCurrently we only support Vector for SMP platforms, that is, all SMP cores have the same vlenb. If we happen to detect a mismatching vlen, it is better to just fail bootting it up to prevent further race/scheduling issues.
Also, move .Lsecondary_park forward and chage tail smp_callin into a regular call in the early assembly. So a core would be parked right after a return from smp_callin. Note that a successful smp_callin does not return.
---
Changelog v4:
- update comment also in the assembly code (Yunhui)
Changelog v2:
- update commit message to explain asm code change (Conor)
--- arch/riscv/kernel/head.S | 19 ++++++++++++------- arch/riscv/kernel/smpboot.c | 14 +++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-)
arch/riscv/kernel/head.S +12 -7
@@ -165,9 +165,20 @@ secondary_start_sbi: #endif call .Lsetup_trap_vector scs_load_current - tail smp_callin + call smp_callin #endif /* CONFIG_SMP */ +.align 2 +.Lsecondary_park: + /* + * Park this hart if we: + * - have too many harts on CONFIG_RISCV_BOOT_SPINWAIT + * - receive an early trap, before setup_trap_vector finished + * - fail in smp_callin(), as a successful one wouldn't return + */ + wfi + j .Lsecondary_park + .align 2 .Lsetup_trap_vector: /* Set trap vector to exception handler */
@@ -181,12 +192,6 @@ secondary_start_sbi: csrw CSR_SCRATCH, zero ret -.align 2 -.Lsecondary_park: - /* We lack SMP support or have too many harts, so park this hart */ - wfi - j .Lsecondary_park - SYM_CODE_END(_start) SYM_CODE_START(_start_kernel)
arch/riscv/kernel/smpboot.c +9 -5
@@ -214,6 +214,15 @@ asmlinkage __visible void smp_callin(void)struct mm_struct *mm = &init_mm;unsigned int curr_cpuid =smp_processor_id (); +if (has_vector ()) { +/* +* Return as early as possible so the hart with a mismatching +* vlen won't boot. +*/ +if (riscv_v_setup_vsize ()) +return ; + } +/* All kernel threads share the same mm context. */ mmgrab (mm); current->active_mm = mm;
@@ -226,11 +235,6 @@ asmlinkage __visible void smp_callin(void)numa_add_cpu (curr_cpuid);set_cpu_online (curr_cpuid,1 ); -if (has_vector ()) { -if (riscv_v_setup_vsize ()) - elf_hwcap &= ~COMPAT_HWCAP_ISA_V ; - } -riscv_user_isa_enable ();/*
Signature · 1 line
2.44.0.rc2
PATCH v5 3/8 riscv: cpufeature: call match_isa_ext() for single-letter extensions
In reply to Andy ChiuSingle-letter extensions may also imply multiple subextensions. For example, Vector extension implies zve64d, and zve64d implies zve64f.
Extension parsing for "riscv,isa-extensions" has the ability to resolve the dependency by calling match_isa_ext(). This patch makes deprecated parser call the same function for single letter extensions.
---
Changelog v3:
- Remove set_bit for single-letter extensions as they are all checked in match_isa_ext. (Clément)
--- arch/riscv/kernel/cpufeature.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
arch/riscv/kernel/cpufeature.c +5 -6
@@ -468,16 +468,15 @@ static void __init riscv_parse_isa_string(unsigned long *this_hwcap, struct riscif (unlikely (ext_err))continue ; + +for (int i =0 ; i < riscv_isa_ext_count; i++) +match_isa_ext (&riscv_isa_ext[i], ext, ext_end, isainfo); +if (!ext_long) {int nr =tolower (*ext) -'a' ; -if (riscv_isa_extension_check (nr)) { +if (riscv_isa_extension_check (nr)) *this_hwcap |= isa2hwcap[nr]; -set_bit (nr, isainfo->isa); - } - }else { -for (int i =0 ; i < riscv_isa_ext_count; i++) -match_isa_ext (&riscv_isa_ext[i], ext, ext_end, isainfo); } } }
Signature · 1 line
2.44.0.rc2
PATCH v5 4/8 dt-bindings: riscv: add Zve32[xf] Zve64[xfd] ISA extension description
In reply to Andy ChiuAdd description for Zve32x Zve32f Zve64x Zve64f Zve64d ISA extensions.
---
Changelog v5:
- Reorder this patch prior than the first patch that uses them. (Conor)
Changelog v3:
- Correct extension names and their order (Stefan)
Changelog v2:
- new patch since v2
--- .../devicetree/bindings/riscv/extensions.yaml | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+)
Documentation/devicetree/bindings/riscv/extensions.yaml +30 -0
@@ -381,6 +381,36 @@ properties: instructions, as ratified in commit 56ed795 ("Update riscv-crypto-spec-vector.adoc") of riscv-crypto. + - const: zve32f + description: + The standard Zve32f extension for embedded processors, as ratified + in commit 6f702a2 ("Vector extensions are now ratified") of + riscv-v-spec. + + - const: zve32x + description: + The standard Zve32x extension for embedded processors, as ratified + in commit 6f702a2 ("Vector extensions are now ratified") of + riscv-v-spec. + + - const: zve64d + description: + The standard Zve64d extension for embedded processors, as ratified + in commit 6f702a2 ("Vector extensions are now ratified") of + riscv-v-spec. + + - const: zve64f + description: + The standard Zve64f extension for embedded processors, as ratified + in commit 6f702a2 ("Vector extensions are now ratified") of + riscv-v-spec. + + - const: zve64x + description: + The standard Zve64x extension for embedded processors, as ratified + in commit 6f702a2 ("Vector extensions are now ratified") of + riscv-v-spec. + - const: zvfh description: The standard Zvfh extension for vectored half-precision
Signature · 1 line
2.44.0.rc2
PATCH v5 5/8 riscv: cpufeature: add zve32[xf] and zve64[xfd] isa detection
In reply to Andy ChiuMultiple Vector subextensions are added. Also, the patch takes care of the dependencies of Vector subextensions by macro expansions. So, if some "embedded" platform only reports "zve64f" on the ISA string, the parser is able to expand it to zve32x zve32f zve64x and zve64f.
---
Changelog v5:
- Remove ZVE32F_IMPLY_LIST as ZVE32F only implies ZVE32X (Conor)
- Add a list for V as it the imply list for ZVE64D does not include ZVE64D.
Changelog v3:
- renumber RISCV_ISA_EXT_ZVE* to rebase on top of 6.9
- alphabetically sort added extensions (Clément)
Changelog v2:
- remove the extension itself from its isa_exts[] list (Clément)
- use riscv_zve64d_exts for v's extension list (Samuel)
--- arch/riscv/include/asm/hwcap.h | 5 +++++ arch/riscv/kernel/cpufeature.c | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-)
arch/riscv/include/asm/hwcap.h +5 -0
@@ -81,6 +81,11 @@#define RISCV_ISA_EXT_ZTSO 72#define RISCV_ISA_EXT_ZACAS 73#define RISCV_ISA_EXT_XANDESPMU 74 +#define RISCV_ISA_EXT_ZVE32X 75 +#define RISCV_ISA_EXT_ZVE32F 76 +#define RISCV_ISA_EXT_ZVE64X 77 +#define RISCV_ISA_EXT_ZVE64F 78 +#define RISCV_ISA_EXT_ZVE64D 79#define RISCV_ISA_EXT_XLINUXENVCFG 127
arch/riscv/kernel/cpufeature.c +40 -1
59 lines not on this page · raw message
Signature · 1 line
2.44.0.rc2
PATCH v5 6/8 riscv: hwprobe: add zve Vector subextensions into hwprobe interface
In reply to Andy ChiuThe following Vector subextensions for "embedded" platforms are added into RISCV_HWPROBE_KEY_IMA_EXT_0:
- ZVE32X
- ZVE32F
- ZVE64X
- ZVE64F
- ZVE64D
Extensions ending with an X indicates that the platform doesn't have a vector FPU.
Extensions ending with F/D mean that whether single (F) or double (D) precision vector operation is supported.
The number 32 or 64 follows from ZVE tells the maximum element length.
---
Changelog v5:
- Rebase thus add ZVE32X after RISCV_HWPROBE_EXT_ZICOND.
Changelog v2:
- zve* extensions in hwprobe depends on whether kernel supports v, so include them after has_vector(). Fix a typo. (Clément)
--- Documentation/arch/riscv/hwprobe.rst | 15 +++++++++++++++ arch/riscv/include/uapi/asm/hwprobe.h | 5 +++++ arch/riscv/kernel/sys_hwprobe.c | 5 +++++ 3 files changed, 25 insertions(+)
Documentation/arch/riscv/hwprobe.rst +15 -0
@@ -192,6 +192,21 @@ The following keys are defined: supported as defined in the RISC-V ISA manual starting from commit d8ab5c78c207 ("Zihintpause is ratified"). + * :c:macro:`RISCV_HWPROBE_EXT_ZVE32X`: The Vector sub-extension Zve32x is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE32F`: The Vector sub-extension Zve32f is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE64X`: The Vector sub-extension Zve64x is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE64F`: The Vector sub-extension Zve64f is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE64D`: The Vector sub-extension Zve64d is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance information about the selected set of processors.
arch/riscv/include/uapi/asm/hwprobe.h +5 -0
@@ -60,6 +60,11 @@ struct riscv_hwprobe {#define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34)#define RISCV_HWPROBE_EXT_ZICOND (1ULL << 35)#define RISCV_HWPROBE_EXT_ZIHINTPAUSE (1ULL << 36) +#define RISCV_HWPROBE_EXT_ZVE32X (1ULL << 37) +#define RISCV_HWPROBE_EXT_ZVE32F (1ULL << 38) +#define RISCV_HWPROBE_EXT_ZVE64X (1ULL << 39) +#define RISCV_HWPROBE_EXT_ZVE64F (1ULL << 40) +#define RISCV_HWPROBE_EXT_ZVE64D (1ULL << 41)#define RISCV_HWPROBE_KEY_CPUPERF_0 5#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)
arch/riscv/kernel/sys_hwprobe.c +5 -0
@@ -114,6 +114,11 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,EXT_KEY (ZIHINTPAUSE );if (has_vector ()) { +EXT_KEY (ZVE32X ); +EXT_KEY (ZVE32F ); +EXT_KEY (ZVE64X ); +EXT_KEY (ZVE64F ); +EXT_KEY (ZVE64D );EXT_KEY (ZVBB );EXT_KEY (ZVBC );EXT_KEY (ZVKB );
Signature · 1 line
2.44.0.rc2
Palmer Dabbelt
maintainerRe: [PATCH v5 6/8] riscv: hwprobe: add zve Vector subextensions into hwprobe interface
Quoted 76 lines · On Thu, 09 May 2024 09:26:56 PDT (-0700), [email protected] wrote:
The following Vector subextensions for "embedded" platforms are added into
RISCV_HWPROBE_KEY_IMA_EXT_0:
- ZVE32X
- ZVE32F
- ZVE64X
- ZVE64F
- ZVE64DExtensions ending with an X indicates that the platform doesn't have a vector FPU.
Extensions ending with F/D mean that whether single (F) or double (D) precision vector operation is supported.
The number 32 or 64 follows from ZVE tells the maximum element length.Signed-off-by Andy Chiu <[email protected]>Reviewed-by Clément Léger <[email protected]>---
Changelog v5:
- Rebase thus add ZVE32X afterRISCV_HWPROBE_EXT_ZICOND.
Changelog v2:
- zve* extensions in hwprobe depends on whether kernel supports v, so include them afterhas_vector(). Fix a typo. (Clément)--- Documentation/arch/riscv/hwprobe.rst | 15 +++++++++++++++ arch/riscv/include/uapi/asm/hwprobe.h | 5 +++++ arch/riscv/kernel/sys_hwprobe.c | 5 +++++ 3 files changed, 25 insertions(+)Documentation/arch/riscv/hwprobe.rst +15
-0@@ -192,6 +192,21 @@ The following keys are defined: supported as defined in the RISC-V ISA manual starting from commit d8ab5c78c207 ("Zihintpause is ratified"). + * :c:macro:`RISCV_HWPROBE_EXT_ZVE32X`: The Vector sub-extension Zve32x is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE32F`: The Vector sub-extension Zve32f is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE64X`: The Vector sub-extension Zve64x is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE64F`: The Vector sub-extension Zve64f is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + + * :c:macro:`RISCV_HWPROBE_EXT_ZVE64D`: The Vector sub-extension Zve64d is + supported, as defined by version 1.0 of the RISC-V Vector extension manual. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance information about the selected set of processors.arch/riscv/include/uapi/asm/hwprobe.h +5
-0@@ -60,6 +60,11 @@ struct riscv_hwprobe {#define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34)#define RISCV_HWPROBE_EXT_ZICOND (1ULL << 35)#define RISCV_HWPROBE_EXT_ZIHINTPAUSE (1ULL << 36) +#define RISCV_HWPROBE_EXT_ZVE32X (1ULL << 37) +#define RISCV_HWPROBE_EXT_ZVE32F (1ULL << 38) +#define RISCV_HWPROBE_EXT_ZVE64X (1ULL << 39) +#define RISCV_HWPROBE_EXT_ZVE64F (1ULL << 40) +#define RISCV_HWPROBE_EXT_ZVE64D (1ULL << 41)#define RISCV_HWPROBE_KEY_CPUPERF_0 5#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)arch/riscv/kernel/sys_hwprobe.c +0
-0@@ -114,6 +114,11 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,EXT_KEY (ZIHINTPAUSE );
arch/riscv/kernel/sys_hwprobe.c static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, · line 124
Quoted 10 lines
arch/riscv/kernel/sys_hwprobe.c +5
-0if (has_vector ()) { +EXT_KEY (ZVE32X ); +EXT_KEY (ZVE32F ); +EXT_KEY (ZVE64X ); +EXT_KEY (ZVE64F ); +EXT_KEY (ZVE64D );EXT_KEY (ZVBB );EXT_KEY (ZVBC );EXT_KEY (ZVKB );
Conor left a comment over here <https://lore.kernel.org/all/[email protected]/>. I think the best bet is to just merge this v5 on for-next now, though -- there's a bunch of patch sets touching ISA string parsing and IIUC that sub-extension parsing stuff is a pre-existing issue, and Clement's patch set still has some outstanding feedback to address.
So I think if we just go with this we're not regressing anything, we just have a bit more to clean up. Maybe it's a little uglier now that userspace can see the sub-extensions, but I'd bet wacky ISA strings will be able to confuse us for a while.
I staged this so I can throw it at the tester, LMK if anyone has issues otherwise it'll show up on for-next.
Re: [PATCH v5 6/8] riscv: hwprobe: add zve Vector subextensions into hwprobe interface
Quoted 8 lines · Palmer Dabbelt
Quoted 7 lines · On Thu, 09 May 2024 09:26:56 PDT (-0700), [email protected] wrote:
arch/riscv/kernel/sys_hwprobe.c +0
-0@@ -114,6 +114,11 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,EXT_KEY (ZIHINTPAUSE );
Quoted 11 lines
arch/riscv/kernel/sys_hwprobe.c static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, · line 124
Quoted 9 lines
arch/riscv/kernel/sys_hwprobe.c +5
-0if (has_vector ()) { +EXT_KEY (ZVE32X ); +EXT_KEY (ZVE32F ); +EXT_KEY (ZVE64X ); +EXT_KEY (ZVE64F ); +EXT_KEY (ZVE64D );EXT_KEY (ZVBB );EXT_KEY (ZVBC );EXT_KEY (ZVKB );Conor left a comment over here <https://lore.kernel.org/all/[email protected]/>.
This link is to the patch you're replying to, not anything from me. I commented on a bunch of stuff in v4, but not this patch - generally I ignore hwprobe to be honest...
Quoted 9 lines
I think the best bet is to just merge this v5 on for-next now, though -- there's a bunch of patch sets touching ISA string parsing and IIUC that sub-extension parsing stuff is a pre-existing issue, and Clement's patch set still has some outstanding feedback to address.
So I think if we just go with this we're not regressing anything, we just have a bit more to clean up. Maybe it's a little uglier now that userspace can see the sub-extensions, but I'd bet wacky ISA strings will be able to confuse us for a while.
I wanna do some cleanup stuff w/ Clements series applied, if that's what you were talking about, but I don't see much point starting that until the cpufeature stuff has calmed down - Charlie's and Clement's series really need to be in for-next for it to be worth doing.
Quoted 2 lines
I staged this so I can throw it at the tester, LMK if anyone has issues otherwise it'll show up on for-next.
PATCH v5 7/8 riscv: vector: adjust minimum Vector requirement to ZVE32X
In reply to Andy ChiuMake 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.
---
Changelog v5:
- Remove the paramerter from has_vector()'s prototype. Instead, make it check for ZVE32X only. Everything else should make additional alternative checks. (Conor)
Changelog v4:
- check static_assert for !CONFIG_RISCV_ISA_V case in has_vector.
Changelog v2:
- update the comment in hwprobe.
--- arch/riscv/include/asm/vector.h | 10 +++++----- arch/riscv/kernel/cpufeature.c | 5 ++++- arch/riscv/kernel/sys_hwprobe.c | 6 +++++- arch/riscv/kernel/vector.c | 5 ++++- arch/riscv/lib/uaccess.S | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-)
arch/riscv/include/asm/vector.h +5 -5
@@ -37,7 +37,7 @@ static inline u32 riscv_v_flags(void) static __always_inline bool has_vector(void) { -return riscv_has_extension_unlikely (RISCV_ISA_EXT_v); +return riscv_has_extension_unlikely (RISCV_ISA_EXT_ZVE32X ); }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 { asmvolatile (".option push\n\t" -".option arch, +v\n\t" +".option arch, +zve32x\n\t" "vsetvl x0, %2, %1\n\t" ".option pop\n\t" "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,__vstate_csr_save (save_to); asmvolatile (".option push\n\t" -".option arch, +v\n\t" +".option arch, +zve32x\n\t" "vsetvli %0, x0, e8, m8, ta, ma\n\t" "vse8.v v0, (%1)\n\t" "add %1, %1, %0\n\t"
@@ -131,7 +131,7 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_riscv_v_enable (); asmvolatile (".option push\n\t" -".option arch, +v\n\t" +".option arch, +zve32x\n\t" "vsetvli %0, x0, e8, m8, ta, ma\n\t" "vle8.v v0, (%1)\n\t" "add %1, %1, %0\n\t"
@@ -153,7 +153,7 @@ static inline void __riscv_v_vstate_discard(void)riscv_v_enable (); asmvolatile (".option push\n\t" -".option arch, +v\n\t" +".option arch, +zve32x\n\t" "vsetvli %0, x0, e8, m8, ta, ma\n\t" "vmv.v.i v0, -1\n\t" "vmv.v.i v8, -1\n\t"
arch/riscv/kernel/cpufeature.c +4 -1
@@ -720,11 +720,14 @@ void __init riscv_fill_hwcap(void) elf_hwcap &= ~COMPAT_HWCAP_ISA_F ; } -if (elf_hwcap &COMPAT_HWCAP_ISA_V ) { +if (__riscv_isa_extension_available (NULL ,RISCV_ISA_EXT_ZVE32X )) {/* * This cannot fail when called on the boot hart */ riscv_v_setup_vsize (); + } + +if (elf_hwcap &COMPAT_HWCAP_ISA_V ) {/* * ISA string in device tree might have 'v' flag, but * CONFIG_RISCV_ISA_V is disabled in kernel.
arch/riscv/kernel/sys_hwprobe.c +5 -1
@@ -69,7 +69,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,if (riscv_isa_extension_available (NULL , c)) pair->value |=RISCV_HWPROBE_IMA_C ; -if (has_vector ()) +if (has_vector () &&riscv_isa_extension_available (NULL , v)) pair->value |=RISCV_HWPROBE_IMA_V ;/*
@@ -113,6 +113,10 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair,EXT_KEY (ZICOND );EXT_KEY (ZIHINTPAUSE ); +/* +* All the following extensions must depend on the kernel +* support of V. +*/ if (has_vector ()) {EXT_KEY (ZVE32X );EXT_KEY (ZVE32F );
arch/riscv/kernel/vector.c +4 -1
@@ -173,8 +173,11 @@ bool riscv_v_first_use_handler(struct pt_regs *regs)u32 __user *epc = (u32 __user *)regs->epc;u32 insn = (u32 )regs->badaddr; +if (!has_vector ()) +return false; +/* Do not handle if V is not supported, or disabled */ -if (!(ELF_HWCAP &COMPAT_HWCAP_ISA_V )) +if (!riscv_v_vstate_ctrl_user_allowed ())return false;/* If V has been enabled then it is not the first-use trap */
arch/riscv/lib/uaccess.S +1 -1
@@ -14,7 +14,7 @@ SYM_FUNC_START(__asm_copy_to_user) #ifdef CONFIG_RISCV_ISA_V - ALTERNATIVE("j fallback_scalar_usercopy", "nop", 0, RISCV_ISA_EXT_v, CONFIG_RISCV_ISA_V) + ALTERNATIVE("j fallback_scalar_usercopy", "nop", 0, RISCV_ISA_EXT_ZVE32X, CONFIG_RISCV_ISA_V) REG_L t0, riscv_v_usercopy_threshold bltu a2, t0, fallback_scalar_usercopy tail enter_vector_usercopy
Signature · 1 line
2.44.0.rc2
PATCH v5 8/8 selftest: run vector prctl test for ZVE32X
In reply to Andy ChiuThe minimal requirement for running Vector subextension on Linux is ZVE32X. So change the test accordingly to run prctl as long as it find it.
---
Changelog v4:
- new patch since v4
--- tools/testing/selftests/riscv/vector/vstate_prctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/riscv/vector/vstate_prctl.c +3 -3
@@ -88,16 +88,16 @@ int main(void)return -2 ; } -if (!(pair.value &RISCV_HWPROBE_IMA_V )) { +if (!(pair.value &RISCV_HWPROBE_EXT_ZVE32X )) { rc =prctl (PR_RISCV_V_GET_CONTROL );if (rc !=-1 || errno !=EINVAL ) { -ksft_test_result_fail ("GET_CONTROL should fail on kernel/hw without V\n" ); +ksft_test_result_fail ("GET_CONTROL should fail on kernel/hw without ZVE32X\n" );return -3 ; } rc =prctl (PR_RISCV_V_SET_CONTROL ,PR_RISCV_V_VSTATE_CTRL_ON );if (rc !=-1 || errno !=EINVAL ) { -ksft_test_result_fail ("GET_CONTROL should fail on kernel/hw without V\n" ); +ksft_test_result_fail ("SET_CONTROL should fail on kernel/hw without ZVE32X\n" );return -4 ; }
Signature · 1 line
2.44.0.rc2
This series was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Hello:
This series was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Quoted 18 lines · On Fri, 10 May 2024 00:26:50 +0800 you wrote:
The series composes of two parts. The first part Specifically, patch 1 adds a comment at a callsite of
riscv_setup_vsizeto 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 makeshas_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.
Quoted 1 line
[...]
Here is the summary with links:
- [v5,1/8] riscv: vector: add a comment when calling riscv_setup_vsize()
https://git.kernel.org/riscv/c/77afe3e514b8 - [v5,2/8] riscv: smp: fail booting up smp if inconsistent vlen is detected https://git.kernel.org/riscv/c/38a94c46660f - [v5,3/8] riscv: cpufeature: call match_isa_ext() for single-letter extensions https://git.kernel.org/riscv/c/98a5700dfaec - [v5,4/8] dt-bindings: riscv: add Zve32[xf] Zve64[xfd] ISA extension description https://git.kernel.org/riscv/c/037df2966afc - [v5,5/8] riscv: cpufeature: add zve32[xf] and zve64[xfd] isa detection https://git.kernel.org/riscv/c/1e7483542bf8 - [v5,6/8] riscv: hwprobe: add zve Vector subextensions into hwprobe interface https://git.kernel.org/riscv/c/de8f8282a969 - [v5,7/8] riscv: vector: adjust minimum Vector requirement to ZVE32X https://git.kernel.org/riscv/c/ac295b67422d - [v5,8/8] selftest: run vector prctl test for ZVE32X https://git.kernel.org/riscv/c/edc96a2b4c79
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html