This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
Home Products Support Community News


[Xen-devel] [PATCH 3/6] xenpaging: update machine_to_phys_mapping[] duri

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 3/6] xenpaging: update machine_to_phys_mapping[] during page deallocation
From: Olaf Hering <olaf@xxxxxxxxx>
Date: Sun, 16 Jan 2011 17:32:32 +0100
Delivery-date: Sun, 16 Jan 2011 08:33:24 -0800
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1295195551; l=2081; s=domk; d=aepfle.de; h=References:Subject:To:From:Date:X-RZG-CLASS-ID:X-RZG-AUTH; bh=axaP6WBuI5lTpUTedo3qKM7yLHI=; b=R990ibx59gGeG0sVrvhnrxF9sucuu65Vvg9/PHIwTPKvt5IccuR2R+eHU3PdoFTaugi 1V+R6NCpJvmFfoMwbZK/ZHY7ZAQP7tzsZOPb2iZIczb1udnBTecBhUEuYM+AmuqVWZpqT tRmeC+R/hmI1VEUdm0QT6OClvfB5H+LJzyg=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <20110116163229.044047464@xxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: quilt/0.48-4.4
The machine_to_phys_mapping[] array needs updating during page
deallocation.  If that page is allocated again, a call to
get_gpfn_from_mfn() will still return an old gfn from another guest.
This will cause trouble because this gfn number has no or different
meaning in the context of the current guest.

This happens when the entire guest ram is paged-out before
xen_vga_populate_vram() runs.  Then XENMEM_populate_physmap is called
with gfn 0xff000.  A new page is allocated with alloc_domheap_pages.
This new page does not have a gfn yet.  However, in
guest_physmap_add_entry() the passed mfn maps still to an old gfn
(perhaps from another old guest).  This old gfn is in paged-out state in
this guests context and has no mfn anymore.  As a result, the ASSERT()
triggers because p2m_is_ram() is true for p2m_ram_paging* types.
If the machine_to_phys_mapping[] array is updated properly, both loops
in guest_physmap_add_entry() turn into no-ops for the new page and the
mfn/gfn mapping will be done at the end of the function.

If XENMEM_add_to_physmap is used with XENMAPSPACE_gmfn,
get_gpfn_from_mfn() will return an appearently valid gfn.  As a result,
guest_physmap_remove_page() is called.  The ASSERT in p2m_remove_page
triggers because the passed mfn does not match the old mfn for the
passed gfn.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
 xen/common/page_alloc.c |    9 +++++++++
 1 file changed, 9 insertions(+)

--- xen-unstable.hg-4.1.22764.orig/xen/common/page_alloc.c
+++ xen-unstable.hg-4.1.22764/xen/common/page_alloc.c
@@ -1200,6 +1200,7 @@ void free_domheap_pages(struct page_info
     int            i, drop_dom_ref;
     struct domain *d = page_get_owner(pg);
+    unsigned long mfn;
@@ -1257,6 +1258,14 @@ void free_domheap_pages(struct page_info
         drop_dom_ref = 0;
+    /* this page is not a gfn anymore */
+    mfn = page_to_mfn(pg);
+    for ( i = 0; i < (1 << order); i++ )
+    {
+        page_set_owner(&pg[i], NULL);
+        set_gpfn_from_mfn(mfn + i, INVALID_M2P_ENTRY);
+    }
     if ( drop_dom_ref )

Xen-devel mailing list