Skip to content

Commit ce03573

Browse files
owniactmarinas
authored andcommitted
kselftest/arm64: abi: fix SVCR detection
When using svcr_in to check ZA and Streaming Mode, we should make sure that the value in x2 is correct, otherwise it may trigger an Illegal instruction if FEAT_SVE and !FEAT_SME. Fixes: 43e3f85 ("kselftest/arm64: Add SME support to syscall ABI test") Signed-off-by: Weizhao Ouyang <o451686892@gmail.com> Reviewed-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20241211111639.12344-1-o451686892@gmail.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent a3b4647 commit ce03573

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,31 @@ do_syscall:
8181
stp x27, x28, [sp, #96]
8282

8383
// Set SVCR if we're doing SME
84-
cbz x1, 1f
84+
cbz x1, load_gpr
8585
adrp x2, svcr_in
8686
ldr x2, [x2, :lo12:svcr_in]
8787
msr S3_3_C4_C2_2, x2
88-
1:
8988

9089
// Load ZA and ZT0 if enabled - uses x12 as scratch due to SME LDR
91-
tbz x2, #SVCR_ZA_SHIFT, 1f
90+
tbz x2, #SVCR_ZA_SHIFT, load_gpr
9291
mov w12, #0
9392
ldr x2, =za_in
94-
2: _ldr_za 12, 2
93+
1: _ldr_za 12, 2
9594
add x2, x2, x1
9695
add x12, x12, #1
9796
cmp x1, x12
98-
bne 2b
97+
bne 1b
9998

10099
// ZT0
101100
mrs x2, S3_0_C0_C4_5 // ID_AA64SMFR0_EL1
102101
ubfx x2, x2, #ID_AA64SMFR0_EL1_SMEver_SHIFT, \
103102
#ID_AA64SMFR0_EL1_SMEver_WIDTH
104-
cbz x2, 1f
103+
cbz x2, load_gpr
105104
adrp x2, zt_in
106105
add x2, x2, :lo12:zt_in
107106
_ldr_zt 2
108-
1:
109107

108+
load_gpr:
110109
// Load GPRs x8-x28, and save our SP/FP for later comparison
111110
ldr x2, =gpr_in
112111
add x2, x2, #64
@@ -125,9 +124,9 @@ do_syscall:
125124
str x30, [x2], #8 // LR
126125

127126
// Load FPRs if we're not doing neither SVE nor streaming SVE
128-
cbnz x0, 1f
127+
cbnz x0, check_sve_in
129128
ldr x2, =svcr_in
130-
tbnz x2, #SVCR_SM_SHIFT, 1f
129+
tbnz x2, #SVCR_SM_SHIFT, check_sve_in
131130

132131
ldr x2, =fpr_in
133132
ldp q0, q1, [x2]
@@ -148,8 +147,8 @@ do_syscall:
148147
ldp q30, q31, [x2, #16 * 30]
149148

150149
b 2f
151-
1:
152150

151+
check_sve_in:
153152
// Load the SVE registers if we're doing SVE/SME
154153

155154
ldr x2, =z_in
@@ -256,32 +255,31 @@ do_syscall:
256255
stp q30, q31, [x2, #16 * 30]
257256

258257
// Save SVCR if we're doing SME
259-
cbz x1, 1f
258+
cbz x1, check_sve_out
260259
mrs x2, S3_3_C4_C2_2
261260
adrp x3, svcr_out
262261
str x2, [x3, :lo12:svcr_out]
263-
1:
264262

265263
// Save ZA if it's enabled - uses x12 as scratch due to SME STR
266-
tbz x2, #SVCR_ZA_SHIFT, 1f
264+
tbz x2, #SVCR_ZA_SHIFT, check_sve_out
267265
mov w12, #0
268266
ldr x2, =za_out
269-
2: _str_za 12, 2
267+
1: _str_za 12, 2
270268
add x2, x2, x1
271269
add x12, x12, #1
272270
cmp x1, x12
273-
bne 2b
271+
bne 1b
274272

275273
// ZT0
276274
mrs x2, S3_0_C0_C4_5 // ID_AA64SMFR0_EL1
277275
ubfx x2, x2, #ID_AA64SMFR0_EL1_SMEver_SHIFT, \
278276
#ID_AA64SMFR0_EL1_SMEver_WIDTH
279-
cbz x2, 1f
277+
cbz x2, check_sve_out
280278
adrp x2, zt_out
281279
add x2, x2, :lo12:zt_out
282280
_str_zt 2
283-
1:
284281

282+
check_sve_out:
285283
// Save the SVE state if we have some
286284
cbz x0, 1f
287285

0 commit comments

Comments
 (0)