Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1049319iob; Fri, 13 May 2022 21:05:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKT9NpEUhHNbfYmSa7Rr38iXKFzxObleqLnsnIha2KmXDfo1LRxsGXNxMPL8A/Vbl4EL+a X-Received: by 2002:a5d:59af:0:b0:20c:52e9:6c49 with SMTP id p15-20020a5d59af000000b0020c52e96c49mr6279137wrr.319.1652501102572; Fri, 13 May 2022 21:05:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652501102; cv=none; d=google.com; s=arc-20160816; b=LeyIhgFbayytbiQL3Y8ZxmXrOFW8ybqwICojSe62hWMRilo6MjmVJRckOij9uUrUqK VkNKptO/DCZLPoCH7mmJQj+CPwiN3aiUwpNXqqOytS34TsOczp4JDVUZ0gdwvTPzZ/ZS UI5LD+ywUZ20bTOTpKoaw6MpHlI5WciXm2+Ip2Q1f6iU7YE/suSZrpcQ0VRWcYozRJDB wBCSzggSCCYD7+sDLkei77Idn92MhgL72Wi66N/I9iMP2euE+fB1RIQ/4XdOHcpBFhLE K4nQX+Noq+yv8b5mA2k6eHZmlJK9/C+14a4gJfXmgHo9XPadB2wrpgpkEkdNErP2hlcy Yovg== 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=7xSrUdnA1OiCjH5kvyp3iABoTsJX17lF1oCQIDPuInU=; b=XMoyQcxTm4Ze5CB50PQO9irj1oBLUrfGleCeipbcW4VeHHFJP63RhSufDuh+FhGYEj j4do8nyGrkftMDkGdRuomt+u+W5z/L5uFW2MSXWPh+IHCkxNs/jgIBTp9CDFgGdVKjgz lTEsxaycG5fbdd4t9q/4d9sND41qrhAgDMgt6E8OAiSSgjY7kh1mq/8Dlz7sakSuvTIS bz7Hl4Thh0rBcphgtlUsLFh81mOKplGTJRoMg/qiwWVJT3+47hIB9WUXxTMl6DLyb83x u8woZ2dXwkHWCmrr12isq9m49D8kf3FOgB2Stuem1J1nnkg6Gs8aQ1hLykpIZ0V7D/rx YHxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oJmTqas0; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o9-20020a5d47c9000000b0020606d7746bsi5275932wrc.1042.2022.05.13.21.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 21:05:02 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oJmTqas0; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BBFED4B9690; Fri, 13 May 2022 17:37:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343705AbiELUGm (ORCPT + 99 others); Thu, 12 May 2022 16:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355330AbiELUGj (ORCPT ); Thu, 12 May 2022 16:06:39 -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 1110E5DA7E for ; Thu, 12 May 2022 13:06:38 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id i11so11732161ybq.9 for ; Thu, 12 May 2022 13:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7xSrUdnA1OiCjH5kvyp3iABoTsJX17lF1oCQIDPuInU=; b=oJmTqas0xC+2qy+kk8WgzgOdjTx5w6qZApvdhSwAEndyUXURPZKCZLybhoilwzTvzi l0wAH2cytfQ+DdcyuxCO7SHCaYu1K4TSjPEqk+L3k7VC+Zu4gqWjwvo9hC/VksHEh4gx KI1gfqoqXoOH0kRcq+gP99WoTnIsG6ly78eiOfDuSde/nrghdfNDqBRFsJunaTgIOojq F4lGABgENIBZtk2zqB4b2r5kOlDPoArntlXCiL4orMuzLVG3JyaFvjytpY+/KYIYvCGE Pv23RO0Ce1szZ8o4Ql2tVK29DPtkgxhFaMES3xtAOIAiBTUwTENXGRUod0MvS6XbEZ8h CERg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7xSrUdnA1OiCjH5kvyp3iABoTsJX17lF1oCQIDPuInU=; b=gQv2JQMjeVEC7/RGesXr57U4IIR0CuRDauOkIsw1JYthL43AAE/TyesxjWafnxANq7 6/zr71Hc8I41ko7IQjixWLvPizJzvG189ShZhuxjPZEhOmrVKtGLUMRbzgdAlLWgimZY KfsEDcaAG0pCtgIdfH0V+JTtNHGvDH7QaL7Xwt0qSa+w0hS1nuopukEhyZDsn/+rLFrI +tLthFwJaBO9ceu6X0dwWY8E6NJ66S3v3qiyTzDhgiDbhvbvjlfshqNc0DAwm5oQB5cW DZ+u9ToG8YPytIv+tMAu1G8u6nIOA8P17CsLVKpl2LZDRNqt3R+biN+E4kAXKsJBqXEU 1XtA== X-Gm-Message-State: AOAM532QVMA1LmpOec9HDKNQhSp/QZD1aT3uxU+51sOIA/5mp+WGt93w /EMZwcJuTZbeMiDuHZYcBXsOc9YpE1144nxa7eIKKg== X-Received: by 2002:a25:230a:0:b0:64b:49c:c67c with SMTP id j10-20020a25230a000000b0064b049cc67cmr1573440ybj.598.1652385996916; Thu, 12 May 2022 13:06:36 -0700 (PDT) MIME-Version: 1.0 References: <20220512103322.380405-1-liujian56@huawei.com> In-Reply-To: <20220512103322.380405-1-liujian56@huawei.com> From: Eric Dumazet Date: Thu, 12 May 2022 13:06:25 -0700 Message-ID: Subject: Re: [PATCH net] tcp: Add READ_ONCE() to read tcp_orphan_count To: Liu Jian , Dmitry Vyukov , Marco Elver , LKML Cc: David Miller , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Paolo Abeni , Neal Cardwell , netdev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 3:32 AM Liu Jian wrote: > > The tcp_orphan_count per-CPU variable is read locklessly, so this commit > add the READ_ONCE() to a load in order to avoid below KCSAN warnning: > > BUG: KCSAN: data-race in tcp_orphan_count_sum net/ipv4/tcp.c:2476 [inline] > BUG: KCSAN: data-race in tcp_orphan_update+0x64/0x100 net/ipv4/tcp.c:2487 > > race at unknown origin, with read to 0xffff9c63bbdac7a8 of 4 bytes by interrupt on cpu 2: > tcp_orphan_count_sum net/ipv4/tcp.c:2476 [inline] > tcp_orphan_update+0x64/0x100 net/ipv4/tcp.c:2487 > call_timer_fn+0x33/0x210 kernel/time/timer.c:1414 > > Fixes: 19757cebf0c5 ("tcp: switch orphan_count to bare per-cpu counters") > Signed-off-by: Liu Jian > --- > net/ipv4/tcp.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c > index cf18fbcbf123..7245609f41e6 100644 > --- a/net/ipv4/tcp.c > +++ b/net/ipv4/tcp.c > @@ -2718,7 +2718,7 @@ int tcp_orphan_count_sum(void) > int i, total = 0; > > for_each_possible_cpu(i) > - total += per_cpu(tcp_orphan_count, i); > + total += READ_ONCE(per_cpu(tcp_orphan_count, i)); We might raise the discussion to lkml and/or KCSAN supporters. Presumably, all per_cpu() uses in the kernel will have the same issue ? By definition per-cpu data can be changed by other cpus. So maybe per_cpu() should contain the annotation, instead of having to annotate all users. > > return max(total, 0); > } > -- > 2.17.1 >