mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] block: order the bi_status load after the waiter check in __blkdev_direct_IO()
@ 2026-12-02 16:24 Zhenwen Liang
  0 siblings, 0 replies; only message in thread
From: Zhenwen Liang @ 2026-12-02 16:24 UTC (permalink / raw)
  To: Jens Axboe, linux-block
  Cc: Christoph Hellwig, Hou Tao, Peter Zijlstra, Paul E . McKenney,
	linux-kernel

In the synchronous path, __blkdev_direct_IO() checks dio->waiter and,
once it is NULL, reads dio->bio.bi_status. When the waiter is already
NULL on the first check, so that the task never sleeps, only a control
dependency separates the two loads, and that does not order loads. On
weakly ordered CPUs the submitter can then see the waiter cleared but a
stale bi_status of 0 and report success for a failed I/O. The completion
side already orders its bi_status store before clearing the waiter
through the fully ordered atomic_dec_and_test().

Hou Tao reported this in 2021, and Peter Zijlstra suggested smp_rmb() on
the reader side; that patch was never respun. Add the smp_rmb().

The problem was found, and this patch prepared, with the help of a
formal analysis tool we are developing that uses AI assistance; I have
reviewed the analysis and the patch.

Link: https://lore.kernel.org/all/20210701113537.582120-1-houtao1@huawei.com/
Fixes: 542ff7bf18c6 ("block: new direct I/O implementation")
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Zhenwen Liang <zhenwenliang@google.com>
---
Compile-tested only (arm64, W=1); the barrier is emitted as dmb ishld
between the two loads.

 block/fops.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/block/fops.c b/block/fops.c
index 0843797..da7a7c5 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -293,6 +293,11 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
 	}
 	__set_current_state(TASK_RUNNING);
 
+	/*
+	 * Order the dio->waiter load above before the dio->bio.bi_status load.
+	 * Pairs with atomic_dec_and_test() in blkdev_bio_end_io().
+	 */
+	smp_rmb();
 	if (!ret)
 		ret = blk_status_to_errno(dio->bio.bi_status);
 	if (likely(!ret))

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

only message in thread, other threads:[~2026-12-02 16:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 16:24 [PATCH] block: order the bi_status load after the waiter check in __blkdev_direct_IO() Zhenwen Liang

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®