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

[Xen-changelog] [xen-unstable] x86: Fix guest_physmap_add_entry checks



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1222334768 -3600
# Node ID 7a32c2325fdc6b6994ba6dbfc1c7f782b60a7463
# Parent  7592da5118ecc1f3beaa0a820148a933ad2cf2da
x86: Fix guest_physmap_add_entry checks

guest_physmap_add_entry() checks to see if the given mfn and gpfn
range in the p2m and m2p tables is already mapped before overwriting
the maps, and attempts to do something reasonable so that we don't
have any "dangling" pointers.

Unfortunately, these checks got broken when the page_order argument
was added.  Each individual p2m and m2p entry needs to be checked, not
just the first page in a page order.

Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
---
 xen/arch/x86/mm/p2m.c |   67 ++++++++++++++++++++++++++++----------------------
 1 files changed, 38 insertions(+), 29 deletions(-)

diff -r 7592da5118ec -r 7a32c2325fdc xen/arch/x86/mm/p2m.c
--- a/xen/arch/x86/mm/p2m.c     Thu Sep 25 10:21:40 2008 +0100
+++ b/xen/arch/x86/mm/p2m.c     Thu Sep 25 10:26:08 2008 +0100
@@ -953,38 +953,47 @@ guest_physmap_add_entry(struct domain *d
 
     P2M_DEBUG("adding gfn=%#lx mfn=%#lx\n", gfn, mfn);
 
-    omfn = gfn_to_mfn(d, gfn, &ot);
-    if ( p2m_is_ram(ot) )
-    {
-        ASSERT(mfn_valid(omfn));
-        for ( i = 0; i < (1UL << page_order); i++ )
+    /* First, remove m->p mappings for existing p->m mappings */
+    for ( i = 0; i < (1UL << page_order); i++ )
+    {
+        omfn = gfn_to_mfn(d, gfn, &ot);
+        if ( p2m_is_ram(ot) )
+        {
+            ASSERT(mfn_valid(omfn));
             set_gpfn_from_mfn(mfn_x(omfn)+i, INVALID_M2P_ENTRY);
-    }
-
-    ogfn = mfn_to_gfn(d, _mfn(mfn));
-    if (
+        }
+    }
+
+    /* Then, look for m->p mappings for this range and deal with them */
+    for ( i = 0; i < (1UL << page_order); i++ )
+    {
+        ogfn = mfn_to_gfn(d, _mfn(mfn));
+        if (
 #ifdef __x86_64__
-        (ogfn != 0x5555555555555555L)
+            (ogfn != 0x5555555555555555L)
 #else
-        (ogfn != 0x55555555L)
-#endif
-        && (ogfn != INVALID_M2P_ENTRY)
-        && (ogfn != gfn) )
-    {
-        /* This machine frame is already mapped at another physical address */
-        P2M_DEBUG("aliased! mfn=%#lx, old gfn=%#lx, new gfn=%#lx\n",
-                  mfn, ogfn, gfn);
-        omfn = gfn_to_mfn(d, ogfn, &ot);
-        if ( p2m_is_ram(ot) )
-        {
-            ASSERT(mfn_valid(omfn));
-            P2M_DEBUG("old gfn=%#lx -> mfn %#lx\n",
-                      ogfn , mfn_x(omfn));
-            if ( mfn_x(omfn) == mfn )
-                p2m_remove_page(d, ogfn, mfn, page_order);
-        }
-    }
-
+            (ogfn != 0x55555555L)
+#endif
+            && (ogfn != INVALID_M2P_ENTRY)
+            && (ogfn != gfn) )
+        {
+            /* This machine frame is already mapped at another physical
+             * address */
+            P2M_DEBUG("aliased! mfn=%#lx, old gfn=%#lx, new gfn=%#lx\n",
+                      mfn, ogfn, gfn);
+            omfn = gfn_to_mfn(d, ogfn, &ot);
+            if ( p2m_is_ram(ot) )
+            {
+                ASSERT(mfn_valid(omfn));
+                P2M_DEBUG("old gfn=%#lx -> mfn %#lx\n",
+                          ogfn , mfn_x(omfn));
+                if ( mfn_x(omfn) == mfn )
+                    p2m_remove_page(d, ogfn, mfn, 0);
+            }
+        }
+    }
+
+    /* Now, actually do the two-way mapping */
     if ( mfn_valid(_mfn(mfn)) ) 
     {
         if ( !set_p2m_entry(d, gfn, _mfn(mfn), page_order, t) )

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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