1. 22 May, 2015 1 commit
    • Ingo Molnar's avatar
      x86/fpu, crypto: Fix AVX2 feature tests · b54b4bbb
      Ingo Molnar authored
      For some CPU models I broke the AVX2 feature detection in:
      
        7bc371fa ("x86/fpu, crypto x86/camellia_aesni_avx2: Simplify the camellia_aesni_init() xfeature checks")
        534ff06e ("x86/fpu, crypto x86/serpent_avx2: Simplify the init() xfeature checks")
      
      ... because I did not realize that it's possible for a CPU to support
      the xstate necessary for AVX2 execution (XSTATE_YMM), but not have
      the AVX2 instructions themselves.
      
      Restore the necessary CPUID checks as well.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      b54b4bbb
  2. 20 May, 2015 5 commits
    • Ingo Molnar's avatar
      Merge branch 'x86/urgent' into x86/fpu, to resolve a conflict · 6f56a8d0
      Ingo Molnar authored
      Conflicts:
      	arch/x86/kernel/i387.c
      
      This commit is conflicting:
      
        e88221c5 ("x86/fpu: Disable XSAVES* support for now")
      
      These functions changed a lot, move the quirk to arch/x86/kernel/fpu/init.c's
      fpu__init_system_xstate_size_legacy().
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      6f56a8d0
    • Ingo Molnar's avatar
      x86/fpu: Disable XSAVES* support for now · e88221c5
      Ingo Molnar authored
      The kernel's handling of 'compacted' xsave state layout is buggy:
      
          http://marc.info/?l=linux-kernel&m=142967852317199
      
      I don't have such a system, and the description there is vague, but
      from extrapolation I guess that there were two kinds of bugs
      observed:
      
        - boot crashes, due to size calculations being wrong and the dynamic
          allocation allocating a too small xstate area. (This is now fixed
          in the new FPU code - but still present in stable kernels.)
      
        - FPU state corruption and ABI breakage: if signal handlers try to
          change the FPU state in standard format, which then the kernel
          tries to restore in the compacted format.
      
      These breakages are scary, but they only occur on a small number of
      systems that have XSAVES* CPU support. Yet we have had XSAVES support
      in the upstream kernel for a large number of stable kernel releases,
      and the fixes are involved and unproven.
      
      So do the safe resolution first: disable XSAVES* support and only
      use the standard xstate format. This makes the code work and is
      easy to backport.
      
      On top of this we can work on enabling (and testing!) proper
      compacted format support, without backporting pressure, on top of the
      new, cleaned up FPU code.
      
      Cc: <stable@vger.kernel.org>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      e88221c5
    • Ingo Molnar's avatar
      x86/fpu/init: Clean up and comment the __setup() functions · 5856afed
      Ingo Molnar authored
      Explain the functions and also standardize their style
      and naming.
      
      No change in functionality.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      5856afed
    • Ingo Molnar's avatar
      x86/fpu/init: Move __setup() functions to fpu/init.c · 7cf82d33
      Ingo Molnar authored
      We had a number of FPU init related boot option handlers
      in arch/x86/kernel/cpu/common.c - move them over into
      arch/x86/kernel/fpu/init.c to have them all in a
      single place.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      7cf82d33
    • Ingo Molnar's avatar
      x86/fpu/xstate: Use explicit parameter in xstate_fault() · b11ca7fb
      Ingo Molnar authored
      While looking at xstate.h it took me some time to realize that
      'xstate_fault' uses 'err' as a silent parameter. This is not
      obvious at the call site, at all.
      
      Make it an explicit macro argument, so that the syntactic
      connection is easier to see. Also explain xstate_fault()
      a bit.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      b11ca7fb
  3. 19 May, 2015 34 commits
    • Ingo Molnar's avatar
      x86/fpu: Reorganize fpu/internal.h · b1b64dc3
      Ingo Molnar authored
      fpu/internal.h has grown organically, with not much high level structure,
      which hurts its readability.
      
      Organize the various definitions into 5 sections:
      
       - high level FPU state functions
       - FPU/CPU feature flag helpers
       - fpstate handling functions
       - FPU context switching helpers
       - misc helper functions
      
      Other related changes:
      
       - Move MXCSR_DEFAULT to fpu/types.h.
       - drop the unused X87_FSW_ES define
      
      No change in functionality.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      b1b64dc3
    • Ingo Molnar's avatar
      x86/fpu: Add CONFIG_X86_DEBUG_FPU=y FPU debugging code · e97131a8
      Ingo Molnar authored
      There are various internal FPU state debugging checks that never
      trigger in practice, but which are useful for FPU code development.
      
      Separate these out into CONFIG_X86_DEBUG_FPU=y, and also add a
      couple of new ones.
      
      The size difference is about 0.5K of code on defconfig:
      
         text        data     bss          filename
         15028906    2578816  1638400      vmlinux
         15029430    2578816  1638400      vmlinux
      
      ( Keep this enabled by default until the new FPU code is debugged. )
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      e97131a8
    • Ingo Molnar's avatar
      x86/fpu: Fix the 'nofxsr' boot parameter to also clear X86_FEATURE_FXSR_OPT · d364a765
      Ingo Molnar authored
      I tried to simulate an ancient CPU via this option, and
      found that it still has fxsr_opt enabled, confusing the
      FPU code.
      
      Make the 'nofxsr' option also clear FXSR_OPT flag.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      d364a765
    • Ingo Molnar's avatar
      x86/fpu: Pass 'struct fpu' to fpu__restore() · e1884d69
      Ingo Molnar authored
      This cleans up the call sites and the function a bit,
      and also makes it more symmetric with the other high
      level FPU state handling functions.
      
      It's still only valid for the current task, as we copy
      to the FPU registers of the current CPU.
      
      No change in functionality.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      e1884d69
    • Ingo Molnar's avatar
      x86/fpu/init: Propagate __init annotations · 32231879
      Ingo Molnar authored
      Now that all the FPU init function call dependencies are
      cleaned up we can propagate __init annotations deeper.
      
      This shrinks the runtime size of the kernel a bit, and
      also addresses a few section warnings.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      32231879
    • Ingo Molnar's avatar
      x86/fpu/xstate: Clean up setup_xstate_comp() call · 5fd402df
      Ingo Molnar authored
      So call setup_xstate_comp() from the xstate init code, not
      from the generic fpu__init_system() code.
      
      This allows us to remove the protytype from xstate.h as well.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      5fd402df
    • Ingo Molnar's avatar
      x86/fpu: Clean up xstate feature reservation · 489e9c01
      Ingo Molnar authored
      Put MPX support into its separate high level structure, and
      also replace the fixed YMM, LWP and MPX structures in
      xregs_state with just reservations - their exact offsets
      in the structure will depend on the CPU and no code actually
      relies on those fields.
      
      No change in functionality.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      489e9c01
    • Ingo Molnar's avatar
      x86/fpu/xstate: Don't assume the first zero xfeatures zero bit means the end · 39f1acd2
      Ingo Molnar authored
      The current xstate code in setup_xstate_features() assumes that
      the first zero bit means the end of xfeatures - but that is not
      so, the SDM clearly states that an arbitrary set of xfeatures
      might be enabled - and it is also clear from the description
      of the compaction feature that holes are possible:
      
        "13-6 Vol. 1MANAGING STATE USING THE XSAVE FEATURE SET
        [...]
      
        Compacted format. Each state component i (i ≥ 2) is located at a byte
        offset from the base address of the XSAVE area based on the XCOMP_BV
        field in the XSAVE header:
      
        — If XCOMP_BV[i] = 0, state component i is not in the XSAVE area.
      
        — If XCOMP_BV[i] = 1, the following items apply:
      
        • If XCOMP_BV[j] = 0 for every j, 2 ≤ j < i, state component i is
          located at a byte offset 576 from the base address of the XSAVE
          area. (This item applies if i is the first bit set in bits 62:2 of
          the XCOMP_BV; it implies that state component i is located at the
          beginning of the extended region.)
      
        • Otherwise, let j, 2 ≤ j < i, be the greatest value such that
          XCOMP_BV[j] = 1. Then state component i is located at a byte offset
          X from the location of state component j, where X is the number of
          bytes required for state component j as enumerated in
          CPUID.(EAX=0DH,ECX=j):EAX. (This item implies that state component i
          immediately follows the preceding state component whose bit is set
          in XCOMP_BV.)"
      
      So don't assume that the first zero xfeatures bit means the end of
      all xfeatures - iterate through all of them.
      
      I'm not aware of hardware that triggers this currently.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      39f1acd2
    • Ingo Molnar's avatar
      x86/fpu: Move debugging check from kernel_fpu_begin() to __kernel_fpu_begin() · 63c6680c
      Ingo Molnar authored
      kernel_fpu_begin() is __kernel_fpu_begin() with a preempt_disable().
      
      Move the kernel_fpu_begin() debugging check into __kernel_fpu_begin(),
      so that users of __kernel_fpu_begin() may benefit from it as well.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      63c6680c
    • Ingo Molnar's avatar
      x86/fpu: Document the various fpregs state formats · bdf80d10
      Ingo Molnar authored
      Document all the structures that make up 'struct fpu'.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      bdf80d10
    • Ingo Molnar's avatar
      x86/fpu: Change fpu->fpregs_active from 'int' to 'char', add lazy switching comments · aeb997b9
      Ingo Molnar authored
      Improve the memory layout of 'struct fpu':
      
       - change ->fpregs_active from 'int' to 'char' - it's just a single flag
         and modern x86 CPUs can do efficient byte accesses.
      
       - pack related fields closer to each other: often 'fpu->state' will not be
         touched, while the other fields will - so pack them into a group.
      
      Also add comments to each field, describing their purpose, and add
      some background information about lazy restores.
      
      Also fix an obsolete, lazy switching related comment in fpu_copy()'s description.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      aeb997b9
    • Ingo Molnar's avatar
      x86/fpu: Harmonize FPU register state types · c47ada30
      Ingo Molnar authored
      Use these consistent names:
      
          struct fregs_state           # was: i387_fsave_struct
          struct fxregs_state          # was: i387_fxsave_struct
          struct swregs_state          # was: i387_soft_struct
          struct xregs_state           # was: xsave_struct
          union  fpregs_state          # was: thread_xstate
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      c47ada30
    • Ingo Molnar's avatar
      x86/fpu: Factor out the FPU regset code into fpu/regset.c · 0c306bcf
      Ingo Molnar authored
      So much of fpu/core.c is the regset code, but it just obscures the generic
      FPU state machine logic. Factor out the regset code into fpu/regset.c, where
      it can be read in isolation.
      
      This affects one API: fpu__activate_stopped() has to be made available
      from the core to fpu/regset.c.
      
      No change in functionality.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      0c306bcf
    • Ingo Molnar's avatar
      x86/fpu: Factor out fpu/signal.c · b992c660
      Ingo Molnar authored
      fpu/xstate.c has a lot of generic FPU signal frame handling routines,
      move them into a separate file: fpu/signal.c.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      b992c660
    • Ingo Molnar's avatar
      x86/fpu: Rename all the fpregs, xregs, fxregs and fregs handling functions · c6813144
      Ingo Molnar authored
      Standardize the naming of the various functions that copy register
      content in specific FPU context formats:
      
        copy_fxregs_to_kernel()         # was: fpu_fxsave()
        copy_xregs_to_kernel()          # was: xsave_state()
      
        copy_kernel_to_fregs()          # was: frstor_checking()
        copy_kernel_to_fxregs()         # was: fxrstor_checking()
        copy_kernel_to_xregs()          # was: fpu_xrstor_checking()
        copy_kernel_to_xregs_booting()  # was: xrstor_state_booting()
      
        copy_fregs_to_user()            # was: fsave_user()
        copy_fxregs_to_user()           # was: fxsave_user()
        copy_xregs_to_user()            # was: xsave_user()
      
        copy_user_to_fregs()            # was: frstor_user()
        copy_user_to_fxregs()           # was: fxrstor_user()
        copy_user_to_xregs()            # was: xrestore_user()
        copy_user_to_fpregs_zeroing()   # was: restore_user_xstate()
      
      Eliminate fpu_xrstor_checking(), because it was just a wrapper.
      
      No change in functionality.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      c6813144
    • Ingo Molnar's avatar
      x86/fpu: Move restore_init_xstate() out of fpu/internal.h · 81541889
      Ingo Molnar authored
      Move restore_init_xstate() next to its sole caller.
      
      Also rename it to copy_init_fpstate_to_fpregs() and add
      some comments about what it does.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      81541889
    • Ingo Molnar's avatar
      x86/fpu: Generalize 'init_xstate_ctx' · 6f575023
      Ingo Molnar authored
      So the handling of init_xstate_ctx has a layering violation: both
      'struct xsave_struct' and 'union thread_xstate' have a
      'struct i387_fxsave_struct' member:
      
         xsave_struct::i387
         thread_xstate::fxsave
      
      The handling of init_xstate_ctx is generic, it is used on all
      CPUs, with or without XSAVE instruction. So it's confusing how
      the generic code passes around and handles an XSAVE specific
      format.
      
      What we really want is for init_xstate_ctx to be a proper
      fpstate and we use its ::fxsave and ::xsave members, as
      appropriate.
      
      Since the xsave_struct::i387 and thread_xstate::fxsave aliases
      each other this is not a functional problem.
      
      So implement this, and move init_xstate_ctx to the generic FPU
      code in the process.
      
      Also, since init_xstate_ctx is not XSAVE specific anymore,
      rename it to init_fpstate, and mark it __read_mostly,
      because it's only modified once during bootup, and used
      as a reference fpstate later on.
      
      There's no change in functionality.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      6f575023
    • Ingo Molnar's avatar
      x86/fpu: Create 'union thread_xstate' helper for fpstate_init() · bf935b0b
      Ingo Molnar authored
      fpstate_init() only uses fpu->state, so pass that in to it.
      
      This enables the cleanup we will do in the next patch.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      bf935b0b
    • Ingo Molnar's avatar
      x86/fpu: Harmonize the names of the fpstate_init() helper functions · 0aba6978
      Ingo Molnar authored
      Harmonize the inconsistent naming of these related functions:
      
                                fpstate_init()
        finit_soft_fpu()   =>   fpstate_init_fsoft()
        fx_finit()         =>   fpstate_init_fxstate()
        fx_finit()         =>   fpstate_init_fstate()       # split out
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      0aba6978
    • Ingo Molnar's avatar
      x86/fpu: Factor out the exception error code handling code · e1cebad4
      Ingo Molnar authored
      Factor out the FPU error code handling code from traps.c and fpu/internal.h
      and move them close to each other.
      
      Also convert the helper functions to 'struct fpu *', which further simplifies
      them.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      e1cebad4
    • Ingo Molnar's avatar
      x86/fpu: Remove run-once init quirks · acd58a3a
      Ingo Molnar authored
      Remove various boot quirks that came from the old code.
      
      The new code is cleanly split up into per-system and per-cpu
      init sequences, and system init functions are only called once.
      
      Remove the run-once quirks.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      acd58a3a
    • Ingo Molnar's avatar
      x86/fpu: Factor out fpu/regset.h from fpu/internal.h · 59a36d16
      Ingo Molnar authored
      Only a few places use the regset definitions, so factor them out.
      
      Also fix related header dependency assumptions.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      59a36d16
    • Ingo Molnar's avatar
      x86/fpu: Split out fpu/signal.h from fpu/internal.h for signal frame handling functions · fcbc99c4
      Ingo Molnar authored
      Most of the FPU does not use them, so split it out and include
      them in signal.c and ia32_signal.c
      
      Also fix header file dependency assumption in fpu/core.c.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      fcbc99c4
    • Ingo Molnar's avatar
      x86/fpu: Move is_ia32*frame() helpers out of fpu/internal.h · 05012c13
      Ingo Molnar authored
      Move them to their only user. This makes the code easier to read,
      the header is less cluttered, and it also speeds up the build a bit.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      05012c13
    • Ingo Molnar's avatar
      x86/fpu: Merge fpu__reset() and fpu__clear() · fbce7782
      Ingo Molnar authored
      With recent cleanups and fixes the fpu__reset() and fpu__clear()
      functions have become almost identical in functionality: the only
      difference is that fpu__reset() assumed that the fpstate
      was already active in the eagerfpu case, while fpu__clear()
      activated it if it was inactive.
      
      This distinction almost never matters, the only case where such
      fpstate activation happens if if the init thread (PID 1) gets exec()-ed
      for the first time.
      
      So keep fpu__clear() and change all fpu__reset() uses to
      fpu__clear() to simpify the logic.
      
      ( In a later patch we'll further simplify fpu__clear() by making
        sure that all contexts it is called on are already active. )
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      fbce7782
    • Ingo Molnar's avatar
      x86/fpu: Move the signal frame handling code closer to each other · 82c0e45e
      Ingo Molnar authored
      Consolidate more signal frame related functions:
      
         text      data    bss     dec       filename
         14108070  2575280 1634304 18317654  vmlinux.before
         14107944  2575344 1634304 18317592  vmlinux.after
      
      Also, while moving it, rename alloc_mathframe() to fpu__alloc_mathframe().
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      82c0e45e
    • Ingo Molnar's avatar
      x86/fpu: Rename restore_xstate_sig() to fpu__restore_sig() · 9dfe99b7
      Ingo Molnar authored
      restore_xstate_sig() is a misnomer: it's not limited to 'xstate' at all,
      it is the high level 'restore FPU state from a signal frame' function
      that works with all legacy FPU formats as well.
      
      Rename it (and its helper) accordingly, and also move it to the
      fpu__*() namespace.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      9dfe99b7
    • Ingo Molnar's avatar
      x86/fpu: Move fpu__clear() to 'struct fpu *' parameter passing · 04c8e01d
      Ingo Molnar authored
      Do it like all other high level FPU state handling functions: they
      only know about struct fpu, not about the task.
      
      (Also remove a dead prototype while at it.)
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      04c8e01d
    • Ingo Molnar's avatar
      x86/fpu: Move all the fpu__*() high level methods closer to each other · 6ffc152e
      Ingo Molnar authored
      The fpu__*() methods are closely related, but they are defined
      in scattered places within the FPU code.
      
      Concentrate them, and also uninline fpu__save(), fpu__drop()
      and fpu__reset() to save about 5K of kernel text on 64-bit kernels:
      
         text            data    bss     dec        filename
         14113063        2575280 1634304 18322647   vmlinux.before
         14108070        2575280 1634304 18317654   vmlinux.after
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      6ffc152e
    • Ingo Molnar's avatar
      x86/fpu: Rename restore_fpu_checking() to copy_fpstate_to_fpregs() · 0e75c54f
      Ingo Molnar authored
      fpu_restore_checking() is a helper function of restore_fpu_checking(),
      but this is not apparent from the naming.
      
      Both copy fpstate contents to fpregs, while the fuller variant does
      a full copy without leaking information.
      
      So rename them to:
      
          copy_fpstate_to_fpregs()
        __copy_fpstate_to_fpregs()
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      0e75c54f
    • Ingo Molnar's avatar
      x86/fpu: Synchronize the naming of drop_fpu() and fpu_reset_state() · 50338615
      Ingo Molnar authored
      drop_fpu() and fpu_reset_state() are similar in functionality
      and in scope, yet this is not apparent from their names.
      
      drop_fpu() deactivates FPU contents (both the fpregs and the fpstate),
      but leaves register contents intact in the eager-FPU case, mostly as an
      optimization. It disables fpregs in the lazy FPU case. The drop_fpu()
      method can be used to destroy FPU state in an optimized way, when we
      know that a new state will be loaded before user-space might see
      any remains of the old FPU state:
      
           - such as in sys_exit()'s exit_thread() where we know this task
             won't execute any user-space instructions anymore and the
             next context switch cleans up the FPU. The old FPU state
             might still be around in the eagerfpu case but won't be
             saved.
      
           - in __restore_xstate_sig(), where we use drop_fpu() before
             copying a new state into the fpstate and activating that one.
             No user-pace instructions can execute between those steps.
      
           - in sys_execve()'s fpu__clear(): there we use drop_fpu() in
             the !eagerfpu case, where it's equivalent to a full reinit.
      
      fpu_reset_state() is a stronger version of drop_fpu(): both in
      the eagerfpu and the lazy-FPU case it guarantees that fpregs
      are reinitialized to init state. This method is used in cases
      where we need a full reset:
      
           - handle_signal() uses fpu_reset_state() to reset the FPU state
             to init before executing a user-space signal handler. While we
             have already saved the original FPU state at this point, and
             always restore the original state, the signal handling code
             still has to do this reinit, because signals may interrupt
             any user-space instruction, and the FPU might be in various
             intermediate states (such as an unbalanced x87 stack) that is
             not immediately usable for general C signal handler code.
      
           - __restore_xstate_sig() uses fpu_reset_state() when the signal
             frame has no FP context. Since the signal handler may have
             modified the FPU state, it gets reset back to init state.
      
           - in another branch __restore_xstate_sig() uses fpu_reset_state()
             to handle a restoration error: when restore_user_xstate() fails
             to restore FPU state and we might have inconsistent FPU data,
             fpu_reset_state() is used to reset it back to a known good
             state.
      
           - __kernel_fpu_end() uses fpu_reset_state() in an error branch.
             This is in a 'must not trigger' error branch, so on bug-free
             kernels this never triggers.
      
           - fpu__restore() uses fpu_reset_state() in an error path
             as well: if the fpstate was set up with invalid FPU state
             (via ptrace or via a signal handler), then it's reset back
             to init state.
      
           - likewise, the scheduler's switch_fpu_finish() uses it in a
             restoration error path too.
      
      Move both drop_fpu() and fpu_reset_state() to the fpu__*() namespace
      and harmonize their naming with their function:
      
          fpu__drop()
          fpu__reset()
      
      This clearly shows that both methods operate on the full state of the
      FPU, just like fpu__restore().
      
      Also add comments to explain what each function does.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      50338615
    • Ingo Molnar's avatar
      x86/alternatives, x86/fpu: Add 'alternatives_patched' debug flag and use it in xsave_state() · 5e907bb0
      Ingo Molnar authored
      We'd like to use xsave_state() earlier, but its SYSTEM_BOOTING check
      is too imprecise.
      
      The real condition that xsave_state() would like to check is whether
      alternative XSAVE instructions were patched into the kernel image
      already.
      
      Add such a (read-mostly) debug flag and use it in xsave_state().
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      5e907bb0
    • Ingo Molnar's avatar
      x86/fpu: Better document fpu__clear() state handling · 2e85591a
      Ingo Molnar authored
      So prior to this fix:
      
        c88d4748 ("x86/fpu: Always restore_xinit_state() when use_eager_cpu()")
      
      we leaked FPU state across execve() boundaries on eagerfpu systems:
      
      	$ /host/home/mingo/dump-xmm-regs-exec
      	# XMM state before execve():
      	XMM0 : 000000000000dede
      	XMM1 : 000000000000dedf
      	XMM2 : 000000000000dee0
      	XMM3 : 000000000000dee1
      	XMM4 : 000000000000dee2
      	XMM5 : 000000000000dee3
      	XMM6 : 000000000000dee4
      	XMM7 : 000000000000dee5
      	XMM8 : 000000000000dee6
      	XMM9 : 000000000000dee7
      	XMM10: 000000000000dee8
      	XMM11: 000000000000dee9
      	XMM12: 000000000000deea
      	XMM13: 000000000000deeb
      	XMM14: 000000000000deec
      	XMM15: 000000000000deed
      
      	# XMM state after execve(), in the new task context:
      	XMM0 : 0000000000000000
      	XMM1 : 2f2f2f2f2f2f2f2f
      	XMM2 : 0000000000000000
      	XMM3 : 0000000000000000
      	XMM4 : 00000000000000ff
      	XMM5 : 00000000ff000000
      	XMM6 : 000000000000dee4
      	XMM7 : 000000000000dee5
      	XMM8 : 0000000000000000
      	XMM9 : 0000000000000000
      	XMM10: 0000000000000000
      	XMM11: 0000000000000000
      	XMM12: 0000000000000000
      	XMM13: 000000000000deeb
      	XMM14: 000000000000deec
      	XMM15: 000000000000deed
      
      Better explain what this function is supposed to do and why.
      Reviewed-by: default avatarBorislav Petkov <bp@alien8.de>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      2e85591a
    • Ingo Molnar's avatar
      x86/fpu: Initialize fpregs in fpu__init_cpu_generic() · b1276c48
      Ingo Molnar authored
      FPU fpregs do not get initialized during bootup on secondary CPUs,
      on non-xsave capable CPUs.
      
      For example on one of my systems, the secondary CPU has this FPU
      state on bootup:
      
      	x86: Booting SMP configuration:
      	.... node  #0, CPUs:      #1
      	x86/fpu ######################
      	x86/fpu # FPU register dump on CPU#1:
      	x86/fpu # ... CWD: ffff0040
      	x86/fpu # ... SWD: ffff0000
      	x86/fpu # ... TWD: ffff555a
      	x86/fpu # ... FIP: 00000000
      	x86/fpu # ... FCS: 00000000
      	x86/fpu # ... FOO: 00000000
      	x86/fpu # ... FOS: ffff0000
      	x86/fpu # ... FP0: 02 57 00 00 00 00 00 00 ff ff
      	x86/fpu # ... FP1: 1b e2 00 00 00 00 00 00 ff ff
      	x86/fpu # ... FP2: 00 00 00 00 00 00 00 00 00 00
      	x86/fpu # ... FP3: 00 00 00 00 00 00 00 00 00 00
      	x86/fpu # ... FP4: 00 00 00 00 00 00 00 00 00 00
      	x86/fpu # ... FP5: 00 00 00 00 00 00 00 00 00 00
      	x86/fpu # ... FP6: 00 00 00 00 00 00 00 00 00 00
      	x86/fpu # ... FP7: 00 00 00 00 00 00 00 00 00 00
      	x86/fpu # ...  SW: dadadada
      	x86/fpu ######################
      
      Note how CWD and TWD are off their usual init state (0x037f and 0xffff),
      and how FP0 and FP1 has non-zero content.
      
      This is normally not a problem, because any user-space FPU state
      is initalized properly - but it can complicate the use of FPU
      instructions in kernel code via kernel_fpu_begin()/end(): if
      the FPU using code does not initialize registers itself, it
      might generate spurious exceptions depending on which CPU it
      executes on.
      
      Fix this by initializing the x87 state via the FNINIT instruction.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      b1276c48