Skip to content

Commit 70486fa

Browse files
hansendcZhengShunQian
authored andcommitted
x86/cpufeature, x86/mm/pkeys: Fix broken compile-time disabling of pkeys
commit e8df1a9 upstream When I added support for the Memory Protection Keys processor feature, I had to reindent the REQUIRED/DISABLED_MASK macros, and also consult the later cpufeature words. I'm not quite sure how I bungled it, but I consulted the wrong word at the end. This only affected required or disabled cpu features in cpufeature words 14, 15 and 16. So, only Protection Keys itself was screwed over here. The result was that if you disabled pkeys in your .config, you might still see some code show up that should have been compiled out. There should be no functional problems, though. In verifying this patch I also realized that the DISABLE_PKU/OSPKE macros were defined backwards and that the cpu_has() check in setup_pku() was not doing the compile-time disabled checks. So also fix the macro for DISABLE_PKU/OSPKE and add a compile-time check for pkeys being enabled in setup_pku(). Signed-off-by: Dave Hansen <[email protected]> Cc: <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vince Weaver <[email protected]> Fixes: dfb4a70 ("x86/cpufeature, x86/mm/pkeys: Add protection keys related CPUID definitions") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Srivatsa S. Bhat <[email protected]> Reviewed-by: Matt Helsley (VMware) <[email protected]> Reviewed-by: Alexey Makhalov <[email protected]> Reviewed-by: Bo Gan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6ff5598 commit 70486fa

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

arch/x86/include/asm/cpufeature.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
6464
(((bit)>>5)==11 && (1UL<<((bit)&31) & REQUIRED_MASK11)) || \
6565
(((bit)>>5)==12 && (1UL<<((bit)&31) & REQUIRED_MASK12)) || \
6666
(((bit)>>5)==13 && (1UL<<((bit)&31) & REQUIRED_MASK13)) || \
67-
(((bit)>>5)==13 && (1UL<<((bit)&31) & REQUIRED_MASK14)) || \
68-
(((bit)>>5)==13 && (1UL<<((bit)&31) & REQUIRED_MASK15)) || \
69-
(((bit)>>5)==14 && (1UL<<((bit)&31) & REQUIRED_MASK16)) )
67+
(((bit)>>5)==14 && (1UL<<((bit)&31) & REQUIRED_MASK14)) || \
68+
(((bit)>>5)==15 && (1UL<<((bit)&31) & REQUIRED_MASK15)) || \
69+
(((bit)>>5)==16 && (1UL<<((bit)&31) & REQUIRED_MASK16)) )
7070

7171
#define DISABLED_MASK_BIT_SET(bit) \
7272
( (((bit)>>5)==0 && (1UL<<((bit)&31) & DISABLED_MASK0 )) || \
@@ -83,9 +83,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
8383
(((bit)>>5)==11 && (1UL<<((bit)&31) & DISABLED_MASK11)) || \
8484
(((bit)>>5)==12 && (1UL<<((bit)&31) & DISABLED_MASK12)) || \
8585
(((bit)>>5)==13 && (1UL<<((bit)&31) & DISABLED_MASK13)) || \
86-
(((bit)>>5)==13 && (1UL<<((bit)&31) & DISABLED_MASK14)) || \
87-
(((bit)>>5)==13 && (1UL<<((bit)&31) & DISABLED_MASK15)) || \
88-
(((bit)>>5)==14 && (1UL<<((bit)&31) & DISABLED_MASK16)) )
86+
(((bit)>>5)==14 && (1UL<<((bit)&31) & DISABLED_MASK14)) || \
87+
(((bit)>>5)==15 && (1UL<<((bit)&31) & DISABLED_MASK15)) || \
88+
(((bit)>>5)==16 && (1UL<<((bit)&31) & DISABLED_MASK16)) )
8989

9090
#define cpu_has(c, bit) \
9191
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \

arch/x86/include/asm/disabled-features.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
#endif /* CONFIG_X86_64 */
3232

3333
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
34-
# define DISABLE_PKU (1<<(X86_FEATURE_PKU))
35-
# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE))
36-
#else
3734
# define DISABLE_PKU 0
3835
# define DISABLE_OSPKE 0
36+
#else
37+
# define DISABLE_PKU (1<<(X86_FEATURE_PKU & 31))
38+
# define DISABLE_OSPKE (1<<(X86_FEATURE_OSPKE & 31))
3939
#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */
4040

4141
/*

0 commit comments

Comments
 (0)