aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hansen <dave.hansen@linux.intel.com>2016-02-12 16:02:15 -0500
committerIngo Molnar <mingo@kernel.org>2016-02-18 03:32:43 -0500
commita927cb83f3300bcb1ae18672e58029acddd18b33 (patch)
tree942413064ab6adbf26405c9ebac038f405db2fa5
parent019132ff3daf36c97a4006655dfd00ee42f2b590 (diff)
x86/mm/pkeys: Add functions to fetch PKRU
This adds the raw instruction to access PKRU as well as some accessor functions that correctly handle when the CPU does not support the instruction. We don't use it here, but we will use read_pkru() in the next patch. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave@sr71.net> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20160212210215.15238D34@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/include/asm/pgtable.h8
-rw-r--r--arch/x86/include/asm/special_insns.h22
2 files changed, 30 insertions, 0 deletions
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 0687c4748b8f..e997dcc6ee2b 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -99,6 +99,14 @@ static inline int pte_dirty(pte_t pte)
99 return pte_flags(pte) & _PAGE_DIRTY; 99 return pte_flags(pte) & _PAGE_DIRTY;
100} 100}
101 101
102
103static inline u32 read_pkru(void)
104{
105 if (boot_cpu_has(X86_FEATURE_OSPKE))
106 return __read_pkru();
107 return 0;
108}
109
102static inline int pte_young(pte_t pte) 110static inline int pte_young(pte_t pte)
103{ 111{
104 return pte_flags(pte) & _PAGE_ACCESSED; 112 return pte_flags(pte) & _PAGE_ACCESSED;
diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 2270e41b32fd..aee6e76e561e 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -98,6 +98,28 @@ static inline void native_write_cr8(unsigned long val)
98} 98}
99#endif 99#endif
100 100
101#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
102static inline u32 __read_pkru(void)
103{
104 u32 ecx = 0;
105 u32 edx, pkru;
106
107 /*
108 * "rdpkru" instruction. Places PKRU contents in to EAX,
109 * clears EDX and requires that ecx=0.
110 */
111 asm volatile(".byte 0x0f,0x01,0xee\n\t"
112 : "=a" (pkru), "=d" (edx)
113 : "c" (ecx));
114 return pkru;
115}
116#else
117static inline u32 __read_pkru(void)
118{
119 return 0;
120}
121#endif
122
101static inline void native_wbinvd(void) 123static inline void native_wbinvd(void)
102{ 124{
103 asm volatile("wbinvd": : :"memory"); 125 asm volatile("wbinvd": : :"memory");