From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948067AbcBRUW2 (ORCPT ); Thu, 18 Feb 2016 15:22:28 -0500 Received: from terminus.zytor.com ([198.137.202.10]:46992 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1947158AbcBRUWM (ORCPT ); Thu, 18 Feb 2016 15:22:12 -0500 Date: Thu, 18 Feb 2016 12:21:09 -0800 From: tip-bot for Dave Hansen Message-ID: Cc: tglx@linutronix.de, dave@sr71.net, linux-kernel@vger.kernel.org, brgerst@gmail.com, dave.hansen@linux.intel.com, torvalds@linux-foundation.org, akpm@linux-foundation.org, bp@alien8.de, dvlasenk@redhat.com, riel@redhat.com, mingo@kernel.org, peterz@infradead.org, luto@amacapital.net, hpa@zytor.com Reply-To: peterz@infradead.org, hpa@zytor.com, luto@amacapital.net, riel@redhat.com, mingo@kernel.org, bp@alien8.de, dvlasenk@redhat.com, akpm@linux-foundation.org, torvalds@linux-foundation.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, dave@sr71.net, dave.hansen@linux.intel.com, brgerst@gmail.com In-Reply-To: <20160212210215.15238D34@viggo.jf.intel.com> References: <20160212210215.15238D34@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:mm/pkeys] x86/mm/pkeys: Add functions to fetch PKRU Git-Commit-ID: a927cb83f3300bcb1ae18672e58029acddd18b33 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: a927cb83f3300bcb1ae18672e58029acddd18b33 Gitweb: http://git.kernel.org/tip/a927cb83f3300bcb1ae18672e58029acddd18b33 Author: Dave Hansen AuthorDate: Fri, 12 Feb 2016 13:02:15 -0800 Committer: Ingo Molnar CommitDate: Thu, 18 Feb 2016 09:32:43 +0100 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 Reviewed-by: Thomas Gleixner Cc: Andrew Morton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rik van Riel Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20160212210215.15238D34@viggo.jf.intel.com Signed-off-by: Ingo Molnar --- arch/x86/include/asm/pgtable.h | 8 ++++++++ arch/x86/include/asm/special_insns.h | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 0687c47..e997dcc 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) 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 --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h index 2270e41..aee6e76 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) } #endif +#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS +static inline u32 __read_pkru(void) +{ + u32 ecx = 0; + u32 edx, pkru; + + /* + * "rdpkru" instruction. Places PKRU contents in to EAX, + * clears EDX and requires that ecx=0. + */ + asm volatile(".byte 0x0f,0x01,0xee\n\t" + : "=a" (pkru), "=d" (edx) + : "c" (ecx)); + return pkru; +} +#else +static inline u32 __read_pkru(void) +{ + return 0; +} +#endif + static inline void native_wbinvd(void) { asm volatile("wbinvd": : :"memory");