From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380207; b=aweolxu83Ay8rkUbWNYqq6AK84wiFxEO3ooz1tVdF9ZMbQZG12Ccc5VXOoYj52KLtVa3 wWxgGCAClJcgj6rg29d4o4srpLg/Sqe+AjdYJdUypQo3/3L1CmbSC4vupEfRTCNkaj98F dT9ytuORbkY64CJbcYV4mhvwPzPCF7ykWHQPcCZrxHb5NO5CPzNV4V8mygrKK5HIZpo26 8Ts/K2iua8XXd/v7RKH8ZxAbqRSMCjctulQHLYGcBiPsW15mz4yOIwhnMTtzQ6PNR1SDf ANIP3ZF8VxFouJxFphK6XAAAEezTMs54XLv4lFnsNbUNQi2CFPupQSipeo0M6B/dH5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380207; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Lhak1juorpta+fvLRzFSclfJwzkcuvd8s5yqX3+Z/Ow=; b=gj0qTLJeLjONfsknFlMzhHt4xeiM2ZEBLkL30VnQxlUNx1Ad/D7un1cVrGu1CEXakalI 5gmqh5OVRWkCGKIFYJSS/edgeON/rMqfg8KRAGTZYKDpZK609v8ZjU37uA0n1HL+GQ/AO MGuIisnP2HiliGzD4OZzCIkjsUULDCPTQGgqWwg9zYR1wfzz5DXfOwP1DLmRdnNJsiDWj i5F/uYe0vNMTYsZgfX9WM604wZW/tlXD06qaHEaZonVIWdynuUPYkVLWIEHrsjg4S9W2f AoL5X4gITqEdKm6X+OFeOaCqUKU0uymFYgMRXY+fdpyV3+twT8VAUtoEbTUuUPRwfng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Bn1jdLAW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC6B1606A32D; Fri, 4 Dec 2026 10:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Bn1jdLAW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 020D91F000CE; Fri, 4 Dec 2026 10:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380207; bh=Lhak1juorpta+fvLRzFSclfJwzkcuvd8s5yqX3+Z/Ow=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Bn1jdLAWPjssDMbFe/hl3QRwNuzjBdvTiW5H9/eSPGwQ7v94nB9G3BUJ9KZfa4653 PB0PR2aelcaVUOg5VXoEKL6v5QCYjDZrC7l0Hqd23T/73Zhn024ydT5VSBd029FYK1 ClnXUa6kHKZXqTX8wpEovJxqYl9+ywnORPtNzYO8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexander Duyck , Jakub Kicinski , Sasha Levin Subject: [PATCH 7.3 136/742] fbnic: Cover all of the HW stats with the stats lock Date: Fri, 4 Dec 2026 19:00:00 +0900 Message-ID: <20261204100638.740070870@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Duyck [ Upstream commit 52a64e64230e03b45c13c615d7cdf0aeea39b210 ] The hw_stats lock covers the PHY, TMI, TTI, RPC, RXB, queue and PCIe stats, but the MAC stats are left to RTNL: the fbnic_reset_hw_stats function resets them outside the lock and asserts RTNL, on the grounds that the ethtool API is their only other user and holds RTNL. That is no longer the case. ethtool only takes RTNL on the Netlink path for the operations a driver lists in op_needs_rtnl, and fbnic lists only the pause getter among the stats ones, so the eth-mac, eth-ctrl and rmon getters update the MAC stats with only the netdev instance lock held, racing each other and the reset. Take the stats lock around the MAC stats updates in those getters and in the reset, and drop the RTNL assertion. Take it in the pause getter as well: it still runs under RTNL, but that no longer serializes it against the reset once the reset does not rely on RTNL. The PCIe stats debugfs read never needed RTNL, as the fbnic_get_hw_stats function updates those stats under the stats lock, so drop it there too. The values are printed from their 64-bit fields without the lock, as the counters keep changing during the read anyway. The issue was found by code review. Fixes: 45079e00133e ("net: ethtool: optionally skip rtnl_lock on Netlink path for GET ops") Signed-off-by: Alexander Duyck Link: https://patch.msgid.link/179460250360.8819.2203630667210523871.stgit@ahduyck-xeon-server.home.arpa Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c | 3 --- drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 8 ++++++++ drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c | 13 +------------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c b/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c index 6edfa0aa69f11..0ad6707777941 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c @@ -3,7 +3,6 @@ #include #include -#include #include #include "fbnic.h" @@ -606,7 +605,6 @@ static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v) { struct fbnic_dev *fbd = s->private; - rtnl_lock(); fbnic_get_hw_stats(fbd); seq_printf(s, "ob_rd_tlp: %llu\n", fbd->hw_stats.pcie.ob_rd_tlp.value); @@ -625,7 +623,6 @@ static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v) fbd->hw_stats.pcie.ob_rd_no_cpl_cred.value); seq_printf(s, "ob_rd_no_np_cred: %llu\n", fbd->hw_stats.pcie.ob_rd_no_np_cred.value); - rtnl_unlock(); return 0; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c index 76e9a545bb165..cb4258bd20538 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -1855,12 +1855,14 @@ fbnic_get_pause_stats(struct net_device *netdev, mac_stats = &fbd->hw_stats.mac; + spin_lock(&fbd->hw_stats.lock); fbd->mac->get_pause_stats(fbd, false, &mac_stats->pause); pause_stats->tx_pause_frames = mac_stats->pause.tx_pause_frames.value; pause_stats->rx_pause_frames = mac_stats->pause.rx_pause_frames.value; tx_ps_events = mac_stats->pause.tx_pause_storm_events.value; pause_stats->tx_pause_storm_events = tx_ps_events; + spin_unlock(&fbd->hw_stats.lock); } static void @@ -1916,6 +1918,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev, mac_stats = &fbd->hw_stats.mac; mac = fbd->mac; + spin_lock(&fbd->hw_stats.lock); mac->get_eth_mac_stats(fbd, false, &mac_stats->eth_mac); fbnic_set_counter(ð_mac_stats->FramesTransmittedOK, @@ -1944,6 +1947,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev, &mac_stats->eth_mac.BroadcastFramesReceivedOK); fbnic_set_counter(ð_mac_stats->FrameTooLongErrors, &mac_stats->eth_mac.FrameTooLongErrors); + spin_unlock(&fbd->hw_stats.lock); } static void @@ -1956,12 +1960,14 @@ fbnic_get_eth_ctrl_stats(struct net_device *netdev, mac_stats = &fbd->hw_stats.mac; + spin_lock(&fbd->hw_stats.lock); fbd->mac->get_eth_ctrl_stats(fbd, false, &mac_stats->eth_ctrl); eth_ctrl_stats->MACControlFramesReceived = mac_stats->eth_ctrl.MACControlFramesReceived.value; eth_ctrl_stats->MACControlFramesTransmitted = mac_stats->eth_ctrl.MACControlFramesTransmitted.value; + spin_unlock(&fbd->hw_stats.lock); } static const struct ethtool_rmon_hist_range fbnic_rmon_ranges[] = { @@ -1991,6 +1997,7 @@ fbnic_get_rmon_stats(struct net_device *netdev, mac_stats = &fbd->hw_stats.mac; + spin_lock(&fbd->hw_stats.lock); fbd->mac->get_rmon_stats(fbd, false, &mac_stats->rmon); rmon_stats->undersize_pkts = @@ -2006,6 +2013,7 @@ fbnic_get_rmon_stats(struct net_device *netdev, rmon_stats->hist[i] = mac_stats->rmon.hist[i].value; rmon_stats->hist_tx[i] = mac_stats->rmon.hist_tx[i].value; } + spin_unlock(&fbd->hw_stats.lock); *ranges = fbnic_rmon_ranges; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c index 8b9b2076beecd..c3b9e8fae396f 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c @@ -1,8 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) Meta Platforms, Inc. and affiliates. */ -#include - #include "fbnic.h" static void fbnic_hw_stat_rst32(struct fbnic_dev *fbd, u32 reg, @@ -551,17 +549,8 @@ void fbnic_reset_hw_stats(struct fbnic_dev *fbd) fbnic_reset_rxb_stats(fbd, &fbd->hw_stats.rxb); fbnic_reset_hw_rxq_stats(fbd, fbd->hw_stats.hw_q); fbnic_reset_pcie_stats_asic(fbd, &fbd->hw_stats.pcie); - spin_unlock(&fbd->hw_stats.lock); - - /* Once registered, the only other access to MAC stats is via the - * ethtool API which is protected by the rtnl_lock. The call to - * fbnic_reset_hw_stats() during PCI recovery is also protected - * by the rtnl_lock hence, we don't need the spinlock to access - * the MAC stats. - */ - if (fbd->netdev) - ASSERT_RTNL(); fbnic_reset_hw_mac_stats(fbd, &fbd->hw_stats.mac); + spin_unlock(&fbd->hw_stats.lock); } void fbnic_init_hw_stats(struct fbnic_dev *fbd) -- 2.53.0