From: Sergey Dyasli Date: Thu, 11 Jan 2018 11:41:20 +0000 (+0000) Subject: xen/pvshim: add shim_mem cmdline parameter X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~777 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=daed6261fd1294bce3e103228c2f34732ef29a9e;p=xen.git xen/pvshim: add shim_mem cmdline parameter Signed-off-by: Sergey Dyasli --- diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown index 579e549821..164ff31909 100644 --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -714,6 +714,8 @@ any dom0 autoballooning feature present in your toolstack. See the _xl.conf(5)_ man page or [Xen Best Practices](http://wiki.xen.org/wiki/Xen_Best_Practices#Xen_dom0_dedicated_memory_and_preventing_dom0_memory_ballooning). +This option doesn't have effect if pv-shim mode is enabled. + ### dom0\_nodes > `= List of [ | relaxed | strict ]` @@ -1484,6 +1486,20 @@ guest compatibly inside an HVM container. In this mode, the kernel and initrd passed as modules to the hypervisor are constructed into a plain unprivileged PV domain. +### shim\_mem (x86) +> `= List of ( min: | max: | )` + +Set the amount of memory that xen-shim reserves for itself. Only has effect +if pv-shim mode is enabled. + +* `min:` specifies the minimum amount of memory. Ignored if greater + than max. Default: 10M. +* `max:` specifies the maximum amount of memory. Default: 128M. +* `` specifies the exact amount of memory. Overrides both min and max. + +By default, 1/16th of total HVM container's memory is reserved for xen-shim +with minimum amount being 10MB and maximum amount 128MB. + ### rcu-idle-timer-period-ms > `= ` diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 8600123516..2aac0803fc 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -51,6 +51,13 @@ static long __init parse_amt(const char *s, const char **ps) static int __init parse_dom0_mem(const char *s) { + /* xen-shim uses shim_mem parameter instead of dom0_mem */ + if ( pv_shim ) + { + printk("Ignoring dom0_mem param in pv-shim mode\n"); + return 0; + } + do { if ( !strncmp(s, "min:", 4) ) dom0_min_nrpages = parse_amt(s+4, &s); @@ -284,7 +291,16 @@ unsigned long __init dom0_compute_nr_pages( * maximum of 128MB. */ if ( nr_pages == 0 ) - nr_pages = -min(avail / 16, 128UL << (20 - PAGE_SHIFT)); + { + uint64_t rsvd = min(avail / 16, 128UL << (20 - PAGE_SHIFT)); + if ( pv_shim ) + { + rsvd = pv_shim_mem(avail); + printk("Reserved %lu pages for xen-shim\n", rsvd); + + } + nr_pages = -rsvd; + } /* Negative specification means "all memory - specified amount". */ if ( (long)nr_pages < 0 ) nr_pages += avail; diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index c53a4ca407..6dc1ee45d7 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -53,6 +53,52 @@ static long pv_shim_grant_table_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count); +/* + * By default, 1/16th of total HVM container's memory is reserved for xen-shim + * with minimum amount being 10MB and maximum amount 128MB. Some users may wish + * to tune this constants for better memory utilization. This can be achieved + * using the following xen-shim's command line option: + * + * shim_mem=[min:,][max:,][] + * + * : The minimum amount of memory that should be allocated for xen-shim + * (ignored if greater than max) + * : The maximum amount of memory that should be allocated for xen-shim + * : The precise amount of memory to allocate for xen-shim + * (overrides both min and max) + */ +static uint64_t __initdata shim_nrpages; +static uint64_t __initdata shim_min_nrpages = 10UL << (20 - PAGE_SHIFT); +static uint64_t __initdata shim_max_nrpages = 128UL << (20 - PAGE_SHIFT); + +static int __init parse_shim_mem(const char *s) +{ + do { + if ( !strncmp(s, "min:", 4) ) + shim_min_nrpages = parse_size_and_unit(s+4, &s) >> PAGE_SHIFT; + else if ( !strncmp(s, "max:", 4) ) + shim_max_nrpages = parse_size_and_unit(s+4, &s) >> PAGE_SHIFT; + else + shim_nrpages = parse_size_and_unit(s, &s) >> PAGE_SHIFT; + } while ( *s++ == ',' ); + + return s[-1] ? -EINVAL : 0; +} +custom_param("shim_mem", parse_shim_mem); + +uint64_t pv_shim_mem(uint64_t avail) +{ + uint64_t rsvd = min(avail / 16, shim_max_nrpages); + + if ( shim_nrpages ) + return shim_nrpages; + + if ( shim_min_nrpages <= shim_max_nrpages ) + rsvd = max(rsvd, shim_min_nrpages); + + return rsvd; +} + #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER| \ _PAGE_GUEST_KERNEL) #define COMPAT_L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) diff --git a/xen/include/asm-x86/pv/shim.h b/xen/include/asm-x86/pv/shim.h index 4d5f0b43fc..0ef452158e 100644 --- a/xen/include/asm-x86/pv/shim.h +++ b/xen/include/asm-x86/pv/shim.h @@ -38,6 +38,7 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, int pv_shim_shutdown(uint8_t reason); void pv_shim_inject_evtchn(unsigned int port); domid_t get_initial_domain_id(void); +uint64_t pv_shim_mem(uint64_t avail); #else @@ -63,6 +64,11 @@ static inline domid_t get_initial_domain_id(void) { return 0; } +static inline uint64_t pv_shim_mem(uint64_t avail) +{ + ASSERT_UNREACHABLE(); + return 0; +} #endif