Skip to content
  • Dave Hansen's avatar
    9782a712
    x86/fpu: Add PKRU storage outside of task XSAVE buffer · 9782a712
    Dave Hansen authored
    
    
    PKRU is currently partly XSAVE-managed and partly not. It has space
    in the task XSAVE buffer and is context-switched by XSAVE/XRSTOR.
    However, it is switched more eagerly than FPU because there may be a
    need for PKRU to be up-to-date for things like copy_to/from_user() since
    PKRU affects user-permission memory accesses, not just accesses from
    userspace itself.
    
    This leaves PKRU in a very odd position. XSAVE brings very little value
    to the table for how Linux uses PKRU except for signal related XSTATE
    handling.
    
    Prepare to move PKRU away from being XSAVE-managed. Allocate space in
    the thread_struct for it and save/restore it in the context-switch path
    separately from the XSAVE-managed features. task->thread_struct.pkru
    is only valid when the task is scheduled out. For the current task the
    authoritative source is the hardware, i.e. it has to be retrieved via
    rdpkru().
    
    Leave the XSAVE code in place for now to ensure bisectability.
    
    Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
    Link: https://lkml.kernel.org/r/20210623121456.399107624@linutronix.de
    9782a712
    x86/fpu: Add PKRU storage outside of task XSAVE buffer
    Dave Hansen authored
    
    
    PKRU is currently partly XSAVE-managed and partly not. It has space
    in the task XSAVE buffer and is context-switched by XSAVE/XRSTOR.
    However, it is switched more eagerly than FPU because there may be a
    need for PKRU to be up-to-date for things like copy_to/from_user() since
    PKRU affects user-permission memory accesses, not just accesses from
    userspace itself.
    
    This leaves PKRU in a very odd position. XSAVE brings very little value
    to the table for how Linux uses PKRU except for signal related XSTATE
    handling.
    
    Prepare to move PKRU away from being XSAVE-managed. Allocate space in
    the thread_struct for it and save/restore it in the context-switch path
    separately from the XSAVE-managed features. task->thread_struct.pkru
    is only valid when the task is scheduled out. For the current task the
    authoritative source is the hardware, i.e. it has to be retrieved via
    rdpkru().
    
    Leave the XSAVE code in place for now to ensure bisectability.
    
    Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
    Link: https://lkml.kernel.org/r/20210623121456.399107624@linutronix.de
Loading