All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3] xen/balloon: flush persistent kmaps in correct position
@ 2014-03-15 16:11 Wei Liu
  2014-03-17 14:53 ` David Vrabel
  2014-03-18 13:47 ` Wei Liu
  0 siblings, 2 replies; 8+ messages in thread
From: Wei Liu @ 2014-03-15 16:11 UTC (permalink / raw)
  To: xen-devel; +Cc: Boris Ostrovsky, Wei Liu, David Vrabel

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 <wei.liu2@citrix.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Konrad Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-03-19 13:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-15 16:11 [PATCH V3] xen/balloon: flush persistent kmaps in correct position Wei Liu
2014-03-17 14:53 ` David Vrabel
2014-03-17 15:04   ` Wei Liu
2014-03-17 15:24     ` David Vrabel
2014-03-18 13:47 ` Wei Liu
2014-03-18 17:40   ` David Vrabel
2014-03-19 11:19     ` Wei Liu
2014-03-19 13:32       ` David Vrabel

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.