mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] blk-wbt: Fix data race and avoid possible false sharing
       [not found] <CANpmjNM9n+nCb46nEAUcrU6kecC5LOyYSxKWN0So0pZwYZ34GQ@mail.gmail.com>
@ 2026-11-23 14:17 ` Jenson Johnathon Reggentin
  0 siblings, 0 replies; only message in thread
From: Jenson Johnathon Reggentin @ 2026-11-23 14:17 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Jenson Johnathon Reggentin, Marco Elver, linux-block,
	linux-kernel, syzbot+ba8947364367f96fe16b

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 14:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CANpmjNM9n+nCb46nEAUcrU6kecC5LOyYSxKWN0So0pZwYZ34GQ@mail.gmail.com>
2026-11-23 14:17 ` [PATCH v2] blk-wbt: Fix data race and avoid possible false sharing Jenson Johnathon Reggentin

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®