Skip to content

Commit

Permalink
xen/balloon: Fix mapping PG_offline pages to user space
Browse files Browse the repository at this point in the history
The XEN balloon driver - in contrast to other balloon drivers - allows
to map some inflated pages to user space. Such pages are allocated via
alloc_xenballooned_pages() and freed via free_xenballooned_pages().
The pfn space of these allocated pages is used to map other things
by the hypervisor using hypercalls.

Pages marked with PG_offline must never be mapped to user space (as
this page type uses the mapcount field of struct pages).

So what we can do is, clear/set PG_offline when allocating/freeing an
inflated pages. This way, most inflated pages can be excluded by
dumping tools and the "reused for other purpose" balloon pages are
correctly not marked as PG_offline.

Fixes: 77c4adf (xen/balloon: mark inflated pages PG_offline)
Reported-by: Julien Grall <[email protected]>
Tested-by: Julien Grall <[email protected]>
Signed-off-by: David Hildenbrand <[email protected]>
Reviewed-by: Juergen Gross <[email protected]>
Signed-off-by: Juergen Gross <[email protected]>
  • Loading branch information
davidhildenbrand authored and jgross1 committed Mar 15, 2019
1 parent f261c4e commit 0266def
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/xen/balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages)
while (pgno < nr_pages) {
page = balloon_retrieve(true);
if (page) {
__ClearPageOffline(page);
pages[pgno++] = page;
#ifdef CONFIG_XEN_HAVE_PVMMU
/*
Expand Down Expand Up @@ -645,8 +646,10 @@ void free_xenballooned_pages(int nr_pages, struct page **pages)
mutex_lock(&balloon_mutex);

for (i = 0; i < nr_pages; i++) {
if (pages[i])
if (pages[i]) {
__SetPageOffline(pages[i]);
balloon_append(pages[i]);
}
}

balloon_stats.target_unpopulated -= nr_pages;
Expand Down

0 comments on commit 0266def

Please sign in to comment.