Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1234358 > unrolled thread

[PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s)

Started byDave Hansen <dave@sr71.net>
First post2015-09-28 21:30 +0200
Last post2015-10-01 19:20 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s) Dave Hansen <dave@sr71.net> - 2015-09-28 21:30 +0200
    Re: [PATCH 05/25] x86, pkey: add PKRU xsave fields and data  structure(s) Thomas Gleixner <tglx@linutronix.de> - 2015-10-01 14:00 +0200
      Re: [PATCH 05/25] x86, pkey: add PKRU xsave fields and data  structure(s) Dave Hansen <dave@sr71.net> - 2015-10-01 19:20 +0200

#1234358 — [PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s)

FromDave Hansen <dave@sr71.net>
Date2015-09-28 21:30 +0200
Subject[PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s)
Message-ID<qdMhz-gH-5@gated-at.bofh.it>
From: Dave Hansen <dave.hansen@linux.intel.com>

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.

Note that we also have to widen the printk of the xsave feature
masks since this is feature 0x200 and we only did two characters
before.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/arch/x86/include/asm/fpu/types.h  |   16 ++++++++++++++++
 b/arch/x86/include/asm/fpu/xstate.h |    4 +++-
 b/arch/x86/kernel/fpu/xstate.c      |    7 ++++++-
 3 files changed, 25 insertions(+), 2 deletions(-)

diff -puN arch/x86/include/asm/fpu/types.h~pkeys-03-xsave arch/x86/include/asm/fpu/types.h
--- a/arch/x86/include/asm/fpu/types.h~pkeys-03-xsave	2015-09-28 11:39:43.198057761 -0700
+++ b/arch/x86/include/asm/fpu/types.h	2015-09-28 11:39:43.205058079 -0700
@@ -109,6 +109,7 @@ enum xfeature {
 	XFEATURE_ZMM_Hi256,
 	XFEATURE_Hi16_ZMM,
 	XFEATURE_PT_UNIMPLEMENTED_SO_FAR,
+	XFEATURE_PKRU,
 
 	XFEATURE_MAX,
 };
@@ -121,6 +122,7 @@ enum xfeature {
 #define XFEATURE_MASK_OPMASK		(1 << XFEATURE_OPMASK)
 #define XFEATURE_MASK_ZMM_Hi256		(1 << XFEATURE_ZMM_Hi256)
 #define XFEATURE_MASK_Hi16_ZMM		(1 << XFEATURE_Hi16_ZMM)
+#define XFEATURE_MASK_PKRU		(1 << XFEATURE_PKRU)
 
 #define XFEATURE_MASK_FPSSE		(XFEATURE_MASK_FP | XFEATURE_MASK_SSE)
 #define XFEATURE_MASK_AVX512		(XFEATURE_MASK_OPMASK \
@@ -213,6 +215,20 @@ struct avx_512_hi16_state {
 	struct reg_512_bit		hi16_zmm[16];
 } __packed;
 
+/*
+ * State component 9: 32-bit PKRU register.
+ */
+struct pkru {
+	u32 pkru;
+} __packed;
+
+struct pkru_state {
+	union {
+		struct pkru		pkru;
+		u8			pad_to_8_bytes[8];
+	};
+} __packed;
+
 struct xstate_header {
 	u64				xfeatures;
 	u64				xcomp_bv;
diff -puN arch/x86/include/asm/fpu/xstate.h~pkeys-03-xsave arch/x86/include/asm/fpu/xstate.h
--- a/arch/x86/include/asm/fpu/xstate.h~pkeys-03-xsave	2015-09-28 11:39:43.200057851 -0700
+++ b/arch/x86/include/asm/fpu/xstate.h	2015-09-28 11:39:43.205058079 -0700
@@ -27,7 +27,9 @@
 				 XFEATURE_MASK_Hi16_ZMM)
 
 /* Supported features which require eager state saving */
-#define XFEATURE_MASK_EAGER	(XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)
+#define XFEATURE_MASK_EAGER	(XFEATURE_MASK_BNDREGS | \
+				 XFEATURE_MASK_BNDCSR | \
+				 XFEATURE_MASK_PKRU)
 
 /* All currently supported features */
 #define XCNTXT_MASK	(XFEATURE_MASK_LAZY | XFEATURE_MASK_EAGER)
diff -puN arch/x86/kernel/fpu/xstate.c~pkeys-03-xsave arch/x86/kernel/fpu/xstate.c
--- a/arch/x86/kernel/fpu/xstate.c~pkeys-03-xsave	2015-09-28 11:39:43.201057897 -0700
+++ b/arch/x86/kernel/fpu/xstate.c	2015-09-28 11:39:43.205058079 -0700
@@ -29,6 +29,8 @@ static const char *xfeature_names[] =
 	"AVX-512 Hi256"			,
 	"AVX-512 ZMM_Hi256"		,
 	"Processor Trace (unused)"	,
+	"Protection Keys User registers",
+	"unknown xstate feature"	,
 };
 
 /*
@@ -57,6 +59,7 @@ void fpu__xstate_clear_all_cpu_caps(void
 	setup_clear_cpu_cap(X86_FEATURE_AVX512ER);
 	setup_clear_cpu_cap(X86_FEATURE_AVX512CD);
 	setup_clear_cpu_cap(X86_FEATURE_MPX);
+	setup_clear_cpu_cap(X86_FEATURE_PKU);
 }
 
 /*
@@ -235,7 +238,7 @@ static void __init print_xstate_feature(
 	const char *feature_name;
 
 	if (cpu_has_xfeatures(xstate_mask, &feature_name))
-		pr_info("x86/fpu: Supporting XSAVE feature 0x%02Lx: '%s'\n", xstate_mask, feature_name);
+		pr_info("x86/fpu: Supporting XSAVE feature 0x%03Lx: '%s'\n", xstate_mask, feature_name);
 }
 
 /*
@@ -251,6 +254,7 @@ static void __init print_xstate_features
 	print_xstate_feature(XFEATURE_MASK_OPMASK);
 	print_xstate_feature(XFEATURE_MASK_ZMM_Hi256);
 	print_xstate_feature(XFEATURE_MASK_Hi16_ZMM);
+	print_xstate_feature(XFEATURE_MASK_PKRU);
 }
 
 /*
@@ -467,6 +471,7 @@ static void check_xstate_against_struct(
 	XCHECK_SZ(sz, nr, XFEATURE_OPMASK,    struct avx_512_opmask_state);
 	XCHECK_SZ(sz, nr, XFEATURE_ZMM_Hi256, struct avx_512_zmm_uppers_state);
 	XCHECK_SZ(sz, nr, XFEATURE_Hi16_ZMM,  struct avx_512_hi16_state);
+	XCHECK_SZ(sz, nr, XFEATURE_PKRU,      struct pkru_state);
 
 	/*
 	 * Make *SURE* to add any feature numbers in below if
_
--
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/

[toc] | [next] | [standalone]


#1237318 — Re: [PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s)

FromThomas Gleixner <tglx@linutronix.de>
Date2015-10-01 14:00 +0200
SubjectRe: [PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s)
Message-ID<qeKGL-383-25@gated-at.bofh.it>
In reply to#1234358
On Mon, 28 Sep 2015, Dave Hansen wrote:
> +/*
> + * State component 9: 32-bit PKRU register.
> + */
> +struct pkru {
> +	u32 pkru;
> +} __packed;
> +
> +struct pkru_state {
> +	union {
> +		struct pkru		pkru;
> +		u8			pad_to_8_bytes[8];
> +	};

Why do you need two structs?

    struct pkru_state {
    	   u32 pkru;
	   u32 pad;
    }

should be sufficient. So instead of

       xsave.pkru_state.pkru.pkru

you get the more obvious

       xsave.pkru_state.pkru

Hmm?

Thanks,

	tglx



      

       
--
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/

[toc] | [prev] | [next] | [standalone]


#1237578 — Re: [PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s)

FromDave Hansen <dave@sr71.net>
Date2015-10-01 19:20 +0200
SubjectRe: [PATCH 05/25] x86, pkey: add PKRU xsave fields and data structure(s)
Message-ID<qePGp-2Bk-11@gated-at.bofh.it>
In reply to#1237318
On 10/01/2015 04:50 AM, Thomas Gleixner wrote:
> On Mon, 28 Sep 2015, Dave Hansen wrote:
>> +/*
>> + * State component 9: 32-bit PKRU register.
>> + */
>> +struct pkru {
>> +	u32 pkru;
>> +} __packed;
>> +
>> +struct pkru_state {
>> +	union {
>> +		struct pkru		pkru;
>> +		u8			pad_to_8_bytes[8];
>> +	};
> 
> Why do you need two structs?
> 
>     struct pkru_state {
>     	   u32 pkru;
> 	   u32 pad;
>     }
> 
> should be sufficient. So instead of
> 
>        xsave.pkru_state.pkru.pkru
> 
> you get the more obvious
> 
>        xsave.pkru_state.pkru
> 
> Hmm?

I was trying to get across that PKRU itself and the "PKRU state" are
differently-sized.

But, it does just end up looking funky if we _use_ it.  I'll fix it up.

--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web