Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86: implement ARCH_HAS_KERNEL_FPU_SUPPORT

x86 already provides kernel_fpu_begin() and kernel_fpu_end(), but in a
different header. Add a wrapper header, and export the CFLAGS adjustments
as found in lib/Makefile.

Link: https://lkml.kernel.org/r/20240329072441.591471-11-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Samuel Holland and committed by
Andrew Morton
b0b8a15b 01db473e

+34
+1
arch/x86/Kconfig
··· 85 85 select ARCH_HAS_FORTIFY_SOURCE 86 86 select ARCH_HAS_GCOV_PROFILE_ALL 87 87 select ARCH_HAS_KCOV if X86_64 88 + select ARCH_HAS_KERNEL_FPU_SUPPORT 88 89 select ARCH_HAS_MEM_ENCRYPT 89 90 select ARCH_HAS_MEMBARRIER_SYNC_CORE 90 91 select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
+20
arch/x86/Makefile
··· 74 74 KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json 75 75 KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2 76 76 77 + # 78 + # CFLAGS for compiling floating point code inside the kernel. 79 + # 80 + CC_FLAGS_FPU := -msse -msse2 81 + ifdef CONFIG_CC_IS_GCC 82 + # Stack alignment mismatch, proceed with caution. 83 + # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3 84 + # (8B stack alignment). 85 + # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383 86 + # 87 + # The "-msse" in the first argument is there so that the 88 + # -mpreferred-stack-boundary=3 build error: 89 + # 90 + # -mpreferred-stack-boundary=3 is not between 4 and 12 91 + # 92 + # can be triggered. Otherwise gcc doesn't complain. 93 + CC_FLAGS_FPU += -mhard-float 94 + CC_FLAGS_FPU += $(call cc-option,-msse -mpreferred-stack-boundary=3,-mpreferred-stack-boundary=4) 95 + endif 96 + 77 97 ifeq ($(CONFIG_X86_KERNEL_IBT),y) 78 98 # 79 99 # Kernel IBT has S_CET.NOTRACK_EN=0, as such the compilers must not generate
+13
arch/x86/include/asm/fpu.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (C) 2023 SiFive 4 + */ 5 + 6 + #ifndef _ASM_X86_FPU_H 7 + #define _ASM_X86_FPU_H 8 + 9 + #include <asm/fpu/api.h> 10 + 11 + #define kernel_fpu_available() true 12 + 13 + #endif /* ! _ASM_X86_FPU_H */