Skip to content

Commit 78b2387

Browse files
mrutland-armwilldeacon
authored andcommitted
kselftest/arm64: fp-ptrace: Fix expected FPMR value when PSTATE.SM is changed
The fp-ptrace test suite expects that FPMR is set to zero when PSTATE.SM is changed via ptrace, but ptrace has never altered FPMR in this way, and the test logic erroneously relies upon (and has concealed) a bug where task_fpsimd_load() would unexpectedly and non-deterministically clobber FPMR. Using ptrace, FPMR can only be altered by writing to the NT_ARM_FPMR regset. The value of PSTATE.SM can be altered by writing to the NT_ARM_SVE or NT_ARM_SSVE regsets, and/or by changing the SME vector length (when writing to the NT_ARM_SVE, NT_ARM_SSVE, or NT_ARM_ZA regsets), but none of these writes will change the value of FPMR. The task_fpsimd_load() bug was introduced with the initial FPMR support in commit: 203f2b9 ("arm64/fpsimd: Support FEAT_FPMR") The incorrect FPMR test code was introduced in commit: 7dbd26d ("kselftest/arm64: Add FPMR coverage to fp-ptrace") Subsequently, the task_fpsimd_load() bug was fixed in commit: e5fa85f ("arm64/fpsimd: Don't corrupt FPMR when streaming mode changes") ... whereupon the fp-ptrace FPMR tests started failing reliably, e.g. | # # Mismatch in saved FPMR: 915058000 != 0 | # not ok 25 SVE write, SVE 64->64, SME 64/0->64/1 Fix this by changing the test to expect that FPMR is *NOT* changed when PSTATE.SM is changed via ptrace, matching the extant behaviour. I've chosen to update the test code rather than modifying ptrace to zero FPMR when PSTATE.SM changes. Not zeroing FPMR is simpler overall, and allows the NT_ARM_FPMR regset to be handled independently from other regsets, leaving less scope for error. Fixes: 7dbd26d ("kselftest/arm64: Add FPMR coverage to fp-ptrace") Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: David Spickett <david.spickett@arm.com> Cc: Luis Machado <luis.machado@arm.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20250508132644.1395904-22-mark.rutland@arm.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 0af2f6b commit 78b2387

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

tools/testing/selftests/arm64/fp/fp-ptrace.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -891,18 +891,11 @@ static void set_initial_values(struct test_config *config)
891891
{
892892
int vq = __sve_vq_from_vl(vl_in(config));
893893
int sme_vq = __sve_vq_from_vl(config->sme_vl_in);
894-
bool sm_change;
895894

896895
svcr_in = config->svcr_in;
897896
svcr_expected = config->svcr_expected;
898897
svcr_out = 0;
899898

900-
if (sme_supported() &&
901-
(svcr_in & SVCR_SM) != (svcr_expected & SVCR_SM))
902-
sm_change = true;
903-
else
904-
sm_change = false;
905-
906899
fill_random(&v_in, sizeof(v_in));
907900
memcpy(v_expected, v_in, sizeof(v_in));
908901
memset(v_out, 0, sizeof(v_out));
@@ -953,12 +946,7 @@ static void set_initial_values(struct test_config *config)
953946
if (fpmr_supported()) {
954947
fill_random(&fpmr_in, sizeof(fpmr_in));
955948
fpmr_in &= FPMR_SAFE_BITS;
956-
957-
/* Entering or exiting streaming mode clears FPMR */
958-
if (sm_change)
959-
fpmr_expected = 0;
960-
else
961-
fpmr_expected = fpmr_in;
949+
fpmr_expected = fpmr_in;
962950
} else {
963951
fpmr_in = 0;
964952
fpmr_expected = 0;

0 commit comments

Comments
 (0)