Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4821156rwb; Mon, 8 Aug 2022 07:34:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5sJ8j40WFQ8QuY2MTrHBzOBs7bLrtrKEqr/DOSXg47KryYIX69VqH04Y70sAi75FNv0p0k X-Received: by 2002:a05:6a00:986:b0:52d:8c68:7b4 with SMTP id u6-20020a056a00098600b0052d8c6807b4mr18692374pfg.35.1659969288548; Mon, 08 Aug 2022 07:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659969288; cv=none; d=google.com; s=arc-20160816; b=VaW22tJukLVzlZi/R/NT0OeXq6rVvjoz2RJ9n8xuG+mfwNOqgcbL5kCB1RLf02CdgB SMuH6oAjwIv/96jLKdOWuiOVqzZcWrBbMlR/7gaTmpr9RCFHMzG2Ewdmew040zvxouan kR+tQdrclehD5VPcGVPJ3g23a/pptbquBycCG8Dqgoe+tPQIgwKjbxUGUnjhx3bDLwYa GFqRtMeTxHHFSLEwAHemrrmS+CEEIgb1hWGVFL4j6MU3P37WWQhnuEbgODnKg5gfakTg cunqV2TSmZyB6mvtnYNt4qsMf4iDkVL14E3w+h49x6aeaKyGGRw54shhfBs3htqazpky yrxg== 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=C6qFvGy4HT+baIVkoLM8gIUhFv7ZzYgakTyFaHG2mz4=; b=NYrKG55wbT8eNlYhRZZrueJmkZ0+V1EsIzC94rY72i/XhTRPHzHHFsnB+fo+U8mcJQ 6ibUO/rlQYkMeeegsNoRW9ZTg6EkDov9TuB+XHPQD8IQQKzGBLd2NCOO1kkswQtgmvzc 69H7Sso2G0lasrNFAg9mSGnX0BZbUxlWbV8gBC6MfEBZyNLQc84+6QjJJB6XB/ZiyTYb P+X/cTstwfGe+/mfhS/cuvL29glNhywgNjPb6Z9KWg+KX63EjK62kYnji82OpfVonLA4 /4DP6peRT4Ey5dybtlmVVdJLopBKQlFNSd7Jc2ICGS8hJhwyYtglO3bUo98PGNJlM5ag g1LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QcijYdxK; 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 g5-20020a170902934500b0016ef87319e6si11336007plp.447.2022.08.08.07.34.33; Mon, 08 Aug 2022 07:34:48 -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=QcijYdxK; 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 S243591AbiHHO00 (ORCPT + 99 others); Mon, 8 Aug 2022 10:26:26 -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 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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, 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