Skip to contentSkip to conversation

xen/balloon: flush persistent kmaps before updating P2M table

PATCH In review Wei Liu 1 participant 2 messages Mar 14, 2014 – Mar 15, 2014 Xen hypervisor interface

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH v2 1/1 xen/balloon: flush persistent kmaps before updating P2M table

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 before __set_phys_to_machine to fix this.

Cc David Vrabel <[email protected]>
Cc Konrad Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
---
 drivers/xen/balloon.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/xen/balloon.c +4 -4
index 37d06ea..49a809c 100644
@@ -392,6 +392,10 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 	if (nr_pages > ARRAY_SIZE(frame_list))
 		nr_pages = ARRAY_SIZE(frame_list);
 
+	/* Ensure that ballooned highmem pages don't have kmaps. */
+	kmap_flush_unused();
+	flush_tlb_all();
+
 	for (i = 0; i < nr_pages; i++) {
 		page = alloc_page(gfp);
 		if (page == NULL) {
@@ -432,10 +436,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);
Signature · 1 line
1.7.10.4
author
#1 lore raw

Please drop this patch as it still doesn't fix the problem. The flush should be moved between get_page and __set_phys_to_machine.

V3 will follow shortly.

Wei.