Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation

From: Peter Zijlstra
Date: Wed Jun 26 2019 - 18:48:10 EST


On Fri, Jun 21, 2019 at 12:23:19AM +0200, John Ogness wrote:
> On 2019-06-18, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> >> +
> >> + if (unlikely(newest_id == EOL)) {
> >> + /* no previous newest means we *are* the list, set oldest */
> >> +
> >> + /*
> >> + * MB UNPAIRED
> >
> > That's a bug, MB must always be paired.
>
> Well, it "pairs" with the smp_rmb() of the readers, but I didn't think
> that counts as a pair. That's why I wrote unpaired. The litmus test is:
>
> P0(int *x, int *y)
> {
> WRITE_ONCE(*x, 1);
> smp_store_release(y, 1);
> }
>
> P1(int *x, int *y)
> {
> int rx;
> int ry;
>
> ry = READ_ONCE(*y);
> smp_rmb();
> rx = READ_ONCE(*x);
> }
>
> exists (1:rx=0 /\ 1:ry=1)
>
> The readers rely on the store_releases "pairing" with the smp_rmb() so
> that the readers see things in a sane order.

That is certainly a valid pairing, see also the 'SMP BARRIER PAIRING'
section in memory-barriers.txt (I thought we had a table in there, but
apparently that never quite made it in).