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

[PATCH RFC] x86+libxl: correct p2m (shadow) memory pool size calculation


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 22 Apr 2022 12:57:03 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=50ko0r9Z9sZripDqhzhdZ+ifhKviRjtt7QFwGCPfRnI=; b=laYd7pEuTRbNQqr7j09s7Xw5ZIyBuaUYgiE4N79k8XOSiaokVfD3h3uQxAPiWWlgDtZmv/OUW7h3ICfpfYBWHRYYqTy3wFZOGa8D2tNJAtE8mKix6ip0/xCLxX+nl8/sjzISY2lwdy4GuLJQGeCdnf3jhyOuE4PE8XN0GogmALV8Xtoyi/NqWWhje+zRVPWWZZcaST7nflJbOykWBeUDMLE1+JxaFtA/3BLpo/dPPhfo4CgWd38j2PGRptNCoVD33DXmgTA9qcngrMcxPKzGADpoV3iGcfF4lF9rK/M1ZVvBtsP2Tdyq30Nr09U+7SCGkusqS0sQqFU+zu96YmzTKw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VlyRxy/TE+glo6GB9jhSSWjqSj3PCooym3mTQ5X+q/vFGw0esE/v8TYm/t/OOsx8W4kRwY9tyqbb0U6gL47Ne46kk7kpe4SVArJmZQ82u+cWxMEAqycC/eBWgW5E0ogXhyMZVK2voulwdJ5754FYEJCa6ufNrrQjvE/WAdjU4r0714sCDGBx97kQzV1yh1xl6FQSReT3UN8UCSVBXz2IdRDyGP6yGdSrnLPQlyS+tC3be5HM+gA9EbP4OMb94mBhGof7TYsbdUeLhOu+SlQUNBbbc1/TSqUPv9CJn2cQTom29SqJsfPbFAbPu0UmpaoW1LdgdhD6kHC5akBAzgKr+w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Fri, 22 Apr 2022 10:57:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The reference "to shadow the resident processes" is applicable to
domains (potentially) running in shadow mode only. Adjust the
calculations accordingly.

In dom0_paging_pages() also take the opportunity and stop open-coding
DIV_ROUND_UP().

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
RFC: I'm pretty sure I can't change a public libxl function (deprecated
     or not) like this, but I also don't know how I should go about
     doing so (short of introducing a brand new function and leaving the
     existing one broken).

--- a/tools/include/libxl_utils.h
+++ b/tools/include/libxl_utils.h
@@ -23,7 +23,10 @@ const
 #endif
 char *libxl_basename(const char *name); /* returns string from strdup */
 
-unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, 
unsigned int smp_cpus);
+unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb,
+                                               unsigned int smp_cpus,
+                                               libxl_domain_type type,
+                                               bool hap);
   /* deprecated; see LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONFIG in libxl.h */
 int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
 int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const char *name, uint32_t 
*domid);
--- a/tools/libs/light/libxl_create.c
+++ b/tools/libs/light/libxl_create.c
@@ -1194,10 +1194,17 @@ int libxl__domain_config_setdefault(libx
     }
 
     if (d_config->b_info.shadow_memkb == LIBXL_MEMKB_DEFAULT
-        && ok_to_default_memkb_in_create(gc))
+        && ok_to_default_memkb_in_create(gc)) {
+        bool hap = d_config->c_info.type != LIBXL_DOMAIN_TYPE_PV
+                   ? libxl_defbool_val(d_config->c_info.hap)
+                   : false;
+
         d_config->b_info.shadow_memkb =
             libxl_get_required_shadow_memory(d_config->b_info.max_memkb,
-                                             d_config->b_info.max_vcpus);
+                                             d_config->b_info.max_vcpus,
+                                             d_config->c_info.type,
+                                             hap);
+    }
 
     /* No IOMMU reservation is needed if passthrough mode is not 'sync_pt' */
     if (d_config->b_info.iommu_memkb == LIBXL_MEMKB_DEFAULT
--- a/tools/libs/light/libxl_utils.c
+++ b/tools/libs/light/libxl_utils.c
@@ -36,15 +36,21 @@ char *libxl_basename(const char *name)
     return strdup(name);
 }
 
-unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, 
unsigned int smp_cpus)
+unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb,
+                                               unsigned int smp_cpus,
+                                               libxl_domain_type type,
+                                               bool hap)
 {
     /* 256 pages (1MB) per vcpu,
-       plus 1 page per MiB of RAM for the P2M map,
-       plus 1 page per MiB of RAM to shadow the resident processes.
+       plus 1 page per MiB of RAM for the P2M map (for non-PV guests),
+       plus 1 page per MiB of RAM to shadow the resident processes (for shadow
+       mode guests).
        This is higher than the minimum that Xen would allocate if no value
        were given (but the Xen minimum is for safety, not performance).
      */
-    return 4 * (256 * smp_cpus + 2 * (maxmem_kb / 1024));
+    return 4 * (256 * smp_cpus +
+                ((type != LIBXL_DOMAIN_TYPE_PV) + !hap) *
+                (maxmem_kb / 1024));
 }
 
 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid)
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -317,9 +317,12 @@ unsigned long __init dom0_paging_pages(c
     /* Copied from: libxl_get_required_shadow_memory() */
     unsigned long memkb = nr_pages * (PAGE_SIZE / 1024);
 
-    memkb = 4 * (256 * d->max_vcpus + 2 * (memkb / 1024));
+    memkb = 4 * (256 * d->max_vcpus +
+                 (paging_mode_enabled(d) +
+                  (opt_dom0_shadow || opt_pv_l1tf_hwdom)) *
+                 (memkb / 1024));
 
-    return ((memkb + 1023) / 1024) << (20 - PAGE_SHIFT);
+    return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT);
 }
 
 




 


Rackspace

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