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 F29BBC00140 for ; Mon, 1 Aug 2022 03:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239621AbiHADVA (ORCPT ); Sun, 31 Jul 2022 23:21:00 -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: 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