Skip to content

Commit 48e1119

Browse files
hansendcIngo Molnar
authored andcommitted
x86/mm: Abstract switching CR3
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]>
1 parent 2ea907c commit 48e1119

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

arch/x86/mm/tlb.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen,
100100
*need_flush = true;
101101
}
102102

103+
static void load_new_mm_cr3(pgd_t *pgdir, u16 new_asid, bool need_flush)
104+
{
105+
unsigned long new_mm_cr3;
106+
107+
if (need_flush) {
108+
new_mm_cr3 = build_cr3(pgdir, new_asid);
109+
} else {
110+
new_mm_cr3 = build_cr3_noflush(pgdir, new_asid);
111+
}
112+
113+
/*
114+
* Caution: many callers of this function expect
115+
* that load_cr3() is serializing and orders TLB
116+
* fills with respect to the mm_cpumask writes.
117+
*/
118+
write_cr3(new_mm_cr3);
119+
}
120+
103121
void leave_mm(int cpu)
104122
{
105123
struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm);
@@ -230,7 +248,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
230248
if (need_flush) {
231249
this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id);
232250
this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen);
233-
write_cr3(build_cr3(next->pgd, new_asid));
251+
load_new_mm_cr3(next->pgd, new_asid, true);
234252

235253
/*
236254
* NB: This gets called via leave_mm() in the idle path
@@ -243,7 +261,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
243261
trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
244262
} else {
245263
/* The new ASID is already up to date. */
246-
write_cr3(build_cr3_noflush(next->pgd, new_asid));
264+
load_new_mm_cr3(next->pgd, new_asid, false);
247265

248266
/* See above wrt _rcuidle. */
249267
trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, 0);

0 commit comments

Comments
 (0)