From: Wei Liu Subject: [PATCH V3] xen/balloon: flush persistent kmaps in correct position Date: Sat, 15 Mar 2014 16:11:47 +0000 Message-ID: <1394899907-2529-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WOrC4-0001n1-HY for xen-devel@lists.xenproject.org; Sat, 15 Mar 2014 16:12:16 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Boris Ostrovsky , Wei Liu , David Vrabel List-Id: xen-devel@lists.xenproject.org Xen balloon driver will update ballooned out pages' P2M entries to point to scratch page for PV guests. In 24f69373e2 ("xen/balloon: don't alloc page while non-preemptible", kmap_flush_unused was moved after updating P2M table. In that case for 32 bit PV guest we might end up with P2M X -----> S (S is mfn of balloon scratch page) M2P Y -----> X (Y is mfn in persistent kmap entry) When kmap_flush_unused is called, it will call into flush_all_zero_pkmaps, which calls pte_page. Pte_page will call into PVMMU, which relies on P2M and M2P tables to do the correct translation. When PVMMU sees X -> S and Y -> X, it gets confused and returns a wrong value, which causes the guest to crash high up the call chain. Move the flush back between get_page and __set_phys_to_machine to fix this. Signed-off-by: Wei Liu Cc: David Vrabel Cc: Konrad Wilk Cc: Boris Ostrovsky --- drivers/xen/balloon.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 37d06ea..6e56174 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -404,6 +404,15 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) frame_list[i] = pfn_to_mfn(pfn); scrub_page(page); + } + + /* Ensure that ballooned highmem pages don't have kmaps. */ + kmap_flush_unused(); + flush_tlb_all(); + + /* No more mappings: invalidate P2M and add to balloon. */ + for (i = 0; i < nr_pages; i++) { + pfn = mfn_to_pfn(frame_list[i]); #ifdef CONFIG_XEN_HAVE_PVMMU /* @@ -432,10 +441,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) balloon_append(pfn_to_page(pfn)); } - /* Ensure that ballooned highmem pages don't have kmaps. */ - kmap_flush_unused(); - flush_tlb_all(); - set_xen_guest_handle(reservation.extent_start, frame_list); reservation.nr_extents = nr_pages; ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation); -- 1.7.10.4