Re: [PATCH next v2 2/3] printk: change @clear_seq to atomic64_t
From: Peter Zijlstra
Date: Wed Dec 09 2020 - 03:08:57 EST
On Wed, Dec 09, 2020 at 05:34:19AM +0900, Sergey Senozhatsky wrote:
> On (20/12/04 10:12), Petr Mladek wrote:
> > On Tue 2020-12-01 21:59:40, John Ogness wrote:
> > > Currently @clear_seq access is protected by @logbuf_lock. Once
> > > @logbuf_lock is removed some other form of synchronization will be
> > > required. Change the type of @clear_seq to atomic64_t to provide the
> > > synchronization.
> > >
> > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > > index fc5e3a7d6d89..e9018c4e1b66 100644
> > > --- a/kernel/printk/printk.c
> > > +++ b/kernel/printk/printk.c
> > > @@ -3412,7 +3418,7 @@ EXPORT_SYMBOL_GPL(kmsg_dump_get_buffer);
> > > */
> > > void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
> > > {
> > > - dumper->cur_seq = clear_seq;
> > > + dumper->cur_seq = atomic64_read(&clear_seq);
> >
> > Sigh, atomic64_read() uses a spin lock in the generic implementation
> > that is used on some architectures.
>
> Oh... So on those archs prb is not lockless in fact, it actually
> takes the spin_lock each time we read the descriptor state?
Yeah, many 32bit archs cannot natively do 64bit atomics and get to use
the horrible hashed spinlock crap.
But it gets even worse, we have a few architectures that cannot do
atomics _at_all_ and _always_ use the horrible hashed spinlock crap for
all atomics, even native word length ones.
I consider these architectures broken crap, and they work mostly by
accident than anything else, but we have them :/ The good new is that
they don't have NMIs either, so that helps.