aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-10-24 18:58:07 -0400
committerIngo Molnar <mingo@kernel.org>2015-02-04 06:10:41 -0500
commit375074cc736ab1d89a708c0a8d7baa4a70d5d476 (patch)
treee7ceb81f6fc54814fc57716a79f8d232f5e6afb8 /arch/x86/kernel
parent0967160ad615985c7c35443156ea9aecc60c37b8 (diff)
x86: Clean up cr4 manipulation
CR4 manipulation was split, seemingly at random, between direct (write_cr4) and using a helper (set/clear_in_cr4). Unfortunately, the set_in_cr4 and clear_in_cr4 helpers also poke at the boot code, which only a small subset of users actually wanted. This patch replaces all cr4 access in functions that don't leave cr4 exactly the way they found it with new helpers cr4_set_bits, cr4_clear_bits, and cr4_set_bits_and_update_boot. Signed-off-by: Andy Lutomirski <luto@amacapital.net> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Vince Weaver <vince@deater.net> Cc: "hillf.zj" <hillf.zj@alibaba-inc.com> Cc: Valdis Kletnieks <Valdis.Kletnieks@vt.edu> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/495a10bdc9e67016b8fd3945700d46cfd5c12c2f.1414190806.git.luto@amacapital.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r--arch/x86/kernel/cpu/common.c10
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c3
-rw-r--r--arch/x86/kernel/cpu/mcheck/p5.c3
-rw-r--r--arch/x86/kernel/cpu/mcheck/winchip.c3
-rw-r--r--arch/x86/kernel/cpu/perf_event.c7
-rw-r--r--arch/x86/kernel/i387.c3
-rw-r--r--arch/x86/kernel/process.c5
-rw-r--r--arch/x86/kernel/xsave.c3
8 files changed, 22 insertions, 15 deletions
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index c6049650c093..9d8fc49f0922 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -278,7 +278,7 @@ __setup("nosmep", setup_disable_smep);
278static __always_inline void setup_smep(struct cpuinfo_x86 *c) 278static __always_inline void setup_smep(struct cpuinfo_x86 *c)
279{ 279{
280 if (cpu_has(c, X86_FEATURE_SMEP)) 280 if (cpu_has(c, X86_FEATURE_SMEP))
281 set_in_cr4(X86_CR4_SMEP); 281 cr4_set_bits(X86_CR4_SMEP);
282} 282}
283 283
284static __init int setup_disable_smap(char *arg) 284static __init int setup_disable_smap(char *arg)
@@ -298,9 +298,9 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
298 298
299 if (cpu_has(c, X86_FEATURE_SMAP)) { 299 if (cpu_has(c, X86_FEATURE_SMAP)) {
300#ifdef CONFIG_X86_SMAP 300#ifdef CONFIG_X86_SMAP
301 set_in_cr4(X86_CR4_SMAP); 301 cr4_set_bits(X86_CR4_SMAP);
302#else 302#else
303 clear_in_cr4(X86_CR4_SMAP); 303 cr4_clear_bits(X86_CR4_SMAP);
304#endif 304#endif
305 } 305 }
306} 306}
@@ -1312,7 +1312,7 @@ void cpu_init(void)
1312 1312
1313 pr_debug("Initializing CPU#%d\n", cpu); 1313 pr_debug("Initializing CPU#%d\n", cpu);
1314 1314
1315 clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE); 1315 cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
1316 1316
1317 /* 1317 /*
1318 * Initialize the per-CPU GDT with the boot GDT, 1318 * Initialize the per-CPU GDT with the boot GDT,
@@ -1393,7 +1393,7 @@ void cpu_init(void)
1393 printk(KERN_INFO "Initializing CPU#%d\n", cpu); 1393 printk(KERN_INFO "Initializing CPU#%d\n", cpu);
1394 1394
1395 if (cpu_feature_enabled(X86_FEATURE_VME) || cpu_has_tsc || cpu_has_de) 1395 if (cpu_feature_enabled(X86_FEATURE_VME) || cpu_has_tsc || cpu_has_de)
1396 clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE); 1396 cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
1397 1397
1398 load_current_idt(); 1398 load_current_idt();
1399 switch_to_new_gdt(cpu); 1399 switch_to_new_gdt(cpu);
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index d23179900755..15ad3ed1a3cd 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -44,6 +44,7 @@
44 44
45#include <asm/processor.h> 45#include <asm/processor.h>
46#include <asm/traps.h> 46#include <asm/traps.h>
47#include <asm/tlbflush.h>
47#include <asm/mce.h> 48#include <asm/mce.h>
48#include <asm/msr.h> 49#include <asm/msr.h>
49 50
@@ -1449,7 +1450,7 @@ static void __mcheck_cpu_init_generic(void)
1449 bitmap_fill(all_banks, MAX_NR_BANKS); 1450 bitmap_fill(all_banks, MAX_NR_BANKS);
1450 machine_check_poll(MCP_UC | m_fl, &all_banks); 1451 machine_check_poll(MCP_UC | m_fl, &all_banks);
1451 1452
1452 set_in_cr4(X86_CR4_MCE); 1453 cr4_set_bits(X86_CR4_MCE);
1453 1454
1454 rdmsrl(MSR_IA32_MCG_CAP, cap); 1455 rdmsrl(MSR_IA32_MCG_CAP, cap);
1455 if (cap & MCG_CTL_P) 1456 if (cap & MCG_CTL_P)
diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
index ec2663a708e4..737b0ad4e61a 100644
--- a/arch/x86/kernel/cpu/mcheck/p5.c
+++ b/arch/x86/kernel/cpu/mcheck/p5.c
@@ -9,6 +9,7 @@
9 9
10#include <asm/processor.h> 10#include <asm/processor.h>
11#include <asm/traps.h> 11#include <asm/traps.h>
12#include <asm/tlbflush.h>
12#include <asm/mce.h> 13#include <asm/mce.h>
13#include <asm/msr.h> 14#include <asm/msr.h>
14 15
@@ -65,7 +66,7 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
65 "Intel old style machine check architecture supported.\n"); 66 "Intel old style machine check architecture supported.\n");
66 67
67 /* Enable MCE: */ 68 /* Enable MCE: */
68 set_in_cr4(X86_CR4_MCE); 69 cr4_set_bits(X86_CR4_MCE);
69 printk(KERN_INFO 70 printk(KERN_INFO
70 "Intel old style machine check reporting enabled on CPU#%d.\n", 71 "Intel old style machine check reporting enabled on CPU#%d.\n",
71 smp_processor_id()); 72 smp_processor_id());
diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
index bd5d46a32210..44f138296fbe 100644
--- a/arch/x86/kernel/cpu/mcheck/winchip.c
+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
@@ -8,6 +8,7 @@
8 8
9#include <asm/processor.h> 9#include <asm/processor.h>
10#include <asm/traps.h> 10#include <asm/traps.h>
11#include <asm/tlbflush.h>
11#include <asm/mce.h> 12#include <asm/mce.h>
12#include <asm/msr.h> 13#include <asm/msr.h>
13 14
@@ -36,7 +37,7 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
36 lo &= ~(1<<4); /* Enable MCE */ 37 lo &= ~(1<<4); /* Enable MCE */
37 wrmsr(MSR_IDT_FCR1, lo, hi); 38 wrmsr(MSR_IDT_FCR1, lo, hi);
38 39
39 set_in_cr4(X86_CR4_MCE); 40 cr4_set_bits(X86_CR4_MCE);
40 41
41 printk(KERN_INFO 42 printk(KERN_INFO
42 "Winchip machine check reporting enabled on CPU#0.\n"); 43 "Winchip machine check reporting enabled on CPU#0.\n");
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 143e5f5dc855..6b5acd5f4a34 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -31,6 +31,7 @@
31#include <asm/nmi.h> 31#include <asm/nmi.h>
32#include <asm/smp.h> 32#include <asm/smp.h>
33#include <asm/alternative.h> 33#include <asm/alternative.h>
34#include <asm/tlbflush.h>
34#include <asm/timer.h> 35#include <asm/timer.h>
35#include <asm/desc.h> 36#include <asm/desc.h>
36#include <asm/ldt.h> 37#include <asm/ldt.h>
@@ -1328,7 +1329,7 @@ x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
1328 1329
1329 case CPU_STARTING: 1330 case CPU_STARTING:
1330 if (x86_pmu.attr_rdpmc) 1331 if (x86_pmu.attr_rdpmc)
1331 set_in_cr4(X86_CR4_PCE); 1332 cr4_set_bits(X86_CR4_PCE);
1332 if (x86_pmu.cpu_starting) 1333 if (x86_pmu.cpu_starting)
1333 x86_pmu.cpu_starting(cpu); 1334 x86_pmu.cpu_starting(cpu);
1334 break; 1335 break;
@@ -1834,9 +1835,9 @@ static void change_rdpmc(void *info)
1834 bool enable = !!(unsigned long)info; 1835 bool enable = !!(unsigned long)info;
1835 1836
1836 if (enable) 1837 if (enable)
1837 set_in_cr4(X86_CR4_PCE); 1838 cr4_set_bits(X86_CR4_PCE);
1838 else 1839 else
1839 clear_in_cr4(X86_CR4_PCE); 1840 cr4_clear_bits(X86_CR4_PCE);
1840} 1841}
1841 1842
1842static ssize_t set_attr_rdpmc(struct device *cdev, 1843static ssize_t set_attr_rdpmc(struct device *cdev,
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index a9a4229f6161..87727b03196d 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -13,6 +13,7 @@
13#include <asm/sigcontext.h> 13#include <asm/sigcontext.h>
14#include <asm/processor.h> 14#include <asm/processor.h>
15#include <asm/math_emu.h> 15#include <asm/math_emu.h>
16#include <asm/tlbflush.h>
16#include <asm/uaccess.h> 17#include <asm/uaccess.h>
17#include <asm/ptrace.h> 18#include <asm/ptrace.h>
18#include <asm/i387.h> 19#include <asm/i387.h>
@@ -180,7 +181,7 @@ void fpu_init(void)
180 if (cpu_has_xmm) 181 if (cpu_has_xmm)
181 cr4_mask |= X86_CR4_OSXMMEXCPT; 182 cr4_mask |= X86_CR4_OSXMMEXCPT;
182 if (cr4_mask) 183 if (cr4_mask)
183 set_in_cr4(cr4_mask); 184 cr4_set_bits(cr4_mask);
184 185
185 cr0 = read_cr0(); 186 cr0 = read_cr0();
186 cr0 &= ~(X86_CR0_TS|X86_CR0_EM); /* clear TS and EM */ 187 cr0 &= ~(X86_CR0_TS|X86_CR0_EM); /* clear TS and EM */
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index e127ddaa2d5a..046e2d620bbe 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -28,6 +28,7 @@
28#include <asm/fpu-internal.h> 28#include <asm/fpu-internal.h>
29#include <asm/debugreg.h> 29#include <asm/debugreg.h>
30#include <asm/nmi.h> 30#include <asm/nmi.h>
31#include <asm/tlbflush.h>
31 32
32/* 33/*
33 * per-CPU TSS segments. Threads are completely 'soft' on Linux, 34 * per-CPU TSS segments. Threads are completely 'soft' on Linux,
@@ -141,7 +142,7 @@ void flush_thread(void)
141 142
142static void hard_disable_TSC(void) 143static void hard_disable_TSC(void)
143{ 144{
144 write_cr4(read_cr4() | X86_CR4_TSD); 145 cr4_set_bits(X86_CR4_TSD);
145} 146}
146 147
147void disable_TSC(void) 148void disable_TSC(void)
@@ -158,7 +159,7 @@ void disable_TSC(void)
158 159
159static void hard_enable_TSC(void) 160static void hard_enable_TSC(void)
160{ 161{
161 write_cr4(read_cr4() & ~X86_CR4_TSD); 162 cr4_clear_bits(X86_CR4_TSD);
162} 163}
163 164
164static void enable_TSC(void) 165static void enable_TSC(void)
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
index 0de1fae2bdf0..34f66e58a896 100644
--- a/arch/x86/kernel/xsave.c
+++ b/arch/x86/kernel/xsave.c
@@ -12,6 +12,7 @@
12#include <asm/i387.h> 12#include <asm/i387.h>
13#include <asm/fpu-internal.h> 13#include <asm/fpu-internal.h>
14#include <asm/sigframe.h> 14#include <asm/sigframe.h>
15#include <asm/tlbflush.h>
15#include <asm/xcr.h> 16#include <asm/xcr.h>
16 17
17/* 18/*
@@ -453,7 +454,7 @@ static void prepare_fx_sw_frame(void)
453 */ 454 */
454static inline void xstate_enable(void) 455static inline void xstate_enable(void)
455{ 456{
456 set_in_cr4(X86_CR4_OSXSAVE); 457 cr4_set_bits(X86_CR4_OSXSAVE);
457 xsetbv(XCR_XFEATURE_ENABLED_MASK, pcntxt_mask); 458 xsetbv(XCR_XFEATURE_ENABLED_MASK, pcntxt_mask);
458} 459}
459 460