From: "Jan Beulich" Subject: [PATCH] x86/Dom0: account for shadow/HAP allocation Date: Wed, 25 Feb 2015 14:45:12 +0000 Message-ID: <54EDEE080200007800063AA4@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE6D352E8.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQdDA-0007zT-89 for xen-devel@lists.xenproject.org; Wed, 25 Feb 2015 14:45:16 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartE6D352E8.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... when calculating how many pages to allocate fopr Dom0. This is basically equivalent to the already present IOMMU related adjustment. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -132,6 +132,8 @@ struct vcpu *__init alloc_dom0_vcpu0(str #ifdef CONFIG_SHADOW_PAGING static bool_t __initdata opt_dom0_shadow; boolean_param("dom0_shadow", opt_dom0_shadow); +#else +#define opt_dom0_shadow 0 #endif =20 static char __initdata opt_dom0_ioports_disable[200] =3D ""; @@ -203,13 +205,23 @@ static struct page_info * __init alloc_c return page; } =20 +static unsigned long __init dom0_paging_pages(const struct domain *d, + unsigned long nr_pages) +{ + /* Copied from: libxl_get_required_shadow_memory() */ + unsigned long memkb =3D nr_pages * (PAGE_SIZE / 1024); + + memkb =3D 4 * (256 * d->max_vcpus + 2 * (memkb / 1024)); + + return ((memkb + 1023) / 1024) << (20 - PAGE_SHIFT); +} + static unsigned long __init compute_dom0_nr_pages( struct domain *d, struct elf_dom_parms *parms, unsigned long = initrd_len) { unsigned long avail =3D avail_domheap_pages() + initial_images_nrpages= (); - unsigned long nr_pages =3D dom0_nrpages; - unsigned long min_pages =3D dom0_min_nrpages; - unsigned long max_pages =3D dom0_max_nrpages; + unsigned long nr_pages, min_pages, max_pages; + bool_t need_paging; =20 /* Reserve memory for further dom0 vcpu-struct allocations... */ avail -=3D (d->max_vcpus - 1UL) @@ -227,23 +239,37 @@ static unsigned long __init compute_dom0 avail -=3D max_pdx >> s; } =20 - /* - * If domain 0 allocation isn't specified, reserve 1/16th of = available - * memory for things like DMA buffers. This reservation is clamped = to=20 - * a maximum of 128MB. - */ - if ( nr_pages =3D=3D 0 ) - nr_pages =3D -min(avail / 16, 128UL << (20 - PAGE_SHIFT)); + need_paging =3D opt_dom0_shadow || (is_pvh_domain(d) && !iommu_hap_pt_= share); + for ( ; ; need_paging =3D 0 ) + { + nr_pages =3D dom0_nrpages; + min_pages =3D dom0_min_nrpages; + max_pages =3D dom0_max_nrpages; + + /* + * If allocation isn't specified, reserve 1/16th of available = memory + * for things like DMA buffers. This reservation is clamped to a + * maximum of 128MB. + */ + if ( nr_pages =3D=3D 0 ) + nr_pages =3D -min(avail / 16, 128UL << (20 - PAGE_SHIFT)); =20 - /* Negative memory specification means "all memory - specified = amount". */ - if ( (long)nr_pages < 0 ) nr_pages +=3D avail; - if ( (long)min_pages < 0 ) min_pages +=3D avail; - if ( (long)max_pages < 0 ) max_pages +=3D avail; - - /* Clamp dom0 memory according to min/max limits and available = memory. */ - nr_pages =3D max(nr_pages, min_pages); - nr_pages =3D min(nr_pages, max_pages); - nr_pages =3D min(nr_pages, avail); + /* Negative specification means "all memory - specified amount". = */ + if ( (long)nr_pages < 0 ) nr_pages +=3D avail; + if ( (long)min_pages < 0 ) min_pages +=3D avail; + if ( (long)max_pages < 0 ) max_pages +=3D avail; + + /* Clamp according to min/max limits and available memory. */ + nr_pages =3D max(nr_pages, min_pages); + nr_pages =3D min(nr_pages, max_pages); + nr_pages =3D min(nr_pages, avail); + + if ( !need_paging ) + break; + + /* Reserve memory for shadow or HAP. */ + avail -=3D dom0_paging_pages(d, nr_pages); + } =20 if ( (parms->p2m_base =3D=3D UNSET_ADDR) && (dom0_nrpages <=3D 0) && ((dom0_min_nrpages <=3D 0) || (nr_pages > min_pages)) ) @@ -1287,14 +1313,7 @@ int __init construct_dom0( } =20 if ( is_pvh_domain(d) ) - { - unsigned long hap_pages, memkb =3D nr_pages * (PAGE_SIZE / 1024); - - /* Copied from: libxl_get_required_shadow_memory() */ - memkb =3D 4 * (256 * d->max_vcpus + 2 * (memkb / 1024)); - hap_pages =3D ( (memkb + 1023) / 1024) << (20 - PAGE_SHIFT); - hap_set_alloc_for_pvh_dom0(d, hap_pages); - } + hap_set_alloc_for_pvh_dom0(d, dom0_paging_pages(d, nr_pages)); =20 /* * We enable paging mode again so guest_physmap_add_page will do the --=__PartE6D352E8.1__= Content-Type: text/plain; name="x86-Dom0-nr-pages.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-Dom0-nr-pages.patch" x86/Dom0: account for shadow/HAP allocation=0A=0A... when calculating how = many pages to allocate fopr Dom0. This is=0Abasically equivalent to the = already present IOMMU related adjustment.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/domain_build.c=0A+++ b/xen/arch= /x86/domain_build.c=0A@@ -132,6 +132,8 @@ struct vcpu *__init alloc_dom0_vc= pu0(str=0A #ifdef CONFIG_SHADOW_PAGING=0A static bool_t __initdata = opt_dom0_shadow;=0A boolean_param("dom0_shadow", opt_dom0_shadow);=0A+#else= =0A+#define opt_dom0_shadow 0=0A #endif=0A =0A static char __initdata = opt_dom0_ioports_disable[200] =3D "";=0A@@ -203,13 +205,23 @@ static = struct page_info * __init alloc_c=0A return page;=0A }=0A =0A+static = unsigned long __init dom0_paging_pages(const struct domain *d,=0A+ = unsigned long nr_pages)=0A+{=0A+ = /* Copied from: libxl_get_required_shadow_memory() */=0A+ unsigned long = memkb =3D nr_pages * (PAGE_SIZE / 1024);=0A+=0A+ memkb =3D 4 * (256 * = d->max_vcpus + 2 * (memkb / 1024));=0A+=0A+ return ((memkb + 1023) / = 1024) << (20 - PAGE_SHIFT);=0A+}=0A+=0A static unsigned long __init = compute_dom0_nr_pages(=0A struct domain *d, struct elf_dom_parms = *parms, unsigned long initrd_len)=0A {=0A unsigned long avail =3D = avail_domheap_pages() + initial_images_nrpages();=0A- unsigned long = nr_pages =3D dom0_nrpages;=0A- unsigned long min_pages =3D dom0_min_nrpa= ges;=0A- unsigned long max_pages =3D dom0_max_nrpages;=0A+ unsigned = long nr_pages, min_pages, max_pages;=0A+ bool_t need_paging;=0A =0A = /* Reserve memory for further dom0 vcpu-struct allocations... */=0A = avail -=3D (d->max_vcpus - 1UL)=0A@@ -227,23 +239,37 @@ static unsigned = long __init compute_dom0=0A avail -=3D max_pdx >> s;=0A = }=0A =0A- /*=0A- * If domain 0 allocation isn't specified, reserve = 1/16th of available=0A- * memory for things like DMA buffers. This = reservation is clamped to =0A- * a maximum of 128MB.=0A- */=0A- = if ( nr_pages =3D=3D 0 )=0A- nr_pages =3D -min(avail / 16, 128UL << = (20 - PAGE_SHIFT));=0A+ need_paging =3D opt_dom0_shadow || (is_pvh_domai= n(d) && !iommu_hap_pt_share);=0A+ for ( ; ; need_paging =3D 0 )=0A+ = {=0A+ nr_pages =3D dom0_nrpages;=0A+ min_pages =3D dom0_min_n= rpages;=0A+ max_pages =3D dom0_max_nrpages;=0A+=0A+ /*=0A+ = * If allocation isn't specified, reserve 1/16th of available = memory=0A+ * for things like DMA buffers. This reservation is = clamped to a=0A+ * maximum of 128MB.=0A+ */=0A+ if = ( nr_pages =3D=3D 0 )=0A+ nr_pages =3D -min(avail / 16, 128UL = << (20 - PAGE_SHIFT));=0A =0A- /* Negative memory specification means = "all memory - specified amount". */=0A- if ( (long)nr_pages < 0 ) = nr_pages +=3D avail;=0A- if ( (long)min_pages < 0 ) min_pages +=3D = avail;=0A- if ( (long)max_pages < 0 ) max_pages +=3D avail;=0A-=0A- = /* Clamp dom0 memory according to min/max limits and available memory. = */=0A- nr_pages =3D max(nr_pages, min_pages);=0A- nr_pages =3D = min(nr_pages, max_pages);=0A- nr_pages =3D min(nr_pages, avail);=0A+ = /* Negative specification means "all memory - specified amount". = */=0A+ if ( (long)nr_pages < 0 ) nr_pages +=3D avail;=0A+ = if ( (long)min_pages < 0 ) min_pages +=3D avail;=0A+ if ( (long)max_= pages < 0 ) max_pages +=3D avail;=0A+=0A+ /* Clamp according to = min/max limits and available memory. */=0A+ nr_pages =3D max(nr_page= s, min_pages);=0A+ nr_pages =3D min(nr_pages, max_pages);=0A+ = nr_pages =3D min(nr_pages, avail);=0A+=0A+ if ( !need_paging )=0A+ = break;=0A+=0A+ /* Reserve memory for shadow or HAP. = */=0A+ avail -=3D dom0_paging_pages(d, nr_pages);=0A+ }=0A =0A = if ( (parms->p2m_base =3D=3D UNSET_ADDR) && (dom0_nrpages <=3D 0) &&=0A = ((dom0_min_nrpages <=3D 0) || (nr_pages > min_pages)) )=0A@@ = -1287,14 +1313,7 @@ int __init construct_dom0(=0A }=0A =0A if ( = is_pvh_domain(d) )=0A- {=0A- unsigned long hap_pages, memkb =3D = nr_pages * (PAGE_SIZE / 1024);=0A-=0A- /* Copied from: libxl_get_req= uired_shadow_memory() */=0A- memkb =3D 4 * (256 * d->max_vcpus + 2 = * (memkb / 1024));=0A- hap_pages =3D ( (memkb + 1023) / 1024) << = (20 - PAGE_SHIFT);=0A- hap_set_alloc_for_pvh_dom0(d, hap_pages);=0A-= }=0A+ hap_set_alloc_for_pvh_dom0(d, dom0_paging_pages(d, = nr_pages));=0A =0A /*=0A * We enable paging mode again so = guest_physmap_add_page will do the=0A --=__PartE6D352E8.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartE6D352E8.1__=--