Skip to content

Commit 09ed3d5

Browse files
Wei LiuDavid Vrabel
authored andcommitted
xen/balloon: flush persistent kmaps in correct position
Xen balloon driver will update ballooned out pages' P2M entries to point to scratch page for PV guests. In 24f6937 ("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) kmap_flush_unused() iterates through all the PTEs in the kmap address space, using pte_to_page() to obtain the page. If the p2m and the m2p are inconsistent the incorrect page is returned. This will clear page->address on the wrong page which may cause subsequent oopses if that page is currently kmap'ed. Move the flush back between get_page and __set_phys_to_machine to fix this. Signed-off-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com> Cc: stable@vger.kernel.org # 3.12+
1 parent b098d67 commit 09ed3d5

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

drivers/xen/balloon.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,25 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
399399
state = BP_EAGAIN;
400400
break;
401401
}
402+
scrub_page(page);
402403

403-
pfn = page_to_pfn(page);
404-
frame_list[i] = pfn_to_mfn(pfn);
404+
frame_list[i] = page_to_pfn(page);
405+
}
405406

406-
scrub_page(page);
407+
/*
408+
* Ensure that ballooned highmem pages don't have kmaps.
409+
*
410+
* Do this before changing the p2m as kmap_flush_unused()
411+
* reads PTEs to obtain pages (and hence needs the original
412+
* p2m entry).
413+
*/
414+
kmap_flush_unused();
415+
416+
/* Update direct mapping, invalidate P2M, and add to balloon. */
417+
for (i = 0; i < nr_pages; i++) {
418+
pfn = frame_list[i];
419+
frame_list[i] = pfn_to_mfn(pfn);
420+
page = pfn_to_page(pfn);
407421

408422
#ifdef CONFIG_XEN_HAVE_PVMMU
409423
/*
@@ -429,11 +443,9 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
429443
}
430444
#endif
431445

432-
balloon_append(pfn_to_page(pfn));
446+
balloon_append(page);
433447
}
434448

435-
/* Ensure that ballooned highmem pages don't have kmaps. */
436-
kmap_flush_unused();
437449
flush_tlb_all();
438450

439451
set_xen_guest_handle(reservation.extent_start, frame_list);

0 commit comments

Comments
 (0)