[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200126182917.GA26911@amd>
Date: Sun, 26 Jan 2020 19:29:18 +0100
From: Pavel Machek <pavel@...x.de>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-kernel@...r.kernel.org, stable@...r.kernel.org,
Eric Dumazet <edumazet@...gle.com>,
Willem de Bruijn <willemb@...gle.com>,
"David S. Miller" <davem@...emloft.net>,
Sasha Levin <sashal@...nel.org>
Subject: Re: [PATCH 4.19 625/639] packet: fix data-race in
fanout_flow_is_huge()
Hi!
> From: Eric Dumazet <edumazet@...gle.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
Download attachment "signature.asc" of type "application/pgp-signature" (182 bytes)
Powered by blists - more mailing lists