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

[Xen-devel] [PATCH 01/17] xen/x86: Introduce helpers to generate/convert the CR3 from/to a MFN/GFN



From: Julien Grall <jgrall@xxxxxxxxxx>

Introduce handy helpers to generate/convert the CR3 from/to a MFN/GFN.

Note that we are using cr3_pa() rather than xen_cr3_to_pfn() because the
latter does not ignore the top 12-bits.

Take the opportunity to use the new helpers when possible.

Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 xen/arch/x86/domain.c    |  4 ++--
 xen/arch/x86/mm.c        |  2 +-
 xen/include/asm-x86/mm.h | 20 ++++++++++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index caf2ecad7e..15750ce210 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1096,7 +1096,7 @@ int arch_set_info_guest(
     set_bit(_VPF_in_reset, &v->pause_flags);
 
     if ( !compat )
-        cr3_mfn = _mfn(xen_cr3_to_pfn(c.nat->ctrlreg[3]));
+        cr3_mfn = cr3_to_mfn(c.nat->ctrlreg[3]);
     else
         cr3_mfn = _mfn(compat_cr3_to_pfn(c.cmp->ctrlreg[3]));
     cr3_page = get_page_from_mfn(cr3_mfn, d);
@@ -1142,7 +1142,7 @@ int arch_set_info_guest(
         v->arch.guest_table = pagetable_from_page(cr3_page);
         if ( c.nat->ctrlreg[1] )
         {
-            cr3_mfn = _mfn(xen_cr3_to_pfn(c.nat->ctrlreg[1]));
+            cr3_mfn = cr3_to_mfn(c.nat->ctrlreg[1]);
             cr3_page = get_page_from_mfn(cr3_mfn, d);
 
             if ( !cr3_page )
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 62507ca651..069a61deb8 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -509,7 +509,7 @@ void make_cr3(struct vcpu *v, mfn_t mfn)
 {
     struct domain *d = v->domain;
 
-    v->arch.cr3 = mfn_x(mfn) << PAGE_SHIFT;
+    v->arch.cr3 = mfn_to_cr3(mfn);
     if ( is_pv_domain(d) && d->arch.pv.pcid )
         v->arch.cr3 |= get_pcid_bits(v, false);
 }
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index a06b2fb81f..9764362a38 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -524,6 +524,26 @@ extern struct rangeset *mmio_ro_ranges;
 #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 
20))
 #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 
20))
 
+static inline unsigned long mfn_to_cr3(mfn_t mfn)
+{
+    return xen_pfn_to_cr3(mfn_x(mfn));
+}
+
+static inline mfn_t cr3_to_mfn(unsigned long cr3)
+{
+    return maddr_to_mfn(cr3_pa(cr3));
+}
+
+static inline unsigned long gfn_to_cr3(gfn_t gfn)
+{
+    return xen_pfn_to_cr3(gfn_x(gfn));
+}
+
+static inline gfn_t cr3_to_gfn(unsigned long cr3)
+{
+    return gaddr_to_gfn(cr3_pa(cr3));
+}
+
 #ifdef MEMORY_GUARD
 void memguard_guard_range(void *p, unsigned long l);
 void memguard_unguard_range(void *p, unsigned long l);
-- 
2.17.1


_______________________________________________
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®.