Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1270819 > unrolled thread
| Started by | Dave Hansen <dave@sr71.net> |
|---|---|
| First post | 2015-11-17 04:50 +0100 |
| Last post | 2015-11-30 17:00 +0100 |
| 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.
[PATCH 17/37] x86, pkeys: add functions to fetch PKRU Dave Hansen <dave@sr71.net> - 2015-11-17 04:50 +0100
Re: [PATCH 17/37] x86, pkeys: add functions to fetch PKRU Thomas Gleixner <tglx@linutronix.de> - 2015-11-27 11:00 +0100
Re: [PATCH 17/37] x86, pkeys: add functions to fetch PKRU Dave Hansen <dave@sr71.net> - 2015-11-30 17:00 +0100
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-11-17 04:50 +0100 |
| Subject | [PATCH 17/37] x86, pkeys: add functions to fetch PKRU |
| Message-ID | <qvFrj-82I-5@gated-at.bofh.it> |
From: Dave Hansen <dave.hansen@linux.intel.com>
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>
---
b/arch/x86/include/asm/pgtable.h | 8 ++++++++
b/arch/x86/include/asm/special_insns.h | 20 ++++++++++++++++++++
2 files changed, 28 insertions(+)
diff -puN arch/x86/include/asm/pgtable.h~pkeys-13-kernel-pkru-instructions arch/x86/include/asm/pgtable.h
--- a/arch/x86/include/asm/pgtable.h~pkeys-13-kernel-pkru-instructions 2015-11-16 12:35:42.830511901 -0800
+++ b/arch/x86/include/asm/pgtable.h 2015-11-16 12:35:42.836512174 -0800
@@ -102,6 +102,14 @@ static inline int pte_dirty(pte_t pte)
return pte_flags(pte) & _PAGE_DIRTY;
}
+
+static inline u32 read_pkru(void)
+{
+ if (boot_cpu_has(X86_FEATURE_OSPKE))
+ return __read_pkru();
+ return 0;
+}
+
static inline int pte_young(pte_t pte)
{
return pte_flags(pte) & _PAGE_ACCESSED;
diff -puN arch/x86/include/asm/special_insns.h~pkeys-13-kernel-pkru-instructions arch/x86/include/asm/special_insns.h
--- a/arch/x86/include/asm/special_insns.h~pkeys-13-kernel-pkru-instructions 2015-11-16 12:35:42.832511992 -0800
+++ b/arch/x86/include/asm/special_insns.h 2015-11-16 12:35:42.836512174 -0800
@@ -98,6 +98,26 @@ static inline void native_write_cr8(unsi
}
#endif
+#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
+static inline u32 __read_pkru(void)
+{
+ unsigned int eax, edx;
+ unsigned int ecx = 0;
+ unsigned int pkru;
+
+ asm volatile(".byte 0x0f,0x01,0xee\n\t"
+ : "=a" (eax), "=d" (edx)
+ : "c" (ecx));
+ pkru = eax;
+ return pkru;
+}
+#else
+static inline u32 __read_pkru(void)
+{
+ return 0;
+}
+#endif
+
static inline void native_wbinvd(void)
{
asm volatile("wbinvd": : :"memory");
_
--
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]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2015-11-27 11:00 +0100 |
| Message-ID | <qznYR-18E-1@gated-at.bofh.it> |
| In reply to | #1270819 |
On Mon, 16 Nov 2015, Dave Hansen wrote:
> +#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
> +static inline u32 __read_pkru(void)
> +{
> + unsigned int eax, edx;
> + unsigned int ecx = 0;
> + unsigned int pkru;
> +
> + asm volatile(".byte 0x0f,0x01,0xee\n\t"
> + : "=a" (eax), "=d" (edx)
> + : "c" (ecx));
> + pkru = eax;
> + return pkru;
Wouldn't a simple 'return eax;' be sufficient?
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]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-11-30 17:00 +0100 |
| Message-ID | <qAz1U-5xV-17@gated-at.bofh.it> |
| In reply to | #1278684 |
On 11/27/2015 01:51 AM, Thomas Gleixner wrote:
> On Mon, 16 Nov 2015, Dave Hansen wrote:
>> +#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
>> +static inline u32 __read_pkru(void)
>> +{
>> + unsigned int eax, edx;
>> + unsigned int ecx = 0;
>> + unsigned int pkru;
>> +
>> + asm volatile(".byte 0x0f,0x01,0xee\n\t"
>> + : "=a" (eax), "=d" (edx)
>> + : "c" (ecx));
>> + pkru = eax;
>> + return pkru;
>
> Wouldn't a simple 'return eax;' be sufficient?
Yes. I wanted to make it clear that EAX specifically was where the data
we want was ending up. But, I guess the "=a" does that equally well.
I'll fix it up.
Also, looking at this, it also deserves a mention that this is the
"rdpkru" instruction. Otherwise, it's hard to figure out what
instruction this is.
--
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