Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751809AbbEGRlV (ORCPT ); Thu, 7 May 2015 13:41:21 -0400 Received: from mga09.intel.com ([134.134.136.24]:44531 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750793AbbEGRlT (ORCPT ); Thu, 7 May 2015 13:41:19 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,384,1427785200"; d="scan'208";a="706831902" Subject: [PATCH 01/12] x86, pkeys: cpuid bit definition To: dave@sr71.net Cc: linux-kernel@vger.kernel.org, x86@kernel.org From: Dave Hansen Date: Thu, 07 May 2015 10:41:33 -0700 References: <20150507174132.34AF8FAF@viggo.jf.intel.com> In-Reply-To: <20150507174132.34AF8FAF@viggo.jf.intel.com> Message-Id: <20150507174133.BA204DA1@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2522 Lines: 69 There are two CPUID bits for protection keys. One is for whether the CPU contains the feature, and the other will appear set once the OS enables protection keys. Specifically: Bit 04: OSPKE. If 1, OS has set CR4.PKE to enable Protection keys (and the RDPKRU/WRPKRU instructions) This is because userspace can not see CR4 contents, but it can see CPUID contents. X86_FEATURE_PKU is referred to as "PKU" in the hardware documentation: CPUID.(EAX=07H,ECX=0H):ECX.PKU [bit 3] X86_FEATURE_OSPKE is "OSPKU": CPUID.(EAX=07H,ECX=0H):ECX.OSPKE [bit 4] These are the first CPU features which need to look at the ECX word in CPUID leaf 0x7, so this patch also includes fetching that word in to the cpuinfo->x86_capability[] array. --- b/arch/x86/include/asm/cpufeature.h | 6 +++++- b/arch/x86/kernel/cpu/common.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff -puN arch/x86/include/asm/cpufeature.h~pkeys-0-cpuid arch/x86/include/asm/cpufeature.h --- a/arch/x86/include/asm/cpufeature.h~pkeys-0-cpuid 2015-05-07 10:31:40.985169281 -0700 +++ b/arch/x86/include/asm/cpufeature.h 2015-05-07 10:31:40.991169552 -0700 @@ -12,7 +12,7 @@ #include #endif -#define NCAPINTS 13 /* N 32-bit words worth of info */ +#define NCAPINTS 14 /* N 32-bit words worth of info */ #define NBUGINTS 1 /* N 32-bit bug flags */ /* @@ -252,6 +252,10 @@ /* Intel-defined CPU QoS Sub-leaf, CPUID level 0x0000000F:1 (edx), word 12 */ #define X86_FEATURE_CQM_OCCUP_LLC (12*32+ 0) /* LLC occupancy monitoring if 1 */ +/* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 13 */ +#define X86_FEATURE_PKU (13*32+ 3) /* Protection Keys for Userspace */ +#define X86_FEATURE_OSPKE (13*32+ 4) /* OS Protection Keys Enable */ + /* * BUG word(s) */ diff -puN arch/x86/kernel/cpu/common.c~pkeys-0-cpuid arch/x86/kernel/cpu/common.c --- a/arch/x86/kernel/cpu/common.c~pkeys-0-cpuid 2015-05-07 10:31:40.987169371 -0700 +++ b/arch/x86/kernel/cpu/common.c 2015-05-07 10:31:40.991169552 -0700 @@ -635,6 +635,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c) cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx); c->x86_capability[9] = ebx; + c->x86_capability[13] = ecx; } /* Extended state features: level 0x0000000d */ _ -- 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/