From: "Nikhil P. Rao" 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 Signed-off-by: Eric Joyner Signed-off-by: Brett Creeley --- 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 + #define IONIC_STAT_INVALID (cpu_to_le64(~0ULL)) #define IONIC_STAT_TO_OFFSET(type, stat_name) (offsetof(type, stat_name)) -- 2.43.0