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

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>

authored by

Samuel Holland and committed by
Andrew Morton
790a4a3d 9613736d

+7 -25
+1 -1
lib/Kconfig.debug
··· 2926 2926 2927 2927 config TEST_FPU 2928 2928 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 2930 2930 help 2931 2931 Enable this option to add /sys/kernel/debug/selftest_helpers/test_fpu 2932 2932 which will trigger a sequence of floating point operations. This is used
+2 -23
lib/Makefile
··· 110 110 obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o 111 111 obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o 112 112 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 - 135 113 obj-$(CONFIG_TEST_FPU) += test_fpu.o 136 114 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) 138 117 139 118 # Some KUnit files (hooks.o) need to be built-in even when KUnit is a module, 140 119 # so we can't just use obj-$(CONFIG_KUNIT).
+4 -1
lib/test_fpu_glue.c
··· 17 17 #include <linux/module.h> 18 18 #include <linux/kernel.h> 19 19 #include <linux/debugfs.h> 20 - #include <asm/fpu/api.h> 20 + #include <linux/fpu.h> 21 21 22 22 #include "test_fpu.h" 23 23 ··· 38 38 39 39 static int __init test_fpu_init(void) 40 40 { 41 + if (!kernel_fpu_available()) 42 + return -EINVAL; 43 + 41 44 selftest_dir = debugfs_create_dir("selftest_helpers", NULL); 42 45 if (!selftest_dir) 43 46 return -ENOMEM;