Skip to content

Commit b465ace

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64/fpsimd: signal: Mandate SVE payload for streaming-mode state
Non-streaming SVE state may be preserved without an SVE payload, in which case the SVE context only has a header with VL==0, and all state can be restored from the FPSIMD context. Streaming SVE state is always preserved with an SVE payload, where the SVE context header has VL!=0, and the SVE_SIG_FLAG_SM flag is set. The kernel never preserves an SVE context where SVE_SIG_FLAG_SM is set without an SVE payload. However, restore_sve_fpsimd_context() doesn't forbid restoring such a context, and will handle this case by clearing PSTATE.SM and restoring the FPSIMD context into non-streaming mode, which isn't consistent with the SVE_SIG_FLAG_SM flag. Forbid this case, and mandate an SVE payload when the SVE_SIG_FLAG_SM flag is set. This avoids an awkward ABI quirk and reduces the risk that later rework to this code permits configuring a task with PSTATE.SM==1 and fp_type==FP_STATE_FPSIMD. I've marked this as a fix given that we never intended to support this case, and we don't want anyone to start relying upon the old behaviour once we re-enable SME. Fixes: 85ed24d ("arm64/sme: Implement streaming SVE signal handling") Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Will Deacon <will@kernel.org> Reviewed-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20250508132644.1395904-4-mark.rutland@arm.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 1bf663a commit b465ace

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

arch/arm64/kernel/signal.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
387387
unsigned int vl, vq;
388388
struct user_fpsimd_state fpsimd;
389389
u16 user_vl, flags;
390+
bool sm;
390391

391392
if (user->sve_size < sizeof(*user->sve))
392393
return -EINVAL;
@@ -396,7 +397,8 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
396397
if (err)
397398
return err;
398399

399-
if (flags & SVE_SIG_FLAG_SM) {
400+
sm = flags & SVE_SIG_FLAG_SM;
401+
if (sm) {
400402
if (!system_supports_sme())
401403
return -EINVAL;
402404

@@ -416,7 +418,16 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
416418
if (user_vl != vl)
417419
return -EINVAL;
418420

419-
if (user->sve_size == sizeof(*user->sve)) {
421+
/*
422+
* Non-streaming SVE state may be preserved without an SVE payload, in
423+
* which case the SVE context only has a header with VL==0, and all
424+
* state can be restored from the FPSIMD context.
425+
*
426+
* Streaming SVE state is always preserved with an SVE payload. For
427+
* consistency and robustness, reject restoring streaming SVE state
428+
* without an SVE payload.
429+
*/
430+
if (!sm && user->sve_size == sizeof(*user->sve)) {
420431
clear_thread_flag(TIF_SVE);
421432
current->thread.svcr &= ~SVCR_SM_MASK;
422433
current->thread.fp_type = FP_STATE_FPSIMD;

0 commit comments

Comments
 (0)