lkml.org 
[lkml]   [2020]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 4.19 625/639] packet: fix data-race in fanout_flow_is_huge()
Hi!

> From: Eric Dumazet <edumazet@google.com>
>
> [ Upstream commit b756ad928d98e5ef0b74af7546a6a31a8dadde00 ]
>
> KCSAN reported the following data-race [1]
>
> Adding a couple of READ_ONCE()/WRITE_ONCE() should silence it.
>
> Since the report hinted about multiple cpus using the history
> concurrently, I added a test avoiding writing on it if the
> victim slot already contains the desired value.

> static bool fanout_flow_is_huge(struct packet_sock *po, struct sk_buff *skb)
> {
> - u32 rxhash;
> + u32 *history = po->rollover->history;
> + u32 victim, rxhash;
> int i, count = 0;
>
> rxhash = skb_get_hash(skb);
> for (i = 0; i < ROLLOVER_HLEN; i++)
> - if (po->rollover->history[i] == rxhash)
> + if (READ_ONCE(history[i]) == rxhash)
> count++;
>
> - 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? Is it likely that array aready contains
required value?]

If this is going to get more common, should we get
WRITE_ONCE_NONDIRTY() macro hiding the uglyness?

Best regards,
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2020-01-26 19:30    [W:1.732 / U:0.728 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site