From patchwork Fri Sep 2 02:55:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 75268 Delivered-To: patch@linaro.org Received: by 10.140.29.8 with SMTP id a8csp623783qga; Thu, 1 Sep 2016 19:58:53 -0700 (PDT) X-Received: by 10.202.244.133 with SMTP id s127mr17451095oih.15.1472785131830; Thu, 01 Sep 2016 19:58:51 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p16si10123188ota.180.2016.09.01.19.58.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Sep 2016 19:58:51 -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; 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 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfef0-0006y7-Dc; Fri, 02 Sep 2016 02:56:54 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfeez-0006x7-6c for xen-devel@lists.xen.org; Fri, 02 Sep 2016 02:56:53 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id C2/13-03281-47AE8C75; Fri, 02 Sep 2016 02:56:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJIsWRWlGSWpSXmKPExsVi9XuGg27xqxP hBseum1ks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnbtp5kKripUbFx2Uf2Bsaz8l2MXBxCAqcY JVa2bmSEcHYzSsxqncfWxcjJwSagK/Fx4xR2EFtEQFZiddccdpAiZoHrjBJ33m9jBUkIC3hJf Lq5G6yBRUBF4u3id4wgNq+Ap8THa09ZQGwJAQ2Jlb0TwGxOoPjbVZ/AhgoJeEg8fvWICaJeUO LkzCdgNcwCEhIHX7xghuhVlGhbf5INwpaUOLjiBgvIERIgZ098vZcdImEq8eV/F8sERsFZSGb NQjJrASPTKkaN4tSistQiXUNjvaSizPSMktzEzBxdQwNjvdzU4uLE9NScxKRiveT83E2MwCBl AIIdjNu2ex5ilORgUhLlzX9yIlyILyk/pTIjsTgjvqg0J7X4EKMMB4eSBK/RS6CcYFFqempFW mYOMF5g0hIcPEoivCtA0rzFBYm5xZnpEKlTjIpS4rw5IAkBkERGaR5cGyxGLzHKSgnzMgIdIs RTkFqUm1mCKv+KUZyDUUmYNwBkCk9mXgnc9FdAi5mAFpdcOw6yuCQRISXVwJjI/jh680/eu1u izF8cfHTh1sJk5UPcMZ8m/JzMXb7i/YldT5fbKbJ/2mikqfc12dyqrsXDZN7OC7pKjZIb/3Gc OL3q3J8U5rsORXMfHjJzX/lLouxqLJfyCtv7ETsjFp3bmfywz+/McakdCZkvGLyd7F1Njny+t 2Zy4MNDnftXn7Sf77au/ct0JZbijERDLeai4kQAQ0jmkswCAAA= X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1472785007!57963628!1 X-Originating-IP: [58.251.152.64] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 19881 invoked from network); 2 Sep 2016 02:56:51 -0000 Received: from szxga01-in.huawei.com (HELO szxga01-in.huawei.com) (58.251.152.64) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 2 Sep 2016 02:56:51 -0000 Received: from 172.24.1.60 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.60]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DQM36336; Fri, 02 Sep 2016 10:56:23 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Fri, 2 Sep 2016 10:56:12 +0800 From: Shannon Zhao To: Date: Fri, 2 Sep 2016 10:55:39 +0800 Message-ID: <1472784939-14404-17-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1472784939-14404-1-git-send-email-zhaoshenglong@huawei.com> References: <1472784939-14404-1-git-send-email-zhaoshenglong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0208.57C8EA59.0044, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: ad722f934561da7ec1edd4c2e16707bf Cc: sstabellini@kernel.org, wei.liu2@citrix.com, ian.jackson@eu.citrix.com, peter.huangpeng@huawei.com, julien.grall@arm.com, shannon.zhao@linaro.org, boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH v5 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" From: Shannon Zhao 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_arch.h | 2 +- tools/libxl/libxl_arm.c | 18 +++++++++++++++++- tools/libxl/libxl_arm.h | 4 ++++ tools/libxl/libxl_arm_acpi.c | 20 ++++++++++++++++++++ tools/libxl/libxl_arm_no_acpi.c | 6 ++++++ tools/libxl/libxl_dom.c | 2 +- tools/libxl/libxl_x86.c | 2 +- 7 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h index 337061f..d62fa4c 100644 --- a/tools/libxl/libxl_arch.h +++ b/tools/libxl/libxl_arch.h @@ -30,7 +30,7 @@ int libxl__arch_domain_save_config(libxl__gc *gc, /* arch specific internal domain creation function */ _hidden int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, - uint32_t domid); + libxl__domain_build_state *state, uint32_t domid); /* setup arch specific hardware description, i.e. DTB on ARM */ _hidden diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index e73d65e..c7d4f65 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -101,8 +101,24 @@ int libxl__arch_domain_save_config(libxl__gc *gc, } int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, - uint32_t domid) + libxl__domain_build_state *state, uint32_t domid) { + libxl_domain_build_info *const info = &d_config->b_info; + libxl_ctx *ctx = libxl__gc_owner(gc); + int size; + + /* Add the size of ACPI tables to maxmem if ACPI is enabled for guest. */ + if (libxl_defbool_val(info->acpi)) { + size = libxl__get_acpi_size(gc, info, state); + if (size < 0) + return ERROR_FAIL; + if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + + LIBXL_MAXMEM_CONSTANT + (size + 1023) / 1024)) { + LOGE(ERROR, "Couldn't set max memory"); + return ERROR_FAIL; + } + } + return 0; } diff --git a/tools/libxl/libxl_arm.h b/tools/libxl/libxl_arm.h index a91ff93..37b1f15 100644 --- a/tools/libxl/libxl_arm.h +++ b/tools/libxl/libxl_arm.h @@ -24,6 +24,10 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, libxl__domain_build_state *state, struct xc_dom_image *dom); +_hidden +int libxl__get_acpi_size(libxl__gc *gc, libxl_domain_build_info *info, + libxl__domain_build_state *state); + 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 30e4d66..9854c7a 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -94,6 +94,26 @@ static int libxl__estimate_madt_size(libxl__gc *gc, return rc; } +int libxl__get_acpi_size(libxl__gc *gc, libxl_domain_build_info *info, + libxl__domain_build_state *state) +{ + int size; + + size = libxl__estimate_madt_size(gc, info, &state->config); + if (size < 0) + goto out; + + size = 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 size; +} + static int libxl__estimate_acpi_size(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 e7f7411..5eeb825 100644 --- a/tools/libxl/libxl_arm_no_acpi.c +++ b/tools/libxl/libxl_arm_no_acpi.c @@ -25,6 +25,12 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, return ERROR_FAIL; } +int libxl__get_acpi_size(libxl__gc *gc, libxl_domain_build_info *info, + libxl__domain_build_state *state) +{ + return ERROR_FAIL; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 7dbf614..a2cd350 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -437,7 +437,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, #endif } - rc = libxl__arch_domain_create(gc, d_config, domid); + rc = libxl__arch_domain_create(gc, d_config, state, domid); return rc; } diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index e9127bb..c872089 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -285,7 +285,7 @@ static int libxl__e820_alloc(libxl__gc *gc, uint32_t domid, } int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, - uint32_t domid) + libxl__domain_build_state *state, uint32_t domid) { int ret = 0; int tsc_mode;