Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4216645pxf; Tue, 16 Mar 2021 08:14:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIVUIQ64SHqent9oFqz3bQiOALpx1BxyFc94vjs0MKHjd1t5UCD4L+e714n2ki7//4e24x X-Received: by 2002:a05:6402:c96:: with SMTP id cm22mr37009307edb.128.1615907698410; 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=cw/4jVyebb+22vlJFNPOcsg3OO/QpZw/gHJH42gh5JfbE9Ny6D54a1hqVOuiilPKeA MxMiHT1VzpXyzEqzpUfZZNYB8wEdOB4uIf6Hng+QCbi1Zvk0By2pKE98uyTPzUeeDWGI 7poNvB9+m+aXik5Wzsme57nqantLGnRyYag8jmijRFz7MHut+B/b2FQuwKyGOrCe8wQY GLF603WSxqCv6HmKeA3Hc3QWdvqrVgep88X3nVvGppqEgLq4BKcMBcd6liBhIwp+LK4n G8CHKLa1iFJD10MH3PzTkK091JleETyCl1RbWX3GCDH9qIRE35dmkGQ+QAa1zXBvKyfX +LPg== 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=CEiUqhCHKWemSRXXRMGc1PRoqQAnoH+WZsZjki4JAqI=; b=nl2MVLDrNRZ8t3z6XDyjjAzHEMQkR983Z7qtd3rTP91Ah6oy2DGM7RUAWSY+XxeYH6 B//qRBCfuSKON6p9h5bVPiibxIjIMkrOlNsiUOl/F6ftSIT6MCFfF1D7Sb3PKBj3virZ 7A9I39LWFrQGxCcZcMo0Ff1vehkmbGsRvIjS+TcD5RWVGx6Pohv5iszjHrgv/JKXFHKH fgDSG/QcA+0BDud/lHlYszaVW6yQMrI7YiAC6VexnR6cRyxOwJA7Nrg70jD2sNWqH56i 5wdXS3vTt5g0R/TJVSTpg2S4fzLYAahkBprgYAU4upwE6QQPyqzcsWCaIT0Ddd+L0cat Xc6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="NHK/rhQx"; 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 j12si13879111edp.565.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; dkim=pass header.i=@google.com header.s=20161025 header.b="NHK/rhQx"; 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 S235556AbhCPJtj (ORCPT + 99 others); Tue, 16 Mar 2021 05:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235638AbhCPJtg (ORCPT ); Tue, 16 Mar 2021 05:49:36 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35A46C06174A for ; Tue, 16 Mar 2021 02:49:26 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id f145so19746325ybg.11 for ; Tue, 16 Mar 2021 02:49:26 -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=CEiUqhCHKWemSRXXRMGc1PRoqQAnoH+WZsZjki4JAqI=; b=NHK/rhQxZ/cljjp3wVFPcva9hjHqNJiZA5dHjILVBL3+C/kw6Z7VDlGY4bcIqPQoXm rAB0M6L47b7z22HazZ/jsZg1Ptl/K4W+AGnhzEg2tEDnV/tEq15hrTJhkPeFnzG+M8o+ TM2C5x3ki58OT0QtmUV6Wu/IYIR/w2ipokYjBOuGet3djfoooZEvyGuj+CM0Xf39BH+w 67dveel6DQSfZyNmmdnfXZgJuYUp5YTjDPDQ+NCXt8pHYHDp+mJOFX7kFVM9JhHHHmpx hZpK0tSfhiL0WaH6d0YOS2EjW0jtzNPnDmbq01wDRTu/WBvER0iz1usEGBStPUyO0nAp u1/Q== 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=CEiUqhCHKWemSRXXRMGc1PRoqQAnoH+WZsZjki4JAqI=; b=dxZGo6Q3aHLv3laxP9ihOncDshhjvihi48CquhTIuNySVmLv1Xejwli32hHIR0BNkO wonkHMXDCDNpgExa1xP/2CnP3GEEZy5C876iD4wrkMOwZkemKubRY2LbCPVsO1aXUGW4 spwdmkJHYFvfKOJlYdmxXxGFIngvV4/NFXxNNdj5tjar6cIEOkLmQUD6Son2OCbTJXjH 7SIG6mRUSRSLNy8RbUfNK2oVWTvr45B7EoeM0UxlAaqT7H/Dljz3wu2nEEC6vGSCoXLG Zxa4GxN05MpY6VfIAzn8Buqlq8ouFOofTldd5V/EKIxodf/mUNBeBIYiLwBsTMkUJdOh 7fzA== X-Gm-Message-State: AOAM532vmE/n2xQwwasOioMFw1SupPQw/U8KmSDkrzjPIwkm5joV/kJH aaWZfOLXF2M8/ynAncSyIsiinhgtyWhNVvvcQzlB/uxFcTbiKQ== X-Received: by 2002:a25:2307:: with SMTP id j7mr5810152ybj.518.1615888165108; Tue, 16 Mar 2021 02:49:25 -0700 (PDT) MIME-Version: 1.0 References: <20210315135720.002213995@linuxfoundation.org> <20210315135720.384809636@linuxfoundation.org> <20210316094137.GA12946@amd> In-Reply-To: <20210316094137.GA12946@amd> From: Eric Dumazet Date: Tue, 16 Mar 2021 10:49:13 +0100 Message-ID: Subject: Re: [PATCH 4.19 011/120] tcp: annotate tp->copied_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:41 AM Pavel Machek wrote: > > Hi! > > > From: Greg Kroah-Hartman > > > > From: Eric Dumazet > > Two From: fields here. > > > [ Upstream commit 7db48e983930285b765743ebd665aecf9850582b ] > > > > There are few places where we fetch tp->copied_seq while > > this field can change from IRQ or other cpu. > > And there are few such places even after the patch is applied; I > quoted them below. > > Doing addition to variable without locking... is kind of > interesting. Are you sure it is okay? We are holding the socket lock here. The WRITE_ONCE() here is paired with sides doing READ_ONCE() while socket lock is _not_ held. We want to make sure compiler won't write into this variable one byte at a time, or using stupid things. > > > @@ -2112,7 +2112,7 @@ int tcp_recvmsg(struct sock *sk, struct > > if (urg_offset < used) { > > if (!urg_offset) { > > if (!sock_flag(sk, SOCK_URGINLINE)) { > > - ++*seq; > > + WRITE_ONCE(*seq, *seq + 1); > > urg_hole++; > > offset++; > > used--; > > @@ -2134,7 +2134,7 @@ int tcp_recvmsg(struct sock *sk, struct > > } > > } > > > > - *seq += used; > > + WRITE_ONCE(*seq, *seq + used); > > copied += used; > > len -= used; > > > > @@ -2163,7 +2163,7 @@ skip_copy: > > > > found_fin_ok: > > /* Process the FIN. */ > > - ++*seq; > > + WRITE_ONCE(*seq, *seq + 1); > > if (!(flags & MSG_PEEK)) > > sk_eat_skb(sk, skb); > > break; > > Best regards, > Pavel > -- > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany