Skip to content

Commit 2613c15

Browse files
Merge patch series "riscv: Add support for xtheadvector"
Charlie Jenkins <[email protected]> says: xtheadvector is a custom extension that is based upon riscv vector version 0.7.1 [1]. All of the vector routines have been modified to support this alternative vector version based upon whether xtheadvector was determined to be supported at boot. vlenb is not supported on the existing xtheadvector hardware, so a devicetree property thead,vlenb is added to provide the vlenb to Linux. There is a new hwprobe key RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0 that is used to request which thead vendor extensions are supported on the current platform. This allows future vendors to allocate hwprobe keys for their vendor. Support for xtheadvector is also added to the vector kselftests. [1] https://github.com/T-head-Semi/thead-extension-spec/blob/95358cb2cca9489361c61d335e03d3134b14133f/xtheadvector.adoc * b4-shazam-merge: riscv: Add ghostwrite vulnerability selftests: riscv: Support xtheadvector in vector tests selftests: riscv: Fix vector tests riscv: hwprobe: Document thead vendor extensions and xtheadvector extension riscv: hwprobe: Add thead vendor extension probing riscv: vector: Support xtheadvector save/restore riscv: Add xtheadvector instruction definitions riscv: csr: Add CSR encodings for CSR_VXRM/CSR_VXSAT RISC-V: define the elements of the VCSR vector CSR riscv: vector: Use vlenb from DT for thead riscv: Add thead and xtheadvector as a vendor extension riscv: dts: allwinner: Add xtheadvector to the D1/D1s devicetree dt-bindings: cpus: add a thead vlen register length property dt-bindings: riscv: Add xtheadvector ISA extension description Signed-off-by: Charlie Jenkins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents 26f2d6d + 4bf9706 commit 2613c15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1053
-273
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,13 @@ The following keys are defined:
293293

294294
* :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED`: Misaligned vector accesses are
295295
not supported at all and will generate a misaligned address fault.
296+
297+
* :c:macro:`RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0`: A bitmask containing the
298+
thead vendor extensions that are compatible with the
299+
:c:macro:`RISCV_HWPROBE_BASE_BEHAVIOR_IMA`: base system behavior.
300+
301+
* T-HEAD
302+
303+
* :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR`: The xtheadvector vendor
304+
extension is supported in the T-Head ISA extensions spec starting from
305+
commit a18c801634 ("Add T-Head VECTOR vendor extension. ").

Documentation/devicetree/bindings/riscv/cpus.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ description: |
2626
allOf:
2727
- $ref: /schemas/cpu.yaml#
2828
- $ref: extensions.yaml
29+
- if:
30+
not:
31+
properties:
32+
compatible:
33+
contains:
34+
enum:
35+
- thead,c906
36+
- thead,c910
37+
- thead,c920
38+
then:
39+
properties:
40+
thead,vlenb: false
2941

3042
properties:
3143
compatible:
@@ -95,6 +107,13 @@ properties:
95107
description:
96108
The blocksize in bytes for the Zicboz cache operations.
97109

110+
thead,vlenb:
111+
$ref: /schemas/types.yaml#/definitions/uint32
112+
description:
113+
VLEN/8, the vector register length in bytes. This property is required on
114+
thead systems where the vector register length is not identical on all harts, or
115+
the vlenb CSR is not available.
116+
98117
# RISC-V has multiple properties for cache op block sizes as the sizes
99118
# differ between individual CBO extensions
100119
cache-op-block-size: false

Documentation/devicetree/bindings/riscv/extensions.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,23 @@ properties:
621621
latency, as ratified in commit 56ed795 ("Update
622622
riscv-crypto-spec-vector.adoc") of riscv-crypto.
623623

624+
# vendor extensions, each extension sorted alphanumerically under the
625+
# vendor they belong to. Vendors are sorted alphanumerically as well.
626+
627+
# Andes
624628
- const: xandespmu
625629
description:
626630
The Andes Technology performance monitor extension for counter overflow
627631
and privilege mode filtering. For more details, see Counter Related
628632
Registers in the AX45MP datasheet.
629633
https://www.andestech.com/wp-content/uploads/AX45MP-1C-Rev.-5.0.0-Datasheet.pdf
630634

635+
# T-HEAD
636+
- const: xtheadvector
637+
description:
638+
The T-HEAD specific 0.7.1 vector implementation as written in
639+
https://github.com/T-head-Semi/thead-extension-spec/blob/95358cb2cca9489361c61d335e03d3134b14133f/xtheadvector.adoc.
640+
631641
allOf:
632642
# Zcb depends on Zca
633643
- if:

arch/riscv/Kconfig.errata

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,15 @@ config ERRATA_THEAD_PMU
119119

120120
If you don't know what to do here, say "Y".
121121

122+
config ERRATA_THEAD_GHOSTWRITE
123+
bool "Apply T-Head Ghostwrite errata"
124+
depends on ERRATA_THEAD && RISCV_ISA_XTHEADVECTOR
125+
default y
126+
help
127+
The T-Head C9xx cores have a vulnerability in the xtheadvector
128+
instruction set. When this errata is enabled, the CPUs will be probed
129+
to determine if they are vulnerable and disable xtheadvector.
130+
131+
If you don't know what to do here, say "Y".
132+
122133
endmenu # "CPU errata selection"

arch/riscv/Kconfig.vendor

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,30 @@ config RISCV_ISA_VENDOR_EXT_ANDES
1616
If you don't know what to do here, say Y.
1717
endmenu
1818

19+
menu "T-Head"
20+
config RISCV_ISA_VENDOR_EXT_THEAD
21+
bool "T-Head vendor extension support"
22+
select RISCV_ISA_VENDOR_EXT
23+
default y
24+
help
25+
Say N here to disable detection of and support for all T-Head vendor
26+
extensions. Without this option enabled, T-Head vendor extensions will
27+
not be detected at boot and their presence not reported to userspace.
28+
29+
If you don't know what to do here, say Y.
30+
31+
config RISCV_ISA_XTHEADVECTOR
32+
bool "xtheadvector extension support"
33+
depends on RISCV_ISA_VENDOR_EXT_THEAD
34+
depends on RISCV_ISA_V
35+
depends on FPU
36+
default y
37+
help
38+
Say N here if you want to disable all xtheadvector related procedures
39+
in the kernel. This will disable vector for any T-Head board that
40+
contains xtheadvector rather than the standard vector.
41+
42+
If you don't know what to do here, say Y.
43+
endmenu
44+
1945
endmenu

arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
riscv,isa = "rv64imafdc";
2828
riscv,isa-base = "rv64i";
2929
riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "zicntr", "zicsr",
30-
"zifencei", "zihpm";
30+
"zifencei", "zihpm", "xtheadvector";
31+
thead,vlenb = <128>;
3132
#cooling-cells = <2>;
3233

3334
cpu0_intc: interrupt-controller {

arch/riscv/errata/thead/errata.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/string.h>
1111
#include <linux/uaccess.h>
1212
#include <asm/alternative.h>
13+
#include <asm/bugs.h>
1314
#include <asm/cacheflush.h>
1415
#include <asm/cpufeature.h>
1516
#include <asm/dma-noncoherent.h>
@@ -142,6 +143,31 @@ static bool errata_probe_pmu(unsigned int stage,
142143
return true;
143144
}
144145

146+
static bool errata_probe_ghostwrite(unsigned int stage,
147+
unsigned long arch_id, unsigned long impid)
148+
{
149+
if (!IS_ENABLED(CONFIG_ERRATA_THEAD_GHOSTWRITE))
150+
return false;
151+
152+
/*
153+
* target-c9xx cores report arch_id and impid as 0
154+
*
155+
* While ghostwrite may not affect all c9xx cores that implement
156+
* xtheadvector, there is no futher granularity than c9xx. Assume
157+
* vulnerable for this entire class of processors when xtheadvector is
158+
* enabled.
159+
*/
160+
if (arch_id != 0 || impid != 0)
161+
return false;
162+
163+
if (stage != RISCV_ALTERNATIVES_EARLY_BOOT)
164+
return false;
165+
166+
ghostwrite_set_vulnerable();
167+
168+
return true;
169+
}
170+
145171
static u32 thead_errata_probe(unsigned int stage,
146172
unsigned long archid, unsigned long impid)
147173
{
@@ -155,6 +181,8 @@ static u32 thead_errata_probe(unsigned int stage,
155181
if (errata_probe_pmu(stage, archid, impid))
156182
cpu_req_errata |= BIT(ERRATA_THEAD_PMU);
157183

184+
errata_probe_ghostwrite(stage, archid, impid);
185+
158186
return cpu_req_errata;
159187
}
160188

arch/riscv/include/asm/bugs.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Interface for managing mitigations for riscv vulnerabilities.
4+
*
5+
* Copyright (C) 2024 Rivos Inc.
6+
*/
7+
8+
#ifndef __ASM_BUGS_H
9+
#define __ASM_BUGS_H
10+
11+
/* Watch out, ordering is important here. */
12+
enum mitigation_state {
13+
UNAFFECTED,
14+
MITIGATED,
15+
VULNERABLE,
16+
};
17+
18+
void ghostwrite_set_vulnerable(void);
19+
bool ghostwrite_enable_mitigation(void);
20+
enum mitigation_state ghostwrite_get_state(void);
21+
22+
#endif /* __ASM_BUGS_H */

arch/riscv/include/asm/cpufeature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ DECLARE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
3434
/* Per-cpu ISA extensions. */
3535
extern struct riscv_isainfo hart_isa[NR_CPUS];
3636

37+
extern u32 thead_vlenb_of;
38+
3739
void __init riscv_user_isa_enable(void);
3840

3941
#define _RISCV_ISA_EXT_DATA(_name, _id, _subset_exts, _subset_exts_size, _validate) { \

arch/riscv/include/asm/csr.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
#define SR_VS_CLEAN _AC(0x00000400, UL)
3131
#define SR_VS_DIRTY _AC(0x00000600, UL)
3232

33+
#define SR_VS_THEAD _AC(0x01800000, UL) /* xtheadvector Status */
34+
#define SR_VS_OFF_THEAD _AC(0x00000000, UL)
35+
#define SR_VS_INITIAL_THEAD _AC(0x00800000, UL)
36+
#define SR_VS_CLEAN_THEAD _AC(0x01000000, UL)
37+
#define SR_VS_DIRTY_THEAD _AC(0x01800000, UL)
38+
3339
#define SR_XS _AC(0x00018000, UL) /* Extension Status */
3440
#define SR_XS_OFF _AC(0x00000000, UL)
3541
#define SR_XS_INITIAL _AC(0x00008000, UL)
@@ -315,6 +321,15 @@
315321
#define CSR_STIMECMP 0x14D
316322
#define CSR_STIMECMPH 0x15D
317323

324+
/* xtheadvector symbolic CSR names */
325+
#define CSR_VXSAT 0x9
326+
#define CSR_VXRM 0xa
327+
328+
/* xtheadvector CSR masks */
329+
#define CSR_VXRM_MASK 3
330+
#define CSR_VXRM_SHIFT 1
331+
#define CSR_VXSAT_MASK 1
332+
318333
/* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */
319334
#define CSR_SISELECT 0x150
320335
#define CSR_SIREG 0x151

0 commit comments

Comments
 (0)