Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752163AbbEGRlX (ORCPT ); Thu, 7 May 2015 13:41:23 -0400 Received: from mga03.intel.com ([134.134.136.65]:49415 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751060AbbEGRlU (ORCPT ); Thu, 7 May 2015 13:41:20 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,384,1427785200"; d="scan'208";a="567920931" Subject: [PATCH 03/12] x86, pkey: pkru xsave fields and data structure To: dave@sr71.net Cc: linux-kernel@vger.kernel.org, x86@kernel.org From: Dave Hansen Date: Thu, 07 May 2015 10:41:34 -0700 References: <20150507174132.34AF8FAF@viggo.jf.intel.com> In-Reply-To: <20150507174132.34AF8FAF@viggo.jf.intel.com> Message-Id: <20150507174134.7CAB5E6B@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2727 Lines: 75 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)); } /* _ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/