Skip to content

Commit 43e3f85

Browse files
brooniectmarinas
authored andcommitted
kselftest/arm64: Add SME support to syscall ABI test
For every possible combination of SVE and SME vector length verify that for each possible value of SVCR after a syscall we leave streaming mode and ZA is preserved. We don't need to take account of any streaming/non streaming SVE vector length changes in the assembler code since the store instructions will handle the vector length for us. We log if the system supports FA64 and only try to set FFR in streaming mode if it does. Signed-off-by: Mark Brown <[email protected]> Reviewed-by: Shuah Khan <[email protected]> Acked-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 86c8888 commit 43e3f85

File tree

3 files changed

+275
-23
lines changed

3 files changed

+275
-23
lines changed

tools/testing/selftests/arm64/abi/syscall-abi-asm.S

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,42 @@
99
// invoked is configured in x8 of the input GPR data.
1010
//
1111
// x0: SVE VL, 0 for FP only
12+
// x1: SME VL
1213
//
1314
// GPRs: gpr_in, gpr_out
1415
// FPRs: fpr_in, fpr_out
1516
// Zn: z_in, z_out
1617
// Pn: p_in, p_out
1718
// FFR: ffr_in, ffr_out
19+
// ZA: za_in, za_out
20+
// SVCR: svcr_in, svcr_out
21+
22+
#include "syscall-abi.h"
1823

1924
.arch_extension sve
2025

26+
/*
27+
* LDR (vector to ZA array):
28+
* LDR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL]
29+
*/
30+
.macro _ldr_za nw, nxbase, offset=0
31+
.inst 0xe1000000 \
32+
| (((\nw) & 3) << 13) \
33+
| ((\nxbase) << 5) \
34+
| ((\offset) & 7)
35+
.endm
36+
37+
/*
38+
* STR (vector from ZA array):
39+
* STR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL]
40+
*/
41+
.macro _str_za nw, nxbase, offset=0
42+
.inst 0xe1200000 \
43+
| (((\nw) & 3) << 13) \
44+
| ((\nxbase) << 5) \
45+
| ((\offset) & 7)
46+
.endm
47+
2148
.globl do_syscall
2249
do_syscall:
2350
// Store callee saved registers x19-x29 (80 bytes) plus x0 and x1
@@ -30,6 +57,24 @@ do_syscall:
3057
stp x25, x26, [sp, #80]
3158
stp x27, x28, [sp, #96]
3259

60+
// Set SVCR if we're doing SME
61+
cbz x1, 1f
62+
adrp x2, svcr_in
63+
ldr x2, [x2, :lo12:svcr_in]
64+
msr S3_3_C4_C2_2, x2
65+
1:
66+
67+
// Load ZA if it's enabled - uses x12 as scratch due to SME LDR
68+
tbz x2, #SVCR_ZA_SHIFT, 1f
69+
mov w12, #0
70+
ldr x2, =za_in
71+
2: _ldr_za 12, 2
72+
add x2, x2, x1
73+
add x12, x12, #1
74+
cmp x1, x12
75+
bne 2b
76+
1:
77+
3378
// Load GPRs x8-x28, and save our SP/FP for later comparison
3479
ldr x2, =gpr_in
3580
add x2, x2, #64
@@ -68,7 +113,7 @@ do_syscall:
68113
ldp q30, q31, [x2, #16 * 30]
69114
1:
70115

71-
// Load the SVE registers if we're doing SVE
116+
// Load the SVE registers if we're doing SVE/SME
72117
cbz x0, 1f
73118

74119
ldr x2, =z_in
@@ -105,9 +150,14 @@ do_syscall:
105150
ldr z30, [x2, #30, MUL VL]
106151
ldr z31, [x2, #31, MUL VL]
107152

153+
// Only set a non-zero FFR, test patterns must be zero since the
154+
// syscall should clear it - this lets us handle FA64.
108155
ldr x2, =ffr_in
109156
ldr p0, [x2, #0]
157+
ldr x2, [x2, #0]
158+
cbz x2, 2f
110159
wrffr p0.b
160+
2:
111161

112162
ldr x2, =p_in
113163
ldr p0, [x2, #0, MUL VL]
@@ -169,6 +219,24 @@ do_syscall:
169219
stp q28, q29, [x2, #16 * 28]
170220
stp q30, q31, [x2, #16 * 30]
171221

222+
// Save SVCR if we're doing SME
223+
cbz x1, 1f
224+
mrs x2, S3_3_C4_C2_2
225+
adrp x3, svcr_out
226+
str x2, [x3, :lo12:svcr_out]
227+
1:
228+
229+
// Save ZA if it's enabled - uses x12 as scratch due to SME STR
230+
tbz x2, #SVCR_ZA_SHIFT, 1f
231+
mov w12, #0
232+
ldr x2, =za_out
233+
2: _str_za 12, 2
234+
add x2, x2, x1
235+
add x12, x12, #1
236+
cmp x1, x12
237+
bne 2b
238+
1:
239+
172240
// Save the SVE state if we have some
173241
cbz x0, 1f
174242

@@ -224,6 +292,10 @@ do_syscall:
224292
str p14, [x2, #14, MUL VL]
225293
str p15, [x2, #15, MUL VL]
226294

295+
// Only save FFR if we wrote a value for SME
296+
ldr x2, =ffr_in
297+
ldr x2, [x2, #0]
298+
cbz x2, 1f
227299
ldr x2, =ffr_out
228300
rdffr p0.b
229301
str p0, [x2, #0]
@@ -237,4 +309,9 @@ do_syscall:
237309
ldp x27, x28, [sp, #96]
238310
ldp x29, x30, [sp], #112
239311

312+
// Clear SVCR if we were doing SME so future tests don't have ZA
313+
cbz x1, 1f
314+
msr S3_3_C4_C2_2, xzr
315+
1:
316+
240317
ret

0 commit comments

Comments
 (0)