Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp849650rdb; Mon, 29 Jan 2024 23:36:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IETkdt0+dvPhShxygmqvpk4Fr3M+rWHFoVVFDOwaHEtgd5UYCAGEEHzH/wnjDobp7Anjs8M X-Received: by 2002:a17:906:c78d:b0:a35:e6a1:2adb with SMTP id cw13-20020a170906c78d00b00a35e6a12adbmr2353111ejb.41.1706600169370; Mon, 29 Jan 2024 23:36:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706600169; cv=pass; d=google.com; s=arc-20160816; b=dvSwju0p7KZlwlXL0pO+D2BwxXdiZlrrLw33/FNCJJWGRnU231LnW6EKe71IBG1cQv mMb00MJNplF6B+fBkq/1X3VCeaUBO7MTHTFS/R78v+kqQIhFwrVE7KCk+3W9bASzTx+T L06ydFsp0bBixXN9YXe1rKZpZxqST2G2ZeQGpbQLm6vtvJyDRiHIVKxg+lOkryc6FGC+ VpgOBMttjuBxz/2QmM5rAbNiGw0yIC5jJs8lpAgO9+i1ZHuTOLwCjlI2p8ZGdJNN0G6z +KhLYC1QwgUIci7zsJTkG9geq2WqZnHDF8/tLfv3Ppe8TYELR4Dv4ed8c9tgNTGeqjTA iv6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=9D4Y7AO9ukbk0Vw/uL6bzKk0hQbCAMUiiZkj9T0JV8M=; fh=CimFb0Hku+GYcI3Am6+ZfLSkYnfTf03Jzb/y3efcJLM=; b=CBB2T+1W0TA95vwXmD+kncUo58MP3F5Ds/CXl1Nh8OIZYU4ZnMtRvZcJ67HMGrU0EU DF9EdPzjnvCyA/8wwUURLyRn1Ld9IjRjBrfdkahUWEhDcMstOO/7D4e6e/WaF4JB0YuA 9G4VxyVeUnbnYJUDdKfHjr60u3lsXgZcy58o7FyXWU3ujUR8ShxbfgzGIOSA1nQ5F54r rhOL1MSK9bel6tZl1dGkuKJDR8i1YErnTXE62JyOgesNlrWuGxa58frOuZszRb2MavCQ nk6rNAHldxWTMnhEo4PeFcpgFZH4PWDP7yNlejtfGZ+qu3l0Y3hu8YtHezc5G/roPAOE ELpA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=z1ZN3vjz; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-44051-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44051-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g5-20020a170906198500b00a35be3ed835si1692362ejd.58.2024.01.29.23.36.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 23:36:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44051-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=z1ZN3vjz; arc=pass (i=1 spf=pass spfdomain=tesarici.cz dkim=pass dkdomain=tesarici.cz dmarc=pass fromdomain=tesarici.cz); spf=pass (google.com: domain of linux-kernel+bounces-44051-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44051-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tesarici.cz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 253061F23E6B for ; Tue, 30 Jan 2024 07:36:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA7CE54F8E; Tue, 30 Jan 2024 07:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b="z1ZN3vjz" Received: from bee.tesarici.cz (bee.tesarici.cz [77.93.223.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89D1A5465D; Tue, 30 Jan 2024 07:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.93.223.253 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706600146; cv=none; b=no8Frwhhw8vJ0zq46e0K7wak1kLkvM0Sn37uswl1BDrqQT15PTQ+9vJNCTpenTNLltkbc6+fph7lT8bGmOEk56NVewm2NDOQK65rVcjMR1Z9Dyq7aUaG2uOSPSFuv5JlAG/S4SDk6UCpe7Bd+Bsz8ubW0M59xt0oaA08nxNW78E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706600146; c=relaxed/simple; bh=/jhiDAXn5xDQ3jcJlcHR5q1dx8ajj5r1UfIhMLOvtTM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lf1FkbDCBpAPCE2bZ7K/W3CTYbrmTbneQ1qTaTZSw9YvyBVTFVkPwYLX4cNCxirweAIt2QynCJdbJ2fShz9J+aWE1119Unq6v+9ElF10fzc+QN/O4fc6S7Glhcgi1ztFNDTKtvpqUDLX6qF+8lEK9xmaU3wbIh64i8w/M+Rfyuc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tesarici.cz; spf=pass smtp.mailfrom=tesarici.cz; dkim=pass (2048-bit key) header.d=tesarici.cz header.i=@tesarici.cz header.b=z1ZN3vjz; arc=none smtp.client-ip=77.93.223.253 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tesarici.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tesarici.cz Received: from meshulam.tesarici.cz (dynamic-2a00-1028-83b8-1e7a-4427-cc85-6706-c595.ipv6.o2.cz [IPv6:2a00:1028:83b8:1e7a:4427:cc85:6706:c595]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id 65FFB19BD2B; Tue, 30 Jan 2024 08:35:40 +0100 (CET) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=quarantine dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1706600140; bh=/jhiDAXn5xDQ3jcJlcHR5q1dx8ajj5r1UfIhMLOvtTM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=z1ZN3vjzuGCX+Y8dEn4+fs1ySTvsw7mor35rpzLLbpdiIU7jI14MfiJQr6sSuXSk+ cS1uXiN+QQcT2P8DfF0xCQ+G5AGr/CPEdyVsnqnTnTQeTQZfdUTL4fxXwLBR6r1bw3 80J4G6nxl2jOiKZaMWnoYm0ug3JOqVnrKoww6oh3thgZYrGr3At7aIrbUwxZHM6QUi qOXRUg55nQPTae3/2tyna2ggFM1kDsZRpz3tseBRi2GitO9ZMvwO76s1t8zcJb98HQ r0BR64lk9k9ZSnSrjwyDK+gJFZ+MPYGUANexI3pnMckyS/Fxo+ZYIpKs2cL6jxYNKK 68IXl2PYqbUYg== Date: Tue, 30 Jan 2024 08:35:39 +0100 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Jisheng Zhang Cc: Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , "open list:STMMAC ETHERNET DRIVER" , "moderated list:ARM/STM32 ARCHITECTURE" , "moderated list:ARM/STM32 ARCHITECTURE" , open list , "open list:ARM/Allwinner sunXi SoC support" , Marc Haber , Andrew Lunn , Florian Fainelli , stable@vger.kernel.org Subject: Re: [PATCH net v2] net: stmmac: protect updates of 64-bit statistics counters Message-ID: <20240130083539.4ea26a8d@meshulam.tesarici.cz> In-Reply-To: References: <20240128193529.24677-1-petr@tesarici.cz> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.39; x86_64-suse-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 30 Jan 2024 13:00:10 +0800 Jisheng Zhang wrote: > On Sun, Jan 28, 2024 at 08:35:29PM +0100, Petr Tesarik wrote: > > As explained by a comment in , write side of struct > > u64_stats_sync must ensure mutual exclusion, or one seqcount update could > > be lost on 32-bit platforms, thus blocking readers forever. Such lockups > > have been observed in real world after stmmac_xmit() on one CPU raced with > > stmmac_napi_poll_tx() on another CPU. > > > > To fix the issue without introducing a new lock, split the statics into > > three parts: > > > > 1. fields updated only under the tx queue lock, > > 2. fields updated only during NAPI poll, > > 3. fields updated only from interrupt context, > > > > Updates to fields in the first two groups are already serialized through > > other locks. It is sufficient to split the existing struct u64_stats_sync > > so that each group has its own. > > > > Note that tx_set_ic_bit is updated from both contexts. Split this counter > > so that each context gets its own, and calculate their sum to get the total > > value in stmmac_get_ethtool_stats(). > > > > For the third group, multiple interrupts may be processed by different CPUs > > at the same time, but interrupts on the same CPU will not nest. Move fields > > from this group to a newly created per-cpu struct stmmac_pcpu_stats. > > > > Fixes: 133466c3bbe1 ("net: stmmac: use per-queue 64 bit statistics where necessary") > > Link: https://lore.kernel.org/netdev/Za173PhviYg-1qIn@torres.zugschlus.de/t/ > > Cc: stable@vger.kernel.org > > Signed-off-by: Petr Tesarik > > Thanks for the fix patch. One trivial improviement below > s/netdev_alloc_pcpu_stats/devm_netdev_alloc_pcpu_stats to simplify > error and exit code path. Thanks for your review. In fact, many other allocations in stmmac could be converted to devm_*. I wanted to stay consistent with the existing code, but hey, you're right there's no good reason for it. Plus, I can send convert the other places with another patch. > With that: > Reviewed-by: Jisheng Zhang > > PS: when I sent the above "net: stmmac: use per-queue 64 bit statistics > where necessary", I had an impression: there are too much statistics in > stmmac driver, I didn't see so many statistics in other eth drivers, is > it possible to remove some useless or not that useful statistic members? I don't feel authorized to make the decision. But I also wonder about some counters. For example, why is there tx_packets and tx_pkt_n? The former is shown as RX packets by "ip stats show dev end0", the latter is shown by as tx_pkt_n by "ethtools -S end0". The values do differ, but I have no clue why, and if they are even expected to be different or if it's a bug. Petr T