Skip to content

RFC x86/pkeys: remove PKRU from kernel XSAVE buffer

Dave Hansen linux-mm lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest8 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8x86/pkeys: add PKRU storage outside of task XSAVE bufferarch/x86/include/asm/pkru.h arch/x86/kernel/cpu/common.c arch/x86/kernel/process_64.c +1 more+14 -50 replies
2/8x86/fpu: hook up PKRU into signal user ABIsarch/x86/kernel/fpu/signal.c+7 -00 replies
3/8x86/fpu: separate the setup of xfeatures not in fpstatearch/x86/kernel/fpu/xstate.c+30 -100 replies
4/8x86/fpu: remove PKRU from FPU user state clearingarch/x86/kernel/fpu/core.c arch/x86/kernel/fpu/signal.c arch/x86/kernel/signal.c+10 -40 replies
5/8x86/fpu: XSAVE buffer access routine renamearch/x86/include/asm/fpu/xstate.h arch/x86/kernel/fpu/xstate.c arch/x86/kvm/x86.c+11 -100 replies
6/8x86/fpu: update xstate size calculations for non-XSAVE-managed featuresarch/x86/kernel/fpu/xstate.c+19 -60 replies
7/8x86/fpu: actually stop using XSAVE on PKRUarch/x86/include/asm/fpu/internal.h arch/x86/kernel/fpu/xstate.c+14 -170 replies
8/8x86/pkeys: remove init_pkru_value variablearch/x86/include/asm/pkru.h arch/x86/kernel/cpu/common.c arch/x86/mm/pkeys.c+22 -240 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC][PATCH 0/8] x86/pkeys: remove PKRU from kernel XSAVE buffer

This is a rework of the kernel's Protection Keys Register code. It severs the connection between PKRU and XSAVE as thoroughly as possible without affecting the existing ABIs.

This compiles in a few configurations and passes the pkeys selftest, but that's about it. It's not been pummeled enough yet for merging anywhere.

This is on top of the current:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git x86/fpu

specifically:

	3d168301c78d ("x86/fpu/signal: Let xrstor handle the features to init")

--

PKRU is currently a strange beast. It can be XSAVE-managed and it has space allocated in the thread 'fpstate' buffer. However, it is switched more eagerly than other FPU state because PKRU affects things like copy_to/from_user(). This is because PKRU affects user *PERMISSION* accesses, not just accesses made from user *MODE* itself.

This leaves PKRU in a very odd position. It is stored in the kernel XSAVE buffer but the XSAVE architecture is not used to manage it.

Move PKRU out of the 'fpstate' buffer. Instead, allocate space in the thread_struct for it and save/restore it in the context-switch path separately from the XSAVE-managed features. This removes the ambiguity of having PKRU state in two places for each task.

 include/asm/fpu/internal.h |    2 -
 include/asm/fpu/xstate.h   |    2 -
 include/asm/pkru.h         |   10 +++--
 kernel/cpu/common.c        |   19 +++++++++-
 kernel/fpu/core.c          |    8 ++--
 kernel/fpu/signal.c        |   12 +++++-
 kernel/fpu/xstate.c        |   83 ++++++++++++++++++++++++++++++---------------
 kernel/process_64.c        |    9 ++--
 kernel/signal.c            |    1 
 kvm/x86.c                  |    8 ++--
 mm/pkeys.c                 |   21 ++---------
 11 files changed, 113 insertions(+), 62 deletions(-)
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Andy Lutomirski <[email protected]>