From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796228650; b=Pq/J/g5+6SMjee3knEDa3N8pwZb/Wk2YKZoBoswhj2Oa7kRFLs8OOkQrMVjxZ8/KNYnK bylTseiaSnqLYccusZLEWz3t+mE8DETsvkpsssg58cfjwyrUAxzWpe0IKRHkT0aTnDoJ2 PsXtZtNDw3Ba7J6p1lpzSNp48oJm1PefFx7KMaOixggyQgNGHDbDnULPLrTQqvIowOKL4 IISb/tMP7pmwp9Fit+9l3Bumes/s240wQX6FZjRTZU3PnU9zYHYpeh45c+0Kne5OihdR8 9NguUq2Qn5J3UObK/5fWbJ1/89s/9I+4e25t9FTnM55Q9Zxgw9Zb4ANZF852otyxxKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796228650; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=DJLOnpTZjowepU0E6stkQd/wBDy06cfP8zky0R11Asg=; b=rGjHPt36t4m98MNAH7+GRI0cIyoKAyG0OfNMGp6tiEAZ2Yz7hBd2NGxDse/rWkj+dzaf dzlVnUUru3bjIfZ9U12cu1f63Wx1+wkyYoHVOiEPLeOe5285yNj/suiATGt2oavUE8QPd ZDFTUOLtZQHw3Jh8sGq3818pXeHEu3oeKQZb/Pu2sPCJNBTsZ+BxOcJflWQ0AIH0GS7G0 oAojv1fcZaA6NJXVWMLiPt9ncWG4JSug9cz/ML/JXwFjqzebGQ4ahzqb1fF2GJMus/Bv1 PGEAVoDfDSfPfME5QLdtJ7fR13RGvo2CalhEO51c2viCoI8hNrSoXwWi4GfC3udhzlQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=C7I5qCvD; arc=none smtp.remote-ip=209.85.210.72 Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DCFF606A68B for ; Wed, 2 Dec 2026 16:24:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DCFF606A68B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=C7I5qCvD Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-86285932977so13313803a34.0 for ; Wed, 02 Dec 2026 08:24:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796228647; x=1796833447; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=DJLOnpTZjowepU0E6stkQd/wBDy06cfP8zky0R11Asg=; b=C7I5qCvDieYNCPTYy8gbhdPXG3j3CxccqZznS3vNfJXtVCoJps26ofMwexEqyzaBHw f5xEdEFbSlyfGlH92Fo8PYwG44/2rHktAkXjySwhzEG8wJUFT6MZWwfzG+Bj+XGIUHR+ 8Q23C9a+QVU+K5wtMMU1VFykcTCGuqETZhkS4w5IXCHcZ0TSIfaLSe+CbaVxhSTt2fc1 k0apzf4v+q6lln2/LE+Jf6y7EiJskPoLz0P5RvUtG/j17EM+Meb2Vgs1pzKNlfLEPz0Q BuA+qdxGeK6AHO/s8Rgzb3tgynRTLO85sBLJdUN1Ymg+5lW+FDlJgrblTO4oMjoa5zi8 D/gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796228647; x=1796833447; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DJLOnpTZjowepU0E6stkQd/wBDy06cfP8zky0R11Asg=; b=WBYT7EL9Q1d4W/86+x7PegGPS7Sf6mbeSmRtP/B62ZC8/kA0p1K2IdnYXohOaqw0hP NxoiuAYGd3ccSpPcX4eVgfjg/QcHi4LKFNE0TRRE7ZxEICI0fcaxSdHkw9z+4YF9JPbE 106XasiCgLg+0KywRsdNWt1P0hzyMga64vGkS3n7L0YwPqGNKdq6gqL7RdpTXxbVj4Xx IXeVs0VeDJLgB0oKxojZ6x7i7vcyYGV1byf5j7krM1OwUveMOOQ5F9uvHFhGtgMZ1PyK 4p6fHdl448NmMz9/q4KNBjwCGvrJFZkAtFyFTM0uiRTIkZdfHxwGKrDz2rH20eXTo3bw dlGA== X-Forwarded-Encrypted: i=1; AL+hErFJ0hMkH15U/eZ77H5MqmrJ8G6g9PJwD4Jj1Cp4luUj6PSI81RkxhWv3zMmMBkrxRodrOxM5FF9cEBReE0=@vger.kernel.org X-Gm-Message-State: APuU4Z/ioLzXKJcHYe4Y61Kf3nDIM3SpFS0OZ2BCOuWgKar0hB+bXRkb tAxwcsvp/U+wl+p+2rB5aWkwBEYaJbDJv409QKYMm07GqoDVZXqCZWg7S0HLg0kLHokv1A2u50b 3P8RpSy1Z4E5AEtHIctHJX5aywKVY0g== X-Received: from ilbdx19-n1.prod.google.com ([2002:a05:6e02:4213:10b0:524:7f06:cd03]) (user=zhenwenliang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:244c:b0:557:4340:4d47 with SMTP id 5614622812f47-57a09400d0amr49043779b6e.35.1796228646798; Wed, 02 Dec 2026 08:24:06 -0800 (PST) Date: Wed, 2 Dec 2026 16:24:05 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261202162405.2044419-1-zhenwenliang@google.com> Subject: [PATCH] block: order the bi_status load after the waiter check in __blkdev_direct_IO() From: Zhenwen Liang To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig , Hou Tao , Peter Zijlstra , "Paul E . McKenney" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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))