Skip to content

Commit 06a916f

Browse files
Dave Martinwildea01
Dave Martin
authored andcommitted
arm64: Expose SVE2 features for userspace
This patch provides support for reporting the presence of SVE2 and its optional features to userspace. This will also enable visibility of SVE2 for guests, when KVM support for SVE-enabled guests is available. Signed-off-by: Dave Martin <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent dd52379 commit 06a916f

File tree

9 files changed

+108
-1
lines changed

9 files changed

+108
-1
lines changed

Documentation/arm64/cpu-feature-registers.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ infrastructure:
209209
| AT | [35-32] | y |
210210
x--------------------------------------------------x
211211

212+
6) ID_AA64ZFR0_EL1 - SVE feature ID register 0
213+
214+
x--------------------------------------------------x
215+
| Name | bits | visible |
216+
|--------------------------------------------------|
217+
| SM4 | [43-40] | y |
218+
|--------------------------------------------------|
219+
| SHA3 | [35-32] | y |
220+
|--------------------------------------------------|
221+
| BitPerm | [19-16] | y |
222+
|--------------------------------------------------|
223+
| AES | [7-4] | y |
224+
|--------------------------------------------------|
225+
| SVEVer | [3-0] | y |
226+
x--------------------------------------------------x
227+
212228
Appendix I: Example
213229
---------------------------
214230

Documentation/arm64/elf_hwcaps.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,30 @@ HWCAP_SVE
163163

164164
Functionality implied by ID_AA64PFR0_EL1.SVE == 0b0001.
165165

166+
HWCAP2_SVE2
167+
168+
Functionality implied by ID_AA64ZFR0_EL1.SVEVer == 0b0001.
169+
170+
HWCAP2_SVEAES
171+
172+
Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0001.
173+
174+
HWCAP2_SVEPMULL
175+
176+
Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0010.
177+
178+
HWCAP2_SVEBITPERM
179+
180+
Functionality implied by ID_AA64ZFR0_EL1.BitPerm == 0b0001.
181+
182+
HWCAP2_SVESHA3
183+
184+
Functionality implied by ID_AA64ZFR0_EL1.SHA3 == 0b0001.
185+
186+
HWCAP2_SVESM4
187+
188+
Functionality implied by ID_AA64ZFR0_EL1.SM4 == 0b0001.
189+
166190
HWCAP_ASIMDFHM
167191

168192
Functionality implied by ID_AA64ISAR0_EL1.FHM == 0b0001.

Documentation/arm64/sve.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ model features for SVE is included in Appendix A.
3434
following sections: software that needs to verify that those interfaces are
3535
present must check for HWCAP_SVE instead.
3636

37+
* On hardware that supports the SVE2 extensions, HWCAP2_SVE2 will also
38+
be reported in the AT_HWCAP2 aux vector entry. In addition to this,
39+
optional extensions to SVE2 may be reported by the presence of:
40+
41+
HWCAP2_SVE2
42+
HWCAP2_SVEAES
43+
HWCAP2_SVEPMULL
44+
HWCAP2_SVEBITPERM
45+
HWCAP2_SVESHA3
46+
HWCAP2_SVESM4
47+
48+
This list may be extended over time as the SVE architecture evolves.
49+
50+
These extensions are also reported via the CPU ID register ID_AA64ZFR0_EL1,
51+
which userspace can read using an MRS instruction. See elf_hwcaps.txt and
52+
cpu-feature-registers.txt for details.
53+
3754
* Debuggers should restrict themselves to interacting with the target via the
3855
NT_ARM_SVE regset. The recommended way of detecting support for this regset
3956
is to connect to a target process first and then attempt a

arch/arm64/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,9 @@ config ARM64_SVE
13721372

13731373
To enable use of this extension on CPUs that implement it, say Y.
13741374

1375+
On CPUs that support the SVE2 extensions, this option will enable
1376+
those too.
1377+
13751378
Note that for architectural reasons, firmware _must_ implement SVE
13761379
support when running on SVE capable hardware. The required support
13771380
is present in:

arch/arm64/include/asm/hwcap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989

9090
#define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + 32)
9191
#define KERNEL_HWCAP_DCPODP __khwcap2_feature(DCPODP)
92+
#define KERNEL_HWCAP_SVE2 __khwcap2_feature(SVE2)
93+
#define KERNEL_HWCAP_SVEAES __khwcap2_feature(SVEAES)
94+
#define KERNEL_HWCAP_SVEPMULL __khwcap2_feature(SVEPMULL)
95+
#define KERNEL_HWCAP_SVEBITPERM __khwcap2_feature(SVEBITPERM)
96+
#define KERNEL_HWCAP_SVESHA3 __khwcap2_feature(SVESHA3)
97+
#define KERNEL_HWCAP_SVESM4 __khwcap2_feature(SVESM4)
9298

9399
/*
94100
* This yields a mask that user programs can use to figure out what

arch/arm64/include/asm/sysreg.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,20 @@
606606
#define ID_AA64PFR1_SSBS_PSTATE_ONLY 1
607607
#define ID_AA64PFR1_SSBS_PSTATE_INSNS 2
608608

609+
/* id_aa64zfr0 */
610+
#define ID_AA64ZFR0_SM4_SHIFT 40
611+
#define ID_AA64ZFR0_SHA3_SHIFT 32
612+
#define ID_AA64ZFR0_BITPERM_SHIFT 16
613+
#define ID_AA64ZFR0_AES_SHIFT 4
614+
#define ID_AA64ZFR0_SVEVER_SHIFT 0
615+
616+
#define ID_AA64ZFR0_SM4 0x1
617+
#define ID_AA64ZFR0_SHA3 0x1
618+
#define ID_AA64ZFR0_BITPERM 0x1
619+
#define ID_AA64ZFR0_AES 0x1
620+
#define ID_AA64ZFR0_AES_PMULL 0x2
621+
#define ID_AA64ZFR0_SVEVER_SVE2 0x1
622+
609623
/* id_aa64mmfr0 */
610624
#define ID_AA64MMFR0_TGRAN4_SHIFT 28
611625
#define ID_AA64MMFR0_TGRAN64_SHIFT 24

arch/arm64/include/uapi/asm/hwcap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@
5757
* HWCAP2 flags - for AT_HWCAP2
5858
*/
5959
#define HWCAP2_DCPODP (1 << 0)
60+
#define HWCAP2_SVE2 (1 << 1)
61+
#define HWCAP2_SVEAES (1 << 2)
62+
#define HWCAP2_SVEPMULL (1 << 3)
63+
#define HWCAP2_SVEBITPERM (1 << 4)
64+
#define HWCAP2_SVESHA3 (1 << 5)
65+
#define HWCAP2_SVESM4 (1 << 6)
6066

6167
#endif /* _UAPI__ASM_HWCAP_H */

arch/arm64/kernel/cpufeature.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
184184
ARM64_FTR_END,
185185
};
186186

187+
static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = {
188+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
189+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
190+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
191+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
192+
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
193+
ARM64_FTR_END,
194+
};
195+
187196
static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = {
188197
S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_TGRAN4_SHIFT, 4, ID_AA64MMFR0_TGRAN4_NI),
189198
S_ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_TGRAN64_SHIFT, 4, ID_AA64MMFR0_TGRAN64_NI),
@@ -392,7 +401,7 @@ static const struct __ftr_reg_entry {
392401
/* Op1 = 0, CRn = 0, CRm = 4 */
393402
ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1, ftr_id_aa64pfr0),
394403
ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1),
395-
ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_raz),
404+
ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_id_aa64zfr0),
396405

397406
/* Op1 = 0, CRn = 0, CRm = 5 */
398407
ARM64_FTR_REG(SYS_ID_AA64DFR0_EL1, ftr_id_aa64dfr0),
@@ -1610,6 +1619,12 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {
16101619
HWCAP_CAP(SYS_ID_AA64MMFR2_EL1, ID_AA64MMFR2_AT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_USCAT),
16111620
#ifdef CONFIG_ARM64_SVE
16121621
HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_SVE_SHIFT, FTR_UNSIGNED, ID_AA64PFR0_SVE, CAP_HWCAP, KERNEL_HWCAP_SVE),
1622+
HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SVEVER_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SVEVER_SVE2, CAP_HWCAP, KERNEL_HWCAP_SVE2),
1623+
HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES, CAP_HWCAP, KERNEL_HWCAP_SVEAES),
1624+
HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES_PMULL, CAP_HWCAP, KERNEL_HWCAP_SVEPMULL),
1625+
HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_BITPERM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_BITPERM, CAP_HWCAP, KERNEL_HWCAP_SVEBITPERM),
1626+
HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SHA3_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SHA3, CAP_HWCAP, KERNEL_HWCAP_SVESHA3),
1627+
HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SM4_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SM4, CAP_HWCAP, KERNEL_HWCAP_SVESM4),
16131628
#endif
16141629
HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, KERNEL_HWCAP_SSBS),
16151630
#ifdef CONFIG_ARM64_PTR_AUTH

arch/arm64/kernel/cpuinfo.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ static const char *const hwcap_str[] = {
8686
"paca",
8787
"pacg",
8888
"dcpodp",
89+
"sve2",
90+
"sveaes",
91+
"svepmull",
92+
"svebitperm",
93+
"svesha3",
94+
"svesm4",
8995
NULL
9096
};
9197

0 commit comments

Comments
 (0)