Re: [patch V3 52/66] x86/fpu: Add PKRU storage outside of task XSAVE buffer

From: Borislav Petkov
Date: Tue Jun 22 2021 - 12:55:10 EST


On Fri, Jun 18, 2021 at 04:19:15PM +0200, Thomas Gleixner wrote:
> From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
>
> 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: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> ---
> V3: Fix the fallout on !PKRU enabled systems in copy_thread() - Intel testing via Dave
> ---
> arch/x86/include/asm/processor.h | 9 +++++++++
> arch/x86/kernel/process.c | 7 +++++++
> arch/x86/kernel/process_64.c | 25 +++++++++++++++++++++++++
> 3 files changed, 41 insertions(+)

Reviewed-by: Borislav Petkov <bp@xxxxxxx>

--
Regards/Gruss,
Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg