Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4910857rwb; Mon, 8 Aug 2022 08:58:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR5NZlW31lxD/3Hwg7kpFeCTSRzQh311JY+zGrImRGnXQ9LxDBARIEqIdZjnDpmljK7fRGHf X-Received: by 2002:a63:d0:0:b0:41b:c075:acb5 with SMTP id 199-20020a6300d0000000b0041bc075acb5mr15752505pga.480.1659974337398; Mon, 08 Aug 2022 08:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659974337; cv=none; d=google.com; s=arc-20160816; b=P9JVu7P3PQbRiqdl/Z+lUP6tNHfi0GY5bM9770+6JWtk7wZHvvz/NhuKMQLMyZc8i1 n2t4p+EjnTSOaLWHYFyq5KSpF4ycDa0UONATRb6MzdBQuMG30XyxMwl2HI09tWbe/G2Q ni0w0zuDtxYJPNs8l6tkClP2+JUgPyjrKlQfuYr61XQ6rqvz7K2FuhBkuQL6vBkgqvcL 0UNJJpDjv5JNUwaNzdV+Lh05r7Khhg7YY34cWakAKVf6+g0+4w33lkvh1icJBNCX8FLg TjsbIBnTEKmITNeZWW0sD4LRtDFECUvC0SVjw4Umu5Dl1W2Ql4JjtfqDs+0ba/fWs8ym twGA== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=DSjhmXl4xWPSJ9dcr8S5H4UYbeb9vJQz9qCHMPvfDRk=; b=mkqPnDBSpYzLzH4AVjEnMszMvqDH1j8FQ3lRBbp8qFAYRB9P4gTalEIe+v5/iCeujF z+fCFXc1JZrAOSrQedUPSVYkCP3KrpRLu+cz70UlNHcIXUAG/9bvwpObcTzQ+Di6N/dS 57PkWB5m4HVx/6yNSdpou9w0BB8A3QDqjBMI6RQ0hiLzv7a6/z35iBfeyvhMet7JeXpo UsvCwe58FZ8GGhv1tG6ueItbr/cdSRD4U166v2YE29MtCByWX/1ja1G2dVEVTmR+0hb0 qoq7iNF5ai6xyUo/GHsAn5gaMUSQ0J9oogLzo3GJl3ujGxlNR8jYgoZ5MjM7PHwnDqEW oplg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OjgXoJ3O; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a056a00190700b0052e13337a6asi13147329pfi.161.2022.08.08.08.58.43; Mon, 08 Aug 2022 08:58:57 -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=@kernel.org header.s=k20201202 header.b=OjgXoJ3O; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243701AbiHHPbS (ORCPT + 99 others); Mon, 8 Aug 2022 11:31:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233652AbiHHPbP (ORCPT ); Mon, 8 Aug 2022 11:31:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A0F1402F; Mon, 8 Aug 2022 08:31:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7A9D2B80EE6; Mon, 8 Aug 2022 15:31:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19AB9C433C1; Mon, 8 Aug 2022 15:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659972672; bh=qOvwZkGh7HLkeEg6nfF9Kxo7AMoAIc1CMELa4sVqOWw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=OjgXoJ3ODIV4FhwtawMvRiSA1XIShisIr5GMZZuVyNrQxt4KpyssI2/uLrc1orCuy Svkf/B0iShPLaSbV82yN7Ol3ZYdbAcUQ5MS0T4PkDKAnzHOQGx5XANm0Prs4qoJN55 pyuoEjiuTo2CdgqOHMTajprcXMksE6z+ExETh/tRxTxOpzL0333WhwBBZP65wt8J4F orGjgJDGvFKZA/78KmmQRGQXAtgMYozYfDVzphMyurxmMuEH5WL+FQJWToxd4Ljm4u Hco8bsHSvyCyq2Jebct9eDE+V7F/ClI4gzSqPWBwxiw3/b3PQlIkGOnZtwuinRtfJV Jbm2wQ3X4DJ0w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id AE1FF5C128A; Mon, 8 Aug 2022 08:31:11 -0700 (PDT) Date: Mon, 8 Aug 2022 08:31:11 -0700 From: "Paul E. McKenney" To: Mikulas Patocka Cc: Matthew Wilcox , Linus Torvalds , Will Deacon , 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: <20220808153111.GE2125313@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 Mon, Aug 08, 2022 at 10:57:45AM -0400, Mikulas Patocka wrote: > > > On Mon, 8 Aug 2022, Matthew Wilcox wrote: > > > On Mon, Aug 08, 2022 at 10:26:10AM -0400, Mikulas Patocka wrote: > > > On Sun, 7 Aug 2022, Matthew Wilcox wrote: > > > > > +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? > > > > > > There's this in fs/reiserfs: > > > > > > if (!buffer_dirty(bh) && !buffer_locked(bh)) { > > > reiserfs_free_jh(bh); <--- this could be moved before buffer_locked > > > > It might be better to think of buffer_locked() as > > buffer_someone_has_exclusive_access(). I can't see the problem with > > moving the reads in reiserfs_free_jh() before the read of buffer_locked. > > > > > if (buffer_locked((journal->j_header_bh))) { > > > ... > > > } > > > journal->j_last_flush_trans_id = trans_id; > > > journal->j_first_unflushed_offset = offset; > > > jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data); <--- this could be moved before buffer_locked > > > > I don't think b_data is going to be changed while someone else holds > > the buffer locked. That's initialised by set_bh_page(), which is an > > initialisation-time thing, before the BH is visible to any other thread. > > So, do you think that we don't need a barrier in buffer_locked()? The question to ask here is "What prevents another call to buffer_locked() from returning false?" > There is also this (where the BUG_ON(!buffer_uptodate(bh)) saves it). > if (buffer_locked(bh)) { Right here, for example. If something prevents any change that might cause buffer_locked() to return false here, we don't need a barrier. If there is nothing preventing such a change, how is a barrier going to help? One way this code could be correct is if the above check is a heuristic, so that a false positive just consumes a bit more CPU and a false negative just delays this action. I must leave final judgment to those having better understanding of this code than do I. Thanx, Paul > int depth; > PROC_INFO_INC(sb, scan_bitmap.wait); > depth = reiserfs_write_unlock_nested(sb); > __wait_on_buffer(bh); > reiserfs_write_lock_nested(sb, depth); > } > BUG_ON(!buffer_uptodate(bh)); > BUG_ON(atomic_read(&bh->b_count) == 0); > > if (info->free_count == UINT_MAX) > reiserfs_cache_bitmap_metadata(sb, bh, info); <--- this could be moved before buffer_locked if there were no BUG_ONs > > Mikulas >