From patchwork Fri Oct 18 15:06:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 11198635 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDEA96A61 for ; Fri, 18 Oct 2019 15:09:43 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E58D222C6 for ; Fri, 18 Oct 2019 15:09:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="SF+HHc+j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E58D222C6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=eu.citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iLTqK-00050m-Il; Fri, 18 Oct 2019 15:07:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iLTqJ-00050f-P2 for xen-devel@lists.xenproject.org; Fri, 18 Oct 2019 15:07:03 +0000 X-Inumbo-ID: eee8016e-f1b8-11e9-93f5-12813bfff9fa Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id eee8016e-f1b8-11e9-93f5-12813bfff9fa; Fri, 18 Oct 2019 15:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1571411220; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=mcnHNnuobJVIoAVNjV2dKd+l7QxXNdod66g53zaBt+0=; b=SF+HHc+jf5+AlilwvmRWglRM937WjqT+ieBXw0uZ7fMp3UbmBXzQFFet BLcMskmZBDdC9Gctxp/hf1Ofa0BhVW06fjyQ4WQAfmzjQDhvt5H2eRAfd BBQ4HncieQQhXQE8KQ8x6Z2yepNRzcQCgi9Zp1MzBLN329nJU1xZrU8QS M=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=ian.jackson@eu.citrix.com; spf=Pass smtp.mailfrom=Ian.Jackson@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of ian.jackson@eu.citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Ian.Jackson@citrix.com"; x-sender="ian.jackson@eu.citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of Ian.Jackson@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Ian.Jackson@citrix.com"; x-sender="Ian.Jackson@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Ian.Jackson@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: OoxVqheXOykuCz+MwgDuY70+V3jAeC0VSPa9U9lUhrIhYJPyKRAsT4F6CwqJTE6SsxpJsjK842 HDfHsYmaW2iXgSwbpDN3g4ztENOjoepj5/t7jhZxXTDx8NCBzLkW3BzWz2wxV5+EUKyX1RyNWe AoIkrXzc7MsMlYMS4GJw/Fm7W3ZwijyADwjh1MXz0UB5hkXFvtkBMWdE0zfsGnp0UQQJtcOIwU ix4Sl94WbePcHZ8Qw5G2HfseGCc5fqYOFqJMd0P33t1exSNkdvyb1YFbvTw6GUyw98g4CJHlQj uKQ= X-SBRS: 2.7 X-MesageID: 7099409 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.67,312,1566878400"; d="scan'208";a="7099409" From: Ian Jackson To: Date: Fri, 18 Oct 2019 16:06:47 +0100 Message-ID: <20191018150653.24862-5-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191018150653.24862-1-ian.jackson@eu.citrix.com> References: <20191018150653.24862-1-ian.jackson@eu.citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH for-4.13 v5 04/10] libxl: libxl_domain_need_memory: Make it take a domain_config X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Paul Durrant , Ian Jackson , Jan Beulich , Andrew Cooper Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This should calculate the extra memory needed for shadow and iommu, the defaults for which depend on values in c_info. So we need this to have the complete domain config available. And the defaults should actually be updated and stored. So make it non-const. We provide the usual kind of compatibility function for callers expecting 4.12 and earlier. This function becomes responsible for the clone-and-modify of the b_info. No overall functional change for external libxl callers which use the API version system to request a particular API version. Other external libxl callers will need to update their calling code, and will then find that the new version of this function fills in most of the defaults in d_config. Because libxl__domain_config_setdefault doesn't quite do all of the defaults, that's only partial. For present purposes that doesn't matter because none of the missing settings are used by the memory calculations. It does mean we need to document in the API spec that the defaulting is only partial. This lack of functional change is despite the fact that numa_place_domain now no longer calls libxl__domain_build_info_setdefault (via libxl_domain_need_memory). That is OK because it's idempotent and numa_place_domain's one call site is libxl__build_pre which is called from libxl__domain_build which is called from domcreate_bootloader_done, well after the defaults are set by initiate_domain_create. Signed-off-by: Ian Jackson Reviewed-by: Anthony PERARD --- v2: Drop now-erroneous GC_FREE as well as the corresponding GC_INIT. --- tools/libxl/libxl.h | 23 +++++++++++++++- tools/libxl/libxl_dom.c | 7 +++-- tools/libxl/libxl_internal.h | 4 +++ tools/libxl/libxl_mem.c | 65 +++++++++++++++++++++++++++++++++++--------- tools/xl/xl_vmcontrol.c | 2 +- 5 files changed, 83 insertions(+), 18 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 518fc9e47f..49b56fa1a3 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1245,6 +1245,20 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); */ #define LIBXL_HAVE_FN_USING_QMP_ASYNC 1 +/* + * LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONFIG + * + * If this is set, libxl_domain_need_memory takes a + * libxl_domain_config* (non-const) and uint32_t domid_for_logging + * (instead of a const libxl_domain_build_info*). + * + * If this is set, there is no need to call + * libxl_get_required_shadow_memory and instead the caller should + * simply leave shadow_memkb set to LIBXL_MEMKB_DEFAULT and allow + * libxl to fill in a suitable default in the usual way. + */ +#define LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONFIG + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); @@ -1723,8 +1737,13 @@ int libxl_get_memory_target_0x040700(libxl_ctx *ctx, uint32_t domid, */ /* how much free memory in the system a domain needs to be built */ int libxl_domain_need_memory(libxl_ctx *ctx, - const libxl_domain_build_info *b_info_in, + libxl_domain_config *config + /* ^ will be partially defaulted */, + uint32_t domid_for_logging /* INVALID_DOMID ok */, uint64_t *need_memkb); +int libxl_domain_need_memory_0x041200(libxl_ctx *ctx, + const libxl_domain_build_info *b_info_in, + uint64_t *need_memkb); int libxl_domain_need_memory_0x040700(libxl_ctx *ctx, const libxl_domain_build_info *b_info_in, uint32_t *need_memkb) @@ -1754,6 +1773,8 @@ int libxl_wait_for_memory_target(libxl_ctx *ctx, uint32_t domid, int wait_secs); #define libxl_get_memory_target libxl_get_memory_target_0x040700 #define libxl_domain_need_memory libxl_domain_need_memory_0x040700 #define libxl_get_free_memory libxl_get_free_memory_0x040700 +#elif defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x041300 +#define libxl_domain_need_memory libxl_domain_need_memory_0x041200 #endif int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass); diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index c5685b061c..cdb294ab8d 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -140,8 +140,9 @@ static int numa_cmpf(const libxl__numa_candidate *c1, /* The actual automatic NUMA placement routine */ static int numa_place_domain(libxl__gc *gc, uint32_t domid, - libxl_domain_build_info *info) + libxl_domain_config *d_config) { + libxl_domain_build_info *info = &d_config->b_info; int found; libxl__numa_candidate candidate; libxl_bitmap cpumap, cpupool_nodemap, *map; @@ -195,7 +196,7 @@ static int numa_place_domain(libxl__gc *gc, uint32_t domid, } } - rc = libxl_domain_need_memory(CTX, info, &memkb); + rc = libxl__domain_need_memory_calculate(gc, info, &memkb); if (rc) goto out; if (libxl_node_bitmap_alloc(CTX, &cpupool_nodemap, 0)) { @@ -432,7 +433,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, if (rc) return rc; - rc = numa_place_domain(gc, domid, info); + rc = numa_place_domain(gc, domid, d_config); if (rc) { libxl_bitmap_dispose(&cpumap_soft); return rc; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 50ac7b64ed..01de5576d9 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1450,6 +1450,10 @@ _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc, _hidden void libxl__rdm_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info); +_hidden int libxl__domain_need_memory_calculate(libxl__gc *gc, + libxl_domain_build_info *b_info, + uint64_t *need_memkb); + _hidden const char *libxl__device_nic_devname(libxl__gc *gc, uint32_t domid, uint32_t devid, diff --git a/tools/libxl/libxl_mem.c b/tools/libxl/libxl_mem.c index fd6f33312e..6042299393 100644 --- a/tools/libxl/libxl_mem.c +++ b/tools/libxl/libxl_mem.c @@ -446,20 +446,12 @@ int libxl_get_memory_target_0x040700( return libxl__memkb_64to32(ctx, rc, my_out_target, out_target); } -int libxl_domain_need_memory(libxl_ctx *ctx, - const libxl_domain_build_info *b_info_in, - uint64_t *need_memkb) +int libxl__domain_need_memory_calculate(libxl__gc *gc, + libxl_domain_build_info *b_info, + uint64_t *need_memkb) { - GC_INIT(ctx); - libxl_domain_build_info b_info[1]; int rc; - libxl_domain_build_info_init(b_info); - libxl_domain_build_info_copy(ctx, b_info, b_info_in); - - rc = libxl__domain_build_info_setdefault(gc, b_info); - if (rc) goto out; - *need_memkb = b_info->target_memkb; *need_memkb += b_info->shadow_memkb + b_info->iommu_memkb; @@ -481,10 +473,57 @@ int libxl_domain_need_memory(libxl_ctx *ctx, *need_memkb += (2 * 1024) - (*need_memkb % (2 * 1024)); rc = 0; out: + return rc; +} + +int libxl_domain_need_memory(libxl_ctx *ctx, + libxl_domain_config *d_config, + uint32_t domid_for_logging, + uint64_t *need_memkb) +{ + GC_INIT(ctx); + int rc; + + rc = libxl__domain_config_setdefault(gc, + d_config, + domid_for_logging); + if (rc) goto out; + + rc = libxl__domain_need_memory_calculate(gc, + &d_config->b_info, + need_memkb); + if (rc) goto out; + + rc = 0; + out: GC_FREE; - libxl_domain_build_info_dispose(b_info); return rc; +} + +int libxl_domain_need_memory_0x041200(libxl_ctx *ctx, + const libxl_domain_build_info *b_info_in, + uint64_t *need_memkb) +{ + GC_INIT(ctx); + int rc; + + libxl_domain_build_info b_info[1]; + libxl_domain_build_info_init(b_info); + libxl_domain_build_info_copy(ctx, b_info, b_info_in); + + rc = libxl__domain_build_info_setdefault(gc, b_info); + if (rc) goto out; + rc = libxl__domain_need_memory_calculate(gc, + b_info, + need_memkb); + if (rc) goto out; + + rc = 0; + out: + libxl_domain_build_info_dispose(b_info); + GC_FREE; + return rc; } int libxl_domain_need_memory_0x040700(libxl_ctx *ctx, @@ -494,7 +533,7 @@ int libxl_domain_need_memory_0x040700(libxl_ctx *ctx, uint64_t my_need_memkb; int rc; - rc = libxl_domain_need_memory(ctx, b_info_in, &my_need_memkb); + rc = libxl_domain_need_memory_0x041200(ctx, b_info_in, &my_need_memkb); return libxl__memkb_64to32(ctx, rc, my_need_memkb, need_memkb); } diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index d33c6b38c9..e520b1da79 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -322,7 +322,7 @@ static bool freemem(uint32_t domid, libxl_domain_config *d_config) if (!autoballoon) return true; - rc = libxl_domain_need_memory(ctx, &d_config->b_info, &need_memkb); + rc = libxl_domain_need_memory(ctx, d_config, domid, &need_memkb); if (rc < 0) return false;