]> git.ipfire.org Git - thirdparty/linux.git/commit
arm64/simd: Avoid pointless clearing of FP/SIMD buffer
authorArd Biesheuvel <ardb@kernel.org>
Tue, 9 Dec 2025 05:48:49 +0000 (06:48 +0100)
committerEric Biggers <ebiggers@kernel.org>
Sun, 14 Dec 2025 18:18:22 +0000 (10:18 -0800)
commitc4b502d60a71cf0c0c938f133dc4c0e2adc17b44
tree650f553d3c95445cde45362a0d2e538dd4e4a85a
parent8f0b4cce4481fb22653697cced8d0d04027cb1e8
arm64/simd: Avoid pointless clearing of FP/SIMD buffer

The buffer provided to kernel_neon_begin() is only used if the task is
scheduled out while the FP/SIMD is in use by the kernel, or when such a
section is interrupted by a softirq that also uses the FP/SIMD.

IOW, this happens rarely, and even if it happened often, there is still
no reason for this buffer to be cleared beforehand, which happens
unconditionally, due to the use of a compound literal expression.

So define that buffer variable explicitly, and mark it as
__uninitialized so that it will not get cleared, even when
-ftrivial-auto-var-init is in effect.

This requires some preprocessor gymnastics, due to the fact that the
variable must be defined throughout the entire guarded scope, and the
expression

  ({ struct user_fpsimd_state __uninitialized st; &st; })

is problematic in that regard, even though the compilers seem to
permit it. So instead, repeat the 'for ()' trick that is also used in
the implementation of the guarded scope helpers.

Cc: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Fixes: 4fa617cc6851 ("arm64/fpsimd: Allocate kernel mode FP/SIMD buffers on the stack")
Link: https://lore.kernel.org/r/20251209054848.998878-2-ardb@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
arch/arm64/include/asm/simd.h