From patchwork Thu Jan 19 17:50:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Fehlig X-Patchwork-Id: 9526569 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0EB1E60113 for ; Thu, 19 Jan 2017 17:52:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F25BB284D5 for ; Thu, 19 Jan 2017 17:52:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E66762853E; Thu, 19 Jan 2017 17:52:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6953E284D5 for ; Thu, 19 Jan 2017 17:52:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUGqp-0000hJ-Bg; Thu, 19 Jan 2017 17:50:19 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUGqo-0000hB-6I for xen-devel@lists.xen.org; Thu, 19 Jan 2017 17:50:18 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 31/33-27429-95CF0885; Thu, 19 Jan 2017 17:50:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRWlGSWpSXmKPExsXS6fgrUDf8T0O EQcc9M4slHxezODB6HN39mymAMYo1My8pvyKBNWPt0b/MBS8FKvY0HWRtYLzM28XIxSEksJ1R Ys612YxdjJwcbALKEi87b7GC2CICUhKL7i1gBrGZBawlvrWuBIsLC9hIbD/WDBZnEVCVmPr0A 5jNK2AqcXLqOhYQW0JATuLl65/MExg5FjAyrGLUKE4tKkst0jW01EsqykzPKMlNzMzRNTQw1c tNLS5OTE/NSUwq1kvOz93ECPRLPQMD4w7GR/1+hxglOZiURHl3f2yIEOJLyk+pzEgszogvKs1 JLT7EqMHBIbB57eoLjFIsefl5qUoSvBm/geoEi1LTUyvSMnOAgQNTKsHBoyTC6wKS5i0uSMwt zkyHSJ1i1OX4svPMSyYhsBlS4rxWIEUCIEUZpXlwI2BBfIlRVkqYl5GBgUGIpyC1KDezBFX+F aM4B6OSMG/yL6ApPJl5JXCbXgEdwQR0hJVyPcgRJYkIKakGRpUDTj62MiH+B27wvuqye+yidv TEj5WKR32UV0mGT29fnLVmpqTr92TNa786Lmdu4/w71+qqiPDKXSXM8jM/6jxvkdFaXbL5RPM Pp69O/u9Vkhes/bXlI5sMo631FJ+3brMf6WiFHJWrflThfzGx/hWj0ulHJlILRBbxR/U0ct/6 3hj3MkTgpRJLcUaioRZzUXEiAFEwDBddAgAA X-Env-Sender: jfehlig@suse.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1484848213!80930466!1 X-Originating-IP: [137.65.250.81] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23292 invoked from network); 19 Jan 2017 17:50:15 -0000 Received: from smtp2.provo.novell.com (HELO smtp2.provo.novell.com) (137.65.250.81) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Jan 2017 17:50:15 -0000 Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Thu, 19 Jan 2017 10:50:12 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Thu, 19 Jan 2017 10:50:05 -0700 Message-Id: <20170119175005.10220-1-jfehlig@suse.com> X-Mailer: git-send-email 2.9.2 Cc: Jim Fehlig , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH] libxl: fix dom0 autoballooning with Xen 4.8 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" X-Virus-Scanned: ClamAV using ClamSMTP xen.git commit 57f8b13c changed several of the libxl memory get/set functions to take 64 bit parameters. The libvirt libxl driver still uses uint32_t variables for these various parameters, which is particularly problematic for the libxl_set_memory_target() function. When dom0 autoballooning is enabled, libvirt (like xl) determines the memory needed to start a domain and the memory available. If memory available is less than memory needed, dom0 is ballooned down by passing a negative value to libxl_set_memory_target() 'target_memkb' parameter. Prior to xen.git commit 57f8b13c, 'target_memkb' was an int32_t. Subtracting a larger uint32 from a smaller uint32 and assigning it to int32 resulted in a negative number. After commit 57f8b13c, the same subtraction is widened to a int64, resulting in a large positive number. The simple fix taken by this patch is to assign the difference of the uint32 values to a temporary int32 variable, which is then passed to 'target_memkb' parameter of libxl_set_memory_target(). Note that it is undesirable to change libvirt to use 64 bit variables since it requires setting LIBXL_API_VERSION to 0x040800. Currently libvirt supports LIBXL_API_VERSION >= 0x040400, essentially Xen >= 4.4. Signed-off-by: Jim Fehlig --- src/libxl/libxl_domain.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index a5314b0..ed73cd2 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -909,6 +909,7 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) { uint32_t needed_mem; uint32_t free_mem; + int32_t target_mem; int tries = 3; int wait_secs = 10; @@ -922,7 +923,8 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) if (free_mem >= needed_mem) return 0; - if (libxl_set_memory_target(ctx, 0, free_mem - needed_mem, + target_mem = free_mem - needed_mem; + if (libxl_set_memory_target(ctx, 0, target_mem, /* relative */ 1, 0) < 0) goto error;