• Sebastian Andrzej Siewior's avatar
    x86/fpu: Make 'no387' and 'nofxsr' command line options useful · 9838e3bf
    Sebastian Andrzej Siewior authored
    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
    
      1f999ab5 ("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: default avatarVegard Nossum <vegard.nossum@oracle.com>
    Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Link: https://lkml.kernel.org/r/20190703083247.57kjrmlxkai3vpw3@linutronix.de
    9838e3bf
init.c 7.33 KB