From patchwork Thu Sep 22 12:52:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 76786 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp15303qgf; Thu, 22 Sep 2016 05:56:43 -0700 (PDT) X-Received: by 10.107.140.12 with SMTP id o12mr2569387iod.206.1474549003933; Thu, 22 Sep 2016 05:56:43 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 191si2822075itb.106.2016.09.22.05.56.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Sep 2016 05:56:43 -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 1bn3Wf-0004s4-Af; Thu, 22 Sep 2016 12:54:53 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bn3We-0004rO-4H for xen-devel@lists.xen.org; Thu, 22 Sep 2016 12:54:52 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 6D/D1-15996-B94D3E75; Thu, 22 Sep 2016 12:54:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVi9XuGg+6sK4/ DDa5+0bVY8nExiwOjx9Hdv5kCGKNYM/OS8isSWDPa+8+wF1zQrVj7ezlzA+ME5S5GLg4hgVOM Esu3vmaCcPYwSny7toqti5GTg01AS+L89B/sILaIgKzE6q457CBFzALXGSXuvN/G2sXIwSEs4 CWxYKUySA2LgKpE876VTCA2r4CnxK8NK1lBbAkBDYmVvRNYQGxOoPiEI+vB4kICHhIrryxkha gXlDg58wlYDbOAhMTBFy+YIXoVJdrWn2SDsCUlDq64wQJhA13d/bAawjaVONH9iX0Co+AsJKN mIRm1gJFpFaNGcWpRWWqRrpGRXlJRZnpGSW5iZo6uoYGpXm5qcXFiempOYlKxXnJ+7iZGYIDW MzAw7mDc0+53iFGSg0lJlPdC/+NwIb6k/JTKjMTijPii0pzU4kOMMhwcShK8CZeBcoJFqempF WmZOcBYgUlLcPAoifAWg6R5iwsSc4sz0yFSpxgVpcR5f18CSgiAJDJK8+DaYPF5iVFWSpiXkY GBQYinILUoN7MEVf4VozgHo5IwrxjIeJ7MvBK46a+AFjMBLd7y8wHI4pJEhJRUA+PCMPewWwk OldWlZ3tyFysEF6x6Y3mw+RILg/P98J2aZ9cYyJ30TjUR0bAp/GJ6ubid5+p8wa2RuoqXeyar G3VOay/e4vBb7ot6bizLA4FzgioPGFQsf048v7glf3/AyhMa8d06QvvmplZqXZl25uaL+ZG/D Lb4KgrssrPzSflpPflayYb985VYijMSDbWYi4oTAYH2OgnKAgAA X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1474548884!45033176!1 X-Originating-IP: [58.251.152.64] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48453 invoked from network); 22 Sep 2016 12:54:49 -0000 Received: from szxga01-in.huawei.com (HELO szxga01-in.huawei.com) (58.251.152.64) by server-16.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 22 Sep 2016 12:54:49 -0000 Received: from 172.24.1.36 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.36]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DRK49282; Thu, 22 Sep 2016 20:53:11 +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; Thu, 22 Sep 2016 20:53:02 +0800 From: z00226004 To: Date: Thu, 22 Sep 2016 20:52:33 +0800 Message-ID: <1474548753-12596-17-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1474548753-12596-1-git-send-email-zhaoshenglong@huawei.com> References: <1474548753-12596-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.0A020205.57E3D439.011A, 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: c7cddda86f9f7d64d07801e5f9c1f8e8 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 v6 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 | 4 ++++ tools/libxl/libxl_arm.c | 16 ++++++++++++++++ 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 | 9 ++++++++- tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_x86.c | 6 ++++++ 8 files changed, 66 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h index 8cb9ba7..a066bbd 100644 --- a/tools/libxl/libxl_arch.h +++ b/tools/libxl/libxl_arch.h @@ -66,6 +66,10 @@ _hidden void libxl__arch_domain_build_info_acpi_setdefault( libxl_domain_build_info *b_info); +_hidden +int libxl__arch_memory_constant(libxl__gc *gc, libxl_domain_build_info *info, + libxl__domain_build_state *state); + #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 913f401..932e674 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -106,6 +106,22 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config, return 0; } +int libxl__arch_memory_constant(libxl__gc *gc, libxl_domain_build_info *info, + libxl__domain_build_state *state) +{ + int size; + + if (libxl_defbool_val(info->acpi)) { + size = libxl__get_acpi_size(gc, info, state); + if (size < 0) + return ERROR_FAIL; + + return DIV_ROUNDUP(size, 1024); + } + + return 0; +} + 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 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 9c4005f..0d4092d 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 2924629..118beab 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -408,8 +408,15 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, } } + + rc = libxl__arch_memory_constant(gc, info, state); + if (rc < 0) { + LOGE(ERROR, "Couldn't get arch constant memory size"); + return ERROR_FAIL; + } + if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + - LIBXL_MAXMEM_CONSTANT) < 0) { + LIBXL_MAXMEM_CONSTANT + rc) < 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 f69f3c2..0a86040 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -358,6 +358,12 @@ out: return ret; } +int libxl__arch_memory_constant(libxl__gc *gc, libxl_domain_build_info *info, + libxl__domain_build_state *state) +{ + return 0; +} + int libxl__arch_domain_init_hw_description(libxl__gc *gc, libxl_domain_build_info *info, libxl__domain_build_state *state,