mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jenson Johnathon Reggentin <mail@jregg.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Jenson Johnathon Reggentin <mail@jregg.de>,
	Marco Elver <elver@google.com>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+ba8947364367f96fe16b@syzkaller.appspotmail.com
Subject: [PATCH v2] blk-wbt: Fix data race and avoid possible false sharing
Date: Mon, 23 Nov 2026 15:17:43 +0100	[thread overview]
Message-ID: <20261123141745.237765-1-mail@jregg.de> (raw)
In-Reply-To: <CANpmjNM9n+nCb46nEAUcrU6kecC5LOyYSxKWN0So0pZwYZ34GQ@mail.gmail.com>

From: Marco Elver <elver@google.com>

The pattern here is to avoid possible false sharing. However, due to
compiler optimizations the code may simply collapse to the write if we
omit READ_ONCE/WRITE_ONCE:
https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE#it-may-improve-performance

Fixes: e34cbd307477 ("blk-wbt: add general throttling mechanism")
Reported-by: syzbot+ba8947364367f96fe16b@syzkaller.appspotmail.com
Link: https://lore.kernel.org/all/20191105182746.217864-1-elver@google.com/
Link: https://bugzilla.kernel.org/show_bug.cgi?id=220759
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Jenson Johnathon Reggentin <mail@jregg.de>
---
v2: Pick up Marco Elver's 2019 patch with updated testing and an updated
Fixes Tag.

Tested with KCSAN, HZ=1000 and null_blk in a 4-vCPU,
2-GiB virtme-ng VM. The 30 second fio workload used two direct 4-KiB
random readers and one buffered 64-KiB writer.

The baseline produced two wbt_wait/wbt_wait and three wbt_done/wbt_done
reports.
Neither signature was observed with this patch. All fio jobs
completed without errors.

I also did an AI Code Review, it really wanted to add READ_ONCE
instructions for the reads inside the close_io function. These changes did not 
impact any of the KCSAN reports, in my testing, though.
So I consider them outside of the scope, but I thought I'd mention it for 
completeness sake.

 block/blk-wbt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 953d400fd013..a60df3524b98 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -156,8 +156,8 @@ static void wb_timestamp(struct rq_wb *rwb, unsigned long *var)
 	if (rwb_enabled(rwb)) {
 		const unsigned long cur = jiffies;
 
-		if (cur != *var)
-			*var = cur;
+		if (cur != READ_ONCE(*var))
+			WRITE_ONCE(*var, cur);
 	}
 }
 

base-commit: 77cc1587b17a356f1638f09ade33872a919a82ab

           reply	other threads:[~2026-11-23 14:18 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CANpmjNM9n+nCb46nEAUcrU6kecC5LOyYSxKWN0So0pZwYZ34GQ@mail.gmail.com>]

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=20261123141745.237765-1-mail@jregg.de \
    --to=mail@jregg.de \
    --cc=axboe@kernel.dk \
    --cc=elver@google.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+ba8947364367f96fe16b@syzkaller.appspotmail.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

all inboxes | Powered by JetHome®