From: Zhenwen Liang <zhenwenliang@google.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>, Hou Tao <houtao@huaweicloud.com>,
Peter Zijlstra <peterz@infradead.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] block: order the bi_status load after the waiter check in __blkdev_direct_IO()
Date: Wed, 2 Dec 2026 16:24:05 +0000 [thread overview]
Message-ID: <20261202162405.2044419-1-zhenwenliang@google.com> (raw)
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))
next reply other threads:[~2026-12-02 16:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 16:24 Zhenwen Liang [this message]
2026-12-03 8:09 ` [PATCH] block: order the bi_status load after the waiter check in __blkdev_direct_IO() Christoph Hellwig
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=20261202162405.2044419-1-zhenwenliang@google.com \
--to=zhenwenliang@google.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=houtao@huaweicloud.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
/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