]> xenbits.xensource.com Git - xen.git/commitdiff
xen/x86: add some cr3 helpers
authorJuergen Gross <jgross@suse.com>
Thu, 26 Apr 2018 11:33:17 +0000 (13:33 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 29 May 2018 08:47:37 +0000 (10:47 +0200)
Add some helper macros to access the address and pcid parts of cr3.

Use those helpers where appropriate.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/debug.c
xen/arch/x86/domain_page.c
xen/include/asm-x86/processor.h

index 58cae22766ba43769affa02e30d4a088ac079124..b929d60a862019aa7754440dac8710e0094c4af9 100644 (file)
@@ -99,7 +99,7 @@ dbg_pv_va2mfn(dbgva_t vaddr, struct domain *dp, uint64_t pgd3val)
     l2_pgentry_t l2e, *l2t;
     l1_pgentry_t l1e, *l1t;
     unsigned long cr3 = (pgd3val ? pgd3val : dp->vcpu[0]->arch.cr3);
-    unsigned long mfn = cr3 >> PAGE_SHIFT;
+    unsigned long mfn = paddr_to_pfn(cr3_pa(cr3));
 
     DBGP2("vaddr:%lx domid:%d cr3:%lx pgd3:%lx\n", vaddr, dp->domain_id, 
           cr3, pgd3val);
index d86f8feed67edb2d42cc1ff68d4cc9b78773f1f6..28f5a5cc856514ab3a916826f69e0bed07395f0b 100644 (file)
@@ -50,7 +50,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)
         if ( (v = idle_vcpu[smp_processor_id()]) == current )
             sync_local_execstate();
         /* We must now be running on the idle page table. */
-        ASSERT(read_cr3() == __pa(idle_pg_table));
+        ASSERT(cr3_pa(read_cr3()) == __pa(idle_pg_table));
     }
 
     return v;
index b0962d6b491b436995622916c186ec2baabf5da8..4516e30fd26cc42547b09a155b0d435555e5bad1 100644 (file)
 #define X86_CR0_CD              0x40000000 /* Cache Disable            (RW) */
 #define X86_CR0_PG              0x80000000 /* Paging                   (RW) */
 
+/*
+ * Intel CPU flags in CR3
+ */
+#define X86_CR3_NOFLUSH    (_AC(1, ULL) << 63)
+#define X86_CR3_ADDR_MASK  (PAGE_MASK & PADDR_MASK)
+#define X86_CR3_PCID_MASK  _AC(0x0fff, ULL) /* Mask for PCID */
+
 /*
  * Intel CPU features in CR4
  */
@@ -339,6 +346,16 @@ static inline void write_cr3(unsigned long val)
     asm volatile ( "mov %0, %%cr3" : : "r" (val) : "memory" );
 }
 
+static inline unsigned long cr3_pa(unsigned long cr3)
+{
+    return cr3 & X86_CR3_ADDR_MASK;
+}
+
+static inline unsigned long cr3_pcid(unsigned long cr3)
+{
+    return cr3 & X86_CR3_PCID_MASK;
+}
+
 static inline unsigned long read_cr4(void)
 {
     return get_cpu_info()->cr4;