x86/fpu: Spring cleaning and PKRU sanitizing
Status from this message: The following commit has been merged into the x86/fpu branch of tip:
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest65 patches 10 repliesApplied
- v366 patches 64 repliesApplied
- v252 patches 31 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 41 patches | 27 replies | Superseded |
Changes in v4 from the cover letter
- Dropped the two bugfixes which are applied already and rebased on top
- Addressed review comments (Andy, Boris)
Patches in v4 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/65 | x86/fpu: Fix copy_xstate_to_kernel() gap handlingarch/ | +61 | 0 replies | |
| 2/65 | x86/pkeys: Revert a5eff7259790 ("x86/pkeys: Add PKRU value to init_fpstate")arch/ arch/ | +0 | 0 replies | |
| 3/65 | x86/fpu: Mark various FPU states __ro_after_initarch/ arch/ | +11 | 0 replies | |
| 4/65 | x86/fpu: Make xfeatures_mask_all __ro_after_initarch/ | +15 | 0 replies | |
| 5/65 | x86/fpu: Get rid of fpu__get_supported_xfeatures_mask()arch/ arch/ arch/ +1 more | +5 | 0 replies | |
| 6/65 | x86/fpu: Remove unused get_xsave_field_ptr()arch/ arch/ | +0 | 0 replies | |
| 7/65 | x86/fpu: Move inlines where they belongarch/ arch/ | +15 | 1 reply | |
| 8/65 | x86/fpu: Limit xstate copy size in xstateregs_set()arch/ | +1 | 0 replies | |
| 9/65 | x86/fpu: Sanitize xstateregs_set()arch/ arch/ arch/ | +26 | 8 replies | |
| 10/65 | x86/fpu: Reject invalid MXCSR values in copy_kernel_to_xstate()arch/ | +16 | 0 replies | |
| 11/65 | x86/fpu: Simplify PTRACE_GETREGS codearch/ arch/ | +6 | 0 replies | |
| 12/65 | x86/fpu: Rewrite xfpregs_set()arch/ | +24 | 0 replies | |
| 13/65 | x86/fpu: Fail ptrace() requests that try to set invalid MXCSR valuesarch/ | +3 | 0 replies | |
| 14/65 | x86/fpu: Clean up fpregs_set()arch/ | +16 | 0 replies | |
| 15/65 | x86/fpu: Make copy_xstate_to_kernel() usable for [x]fpregs_get()arch/ arch/ arch/ | +42 | 1 reply | |
| 16/65 | x86/fpu: Use copy_xstate_to_uabi_buf() in xfpregs_get()arch/ | +8 | 0 replies | |
| 17/65 | x86/fpu: Use copy_xstate_to_uabi_buf() in fpregs_get()arch/ | +20 | 0 replies | |
| 18/65 | x86/fpu: Remove fpstate_sanitize_xstate()arch/ arch/ | +0 | 0 replies | |
| 19/65 | x86/fpu/regset: Move fpu__read_begin() into regsetarch/ arch/ arch/ | +19 | 0 replies | |
| 20/65 | x86/fpu: Move fpu__write_begin() to regsetarch/ arch/ arch/ | +22 | 0 replies | |
| 21/65 | x86/fpu: Get rid of using_compacted_format()arch/ arch/ | +4 | 0 replies | |
| 22/65 | x86/kvm: Avoid looking up PKRU in XSAVE bufferarch/ | +22 | 0 replies | |
| 23/65 | x86/fpu: Cleanup arch_set_user_pkey_access()arch/ | +6 | 0 replies | |
| 24/65 | x86/fpu: Get rid of copy_supervisor_to_kernel()arch/ arch/ arch/ | +8 | 0 replies | |
| 25/65 | x86/fpu: Rename copy_xregs_to_kernel() and copy_kernel_to_xregs()arch/ arch/ arch/ +1 more | +26 | 0 replies | |
| 26/65 | x86/fpu: Rename copy_user_to_xregs() and copy_xregs_to_user()arch/ arch/ | +4 | 0 replies | |
| 27/65 | x86/fpu: Rename fxregs related copy functionsarch/ arch/ arch/ | +13 | 0 replies | |
| 28/65 | x86/math-emu: Rename frstor()arch/ arch/ arch/ | +3 | 0 replies | |
| 29/65 | x86/fpu: Rename fregs related copy functionsarch/ arch/ arch/ | +9 | 0 replies | |
| 30/65 | x86/fpu: Rename xstate copy functions which are related to UABIarch/ arch/ arch/ +1 more | +7 | 0 replies | |
| 31/65 | x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate()arch/ | +47 | 0 replies | |
| 32/65 | x86/fpu: Rename copy_fpregs_to_fpstate() to save_fpregs_to_fpstate()arch/ arch/ arch/ | +8 | 0 replies | |
| 33/65 | x86/fpu: Get rid of the FNSAVE optimizationarch/ arch/ | +34 | 0 replies | |
| 34/65 | x86/fpu: Rename copy_kernel_to_fpregs() to restore_fpregs_from_fpstate()arch/ arch/ arch/ | +7 | 0 replies | |
| 35/65 | x86/fpu: Rename initstate copy functionsarch/ | +3 | 0 replies | |
| 36/65 | x86/fpu: Rename "dynamic" XSTATEs to "independent"arch/ arch/ arch/ | +45 | 0 replies | |
| 37/65 | x86/fpu/xstate: Sanitize handling of independent featuresarch/ arch/ arch/ | +54 | 0 replies | |
| 38/65 | x86/pkeys: Move read_pkru() and write_pkru()arch/ arch/ arch/ +4 more | +67 | 0 replies | |
| 39/65 | x86/fpu: Rename and sanitize fpu__save/copy()arch/ arch/ arch/ +2 more | +17 | 0 replies | |
| 40/65 | x86/cpu: Sanitize X86_FEATURE_OSPKEarch/ arch/ arch/ +4 more | +21 | 0 replies | |
| 41/65 | x86/pkru: Provide pkru_get_init_value()arch/ | +2 | 0 replies | |
| 42/65 | x86/pkru: Provide pkru_write_default()arch/ | +8 | 0 replies | |
| 43/65 | x86/cpu: Write the default PKRU value when enabling PKEarch/ | +2 | 0 replies | |
| 44/65 | x86/fpu: Use pkru_write_default() in copy_init_fpstate_to_fpregs()arch/ arch/ arch/ +1 more | +1 | 0 replies | |
| 45/65 | x86/fpu: Rename fpu__clear_all() to fpu_flush_thread()arch/ arch/ arch/ | +5 | 0 replies | |
| 46/65 | x86/fpu: Clean up the fpu__clear() variantsarch/ arch/ | +86 | 0 replies | |
| 47/65 | x86/fpu: Rename __fpregs_load_activate() to fpregs_restore_userregs()arch/ arch/ arch/ | +4 | 0 replies | |
| 48/65 | x86/fpu: Move FXSAVE_LEAK quirk info __copy_kernel_to_fpregs()arch/ arch/ | +28 | 0 replies | |
| 49/65 | x86/fpu: Rename xfeatures_mask_user() to xfeatures_mask_uabi()arch/ arch/ arch/ +2 more | +26 | 0 replies | |
| 50/65 | x86/fpu: Dont restore PKRU in fpregs_restore_userspace()arch/ arch/ arch/ | +35 | 0 replies | |
| 51/65 | x86/fpu: Add PKRU storage outside of task XSAVE bufferarch/ arch/ arch/ | +41 | 0 replies | |
| 52/65 | x86/fpu: Hook up PKRU into ptrace()arch/ arch/ arch/ | +23 | 0 replies | |
| 53/65 | x86/fpu: Mask PKRU from kernel XRSTOR[S] operationsarch/ arch/ arch/ +1 more | +14 | 0 replies | |
| 54/65 | x86/fpu: Remove PKRU handling from switch_fpu_finish()arch/ | +4 | 0 replies | |
| 55/65 | x86/fpu: Dont store PKRU in xstate in fpu_reset_fpstate()arch/ | +4 | 0 replies | |
| 56/65 | x86/pkru: Remove xstate fiddling from write_pkru()arch/ arch/ arch/ | +7 | 0 replies | |
| 57/65 | x86/fpu: Mark init_fpstate __ro_after_initarch/ | +1 | 0 replies | |
| 58/65 | x86/fpu/signal: Move initial checks into fpu__sig_restore()arch/ | +41 | 0 replies | |
| 59/65 | x86/fpu/signal: Remove the legacy alignment checkarch/ | +0 | 0 replies | |
| 60/65 | x86/fpu/signal: Sanitize the xstate check on sigframearch/ | +33 | 0 replies | |
| 61/65 | x86/fpu/signal: Sanitize copy_user_to_fpregs_zeroing()arch/ | +15 | 0 replies | |
| 62/65 | x86/fpu/signal: Split out the direct restore codearch/ | +58 | 0 replies | |
| 63/65 | x86/fpu: Return proper error codes from user access functionsarch/ | +12 | 0 replies | |
| 64/65 | x86/fpu/signal: Handle #PF in the direct restore patharch/ | +33 | 0 replies | |
| 65/65 | x86/fpu/signal: Let xrstor handle the features to initarch/ | +31 | 0 replies |
Reviews trailers per patch
49 of 65 patches have a Reviewed-by or Acked-by.
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.
Cover letter [patch V4 00/65] x86/fpu: Spring cleaning and PKRU sanitizing
The main parts of this series are:
- Simplification and removal/replacement of redundant and/or overengineered code.
- Name space cleanup as the existing names were just a permanent source of confusion.
- Clear seperation of user ABI and kernel internal state handling.
- Removal of PKRU from being XSTATE managed in the kernel because PKRU has to be eagerly restored on context switch and keeping it in sync in the xstate buffer is just pointless overhead and fragile.
The kernel still XSAVEs PKRU on context switch but the value in the buffer is not longer used and never restored from the buffer.
This still needs to be cleaned up, but the series is already 40+ patches large and the cleanup of this is not a functional problem.
The functional issues of PKRU management are fully addressed with the series as is.
- Cleanup of fpu signal restore
- Make the fast path self contained. Handle #PF directly and skip the slow path on any other exception as that will just end up with the same result that the frame is invalid. This allows the compiler to optimize the slow path out for 64bit kernels w/o ia32 emulation.
- Reduce code duplication and unnecessary operations
It applies on top of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master
and is also available via git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git x86/fpu
This is a follow up to V3 which can be found here:
https://lore.kernel.org/r/[email protected]
Changes vs. V3:
- Dropped the two bugfixes which are applied already and rebased on top
- Addressed review comments (Andy, Boris)
Patches: 13, 35, 36, 37, 46, 58, 62, 63
- Fixed the math-emu fallout which I had stashed safely on the 32bit
testbox (Boris)
Patch: 28- Picked up tags
Thanks to everyone for review, feedback and testing (various teams @Intel).
Note: I've not picked up any tested-by tags. It would be nice to have them on this hopefully final version.
Thanks,
tglx
--- arch/x86/events/intel/lbr.c | 6 arch/x86/include/asm/fpu/internal.h | 202 ++++------ arch/x86/include/asm/fpu/xstate.h | 78 +++- arch/x86/include/asm/pgtable.h | 57 --- arch/x86/include/asm/pkeys.h | 9 arch/x86/include/asm/pkru.h | 62 +++ arch/x86/include/asm/processor.h | 9 arch/x86/include/asm/special_insns.h | 14 arch/x86/kernel/cpu/common.c | 34 - arch/x86/kernel/fpu/core.c | 282 +++++++-------- arch/x86/kernel/fpu/init.c | 15 arch/x86/kernel/fpu/regset.c | 223 ++++++------ arch/x86/kernel/fpu/signal.c | 419 ++++++++++------------ arch/x86/kernel/fpu/xstate.c | 645 +++++++++++++---------------------- arch/x86/kernel/process.c | 22 + arch/x86/kernel/process_64.c | 28 + arch/x86/kernel/traps.c | 5 arch/x86/kvm/svm/sev.c | 1 arch/x86/kvm/x86.c | 56 +-- arch/x86/math-emu/fpu_proto.h | 2 arch/x86/math-emu/load_store.c | 2 arch/x86/math-emu/reg_ld_str.c | 2 arch/x86/mm/extable.c | 2 arch/x86/mm/fault.c | 2 arch/x86/mm/pkeys.c | 22 - include/linux/pkeys.h | 4 26 files changed, 1037 insertions(+), 1166 deletions(-)