debuggers.hg

changeset 22752:ca10302ac285

xenpaging: update machine_to_phys_mapping[] during page deallocation

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>
author Keir Fraser <keir@xen.org>
date Tue Jan 11 11:27:37 2011 +0000 (2011-01-11)
parents c5b42971234a
children 2ff199e2842b
files xen/common/page_alloc.c
line diff
     1.1 --- a/xen/common/page_alloc.c	Tue Jan 11 10:38:28 2011 +0000
     1.2 +++ b/xen/common/page_alloc.c	Tue Jan 11 11:27:37 2011 +0000
     1.3 @@ -527,7 +527,7 @@ static int reserve_offlined_page(struct 
     1.4  static void free_heap_pages(
     1.5      struct page_info *pg, unsigned int order)
     1.6  {
     1.7 -    unsigned long mask;
     1.8 +    unsigned long mask, mfn = page_to_mfn(pg);
     1.9      unsigned int i, node = phys_to_nid(page_to_maddr(pg)), tainted = 0;
    1.10      unsigned int zone = page_to_zone(pg);
    1.11  
    1.12 @@ -538,6 +538,10 @@ static void free_heap_pages(
    1.13  
    1.14      for ( i = 0; i < (1 << order); i++ )
    1.15      {
    1.16 +        /* This page is not a guest frame any more. */
    1.17 +        page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */
    1.18 +        set_gpfn_from_mfn(mfn + i, INVALID_M2P_ENTRY);
    1.19 +
    1.20          /*
    1.21           * Cannot assume that count_info == 0, as there are some corner cases
    1.22           * where it isn't the case and yet it isn't a bug: