]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
x86/fpu: Make 'no387' and 'nofxsr' command line options useful
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Wed, 3 Jul 2019 08:32:47 +0000 (10:32 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Sun, 7 Jul 2019 10:01:46 +0000 (12:01 +0200)
The command line option `no387' is designed to disable the FPU
entirely. This only 'works' with CONFIG_MATH_EMULATION enabled.

But on 64bit this cannot work because user space expects SSE to work which
required basic FPU support. MATH_EMULATION does not help because SSE is not
emulated.

The command line option `nofxsr' should also be limited to 32bit because
FXSR is part of the required flags on 64bit so turning it off is not
possible.

Clearing X86_FEATURE_FPU without emulation enabled will not work anyway and
hang in fpu__init_system_early_generic() before the console is enabled.

Setting additioal dependencies, ensures that the CPU still boots on a
modern CPU. Otherwise, dropping FPU will leave FXSR enabled causing the
kernel to crash early in fpu__init_system_mxcsr().

With XSAVE support it will crash in fpu__init_cpu_xstate(). The problem is
that xsetbv() with XMM set and SSE cleared is not allowed.  That means
XSAVE has to be disabled. The XSAVE support is disabled in
fpu__init_system_xstate_size_legacy() but it is too late. It can be
removed, it has been added in commit

  1f999ab5a1360 ("x86, xsave: Disable xsave in i387 emulation mode")

to use `no387' on a CPU with XSAVE support.

All this happens before console output.

After hat, the next possible crash is in RAID6 detect code because MMX
remained enabled. With a 3DNOW enabled config it will explode in memcpy()
for instance due to kernel_fpu_begin() but this is unconditionally enabled.

This is enough to boot a Debian Wheezy on a 32bit qemu "host" CPU which
supports everything up to XSAVES, AVX2 without 3DNOW. Later, Debian
increased the minimum requirements to i686 which means it does not boot
userland atleast due to CMOV.

After masking the additional features it still keeps SSE4A and 3DNOW*
enabled (if present on the host) but those are unused in the kernel.

Restrict `no387' and `nofxsr' otions to 32bit only. Add dependencies for
FPU, FXSR to additionaly mask CMOV, MMX, XSAVE if FXSR or FPU is cleared.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190703083247.57kjrmlxkai3vpw3@linutronix.de
arch/x86/kernel/cpu/cpuid-deps.c
arch/x86/kernel/fpu/init.c

index 2c0bd38a44ab125c6a6f9627eea0cc69c3d882f5..e794e3860fc83ec234af8a1a55678c60ae3f3916 100644 (file)
@@ -20,6 +20,7 @@ struct cpuid_dep {
  * but it's difficult to tell that to the init reference checker.
  */
 static const struct cpuid_dep cpuid_deps[] = {
+       { X86_FEATURE_FXSR,             X86_FEATURE_FPU       },
        { X86_FEATURE_XSAVEOPT,         X86_FEATURE_XSAVE     },
        { X86_FEATURE_XSAVEC,           X86_FEATURE_XSAVE     },
        { X86_FEATURE_XSAVES,           X86_FEATURE_XSAVE     },
@@ -27,7 +28,11 @@ static const struct cpuid_dep cpuid_deps[] = {
        { X86_FEATURE_PKU,              X86_FEATURE_XSAVE     },
        { X86_FEATURE_MPX,              X86_FEATURE_XSAVE     },
        { X86_FEATURE_XGETBV1,          X86_FEATURE_XSAVE     },
+       { X86_FEATURE_CMOV,             X86_FEATURE_FXSR      },
+       { X86_FEATURE_MMX,              X86_FEATURE_FXSR      },
+       { X86_FEATURE_MMXEXT,           X86_FEATURE_MMX       },
        { X86_FEATURE_FXSR_OPT,         X86_FEATURE_FXSR      },
+       { X86_FEATURE_XSAVE,            X86_FEATURE_FXSR      },
        { X86_FEATURE_XMM,              X86_FEATURE_FXSR      },
        { X86_FEATURE_XMM2,             X86_FEATURE_XMM       },
        { X86_FEATURE_XMM3,             X86_FEATURE_XMM2      },
index ef0030e3fe6b989542e9e557a11bf14a13b3e674..5baae74af4f9173e8d2736a2eefd210835d31bd4 100644 (file)
@@ -204,12 +204,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)
         */
 
        if (!boot_cpu_has(X86_FEATURE_FPU)) {
-               /*
-                * Disable xsave as we do not support it if i387
-                * emulation is enabled.
-                */
-               setup_clear_cpu_cap(X86_FEATURE_XSAVE);
-               setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
                fpu_kernel_xstate_size = sizeof(struct swregs_state);
        } else {
                if (boot_cpu_has(X86_FEATURE_FXSR))
@@ -252,14 +246,17 @@ static void __init fpu__init_parse_early_param(void)
        char *argptr = arg;
        int bit;
 
+#ifdef CONFIG_X86_32
        if (cmdline_find_option_bool(boot_command_line, "no387"))
+#ifdef CONFIG_MATH_EMULATION
                setup_clear_cpu_cap(X86_FEATURE_FPU);
+#else
+               pr_err("Option 'no387' required CONFIG_MATH_EMULATION enabled.\n");
+#endif
 
-       if (cmdline_find_option_bool(boot_command_line, "nofxsr")) {
+       if (cmdline_find_option_bool(boot_command_line, "nofxsr"))
                setup_clear_cpu_cap(X86_FEATURE_FXSR);
-               setup_clear_cpu_cap(X86_FEATURE_FXSR_OPT);
-               setup_clear_cpu_cap(X86_FEATURE_XMM);
-       }
+#endif
 
        if (cmdline_find_option_bool(boot_command_line, "noxsave"))
                fpu__xstate_clear_all_cpu_caps();