[PATCH 07/31] x86, pkeys: PTE bits for storing protection key

2016-01-29 Thread Dave Hansen

From: Dave Hansen 

Previous documentation has referred to these 4 bits as "ignored".
That means that software could have made use of them.  But, as
far as I know, the kernel never used them.

They are still ignored when protection keys is not enabled, so
they could theoretically still get used for software purposes.

We also implement "empty" versions so that code that references
to them can be optimized away by the compiler when the config
option is not enabled.

Signed-off-by: Dave Hansen 
Reviewed-by: Thomas Gleixner 
---

 b/arch/x86/include/asm/pgtable_types.h |   22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff -puN arch/x86/include/asm/pgtable_types.h~pkeys-04-ptebits 
arch/x86/include/asm/pgtable_types.h
--- a/arch/x86/include/asm/pgtable_types.h~pkeys-04-ptebits 2016-01-28 
15:52:19.366358352 -0800
+++ b/arch/x86/include/asm/pgtable_types.h  2016-01-28 15:52:19.369358489 
-0800
@@ -20,13 +20,18 @@
 #define _PAGE_BIT_SOFTW2   10  /* " */
 #define _PAGE_BIT_SOFTW3   11  /* " */
 #define _PAGE_BIT_PAT_LARGE12  /* On 2MB or 1GB pages */
+#define _PAGE_BIT_SOFTW4   58  /* available for programmer */
+#define _PAGE_BIT_PKEY_BIT059  /* Protection Keys, bit 1/4 */
+#define _PAGE_BIT_PKEY_BIT160  /* Protection Keys, bit 2/4 */
+#define _PAGE_BIT_PKEY_BIT261  /* Protection Keys, bit 3/4 */
+#define _PAGE_BIT_PKEY_BIT362  /* Protection Keys, bit 4/4 */
+#define _PAGE_BIT_NX   63  /* No execute: only valid after cpuid 
check */
+
 #define _PAGE_BIT_SPECIAL  _PAGE_BIT_SOFTW1
 #define _PAGE_BIT_CPA_TEST _PAGE_BIT_SOFTW1
 #define _PAGE_BIT_HIDDEN   _PAGE_BIT_SOFTW3 /* hidden by kmemcheck */
 #define _PAGE_BIT_SOFT_DIRTY   _PAGE_BIT_SOFTW3 /* software dirty tracking */
-#define _PAGE_BIT_SOFTW4   58  /* available for programmer */
-#define _PAGE_BIT_DEVMAP   _PAGE_BIT_SOFTW4
-#define _PAGE_BIT_NX   63  /* No execute: only valid after cpuid 
check */
+#define _PAGE_BIT_DEVMAP   _PAGE_BIT_SOFTW4
 
 /* If _PAGE_BIT_PRESENT is clear, we use these: */
 /* - if the user mapped it with PROT_NONE; pte_present gives true */
@@ -47,6 +52,17 @@
 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
 #define _PAGE_SPECIAL  (_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
 #define _PAGE_CPA_TEST (_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
+#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
+#define _PAGE_PKEY_BIT0(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT0)
+#define _PAGE_PKEY_BIT1(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT1)
+#define _PAGE_PKEY_BIT2(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT2)
+#define _PAGE_PKEY_BIT3(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT3)
+#else
+#define _PAGE_PKEY_BIT0(_AT(pteval_t, 0))
+#define _PAGE_PKEY_BIT1(_AT(pteval_t, 0))
+#define _PAGE_PKEY_BIT2(_AT(pteval_t, 0))
+#define _PAGE_PKEY_BIT3(_AT(pteval_t, 0))
+#endif
 #define __HAVE_ARCH_PTE_SPECIAL
 
 #ifdef CONFIG_KMEMCHECK
_


[PATCH 07/31] x86, pkeys: PTE bits for storing protection key

2016-01-06 Thread Dave Hansen

From: Dave Hansen 

Previous documentation has referred to these 4 bits as "ignored".
That means that software could have made use of them.  But, as
far as I know, the kernel never used them.

They are still ignored when protection keys is not enabled, so
they could theoretically still get used for software purposes.

We also implement "empty" versions so that code that references
to them can be optimized away by the compiler when the config
option is not enabled.

Signed-off-by: Dave Hansen 
Reviewed-by: Thomas Gleixner 
---

 b/arch/x86/include/asm/pgtable_types.h |   17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff -puN arch/x86/include/asm/pgtable_types.h~pkeys-04-ptebits 
arch/x86/include/asm/pgtable_types.h
--- a/arch/x86/include/asm/pgtable_types.h~pkeys-04-ptebits 2016-01-06 
15:50:05.662158333 -0800
+++ b/arch/x86/include/asm/pgtable_types.h  2016-01-06 15:50:05.665158468 
-0800
@@ -25,7 +25,11 @@
 #define _PAGE_BIT_SPLITTING_PAGE_BIT_SOFTW2 /* only valid on a PSE pmd */
 #define _PAGE_BIT_HIDDEN   _PAGE_BIT_SOFTW3 /* hidden by kmemcheck */
 #define _PAGE_BIT_SOFT_DIRTY   _PAGE_BIT_SOFTW3 /* software dirty tracking */
-#define _PAGE_BIT_NX   63   /* No execute: only valid after cpuid 
check */
+#define _PAGE_BIT_PKEY_BIT059   /* Protection Keys, bit 1/4 */
+#define _PAGE_BIT_PKEY_BIT160   /* Protection Keys, bit 2/4 */
+#define _PAGE_BIT_PKEY_BIT261   /* Protection Keys, bit 3/4 */
+#define _PAGE_BIT_PKEY_BIT362   /* Protection Keys, bit 4/4 */
+#define _PAGE_BIT_NX   63   /* No execute: only valid after cpuid 
check */
 
 /* If _PAGE_BIT_PRESENT is clear, we use these: */
 /* - if the user mapped it with PROT_NONE; pte_present gives true */
@@ -47,6 +51,17 @@
 #define _PAGE_SPECIAL  (_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
 #define _PAGE_CPA_TEST (_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
 #define _PAGE_SPLITTING(_AT(pteval_t, 1) << _PAGE_BIT_SPLITTING)
+#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
+#define _PAGE_PKEY_BIT0(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT0)
+#define _PAGE_PKEY_BIT1(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT1)
+#define _PAGE_PKEY_BIT2(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT2)
+#define _PAGE_PKEY_BIT3(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT3)
+#else
+#define _PAGE_PKEY_BIT0(_AT(pteval_t, 0))
+#define _PAGE_PKEY_BIT1(_AT(pteval_t, 0))
+#define _PAGE_PKEY_BIT2(_AT(pteval_t, 0))
+#define _PAGE_PKEY_BIT3(_AT(pteval_t, 0))
+#endif
 #define __HAVE_ARCH_PTE_SPECIAL
 
 #ifdef CONFIG_KMEMCHECK
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/