Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1739868imn; Sun, 31 Jul 2022 20:33:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR4u1d3r4JsXYRRNLi4uCjDlyhJXlCpAiM8XkPvKYQIkoDj5rb41bpsjr6pwX2JNQMfs7J5p X-Received: by 2002:aa7:d283:0:b0:43d:8f56:f388 with SMTP id w3-20020aa7d283000000b0043d8f56f388mr4446042edq.53.1659324830088; Sun, 31 Jul 2022 20:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659324830; cv=none; d=google.com; s=arc-20160816; b=rr6DhuyM73UFgMwComibzhY+t3x3npGSROFVBJ3I7bz6hv66mQCon/GDXbLB9X5Lh3 cTeMXjdDyBvp6OY3sJQ6fFpJKZTZ59vaMpKvcAtKLrR9u+ttjRwlQHpRsthlj6RvIwtd JckNrQzkeCVEKex9VNIOACzQpyX7Ns/IdKKZ7C/arMbOGf8kyR2gFcgjGsvNCY7ZRQk7 5i1c1eKuIpruocEAU/jyqrpEBYJtpf9Lg3M031fwpr9YVBn26yoMmx/GOXNaVfvszAUH 2wmg9hkMlNDP/xs715kfvUeV7O6owusuLobd1tDuQhw9Tm9BdYZ0HIiLEkbBHM8Uu0m8 1avQ== 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=ArDKGW7/fiB1HuDmFbaiE7OJ0tkw3Cx8Pc289FPLnJA=; b=kFR9PTrqTjP+L3RmgLB4LUf1OSe0rOT4ByM7/ncqeECW0Wdv6A1vwn3LKQC4tkcj1o RznUOMW9yIPPTk+st+LMX7eeqkCVyjGd4aHL/igIgXIiSWtactAkvlvLLvE4/xJ+Whte dg2Ht/M3FyHY2Y86JtD3drWfUoUh4Scjfh9ww9jK//cjhbW8XXtwwNdABXU3VkEHw24Y ca1Lv0WlrCp8tR86BQ0h3Q/1oXeBWeRJzLC/fLCDAml26czJB2HsugUcn5jydnNdr8Em XsKHLPIouI8bmWzvFJm3sIgwiDPstAKfha+bo8L54n27ZeublyMKNP5cX+4z25x+UGrv MFsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nsrKs+ys; 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 z6-20020a17090665c600b0072af12dbfafsi7830670ejn.941.2022.07.31.20.33.24; Sun, 31 Jul 2022 20:33:50 -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=nsrKs+ys; 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 S239609AbiHADU6 (ORCPT + 99 others); Sun, 31 Jul 2022 23:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239521AbiHADUu (ORCPT ); Sun, 31 Jul 2022 23:20:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A3F6451; Sun, 31 Jul 2022 20:20:46 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 47EC460FF8; Mon, 1 Aug 2022 03:20:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A45A2C433C1; Mon, 1 Aug 2022 03:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659324045; bh=XcVtSPHVyz9TCIWPL/CT3cYLdvOGA6J9UpEZKi9CB1A=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=nsrKs+ys2S25dcwsjC8ako9YHKLFBcjGWqrL2ZwsOgq3SUCdyq9E3FBS5biNuOxlz d6/BclXitukK1K/SsGd3InWgEeSPbe2F8ldOkx12ijVHPe7YxCvivh2hxiJ6uDKklN VmUzder6K/DS2y+dv93Jsjl2eGtUu7F7w/Y/w8pIBFY1I/yyDTADnP900YnDi/kN3J lrlxCYEDS+cdW8CPjeIOK7LzbohoYIE44FJxlK76isCIxDruJlOFxxdFH9KUtHKS4I yH+Htssn8Rvh9+0NqzKHFpcEIHOci29ys7B586tQxjUcN0p/VE9NLqEtO7/yezQ9NV ZTxYslP/bHiUQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 433805C03E0; Sun, 31 Jul 2022 20:20:45 -0700 (PDT) Date: Sun, 31 Jul 2022 20:20:45 -0700 From: "Paul E. McKenney" To: Matthew Wilcox Cc: Linus Torvalds , Mikulas Patocka , 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 v2] make buffer_locked provide an acquire semantics Message-ID: <20220801032045.GZ2860372@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220731173011.GX2860372@paulmck-ThinkPad-P17-Gen-1> 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 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, Jul 31, 2022 at 11:48:32PM +0100, Matthew Wilcox wrote: > On Sun, Jul 31, 2022 at 10:30:11AM -0700, Paul E. McKenney wrote: > > That said, I confess that I am having a hard time finding the > > buffer_locked() definition. So if buffer_locked() uses normal C-language > > accesses to sample the BH_Lock bit of the ->b_state field, then yes, > > there could be a problem. The compiler would then be free to reorder > > calls to buffer_locked() because it could then assume that no other > > thread was touching that ->b_state field. > > You're having a hard time finding it because it's constructed with the C > preprocessor. I really wish we generated header files using CPP once > and then included the generated/ file. That would make them greppable. > > You're looking for include/linux/buffer_head.h and it's done like this: > > enum bh_state_bits { > ... > BH_Lock, /* Is locked */ > ... > > #define BUFFER_FNS(bit, name) \ > ... > static __always_inline int buffer_##name(const struct buffer_head *bh) \ > { \ > return test_bit(BH_##bit, &(bh)->b_state); \ > } > > BUFFER_FNS(Lock, locked) > > (fwiw, the page/folio versions of these functions don't autogenerate > the lock or uptodate ones because they need extra functions called) Thank you! Another thing that would have helped me find it would have been to leave the "BH_" prefix on the bit name in the BUFFER_FNS() invocation, as in ditch the "BH_##" in the definition and then just say "BUFFER_FNS(BH_Lock, locked)". But what is life without a challenge? ;-/ Anyway, on x86 this will use the constant_test_bit() function, which uses a volatile declaration for its parameter. So it should avoid vulnerability to the vicissitudes of the compiler. So I feel much better now. Thanx, Paul