From: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: broonie@kernel.org, catalin.marinas@arm.com, daniel.kiss@arm.com,
david.spickett@arm.com, luis.machado@arm.com,
mark.rutland@arm.com, maz@kernel.org, richard.sandiford@arm.com,
sander.desmalen@arm.com, tabba@google.com, tamas.petz@arm.com,
tkjos@google.com, will@kernel.org, yury.khrustalev@arm.com
Subject: [PATCH v2 08/24] arm64/fpsimd: Add task_smstop_sm()
Date: Thu, 8 May 2025 14:26:28 +0100 [thread overview]
Message-ID: <20250508132644.1395904-9-mark.rutland@arm.com> (raw)
In-Reply-To: <20250508132644.1395904-1-mark.rutland@arm.com>
In a few places we want to transition a task from streaming mode to
non-streaming mode, e.g. signal delivery where we historically tried to
use an SMSTOP SM instruction.
Add a new helper to manipulate a task's state in the same way as an
SMSTOP SM instruction. I have not added a corresponding helper to
simulate the effects of SMSTART SM. Only ptrace transitions a task into
streaming mode, and ptrace has distinct semantics for such transitions.
Per ARM DDI 0487 L.a, section B1.4.6:
| RRSWFQ
| When the Effective value of PSTATE.SM is changed by any method from 0
| to 1, an entry to Streaming SVE mode is performed, and all implemented
| bits of Streaming SVE register state are set to zero.
| RKFRQZ
| When the Effective value of PSTATE.SM is changed by any method from 1
| to 0, an exit from Streaming SVE mode is performed, and in the
| newly-entered mode, all implemented bits of the SVE scalable vector
| registers, SVE predicate registers, and FFR, are set to zero.
Per ARM DDI 0487 L.a, section C5.2.9:
| On entry to or exit from Streaming SVE mode, FPMR is set to 0
Per ARM DDI 0487 L.a, section C5.2.10:
| On entry to or exit from Streaming SVE mode, FPSR.{IOC, DZC, OFC, UFC,
| IXC, IDC, QC} are set to 1 and the remaining bits are set to 0.
This means bits 0, 1, 2, 3, 4, 7, and 27 respectively, i.e. 0x0800009f
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/include/asm/fpsimd.h | 2 ++
arch/arm64/kernel/fpsimd.c | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h
index b751064bbaaa1..b8cf0ea43cc05 100644
--- a/arch/arm64/include/asm/fpsimd.h
+++ b/arch/arm64/include/asm/fpsimd.h
@@ -111,6 +111,8 @@ static inline bool thread_za_enabled(struct thread_struct *thread)
return system_supports_sme() && (thread->svcr & SVCR_ZA_MASK);
}
+extern void task_smstop_sm(struct task_struct *task);
+
/* Maximum VL that SVE/SME VL-agnostic software can transparently support */
#define VL_ARCH_MAX 0x100
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index c2603fe8dd243..fe96e018e18c0 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -695,6 +695,28 @@ static inline void sve_to_fpsimd(struct task_struct *task)
}
}
+static inline void __fpsimd_zero_vregs(struct user_fpsimd_state *fpsimd)
+{
+ memset(&fpsimd->vregs, 0, sizeof(fpsimd->vregs));
+}
+
+/*
+ * Simulate the effects of an SMSTOP SM instruction.
+ */
+void task_smstop_sm(struct task_struct *task)
+{
+ if (!thread_sm_enabled(&task->thread))
+ return;
+
+ __fpsimd_zero_vregs(&task->thread.uw.fpsimd_state);
+ task->thread.uw.fpsimd_state.fpsr = 0x0800009f;
+ if (system_supports_fpmr())
+ task->thread.uw.fpmr = 0;
+
+ task->thread.svcr &= ~SVCR_SM_MASK;
+ task->thread.fp_type = FP_STATE_FPSIMD;
+}
+
void cpu_enable_fpmr(const struct arm64_cpu_capabilities *__always_unused p)
{
write_sysreg_s(read_sysreg_s(SYS_SCTLR_EL1) | SCTLR_EL1_EnFPM_MASK,
--
2.30.2
next prev parent reply other threads:[~2025-05-08 13:47 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-08 13:26 [PATCH v2 00/24] arm64: FPSIMD/SVE/SME fixes + re-enable SME Mark Rutland
2025-05-08 13:26 ` [PATCH v2 01/24] arm64/fpsimd: Do not discard modified SVE state Mark Rutland
2025-05-08 15:02 ` Will Deacon
2025-05-08 13:26 ` [PATCH v2 02/24] arm64/fpsimd: signal: Clear PSTATE.SM when restoring FPSIMD frame only Mark Rutland
2025-05-08 13:26 ` [PATCH v2 03/24] arm64/fpsimd: signal: Mandate SVE payload for streaming-mode state Mark Rutland
2025-05-08 13:26 ` [PATCH v2 04/24] arm64/fpsimd: signal: Consistently read FPSIMD context Mark Rutland
2025-05-08 14:34 ` Will Deacon
2025-05-08 13:26 ` [PATCH v2 05/24] arm64/fpsimd: ptrace: Consistently handle partial writes to NT_ARM_(S)SVE Mark Rutland
2025-05-08 13:26 ` [PATCH v2 06/24] arm64/fpsimd: Clarify sve_sync_*() functions Mark Rutland
2025-05-08 13:26 ` [PATCH v2 07/24] arm64/fpsimd: Factor out {sve,sme}_state_size() helpers Mark Rutland
2025-05-08 13:26 ` Mark Rutland [this message]
2025-05-08 13:26 ` [PATCH v2 09/24] arm64/fpsimd: signal: Use SMSTOP behaviour in setup_return() Mark Rutland
2025-05-08 13:26 ` [PATCH v2 10/24] arm64/fpsimd: Remove redundant task->mm check Mark Rutland
2025-05-08 13:26 ` [PATCH v2 11/24] arm64/fpsimd: Consistently preserve FPSIMD state during clone() Mark Rutland
2025-05-08 13:26 ` [PATCH v2 12/24] arm64/fpsimd: Clear PSTATE.SM " Mark Rutland
2025-05-08 13:26 ` [PATCH v2 13/24] arm64/fpsimd: Make clone() compatible with ZA lazy saving Mark Rutland
2025-05-08 13:26 ` [PATCH v2 14/24] arm64/fpsimd: ptrace/prctl: Ensure VL changes do not resurrect stale data Mark Rutland
2025-05-08 13:26 ` [PATCH v2 15/24] arm64/fpsimd: ptrace/prctl: Ensure VL changes leave task in a valid state Mark Rutland
2025-05-08 13:26 ` [PATCH v2 16/24] arm64/fpsimd: ptrace: Save task state before generating SVE header Mark Rutland
2025-05-08 13:26 ` [PATCH v2 17/24] arm64/fpsimd: ptrace: Do not present register data for inactive mode Mark Rutland
2025-05-08 13:26 ` [PATCH v2 18/24] arm64/fpsimd: ptrace: Mandate SVE payload for streaming-mode state Mark Rutland
2025-05-08 13:26 ` [PATCH v2 19/24] arm64/fpsimd: ptrace: Gracefully handle errors Mark Rutland
2025-05-08 13:26 ` [PATCH v2 20/24] arm64/fpsimd: Allow CONFIG_ARM64_SME to be selected Mark Rutland
2025-05-08 13:26 ` [PATCH v2 21/24] kselftest/arm64: fp-ptrace: Fix expected FPMR value when PSTATE.SM is changed Mark Rutland
2025-05-08 13:26 ` [PATCH v2 22/24] kselftest/arm64: tpidr2: Adjust to new clone() behaviour Mark Rutland
2025-05-08 13:26 ` [PATCH v2 23/24] kselftest/arm64: fp-ptrace: Adjust to new VL change behaviour Mark Rutland
2025-05-08 13:26 ` [PATCH v2 24/24] kselftest/arm64: fp-ptrace: Adjust to new inactive mode behaviour Mark Rutland
2025-05-08 15:02 ` [PATCH v2 00/24] arm64: FPSIMD/SVE/SME fixes + re-enable SME Will Deacon
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=20250508132644.1395904-9-mark.rutland@arm.com \
--to=mark.rutland@arm.com \
--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=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=will@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).