[PATCH 03/14] arm64/fpsimd: Remove redundant clearing of TIF_SVE
Mark Rutland
mark.rutland at arm.com
Fri Apr 4 10:44:24 PDT 2025
TIF_SVE implies that sve_state has been allocated. Barring specific
transient periods (e.g. during changes to SVE/SME vector lengths), it is
not valid for a task to have TIF_SVE set while sve_state is NULL.
This was not taken into account in commit:
7559b7d7d651d397 ("arm64/sve: Better handle failure to allocate SVE register storage")
As of that commit, sve_set_common() and restore_sve_fpsimd_context()
clear TIF_SVE if sve_alloc() fails to allocate memory. In these cases
TIF_SVE cannot legitimately have been set to begin with, and clearing
TIF_SVE only serves to complicate the code. No other code paths clear
TIF_SVE if sve_alloc() fails to allocate memory.
The unnecessary clearing of TIF_SVE lead to further unnecessary changes
in commit:
baa8515281b30861 ("arm64/fpsimd: Track the saved FPSIMD state type separately to TIF_SVE")
As of that commit, sve_set_common() also sets the task's saved fp_type
to FP_STATE_FPSIMD if sve_alloc() fails to allocate memory. This is
unnecessary as when sve_state is NULL, the saved fp_type can only
legitimately be FP_STATE_FPSIMD. That commit did not update
restore_sve_fpsimd_context() similarly, and so
restore_sve_fpsimd_context() does not alter the task's saved fp_type if
sve_alloc() fails to allocate memory.
Remove the unnecessary and confusing clearing of TIF_SVE, and remove the
similarly unnecessary and confusing update of the saved fp_type.
Signed-off-by: Mark Rutland <mark.rutland at arm.com>
Cc: Catalin Marinas <catalin.marinas at arm.com>
Cc: Marc Zyngier <maz at kernel.org>
Cc: Mark Brown <broonie at kernel.org>
Cc: Will Deacon <will at kernel.org>
---
arch/arm64/kernel/ptrace.c | 2 --
arch/arm64/kernel/signal.c | 4 +---
2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index f79b0d5f71ac9..575ececb8b720 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -969,8 +969,6 @@ static int sve_set_common(struct task_struct *target,
sve_alloc(target, true);
if (!target->thread.sve_state) {
ret = -ENOMEM;
- clear_tsk_thread_flag(target, TIF_SVE);
- target->thread.fp_type = FP_STATE_FPSIMD;
goto out;
}
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 99ea26d400ffe..40c572869325b 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -443,10 +443,8 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
/* From now, fpsimd_thread_switch() won't touch thread.sve_state */
sve_alloc(current, true);
- if (!current->thread.sve_state) {
- clear_thread_flag(TIF_SVE);
+ if (!current->thread.sve_state)
return -ENOMEM;
- }
err = __copy_from_user(current->thread.sve_state,
(char __user const *)user->sve +
--
2.30.2
More information about the linux-arm-kernel
mailing list