From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25052C35247 for ; Sun, 26 Jan 2020 18:29:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF85220716 for ; Sun, 26 Jan 2020 18:29:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728809AbgAZS3b (ORCPT ); Sun, 26 Jan 2020 13:29:31 -0500 Received: from jabberwock.ucw.cz ([46.255.230.98]:49498 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbgAZS3b (ORCPT ); Sun, 26 Jan 2020 13:29:31 -0500 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 309901C013C; Sun, 26 Jan 2020 19:29:29 +0100 (CET) Date: Sun, 26 Jan 2020 19:29:18 +0100 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Eric Dumazet , Willem de Bruijn , "David S. Miller" , Sasha Levin Subject: Re: [PATCH 4.19 625/639] packet: fix data-race in fanout_flow_is_huge() Message-ID: <20200126182917.GA26911@amd> References: <20200124093047.008739095@linuxfoundation.org> <20200124093207.912523612@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline In-Reply-To: <20200124093207.912523612@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Eric Dumazet >=20 > [ Upstream commit b756ad928d98e5ef0b74af7546a6a31a8dadde00 ] >=20 > KCSAN reported the following data-race [1] >=20 > Adding a couple of READ_ONCE()/WRITE_ONCE() should silence it. >=20 > 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 =3D po->rollover->history; > + u32 victim, rxhash; > int i, count =3D 0; > =20 > rxhash =3D skb_get_hash(skb); > for (i =3D 0; i < ROLLOVER_HLEN; i++) > - if (po->rollover->history[i] =3D=3D rxhash) > + if (READ_ONCE(history[i]) =3D=3D rxhash) > count++; > =20 > - po->rollover->history[prandom_u32() % ROLLOVER_HLEN] =3D rxhash; > + victim =3D prandom_u32() % ROLLOVER_HLEN; > + > + /* Avoid dirtying the cache line if possible */ > + if (READ_ONCE(history[victim]) !=3D 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 --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --17pEHd4RhPHOinZp Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl4t2n0ACgkQMOfwapXb+vKWZACfXGUxeWdbOxPidKjzXNS5xqcf llUAmwZqpQqfdyEY953YC5qnZziTVQa/ =ckpY -----END PGP SIGNATURE----- --17pEHd4RhPHOinZp--