Skip to content

x86/fpu: Spring cleaning and PKRU sanitizing

Thomas Gleixner lkml 4 versions – Applied

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

  1. v4 Latest65 patches 10 repliesApplied
  2. v366 patches 64 repliesApplied
  3. v252 patches 31 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v141 patches27 repliesSuperseded

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 filesSizeRepliesApplied
1/65x86/fpu: Fix copy_xstate_to_kernel() gap handlingarch/x86/kernel/fpu/xstate.c+61 -440 replies
2/65x86/pkeys: Revert a5eff7259790 ("x86/pkeys: Add PKRU value to init_fpstate")arch/x86/kernel/cpu/common.c arch/x86/mm/pkeys.c+0 -110 replies
3/65x86/fpu: Mark various FPU states __ro_after_initarch/x86/kernel/fpu/init.c arch/x86/kernel/fpu/xstate.c+11 -70 replies
4/65x86/fpu: Make xfeatures_mask_all __ro_after_initarch/x86/kernel/fpu/xstate.c+15 -130 replies
5/65x86/fpu: Get rid of fpu__get_supported_xfeatures_mask()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/cpu/common.c arch/x86/kernel/fpu/init.c +1 more+5 -160 replies
6/65x86/fpu: Remove unused get_xsave_field_ptr()arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/xstate.c+0 -310 replies
7/65x86/fpu: Move inlines where they belongarch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c+15 -141 reply
8/65x86/fpu: Limit xstate copy size in xstateregs_set()arch/x86/kernel/fpu/regset.c+1 -10 replies
9/65x86/fpu: Sanitize xstateregs_set()arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/regset.c arch/x86/kernel/fpu/xstate.c+26 -368 replies
10/65x86/fpu: Reject invalid MXCSR values in copy_kernel_to_xstate()arch/x86/kernel/fpu/xstate.c+16 -30 replies
11/65x86/fpu: Simplify PTRACE_GETREGS codearch/x86/kernel/fpu/regset.c arch/x86/kernel/fpu/xstate.c+6 -240 replies
12/65x86/fpu: Rewrite xfpregs_set()arch/x86/kernel/fpu/regset.c+24 -150 replies
13/65x86/fpu: Fail ptrace() requests that try to set invalid MXCSR valuesarch/x86/kernel/fpu/regset.c+3 -20 replies
14/65x86/fpu: Clean up fpregs_set()arch/x86/kernel/fpu/regset.c+16 -150 replies
15/65x86/fpu: Make copy_xstate_to_kernel() usable for [x]fpregs_get()arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/regset.c arch/x86/kernel/fpu/xstate.c+42 -141 reply
16/65x86/fpu: Use copy_xstate_to_uabi_buf() in xfpregs_get()arch/x86/kernel/fpu/regset.c+8 -30 replies
17/65x86/fpu: Use copy_xstate_to_uabi_buf() in fpregs_get()arch/x86/kernel/fpu/regset.c+20 -100 replies
18/65x86/fpu: Remove fpstate_sanitize_xstate()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/xstate.c+0 -810 replies
19/65x86/fpu/regset: Move fpu__read_begin() into regsetarch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/regset.c+19 -240 replies
20/65x86/fpu: Move fpu__write_begin() to regsetarch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/regset.c+22 -280 replies
21/65x86/fpu: Get rid of using_compacted_format()arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/xstate.c+4 -190 replies
22/65x86/kvm: Avoid looking up PKRU in XSAVE bufferarch/x86/kvm/x86.c+22 -190 replies
23/65x86/fpu: Cleanup arch_set_user_pkey_access()arch/x86/kernel/fpu/xstate.c+6 -50 replies
24/65x86/fpu: Get rid of copy_supervisor_to_kernel()arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/signal.c arch/x86/kernel/fpu/xstate.c+8 -610 replies
25/65x86/fpu: Rename copy_xregs_to_kernel() and copy_kernel_to_xregs()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/signal.c +1 more+26 -210 replies
26/65x86/fpu: Rename copy_user_to_xregs() and copy_xregs_to_user()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/signal.c+4 -40 replies
27/65x86/fpu: Rename fxregs related copy functionsarch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/signal.c+13 -210 replies
28/65x86/math-emu: Rename frstor()arch/x86/math-emu/fpu_proto.h arch/x86/math-emu/load_store.c arch/x86/math-emu/reg_ld_str.c+3 -30 replies
29/65x86/fpu: Rename fregs related copy functionsarch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/signal.c+9 -90 replies
30/65x86/fpu: Rename xstate copy functions which are related to UABIarch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/regset.c arch/x86/kernel/fpu/signal.c +1 more+7 -60 replies
31/65x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate()arch/x86/kernel/fpu/xstate.c+47 -900 replies
32/65x86/fpu: Rename copy_fpregs_to_fpstate() to save_fpregs_to_fpstate()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kvm/x86.c+8 -80 replies
33/65x86/fpu: Get rid of the FNSAVE optimizationarch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c+34 -380 replies
34/65x86/fpu: Rename copy_kernel_to_fpregs() to restore_fpregs_from_fpstate()arch/x86/include/asm/fpu/internal.h arch/x86/kvm/x86.c arch/x86/mm/extable.c+7 -70 replies
35/65x86/fpu: Rename initstate copy functionsarch/x86/kernel/fpu/core.c+3 -30 replies
36/65x86/fpu: Rename "dynamic" XSTATEs to "independent"arch/x86/events/intel/lbr.c arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/xstate.c+45 -450 replies
37/65x86/fpu/xstate: Sanitize handling of independent featuresarch/x86/events/intel/lbr.c arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/xstate.c+54 -550 replies
38/65x86/pkeys: Move read_pkru() and write_pkru()arch/x86/include/asm/fpu/xstate.h arch/x86/include/asm/pgtable.h arch/x86/include/asm/pkru.h +4 more+67 -560 replies
39/65x86/fpu: Rename and sanitize fpu__save/copy()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/regset.c +2 more+17 -160 replies
40/65x86/cpu: Sanitize X86_FEATURE_OSPKEarch/x86/include/asm/pkeys.h arch/x86/include/asm/pkru.h arch/x86/kernel/cpu/common.c +4 more+21 -230 replies
41/65x86/pkru: Provide pkru_get_init_value()arch/x86/include/asm/pkru.h+2 -00 replies
42/65x86/pkru: Provide pkru_write_default()arch/x86/include/asm/pkru.h+8 -00 replies
43/65x86/cpu: Write the default PKRU value when enabling PKEarch/x86/kernel/cpu/common.c+2 -00 replies
44/65x86/fpu: Use pkru_write_default() in copy_init_fpstate_to_fpregs()arch/x86/include/asm/pkeys.h arch/x86/kernel/fpu/core.c arch/x86/mm/pkeys.c +1 more+1 -240 replies
45/65x86/fpu: Rename fpu__clear_all() to fpu_flush_thread()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/process.c+5 -40 replies
46/65x86/fpu: Clean up the fpu__clear() variantsarch/x86/kernel/fpu/core.c arch/x86/kernel/process.c+86 -370 replies
47/65x86/fpu: Rename __fpregs_load_activate() to fpregs_restore_userregs()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/signal.c+4 -60 replies
48/65x86/fpu: Move FXSAVE_LEAK quirk info __copy_kernel_to_fpregs()arch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/core.c+28 -240 replies
49/65x86/fpu: Rename xfeatures_mask_user() to xfeatures_mask_uabi()arch/x86/include/asm/fpu/internal.h arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/core.c +2 more+26 -170 replies
50/65x86/fpu: Dont restore PKRU in fpregs_restore_userspace()arch/x86/include/asm/fpu/internal.h arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/core.c+35 -20 replies
51/65x86/fpu: Add PKRU storage outside of task XSAVE bufferarch/x86/include/asm/processor.h arch/x86/kernel/process.c arch/x86/kernel/process_64.c+41 -00 replies
52/65x86/fpu: Hook up PKRU into ptrace()arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/regset.c arch/x86/kernel/fpu/xstate.c+23 -140 replies
53/65x86/fpu: Mask PKRU from kernel XRSTOR[S] operationsarch/x86/include/asm/fpu/internal.h arch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/xstate.c +1 more+14 -30 replies
54/65x86/fpu: Remove PKRU handling from switch_fpu_finish()arch/x86/include/asm/fpu/internal.h+4 -300 replies
55/65x86/fpu: Dont store PKRU in xstate in fpu_reset_fpstate()arch/x86/kernel/fpu/core.c+4 -180 replies
56/65x86/pkru: Remove xstate fiddling from write_pkru()arch/x86/include/asm/pkru.h arch/x86/include/asm/special_insns.h arch/x86/kvm/x86.c+7 -280 replies
57/65x86/fpu: Mark init_fpstate __ro_after_initarch/x86/kernel/fpu/core.c+1 -10 replies
58/65x86/fpu/signal: Move initial checks into fpu__sig_restore()arch/x86/kernel/fpu/signal.c+41 -350 replies
59/65x86/fpu/signal: Remove the legacy alignment checkarch/x86/kernel/fpu/signal.c+0 -30 replies
60/65x86/fpu/signal: Sanitize the xstate check on sigframearch/x86/kernel/fpu/signal.c+33 -370 replies
61/65x86/fpu/signal: Sanitize copy_user_to_fpregs_zeroing()arch/x86/kernel/fpu/signal.c+15 -210 replies
62/65x86/fpu/signal: Split out the direct restore codearch/x86/kernel/fpu/signal.c+58 -540 replies
63/65x86/fpu: Return proper error codes from user access functionsarch/x86/include/asm/fpu/internal.h+12 -70 replies
64/65x86/fpu/signal: Handle #PF in the direct restore patharch/x86/kernel/fpu/signal.c+33 -340 replies
65/65x86/fpu/signal: Let xrstor handle the features to initarch/x86/kernel/fpu/signal.c+31 -580 replies

Reviews trailers per patch

49 of 65 patches have a Reviewed-by or Acked-by.

PatchBorislav PetkovAndy LutomirskiKan Liang
1/65R-b
2/65R-b
3/65R-b R-b
4/65R-b
5/65R-b
6/65R-b R-b
7/65R-b
8/65R-b R-b
9/65R-b
10/65R-b
11/65R-b R-b
12/65R-b
13/65
14/65R-b
15/65R-b
16/65R-b
17/65R-b
18/65
19/65R-b
20/65R-b
21/65R-b
22/65R-b
23/65R-b
24/65R-b R-b
25/65R-b
26/65R-b
27/65
28/65
29/65R-b
30/65R-b
31/65R-b A-b
32/65R-b
33/65R-b
34/65R-b
35/65
36/65
37/65T-b
38/65
39/65R-b
40/65R-b
41/65
42/65R-b
43/65
44/65
45/65R-b
46/65
47/65R-b
48/65R-b
49/65R-b
50/65R-b
51/65R-b
52/65R-b
53/65R-b
54/65R-b
55/65R-b
56/65R-b
57/65
58/65
59/65R-b
60/65R-b
61/65R-b
62/65
63/65
64/65R-b
65/65R-b

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.

Read the v4 thread

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(-)