FAILED: patch "[PATCH] arm64/ptrace: Ensure that SME is set up for target when" failed to apply to 6.1-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 5d0a8d2fba50e9c07cde4aad7fba28c008b07a5b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023082121-chewing-regroup-4f67@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^..
Possible dependencies:
5d0a8d2fba50 ("arm64/ptrace: Ensure that SME is set up for target when writing SSVE state") f90b529bcbe5 ("arm64/sme: Implement ZT0 ptrace support")ce514000da4f ("arm64/sme: Rename za_state to sme_state")1192b93ba352 ("arm64/fp: Use a struct to pass data to fpsimd_bind_state_to_cpu()") deeb8f9a80fd ("arm64/fpsimd: Have KVM explicitly say which FP registers to save") baa8515281b3 ("arm64/fpsimd: Track the saved FPSIMD state type separately to TIF_SVE") 93ae6b01bafe ("KVM: arm64: Discard any SVE state when entering KVM guests")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 5d0a8d2fba50e9c07cde4aad7fba28c008b07a5b Mon Sep 17 00:00:00 2001
From: Mark Brown <[email protected]>
Date: Thu, 10 Aug 2023 12:28:19 +0100
Subject: [PATCH] arm64/ptrace: Ensure that SME is set up for target when
writing SSVE state
When we use NT_ARM_SSVE to either enable streaming mode or change the vector length for a process we do not currently do anything to ensure that there is storage allocated for the SME specific register state. If the task had not previously used SME or we changed the vector length then the task will not have had TIF_SME set or backing storage for ZA/ZT allocated, resulting in inconsistent register sizes when saving state and spurious traps which flush the newly set register state.
We should set TIF_SME to disable traps and ensure that storage is allocated for ZA and ZT if it is not already allocated. This requires modifying sme_alloc() to make the flush of any existing register state optional so we don't disturb existing state for ZA and ZT.
arch/arm64/include/asm/fpsimd.h +2 -2
@@ -356,7 +356,7 @@ static inline int sme_max_virtualisable_vl(void)return vec_max_virtualisable_vl (ARM64_VEC_SME ); } -extern void sme_alloc (struct task_struct *task); +extern void sme_alloc (struct task_struct *task,bool flush);extern unsigned int sme_get_vl (void );extern int sme_set_current_vl (unsigned long arg);extern int sme_get_current_vl (void );
@@ -388,7 +388,7 @@ static inline void sme_smstart_sm(void) { }static inline void sme_smstop_sm (void ) { }static inline void sme_smstop (void ) { } -static inline void sme_alloc (struct task_struct *task) { } +static inline void sme_alloc (struct task_struct *task,bool flush) { }static inline void sme_setup (void ) { }static inline unsigned int sme_get_vl (void ) {return 0 ; }static inline int sme_max_vl (void ) {return 0 ; }
arch/arm64/kernel/fpsimd.c +3 -3
@@ -1285,9 +1285,9 @@ void fpsimd_release_task(struct task_struct *dead_task)* the interest of testability and predictability, the architecture * guarantees that when ZA is enabled it will be zeroed. */ -void sme_alloc (struct task_struct *task) +void sme_alloc (struct task_struct *task,bool flush) { -if (task->thread.sme_state) { +if (task->thread.sme_state && flush) {memset (task->thread.sme_state,0 ,sme_state_size (task));return ; }
@@ -1515,7 +1515,7 @@ void do_sme_acc(unsigned long esr, struct pt_regs *regs) }sve_alloc (current, false); -sme_alloc (current); +sme_alloc (current, true);if (!current->thread.sve_state || !current->thread.sme_state) {force_sig (SIGKILL );return ;
arch/arm64/kernel/ptrace.c +9 -2
@@ -881,6 +881,13 @@ static int sve_set_common(struct task_struct *target,break ;case ARM64_VEC_SME : target->thread.svcr |=SVCR_SM_MASK ; + +/* +* Disable traps and ensure there is SME storage but +* preserve any currently set values in ZA/ZT. +*/ +sme_alloc (target, false); +set_tsk_thread_flag (target,TIF_SME );break ;default :WARN_ON_ONCE (1 );
@@ -1100,7 +1107,7 @@ static int za_set(struct task_struct *target, }/* Allocate/reinit ZA storage */ -sme_alloc (target); +sme_alloc (target, true);if (!target->thread.sme_state) { ret = -ENOMEM ; goto out;
@@ -1171,7 +1178,7 @@ static int zt_set(struct task_struct *target,return -EINVAL ;if (!thread_za_enabled (&target->thread)) { -sme_alloc (target); +sme_alloc (target, true);if (!target->thread.sme_state)return -ENOMEM ; }
arch/arm64/kernel/signal.c +1 -1
@@ -475,7 +475,7 @@ static int restore_za_context(struct user_ctxs *user)fpsimd_flush_task_state (current);/* From now, fpsimd_thread_switch() won't touch thread.sve_state */ -sme_alloc (current); +sme_alloc (current, true);if (!current->thread.sme_state) { current->thread.svcr &= ~SVCR_ZA_MASK ;clear_thread_flag (TIF_SME );
PATCH 1/1 arm64/ptrace: Ensure that SME is set up for target when writing SSVE state
When we use NT_ARM_SSVE to either enable streaming mode or change the vector length for a process we do not currently do anything to ensure that there is storage allocated for the SME specific register state. If the task had not previously used SME or we changed the vector length then the task will not have had TIF_SME set or backing storage for ZA/ZT allocated, resulting in inconsistent register sizes when saving state and spurious traps which flush the newly set register state.
We should set TIF_SME to disable traps and ensure that storage is allocated for ZA and ZT if it is not already allocated. This requires modifying sme_alloc() to make the flush of any existing register state optional so we don't disturb existing state for ZA and ZT.
--- arch/arm64/include/asm/fpsimd.h | 4 ++-- arch/arm64/kernel/fpsimd.c | 6 +++--- arch/arm64/kernel/ptrace.c | 9 ++++++++- arch/arm64/kernel/signal.c | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-)
arch/arm64/include/asm/fpsimd.h +2 -2
@@ -339,7 +339,7 @@ static inline int sme_max_virtualisable_vl(void)return vec_max_virtualisable_vl (ARM64_VEC_SME ); } -extern void sme_alloc (struct task_struct *task); +extern void sme_alloc (struct task_struct *task,bool flush);extern unsigned int sme_get_vl (void );extern int sme_set_current_vl (unsigned long arg);extern int sme_get_current_vl (void );
@@ -365,7 +365,7 @@ static inline void sme_smstart_sm(void) { }static inline void sme_smstop_sm (void ) { }static inline void sme_smstop (void ) { } -static inline void sme_alloc (struct task_struct *task) { } +static inline void sme_alloc (struct task_struct *task,bool flush) { }static inline void sme_setup (void ) { }static inline unsigned int sme_get_vl (void ) {return 0 ; }static inline int sme_max_vl (void ) {return 0 ; }
arch/arm64/kernel/fpsimd.c +3 -3
@@ -1239,9 +1239,9 @@ void fpsimd_release_task(struct task_struct *dead_task)* the interest of testability and predictability, the architecture * guarantees that when ZA is enabled it will be zeroed. */ -void sme_alloc (struct task_struct *task) +void sme_alloc (struct task_struct *task,bool flush) { -if (task->thread.za_state) { +if (task->thread.za_state && flush) {memset (task->thread.za_state,0 ,za_state_size (task));return ; }
@@ -1460,7 +1460,7 @@ void do_sme_acc(unsigned long esr, struct pt_regs *regs) }sve_alloc (current, false); -sme_alloc (current); +sme_alloc (current, true);if (!current->thread.sve_state || !current->thread.za_state) {force_sig (SIGKILL );return ;
arch/arm64/kernel/ptrace.c +8 -1
@@ -886,6 +886,13 @@ static int sve_set_common(struct task_struct *target,break ;case ARM64_VEC_SME : target->thread.svcr |=SVCR_SM_MASK ; + +/* +* Disable traps and ensure there is SME storage but +* preserve any currently set values in ZA/ZT. +*/ +sme_alloc (target, false); +set_tsk_thread_flag (target,TIF_SME );break ;default :WARN_ON_ONCE (1 );
@@ -1107,7 +1114,7 @@ static int za_set(struct task_struct *target, }/* Allocate/reinit ZA storage */ -sme_alloc (target); +sme_alloc (target, true);if (!target->thread.za_state) { ret = -ENOMEM ; goto out;
arch/arm64/kernel/signal.c +1 -1
@@ -430,7 +430,7 @@ static int restore_za_context(struct user_ctxs *user)fpsimd_flush_task_state (current);/* From now, fpsimd_thread_switch() won't touch thread.sve_state */ -sme_alloc (current); +sme_alloc (current, true);if (!current->thread.za_state) { current->thread.svcr &= ~SVCR_ZA_MASK ;clear_thread_flag (TIF_SME );
Signature · 1 line
2.30.2
Greg KH
maintainerRe: [PATCH 6.1.y] arm64/ptrace: Ensure that SME is set up for target when writing SSVE state
Quoted 13 lines · Mark Brown
When we use
NT_ARM_SSVEto either enable streaming mode or change the vector length for a process we do not currently do anything to ensure that there is storage allocated for the SME specific register state. If the task had not previously used SME or we changed the vector length then the task will not have hadTIF_SMEset or backing storage for ZA/ZT allocated, resulting in inconsistent register sizes when saving state and spurious traps which flush the newly set register state.We should set
TIF_SMEto disable traps and ensure that storage is allocated for ZA and ZT if it is not already allocated. This requires modifyingsme_alloc()to make the flush of any existing register state optional so we don't disturb existing state for ZA and ZT.
Quoted 8 lines
Fixes e12310a0d30f ("arm64/sme: Implement ptrace support for streaming mode SVE registers")Reported-by David Spickett <[email protected]>Signed-off-by Mark Brown <[email protected]>Cc <[email protected]> # 5.19.xSigned-off-by Catalin Marinas <[email protected]>(cherry picked from commit 5d0a8d2fba50e9c07cde4aad7fba28c008b07a5b)Signed-off-by Mark Brown <[email protected]>
Thanks, now queued up.
greg k-h