From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85451C00140 for ; Mon, 8 Aug 2022 14:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243608AbiHHO02 (ORCPT ); Mon, 8 Aug 2022 10:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243247AbiHHO0V (ORCPT ); Mon, 8 Aug 2022 10:26:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6C0AA11A31 for ; Mon, 8 Aug 2022 07:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659968779; 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=C6qFvGy4HT+baIVkoLM8gIUhFv7ZzYgakTyFaHG2mz4=; b=QcijYdxKOa1j2yU+t/4Uwu9X/RCXb/rkI0OpFQ/qL9kz/DyEPw2bu+MCuMP+6WxgEfPXq9 JoVCYG/INt/dktrzeGxIvnPd59dxcmiC2kO1/9HgWYodV6uxg44h/GKjI/ARrsFaADzTMh 7pb44jFJv1tvXW4i4THGh0XtKOUKIGU= 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-422-kHp-W3CyNoWdE_-XTSVRpA-1; Mon, 08 Aug 2022 10:26:15 -0400 X-MC-Unique: kHp-W3CyNoWdE_-XTSVRpA-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 A3D84821907; Mon, 8 Aug 2022 14:26:12 +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 3A6A61121315; Mon, 8 Aug 2022 14:26:12 +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 278EQCjL012350; Mon, 8 Aug 2022 10:26:12 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 278EQAPT012346; Mon, 8 Aug 2022 10:26:11 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Mon, 8 Aug 2022 10:26:10 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 7 Aug 2022, Matthew Wilcox wrote: > 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; Yes, it may be nicer. > > +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 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 Mikulas