Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4216643pxf; Tue, 16 Mar 2021 08:14:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyp7W4x67Vj0iar5gyZgPCVQltT740y9HtKN5YDpvtx8+kQevM5Xm+bTyll4ijkwQiYzYtk X-Received: by 2002:a17:906:3f87:: with SMTP id b7mr30078343ejj.139.1615907698255; Tue, 16 Mar 2021 08:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615907698; cv=none; d=google.com; s=arc-20160816; b=AmG7q/KgxGaxzhlA1tbnIhv9m/XwefqlI33cfREYs0s3H+XTkKSZs+OvR/CMOFdGzU mQvfF6BMt2fO64p0kZIUthz7v6WaZ2Vma1S3BaLQHmUlCAnofskaV8ykFX+gJclVPxFn tFy+V2ztk8dyqSGRsTC4oodeOpknHkUaiXhzO8wFLhr9bOccY+5y5Hzr+n2WOK3c59lO 8BH1NQRhcTdQOtoDzG4rXOM/2Q3imBKDmdArh04Yyfg9Fg33q00+AEnWIAgyMhvOCYwl hX0fViyo8TLFmm2FUqFr2Es8IXJlB81pJGgJc64JQ6ghtaeg6ypVfGIi+ACLjXomVfTI KGGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ilMh0R6tKJfAAGhsCUQRj/IYkqWliqo3MqAgBjAm0SA=; b=n5kGNVfBQQYt2TGb3CQreisxNBb2hRXMEeqqjimX635N7sUhkXdI2nVUf/fyp+HGKi tHgKqcEJ6dGC59P7aAhT8nDuzWeQNTO35mQODoZgWqdNtzIDyXMYOcZ6NmUMaYrlWiio IJL8LvXm3YEuKDdEsAq9De1oFhYZFUvxT039B67E5D6wR1if54m0L8DN3cEFpTx7ogMU coOk3pP8vG65MBJbqFHf2XA7Uw4Oj1sA0/rbbNZzZnA+pPYad2jpZdB+UMFeoxsgnkGL tj/0TXMCnFvACbyF3FcEIiWomtCYIySR9c9xxjOCpYKQ5c+XyTgMHnlNOgmav7kovOsh QZcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k12si14389549edq.82.2021.03.16.08.14.35; Tue, 16 Mar 2021 08:14:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235467AbhCPJvP (ORCPT + 99 others); Tue, 16 Mar 2021 05:51:15 -0400 Received: from jabberwock.ucw.cz ([46.255.230.98]:52956 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236330AbhCPJuw (ORCPT ); Tue, 16 Mar 2021 05:50:52 -0400 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 446261C0B8B; Tue, 16 Mar 2021 10:50:50 +0100 (CET) Date: Tue, 16 Mar 2021 10:50:49 +0100 From: Pavel Machek To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Eric Dumazet , "David S. Miller" Subject: Re: [PATCH 4.19 012/120] tcp: annotate tp->write_seq lockless reads Message-ID: <20210316095049.GB12946@amd> References: <20210315135720.002213995@linuxfoundation.org> <20210315135720.418426545@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="4SFOXa2GPu3tIq4H" Content-Disposition: inline In-Reply-To: <20210315135720.418426545@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --4SFOXa2GPu3tIq4H Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Greg Kroah-Hartman >=20 > From: Eric Dumazet Dup. > We need to add READ_ONCE() annotations, and also make > sure write sides use corresponding WRITE_ONCE() to avoid > store-tearing. > @@ -1037,7 +1037,7 @@ new_segment: > sk->sk_wmem_queued +=3D copy; > sk_mem_charge(sk, copy); > skb->ip_summed =3D CHECKSUM_PARTIAL; > - tp->write_seq +=3D copy; > + WRITE_ONCE(tp->write_seq, tp->write_seq + copy); > TCP_SKB_CB(skb)->end_seq +=3D copy; > tcp_skb_pcount_set(skb, 0); > I wonder if this needs to do READ_ONCE, too? > @@ -1391,7 +1391,7 @@ new_segment: > if (!copied) > TCP_SKB_CB(skb)->tcp_flags &=3D ~TCPHDR_PSH; > =20 > - tp->write_seq +=3D copy; > + WRITE_ONCE(tp->write_seq, tp->write_seq + copy); > TCP_SKB_CB(skb)->end_seq +=3D copy; > tcp_skb_pcount_set(skb, 0); > And here. > @@ -2593,9 +2594,12 @@ int tcp_disconnect(struct sock *sk, int > sock_reset_flag(sk, SOCK_DONE); > tp->srtt_us =3D 0; > tp->rcv_rtt_last_tsecr =3D 0; > - tp->write_seq +=3D tp->max_window + 2; > - if (tp->write_seq =3D=3D 0) > - tp->write_seq =3D 1; > + > + seq =3D tp->write_seq + tp->max_window + 2; > + if (!seq) > + seq =3D 1; > + WRITE_ONCE(tp->write_seq, seq); And here. > --- a/net/ipv4/tcp_minisocks.c > +++ b/net/ipv4/tcp_minisocks.c > @@ -510,7 +510,7 @@ struct sock *tcp_create_openreq_child(co > newtp->app_limited =3D ~0U; > =20 > tcp_init_xmit_timers(newsk); > - newtp->write_seq =3D newtp->pushed_seq =3D treq->snt_isn + 1; > + WRITE_ONCE(newtp->write_seq, newtp->pushed_seq =3D treq->snt_isn + 1); Would it be better to do assignment to pushed_seq outside of WRITE_ONCE macro? This is ... "interesting". Best regards, Pavel --=20 DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany --4SFOXa2GPu3tIq4H Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAmBQf3kACgkQMOfwapXb+vKgIwCdHCjqPEK7PmDmmfIAd0twUUWA AhsAoIJipW/LvtuR27NuwI01WjMYOpGO =8Gfw -----END PGP SIGNATURE----- --4SFOXa2GPu3tIq4H--