Skip to content

Commit 24f6937

Browse files
David Vrabelkonradwilk
authored andcommitted
xen/balloon: don't alloc page while non-preemptible
get_balloon_scratch_page() disables preemption so we cannot call alloc_page() in between get/put_balloon_scratch_page(). Shuffle bits around in decrease_reservation() to avoid this. Signed-off-by: David Vrabel <david.vrabel@citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent a945928 commit 24f6937

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

drivers/xen/balloon.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
398398
if (nr_pages > ARRAY_SIZE(frame_list))
399399
nr_pages = ARRAY_SIZE(frame_list);
400400

401-
scratch_page = get_balloon_scratch_page();
402-
403401
for (i = 0; i < nr_pages; i++) {
404402
page = alloc_page(gfp);
405403
if (page == NULL) {
@@ -413,6 +411,12 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
413411

414412
scrub_page(page);
415413

414+
/*
415+
* Ballooned out frames are effectively replaced with
416+
* a scratch frame. Ensure direct mappings and the
417+
* p2m are consistent.
418+
*/
419+
scratch_page = get_balloon_scratch_page();
416420
#ifdef CONFIG_XEN_HAVE_PVMMU
417421
if (xen_pv_domain() && !PageHighMem(page)) {
418422
ret = HYPERVISOR_update_va_mapping(
@@ -422,24 +426,19 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
422426
BUG_ON(ret);
423427
}
424428
#endif
425-
}
426-
427-
/* Ensure that ballooned highmem pages don't have kmaps. */
428-
kmap_flush_unused();
429-
flush_tlb_all();
430-
431-
/* No more mappings: invalidate P2M and add to balloon. */
432-
for (i = 0; i < nr_pages; i++) {
433-
pfn = mfn_to_pfn(frame_list[i]);
434429
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
435430
unsigned long p;
436431
p = page_to_pfn(scratch_page);
437432
__set_phys_to_machine(pfn, pfn_to_mfn(p));
438433
}
434+
put_balloon_scratch_page();
435+
439436
balloon_append(pfn_to_page(pfn));
440437
}
441438

442-
put_balloon_scratch_page();
439+
/* Ensure that ballooned highmem pages don't have kmaps. */
440+
kmap_flush_unused();
441+
flush_tlb_all();
443442

444443
set_xen_guest_handle(reservation.extent_start, frame_list);
445444
reservation.nr_extents = nr_pages;

0 commit comments

Comments
 (0)