From: Ard Biesheuvel Date: Wed, 8 Oct 2025 04:22:05 +0000 (+0200) Subject: arm64/fpu: Enforce task-context only for generic kernel mode FPU X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=103728a7162cb5ed22904e31066904375f1fb71e;p=thirdparty%2Flinux.git arm64/fpu: Enforce task-context only for generic kernel mode FPU The generic kernel mode FPU API, which is used by the AMDGPU driver to perform floating point calculations, is modeled after the most restrictive architecture that supports it. This means it doesn't support preemption, and can only be used from task context. The arm64 implementation is a bit more flexible, but supporting that in the generic API complicates matters slightly, and for no good reason, given that the only user does not need it. So enforce that kernel_fpu_begin() can only be called from task context, and [redundantly] disable preemption. This removes the need for users of this API to provide a kernel mode FP/SIMD state after a future patch that makes that compulsory for preemptible task context. Acked-by: Catalin Marinas Signed-off-by: Ard Biesheuvel --- diff --git a/arch/arm64/include/asm/fpu.h b/arch/arm64/include/asm/fpu.h index 2ae50bdce59b4..bdc4c6304c6a7 100644 --- a/arch/arm64/include/asm/fpu.h +++ b/arch/arm64/include/asm/fpu.h @@ -6,10 +6,22 @@ #ifndef __ASM_FPU_H #define __ASM_FPU_H +#include #include #define kernel_fpu_available() cpu_has_neon() -#define kernel_fpu_begin() kernel_neon_begin() -#define kernel_fpu_end() kernel_neon_end() + +static inline void kernel_fpu_begin(void) +{ + BUG_ON(!in_task()); + preempt_disable(); + kernel_neon_begin(); +} + +static inline void kernel_fpu_end(void) +{ + kernel_neon_end(); + preempt_enable(); +} #endif /* ! __ASM_FPU_H */