From patchwork Mon Jul 3 15:40:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 9823649 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 B889860246 for ; Mon, 3 Jul 2017 15:43:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F465285BF for ; Mon, 3 Jul 2017 15:43:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 920AE285EB; Mon, 3 Jul 2017 15:43:21 +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 09C02285BF for ; Mon, 3 Jul 2017 15:43:20 +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 1dS3T5-0006ji-BV; Mon, 03 Jul 2017 15:40:55 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dS3T3-0006jc-6X for xen-devel@lists.xenproject.org; Mon, 03 Jul 2017 15:40:53 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 04/76-01987-4856A595; Mon, 03 Jul 2017 15:40:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrLLMWRWlGSWpSXmKPExsVyuP0Ov25zalS kwa+tRhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0bv9H/sBSclK/r3hjQwPhDtYuTkkBAwkng7 8R9TFyMXh5DAQkaJB9cPsoIk2ARUJTZcPwVmiwg4SqxuWwpmMws4SMyadZS5i5GDQ1jAXmJFS xxImAWo/MiHS+wgNq+AicT9hStZIebLS3QcmMwygZFzASPDKkb14tSistQiXTO9pKLM9IyS3M TMHF1DA2O93NTi4sT01JzEpGK95PzcTYxAT9UzMDDuYLzS5nyIUZKDSUmU1/VmZKQQX1J+SmV GYnFGfFFpTmrxIUYZDg4lCd4lKVGRQoJFqempFWmZOcCQgUlLcPAoifBuMQRK8xYXJOYWZ6ZD pE4xGnNsWL3+CxPHqwn/vzEJseTl56VKifPWgEwSACnNKM2DGwQL5UuMslLCvIwMDAxCPAWpR bmZJajyrxjFORiVhHn1koGm8GTmlcDtewV0ChPQKQ09ESCnlCQipKQaGKtnTlGt/Ch6QcXB+n 73n+jSkM/HMwtKlFdmfCvYU/Ut+Ft10afLnl+eiXKvuNv9VlTOir9f+Ov5s89ZlMLyZOrZDFn c5uYv318+h+/zqfZPUXZptlNFZYx9DUsDPszYunXCqXTGJdou699rZjY6ltc33De/tzyjRZzr VeXqd8I9OR8/ZtWJKLEUZyQaajEXFScCAGdc5G5gAgAA X-Env-Sender: jgross@suse.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1499096451!96171607!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34371 invoked from network); 3 Jul 2017 15:40:51 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-7.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 3 Jul 2017 15:40:51 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5FB97AAC5; Mon, 3 Jul 2017 15:40:51 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Date: Mon, 3 Jul 2017 17:40:37 +0200 Message-Id: <20170703154037.17851-1-jgross@suse.com> X-Mailer: git-send-email 2.12.3 Cc: Juergen Gross , boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH] xen/balloon: don't online new memory initially 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 When setting up the Xenstore watch for the memory target size the new watch will fire at once. Don't try to reach the configured target size by onlining new memory in this case, as the current memory size will be smaller in almost all cases due to e.g. BIOS reserved pages. Onlining new memory will lead to more problems e.g. undesired conflicts with NVMe devices meant to be operated as block devices. Instead remember the difference between target size and current size when the watch fires for the first time and apply it to any further size changes, too. In order to avoid races between balloon.c and xen-balloon.c init calls do the xen-balloon.c initialization from balloon.c. Signed-off-by: Juergen Gross --- drivers/xen/balloon.c | 3 +++ drivers/xen/xen-balloon.c | 20 ++++++++++++-------- include/xen/balloon.h | 8 ++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 50dcb68d8070..ab609255a0f3 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -780,6 +780,9 @@ static int __init balloon_init(void) } #endif + /* Init the xen-balloon driver. */ + xen_balloon_init(); + return 0; } subsys_initcall(balloon_init); diff --git a/drivers/xen/xen-balloon.c b/drivers/xen/xen-balloon.c index e7715cb62eef..66ec519c825c 100644 --- a/drivers/xen/xen-balloon.c +++ b/drivers/xen/xen-balloon.c @@ -59,6 +59,8 @@ static void watch_target(struct xenbus_watch *watch, { unsigned long long new_target; int err; + static bool watch_fired; + static unsigned long target_diff; err = xenbus_scanf(XBT_NIL, "memory", "target", "%llu", &new_target); if (err != 1) { @@ -69,7 +71,14 @@ static void watch_target(struct xenbus_watch *watch, /* The given memory/target value is in KiB, so it needs converting to * pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10. */ - balloon_set_new_target(new_target >> (PAGE_SHIFT - 10)); + new_target >>= PAGE_SHIFT - 10; + if (watch_fired) { + balloon_set_new_target(new_target - target_diff); + return; + } + + watch_fired = true; + target_diff = new_target - balloon_stats.target_pages; } static struct xenbus_watch target_watch = { .node = "memory/target", @@ -94,13 +103,8 @@ static struct notifier_block xenstore_notifier = { .notifier_call = balloon_init_watcher, }; -static int __init balloon_init(void) +void __init xen_balloon_init(void) { - if (!xen_domain()) - return -ENODEV; - - pr_info("Initialising balloon driver\n"); - register_balloon(&balloon_dev); register_xen_selfballooning(&balloon_dev); @@ -109,7 +113,7 @@ static int __init balloon_init(void) return 0; } -subsys_initcall(balloon_init); +EXPORT_SYMBOL_GPL(xen_balloon_init); #define BALLOON_SHOW(name, format, args...) \ static ssize_t show_##name(struct device *dev, \ diff --git a/include/xen/balloon.h b/include/xen/balloon.h index d1767dfb0d95..8906361bb50c 100644 --- a/include/xen/balloon.h +++ b/include/xen/balloon.h @@ -35,3 +35,11 @@ static inline int register_xen_selfballooning(struct device *dev) return -ENOSYS; } #endif + +#ifdef CONFIG_XEN_BALLOON +void xen_balloon_init(void); +#else +static inline void xen_balloon_init(void) +{ +} +#endif