Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4217200pxf; Tue, 16 Mar 2021 08:15:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6XTwLRda4x7m7z5emJbuKbsBcKMIGt+b2zfwigclUY8h1JhF6OruaMwdE4SDl6sf8CJOV X-Received: by 2002:a17:906:1b42:: with SMTP id p2mr30232673ejg.236.1615907733957; Tue, 16 Mar 2021 08:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615907733; cv=none; d=google.com; s=arc-20160816; b=NNuy4LqfoxzI0IVJoQytOO4SqvB4FV1OxkaC0EryjWytGyvYby2K6PL8X5essl/eWN Fce2usT+I76qefncXEC0yx8yTTAZVSK2plSa2myMksw6+6gbAoRwTYgUjslY+NKJ9aU1 ktiKIUX0J2WB2NpKpd5uUX3mGglG7sP3rPp+SRcPzlZCLP7errlK9NJ3Z0de/lsiERCk WzbfURl15q0VsPzHocQh3qUnb1GH0bsJZ8Gg3YdXLa/5DPHJes0AK20y0LW5ANT0JR01 FvMt79/ASkA6le5cIKelq6/hvLpyq8Bjt8Htn0HTaP1xdjh0hnRVPdUv5ZYD3c/ZdEo8 XLKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kfVxFqytKWqvy1UjxUsD9Fb71TDdqI2Pc9nXwmKc2jg=; b=TjLPgs/6Bo6zFIC2eu6aKiswPMveqAXOPEn0CMTgiG+TZmOqSbHUVM909SAf+GAfNk V9mqnRmqxDyfrn/qaMJ7mo1Yz0qdi8e8Jj6RZsNVcSxZkU1BZB5bE0/gQjOS+Pcs9g+i E+Ppo+68v5mDi0vqCbbU4pEax/iBcPjRIDdyHgOntsJ93zGCFRNhKYJdsiyrO1Tnh44E 6XD7WK77fwdQniEESINZRztdONO3q6PU5Rvr1+Zn4z0CzbS5QMYTCa4FpDn7PhDb+Mg7 ARY/T2RaWIXMRSpBy1eIbjzbYVq4Slb36CRGLoOE17ViRlBepMHYsl0h61qjZ5HXWkik 9i1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IAS6QbnN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si14652239ejb.608.2021.03.16.08.15.11; Tue, 16 Mar 2021 08:15:33 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=IAS6QbnN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236347AbhCPJwv (ORCPT + 99 others); Tue, 16 Mar 2021 05:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236391AbhCPJwt (ORCPT ); Tue, 16 Mar 2021 05:52:49 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11C9EC061756 for ; Tue, 16 Mar 2021 02:52:49 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id n195so36142481ybg.9 for ; Tue, 16 Mar 2021 02:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kfVxFqytKWqvy1UjxUsD9Fb71TDdqI2Pc9nXwmKc2jg=; b=IAS6QbnNjP8iASJwity5wb7YMdd9LHdCP+PF/HGFeaggwz8Vc4Kpjiagtj65EAZx/l NgmtvZP4uP+70kuOwG9xMuov9gZP2ebqZzNf5GfJ4iw2u+rDg4yzHh26zxjpP9UP8u7m iTH7tynS/iz3fTu5rjEroN41odvl9hNn4u8MLY4WCYnHkkDATct81RhE7W45CsLiPxSj YX7LY/cmdixq/xI52h/mY+H39p4SImYZP9Xlq5FRDuAwr9IsKKd2CJttwkU5AYF6eanF bOakjn/NbSCEVfzoXRSJgZMWJ5Aqir0Nf96/5aluSTR24QruxXpfVS9VGjvMSL3cb/6E AEQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kfVxFqytKWqvy1UjxUsD9Fb71TDdqI2Pc9nXwmKc2jg=; b=KNm6Jbx72HoWu55VEWbt2cNCdu0tKgd/aYQauRreX36WAjgRBnex7uppOOxrj0bRXc bGeQWlNdidMlRpXys0FP9bFtwhoUajHY0cWHdYc0dVcJuXhti7JiHRgD2Ni/rDuNQ/Cq Oz2p4vIRshpiAAtT8miFicQWLTCanRqeGEirsARYOAXRj7TSN4Go1o2gqXAGut8JjEaE dZhy6ngtB2DDqmdNxeYZeuUw77I3Wp4aTbFAX3jEEjOAfzNSi565qzJVh0nhFFi6hH+T JXJP0I/u4JR6dLHRgY6MsQvcbhZD1TaXlmJupVty0l4M9SGbScwppweNe66EgkHAxIVg ZeKA== X-Gm-Message-State: AOAM530s+ZgWdtLXPWLZiOmc82dXu0mOvUmF+dSYmyuxbkf2sE9pKX4A M7ufRW1dSw9HIVMCNZnuN7Ihphw1kXhIL0+gIaZy3g== X-Received: by 2002:a25:ac52:: with SMTP id r18mr5626572ybd.303.1615888367899; Tue, 16 Mar 2021 02:52:47 -0700 (PDT) MIME-Version: 1.0 References: <20210315135720.002213995@linuxfoundation.org> <20210315135720.418426545@linuxfoundation.org> <20210316095049.GB12946@amd> In-Reply-To: <20210316095049.GB12946@amd> From: Eric Dumazet Date: Tue, 16 Mar 2021 10:52:36 +0100 Message-ID: Subject: Re: [PATCH 4.19 012/120] tcp: annotate tp->write_seq lockless reads To: Pavel Machek Cc: Greg Kroah-Hartman , LKML , stable@vger.kernel.org, "David S. Miller" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021 at 10:50 AM Pavel Machek wrote: > > Hi! > > > From: Greg Kroah-Hartman > > > > 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 += copy; > > sk_mem_charge(sk, copy); > > skb->ip_summed = CHECKSUM_PARTIAL; > > - tp->write_seq += copy; > > + WRITE_ONCE(tp->write_seq, tp->write_seq + copy); > > TCP_SKB_CB(skb)->end_seq += copy; > > tcp_skb_pcount_set(skb, 0); > > > > I wonder if this needs to do READ_ONCE, too? No, because we hold the socket lock. This is a backport to ease another backport, please try to review patches when they hit mainline, if you have any concerns. > > > @@ -1391,7 +1391,7 @@ new_segment: > > if (!copied) > > TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH; > > > > - tp->write_seq += copy; > > + WRITE_ONCE(tp->write_seq, tp->write_seq + copy); > > TCP_SKB_CB(skb)->end_seq += 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 = 0; > > tp->rcv_rtt_last_tsecr = 0; > > - tp->write_seq += tp->max_window + 2; > > - if (tp->write_seq == 0) > > - tp->write_seq = 1; > > + > > + seq = tp->write_seq + tp->max_window + 2; > > + if (!seq) > > + seq = 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 = ~0U; > > > > tcp_init_xmit_timers(newsk); > > - newtp->write_seq = newtp->pushed_seq = treq->snt_isn + 1; > > + WRITE_ONCE(newtp->write_seq, newtp->pushed_seq = 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 > -- > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany