Skip to content

Commit 790a4a3

Browse files
SiFiveHollandakpm00
authored andcommitted
selftests/fpu: allow building on other architectures
Now that ARCH_HAS_KERNEL_FPU_SUPPORT provides a common way to compile and run floating-point code, this test is no longer x86-specific. Link: https://lkml.kernel.org/r/20240329072441.591471-16-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 9613736 commit 790a4a3

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

lib/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,7 @@ config TEST_FREE_PAGES
29262926

29272927
config TEST_FPU
29282928
tristate "Test floating point operations in kernel space"
2929-
depends on X86 && !KCOV_INSTRUMENT_ALL
2929+
depends on ARCH_HAS_KERNEL_FPU_SUPPORT && !KCOV_INSTRUMENT_ALL
29302930
help
29312931
Enable this option to add /sys/kernel/debug/selftest_helpers/test_fpu
29322932
which will trigger a sequence of floating point operations. This is used

lib/Makefile

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,10 @@ CFLAGS_test_fprobe.o += $(CC_FLAGS_FTRACE)
110110
obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o
111111
obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o
112112

113-
#
114-
# CFLAGS for compiling floating point code inside the kernel. x86/Makefile turns
115-
# off the generation of FPU/SSE* instructions for kernel proper but FPU_FLAGS
116-
# get appended last to CFLAGS and thus override those previous compiler options.
117-
#
118-
FPU_CFLAGS := -msse -msse2
119-
ifdef CONFIG_CC_IS_GCC
120-
# Stack alignment mismatch, proceed with caution.
121-
# GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
122-
# (8B stack alignment).
123-
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
124-
#
125-
# The "-msse" in the first argument is there so that the
126-
# -mpreferred-stack-boundary=3 build error:
127-
#
128-
# -mpreferred-stack-boundary=3 is not between 4 and 12
129-
#
130-
# can be triggered. Otherwise gcc doesn't complain.
131-
FPU_CFLAGS += -mhard-float
132-
FPU_CFLAGS += $(call cc-option,-msse -mpreferred-stack-boundary=3,-mpreferred-stack-boundary=4)
133-
endif
134-
135113
obj-$(CONFIG_TEST_FPU) += test_fpu.o
136114
test_fpu-y := test_fpu_glue.o test_fpu_impl.o
137-
CFLAGS_test_fpu_impl.o += $(FPU_CFLAGS)
115+
CFLAGS_test_fpu_impl.o += $(CC_FLAGS_FPU)
116+
CFLAGS_REMOVE_test_fpu_impl.o += $(CC_FLAGS_NO_FPU)
138117

139118
# Some KUnit files (hooks.o) need to be built-in even when KUnit is a module,
140119
# so we can't just use obj-$(CONFIG_KUNIT).

lib/test_fpu_glue.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <linux/module.h>
1818
#include <linux/kernel.h>
1919
#include <linux/debugfs.h>
20-
#include <asm/fpu/api.h>
20+
#include <linux/fpu.h>
2121

2222
#include "test_fpu.h"
2323

@@ -38,6 +38,9 @@ static struct dentry *selftest_dir;
3838

3939
static int __init test_fpu_init(void)
4040
{
41+
if (!kernel_fpu_available())
42+
return -EINVAL;
43+
4144
selftest_dir = debugfs_create_dir("selftest_helpers", NULL);
4245
if (!selftest_dir)
4346
return -ENOMEM;

0 commit comments

Comments
 (0)