From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roger Pau Monne Subject: [PATCH RFC 01/13] xen: use the hardware e820 map on Dom0 Date: Tue, 24 Dec 2013 12:20:50 +0100 Message-ID: <1387884062-41154-2-git-send-email-roger.pau__28499.1790228107$1387884290$gmane$org@citrix.com> References: <1387884062-41154-1-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VvQ4F-0001EN-4n for xen-devel@lists.xenproject.org; Tue, 24 Dec 2013 11:22:31 +0000 In-Reply-To: <1387884062-41154-1-git-send-email-roger.pau@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: freebsd-xen@freebsd.org, freebsd-current@freebsd.org, xen-devel@lists.xenproject.org, gibbs@freebsd.org, jhb@freebsd.org, kib@freebsd.org, julien.grall@citrix.com Cc: Roger Pau Monne List-Id: xen-devel@lists.xenproject.org We need to do some tweaking of the hardware e820 map, since the memory layout provided by Xen and the e820 map doesn't match. This consists in clamping the e820 map so that regions above max_pfn are marked as unusuable. --- sys/x86/xen/pv.c | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-) diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c index 4f7415e..ab4afba 100644 --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -297,17 +297,48 @@ static void xen_pv_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) { struct xen_memory_map memmap; + unsigned long max_pfn = HYPERVISOR_start_info->nr_pages; + u_int64_t mem_end = ptoa(max_pfn); u_int32_t size; - int rc; + int rc, mem_op, i; /* Fetch the E820 map from Xen */ memmap.nr_entries = MAX_E820_ENTRIES; set_xen_guest_handle(memmap.buffer, xen_smap); - rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); + mem_op = xen_initial_domain() ? + XENMEM_machine_memory_map : + XENMEM_memory_map; + rc = HYPERVISOR_memory_op(mem_op, &memmap); if (rc) panic("unable to fetch Xen E820 memory map"); size = memmap.nr_entries * sizeof(xen_smap[0]); + /* + * This should be improved, Xen provides us with a single + * chunk of physical memory that goes from 0 to max_pfn, + * and what we do here is clamp the HW memory map to make + * sure regions above max_pfn are marked as reserved. + * + * TRTTD would be to move the memory not used because of + * the holes in the HW memory map to the now clamped regions + * using XENMEM_{decrease/increase}_reservation. + */ + for (i = 0; i < memmap.nr_entries; i++) { + u_int64_t end = xen_smap[i].base + xen_smap[i].length; + if (xen_smap[i].type == SMAP_TYPE_MEMORY) { + if (xen_smap[i].base > mem_end) { + /* Mark as reserved */ + xen_smap[i].type = SMAP_TYPE_RESERVED; + continue; + } + if (end > mem_end) { + /* Truncate region */ + xen_smap[i].length -= end - mem_end; + } + } + } + + bios_add_smap_entries(xen_smap, size, physmap, physmap_idx); } -- 1.7.7.5 (Apple Git-26)