All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: Keir Fraser <keir@xen.org>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH 06/12] xenpaging: update machine_to_phys_mapping[] during page deallocation
Date: Tue, 11 Jan 2011 12:00:22 +0100	[thread overview]
Message-ID: <20110111110022.GA3634@aepfle.de> (raw)
In-Reply-To: <C951E354.29FA4%keir@xen.org>

On Tue, Jan 11, Keir Fraser wrote:

> Could we do this in free_heap_pages() instead? That definitely catches
> everything that gets placed in Xen's free pool.

Yes, this is a compile-tested patch.


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@aepfle.de>

---
v2:
    move from free_domheap_pages() to free_heap_pages() as suggested by Keir

 xen/common/page_alloc.c |    6 ++++++
 1 file changed, 6 insertions(+)

--- xen-unstable.hg-4.1.22697.orig/xen/common/page_alloc.c
+++ xen-unstable.hg-4.1.22697/xen/common/page_alloc.c
@@ -527,6 +527,7 @@ static int reserve_offlined_page(struct
 static void free_heap_pages(
     struct page_info *pg, unsigned int order)
 {
+    unsigned long mfn;
     unsigned long mask;
     unsigned int i, node = phys_to_nid(page_to_maddr(pg)), tainted = 0;
     unsigned int zone = page_to_zone(pg);
@@ -536,6 +537,11 @@ static void free_heap_pages(
 
     spin_lock(&heap_lock);
 
+    /* this page is not a gfn anymore */
+    mfn = page_to_mfn(pg);
+    for ( i = 0; i < (1 << order); i++ )
+        set_gpfn_from_mfn(mfn + i, INVALID_M2P_ENTRY);
+
     for ( i = 0; i < (1 << order); i++ )
     {
         /*

  reply	other threads:[~2011-01-11 11:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-10 16:43 [PATCH 00/12] xenpaging changes for xen-unstable Olaf Hering
2011-01-10 16:43 ` [PATCH 01/12] xenpaging: remove domain_id and mfn from struct xenpaging_victim Olaf Hering
2011-01-10 16:43 ` [PATCH 02/12] xenpaging: specify policy mru_size at runtime Olaf Hering
2011-01-10 16:43 ` [PATCH 03/12] xenpaging: mkdir /var/lib/xen/xenpaging during make install Olaf Hering
2011-01-10 16:43 ` [PATCH 04/12] xenpaging: print page-in/page-out progress Olaf Hering
2011-01-10 16:43 ` [PATCH 05/12] xenpaging: make three functions static Olaf Hering
2011-01-11 18:36   ` Ian Jackson
2011-01-10 16:43 ` [PATCH 06/12] xenpaging: update machine_to_phys_mapping[] during page deallocation Olaf Hering
2011-01-11 10:37   ` Keir Fraser
2011-01-11 11:00     ` Olaf Hering [this message]
2011-01-11 11:29       ` Keir Fraser
2011-01-10 16:43 ` [PATCH 07/12] xenpaging: update machine_to_phys_mapping[] during page-in Olaf Hering
2011-01-10 16:43 ` [PATCH 08/12] xenpaging: drop paged pages in guest_remove_page Olaf Hering
2011-01-14 16:53   ` Olaf Hering
2011-01-10 16:43 ` [PATCH 09/12] xenpaging: prevent page-out of gfn 0x80 Olaf Hering
2011-01-10 16:43 ` [PATCH 10/12] xenpaging: handle HVMCOPY_gfn_paged_out in copy_from/to_user Olaf Hering
2011-01-10 16:43 ` [PATCH 11/12] xenpaging: start xenpaging via config option Olaf Hering
2011-01-10 16:43 ` [PATCH 12/12] xenpaging: document missing live migration Olaf Hering
2011-01-11 17:20 ` [PATCH 00/12] xenpaging changes for xen-unstable Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110111110022.GA3634@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.