Messages in this thread Patch in this message | | | Subject | [PATCH 03/12] x86, pkey: pkru xsave fields and data structure | From | Dave Hansen <> | Date | Thu, 07 May 2015 10:41:34 -0700 |
| |
The protection keys register (PKRU) is saved and restored using xsave. Define the data structure that we will use to access it inside the xsave buffer, and also double-check that the new structure matches the size that comes out of the CPU.
---
b/arch/x86/include/asm/processor.h | 9 +++++++++ b/arch/x86/include/asm/xsave.h | 3 ++- b/arch/x86/kernel/xsave.c | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-)
diff -puN arch/x86/include/asm/processor.h~pkeys-2-xsave arch/x86/include/asm/processor.h --- a/arch/x86/include/asm/processor.h~pkeys-2-xsave 2015-05-07 10:31:41.756204056 -0700 +++ b/arch/x86/include/asm/processor.h 2015-05-07 10:31:41.763204372 -0700 @@ -406,6 +406,15 @@ struct bndcsr { u64 bndstatus; } __packed; +/* + * "The size of XSAVE state component for PKRU is 8 bytes, + * of which only the first four bytes are used...". + */ +struct pkru { + u32 pkru; + u32 pkru_unused; +} __packed; + struct xsave_hdr_struct { u64 xstate_bv; u64 xcomp_bv; diff -puN arch/x86/include/asm/xsave.h~pkeys-2-xsave arch/x86/include/asm/xsave.h --- a/arch/x86/include/asm/xsave.h~pkeys-2-xsave 2015-05-07 10:31:41.758204147 -0700 +++ b/arch/x86/include/asm/xsave.h 2015-05-07 10:31:41.764204417 -0700 @@ -14,6 +14,7 @@ #define XSTATE_OPMASK 0x20 #define XSTATE_ZMM_Hi256 0x40 #define XSTATE_Hi16_ZMM 0x80 +#define XSTATE_PKRU 0x200 #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) #define XSTATE_AVX512 (XSTATE_OPMASK | XSTATE_ZMM_Hi256 | XSTATE_Hi16_ZMM) @@ -33,7 +34,7 @@ | XSTATE_OPMASK | XSTATE_ZMM_Hi256 | XSTATE_Hi16_ZMM) /* Supported features which require eager state saving */ -#define XSTATE_EAGER (XSTATE_BNDREGS | XSTATE_BNDCSR) +#define XSTATE_EAGER (XSTATE_BNDREGS | XSTATE_BNDCSR | XSTATE_PKRU) /* All currently supported features */ #define XCNTXT_MASK (XSTATE_LAZY | XSTATE_EAGER) diff -puN arch/x86/kernel/xsave.c~pkeys-2-xsave arch/x86/kernel/xsave.c --- a/arch/x86/kernel/xsave.c~pkeys-2-xsave 2015-05-07 10:31:41.760204237 -0700 +++ b/arch/x86/kernel/xsave.c 2015-05-07 10:31:41.764204417 -0700 @@ -528,6 +528,13 @@ void setup_xstate_comp(void) + xstate_comp_sizes[i-1]; } + /* + * Check that the size of the "PKRU" xsave area + * which the CPU knows about matches the kernel + * data structure that we have defined. + */ + if ((xstate_features >= XSTATE_PKRU) && xstate_comp_sizes[XSTATE_PKRU]) + WARN_ON(xstate_comp_sizes[XSTATE_PKRU] != sizeof(struct pkru)); } /* _
| |