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 Signed-off-by: Zhenwen Liang --- 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))