From: Tim Deegan Date: Thu, 17 May 2012 09:37:09 +0000 (+0100) Subject: x86/mem_sharing: Fix test for "empty" physmap entry in sharing_add_to_physmap X-Git-Tag: 4.2.0-rc1~327 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=8d204daa8f1d949092afbf4098d6e70bc40a3c20;p=xen.git x86/mem_sharing: Fix test for "empty" physmap entry in sharing_add_to_physmap Signed-off-by: Andres Lagar-Cavilla Signed-off-by: Tim Deegan Committed-by: Tim Deegan --- diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 5cc879578b..a2d82e9bd8 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1073,9 +1073,10 @@ int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle if ( spage->sharing->handle != sh ) goto err_unlock; - /* Make sure the target page is a hole in the physmap */ - if ( mfn_valid(cmfn) || - (!(p2m_is_ram(cmfn_type))) ) + /* Make sure the target page is a hole in the physmap. These are typically + * p2m_mmio_dm, but also accept p2m_invalid and paged out pages. See the + * definition of p2m_is_hole in p2m.h. */ + if ( !p2m_is_hole(cmfn_type) ) { ret = XENMEM_SHARING_OP_C_HANDLE_INVALID; goto err_unlock; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 94bd136168..febf764582 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -133,6 +133,12 @@ typedef unsigned int p2m_query_t; | p2m_to_mask(p2m_ram_paging_in) \ | p2m_to_mask(p2m_ram_shared)) +/* Types that represent a physmap hole that is ok to replace with a shared + * entry */ +#define P2M_HOLE_TYPES (p2m_to_mask(p2m_mmio_dm) \ + | p2m_to_mask(p2m_invalid) \ + | p2m_to_mask(p2m_ram_paged)) + /* Grant mapping types, which map to a real machine frame in another * VM */ #define P2M_GRANT_TYPES (p2m_to_mask(p2m_grant_map_rw) \ @@ -173,6 +179,7 @@ typedef unsigned int p2m_query_t; /* Useful predicates */ #define p2m_is_ram(_t) (p2m_to_mask(_t) & P2M_RAM_TYPES) +#define p2m_is_hole(_t) (p2m_to_mask(_t) & P2M_HOLE_TYPES) #define p2m_is_mmio(_t) (p2m_to_mask(_t) & P2M_MMIO_TYPES) #define p2m_is_readonly(_t) (p2m_to_mask(_t) & P2M_RO_TYPES) #define p2m_is_magic(_t) (p2m_to_mask(_t) & P2M_MAGIC_TYPES)