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 1/3] vmw_balloon: access reset_required through READ/WRITE_ONCE
Date: Tue, 13 Sep 2022 02:43:04 -0700	[thread overview]
Message-ID: <20220913094306.317734-2-namit@vmware.com> (raw)
In-Reply-To: <20220913094306.317734-1-namit@vmware.com>

From: Nadav Amit <namit@vmware.com>

reset_required might be accessed concurrently, at least through debugfs.
While there is no apparent functional risk, avoid any potential race,
even if it is benign.

Use READ_ONCE() and WRITE_ONCE() when accessing reset_required.

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

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 61a2be712bf7..7fa91983c567 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -492,7 +492,7 @@ __vmballoon_cmd(struct vmballoon *b, unsigned long cmd, unsigned long arg1,
 
 	/* mark reset required accordingly */
 	if (status == VMW_BALLOON_ERROR_RESET)
-		b->reset_required = true;
+		WRITE_ONCE(b->reset_required, true);
 
 	return status;
 }
@@ -965,7 +965,7 @@ static int64_t vmballoon_change(struct vmballoon *b)
 	 * Otherwise we might get huge positives instead of negatives
 	 */
 
-	if (b->reset_required)
+	if (READ_ONCE(b->reset_required))
 		return 0;
 
 	/* consider a 2MB slack on deflate, unless the balloon is emptied */
@@ -1446,7 +1446,7 @@ static void vmballoon_reset(struct vmballoon *b)
 	}
 
 	vmballoon_stats_gen_inc(b, VMW_BALLOON_STAT_RESET);
-	b->reset_required = false;
+	WRITE_ONCE(b->reset_required, false);
 
 	error = vmballoon_vmci_init(b);
 	if (error)
@@ -1473,7 +1473,7 @@ static void vmballoon_work(struct work_struct *work)
 	struct vmballoon *b = container_of(dwork, struct vmballoon, dwork);
 	int64_t change = 0;
 
-	if (b->reset_required)
+	if (READ_ONCE(b->reset_required))
 		vmballoon_reset(b);
 
 	down_read(&b->conf_sem);
@@ -1666,7 +1666,7 @@ static int vmballoon_debug_show(struct seq_file *f, void *offset)
 		   VMW_BALLOON_CAPABILITIES);
 	seq_printf(f, "%-22s: %#16lx\n", "used capabilities", b->capabilities);
 	seq_printf(f, "%-22s: %16s\n", "is resetting",
-		   b->reset_required ? "y" : "n");
+		   READ_ONCE(b->reset_required) ? "y" : "n");
 
 	/* format size info */
 	seq_printf(f, "%-22s: %16lu\n", "target", READ_ONCE(b->target));
-- 
2.25.1


  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 ` Nadav Amit [this message]
2022-09-13  9:43 ` [PATCH 2/3] vmw_balloon: exit if initalization fails Nadav Amit
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-2-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