Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1642056imn; Sun, 31 Jul 2022 15:46:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uauOY/YaL+X4SGK4UjR4+tfqpTSgwaRy/sStSxUJcqfITy1jtdFiWU4DTksJVfKllLcD/Y X-Received: by 2002:a17:906:7b82:b0:6f3:ee8d:b959 with SMTP id s2-20020a1709067b8200b006f3ee8db959mr10188621ejo.458.1659307614727; Sun, 31 Jul 2022 15:46:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659307614; cv=none; d=google.com; s=arc-20160816; b=Np6+VzjvnYGF6OZdhzzXQzI2ao8sMMDrT6KbGoiSIUjsmTbjbEJA+ZMbyLslmHKf6A ME8BTvsYX21YOY6FliS0+QQW7vox9MT56OcMZPp3AUUd2gYXPS3Ke1BJzZ7o9gSNWbYW kgwHC3gqOdt9lYhkv1G8bX3wWtQIE8/l/t1AJF0ERxU15DgycvBuykXjGBnHjR/r8TM+ 6SjUY7P9UWp1R3MUOptH2qdEf89ntO//cSURCyhpo/0hge0ILoq+hMcj5iR2TkhSOsMc Oa4IRCZp7i6afKj+btTeX9QP/virnksR2uNJOj2tc3XLrBNRC104k1SicItzfUl3ZJxk vbag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+qm1vAmgi6sjZNEi6Z0fSdbuq7XPAQLGXeiD0XxIuOY=; b=f5WJtLSe+LPUg8r6xtZA0t6lSDBj/AMdeGZqkrFdPSOAEbtfUGTXjzdxcj02oBTUmL nk2BGEs6mL9AbEhLcxd3L+nvwsaIKlOVaPZ0Iz4WzwnaCOjBHQ0CGZInA2iB3TkhXN4S 1bIa6yPrVdq1oAVeD7WNCHjfxA6dAEPG5I0PdDR83haz/kMyhu8+eMFCaqRDKhDRmzLX Ndc98XMXanzm5zhY/8y45c1eB3h0unRMYVCTCKXkZPGyGOsY1b+IMg3U8lGqhjj3V6ZU MlxsMiavI1d8NBewAZteWSRoE2cZARiJ5Evtrf1F7iaUzc8u8GhDSXBfml4t3TCF0Ni9 WdnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HbUcOri3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j27-20020a056402239b00b0043d5404f4fasi4367611eda.104.2022.07.31.15.46.30; Sun, 31 Jul 2022 15:46:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HbUcOri3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238349AbiGaWOw (ORCPT + 99 others); Sun, 31 Jul 2022 18:14:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbiGaWOv (ORCPT ); Sun, 31 Jul 2022 18:14:51 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7A69DEFE; Sun, 31 Jul 2022 15:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+qm1vAmgi6sjZNEi6Z0fSdbuq7XPAQLGXeiD0XxIuOY=; b=HbUcOri3IfM8aEODm6uq0lPTlX Td1B9C+jQvJNZeArAg9FQVsunSHEatuIuq2N4hLFVV56R06dLus5sIcgladiW9a/3h0XyQL6H7iNo L0LOfaiVQYfU/O+lx0d7lkuOjE7JFd0Ax3x3qT5tMjObgECHRgA46V9Sz3IYsq5et9n6lzd3PcAJ4 /vrcYhhisOBYKQrwbs/mLmV8I43ORiM+qeBmov5NH857ExVaiQQ8SRxstAMTqsYx/WT8FDsbiCu9C fdJoXt4jmHaH+VK2/NFg80oN4v84Ixb3zxlkmEwW9zVKtyo2T4QXjc9zucLWm09Ajl0MRzFHjhQ0a 5bWQXYvg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oIHCW-006bWs-A2; Sun, 31 Jul 2022 22:14:20 +0000 Date: Sun, 31 Jul 2022 23:14:20 +0100 From: Matthew Wilcox To: Mikulas Patocka Cc: Linus Torvalds , Will Deacon , "Paul E. McKenney" , Ard Biesheuvel , Alexander Viro , Alan Stern , Andrea Parri , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Linux Kernel Mailing List , linux-arch , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v3 2/2] make buffer_locked provide an acquire semantics Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 31, 2022 at 04:43:08PM -0400, Mikulas Patocka wrote: > Let's have a look at this piece of code in __bread_slow: > get_bh(bh); > bh->b_end_io = end_buffer_read_sync; > submit_bh(REQ_OP_READ, 0, bh); > wait_on_buffer(bh); > if (buffer_uptodate(bh)) > return bh; > Neither wait_on_buffer nor buffer_uptodate contain a memory barrier. > Consequently, if someone calls sb_bread and then reads the buffer data, > the read of buffer data may be executed before wait_on_buffer(bh) on > architectures with weak memory ordering and it may return invalid data. I think we should be consistent between PageUptodate() and buffer_uptodate(). Here's how it's done for pages currently: static inline bool folio_test_uptodate(struct folio *folio) bool ret = test_bit(PG_uptodate, folio_flags(folio, 0)); /* * Must ensure that the data we read out of the folio is loaded * _after_ we've loaded folio->flags to check the uptodate bit. * We can skip the barrier if the folio is not uptodate, because * we wouldn't be reading anything from it. * * See folio_mark_uptodate() for the other side of the story. */ if (ret) smp_rmb(); return ret; ... static __always_inline void folio_mark_uptodate(struct folio *folio) /* * Memory barrier must be issued before setting the PG_uptodate bit, * so that all previous stores issued in order to bring the folio * uptodate are actually visible before folio_test_uptodate becomes true. */ smp_wmb(); set_bit(PG_uptodate, folio_flags(folio, 0)); I'm happy for these to also be changed to use acquire/release; no attachment to the current code. But bufferheads & pages should have the same semantics, or we'll be awfully confused.