1 From 03bbd596ac04fef47ce93a730b8f086d797c3021 Mon Sep 17 00:00:00 2001
2 From: "H. Peter Anvin" <hpa@linux.intel.com>
3 Date: Thu, 13 Feb 2014 07:34:30 -0800
4 Subject: x86, smap: Don't enable SMAP if CONFIG_X86_SMAP is disabled
6 From: "H. Peter Anvin" <hpa@linux.intel.com>
8 commit 03bbd596ac04fef47ce93a730b8f086d797c3021 upstream.
10 If SMAP support is not compiled into the kernel, don't enable SMAP in
11 CR4 -- in fact, we should clear it, because the kernel doesn't contain
12 the proper STAC/CLAC instructions for SMAP support.
14 Found by Fengguang Wu's test system.
16 Reported-by: Fengguang Wu <fengguang.wu@intel.com>
17 Link: http://lkml.kernel.org/r/20140213124550.GA30497@localhost
18 Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 arch/x86/kernel/cpu/common.c | 7 ++++++-
23 1 file changed, 6 insertions(+), 1 deletion(-)
25 --- a/arch/x86/kernel/cpu/common.c
26 +++ b/arch/x86/kernel/cpu/common.c
27 @@ -284,8 +284,13 @@ static __always_inline void setup_smap(s
28 raw_local_save_flags(eflags);
29 BUG_ON(eflags & X86_EFLAGS_AC);
31 - if (cpu_has(c, X86_FEATURE_SMAP))
32 + if (cpu_has(c, X86_FEATURE_SMAP)) {
33 +#ifdef CONFIG_X86_SMAP
34 set_in_cr4(X86_CR4_SMAP);
36 + clear_in_cr4(X86_CR4_SMAP);