From owner-freebsd-current@FreeBSD.ORG Tue Jan 21 19:03:17 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AACFC460; Tue, 21 Jan 2014 19:03:17 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7F2F81E10; Tue, 21 Jan 2014 19:03:17 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 71FC2B94C; Tue, 21 Jan 2014 14:03:16 -0500 (EST) From: John Baldwin To: Roger Pau Monne Subject: Re: [PATCH RFC 01/13] xen: use the hardware e820 map on Dom0 Date: Tue, 21 Jan 2014 13:25:29 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <1387884062-41154-1-git-send-email-roger.pau@citrix.com> <1387884062-41154-2-git-send-email-roger.pau@citrix.com> In-Reply-To: <1387884062-41154-2-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201401211325.29460.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 21 Jan 2014 14:03:16 -0500 (EST) Cc: julien.grall@citrix.com, freebsd-xen@freebsd.org, freebsd-current@freebsd.org, kib@freebsd.org, xen-devel@lists.xenproject.org, gibbs@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jan 2014 19:03:17 -0000 On Tuesday, December 24, 2013 6:20:50 am Roger Pau Monne wrote: > 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; One minor nit is that it is preferred to not initalize variables in declarations style-wise. Aside from that, this looks fine to me. > /* 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) > > -- John Baldwin