Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/cpufeatures, x86/fault: Mark SMAP as disabled when configured out

Add X86_FEATURE_SMAP to the disabled features mask as appropriate
and use cpu_feature_enabled() in the fault code. This lets us get
rid of a redundant IS_ENABLED(CONFIG_X86_SMAP).

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yu-cheng Yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/fe93332eded3d702f0b0b4cf83928d6830739ba3.1542667307.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
dae0a105 6344be60

+8 -5
+7 -1
arch/x86/include/asm/disabled-features.h
··· 16 16 # define DISABLE_MPX (1<<(X86_FEATURE_MPX & 31)) 17 17 #endif 18 18 19 + #ifdef CONFIG_X86_SMAP 20 + # define DISABLE_SMAP 0 21 + #else 22 + # define DISABLE_SMAP (1<<(X86_FEATURE_SMAP & 31)) 23 + #endif 24 + 19 25 #ifdef CONFIG_X86_INTEL_UMIP 20 26 # define DISABLE_UMIP 0 21 27 #else ··· 74 68 #define DISABLED_MASK6 0 75 69 #define DISABLED_MASK7 (DISABLE_PTI) 76 70 #define DISABLED_MASK8 0 77 - #define DISABLED_MASK9 (DISABLE_MPX) 71 + #define DISABLED_MASK9 (DISABLE_MPX|DISABLE_SMAP) 78 72 #define DISABLED_MASK10 0 79 73 #define DISABLED_MASK11 0 80 74 #define DISABLED_MASK12 0
+1 -4
arch/x86/mm/fault.c
··· 1150 1150 1151 1151 static inline bool smap_violation(int error_code, struct pt_regs *regs) 1152 1152 { 1153 - if (!IS_ENABLED(CONFIG_X86_SMAP)) 1154 - return false; 1155 - 1156 - if (!static_cpu_has(X86_FEATURE_SMAP)) 1153 + if (!cpu_feature_enabled(X86_FEATURE_SMAP)) 1157 1154 return false; 1158 1155 1159 1156 if (error_code & X86_PF_USER)