Skip to content

Commit b0b8a15

Browse files
SiFiveHollandakpm00
authored andcommitted
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>
1 parent 01db473 commit b0b8a15

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ config X86
8585
select ARCH_HAS_FORTIFY_SOURCE
8686
select ARCH_HAS_GCOV_PROFILE_ALL
8787
select ARCH_HAS_KCOV if X86_64
88+
select ARCH_HAS_KERNEL_FPU_SUPPORT
8889
select ARCH_HAS_MEM_ENCRYPT
8990
select ARCH_HAS_MEMBARRIER_SYNC_CORE
9091
select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS

arch/x86/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
7474
KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json
7575
KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2
7676

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+
7797
ifeq ($(CONFIG_X86_KERNEL_IBT),y)
7898
#
7999
# Kernel IBT has S_CET.NOTRACK_EN=0, as such the compilers must not generate

arch/x86/include/asm/fpu.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 */

0 commit comments

Comments
 (0)