[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220801032045.GZ2860372@paulmck-ThinkPad-P17-Gen-1>
Date: Sun, 31 Jul 2022 20:20:45 -0700
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Matthew Wilcox <willy@...radead.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Mikulas Patocka <mpatocka@...hat.com>,
Will Deacon <will@...nel.org>,
Ard Biesheuvel <ardb@...nel.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Alan Stern <stern@...land.harvard.edu>,
Andrea Parri <parri.andrea@...il.com>,
Peter Zijlstra <peterz@...radead.org>,
Boqun Feng <boqun.feng@...il.com>,
Nicholas Piggin <npiggin@...il.com>,
David Howells <dhowells@...hat.com>,
Jade Alglave <j.alglave@....ac.uk>,
Luc Maranget <luc.maranget@...ia.fr>,
Akira Yokosawa <akiyks@...il.com>,
Daniel Lustig <dlustig@...dia.com>,
Joel Fernandes <joel@...lfernandes.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-arch <linux-arch@...r.kernel.org>,
linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH v2] make buffer_locked provide an acquire semantics
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
Powered by blists - more mailing lists