[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 09/44] x86/mm: Track the current %cr3 in a per_cpu variable



... and assert that it isn't changing under our feet.  early_switch_to_idle()
is adjusted to set the shadow initially, when switching off idle_pg_table[].

EFI Runtime Service handling happens synchronously and under lock, so doesn't
interact with this path.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/mm.c        | 9 +++++++++
 xen/arch/x86/setup.c     | 2 ++
 xen/include/asm-x86/mm.h | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 25f9588..f85ef6c 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -497,14 +497,23 @@ void make_cr3(struct vcpu *v, mfn_t mfn)
     v->arch.cr3 = mfn_x(mfn) << PAGE_SHIFT;
 }
 
+DEFINE_PER_CPU(unsigned long, curr_ptbase);
+
 void do_write_ptbase(struct vcpu *v, bool tlb_maintenance)
 {
     unsigned long new_cr3 = v->arch.cr3;
+    unsigned int cpu = smp_processor_id();
+    unsigned long *this_curr_ptbase = &per_cpu(curr_ptbase, cpu);
+
+    /* Check that %cr3 isn't being shuffled under our feet. */
+    ASSERT(*this_curr_ptbase == read_cr3());
 
     if ( tlb_maintenance )
         write_cr3(new_cr3);
     else
         asm volatile ( "mov %0, %%cr3" :: "r" (new_cr3) : "memory" );
+
+    *this_curr_ptbase = new_cr3;
 }
 
 /*
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index b8e52cf..7a05a7c 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -254,6 +254,8 @@ void early_switch_to_idle(void)
                     [cr3]  "r" (v->arch.cr3),
                     [pge]  "r" (cr4)
                    : "memory" );
+
+    per_cpu(curr_ptbase, cpu) = v->arch.cr3;
 }
 
 static void __init init_idle_domain(void)
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 4af6b23..ceb7dd4 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -561,6 +561,8 @@ void audit_domains(void);
 
 #endif
 
+DECLARE_PER_CPU(unsigned long, curr_ptbase);
+
 void make_cr3(struct vcpu *v, mfn_t mfn);
 void update_cr3(struct vcpu *v);
 int vcpu_destroy_pagetables(struct vcpu *);
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.