From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948234AbcBRU0Q (ORCPT ); Thu, 18 Feb 2016 15:26:16 -0500 Received: from terminus.zytor.com ([198.137.202.10]:47268 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1947701AbcBRU0N (ORCPT ); Thu, 18 Feb 2016 15:26:13 -0500 Date: Thu, 18 Feb 2016 12:25:09 -0800 From: tip-bot for Dave Hansen Message-ID: Cc: mingo@kernel.org, akpm@linux-foundation.org, riel@redhat.com, tglx@linutronix.de, torvalds@linux-foundation.org, dvlasenk@redhat.com, luto@amacapital.net, linux-kernel@vger.kernel.org, bp@alien8.de, dave@sr71.net, brgerst@gmail.com, hpa@zytor.com, peterz@infradead.org, dave.hansen@linux.intel.com Reply-To: torvalds@linux-foundation.org, dvlasenk@redhat.com, tglx@linutronix.de, riel@redhat.com, mingo@kernel.org, akpm@linux-foundation.org, hpa@zytor.com, dave.hansen@linux.intel.com, peterz@infradead.org, brgerst@gmail.com, dave@sr71.net, bp@alien8.de, luto@amacapital.net, linux-kernel@vger.kernel.org In-Reply-To: <20160212210229.6708027C@viggo.jf.intel.com> References: <20160212210229.6708027C@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:mm/pkeys] x86/mm/pkeys: Actually enable Memory Protection Keys in the CPU Git-Commit-ID: 0697694564c84f4c9320e5d103d0191297a20023 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: 0697694564c84f4c9320e5d103d0191297a20023 Gitweb: http://git.kernel.org/tip/0697694564c84f4c9320e5d103d0191297a20023 Author: Dave Hansen AuthorDate: Fri, 12 Feb 2016 13:02:29 -0800 Committer: Ingo Molnar CommitDate: Thu, 18 Feb 2016 19:46:30 +0100 x86/mm/pkeys: Actually enable Memory Protection Keys in the CPU This sets the bit in 'cr4' to actually enable the protection keys feature. We also include a boot-time disable for the feature "nopku". Seting X86_CR4_PKE will cause the X86_FEATURE_OSPKE cpuid bit to appear set. At this point in boot, identify_cpu() has already run the actual CPUID instructions and populated the "cpu features" structures. We need to go back and re-run identify_cpu() to make sure it gets updated values. We *could* simply re-populate the 11th word of the cpuid data, but this is probably quick enough. Also note that with the cpu_has() check and X86_FEATURE_PKU present in disabled-features.h, we do not need an #ifdef for setup_pku(). 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/20160212210229.6708027C@viggo.jf.intel.com [ Small readability edits. ] Signed-off-by: Ingo Molnar --- Documentation/kernel-parameters.txt | 3 +++ arch/x86/kernel/cpu/common.c | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index a37b5bb..acf467d 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -976,6 +976,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. See Documentation/x86/intel_mpx.txt for more information about the feature. + nopku [X86] Disable Memory Protection Keys CPU feature found + in some Intel CPUs. + eagerfpu= [X86] on enable eager fpu restore off disable eager fpu restore diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index a719ad7..4fac263 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -304,6 +304,48 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c) } /* + * Protection Keys are not available in 32-bit mode. + */ +static bool pku_disabled; + +static __always_inline void setup_pku(struct cpuinfo_x86 *c) +{ + if (!cpu_has(c, X86_FEATURE_PKU)) + return; + if (pku_disabled) + return; + + cr4_set_bits(X86_CR4_PKE); + /* + * Seting X86_CR4_PKE will cause the X86_FEATURE_OSPKE + * cpuid bit to be set. We need to ensure that we + * update that bit in this CPU's "cpu_info". + */ + get_cpu_cap(c); +} + +#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS +static __init int setup_disable_pku(char *arg) +{ + /* + * Do not clear the X86_FEATURE_PKU bit. All of the + * runtime checks are against OSPKE so clearing the + * bit does nothing. + * + * This way, we will see "pku" in cpuinfo, but not + * "ospke", which is exactly what we want. It shows + * that the CPU has PKU, but the OS has not enabled it. + * This happens to be exactly how a system would look + * if we disabled the config option. + */ + pr_info("x86: 'nopku' specified, disabling Memory Protection Keys\n"); + pku_disabled = true; + return 1; +} +__setup("nopku", setup_disable_pku); +#endif /* CONFIG_X86_64 */ + +/* * Some CPU features depend on higher CPUID levels, which may not always * be available due to CPUID level capping or broken virtualization * software. Add those features to this table to auto-disable them. @@ -960,6 +1002,7 @@ static void identify_cpu(struct cpuinfo_x86 *c) init_hypervisor(c); x86_init_rdrand(c); x86_init_cache_qos(c); + setup_pku(c); /* * Clear/Set all flags overriden by options, need do it