Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4853072rwb; Mon, 8 Aug 2022 08:04:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR7aTdaDRfFNZLdfuTcsNJISPxJ0rYU7epMhWx88KljBHRuPCi32TDQfKLXfxD3gSJIZn6og X-Received: by 2002:a17:907:2e01:b0:730:a098:7257 with SMTP id ig1-20020a1709072e0100b00730a0987257mr14123470ejc.705.1659971081931; Mon, 08 Aug 2022 08:04:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659971081; cv=none; d=google.com; s=arc-20160816; b=NlJkSlLbcvbYd5pWHZtqiwcePy9kzdpvUNUllKProk7kXCQvZ49+AHi4k2975Khoo2 P+Ee+qMac2IQkBsIu9rlyC82+6FDAvLaztGFZz0+YXvUeHugGJSQ+ldm+jzuRrYfTCdF WKdmMqPhhSna+HmqWcmCsvNVWGXmeA7ceHNqNCi8prEGc5zoi/Vy14cP7ILEZMdyYZ6k BBGWSxJHZ3uU0KhN+AzJBfjhnsHAeK6IBiEczR3TTphm2821Ni9T0vrt6DNnxeMNY4pQ 2sAO46uw/wi4Bn/mje/X+Y7Y9ze6dOUQ58vwcpL4njrEWvwKQYQy+HWYL4wqnrCW52FE Wkkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=QV1haXmrif3A28i1cY1lp+uj/T99BiZiUpEQe1keJWk=; b=jBPdKKRBYIzyryPLGTwbRioU9KJYfG9Q4o7nQtax5rUHnKWODq4JmWuxpi05kvCINE Jkd8brTZ9X5Rr8BHKQlfZP/QuvZ4WRaZqnQ7WvDwPWgdsecGOW42Ud8iGxEmzfXdf750 CyYmQ+CxZ03/mtdrNDJvjbvBoU2IQufCHBbLoitXYe371+e/KLng8wUGGLaUqv95YI/k e9C4F87ka+swMKknErnpNLQe2nTMJT7rweOC0mD5UAg9OL2vOBaOdY2HMwPt4BcFZomN 2PIe5q31nzFYqEDzcDuQc4y6pvVVJIA0TC0WwwAEXJ76BsINukb9oFOERGOQhjGd2vcy m2HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Z93pILJO; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb32-20020a1709077ea000b007120a60b38asi5555215ejc.1001.2022.08.08.08.04.15; Mon, 08 Aug 2022 08:04:41 -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=@redhat.com header.s=mimecast20190719 header.b=Z93pILJO; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243661AbiHHO6d (ORCPT + 99 others); Mon, 8 Aug 2022 10:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243700AbiHHO6O (ORCPT ); Mon, 8 Aug 2022 10:58:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7009613DF7 for ; Mon, 8 Aug 2022 07:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659970673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QV1haXmrif3A28i1cY1lp+uj/T99BiZiUpEQe1keJWk=; b=Z93pILJOSh+aB4UhEUHwTwRB7Ci+al2KxvOhr/LNm04PG5VMgvz5jMzg6DjoT93OuGvw8O KXxxZGER7VoVRNg5XZza5A9/Jc9lIeTjrebI6MXW6RZW5kVheeAC4We6dmFyM1QamGhAmi Jf0x+9XoOWyHEUI/Hu7LlwCBa331NuI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-177-7qqwk5nNPyObKHLoqMHhMw-1; Mon, 08 Aug 2022 10:57:48 -0400 X-MC-Unique: 7qqwk5nNPyObKHLoqMHhMw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A0F6C823F0D; Mon, 8 Aug 2022 14:57:46 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CF36112131B; Mon, 8 Aug 2022 14:57:46 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id 278EvkLc013506; Mon, 8 Aug 2022 10:57:46 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 278Evjcp013502; Mon, 8 Aug 2022 10:57:45 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Mon, 8 Aug 2022 10:57:45 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Matthew Wilcox 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 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, 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()? There is also this (where the BUG_ON(!buffer_uptodate(bh)) saves it). if (buffer_locked(bh)) { 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