FROMGIT: arm64/fpsimd: Consistently preserve FPSIMD state during clone()
In arch_dup_task_struct() we try to ensure that the child task inherits the FPSIMD state of its parent, but this depends on the parent task's saved state being in FPSIMD format, which is not always the case. Consequently the child task may inherit stale FPSIMD state in some cases. This can happen when the parent's state has been modified by ptrace since syscall entry, as writes to the NT_ARM_SVE regset may save state in SVE format. This has been possible since commit:bc0ee47603("arm64/sve: Core task context handling") More recently it has been possible for a task's FPSIMD/SVE state to be saved before lazy discarding was guaranteed to occur, in which case preemption could cause the effective FPSIMD state to be saved in SVE format non-deterministically. This has been possible since commit:f130ac0ae4("arm64: syscall: unmask DAIF earlier for SVCs") Fix this by saving the parent task's effective FPSIMD state into FPSIMD format before copying the task_struct. As this requires modifying the parent's fpsimd_state, we must save+flush the state to avoid racing with concurrent manipulation. Similar issues exist when the parent has streaming mode state, and will be addressed by subsequent patches. Fixes:bc0ee47603("arm64/sve: Core task context handling") Fixes:f130ac0ae4("arm64: syscall: unmask DAIF earlier for SVCs") 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> Link: https://lore.kernel.org/r/20250508132644.1395904-12-mark.rutland@arm.com Signed-off-by: Will Deacon <will@kernel.org> (cherry picked from commit e0cb0f26594c644c71ee7f48ebaae6b26bf56a12 https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/sme-fixes) Bug: 393087661 Signed-off-by: Will Deacon <willdeacon@google.com> Change-Id: I8331aa3a2222208d8ce508bc21cd3c65c8be82f8
This commit is contained in:
committed by
Will Deacon
parent
f5db1f9a3b
commit
370e80e212
@@ -299,7 +299,14 @@ void arch_release_task_struct(struct task_struct *tsk)
|
||||
|
||||
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
|
||||
{
|
||||
fpsimd_preserve_current_state();
|
||||
/*
|
||||
* The current/src task's FPSIMD state may or may not be live, and may
|
||||
* have been altered by ptrace after entry to the kernel. Save the
|
||||
* effective FPSIMD state so that this will be copied into dst.
|
||||
*/
|
||||
fpsimd_save_and_flush_current_state();
|
||||
fpsimd_sync_from_effective_state(src);
|
||||
|
||||
*dst = *src;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user