Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp3840325rwb; Sun, 7 Aug 2022 08:27:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR66XBIT2TUwW2Uv1X67ydx+DUB9zdWfR2hNl/NWRDpDRXHrZtnljjuU5FbWwPn3o3qnzbA/ X-Received: by 2002:a05:6402:190b:b0:43d:d001:2cce with SMTP id e11-20020a056402190b00b0043dd0012ccemr14487104edz.326.1659886025298; Sun, 07 Aug 2022 08:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659886025; cv=none; d=google.com; s=arc-20160816; b=LyTk52G/9QSXp03RneQneWDDS3czJ8/QwIIGdu8ITvAr4lT1Rz1z1mFZrxiZKmU+LJ DeLUppPvo17u8jMQIaJ2e1JlEB5Ekm4dSKkdPhWuFIdnWg4oVsQHS1pQU/jytIiWmKoC /b+KErOregXPiqv8voJbnmJHMe7r5pislUDgybg76HDcevzHtwnI0/iYcxPMjgPGEluk 0a/dZ6jKv9yUYwEiBOk2aN4Hsb3hGadbInqQmJNR8V6mqLyC/KkmeFEwO4UQ9fCo4x82 QQk1Tj5V1nC+AOQI/Zf06Yyi4Kzo8j3elWnVySpiVOGk41i9pGW8aNeHI19EUhTM6UBr o8EQ== 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=AwfVzm7jiZjpn8Qxl8YEy4z+Wq+bogYNtYxMRJ65KwM=; b=y64Wb6baNHzeJuJtne5wruD23CTQJr82jneDCMFVZ5IM11zZdvfd+ZguxyDw1kW+sg T16LTkD4jpRHmYkcjRrqGG1X7xk9v6AqvEC8Ae8lDv9w8K1HyGahKv4cKJNegkIJommg tFyu/Eo9YcUOtX2RfDGPeDl/InZ+be8eiCwjbd9uV+j4HqMnfkWFmu9JdRmC8Wj/YqHq 5BZJqkn/h/jwMpnwtm7ZgUzSFo/K3tBertaymKcxu7Egqv9/8cTtKNncLuTo2CbXJgrl jag++KQy0qs0b2ABlqyzHN/UfHQzTeI6CibqDK57J6jrwawO8gYVCtRjE0p8XT6aOn4q WTYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LyHMz+kc; 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 f20-20020a056402355400b0043c2e89d0acsi5202821edd.3.2022.08.07.08.26.40; Sun, 07 Aug 2022 08:27:05 -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=LyHMz+kc; 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 S234096AbiHGOuh (ORCPT + 99 others); Sun, 7 Aug 2022 10:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230332AbiHGOug (ORCPT ); Sun, 7 Aug 2022 10:50:36 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71E46418; Sun, 7 Aug 2022 07:50:34 -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=AwfVzm7jiZjpn8Qxl8YEy4z+Wq+bogYNtYxMRJ65KwM=; b=LyHMz+kclwkYVjF6uGwuPnsKnU BqV0xk1gaFnui5fO4kFxsNVTzkFqitlBp0e3I0Rdqu4XdQndJtiCpHtUMKCKnPieyBGTY6lH7vCt2 VTJFbyH/DYyuEzUQ8z4Kk5tlOsugfBcNJtTg14l+Da1Alr8C8hzG3cJDCQdYAdE3jCeijQfaYwhwi 54AI5BHp6JgMnZSlt6tYyKGA9IVp53oiQXZwlGp6BN8QtQE7Ujpq8GyIJqThLZD1h//y7ZcTsw90B p6i7mTVxbZ/U7B5+ZnE530cwmTGovtklZIG9HDdrNjU8vwwVloqjEwq94zWJJhPL1wxAYRq+zRg9X P1EOcWHw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKhba-00D5Lb-Me; Sun, 07 Aug 2022 14:50:14 +0000 Date: Sun, 7 Aug 2022 15:50:14 +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 v5] add barriers to buffer functions 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,T_SCC_BODY_TEXT_LINE 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, Aug 07, 2022 at 07:37:22AM -0400, Mikulas Patocka wrote: > @@ -135,6 +133,49 @@ BUFFER_FNS(Meta, meta) > BUFFER_FNS(Prio, prio) > BUFFER_FNS(Defer_Completion, defer_completion) > > +static __always_inline void set_buffer_uptodate(struct buffer_head *bh) > +{ > + /* > + * make it consistent with folio_mark_uptodate > + * pairs with smp_acquire__after_ctrl_dep in buffer_uptodate > + */ > + smp_wmb(); > + set_bit(BH_Uptodate, &bh->b_state); > +} > + > +static __always_inline void clear_buffer_uptodate(struct buffer_head *bh) > +{ > + clear_bit(BH_Uptodate, &bh->b_state); > +} > + > +static __always_inline int buffer_uptodate(const struct buffer_head *bh) > +{ > + bool ret = test_bit(BH_Uptodate, &bh->b_state); > + /* > + * make it consistent with folio_test_uptodate > + * pairs with smp_wmb in set_buffer_uptodate > + */ > + if (ret) > + smp_acquire__after_ctrl_dep(); > + return ret; > +} This all works for me. While we have the experts paying attention, would it be better to do return smp_load_acquire(&bh->b_state) & (1L << BH_Uptodate) > 0; > +static __always_inline void set_buffer_locked(struct buffer_head *bh) > +{ > + set_bit(BH_Lock, &bh->b_state); > +} > + > +static __always_inline int buffer_locked(const struct buffer_head *bh) > +{ > + bool ret = test_bit(BH_Lock, &bh->b_state); > + /* > + * pairs with smp_mb__after_atomic in unlock_buffer > + */ > + if (!ret) > + smp_acquire__after_ctrl_dep(); > + return ret; > +} Are there places that think that lock/unlock buffer implies a memory barrier?