[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 1/6] x86/PVH: improve Dom0 memory size calculation


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 22 Oct 2021 11:55:50 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UTo9TBQcK1jyKcuXW85QXab6ida/aLRFTSoVKZPUKK8=; b=elj+IswdSU/9jj5M70VpErrFMa3/niS4Ui3NA/idK0K7q8rN621KzebITk/K2YYeyxRPNOsELWK2V2tAo5c5L42masURCnaBFzVkY+IyVQwxZ/23PeWKj0F7TT0k/kMg6v/LNufl0MQMmr6+GoRFR9TCqHUsl0E2MN3A3L3/NUnBuUDLo1XTUaLL/oBFpMQf5Xi2hIjGlJG/5C2jc2blM8Hf/rEHPWslhEe35GR8i2E+WDkIcAwj6SrxJ/RuW24y+ODHKG7E1Zlvr6ViHBFcX5kxdKhcJt+9DIBbwC2sGAHkfABJWVruZ76AjBg8zFl6/OQLtiS96CJNj0WIUN+FtQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KU1UjmwE8w7NNPf/eQDq/30NZDZ4eJofRC5GSsqhyQEAE111MAUtTHObroV20nDdF7FJQBtQOOkNrwfsVQmhHm2HPoRaJOQPG5L2dz++6D2ZZvqDcKkojMQ55C69/1XTBYOIOzOI0TDNKKK72K6jAjIZ9qkb+PCLDHiiulcg8CmfQ8X3QxZ07S9wsxEa/1Tb4ReqfDuow9FAfxWklvjNFGnlvPxqXBaHAm/V3sM11OW+J+dS7fWfSxec79LZ8NpLuG3NdncoidUSIxMWW75c37abvmBDfCemk1UMyAVMts78tHk8O3C3RHmWQvdjiFm/2sEdGqPM7RMbCJdA3pTUZw==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 22 Oct 2021 09:56:07 +0000
  • Ironport-data: A9a23:KaGVLKBk2F6iOxVW//Lkw5YqxClBgxIJ4kV8jS/XYbTApDtw02BTz GIXWm7VPPeNYWCgc4p0atm1oUhT6JCHm983QQY4rX1jcSlH+JHPbTi7wuYcHM8wwunrFh8PA xA2M4GYRCwMo/u1Si6FatANl1ElvU2zbue6WLGs1hxZH1c+EX5500g7wYbVv6Yz6TSHK1LV0 T/Ni5W31G+Ng1aY5UpNtspvADs21BjDkGtwUm4WPJinj3eH/5UhN7oNJLnZEpfNatI88thW5 Qr05OrREmvxp3/BAz4++1rxWhVirrX6ZWBihpfKMkQLb9crSiEai84G2PQghUh/uxiZgdZz+ v50hLvvVCF1B/Tz3/4MXEwNe81+FfUuFL7vJHG+tYqYzlHccmuqyPJrZK00FdRGoKAtWzgIr KFGbmBWBvyAr7veLLaTUO5ji95lNMD2FIgepmth3XfSCvNOrZXrHviauYcFgGdYasZmQurPa u8SThZUSh3NfURREVYzA7Qeg7L97pX4W2IB8w/EzUYt2EDMyCRh3b6rN8DaEvSaSMMQkkuGq 2bu+2XiHgpcJNGZ0SCC8H+nmqnIhyyTcIAYGaC89/VqqEaO3WFVAxoTPWZXutHg1BT4AYgGb RVJpGx+9sDe6XBHUPHNcg2mpny2lSctfIVNNbEDsT7K0LvbtlPx6nc/chZNb9kvtckTTDMs1 0OUk96B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9IXjJjVWPHxXgspbnmFE43OgYzVLrX59dOME/f Snl656jgvlXU5SQtWwB3EDUeSGjcbMjojabRkPAANiwBWSjBuzgYSKUySw71M7aXdi0L0i+W /Kn0jS/aO4qcy2zRfayiv684lWot380dFObfb8yfT9aw+cyDpAVr4RH4FqjwpF591HL2xa1u Ukli1QevibLUmhJ11d7yGdgzUImwxemkMKgWXo8UcL5/aJHw7TT6F69Nhkm1LimjkdlcA536 RR022DsZ1LSRvGgSTm/tDNEwpnj0yuvBMZ4KMuZlFkIMAjgYVq3MYiFYJuYeA9NTO/7JpiHP hlDcna6voTeVSGb2rBtm0qxNC3RHw8EhqPX0BH46WuondrtWE8y1FdyN0Un38G+p54Q55Y5/ 7cOqAtkL1VVMcZYa90Ge9ES8qqDW7GRw7KLQupUBjaPbBCP2iIp4/84b0z6u3vcJsUzIEqkJ CES19cvX5aQTOnNSRP5uwDzvngehTJYd3d8LAp23EigMyPeFPCC1z2dGwT
  • Ironport-sdr: 27zrPdD7SZoi4uQahePBhYstjTeG9PgCDXb4OfU3yR7csNG9h2+mo7qcSC16zNTqn0vPDvRH2b 9zncU+d6sGOEJxHOs4rvEBuozU649PGE1DKPXk7TyP5jPo5zhZZGjvmhISsz+jVkbVp5yDoKZZ wuwq8mXmKckrQ/yJwBWe9ZcSLdUV8YTIFPmqu8hr6GYZhNm2mn1kmrdp3lQxFoDG7cT0Lpxweh 28AdUenyreTKCD672WBtNCdVFdPubWp8EJeadYFEjAb9UITHPNZtrNXWVXd01vaxqz4W0FR5ff jnKDUb7NJnbuwaffrn3Sb7A4
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, Sep 29, 2021 at 03:13:24PM +0200, Jan Beulich wrote:
> Assuming that the accounting for IOMMU page tables will also take care
> of the P2M needs was wrong: dom0_paging_pages() can determine a far
> higher value, high enough for the system to run out of memory while
> setting up Dom0. Hence in the case of shared page tables the larger of
> the two values needs to be used (without shared page tables the sum of
> both continues to be applicable).
> 
> To not further complicate the logic, eliminate the up-to-2-iteration
> loop in favor of doing a few calculations twice (before and after
> calling dom0_paging_pages()). While this will lead to slightly too high
> a value in "cpu_pages", it is deemed better to account a few too many
> than a few too little.
> 
> Also uniformly use paging_mode_enabled(), not is_hvm_domain().
> 
> While there also account for two further aspects in the PV case: With
> "iommu=dom0-passthrough" no IOMMU page tables would get allocated, so
> none need accounting for. And if shadow mode is to be enabled, setting
> aside a suitable amount for the P2M pool to get populated is also
> necessary (i.e. similar to the non-shared-page-tables case of PVH).
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> I wonder whether this isn't enough to drop the "PVH dom0 without
> dom0_mem" warning.
> 
> --- a/xen/arch/x86/dom0_build.c
> +++ b/xen/arch/x86/dom0_build.c
> @@ -318,8 +318,7 @@ unsigned long __init dom0_compute_nr_pag
>      struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_len)
>  {
>      nodeid_t node;
> -    unsigned long avail = 0, nr_pages, min_pages, max_pages;
> -    bool need_paging;
> +    unsigned long avail = 0, nr_pages, min_pages, max_pages, iommu_pages = 0;
>  
>      /* The ordering of operands is to work around a clang5 issue. */
>      if ( CONFIG_DOM0_MEM[0] && !dom0_mem_set )
> @@ -337,53 +336,65 @@ unsigned long __init dom0_compute_nr_pag
>          avail -= d->max_vcpus - 1;
>  
>      /* Reserve memory for iommu_dom0_init() (rough estimate). */
> -    if ( is_iommu_enabled(d) )
> +    if ( is_iommu_enabled(d) && !iommu_hwdom_passthrough )
>      {
>          unsigned int s;
>  
>          for ( s = 9; s < BITS_PER_LONG; s += 9 )
> -            avail -= max_pdx >> s;
> +            iommu_pages += max_pdx >> s;
> +
> +        avail -= iommu_pages;
> +    }
> +
> +    nr_pages = get_memsize(&dom0_size, avail);
> +
> +    /*
> +     * 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 )
> +    {
> +        nr_pages = avail - (pv_shim ? pv_shim_mem(avail)
> +                            : min(avail / 16, 128UL << (20 - PAGE_SHIFT)));
> +        if ( paging_mode_enabled(d) )
> +            /*
> +             * Temporary workaround message until internal (paging) memory
> +             * accounting required to build a pvh dom0 is improved.
> +             */
> +            printk("WARNING: PVH dom0 without dom0_mem set is still 
> unstable. "
> +                   "If you get crashes during boot, try adding a dom0_mem 
> parameter\n");
>      }
>  
> -    need_paging = is_hvm_domain(d) &&
> -        (!iommu_use_hap_pt(d) || !paging_mode_hap(d));
> -    for ( ; ; need_paging = false )
> +    if ( paging_mode_enabled(d) || opt_dom0_shadow )

Do we also need to account for opt_pv_l1tf_hwdom in case dom0 gets
shadowing enabled during runtime?

The rest LGTM, so:

Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

I'm also fine if you want to remove the warning message at this time.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.