Re: [PATCH 4.19 625/639] packet: fix data-race in fanout_flow_is_huge()
From: Eric Dumazet
Date: Sun Jan 26 2020 - 13:38:56 EST
On Sun, Jan 26, 2020 at 10:29 AM Pavel Machek <pavel@xxxxxxx> wrote:
>
>
> > - po->rollover->history[prandom_u32() % ROLLOVER_HLEN] = rxhash;
> > + victim = prandom_u32() % ROLLOVER_HLEN;
> > +
> > + /* Avoid dirtying the cache line if possible */
> > + if (READ_ONCE(history[victim]) != rxhash)
> > + WRITE_ONCE(history[victim], rxhash);
> > +
>
> Replacing simple asignment with if() is ... not nice and with all the
> "volatile" magic in _ONCE macros may not be win for
> everyone. [Actually, I don't think this is win here. This is not
> exactly hot path, is it?
This is a critical hot path, eg under DDOS attack.
>
> If this is going to get more common, should we get
> WRITE_ONCE_NONDIRTY() macro hiding the uglyness?
>
Sure, but we do not add macros for stable patches, usually.
Honestly, WRITE_ONCE_NONDIRTY() looks ugly to me.
Note that the KCSAN race might be solved in another way when
data_race() is available.