Article View: linux.kernel.netdev
Article #23870Re: [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time
From: Vadim Fedorenko
Date: Sat, 28 Nov 2026 13:21
Date: Sat, 28 Nov 2026 13:21
108 lines
13070 bytes
13070 bytes
On 25/11/2026 23:22, Brett Creeley wrote:
> From: "Nikhil P. Rao" <nikhil.rao@amd.com>
>
> ionic_port_init() marks every counter in the device-written extra_stats
> block invalid before asking firmware to refresh it, so that a statistic
> this driver knows about but the firmware does not is reported as absent
> rather than as zero. It does that with a memset() of the whole block,
> and ethtool -S takes its snapshot of the block with a struct copy.
>
> Both run without a common lock: ionic_port_init() is called from the
> firmware recovery work, and an ethtool -S that got past the device
> present check before the netdev was detached can still be running.
> Neither memset() nor a struct copy guarantees the width of its
> accesses, so the snapshot can hold a counter that is neither its old
> value nor the marker, and ethtool -S then reports it. The
> .get_fec_stats handler added later in this series has the same need.
>
> The block is entirely __le64, each member naturally aligned, so walk it
> as an array and write the markers, and take the snapshot, one counter
> at a time with WRITE_ONCE() and READ_ONCE(). A counter read on its own
> is then either a complete value or the marker.
>
> Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
> Signed-off-by: Eric Joyner <eric.joyner@amd.com>
> Signed-off-by: Brett Creeley <brett.creeley@amd.com>
> ---
> drivers/net/ethernet/pensando/ionic/ionic_main.c | 8 ++++++--
> drivers/net/ethernet/pensando/ionic/ionic_stats.c | 8 +++++++-
> drivers/net/ethernet/pensando/ionic/ionic_stats.h | 2 ++
> 3 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_main.c b/drivers/net/ethernet/pensando/ionic/ionic_main.c
> index 1ad5f529e600..16c1b1fd155c 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_main.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_main.c
> @@ -12,6 +12,7 @@
> #include "ionic.h"
> #include "ionic_bus.h"
> #include "ionic_lif.h"
> +#include "ionic_stats.h"
> #include "ionic_debugfs.h"
>
> MODULE_DESCRIPTION(IONIC_DRV_DESCRIPTION);
> @@ -728,7 +729,9 @@ int ionic_port_init(struct ionic *ionic)
> struct ionic_identity *ident = &ionic->ident;
> struct ionic_dev *idev = &ionic->idev;
> bool allocated = false;
> + __le64 *stat;
> size_t sz;
> + size_t i;
> int err;
>
> if (!idev->port_info) {
> @@ -746,8 +749,9 @@ int ionic_port_init(struct ionic *ionic)
> /* If the driver knows about more "extra stats" than the firmware,
> * make sure these stats are marked as invalid.
> */
> - memset(&idev->port_info->extra_stats, 0xff,
> - sizeof(idev->port_info->extra_stats));
> + stat = (__le64 *)&idev->port_info->extra_stats;
> + for (i = 0; i < sizeof(idev->port_info->extra_stats) / sizeof(*stat); i++)
> + WRITE_ONCE(stat[i], IONIC_STAT_INVALID);
>
> WRITE_ONCE(idev->link_down_count_init, false);
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> index 428d5cca930f..89926e5a2f3c 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> @@ -237,7 +237,10 @@ static u32 ionic_extra_port_stats_get_count(struct ionic_lif *lif)
> {
> struct ionic_dev *idev = &lif->ionic->idev;
> struct ionic_port_extra_stats *pes_cache;
> + const __le64 *src;
> u32 count = 0;
> + __le64 *dst;
> + size_t i;
>
> if (!(lif->ionic->ident.dev.capabilities &
> cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
> @@ -252,7 +255,10 @@ static u32 ionic_extra_port_stats_get_count(struct ionic_lif *lif)
> return count;
> }
>
> - *pes_cache = idev->port_info->extra_stats;
> + src = (const __le64 *)&idev->port_info->extra_stats;
> + dst = (__le64 *)pes_cache;
> + for (i = 0; i < sizeof(*pes_cache) / sizeof(*dst); i++)
> + dst[i] = READ_ONCE(src[i]);
>
> if (pes_cache->rx_bits_phy != IONIC_STAT_INVALID)
> count++;
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.h b/drivers/net/ethernet/pensando/ionic/ionic_stats.h
> index 7ed935868e84..8a0edcc86fb8 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_stats.h
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.h
> @@ -4,6 +4,8 @@
> #ifndef _IONIC_STATS_H_
> #define _IONIC_STATS_H_
>
> +#include <linux/ethtool.h>
> +
> #define IONIC_STAT_INVALID (cpu_to_le64(~0ULL))
>
> #define IONIC_STAT_TO_OFFSET(type, stat_name) (offsetof(type, stat_name))
>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Technical Details
Message-ID:
<0a15473f-6aaf-45b2-9ae2-3660f82ad9a2@linux.dev>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373126-linux-kernel-netdev=dewy.ruReferences:
<20261125-ionic-get-fec-stats-v6-0-1ab49c729c00@amd.com> <20261125-ionic-get-fec-stats-v6-1-1ab49c729c00@amd.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373126-linux-kernel-netdev=dewy.ru From: vadim.fedorenko@linux.dev (Vadim Fedorenko) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time Date: Sat, 28 Nov 2026 13:21:58 +0000 Organization: Usenet Network Message-ID: <0a15473f-6aaf-45b2-9ae2-3660f82ad9a2@linux.dev> References: <20261125-ionic-get-fec-stats-v6-0-1ab49c729c00@amd.com> <20261125-ionic-get-fec-stats-v6-1-1ab49c729c00@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="954439"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:PFnMz6qTT1tqmKL+R8xS/7m/bOc= sha256:ASf9ZMVvfXrKuLux/bjp3pGfItjVrssiTtAWwJ5/QvU= sha1:NCoYhp9sqkTKO37Nqs87+kq/DgY= sha256:k10wAviKUR6hzHfxhbj8A+uYx8GFfbyfc4iL6ioXxUc= Content-Language: en-US List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id BCDC5125F79; Sat, 28 Nov 2026 16:22:16 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.15 X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4SGY18nKneMd; Sat, 28 Nov 2026 16:22:12 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-373126-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 6A262125F77; Sat, 28 Nov 2026 16:22:04 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 027EF602F6A; Sat, 28 Nov 2026 13:22:04 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795872123; b=dZXI3MXZAsvVNrbS4DMxiW5kAL5W7iwnY2E0KvzPB4Jn3pIkhtxVnnonJBKXdpmbFjSm +I7HNTTRUbs5wLqvjkklroj7UJ0VU5pl33alGSZuPaKxtilPUYg2ozJwXfzLA1bd4u45J 82fp43ba09F0sgVMp9789+t2jlM3XNg5apdBv/06Q9Lpij3Rr2I03uiF9/FeB/FkBHqtO oR43GP2IMr4ZNegAlRMeJD0GRAsk9jtz7XnUPJjWJ0xQMPVUf8UqlSXxNIngFkBQu89ml agFnAaHjA3w8YMPXCKv/l+sRU4mAF11Bz56ms468BidhNNprbQsr6hHb8QJGaEsYgbg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795872123; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=9M+h8Fm7d9Wa8TbU9ATtCpoBY1oi/bBqQ0Cbg0S5pfA=; b=eukYIbFy2uClk/1Jk3jHool1+pjAtOoBLfDFb5POyZIyX4tm0Mo5zrdqWH8os1PVDdvL POM/el6RLEt2PPOMrVSSA3u9rzo5G3f8jTKsxGALx27pYfFzt/3vJeTQTOLvbe6tYnCJ6 YVdHE6FnaooiUUv5TM/kqq54noq0kr4nSiOl0aeOlxzLZJrlN/hrOHvBPtS6uzcbnoggh VCndkro+oBk/fj9T79n4TZJyn339nkop3w5DE2hlC4xQwLpVwbnDfEWxON4xK/czUJ2B8 1MA/4UcM9fIFxBid6wQoSCIPKFgLztJcGakYzp67H9vtBxbcMcJjazWfDdIhxEmsENA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=pEEbg3QB; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26B0D606A32A; Sat, 28 Nov 2026 13:22:03 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=pEEbg3QB X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.163 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795872122; b=48fS1MHCEdaNpWDpzD2766taFMXG27KMujCRpovza/0VmEzOeIsMAY5nj1o1fqnUG8k5 vdafz5fxpE2HT7Q50m0iKQbkiU0W6f9vItSZb4lxpcXHNrrUkqXpr6yW1CYTGpcEK+G7J KJbCN7k271S9edWDi/qTieTeuZ4byUWYbzPeITpFrfCPgXDvuKa4HZ2W3oG3WHTFYEG8r EIVkeLlKZGQYtgA+tHnyiLJFaIvWpsFXQTv4HCOwNAMtzjwbG6p4yVf3tw/CUtSjgj07J xH1FDVEUhMfq9lzNKzjPYQRW3dEFcQ+nHPD5XkYztopAqgk3VbWxwAAiu7hgunSeO7Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795872122; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=9M+h8Fm7d9Wa8TbU9ATtCpoBY1oi/bBqQ0Cbg0S5pfA=; b=YNC58ApxikIDhUKR4Uxp7/Vl+jH64bebaSU+8etJ7ysFC/EM0rG30Z4o1hPQE/VbdI/T T1Ev/qcnV0xa9hRS3fU+bBioITtFGhAxyyn8zzxn+FM/OYixrsvzubyPXbz5rdXrXoiPo MFIb6K/LJXSJJfXa+f8bJ3AEEt9wYUeaYtwoxBLQa0UJkEKdl4lmW39OdbNdtGSHrDDFh ir8PvovgZeD1rDnLzvwjkJ+eG0q8hZupAUiAxfBZJpYUp5wi5KWhHks7H1FidtKdR7ARv NdC/0MY7fgcMt2ONF0c6F1k7H9cNVu2Esm3RNAN/tMVzIePR4hc6GTNjps9MXGzBmcQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=pEEbg3QB; arc=none smtp.remote-ip=95.215.58.163 X-Received: from mta1.migadu.com (out-163.mta1.migadu.com [95.215.58.163]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D050606A321 for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 13:22:01 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8D050606A321 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=cRB0bFCO51Zn5hm+TGjeTHiA7vrbV/8Qg0Q/l7lyT3s=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795872119; v=1; x=1796476919; b=pEEbg3QBQILQThnak+rO2oNeSU+W97pRA5AuGCnU390x5RFQmRVQuW5yZJ03/lJPsAAyjZ93 6XfnZC/gq19YicXQb/hQ1QAQPiY6Qco43L6HIe/776Y/3PJJloJSSdvQiQ/M4l9j7X6S9Amcozv r84lvGdS0k90TOAkbMXSHlB0= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 4d515811890fdf78; Sat, 28 Nov 2026 13:21:59 +0000 X-Mizu-Trace-ID: 4d515811890fdf78 X-Migadu-Flow: FLOW_OUT X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-User-Agent: Mozilla Thunderbird X-Cc: netdev@vger.kernel.org, Simon Horman <horms@kernel.org>, "Nikhil P. Rao" <nikhil.rao@amd.com>, Eric Joyner <eric.joyner@amd.com>, Breno Leitao <leitao@debian.org>, Arun Kumar Prakash <ArunKumar.Prakash@amd.com> X-In-Reply-To: <20261125-ionic-get-fec-stats-v6-1-1ab49c729c00@amd.com>