public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <nadav.amit@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	VMware PV-Drivers Reviewers <pv-drivers@vmware.com>,
	Arnd Bergmann <arnd@arndb.de>, Nadav Amit <namit@vmware.com>
Subject: [PATCH 2/3] vmw_balloon: exit if initalization fails
Date: Tue, 13 Sep 2022 02:43:05 -0700	[thread overview]
Message-ID: <20220913094306.317734-3-namit@vmware.com> (raw)
In-Reply-To: <20220913094306.317734-1-namit@vmware.com>

From: Nadav Amit <namit@vmware.com>

In certain VMware hypervisor variants the balloon might not be
supported. In such cases initialization would fail, but resources would
keep being unnecessarily wasted. The balloon driver would retry
reinitialization every second for no reason.

Initialize the balloon once during init, before starting the worker. If
initialization fails, put out a message and fail gracefully.

Signed-off-by: Nadav Amit <namit@vmware.com>
---
 drivers/misc/vmw_balloon.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 7fa91983c567..762442b9ece8 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -1416,7 +1416,7 @@ static void vmballoon_pop(struct vmballoon *b)
  * is not  empty) and then restarting protocol. This operation normally
  * happens when host responds with VMW_BALLOON_ERROR_RESET to a command.
  */
-static void vmballoon_reset(struct vmballoon *b)
+static int vmballoon_reset(struct vmballoon *b)
 {
 	int error;
 
@@ -1427,11 +1427,13 @@ static void vmballoon_reset(struct vmballoon *b)
 	/* free all pages, skipping monitor unlock */
 	vmballoon_pop(b);
 
-	if (vmballoon_send_start(b, VMW_BALLOON_CAPABILITIES))
+	error = vmballoon_send_start(b, VMW_BALLOON_CAPABILITIES);
+	if (error)
 		goto unlock;
 
 	if ((b->capabilities & VMW_BALLOON_BATCHED_CMDS) != 0) {
-		if (vmballoon_init_batching(b)) {
+		error = vmballoon_init_batching(b);
+		if (error) {
 			/*
 			 * We failed to initialize batching, inform the monitor
 			 * about it by sending a null capability.
@@ -1448,8 +1450,7 @@ static void vmballoon_reset(struct vmballoon *b)
 	vmballoon_stats_gen_inc(b, VMW_BALLOON_STAT_RESET);
 	WRITE_ONCE(b->reset_required, false);
 
-	error = vmballoon_vmci_init(b);
-	if (error)
+	if (vmballoon_vmci_init(b))
 		pr_err_once("failed to initialize vmci doorbell\n");
 
 	if (vmballoon_send_guest_id(b))
@@ -1457,6 +1458,7 @@ static void vmballoon_reset(struct vmballoon *b)
 
 unlock:
 	up_write(&b->conf_sem);
+	return error;
 }
 
 /**
@@ -1879,6 +1881,23 @@ static int __init vmballoon_init(void)
 	if (x86_hyper_type != X86_HYPER_VMWARE)
 		return -ENODEV;
 
+	INIT_LIST_HEAD(&balloon.huge_pages);
+	spin_lock_init(&balloon.comm_lock);
+	init_rwsem(&balloon.conf_sem);
+	balloon.vmci_doorbell = VMCI_INVALID_HANDLE;
+	balloon.batch_page = NULL;
+	balloon.page = NULL;
+	balloon.reset_required = true;
+
+	/*
+	 * Reset the balloon to check that it is indeed supported.
+	 */
+	error = vmballoon_reset(&balloon);
+	if (error) {
+		pr_err("memory ballooning is disabled");
+		goto fail;
+	}
+
 	INIT_DELAYED_WORK(&balloon.dwork, vmballoon_work);
 
 	error = vmballoon_register_shrinker(&balloon);
@@ -1892,14 +1911,6 @@ static int __init vmballoon_init(void)
 	balloon_devinfo_init(&balloon.b_dev_info);
 	vmballoon_compaction_init(&balloon);
 
-	INIT_LIST_HEAD(&balloon.huge_pages);
-	spin_lock_init(&balloon.comm_lock);
-	init_rwsem(&balloon.conf_sem);
-	balloon.vmci_doorbell = VMCI_INVALID_HANDLE;
-	balloon.batch_page = NULL;
-	balloon.page = NULL;
-	balloon.reset_required = true;
-
 	queue_delayed_work(system_freezable_wq, &balloon.dwork, 0);
 
 	vmballoon_debugfs_init(&balloon);
-- 
2.25.1


  parent reply	other threads:[~2022-09-13 18:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-13  9:43 [PATCH 0/3] vmw_balloon: misc fixes and enhancements Nadav Amit
2022-09-13  9:43 ` [PATCH 1/3] vmw_balloon: access reset_required through READ/WRITE_ONCE Nadav Amit
2022-09-13  9:43 ` Nadav Amit [this message]
2022-09-13  9:43 ` [PATCH 3/3] vmw_balloon: open-code vmballoon_compaction_init() Nadav Amit
2022-09-14 10:14   ` David Hildenbrand
2022-09-15  0:05   ` kernel test robot
2022-09-15  3:16     ` Nadav Amit
2022-09-16  8:10   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220913094306.317734-3-namit@vmware.com \
    --to=nadav.amit@gmail.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namit@vmware.com \
    --cc=pv-drivers@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox