Skip to content

Commit 49886aa

Browse files
brooniectmarinas
authored andcommitted
kselftest/arm64: Add SME2 coverage to syscall-abi
Verify that ZT0 is preserved over syscalls when it is present and PSTATE.ZA is set. Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20221208-arm64-sme2-v4-19-f2fa0aef982f@kernel.org Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 18f8729 commit 49886aa

2 files changed

Lines changed: 80 additions & 3 deletions

File tree

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
.arch_extension sve
2525

26+
#define ID_AA64SMFR0_EL1_SMEver_SHIFT 56
27+
#define ID_AA64SMFR0_EL1_SMEver_WIDTH 4
28+
2629
/*
2730
* LDR (vector to ZA array):
2831
* LDR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL]
@@ -45,6 +48,26 @@
4548
| ((\offset) & 7)
4649
.endm
4750

51+
/*
52+
* LDR (ZT0)
53+
*
54+
* LDR ZT0, nx
55+
*/
56+
.macro _ldr_zt nx
57+
.inst 0xe11f8000 \
58+
| (((\nx) & 0x1f) << 5)
59+
.endm
60+
61+
/*
62+
* STR (ZT0)
63+
*
64+
* STR ZT0, nx
65+
*/
66+
.macro _str_zt nx
67+
.inst 0xe13f8000 \
68+
| (((\nx) & 0x1f) << 5)
69+
.endm
70+
4871
.globl do_syscall
4972
do_syscall:
5073
// Store callee saved registers x19-x29 (80 bytes) plus x0 and x1
@@ -64,7 +87,7 @@ do_syscall:
6487
msr S3_3_C4_C2_2, x2
6588
1:
6689

67-
// Load ZA if it's enabled - uses x12 as scratch due to SME LDR
90+
// Load ZA and ZT0 if enabled - uses x12 as scratch due to SME LDR
6891
tbz x2, #SVCR_ZA_SHIFT, 1f
6992
mov w12, #0
7093
ldr x2, =za_in
@@ -73,6 +96,15 @@ do_syscall:
7396
add x12, x12, #1
7497
cmp x1, x12
7598
bne 2b
99+
100+
// ZT0
101+
mrs x2, S3_0_C0_C4_5 // ID_AA64SMFR0_EL1
102+
ubfx x2, x2, #ID_AA64SMFR0_EL1_SMEver_SHIFT, \
103+
#ID_AA64SMFR0_EL1_SMEver_WIDTH
104+
cbz x2, 1f
105+
adrp x2, zt_in
106+
add x2, x2, :lo12:zt_in
107+
_ldr_zt 2
76108
1:
77109

78110
// Load GPRs x8-x28, and save our SP/FP for later comparison
@@ -235,6 +267,15 @@ do_syscall:
235267
add x12, x12, #1
236268
cmp x1, x12
237269
bne 2b
270+
271+
// ZT0
272+
mrs x2, S3_0_C0_C4_5 // ID_AA64SMFR0_EL1
273+
ubfx x2, x2, #ID_AA64SMFR0_EL1_SMEver_SHIFT, \
274+
#ID_AA64SMFR0_EL1_SMEver_WIDTH
275+
cbz x2, 1f
276+
adrp x2, zt_out
277+
add x2, x2, :lo12:zt_out
278+
_str_zt 2
238279
1:
239280

240281
// Save the SVE state if we have some

tools/testing/selftests/arm64/abi/syscall-abi.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,35 @@ static int check_za(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
311311
return errors;
312312
}
313313

314+
uint8_t zt_in[ZT_SIG_REG_BYTES] __attribute__((aligned(16)));
315+
uint8_t zt_out[ZT_SIG_REG_BYTES] __attribute__((aligned(16)));
316+
317+
static void setup_zt(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
318+
uint64_t svcr)
319+
{
320+
fill_random(zt_in, sizeof(zt_in));
321+
memset(zt_out, 0, sizeof(zt_out));
322+
}
323+
324+
static int check_zt(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
325+
uint64_t svcr)
326+
{
327+
int errors = 0;
328+
329+
if (!(getauxval(AT_HWCAP2) & HWCAP2_SME2))
330+
return 0;
331+
332+
if (!(svcr & SVCR_ZA_MASK))
333+
return 0;
334+
335+
if (memcmp(zt_in, zt_out, sizeof(zt_in)) != 0) {
336+
ksft_print_msg("SME VL %d ZT does not match\n", sme_vl);
337+
errors++;
338+
}
339+
340+
return errors;
341+
}
342+
314343
typedef void (*setup_fn)(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
315344
uint64_t svcr);
316345
typedef int (*check_fn)(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
@@ -334,6 +363,7 @@ static struct {
334363
{ setup_ffr, check_ffr },
335364
{ setup_svcr, check_svcr },
336365
{ setup_za, check_za },
366+
{ setup_zt, check_zt },
337367
};
338368

339369
static bool do_test(struct syscall_cfg *cfg, int sve_vl, int sme_vl,
@@ -474,6 +504,7 @@ int main(void)
474504
{
475505
int i;
476506
int tests = 1; /* FPSIMD */
507+
int sme_ver;
477508

478509
srandom(getpid());
479510

@@ -482,10 +513,15 @@ int main(void)
482513
tests += (sve_count_vls() * sme_count_vls()) * 3;
483514
ksft_set_plan(ARRAY_SIZE(syscalls) * tests);
484515

516+
if (getauxval(AT_HWCAP2) & HWCAP2_SME2)
517+
sme_ver = 2;
518+
else
519+
sme_ver = 1;
520+
485521
if (getauxval(AT_HWCAP2) & HWCAP2_SME_FA64)
486-
ksft_print_msg("SME with FA64\n");
522+
ksft_print_msg("SME%d with FA64\n", sme_ver);
487523
else if (getauxval(AT_HWCAP2) & HWCAP2_SME)
488-
ksft_print_msg("SME without FA64\n");
524+
ksft_print_msg("SME%d without FA64\n", sme_ver);
489525

490526
for (i = 0; i < ARRAY_SIZE(syscalls); i++)
491527
test_one_syscall(&syscalls[i]);

0 commit comments

Comments
 (0)