[PATCH] block/blk-iocost: annotate committed flag with READ_ONCE/WRITE_ONCE

Tao Cui <[email protected]> Sun, 2 Aug 2026 23:17:55 +0800
Newsgroups org.kernel.vger.cgroups,org.kernel.vger.linux-block,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
From: Tao Cui <[email protected]>

The "committed" wait flag is written by iocg_wake_fn() under
waitq.lock and read by ioc_rqos_throttle() without the lock, which
trips KCSAN.  The ordering is already handled by
set_current_state()/wake_up() so the race is harmless.  Use
READ_ONCE()/WRITE_ONCE() to document the intentional lockless access.

Signed-off-by: Tao Cui <[email protected]>
---
 block/blk-iocost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 8b2aeba2e1e3..782bbe2d27b3 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1458,7 +1458,7 @@ static int iocg_wake_fn(struct wait_queue_entry *wq_entry, unsigned mode,
 		return -1;
 
 	iocg_commit_bio(ctx->iocg, wait->bio, wait->abs_cost, cost);
-	wait->committed = true;
+	WRITE_ONCE(wait->committed, true);
 
 	/*
 	 * autoremove_wake_function() removes the wait entry only when it
@@ -2763,7 +2763,7 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio)
 
 	while (true) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
-		if (wait.committed)
+		if (READ_ONCE(wait.committed))
 			break;
 		io_schedule();
 	}
-- 
2.43.0