aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/mm
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-10-24 18:58:08 -0400
committerIngo Molnar <mingo@kernel.org>2015-02-04 06:10:42 -0500
commit1e02ce4cccdcb9688386e5b8d2c9fa4660b45389 (patch)
tree7d514286844acea505228590119ac1a886cf6995 /arch/x86/mm
parent375074cc736ab1d89a708c0a8d7baa4a70d5d476 (diff)
x86: Store a per-cpu shadow copy of CR4
Context switches and TLB flushes can change individual bits of CR4. CR4 reads take several cycles, so store a shadow copy of CR4 in a per-cpu variable. To avoid wasting a cache line, I added the CR4 shadow to cpu_tlbstate, which is already touched in switch_mm. The heaviest users of the cr4 shadow will be switch_mm and __switch_to_xtra, and __switch_to_xtra is called shortly after switch_mm during context switch, so the cacheline is likely to be hot. 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: Kees Cook <keescook@chromium.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: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/3a54dd3353fffbf84804398e00dfdc5b7c1afd7d.1414190806.git.luto@amacapital.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/mm')
-rw-r--r--arch/x86/mm/fault.c2
-rw-r--r--arch/x86/mm/init.c9
-rw-r--r--arch/x86/mm/tlb.c3
3 files changed, 10 insertions, 4 deletions
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index e3ff27a5b634..ede025fb46f1 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -600,7 +600,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
600 printk(nx_warning, from_kuid(&init_user_ns, current_uid())); 600 printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
601 if (pte && pte_present(*pte) && pte_exec(*pte) && 601 if (pte && pte_present(*pte) && pte_exec(*pte) &&
602 (pgd_flags(*pgd) & _PAGE_USER) && 602 (pgd_flags(*pgd) & _PAGE_USER) &&
603 (read_cr4() & X86_CR4_SMEP)) 603 (__read_cr4() & X86_CR4_SMEP))
604 printk(smep_warning, from_kuid(&init_user_ns, current_uid())); 604 printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
605 } 605 }
606 606
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index d4eddbd92c28..a74aa0fd1853 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -713,6 +713,15 @@ void __init zone_sizes_init(void)
713 free_area_init_nodes(max_zone_pfns); 713 free_area_init_nodes(max_zone_pfns);
714} 714}
715 715
716DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate) = {
717#ifdef CONFIG_SMP
718 .active_mm = &init_mm,
719 .state = 0,
720#endif
721 .cr4 = ~0UL, /* fail hard if we screw up cr4 shadow initialization */
722};
723EXPORT_SYMBOL_GPL(cpu_tlbstate);
724
716void update_cache_mode_entry(unsigned entry, enum page_cache_mode cache) 725void update_cache_mode_entry(unsigned entry, enum page_cache_mode cache)
717{ 726{
718 /* entry 0 MUST be WB (hardwired to speed up translations) */ 727 /* entry 0 MUST be WB (hardwired to speed up translations) */
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index ee61c36d64f8..3250f2371aea 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -14,9 +14,6 @@
14#include <asm/uv/uv.h> 14#include <asm/uv/uv.h>
15#include <linux/debugfs.h> 15#include <linux/debugfs.h>
16 16
17DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate)
18 = { &init_mm, 0, };
19
20/* 17/*
21 * Smarter SMP flushing macros. 18 * Smarter SMP flushing macros.
22 * c/o Linus Torvalds. 19 * c/o Linus Torvalds.