From patchwork Thu Sep 29 01:19:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 77106 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp79887qgf; Wed, 28 Sep 2016 18:22:15 -0700 (PDT) X-Received: by 10.36.40.144 with SMTP id h138mr5620014ith.31.1475112134949; Wed, 28 Sep 2016 18:22:14 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p5si13162666itd.98.2016.09.28.18.22.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Sep 2016 18:22:14 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpQ11-0001lG-EH; Thu, 29 Sep 2016 01:19:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpQ0z-0001df-KI for xen-devel@lists.xen.org; Thu, 29 Sep 2016 01:19:57 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 23/35-28857-D3C6CE75; Thu, 29 Sep 2016 01:19:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsVyMfTAFl2bnDf hBpuaDSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ozVh6+wFDQGVsz/4t/A2GXTxcjFISQwiVHi x7k2RhCHRWAes8SCn1OYQBwJgX5Wiaady5i7GDmBnBiJfydPQdmVEns3zWACsYUE1CSWHV7ID DGqiUmi8clfNpAEm4COxItJO8FsEQFpiWufL4OtYBY4wihxa/5JoA4ODmEBL4n2xkyQGhYBVY mZ3+8zgti8AjYSv3rPQi3TlJg+6zWYzQkU/9DyixlisbXEsm+bWSYwCixgZFjFqF6cWlSWWqR rrJdUlJmeUZKbmJmja2hgppebWlycmJ6ak5hUrJecn7uJERhYDECwg7Hjn9MhRkkOJiVRXk6f N+FCfEn5KZUZicUZ8UWlOanFhxhlODiUJHivZAHlBItS01Mr0jJzgCEOk5bg4FES4X0FkuYtL kjMLc5Mh0idYjTm2PL72lomjm1T761lEmLJy89LlRLnvQpSKgBSmlGaBzcIFnuXGGWlhHkZgU 4T4ilILcrNLEGVf8UozsGoJMz7GmQKT2ZeCdy+V0CnMAGdsvTEC5BTShIRUlINjIdWJE37Grd vLXPhY4nwDTX/L9hZyZ1/FLl9o7/Sw+bAKxucHwUwVH/atNRli3BB90rt6YzWp5Jq5tWsKLp+ Q+PTjRiB1xulL23LmlT59KuaxfeNTn5XlLak7Dief8ev6YLw/r0h3KlORpwb0m4450yMLxLQK Hwu/f+EhlmPbsXllunS0cv31SqxFGckGmoxFxUnAgDWpolAuAIAAA== X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-7.tower-27.messagelabs.com!1475111995!57477610!1 X-Originating-IP: [209.85.192.180] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56798 invoked from network); 29 Sep 2016 01:19:56 -0000 Received: from mail-pf0-f180.google.com (HELO mail-pf0-f180.google.com) (209.85.192.180) by server-7.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 29 Sep 2016 01:19:56 -0000 Received: by mail-pf0-f180.google.com with SMTP id s13so22877762pfd.2 for ; Wed, 28 Sep 2016 18:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NvY4kPVoIV+1r5w0SOTRnumoguxtYo0kLWdYk8/fINE=; b=CMsdTM7WShQq1dAlrE9PZGXwQkdOJVtuDysKbCEH5lrgZskBhThF6aWmiGUTpPW8D5 HzbDHc3C02DD4JUk7IrDw4xxl1jz0BvsCXqGRJyonOLqMcIFn28/16LAx64s9RjVDOI9 JU4lwQqJiaNbeM30fwjuMzbzPNZk5R7GKC7Vg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NvY4kPVoIV+1r5w0SOTRnumoguxtYo0kLWdYk8/fINE=; b=QmH6TQnkH2RG2xjtFVfQs9deNio6Kj6/HyJAYVfJ/EzuCjakrahSFeuZOi0zgX9p3u O0x48ho/S0jamftgIfsxLTxy25ivibowmC7kDHqRTUEbBN1Imji2p93tvoMV1mG1dTsn Pwg7XPqZh39czlJg7M2tDvxI0wCE6TewuuBO9pBdMzr7x4VntbxcryDln4xkbSZqryZN WnxQn7Ud47KjSQXocFjlzJjOqns2/8LBrU6RLuwE9R36Ep6U+B1Y5HokggmVMmc+Llqy qbjSnN5qISEKVazOhyCnshjg9hPoQ5KKZzY0s7QWeFOQAREtnctL8G5h8tmyGVTUeXpp +0uA== X-Gm-Message-State: AE9vXwP7dOZUC8tSLh2pDcKoZ8QokymIUYyO7EWNiEszXm812cfGYocDWFaC4T/WPkSXUGI5 X-Received: by 10.98.70.80 with SMTP id t77mr61643141pfa.110.1475111995080; Wed, 28 Sep 2016 18:19:55 -0700 (PDT) Received: from HZA160860128-A.china.huawei.com ([67.238.99.186]) by smtp.gmail.com with ESMTPSA id wd7sm15228744pab.2.2016.09.28.18.19.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Sep 2016 18:19:54 -0700 (PDT) From: Shannon Zhao To: xen-devel@lists.xen.org Date: Wed, 28 Sep 2016 18:19:02 -0700 Message-Id: <20160929011902.7784-17-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.10.0.windows.1 In-Reply-To: <20160929011902.7784-1-shannon.zhao@linaro.org> References: <20160929011902.7784-1-shannon.zhao@linaro.org> Cc: sstabellini@kernel.org, wei.liu2@citrix.com, ian.jackson@eu.citrix.com, julien.grall@arm.com, Shannon Zhao , zhaoshenglong@huawei.com, boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH v8 16/16] libxl/arm: Add the size of ACPI tables to maxmem X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" Here it adds the ACPI tables size to set the target maxmem to avoid providing less available memory for guest. Signed-off-by: Shannon Zhao --- tools/libxl/libxl.c | 45 ++++++++++++++++++++++++++++++++--------- tools/libxl/libxl_arch.h | 5 +++++ tools/libxl/libxl_arm.c | 20 ++++++++++++++++++ tools/libxl/libxl_arm.h | 5 +++++ tools/libxl/libxl_arm_acpi.c | 23 +++++++++++++++++++++ tools/libxl/libxl_arm_no_acpi.c | 7 +++++++ tools/libxl/libxl_dom.c | 11 ++++++++-- tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_x86.c | 9 +++++++++ 9 files changed, 116 insertions(+), 11 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 997d94c..a46b827 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -17,6 +17,7 @@ #include "libxl_osdeps.h" #include "libxl_internal.h" +#include "libxl_arch.h" #define PAGE_TO_MEMKB(pages) ((pages) * 4) #define BACKEND_STRING_SIZE 5 @@ -4022,10 +4023,11 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint64_t max_memkb) { GC_INIT(ctx); char *mem, *endptr; - uint64_t memorykb; + uint64_t memorykb, size; char *dompath = libxl__xs_get_dompath(gc, domid); int rc = 1; libxl__domain_userdata_lock *lock = NULL; + libxl_domain_config d_config; CTX_LOCK; @@ -4051,11 +4053,24 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint64_t max_memkb) "memory_static_max must be greater than or or equal to memory_dynamic_max"); goto out; } - rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb + LIBXL_MAXMEM_CONSTANT); + + rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config); + if (rc < 0) { + LOGE(ERROR, "unable to retrieve domain configuration"); + goto out; + } + + rc = libxl__arch_extra_memory(gc, &d_config.b_info, &size); + if (rc < 0) { + LOGE(ERROR, "Couldn't get arch extra constant memory size"); + goto out; + } + + rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb + size); if (rc != 0) { LOGE(ERROR, "xc_domain_setmaxmem domid=%d memkb=%"PRIu64" failed ""rc=%d\n", - domid, max_memkb + LIBXL_MAXMEM_CONSTANT, rc); + domid, max_memkb + size, rc); goto out; } @@ -4149,7 +4164,7 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, { GC_INIT(ctx); int rc, r, lrc, abort_transaction = 0; - uint64_t memorykb; + uint64_t memorykb, size; uint64_t videoram = 0; uint64_t current_target_memkb = 0, new_target_memkb = 0; uint64_t current_max_memkb = 0; @@ -4160,6 +4175,7 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, char *uuid; xs_transaction_t t; libxl__domain_userdata_lock *lock; + libxl_domain_config d_config; CTX_LOCK; @@ -4169,6 +4185,18 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, goto out_no_transaction; } + rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config); + if (rc < 0) { + LOGE(ERROR, "unable to retrieve domain configuration"); + goto out_no_transaction; + } + + rc = libxl__arch_extra_memory(gc, &d_config.b_info, &size); + if (rc < 0) { + LOGE(ERROR, "Couldn't get arch extra constant memory size"); + goto out_no_transaction; + } + retry_transaction: t = xs_transaction_start(ctx->xsh); @@ -4246,13 +4274,12 @@ retry_transaction: if (enforce) { memorykb = new_target_memkb + videoram; - r = xc_domain_setmaxmem(ctx->xch, domid, memorykb + - LIBXL_MAXMEM_CONSTANT); + r = xc_domain_setmaxmem(ctx->xch, domid, memorykb + size); if (r != 0) { LOGE(ERROR, "xc_domain_setmaxmem domid=%u memkb=%"PRIu64" failed ""rc=%d\n", domid, - memorykb + LIBXL_MAXMEM_CONSTANT, + memorykb + size, r); abort_transaction = 1; rc = ERROR_FAIL; @@ -4261,12 +4288,12 @@ retry_transaction: } r = xc_domain_set_pod_target(ctx->xch, domid, - (new_target_memkb + LIBXL_MAXMEM_CONSTANT) / 4, NULL, NULL, NULL); + (new_target_memkb + size) / 4, NULL, NULL, NULL); if (r != 0) { LOGE(ERROR, "xc_domain_set_pod_target domid=%d, memkb=%"PRIu64" failed rc=%d\n", domid, - new_target_memkb / 4, + (new_target_memkb + size) / 4, r); abort_transaction = 1; rc = ERROR_FAIL; diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h index fff0554..5e1fc60 100644 --- a/tools/libxl/libxl_arch.h +++ b/tools/libxl/libxl_arch.h @@ -66,6 +66,11 @@ _hidden void libxl__arch_domain_build_info_acpi_setdefault( libxl_domain_build_info *b_info); +_hidden +int libxl__arch_extra_memory(libxl__gc *gc, + const libxl_domain_build_info *info, + uint64_t *out); + #if defined(__i386__) || defined(__x86_64__) #define LAPIC_BASE_ADDRESS 0xfee00000 diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index 5f5ff03..d842d88 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -106,6 +106,26 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, return 0; } +int libxl__arch_extra_memory(libxl__gc *gc, + const libxl_domain_build_info *info, + uint64_t *out) +{ + int rc = 0; + uint64_t size = 0; + + if (libxl_defbool_val(info->acpi)) { + rc = libxl__get_acpi_size(gc, info, &size); + if (rc < 0) { + rc = ERROR_FAIL; + goto out; + } + } + + *out = LIBXL_MAXMEM_CONSTANT + DIV_ROUNDUP(size, 1024); +out: + return rc; +} + static struct arch_info { const char *guest_type; const char *timer_compat; diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h index 7097def..8aef210 100644 --- a/tools/libxl/libxl_arm.h +++ b/tools/libxl/libxl_arm.h @@ -23,6 +23,11 @@ _hidden int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, struct xc_dom_image *dom); +_hidden +int libxl__get_acpi_size(libxl__gc *gc, + const libxl_domain_build_info *info, + uint64_t *out); + static inline uint64_t libxl__compute_mpdir(unsigned int cpuid) { /* diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index 6c713ac..db113db 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -94,6 +94,29 @@ static int libxl__estimate_madt_size(libxl__gc *gc, return rc; } +int libxl__get_acpi_size(libxl__gc *gc, + const libxl_domain_build_info *info, + uint64_t *out) +{ + uint64_t size; + int rc = 0; + + + rc = libxl__estimate_madt_size(gc, info, &size); + if (rc < 0) + goto out; + + *out = ROUNDUP(size, 3) + + ROUNDUP(sizeof(struct acpi_table_rsdp), 3) + + ROUNDUP(sizeof(struct acpi_table_xsdt), 3) + + ROUNDUP(sizeof(struct acpi_table_gtdt), 3) + + ROUNDUP(sizeof(struct acpi_table_fadt), 3) + + ROUNDUP(sizeof(dsdt_anycpu_arm_len), 3); + +out: + return rc; +} + static int libxl__allocate_acpi_tables(libxl__gc *gc, libxl_domain_build_info *info, struct xc_dom_image *dom, diff --git a/tools/libxl/libxl_arm_no_acpi.c b/tools/libxl/libxl_arm_no_acpi.c index 88ebbb6..5dde0cd 100644 --- a/tools/libxl/libxl_arm_no_acpi.c +++ b/tools/libxl/libxl_arm_no_acpi.c @@ -24,6 +24,13 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, return ERROR_FAIL; } +int libxl__get_acpi_size(libxl__gc *gc, + const libxl_domain_build_info *info, + uint64_t *out) +{ + return ERROR_FAIL; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 2924629..d519c8d 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -302,6 +302,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, libxl_ctx *ctx = libxl__gc_owner(gc); char *xs_domid, *con_domid; int rc; + uint64_t size; if (xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus) != 0) { LOG(ERROR, "Couldn't set max vcpu count"); @@ -408,8 +409,14 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, } } - if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + - LIBXL_MAXMEM_CONSTANT) < 0) { + + rc = libxl__arch_extra_memory(gc, info, &size); + if (rc < 0) { + LOGE(ERROR, "Couldn't get arch extra constant memory size"); + return ERROR_FAIL; + } + + if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + size) < 0) { LOGE(ERROR, "Couldn't set max memory"); return ERROR_FAIL; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index cb6d9e0..8366fee 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -128,6 +128,8 @@ #define ROUNDUP(_val, _order) \ (((unsigned long)(_val)+(1UL<<(_order))-1) & ~((1UL<<(_order))-1)) +#define DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d)) + #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m))) #define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m)) diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index 84493df..e1844c8 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -359,6 +359,15 @@ out: return ret; } +int libxl__arch_extra_memory(libxl__gc *gc, + const libxl_domain_build_info *info, + uint64_t *out) +{ + *out = LIBXL_MAXMEM_CONSTANT; + + return 0; +} + int libxl__arch_domain_init_hw_description(libxl__gc *gc, libxl_domain_build_info *info, libxl__domain_build_state *state,