| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- From 7cc2d98148d5b5be191f4dbf4c29d4d6da93a9f8 Mon Sep 17 00:00:00 2001
- From: Dave Hansen <[email protected]>
- Date: Mon, 4 Dec 2017 15:07:58 +0100
- Subject: [PATCH 208/242] x86/mm: Abstract switching CR3
- MIME-Version: 1.0
- Content-Type: text/plain; charset=UTF-8
- Content-Transfer-Encoding: 8bit
- CVE-2017-5754
- In preparation to adding additional PCID flushing, abstract the
- loading of a new ASID into CR3.
- [ PeterZ: Split out from big combo patch ]
- Signed-off-by: Dave Hansen <[email protected]>
- Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
- Signed-off-by: Thomas Gleixner <[email protected]>
- Cc: Andy Lutomirski <[email protected]>
- Cc: Boris Ostrovsky <[email protected]>
- Cc: Borislav Petkov <[email protected]>
- Cc: Brian Gerst <[email protected]>
- Cc: David Laight <[email protected]>
- Cc: Denys Vlasenko <[email protected]>
- Cc: Eduardo Valentin <[email protected]>
- Cc: Greg KH <[email protected]>
- Cc: H. Peter Anvin <[email protected]>
- Cc: Josh Poimboeuf <[email protected]>
- Cc: Juergen Gross <[email protected]>
- Cc: Linus Torvalds <[email protected]>
- Cc: Peter Zijlstra <[email protected]>
- Cc: Will Deacon <[email protected]>
- Cc: [email protected]
- Cc: [email protected]
- Cc: [email protected]
- Cc: [email protected]
- Signed-off-by: Ingo Molnar <[email protected]>
- (cherry picked from commit 48e111982cda033fec832c6b0592c2acedd85d04)
- Signed-off-by: Andy Whitcroft <[email protected]>
- Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
- (cherry picked from commit 1e2affe2a79305b3a5f3ad65d3f61ad9d1f9e168)
- Signed-off-by: Fabian Grünbichler <[email protected]>
- ---
- arch/x86/mm/tlb.c | 22 ++++++++++++++++++++--
- 1 file changed, 20 insertions(+), 2 deletions(-)
- diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
- index ce87b69fb4e0..353f2f4e1d96 100644
- --- a/arch/x86/mm/tlb.c
- +++ b/arch/x86/mm/tlb.c
- @@ -101,6 +101,24 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen,
- *need_flush = true;
- }
-
- +static void load_new_mm_cr3(pgd_t *pgdir, u16 new_asid, bool need_flush)
- +{
- + unsigned long new_mm_cr3;
- +
- + if (need_flush) {
- + new_mm_cr3 = build_cr3(pgdir, new_asid);
- + } else {
- + new_mm_cr3 = build_cr3_noflush(pgdir, new_asid);
- + }
- +
- + /*
- + * Caution: many callers of this function expect
- + * that load_cr3() is serializing and orders TLB
- + * fills with respect to the mm_cpumask writes.
- + */
- + write_cr3(new_mm_cr3);
- +}
- +
- void leave_mm(int cpu)
- {
- struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm);
- @@ -228,7 +246,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
- if (need_flush) {
- this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id);
- this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen);
- - write_cr3(build_cr3(next->pgd, new_asid));
- + load_new_mm_cr3(next->pgd, new_asid, true);
-
- /*
- * NB: This gets called via leave_mm() in the idle path
- @@ -241,7 +259,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
- trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
- } else {
- /* The new ASID is already up to date. */
- - write_cr3(build_cr3_noflush(next->pgd, new_asid));
- + load_new_mm_cr3(next->pgd, new_asid, false);
-
- /* See above wrt _rcuidle. */
- trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, 0);
- --
- 2.14.2
|