Patch "xen/balloon: Mark unallocated host memory as UNUSABLE" has been added to the 4.14-stable tree
Subsystems (4)
This is a note to let you know that I've just added the patch titled
xen/balloon: Mark unallocated host memory as UNUSABLE
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
xen-balloon-mark-unallocated-host-memory-as-unusable.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Wed Feb 28 16:23:28 CET 2018
From: Boris Ostrovsky <[email protected]>
Date: Tue, 12 Dec 2017 15:08:21 -0500
Subject: xen/balloon: Mark unallocated host memory as UNUSABLE
From: Boris Ostrovsky <[email protected]>
[ Upstream commit b3cf8528bb21febb650a7ecbf080d0647be40b9f ]
Commit f5775e0b6116 ("x86/xen: discard RAM regions above the maximum reservation") left host memory not assigned to dom0 as available for memory hotplug.
Unfortunately this also meant that those regions could be used by others. Specifically, commit fa564ad96366 ("x86/PCI: Enable a 64bit BAR on AMD Family 15h (Models 00-1f, 30-3f, 60-7f)") may try to map those addresses as MMIO.
To prevent this mark unallocated host memory as E820_TYPE_UNUSABLE (thus effectively reverting f5775e0b6116) and keep track of that region as a hostmem resource that can be used for the hotplug.
--- arch/x86/xen/enlighten.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/xen/setup.c | 6 +-- drivers/xen/balloon.c | 65 ++++++++++++++++++++++++++++++++----- include/xen/balloon.h | 5 ++ 4 files changed, 144 insertions(+), 13 deletions(-)
arch/x86/xen/enlighten.c +81 -0
@@ -1,8 +1,12 @@ +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG +#include <linux/bootmem.h> +#endif #include <linux/cpu.h> #include <linux/kexec.h> #include <xen/features.h> #include <xen/page.h> +#include <xen/interface/memory.h> #include <asm/xen/hypercall.h> #include <asm/xen/hypervisor.h>
@@ -331,3 +335,80 @@ void xen_arch_unregister_cpu(int num) }EXPORT_SYMBOL (xen_arch_unregister_cpu);#endif + +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG +void __init arch_xen_balloon_init (struct resource *hostmem_resource) +{ +struct xen_memory_map memmap; +int rc; +unsigned int i, last_guest_ram; +phys_addr_t max_addr =PFN_PHYS (max_pfn); +struct e820_table *xen_e820_table; +const struct e820_entry *entry; +struct resource *res; + +if (!xen_initial_domain ()) +return ; + + xen_e820_table =kmalloc (sizeof (*xen_e820_table),GFP_KERNEL ); +if (!xen_e820_table) +return ; + + memmap.nr_entries =ARRAY_SIZE (xen_e820_table->entries); +set_xen_guest_handle (memmap.buffer, xen_e820_table->entries); + rc =HYPERVISOR_memory_op (XENMEM_machine_memory_map, &memmap); +if (rc) { +pr_warn ("%s: Can't read host e820 (%d)\n" , __func__, rc); + goto out; + } + + last_guest_ram =0 ; +for (i =0 ; i < memmap.nr_entries; i++) { +if (xen_e820_table->entries[i].addr >= max_addr) +break ; +if (xen_e820_table->entries[i].type ==E820_TYPE_RAM ) + last_guest_ram = i; + } + + entry = &xen_e820_table->entries[last_guest_ram]; +if (max_addr >= entry->addr + entry->size) + goto out;/* No unallocated host RAM. */ + + hostmem_resource->start = max_addr; + hostmem_resource->end = entry->addr + entry->size; + +/* +* Mark non-RAM regions between the end of dom0 RAM and end of host RAM +* as unavailable. The rest of that region can be used for hotplug-based +* ballooning. +*/ +for (; i < memmap.nr_entries; i++) { + entry = &xen_e820_table->entries[i]; + +if (entry->type ==E820_TYPE_RAM ) +continue ; + +if (entry->addr >= hostmem_resource->end) +break ; + + res =kzalloc (sizeof (*res),GFP_KERNEL ); +if (!res) + goto out; + + res->name ="Unavailable host RAM" ; + res->start = entry->addr; + res->end = (entry->addr + entry->size < hostmem_resource->end) ? + entry->addr + entry->size : hostmem_resource->end; + rc =insert_resource (hostmem_resource, res); +if (rc) { +pr_warn ("%s: Can't insert [%llx - %llx) (%d)\n" , + __func__, res->start, res->end, rc); +kfree (res); + goto out; + } + } + + out: +kfree (xen_e820_table); +} +#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */
arch/x86/xen/setup.c +2 -4
@@ -808,7 +808,6 @@ char * __init xen_memory_setup(void) addr = xen_e820_table.entries[0 ].addr; size = xen_e820_table.entries[0 ].size;while (i < xen_e820_table.nr_entries) { -bool discard = false; chunk_size = size; type = xen_e820_table.entries[i].type;
@@ -824,11 +823,10 @@ char * __init xen_memory_setup(void)xen_add_extra_mem (pfn_s, n_pfns); xen_max_p2m_pfn = pfn_s + n_pfns; }else - discard = true; + type =E820_TYPE_UNUSABLE ; } -if (!discard) -xen_align_and_add_e820_region (addr, chunk_size, type); +xen_align_and_add_e820_region (addr, chunk_size, type); addr += chunk_size; size -= chunk_size;
drivers/xen/balloon.c +56 -9
91 lines not on this page · raw message
include/xen/balloon.h +5 -0
@@ -44,3 +44,8 @@ static inline void xen_balloon_init(void { }#endif + +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG +struct resource ; +void arch_xen_balloon_init (struct resource *hostmem_resource); +#endif
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/xen-gntdev-fix-off-by-one-error-when-unmapping-with-holes.patch queue-4.14/xen-balloon-mark-unallocated-host-memory-as-unusable.patch queue-4.14/xen-gntdev-fix-partial-gntdev_mmap-cleanup.patch queue-4.14/x86-64-xen-eliminate-w-x-mappings.patch queue-4.14/xen-netfront-enable-device-after-manual-module-load.patch