[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251003201818.GA24598@quark>
Date: Fri, 3 Oct 2025 13:18:18 -0700
From: Eric Biggers <ebiggers@...nel.org>
To: Ard Biesheuvel <ardb+git@...gle.com>
Cc: linux-arm-kernel@...ts.infradead.org, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org, herbert@...dor.apana.org.au,
linux@...linux.org.uk, Ard Biesheuvel <ardb@...nel.org>,
Marc Zyngier <maz@...nel.org>, Will Deacon <will@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Kees Cook <keescook@...omium.org>,
Catalin Marinas <catalin.marinas@....com>,
Mark Brown <broonie@...nel.org>
Subject: Re: [PATCH v2 20/20] arm64/fpsimd: Allocate kernel mode FP/SIMD
buffers on the stack
On Wed, Oct 01, 2025 at 11:02:22PM +0200, Ard Biesheuvel wrote:
> diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
> index 4f8d677b73ee..93bca4d454d7 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;
Is TIF_KERNEL_FPSTATE redundant with kernel_fpsimd_state != NULL? If
so, should we have both?
> +void kernel_neon_begin(struct user_fpsimd_state *s)
> {
> if (WARN_ON(!system_supports_fpsimd()))
> return;
> @@ -1866,8 +1869,16 @@ void kernel_neon_begin(void)
> * mode in task context. So in this case, setting the flag here
> * is always appropriate.
> */
> - 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.
> + */
> + if (cmpxchg(¤t->thread.kernel_fpsimd_state, NULL, s))
> + BUG();
Does this really need to be a cmpxchg, vs. a regular load and store?
It's just operating on current.
> + else if (test_and_clear_thread_flag(TIF_KERNEL_FPSTATE))
> + if (cmpxchg(¤t->thread.kernel_fpsimd_state, s, NULL) != s)
> + BUG();
Likewise.
- Eric
Powered by blists - more mailing lists