From patchwork Wed Jul 5 15:38:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9826739 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 64B9E60317 for ; Wed, 5 Jul 2017 15:40:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54A1D2858F for ; Wed, 5 Jul 2017 15:40:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4950528590; Wed, 5 Jul 2017 15:40:59 +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 C1E9928595 for ; Wed, 5 Jul 2017 15:40:58 +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 1dSmNv-0007mI-Tz; Wed, 05 Jul 2017 15:38:35 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSmNv-0007mC-59 for xen-devel@lists.xenproject.org; Wed, 05 Jul 2017 15:38:35 +0000 Received: from [85.158.143.35] by server-5.bemta-6.messagelabs.com id 02/43-03368-AF70D595; Wed, 05 Jul 2017 15:38:34 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHLMWRWlGSWpSXmKPExsVyuP0Ov+5P9th Ig0X31S2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyb1ycyFeyXrLi77CxLA+Md0S5GTg4JASOJ txP/MXUxcnEICSxklOjdPo0VJMEmoCqx4fopMFtEwFFiddtSMJtZwEFi1qyjzF2MHBzCAk4Sn 8+FgIRZgMpXbv3ICGLzCphIXHw3ixVivrxEx4HJLBMYORcwMqxiVC9OLSpLLdK11EsqykzPKM lNzMzRNTQw08tNLS5OTE/NSUwq1kvOz93ECPQVAxDsYLy7KeAQoyQHk5Iob+XpmEghvqT8lMq MxOKM+KLSnNTiQ4wyHBxKEryT2GIjhQSLUtNTK9Iyc4BBA5OW4OBREuFdcweolbe4IDG3ODMd InWK0Zhjw+r1X5g4Xk34/41JiCUvPy9VSpy3AGSSAEhpRmke3CBYMF9ilJUS5mUEOk2IpyC1K DezBFX+FaM4B6OSMC8DMDaEeDLzSuD2vQI6hQnoFMVGsFNKEhFSUg2Msesqzs615Wa9Vl7Fkl vnzii3JvmaZfmHozwarHNXfpVq6+p+W24ven5S/iHHgwnLX3xcLWYYmtMmKRGbYjvD7a3d++g lEWuETObeL2X0+BDV4Fu0xehN7VG+oA+rBepLuJmezeAT1Kxc+asyp9us+qFzy3zHpk7veIfu 2LNTfixkOuNi/kCJpTgj0VCLuag4EQAX76KAYQIAAA== X-Env-Sender: jgross@suse.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1499269113!63851835!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.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29598 invoked from network); 5 Jul 2017 15:38:33 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-5.tower-21.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 5 Jul 2017 15:38:33 -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 E291EABB3; Wed, 5 Jul 2017 15:38:32 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Date: Wed, 5 Jul 2017 17:38:06 +0200 Message-Id: <20170705153806.23488-1-jgross@suse.com> X-Mailer: git-send-email 2.12.3 Cc: Juergen Gross , boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH v2] 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 | 22 ++++++++++++---------- include/xen/balloon.h | 8 ++++++++ 3 files changed, 23 insertions(+), 10 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..d78fee8dd8dd 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 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,22 +103,15 @@ 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); register_xenstore_notifier(&xenstore_notifier); - - 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