* [PATCH v2 0/4] arm64/sme: SME related fixes
@ 2022-08-15 13:28 Mark Brown
2022-08-15 13:28 ` [PATCH v2 1/4] arm64/signal: Raise limit on stack frames Mark Brown
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Mark Brown @ 2022-08-15 13:28 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, Mark Brown
This series collates together a number of SME related fixes that have
come up in testing.
v2:
- Rebase onto v6.0-rc1.
- Fix allnoconfig build.
Mark Brown (4):
arm64/signal: Raise limit on stack frames
arm64/signal: Flush FPSIMD register state when disabling streaming
mode
arm64/sme: Don't flush SVE register state when allocating SME storage
arm64/sme: Don't flush SVE register state when handling SME traps
arch/arm64/include/asm/fpsimd.h | 4 ++--
arch/arm64/kernel/fpsimd.c | 21 ++++++---------------
arch/arm64/kernel/ptrace.c | 6 +++---
arch/arm64/kernel/signal.c | 14 ++++++++++++--
4 files changed, 23 insertions(+), 22 deletions(-)
base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v2 1/4] arm64/signal: Raise limit on stack frames 2022-08-15 13:28 [PATCH v2 0/4] arm64/sme: SME related fixes Mark Brown @ 2022-08-15 13:28 ` Mark Brown 2022-08-17 14:04 ` Catalin Marinas 2022-08-15 13:28 ` [PATCH v2 2/4] arm64/signal: Flush FPSIMD register state when disabling streaming mode Mark Brown ` (2 subsequent siblings) 3 siblings, 1 reply; 10+ messages in thread From: Mark Brown @ 2022-08-15 13:28 UTC (permalink / raw) To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, Mark Brown The signal code has a limit of 64K on the size of a stack frame that it will generate, if this limit is exceeded then a process will be killed if it receives a signal. Unfortunately with the advent of SME this limit is too small - the maximum possible size of the ZA register alone is 64K. This is not an issue for practical systems at present but is easily seen using virtual platforms. Raise the limit to 256K, this is substantially more than could be used by any current architecture extension. Signed-off-by: Mark Brown <broonie@kernel.org> --- arch/arm64/kernel/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 3e6d0352d7d3..a410c980e50e 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -91,7 +91,7 @@ static size_t sigframe_size(struct rt_sigframe_user_layout const *user) * not taken into account. This limit is not a guarantee and is * NOT ABI. */ -#define SIGFRAME_MAXSZ SZ_64K +#define SIGFRAME_MAXSZ (SZ_64K * 4) static int __sigframe_alloc(struct rt_sigframe_user_layout *user, unsigned long *offset, size_t size, bool extend) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] arm64/signal: Raise limit on stack frames 2022-08-15 13:28 ` [PATCH v2 1/4] arm64/signal: Raise limit on stack frames Mark Brown @ 2022-08-17 14:04 ` Catalin Marinas 2022-08-17 15:24 ` Mark Brown 0 siblings, 1 reply; 10+ messages in thread From: Catalin Marinas @ 2022-08-17 14:04 UTC (permalink / raw) To: Mark Brown; +Cc: Will Deacon, linux-arm-kernel On Mon, Aug 15, 2022 at 02:28:31PM +0100, Mark Brown wrote: > The signal code has a limit of 64K on the size of a stack frame that it > will generate, if this limit is exceeded then a process will be killed if > it receives a signal. Unfortunately with the advent of SME this limit is > too small - the maximum possible size of the ZA register alone is 64K. This > is not an issue for practical systems at present but is easily seen using > virtual platforms. > > Raise the limit to 256K, this is substantially more than could be used by > any current architecture extension. > > Signed-off-by: Mark Brown <broonie@kernel.org> > --- > arch/arm64/kernel/signal.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c > index 3e6d0352d7d3..a410c980e50e 100644 > --- a/arch/arm64/kernel/signal.c > +++ b/arch/arm64/kernel/signal.c > @@ -91,7 +91,7 @@ static size_t sigframe_size(struct rt_sigframe_user_layout const *user) > * not taken into account. This limit is not a guarantee and is > * NOT ABI. > */ > -#define SIGFRAME_MAXSZ SZ_64K > +#define SIGFRAME_MAXSZ (SZ_64K * 4) Why not SZ_256K? Otherwise it looks fine: Acked-by: Catalin Marinas <catalin.marinas@arm.com> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] arm64/signal: Raise limit on stack frames 2022-08-17 14:04 ` Catalin Marinas @ 2022-08-17 15:24 ` Mark Brown 0 siblings, 0 replies; 10+ messages in thread From: Mark Brown @ 2022-08-17 15:24 UTC (permalink / raw) To: Catalin Marinas; +Cc: Will Deacon, linux-arm-kernel [-- Attachment #1.1: Type: text/plain, Size: 371 bytes --] On Wed, Aug 17, 2022 at 03:04:40PM +0100, Catalin Marinas wrote: > On Mon, Aug 15, 2022 at 02:28:31PM +0100, Mark Brown wrote: > > -#define SIGFRAME_MAXSZ SZ_64K > > +#define SIGFRAME_MAXSZ (SZ_64K * 4) > Why not SZ_256K? I think I'd initially picked a different number which didn't have a SZ_ macro then forgot to check if there was one when I dithered back to 256K. [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] [-- Attachment #2: Type: text/plain, Size: 176 bytes --] _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/4] arm64/signal: Flush FPSIMD register state when disabling streaming mode 2022-08-15 13:28 [PATCH v2 0/4] arm64/sme: SME related fixes Mark Brown 2022-08-15 13:28 ` [PATCH v2 1/4] arm64/signal: Raise limit on stack frames Mark Brown @ 2022-08-15 13:28 ` Mark Brown 2022-08-17 14:09 ` Catalin Marinas 2022-08-15 13:28 ` [PATCH v2 3/4] arm64/sme: Don't flush SVE register state when allocating SME storage Mark Brown 2022-08-15 13:28 ` [PATCH v2 4/4] arm64/sme: Don't flush SVE register state when handling SME traps Mark Brown 3 siblings, 1 reply; 10+ messages in thread From: Mark Brown @ 2022-08-15 13:28 UTC (permalink / raw) To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, Mark Brown When handling a signal delivered to a context with streaming mode enabled we will disable streaming mode for the signal handler, when doing so we should also flush the saved FPSIMD register state like exiting streaming mode in the hardware would do so that if that state is reloaded we get the same behaviour. Without this we will reload whatever the last FPSIMD state that was saved for the task was. Fixes: 40a8e87bb3285 ("arm64/sme: Disable ZA and streaming mode when handling signals") Signed-off-by: Mark Brown <broonie@kernel.org> --- arch/arm64/kernel/signal.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index a410c980e50e..0c227f57def5 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -926,6 +926,16 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, /* Signal handlers are invoked with ZA and streaming mode disabled */ if (system_supports_sme()) { + /* + * If we were in streaming mode the saved register + * state was SVE but we will exit SM and use the + * FPSIMD register state - flush the saved FPSIMD + * register state in case it gets loaded. + */ + if (current->thread.svcr & SVCR_SM_MASK) + memset(¤t->thread.uw.fpsimd_state, 0, + sizeof(current->thread.uw.fpsimd_state)); + current->thread.svcr &= ~(SVCR_ZA_MASK | SVCR_SM_MASK); sme_smstop(); -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/4] arm64/signal: Flush FPSIMD register state when disabling streaming mode 2022-08-15 13:28 ` [PATCH v2 2/4] arm64/signal: Flush FPSIMD register state when disabling streaming mode Mark Brown @ 2022-08-17 14:09 ` Catalin Marinas 0 siblings, 0 replies; 10+ messages in thread From: Catalin Marinas @ 2022-08-17 14:09 UTC (permalink / raw) To: Mark Brown; +Cc: Will Deacon, linux-arm-kernel On Mon, Aug 15, 2022 at 02:28:32PM +0100, Mark Brown wrote: > When handling a signal delivered to a context with streaming mode enabled > we will disable streaming mode for the signal handler, when doing so we > should also flush the saved FPSIMD register state like exiting streaming > mode in the hardware would do so that if that state is reloaded we get the > same behaviour. Without this we will reload whatever the last FPSIMD state > that was saved for the task was. > > Fixes: 40a8e87bb3285 ("arm64/sme: Disable ZA and streaming mode when handling signals") > Signed-off-by: Mark Brown <broonie@kernel.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/4] arm64/sme: Don't flush SVE register state when allocating SME storage 2022-08-15 13:28 [PATCH v2 0/4] arm64/sme: SME related fixes Mark Brown 2022-08-15 13:28 ` [PATCH v2 1/4] arm64/signal: Raise limit on stack frames Mark Brown 2022-08-15 13:28 ` [PATCH v2 2/4] arm64/signal: Flush FPSIMD register state when disabling streaming mode Mark Brown @ 2022-08-15 13:28 ` Mark Brown 2022-08-17 14:27 ` Catalin Marinas 2022-08-15 13:28 ` [PATCH v2 4/4] arm64/sme: Don't flush SVE register state when handling SME traps Mark Brown 3 siblings, 1 reply; 10+ messages in thread From: Mark Brown @ 2022-08-15 13:28 UTC (permalink / raw) To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, Mark Brown Currently when taking a SME access trap we allocate storage for the SVE register state in order to be able to handle storage of streaming mode SVE. Due to the original usage in a purely SVE context the SVE register state allocation this also flushes the register state for SVE if storage was already allocated but in the SME context this is not desirable. For a SME access trap to be taken the task must not be in streaming mode so either there already is SVE register state present for regular SVE mode which would be corrupted or the task does not have TIF_SVE and the flush is redundant. Fix this by adding a flag to sve_alloc() indicating if we are in a SVE context and need to flush the state. Freshly allocated storage is always zeroed either way. Fixes: 8bd7f91c03d88 ("arm64/sme: Implement traps and syscall handling for SME") Signed-off-by: Mark Brown <broonie@kernel.org> --- arch/arm64/include/asm/fpsimd.h | 4 ++-- arch/arm64/kernel/fpsimd.c | 10 ++++++---- arch/arm64/kernel/ptrace.c | 6 +++--- arch/arm64/kernel/signal.c | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index 9bb1873f5295..6f86b7ab6c28 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -153,7 +153,7 @@ struct vl_info { #ifdef CONFIG_ARM64_SVE -extern void sve_alloc(struct task_struct *task); +extern void sve_alloc(struct task_struct *task, bool flush); extern void fpsimd_release_task(struct task_struct *task); extern void fpsimd_sync_to_sve(struct task_struct *task); extern void fpsimd_force_sync_to_sve(struct task_struct *task); @@ -256,7 +256,7 @@ size_t sve_state_size(struct task_struct const *task); #else /* ! CONFIG_ARM64_SVE */ -static inline void sve_alloc(struct task_struct *task) { } +static inline void sve_alloc(struct task_struct *task, bool flush) { } static inline void fpsimd_release_task(struct task_struct *task) { } static inline void sve_sync_to_fpsimd(struct task_struct *task) { } static inline void sve_sync_from_fpsimd_zeropad(struct task_struct *task) { } diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index dd63ffc3a2fa..b9ae9827e6e8 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -715,10 +715,12 @@ size_t sve_state_size(struct task_struct const *task) * do_sve_acc() case, there is no ABI requirement to hide stale data * written previously be task. */ -void sve_alloc(struct task_struct *task) +void sve_alloc(struct task_struct *task, bool flush) { if (task->thread.sve_state) { - memset(task->thread.sve_state, 0, sve_state_size(task)); + if (flush) + memset(task->thread.sve_state, 0, + sve_state_size(task)); return; } @@ -1388,7 +1390,7 @@ void do_sve_acc(unsigned long esr, struct pt_regs *regs) return; } - sve_alloc(current); + sve_alloc(current, true); if (!current->thread.sve_state) { force_sig(SIGKILL); return; @@ -1439,7 +1441,7 @@ void do_sme_acc(unsigned long esr, struct pt_regs *regs) return; } - sve_alloc(current); + sve_alloc(current, false); sme_alloc(current); if (!current->thread.sve_state || !current->thread.za_state) { force_sig(SIGKILL); diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 21da83187a60..eb7c08dfb834 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -882,7 +882,7 @@ static int sve_set_common(struct task_struct *target, * state and ensure there's storage. */ if (target->thread.svcr != old_svcr) - sve_alloc(target); + sve_alloc(target, true); } /* Registers: FPSIMD-only case */ @@ -912,7 +912,7 @@ static int sve_set_common(struct task_struct *target, goto out; } - sve_alloc(target); + sve_alloc(target, true); if (!target->thread.sve_state) { ret = -ENOMEM; clear_tsk_thread_flag(target, TIF_SVE); @@ -1082,7 +1082,7 @@ static int za_set(struct task_struct *target, /* Ensure there is some SVE storage for streaming mode */ if (!target->thread.sve_state) { - sve_alloc(target); + sve_alloc(target, false); if (!target->thread.sve_state) { clear_thread_flag(TIF_SME); ret = -ENOMEM; diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 0c227f57def5..f00e8b33170a 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -310,7 +310,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user) fpsimd_flush_task_state(current); /* From now, fpsimd_thread_switch() won't touch thread.sve_state */ - sve_alloc(current); + sve_alloc(current, true); if (!current->thread.sve_state) { clear_thread_flag(TIF_SVE); return -ENOMEM; -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 3/4] arm64/sme: Don't flush SVE register state when allocating SME storage 2022-08-15 13:28 ` [PATCH v2 3/4] arm64/sme: Don't flush SVE register state when allocating SME storage Mark Brown @ 2022-08-17 14:27 ` Catalin Marinas 0 siblings, 0 replies; 10+ messages in thread From: Catalin Marinas @ 2022-08-17 14:27 UTC (permalink / raw) To: Mark Brown; +Cc: Will Deacon, linux-arm-kernel On Mon, Aug 15, 2022 at 02:28:33PM +0100, Mark Brown wrote: > Currently when taking a SME access trap we allocate storage for the SVE > register state in order to be able to handle storage of streaming mode SVE. > Due to the original usage in a purely SVE context the SVE register state > allocation this also flushes the register state for SVE if storage was > already allocated but in the SME context this is not desirable. For a SME > access trap to be taken the task must not be in streaming mode so either > there already is SVE register state present for regular SVE mode which would > be corrupted or the task does not have TIF_SVE and the flush is redundant. > > Fix this by adding a flag to sve_alloc() indicating if we are in a SVE > context and need to flush the state. Freshly allocated storage is always > zeroed either way. > > Fixes: 8bd7f91c03d88 ("arm64/sme: Implement traps and syscall handling for SME") > Signed-off-by: Mark Brown <broonie@kernel.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 4/4] arm64/sme: Don't flush SVE register state when handling SME traps 2022-08-15 13:28 [PATCH v2 0/4] arm64/sme: SME related fixes Mark Brown ` (2 preceding siblings ...) 2022-08-15 13:28 ` [PATCH v2 3/4] arm64/sme: Don't flush SVE register state when allocating SME storage Mark Brown @ 2022-08-15 13:28 ` Mark Brown 2022-08-17 14:28 ` Catalin Marinas 3 siblings, 1 reply; 10+ messages in thread From: Mark Brown @ 2022-08-15 13:28 UTC (permalink / raw) To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, Mark Brown Currently as part of handling a SME access trap we flush the SVE register state. This is not needed and would corrupt register state if the task has access to the SVE registers already. For non-streaming mode accesses the required flushing will be done in the SVE access trap. For streaming mode SVE register accesses the architecture guarantees that the register state will be flushed when streaming mode is entered or exited so there is no need for us to do so. Simply remove the register initialisation. Fixes: 8bd7f91c03d88 ("arm64/sme: Implement traps and syscall handling for SME") Signed-off-by: Mark Brown <broonie@kernel.org> --- arch/arm64/kernel/fpsimd.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index b9ae9827e6e8..23834d96d1e7 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1462,17 +1462,6 @@ void do_sme_acc(unsigned long esr, struct pt_regs *regs) fpsimd_bind_task_to_cpu(); } - /* - * If SVE was not already active initialise the SVE registers, - * any non-shared state between the streaming and regular SVE - * registers is architecturally guaranteed to be zeroed when - * we enter streaming mode. We do not need to initialize ZA - * since ZA must be disabled at this point and enabling ZA is - * architecturally defined to zero ZA. - */ - if (system_supports_sve() && !test_thread_flag(TIF_SVE)) - sve_init_regs(); - put_cpu_fpsimd_context(); } -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 4/4] arm64/sme: Don't flush SVE register state when handling SME traps 2022-08-15 13:28 ` [PATCH v2 4/4] arm64/sme: Don't flush SVE register state when handling SME traps Mark Brown @ 2022-08-17 14:28 ` Catalin Marinas 0 siblings, 0 replies; 10+ messages in thread From: Catalin Marinas @ 2022-08-17 14:28 UTC (permalink / raw) To: Mark Brown; +Cc: Will Deacon, linux-arm-kernel On Mon, Aug 15, 2022 at 02:28:34PM +0100, Mark Brown wrote: > Currently as part of handling a SME access trap we flush the SVE register > state. This is not needed and would corrupt register state if the task has > access to the SVE registers already. For non-streaming mode accesses the > required flushing will be done in the SVE access trap. For streaming > mode SVE register accesses the architecture guarantees that the register > state will be flushed when streaming mode is entered or exited so there is > no need for us to do so. Simply remove the register initialisation. > > Fixes: 8bd7f91c03d88 ("arm64/sme: Implement traps and syscall handling for SME") > Signed-off-by: Mark Brown <broonie@kernel.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-08-17 15:26 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-08-15 13:28 [PATCH v2 0/4] arm64/sme: SME related fixes Mark Brown 2022-08-15 13:28 ` [PATCH v2 1/4] arm64/signal: Raise limit on stack frames Mark Brown 2022-08-17 14:04 ` Catalin Marinas 2022-08-17 15:24 ` Mark Brown 2022-08-15 13:28 ` [PATCH v2 2/4] arm64/signal: Flush FPSIMD register state when disabling streaming mode Mark Brown 2022-08-17 14:09 ` Catalin Marinas 2022-08-15 13:28 ` [PATCH v2 3/4] arm64/sme: Don't flush SVE register state when allocating SME storage Mark Brown 2022-08-17 14:27 ` Catalin Marinas 2022-08-15 13:28 ` [PATCH v2 4/4] arm64/sme: Don't flush SVE register state when handling SME traps Mark Brown 2022-08-17 14:28 ` Catalin Marinas
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).