From 2a62721ee2608ed2bf00fd50b3aa78619c4f7a43 Mon Sep 17 00:00:00 2001 From: Andres Lagar-Cavilla Date: Fri, 18 May 2012 16:19:21 +0100 Subject: [PATCH] x86/mem_sharing: Allow paging-in pages to be replaced by shared ones. Making sure to tidy up any partially paged frames. Signed-off-by: Andres Lagar-Cavilla Acked-by: Tim Deegan Committed-by: Tim Deegan --- xen/arch/x86/mm/mem_sharing.c | 10 ++++++++++ xen/include/asm-x86/p2m.h | 1 + 2 files changed, 11 insertions(+) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index a2d82e9bd8..510328554e 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1103,7 +1103,17 @@ int mem_sharing_add_to_physmap(struct domain *sd, unsigned long sgfn, shr_handle ret = 0; /* There is a chance we're plugging a hole where a paged out page was */ if ( p2m_is_paging(cmfn_type) && (cmfn_type != p2m_ram_paging_out) ) + { atomic_dec(&cd->paged_pages); + /* Further, there is a chance this was a valid page. Don't leak it. */ + if ( mfn_valid(cmfn) ) + { + struct page_info *cpage = mfn_to_page(cmfn); + ASSERT(cpage != NULL); + if ( test_and_clear_bit(_PGC_allocated, &cpage->count_info) ) + put_page(cpage); + } + } } atomic_inc(&nr_saved_mfns); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index febf764582..63bc7cf451 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -137,6 +137,7 @@ typedef unsigned int p2m_query_t; * entry */ #define P2M_HOLE_TYPES (p2m_to_mask(p2m_mmio_dm) \ | p2m_to_mask(p2m_invalid) \ + | p2m_to_mask(p2m_ram_paging_in) \ | p2m_to_mask(p2m_ram_paged)) /* Grant mapping types, which map to a real machine frame in another -- 2.39.5