Commit c1d15f5c authored by Stefano Stabellini's avatar Stefano Stabellini Committed by Konrad Rzeszutek Wilk

xen/balloon: Seperate the auto-translate logic properly (v2)

The auto-xlat logic vs the non-xlat means that we don't need to for
auto-xlat guests (like PVH, HVM or ARM):
 - use P2M
 - use scratch page.

However the code in increase_reservation does modify the p2m for
auto_translate guests, but not in decrease_reservation.

Fix that by avoiding any p2m modifications in both increase_reservation
and decrease_reservation for auto_translated guests.

And also avoid allocating or using scratch pages for auto_translated guests.

Lastly, since !auto-xlat is really another way of saying 'xen_pv'
remove the redundant 'xen_pv_domain' check.
Signed-off-by: default avatarStefano Stabellini <stefano.stabellini@eu.citrix.com>
[v2: Updated the description]
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
parent 380108d8
...@@ -350,11 +350,12 @@ static enum bp_state increase_reservation(unsigned long nr_pages) ...@@ -350,11 +350,12 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
pfn = page_to_pfn(page); pfn = page_to_pfn(page);
#ifdef CONFIG_XEN_HAVE_PVMMU
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
set_phys_to_machine(pfn, frame_list[i]); set_phys_to_machine(pfn, frame_list[i]);
#ifdef CONFIG_XEN_HAVE_PVMMU
/* Link back into the page tables if not highmem. */ /* Link back into the page tables if not highmem. */
if (xen_pv_domain() && !PageHighMem(page)) { if (!PageHighMem(page)) {
int ret; int ret;
ret = HYPERVISOR_update_va_mapping( ret = HYPERVISOR_update_va_mapping(
(unsigned long)__va(pfn << PAGE_SHIFT), (unsigned long)__va(pfn << PAGE_SHIFT),
...@@ -362,6 +363,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages) ...@@ -362,6 +363,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
0); 0);
BUG_ON(ret); BUG_ON(ret);
} }
}
#endif #endif
/* Relinquish the page back to the allocator. */ /* Relinquish the page back to the allocator. */
...@@ -378,7 +380,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) ...@@ -378,7 +380,6 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
enum bp_state state = BP_DONE; enum bp_state state = BP_DONE;
unsigned long pfn, i; unsigned long pfn, i;
struct page *page; struct page *page;
struct page *scratch_page;
int ret; int ret;
struct xen_memory_reservation reservation = { struct xen_memory_reservation reservation = {
.address_bits = 0, .address_bits = 0,
...@@ -411,27 +412,29 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) ...@@ -411,27 +412,29 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
scrub_page(page); scrub_page(page);
#ifdef CONFIG_XEN_HAVE_PVMMU
/* /*
* Ballooned out frames are effectively replaced with * Ballooned out frames are effectively replaced with
* a scratch frame. Ensure direct mappings and the * a scratch frame. Ensure direct mappings and the
* p2m are consistent. * p2m are consistent.
*/ */
scratch_page = get_balloon_scratch_page(); if (!xen_feature(XENFEAT_auto_translated_physmap)) {
#ifdef CONFIG_XEN_HAVE_PVMMU unsigned long p;
if (xen_pv_domain() && !PageHighMem(page)) { struct page *scratch_page = get_balloon_scratch_page();
if (!PageHighMem(page)) {
ret = HYPERVISOR_update_va_mapping( ret = HYPERVISOR_update_va_mapping(
(unsigned long)__va(pfn << PAGE_SHIFT), (unsigned long)__va(pfn << PAGE_SHIFT),
pfn_pte(page_to_pfn(scratch_page), pfn_pte(page_to_pfn(scratch_page),
PAGE_KERNEL_RO), 0); PAGE_KERNEL_RO), 0);
BUG_ON(ret); BUG_ON(ret);
} }
#endif
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
unsigned long p;
p = page_to_pfn(scratch_page); p = page_to_pfn(scratch_page);
__set_phys_to_machine(pfn, pfn_to_mfn(p)); __set_phys_to_machine(pfn, pfn_to_mfn(p));
}
put_balloon_scratch_page(); put_balloon_scratch_page();
}
#endif
balloon_append(pfn_to_page(pfn)); balloon_append(pfn_to_page(pfn));
} }
...@@ -627,6 +630,7 @@ static int __init balloon_init(void) ...@@ -627,6 +630,7 @@ static int __init balloon_init(void)
if (!xen_domain()) if (!xen_domain())
return -ENODEV; return -ENODEV;
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
for_each_online_cpu(cpu) for_each_online_cpu(cpu)
{ {
per_cpu(balloon_scratch_page, cpu) = alloc_page(GFP_KERNEL); per_cpu(balloon_scratch_page, cpu) = alloc_page(GFP_KERNEL);
...@@ -636,6 +640,7 @@ static int __init balloon_init(void) ...@@ -636,6 +640,7 @@ static int __init balloon_init(void)
} }
} }
register_cpu_notifier(&balloon_cpu_notifier); register_cpu_notifier(&balloon_cpu_notifier);
}
pr_info("Initialising balloon driver\n"); pr_info("Initialising balloon driver\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment