]> xenbits.xensource.com Git - xen.git/commitdiff
xen/x86: add a function for modifying cr3
authorJuergen Gross <jgross@suse.com>
Thu, 26 Apr 2018 11:33:11 +0000 (13:33 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 29 May 2018 08:43:14 +0000 (10:43 +0200)
Instead of having multiple places with more or less identical asm
statements just have one function doing a write to cr3.

As this function should be named write_cr3() rename the current
write_cr3() function to switch_cr3().

Suggested-by: Andrew Copper <andrew.cooper3@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/flushtlb.c
xen/arch/x86/mm.c
xen/arch/x86/x86_64/traps.c
xen/common/efi/runtime.c
xen/include/asm-x86/flushtlb.h
xen/include/asm-x86/processor.h

index f0d2bc1d7a86e245dd9f6611c93425bd219be069..e204b0a1e07c864cae189f2cc80ec759e4f83f15 100644 (file)
@@ -73,7 +73,7 @@ static void post_flush(u32 t)
     this_cpu(tlbflush_time) = t;
 }
 
-void write_cr3(unsigned long cr3)
+void switch_cr3(unsigned long cr3)
 {
     unsigned long flags, cr4;
     u32 t;
@@ -85,7 +85,7 @@ void write_cr3(unsigned long cr3)
     cr4 = read_cr4();
 
     write_cr4(cr4 & ~X86_CR4_PGE);
-    asm volatile ( "mov %0, %%cr3" : : "r" (cr3) : "memory" );
+    write_cr3(cr3);
     write_cr4(cr4);
 
     post_flush(t);
index 0ed878a015cd3a93d21b0cfb91b999097c5c0e7f..12adc1e1b4ee623524cc32cb3bc8055a8e24e51e 100644 (file)
@@ -500,7 +500,7 @@ void make_cr3(struct vcpu *v, unsigned long mfn)
 void write_ptbase(struct vcpu *v)
 {
     get_cpu_info()->root_pgt_changed = 1;
-    write_cr3(v->arch.cr3);
+    switch_cr3(v->arch.cr3);
 }
 
 /*
index 4e6c68128f43fc37d59f41f39d241aec8326fba7..aba7213ad6c9a2ebcdc0b6fb73d2384ff31f0dfd 100644 (file)
@@ -287,7 +287,7 @@ void toggle_guest_pt(struct vcpu *v)
     get_cpu_info()->root_pgt_changed = 1;
 
     /* Don't flush user global mappings from the TLB. Don't tick TLB clock. */
-    asm volatile ( "mov %0, %%cr3" : : "r" (v->arch.cr3) : "memory" );
+    write_cr3(v->arch.cr3);
 
     if ( !(v->arch.flags & TF_kernel_mode) )
         return;
index 40646204afb6d11bce3bdd07f382608a92a2fbfb..cab61be7c87cf29d11863fa4f573213eee124e15 100644 (file)
@@ -106,7 +106,7 @@ struct efi_rs_state efi_rs_enter(void)
         asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
     }
 
-    write_cr3(virt_to_maddr(efi_l4_pgtable));
+    switch_cr3(virt_to_maddr(efi_l4_pgtable));
 
     return state;
 }
@@ -115,7 +115,7 @@ void efi_rs_leave(struct efi_rs_state *state)
 {
     if ( !state->cr3 )
         return;
-    write_cr3(state->cr3);
+    switch_cr3(state->cr3);
     if ( is_pv_vcpu(current) && !is_idle_vcpu(current) )
     {
         struct desc_ptr gdt_desc = {
index 1be6a72306c2d04f7f45a16c3d4cd7bfd0c51c97..ab855f93931b6e825026fce976c47e618ecb7b31 100644 (file)
@@ -84,7 +84,7 @@ static inline unsigned long read_cr3(void)
 }
 
 /* Write pagetable base and implicitly tick the tlbflush clock. */
-void write_cr3(unsigned long cr3);
+void switch_cr3(unsigned long cr3);
 
 /* flush_* flag fields: */
  /*
index 95b87044280d718abdc1ae5e47fc62f2fa9605a7..b0962d6b491b436995622916c186ec2baabf5da8 100644 (file)
@@ -334,6 +334,11 @@ static inline unsigned long read_cr2(void)
     return cr2;
 }
 
+static inline void write_cr3(unsigned long val)
+{
+    asm volatile ( "mov %0, %%cr3" : : "r" (val) : "memory" );
+}
+
 static inline unsigned long read_cr4(void)
 {
     return get_cpu_info()->cr4;