From: Will Deacon <will@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org, broonie@kernel.org,
catalin.marinas@arm.com, daniel.kiss@arm.com,
david.spickett@arm.com, luis.machado@arm.com, maz@kernel.org,
richard.sandiford@arm.com, sander.desmalen@arm.com,
tabba@google.com, tamas.petz@arm.com, tkjos@google.com,
yury.khrustalev@arm.com
Subject: Re: [PATCH 04/20] arm64/fpsimd: signal: Mandate SVE payload for streaming-mode state
Date: Wed, 7 May 2025 13:59:16 +0100 [thread overview]
Message-ID: <20250507125915.GB2227@willie-the-truck> (raw)
In-Reply-To: <20250506152523.1107431-5-mark.rutland@arm.com>
On Tue, May 06, 2025 at 04:25:07PM +0100, Mark Rutland wrote:
> 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: 85ed24dad290 ("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>
> ---
> arch/arm64/kernel/signal.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
> index fdce1b856f498..e898948a31b65 100644
> --- a/arch/arm64/kernel/signal.c
> +++ b/arch/arm64/kernel/signal.c
> @@ -387,6 +387,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
> unsigned int vl, vq;
> struct user_fpsimd_state fpsimd;
> u16 user_vl, flags;
> + bool sm;
>
> if (user->sve_size < sizeof(*user->sve))
> return -EINVAL;
> @@ -396,7 +397,8 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
> if (err)
> return err;
>
> - if (flags & SVE_SIG_FLAG_SM) {
> + sm = flags & SVE_SIG_FLAG_SM;
> + if (sm) {
> if (!system_supports_sme())
> return -EINVAL;
>
> @@ -416,7 +418,16 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
> if (user_vl != vl)
> return -EINVAL;
>
> - if (user->sve_size == sizeof(*user->sve)) {
> + /*
> + * 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. For
> + * consistency and robustness, reject restoring streaming SVE state
> + * without an SVE payload.
> + */
> + if (!sm && user->sve_size == sizeof(*user->sve)) {
> clear_thread_flag(TIF_SVE);
> current->thread.svcr &= ~SVCR_SM_MASK;
> current->thread.fp_type = FP_STATE_FPSIMD;
This (along with the 'fpsimd_only:' block) is now practically identical
to restore_fpsimd_context(). I think that's a sign that we're doing the
right thing, but can we move that into a shared helper function?
Will
next prev parent reply other threads:[~2025-05-07 13:01 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 15:25 [PATCH 00/20] arm64: FPSIMD/SVE/SME fixes + re-eanble SME Mark Rutland
2025-05-06 15:25 ` [PATCH 01/20] kselftest/arm64: fp-ptrace: Fix expected FPMR value when PSTATE.SM is changed Mark Rutland
2025-05-06 15:25 ` [PATCH 02/20] arm64/fpsimd: Do not discard modified SVE state Mark Rutland
2025-05-06 15:25 ` [PATCH 03/20] arm64/fpsimd: signal: Clear PSTATE.SM when restoring FPSIMD frame only Mark Rutland
2025-05-07 12:46 ` Will Deacon
2025-05-07 14:01 ` Mark Rutland
2025-05-07 14:39 ` Will Deacon
2025-05-06 15:25 ` [PATCH 04/20] arm64/fpsimd: signal: Mandate SVE payload for streaming-mode state Mark Rutland
2025-05-07 0:59 ` Mark Brown
2025-05-07 12:59 ` Will Deacon [this message]
2025-05-07 14:21 ` Mark Rutland
2025-05-07 14:29 ` Will Deacon
2025-05-07 15:02 ` Mark Rutland
2025-05-07 16:14 ` Will Deacon
2025-05-06 15:25 ` [PATCH 05/20] arm64/fpsimd: ptrace: Consistently handle partial writes to NT_ARM_(S)SVE Mark Rutland
2025-05-06 15:25 ` [PATCH 06/20] arm64/fpsimd: Clarify sve_sync_*() functions Mark Rutland
2025-05-06 15:25 ` [PATCH 07/20] arm64/fpsimd: Factor out {sve,sme}_state_size() helpers Mark Rutland
2025-05-06 15:25 ` [PATCH 08/20] arm64/fpsimd: Add task_smstop_sm() Mark Rutland
2025-05-06 15:25 ` [PATCH 09/20] arm64/fpsimd: signal: Use SMSTOP behaviour in setup_return() Mark Rutland
2025-05-06 15:25 ` [PATCH 10/20] arm64/fpsimd: Remove redundant task->mm check Mark Rutland
2025-05-06 15:25 ` [PATCH 11/20] arm64/fpsimd: Consistently preserve FPSIMD state during clone() Mark Rutland
2025-05-06 15:25 ` [PATCH 12/20] arm64/fpsimd: Clear PSTATE.SM " Mark Rutland
2025-05-06 15:25 ` [PATCH 13/20] arm64/fpsimd: Make clone() compatible with ZA lazy saving Mark Rutland
2025-05-07 14:58 ` Will Deacon
2025-05-07 15:22 ` Mark Rutland
2025-05-07 16:11 ` Will Deacon
2025-05-07 17:21 ` Mark Rutland
2025-05-07 15:57 ` Yury Khrustalev
2025-05-06 15:25 ` [PATCH 14/20] arm64/fpsimd: ptrace/prctl: Ensure VL changes do not resurrect stale data Mark Rutland
2025-05-06 15:25 ` [PATCH 15/20] arm64/fpsimd: ptrace/prctl: Ensure VL changes leave task in a valid state Mark Rutland
2025-05-07 16:12 ` Will Deacon
2025-05-07 17:10 ` Mark Rutland
2025-05-08 10:31 ` Will Deacon
2025-05-06 15:25 ` [PATCH 16/20] arm64/fpsimd: ptrace: Save task state before generating SVE header Mark Rutland
2025-05-06 15:25 ` [PATCH 17/20] arm64/fpsimd: ptrace: Do not present register data for inactive mode Mark Rutland
2025-05-06 15:25 ` [PATCH 18/20] arm64/fpsimd: ptrace: Mandate SVE payload for streaming-mode state Mark Rutland
2025-05-07 1:09 ` Mark Brown
2025-05-06 15:25 ` [PATCH 19/20] arm64/fpsimd: ptrace: Gracefully handle errors Mark Rutland
2025-05-07 16:32 ` Will Deacon
2025-05-08 12:12 ` Mark Rutland
2025-05-06 15:25 ` [PATCH 20/20] arm64/fpsimd: Allow CONFIG_ARM64_SME to be selected Mark Rutland
2025-05-07 1:48 ` [PATCH 00/20] arm64: FPSIMD/SVE/SME fixes + re-eanble SME Mark Brown
2025-05-07 9:56 ` Mark Rutland
2025-05-07 11:26 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250507125915.GB2227@willie-the-truck \
--to=will@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel.kiss@arm.com \
--cc=david.spickett@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=luis.machado@arm.com \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=richard.sandiford@arm.com \
--cc=sander.desmalen@arm.com \
--cc=tabba@google.com \
--cc=tamas.petz@arm.com \
--cc=tkjos@google.com \
--cc=yury.khrustalev@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox