[PATCH v3 21/21] arm64/fpsimd: Allocate kernel mode FP/SIMD buffers on the stack
Eric Biggers
ebiggers at kernel.org
Fri Oct 17 10:12:23 PDT 2025
On Wed, Oct 08, 2025 at 05:45:55PM +0200, Ard Biesheuvel wrote:
> diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
> index 61d62bfd5a7b..226e635c53d9 100644
> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -172,7 +172,7 @@ struct thread_struct {
> unsigned long fault_code; /* ESR_EL1 value */
> struct debug_info debug; /* debugging */
>
> - struct user_fpsimd_state kernel_fpsimd_state;
> + struct user_fpsimd_state *kernel_fpsimd_state;
Perhaps this field deserves a comment?
> @@ -1834,7 +1837,7 @@ void fpsimd_save_and_flush_cpu_state(void)
> * The caller may freely use the FPSIMD registers until kernel_neon_end() is
> * called.
> */
> -void kernel_neon_begin(void)
> +void kernel_neon_begin(struct user_fpsimd_state *state)
Similarly, the 'state' parameter to kernel_neon_begin() and
kernel_neon_end() could use documentation.
> - if (IS_ENABLED(CONFIG_PREEMPT_RT) || !in_serving_softirq())
> + if (IS_ENABLED(CONFIG_PREEMPT_RT) || !in_serving_softirq()) {
> + /*
> + * Record the caller provided buffer as the kernel mode
> + * FP/SIMD buffer for this task, so that the state can
> + * be preserved and restored on a context switch.
> + */
> + WARN_ON(current->thread.kernel_fpsimd_state != NULL);
> + current->thread.kernel_fpsimd_state = state;
> set_thread_flag(TIF_KERNEL_FPSTATE);
> + }
'state' can be NULL here, right? So in that case we do set
TIF_KERNEL_FPSTATE, but we assume context switching cannot happen?
- Eric
More information about the linux-arm-kernel
mailing list