Skip to contentSkip to conversation

kselftest/arm64: abi: fix SVCR detection

PATCH Superseded Weizhao Ouyang 2 participants 7 messages Dec 9, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 43e3f85523e4 ("kselftest/arm64: Add SME support to syscall ABI test")
---
 tools/testing/selftests/arm64/abi/syscall-abi-asm.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/arm64/abi/syscall-abi-asm.S +1 -1
index df3230fdac39..98cde4f37abf 100644
@@ -81,9 +81,9 @@ do_syscall:
 	stp	x27, x28, [sp, #96]
 
 	// Set SVCR if we're doing SME
-	cbz	x1, 1f
 	adrp	x2, svcr_in
 	ldr	x2, [x2, :lo12:svcr_in]
+	cbz	x1, 1f
 	msr	S3_3_C4_C2_2, x2
 1:
 
Signature · 1 line
2.45.2
#1 lore raw

tools/testing/selftests/arm64/abi/syscall-abi-asm.S do_syscall: · line 87

Quoted 10 lines · Weizhao Ouyang

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.

tools/testing/selftests/arm64/abi/syscall-abi-asm.S +1 -1
 	// Set SVCR if we're doing SME
-	cbz	x1, 1f
 	adrp	x2, svcr_in
 	ldr	x2, [x2, :lo12:svcr_in]
+	cbz	x1, 1f
 	msr	S3_3_C4_C2_2, x2

This is against an older verison of the code so wouldn't apply now. It's not also checking the value of SVCR, this is checking the SME flag passed in via x1. You can see that the SVCR value is loaded into x2 but the check is against x1.

#2 lore raw
Quoted 14 lines · Mark Brown

tools/testing/selftests/arm64/abi/syscall-abi-asm.S do_syscall: · line 87

Quoted 10 lines · Weizhao Ouyang

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.

      // Set SVCR if we're doing SME
tools/testing/selftests/arm64/abi/syscall-abi-asm.S +1 -1
-     cbz     x1, 1f
      adrp    x2, svcr_in
      ldr     x2, [x2, :lo12:svcr_in]
+     cbz     x1, 1f
      msr     S3_3_C4_C2_2, x2
Quoted 4 lines

This is against an older verison of the code so wouldn't apply now. It's not also checking the value of SVCR, this is checking the SME flag passed in via x1. You can see that the SVCR value is loaded into x2 but the check is against x1.

Hi Mark,

This patch aims to fix the second check (SVCR_ZA_SHIFT) instead of the first one (the x1 SME flag you're referring to):

// Load ZA and ZT0 if enabled - uses x12 as scratch due to SME LDR tbz x2, #SVCR_ZA_SHIFT, 1f
mov w12, #0
ldr x2, =za_in
2: _ldr_za 12, 2

If SME disabled, x2 will not have an expected value.

BR,
Weizhao

#3 lore raw
Quoted 9 lines · Weizhao Ouyang
Quoted 6 lines · Mark Brown
Quoted 6 lines
      // Set SVCR if we're doing SME
tools/testing/selftests/arm64/abi/syscall-abi-asm.S +1 -1
-     cbz     x1, 1f
      adrp    x2, svcr_in
      ldr     x2, [x2, :lo12:svcr_in]
+     cbz     x1, 1f
      msr     S3_3_C4_C2_2, x2
Quoted 6 lines
Quoted 3 lines

This is against an older verison of the code so wouldn't apply now. It's not also checking the value of SVCR, this is checking the SME flag the check is against x1.

This patch aims to fix the second check (SVCR_ZA_SHIFT) instead of the first one (the x1 SME flag you're referring to):

If we don't have SME we should be skipping over all the SME code and never even looking at the value of SVCR. Looking at the current version of the code it does that, it branches to check_sve_in if SME is not enabled.

#4 lore raw
Quoted 15 lines · Mark Brown
Quoted 12 lines · Weizhao Ouyang
Quoted 10 lines · Mark Brown

tools/testing/selftests/arm64/abi/syscall-abi-asm.S do_syscall: · line 87

Quoted 6 lines
      // Set SVCR if we're doing SME
tools/testing/selftests/arm64/abi/syscall-abi-asm.S +1 -1
-     cbz     x1, 1f
      adrp    x2, svcr_in
      ldr     x2, [x2, :lo12:svcr_in]
+     cbz     x1, 1f
      msr     S3_3_C4_C2_2, x2

This is against an older verison of the code so wouldn't apply now. It's not also checking the value of SVCR, this is checking the SME flag the check is against x1.

Quoted 7 lines
Quoted 2 lines

This patch aims to fix the second check (SVCR_ZA_SHIFT) instead of the first one (the x1 SME flag you're referring to):

If we don't have SME we should be skipping over all the SME code and never even looking at the value of SVCR. Looking at the current version of the code it does that, it branches to check_sve_in if SME is not enabled.

Hi Mark,

Yes we should skip it, this is just a minor tweak based on the current implementation, after all, we manually passed its value by svcr_in.

Which latest code version are you referring to? I think check_sve_in is in fp testcase, not in the abi testcase. (checked the -next tree)

BR,
Weizhao

#5 lore raw
Quoted 8 lines · Weizhao Ouyang
Quoted 4 lines

If we don't have SME we should be skipping over all the SME code and never even looking at the value of SVCR. Looking at the current version of the code it does that, it branches to check_sve_in if SME is not enabled.

Yes we should skip it, this is just a minor tweak based on the current implementation, after all, we manually passed its value by svcr_in.

It's a fairly trivial tweak to make... in any case, it looks like we also need the same change in the save path.

Quoted 2 lines

Which latest code version are you referring to? I think check_sve_in is in fp testcase, not in the abi testcase. (checked the -next tree)

Ah, yes sorry.

#6 lore raw
Quoted 8 lines · Mark Brown
Quoted 4 lines · Weizhao Ouyang
Quoted 4 lines

If we don't have SME we should be skipping over all the SME code and never even looking at the value of SVCR. Looking at the current version of the code it does that, it branches to check_sve_in if SME is not enabled.

Quoted 6 lines
Quoted 3 lines

Yes we should skip it, this is just a minor tweak based on the current implementation, after all, we manually passed its value by svcr_in.

It's a fairly trivial tweak to make... in any case, it looks like we also need the same change in the save path.

Yeah. I have encountered this issue with both QEMU and FVP. I can help to add a check_sve_in similar to the fp testcase for the abi testcase.

BR,
Weizhao

Quoted 5 lines
Quoted 3 lines

Which latest code version are you referring to? I think check_sve_in is in fp testcase, not in the abi testcase. (checked the -next tree)

Ah, yes sorry.