Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp971257iob; Fri, 13 May 2022 18:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3unsO7kMchlrdlcgp5ZLjPa+1ObQ+IMSpqMPBuqVwDSHpt010kfAoneRqeJD0jWliU0dz X-Received: by 2002:a5d:554a:0:b0:20a:d511:c514 with SMTP id g10-20020a5d554a000000b0020ad511c514mr5846383wrw.347.1652490498410; Fri, 13 May 2022 18:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652490498; cv=none; d=google.com; s=arc-20160816; b=Y00ro7OVv3Jy0m7AMwI8fYv8ql3ac4ni9A7WPojv3VhprDl3KAk2Jtf0o7j+TSZjxH f+4H7+7oW39TMScxpnSKSe5zervimKtM8HlGGiKeXp8Wxw/v4KxqWmLpDLPZgqPVxSng VBuMVz+Ymm+4oaZ9AzJ7jV709S65lsm0dPUPF9CkcJrfAfQwp8dLPk64i89s9JeUFkPN Iis1c43i084zV3TsfE/vUH2ffXTRiLLOp58eNtW78tBlHm6P7YjxxiKf2tZLZh61Wws+ 150Ob7LisoM2ih0VvzfSZ0etm3qzsL+oZ/tBUwyG2Q45telSYxo1h8B4eYBI9j7Co3nx bWfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=SetkBEDOZiUShCsn4xR4YJMw8sgALqWN66IN427Fvsw=; b=qjMgZSta5cE7KkkL5YGgccGDTWXqEV2bWFIbrQ8uOYqTIHj5/kfxrUngX3QSI9qLwZ 3CNggY3J3I15yBAjMeKWZDuWUUwjRdlmEZr555te6sypNii7BwDySaJ+hpJnBwTp6/NI M/jftjqmaHRHsQnC3Q+TTjHqG+JNTKOfPuRkrcOq9c65GvIp+5aJ52zClDT1rnhrWK+P EjAoQSV42jRT0EvO9DSc/PtZWuU5g7+g1wFIVbcvba1LKWFezxZAx7wH0dy9kOSOrWaI D8Yr0g+U4JNwBSzhpNk0fAIfEm48s/WpU9+y+FiuW9oF79kbEgvfADyqHLC3RVB6WXPe YhtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fOjNoVb2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i2-20020adfb642000000b0020c6912683bsi3296793wre.303.2022.05.13.18.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:08:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fOjNoVb2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8F78386C59; Fri, 13 May 2022 16:40:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352175AbiELXKi (ORCPT + 99 others); Thu, 12 May 2022 19:10:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343976AbiELXKg (ORCPT ); Thu, 12 May 2022 19:10:36 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB57D1FCC7; Thu, 12 May 2022 16:10:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 267E4CE2A77; Thu, 12 May 2022 23:10:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75B61C385B8; Thu, 12 May 2022 23:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652397031; bh=AOiw8wF4PdvBa3YU1oidYvIy6PmC88xLHJ48WAyDw/g=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=fOjNoVb2DXO/8uT9kYs+2duTISnPYmvsKGh1NfBbeYk8RoEHe2vPQ4I2faPjYGWZ6 GhU6GCNVWXgCqIzCdsDqL1dcNFYqrSJUnFvAmJAIpzZYLTYolsTMC5/zt0SOi5YJs3 d1/tOilo94RhD9qzHPZLq/8r99XYbyVoa6P6ZfDN/G26PCjjp+gPBBaude5RJEhAQF s7VmBmNdeKhfgXu2M7Gk829iXDp8N5U5Nh8qIRw0G8NIw/R0QLqEyobvR00yAEZGLp mtue47JeO3OBaocT/qfyB0Y5/YBj+0OmnO3V1P/diGGr4IQDqFh0fRY+d7OrQ3J8Uf CFkoxRfGXu/Ag== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 1635E5C051B; Thu, 12 May 2022 16:10:31 -0700 (PDT) Date: Thu, 12 May 2022 16:10:31 -0700 From: "Paul E. McKenney" To: Eric Dumazet Cc: Marco Elver , Liu Jian , Dmitry Vyukov , LKML , David Miller , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Paolo Abeni , Neal Cardwell , netdev Subject: Re: [PATCH net] tcp: Add READ_ONCE() to read tcp_orphan_count Message-ID: <20220512231031.GT1790663@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220512103322.380405-1-liujian56@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 12, 2022 at 02:31:48PM -0700, Eric Dumazet wrote: > On Thu, May 12, 2022 at 2:18 PM Marco Elver wrote: > > > > > I guess the question is, is it the norm that per_cpu() retrieves data > > that can legally be modified concurrently, or not. If not, and in most > > cases it's a bug, the annotations should be here. > > > > Paul, was there any guidance/documentation on this, but I fail to find > > it right now? (access-marking.txt doesn't say much about per-CPU > > data.) > > Normally, whenever we add a READ_ONCE(), we are supposed to add a comment. I am starting to think that comments are even more necessary for unmarked accesses to shared variables, with the comments setting out why the compiler cannot mess things up. ;-) > We could make an exception for per_cpu_once(), because the comment > would be centralized > at per_cpu_once() definition. This makes a lot of sense to me. > We will be stuck with READ_ONCE() in places we are using > per_cpu_ptr(), for example > in dev_fetch_sw_netstats() If this is strictly statistics, data_race() is another possibility. But it does not constrain the compiler at all. Thanx, Paul > diff --git a/net/core/dev.c b/net/core/dev.c > index 1461c2d9dec8099a9a2d43a704b4c6cb0375f480..b66470291d7b7e6c33161093d71e40587f9ed838 > 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -10381,10 +10381,13 @@ void dev_fetch_sw_netstats(struct > rtnl_link_stats64 *s, > stats = per_cpu_ptr(netstats, cpu); > do { > start = u64_stats_fetch_begin_irq(&stats->syncp); > - tmp.rx_packets = stats->rx_packets; > - tmp.rx_bytes = stats->rx_bytes; > - tmp.tx_packets = stats->tx_packets; > - tmp.tx_bytes = stats->tx_bytes; > + /* These values can change under us. > + * READ_ONCE() pair with too many write sides... > + */ > + tmp.rx_packets = READ_ONCE(stats->rx_packets); > + tmp.rx_bytes = READ_ONCE(stats->rx_bytes); > + tmp.tx_packets = READ_ONCE(stats->tx_packets); > + tmp.tx_bytes = READ_ONCE(stats->tx_bytes); > } while (u64_stats_fetch_retry_irq(&stats->syncp, start)); > > s->rx_packets += tmp.rx_packets;