From patchwork Tue Dec 3 07:21:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinas Rasheed X-Patchwork-Id: 13891785 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (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 DF5E0190068; Tue, 3 Dec 2024 07:21:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210517; cv=none; b=EVGmoQKoktXVSFm34o2b7ao0CeQuit8mQGu1srnfc/W/vFXJByKTuZxNWsOhqUxq54iw+ZkqGv8LgO7MwA3wZo397xdgTPPAUH3jOfHcHmOr8gmAV3GxHge13iD8bKvCEBB9dZLClhxrUW/mKsXU5UC49o1lwgOI75214dSsBbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210517; c=relaxed/simple; bh=iylAhosW77w2u9xAeYd/1FbXH+I7TjDY4QEVCoIu+tE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zm3dhFiPAZR5/QC4E0aYQqI836PCrXJPH7mmFCFSQoCTzOgJu+GEbfNKNp5KvAoDvhrYn/e5Y6t6l93tcYDzmdDPv57bCYoAPy2RWo+T24Rl/koYmzURz2SvxZ67+tSq3eXhKoLjsigfBCNuQP/9XZbvWyKhN9SfnXTm7D2/rmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=YMm2+u09; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="YMm2+u09" Received: from pps.filterd (m0431383.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B30BHvG032757; Mon, 2 Dec 2024 23:21:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=q 0v3XGHnrUCbd0Zjf9nphx1E5qKnd4Kf5ev2MrlxOU4=; b=YMm2+u09r2tf3NZZJ X41VW7MuIwRALVdHhl4n8g4KqDjR+jXgv+wNXHOMYX7njnb0pCOTsGlpl8YhlbqH 6PcnfrIeOwxxKoJ494EEiQhvrzespPz7H+KkDX9goKQZ2LtCKg8tDQOXqeM80GWs DJ1JIC+248mzs+wfMohZ2iYkbTttlGp5K9mPypqPhCNS30GS1uJKwcZ5iY5Wzv1E OJcoh7W1FgSo6WiDGbXbntg/WLEOR21aaJqYVAhQpzS0etU7h4kbpynqQCWPZ6NO OyIre5KQrZcUJaK/CXsGMr5J5+1zk9ETxiNaemsZE92WLyH1rIFFr2rY/dLjdyE4 9l43Q== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 439q7cgpec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 23:21:35 -0800 (PST) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 2 Dec 2024 23:21:34 -0800 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 2 Dec 2024 23:21:34 -0800 Received: from ubuntu-PowerEdge-T110-II.sclab.marvell.com (unknown [10.106.27.86]) by maili.marvell.com (Postfix) with ESMTP id 003615B6952; Mon, 2 Dec 2024 23:21:33 -0800 (PST) From: Shinas Rasheed To: , CC: , , , , , , , , , , Shinas Rasheed , Veerasenareddy Burru , Andrew Lunn , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , Satananda Burla , Abhijit Ayarekar Subject: [PATCH net v1 1/4] octeon_ep: fix race conditions in ndo_get_stats64 Date: Mon, 2 Dec 2024 23:21:27 -0800 Message-ID: <20241203072130.2316913-2-srasheed@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241203072130.2316913-1-srasheed@marvell.com> References: <20241203072130.2316913-1-srasheed@marvell.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7nZToYQvVJaFCJxhTuX00LWzmER69LIk X-Proofpoint-GUID: 7nZToYQvVJaFCJxhTuX00LWzmER69LIk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 X-Patchwork-Delegate: kuba@kernel.org ndo_get_stats64() can race with ndo_stop(), which frees input and output queue resources. Implement device state variable to protect against such resource usage. Fixes: 6a610a46bad1 ("octeon_ep: add support for ndo ops") Signed-off-by: Shinas Rasheed --- .../ethernet/marvell/octeon_ep/octep_main.c | 27 +++++++++++++++++++ .../ethernet/marvell/octeon_ep/octep_main.h | 8 ++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c index 549436efc204..872b4848027c 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c @@ -733,6 +733,7 @@ static int octep_open(struct net_device *netdev) if (ret > 0) octep_link_up(netdev); + set_bit(OCTEP_DEV_STATE_OPEN, &oct->state); return 0; set_queues_err: @@ -745,6 +746,11 @@ static int octep_open(struct net_device *netdev) return -1; } +static bool octep_drv_busy(struct octep_device *oct) +{ + return test_bit(OCTEP_DEV_STATE_READ_STATS, &oct->state); +} + /** * octep_stop() - stop the octeon network device. * @@ -759,6 +765,14 @@ static int octep_stop(struct net_device *netdev) netdev_info(netdev, "Stopping the device ...\n"); + clear_bit(OCTEP_DEV_STATE_OPEN, &oct->state); + /* Make sure device state open is cleared so that no more + * stats fetch can happen intermittently + */ + smp_mb__after_atomic(); + while (octep_drv_busy(oct)) + msleep(20); + octep_ctrl_net_set_link_status(oct, OCTEP_CTRL_NET_INVALID_VFID, false, false); octep_ctrl_net_set_rx_state(oct, OCTEP_CTRL_NET_INVALID_VFID, false, @@ -1001,6 +1015,16 @@ static void octep_get_stats64(struct net_device *netdev, &oct->iface_rx_stats, &oct->iface_tx_stats); + set_bit(OCTEP_DEV_STATE_READ_STATS, &oct->state); + /* Make sure read stats state is set, so that ndo_stop + * doesn't clear resources as they are read + */ + smp_mb__after_atomic(); + if (!test_bit(OCTEP_DEV_STATE_OPEN, &oct->state)) { + clear_bit(OCTEP_DEV_STATE_READ_STATS, &oct->state); + return; + } + tx_packets = 0; tx_bytes = 0; rx_packets = 0; @@ -1022,6 +1046,7 @@ static void octep_get_stats64(struct net_device *netdev, stats->rx_errors = oct->iface_rx_stats.err_pkts; stats->collisions = oct->iface_tx_stats.xscol; stats->tx_fifo_errors = oct->iface_tx_stats.undflw; + clear_bit(OCTEP_DEV_STATE_READ_STATS, &oct->state); } /** @@ -1526,6 +1551,8 @@ static int octep_sriov_disable(struct octep_device *oct) pci_disable_sriov(pdev); CFG_GET_ACTIVE_VFS(oct->conf) = 0; + clear_bit(OCTEP_DEV_STATE_OPEN, &oct->state); + return 0; } diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.h b/drivers/net/ethernet/marvell/octeon_ep/octep_main.h index fee59e0e0138..78293366e7de 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.h +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.h @@ -223,6 +223,12 @@ struct octep_pfvf_info { u32 mbox_version; }; +/* Device state */ +enum octep_dev_state { + OCTEP_DEV_STATE_OPEN, + OCTEP_DEV_STATE_READ_STATS, +}; + /* The Octeon device specific private data structure. * Each Octeon device has this structure to represent all its components. */ @@ -318,6 +324,8 @@ struct octep_device { atomic_t hb_miss_cnt; /* Task to reset device on heartbeat miss */ struct delayed_work hb_task; + /* Device state */ + unsigned long state; }; static inline u16 OCTEP_MAJOR_REV(struct octep_device *oct) From patchwork Tue Dec 3 07:21:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinas Rasheed X-Patchwork-Id: 13891782 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (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 752EE16FF44; Tue, 3 Dec 2024 07:21:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210513; cv=none; b=cZS6McapMnCRzowCbWcODDA+JbKFDoXxgYZd2WJZYSivgfVslfol+BJLzlLtZSlNs/5VLjv2DFCAlaRx3Tr7jhXJ65k6lM0JKzhOcSpHs4IG+bymArYQIdNp39YX0yQQIO/zHsxOr1xZ3A4fGvUGtFVm1ZaiuMvHAmSymoWFGOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210513; c=relaxed/simple; bh=sEdAioFmf9Lv9Bzh6KE1MU1PkU2fq233DbnGmvjON7s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f9bIrzWQPhuTZJ/ETbH756HqoFCxATjJ7q8YcYPRlCCDTJxvPblShx7/FrkoiAlzDULdOvGDEFF19XrhFAXAJu5fKCXqth8Rg1mYpK2w8sUTLHXbE+aS9Jt3r6TizvzyNVHEYB6iTxaiQJAvfM8cpD3a88rMHBrOncsHru4KMSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=k8H0m4Gi; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="k8H0m4Gi" Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B3425fT025988; Mon, 2 Dec 2024 23:21:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=w jy6BB6VduUyPdEuxxU2kGiraZEi6RInQ4CSuJ+p5fg=; b=k8H0m4GiVTV1JJvuS tn1vGuMW4fsoAeXgORTV/pJAi270BBC3lxkY3Ydazgxl76++VIA+ybO9L+ypse7d H9Gq8/0hcdZ/GDhGzNmaL4Rgdb0osP9iZ6GMdhGGf/n2+NsYhFyZ+EchNabNrZwv 02mYUmCtt2BDkWaF2lP0zFbI9u1Wyv8mvQMVzW83Ffu2UuHptM4npJ5ratev8ald y1i1e54vzBxtUKX7EKV0n6P7YewHWa33wKZGr9Tw8cNZg3Wip8Ql+YK7wIM5ckk1 iz1P9RmF0IFj9GKw0XhWQFVxpjELa01lgxK8n4ojF21FsaA+bTdZ+BVQGbcI6s5F kGrcw== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 439tkw8ay2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 23:21:37 -0800 (PST) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 2 Dec 2024 23:21:37 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 2 Dec 2024 23:21:37 -0800 Received: from ubuntu-PowerEdge-T110-II.sclab.marvell.com (unknown [10.106.27.86]) by maili.marvell.com (Postfix) with ESMTP id 6F1C85B694F; Mon, 2 Dec 2024 23:21:36 -0800 (PST) From: Shinas Rasheed To: , CC: , , , , , , , , , , Shinas Rasheed , Veerasenareddy Burru , Andrew Lunn , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , Abhijit Ayarekar , "Satananda Burla" Subject: [PATCH net v1 2/4] octeon_ep: remove firmware stats fetch in ndo_get_stats64 Date: Mon, 2 Dec 2024 23:21:28 -0800 Message-ID: <20241203072130.2316913-3-srasheed@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241203072130.2316913-1-srasheed@marvell.com> References: <20241203072130.2316913-1-srasheed@marvell.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: a-SoDUzvR_nYhptRavZE2XrxNPVFJG1t X-Proofpoint-ORIG-GUID: a-SoDUzvR_nYhptRavZE2XrxNPVFJG1t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Patchwork-Delegate: kuba@kernel.org The per queue stats are available already and are retrieved from register reads during ndo_get_stats64. The firmware stats fetch call that happens in ndo_get_stats64() is currently not required Fixes: 6a610a46bad1 ("octeon_ep: add support for ndo ops") Signed-off-by: Shinas Rasheed --- drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c index 872b4848027c..8c0a955a02dc 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c @@ -1009,12 +1009,6 @@ static void octep_get_stats64(struct net_device *netdev, struct octep_device *oct = netdev_priv(netdev); int q; - if (netif_running(netdev)) - octep_ctrl_net_get_if_stats(oct, - OCTEP_CTRL_NET_INVALID_VFID, - &oct->iface_rx_stats, - &oct->iface_tx_stats); - set_bit(OCTEP_DEV_STATE_READ_STATS, &oct->state); /* Make sure read stats state is set, so that ndo_stop * doesn't clear resources as they are read @@ -1042,11 +1036,6 @@ static void octep_get_stats64(struct net_device *netdev, stats->tx_bytes = tx_bytes; stats->rx_packets = rx_packets; stats->rx_bytes = rx_bytes; - stats->multicast = oct->iface_rx_stats.mcast_pkts; - stats->rx_errors = oct->iface_rx_stats.err_pkts; - stats->collisions = oct->iface_tx_stats.xscol; - stats->tx_fifo_errors = oct->iface_tx_stats.undflw; - clear_bit(OCTEP_DEV_STATE_READ_STATS, &oct->state); } /** From patchwork Tue Dec 3 07:21:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinas Rasheed X-Patchwork-Id: 13891786 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (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 DF57718FDC9; Tue, 3 Dec 2024 07:21:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210518; cv=none; b=a4PBAqTilwyF7dSbXXxr4BPm/Fv/TbHFkLB3TmRLNXU/onXncNne8g3MNkOWJzOEJIV1z0W0iWLyZY0lAVrp4ClGvCyrKl1uo5c3z4T2zDQiCYiIRMuK/Y/3gu+MJB5KG1pOr7cxGejLKYfYlVV2HlkjJ9hkHbD4DyIdLwsiiyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210518; c=relaxed/simple; bh=piuztm2JC1bAKcnC1hwkkT/67MNkUP6SLFTwxU1O2xc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HdHBJMR2TfeQqpvpjCiR3yuAYGgvF4BKjPT28x4URroT9clOv6hliUAcAZQ7MuN60E5acpPBjvW9Q5YfQeErsdFgJ0aBVAFmtvmd74vyU+rR/sD/GnCK6w9jSq9y3dzknU2Cvp/hsNl4o/C21ZgzN0etLK2OTRC4fYiDqN9okFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=LPgRMpzw; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="LPgRMpzw" Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B34Kp8e026622; Mon, 2 Dec 2024 23:21:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=D 7KcRipFCxqXuMMCt68EFtKaOtb5E+BZHExMXeYNFN8=; b=LPgRMpzw6LuEMU06l atWnmNICIZeDR2Ny+HAe3tpgRh+k3vqZ9QhQP/Gjh9rcFGRJMInTilWnuzdNFYW+ Txl6ts6BPtQ7UNIe/KJ1JhVJog4K6AydjcETwFwHzMu9LMxQz60FrTQFMe7EHIOx gdB0Hs8fMdjwfoHx6J8Z4aPXVKpg2RG5chga7Y3lTro80l0/dEnpnxJWFhfeL1t1 xe5vBabucl0T6TEyzbLqA8On7nFxKhcKLsSOhXtTi101MzEHa6XfGopTEa2VkhLg o4sa5WbVhSOSNOFxBSzOdR1draSDyggC2ufduQgO22ogn03C+MVPHZX4QOUaC9lH 3VeOA== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 439b8qa76x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 23:21:39 -0800 (PST) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 2 Dec 2024 23:21:39 -0800 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 2 Dec 2024 23:21:39 -0800 Received: from ubuntu-PowerEdge-T110-II.sclab.marvell.com (unknown [10.106.27.86]) by maili.marvell.com (Postfix) with ESMTP id 83C3C5B6952; Mon, 2 Dec 2024 23:21:38 -0800 (PST) From: Shinas Rasheed To: , CC: , , , , , , , , , , Shinas Rasheed , Veerasenareddy Burru , Satananda Burla , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH net v1 3/4] octeon_ep_vf: fix race conditions in ndo_get_stats64 Date: Mon, 2 Dec 2024 23:21:29 -0800 Message-ID: <20241203072130.2316913-4-srasheed@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241203072130.2316913-1-srasheed@marvell.com> References: <20241203072130.2316913-1-srasheed@marvell.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QuasgP3i_da6lSIwMYnHlqC-06b1iXzX X-Proofpoint-GUID: QuasgP3i_da6lSIwMYnHlqC-06b1iXzX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Patchwork-Delegate: kuba@kernel.org ndo_get_stats64() can race with ndo_stop(), which frees input and output queue resources. Implement device state variable to protect against such resource usage. Fixes: c3fad23cdc06 ("octeon_ep_vf: add support for ndo ops") Signed-off-by: Shinas Rasheed --- .../marvell/octeon_ep_vf/octep_vf_main.c | 29 +++++++++++++++++++ .../marvell/octeon_ep_vf/octep_vf_main.h | 9 ++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c index 7e6771c9cdbb..12b95fb21e64 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c @@ -497,6 +497,8 @@ static int octep_vf_open(struct net_device *netdev) if (ret) octep_vf_link_up(netdev); + set_bit(OCTEP_VF_DEV_STATE_OPEN, &oct->state); + return 0; set_queues_err: @@ -511,6 +513,11 @@ static int octep_vf_open(struct net_device *netdev) return -1; } +static bool octep_vf_drv_busy(struct octep_vf_device *oct) +{ + return test_bit(OCTEP_VF_DEV_STATE_READ_STATS, &oct->state); +} + /** * octep_vf_stop() - stop the octeon network device. * @@ -525,6 +532,14 @@ static int octep_vf_stop(struct net_device *netdev) netdev_info(netdev, "Stopping the device ...\n"); + clear_bit(OCTEP_VF_DEV_STATE_OPEN, &oct->state); + /* Make sure device state open is cleared so that no more + * stats fetch can happen intermittently + */ + smp_mb__after_atomic(); + while (octep_vf_drv_busy(oct)) + msleep(20); + /* Stop Tx from stack */ netif_carrier_off(netdev); netif_tx_disable(netdev); @@ -782,6 +797,16 @@ static void octep_vf_get_stats64(struct net_device *netdev, u64 tx_packets, tx_bytes, rx_packets, rx_bytes; int q; + set_bit(OCTEP_VF_DEV_STATE_READ_STATS, &oct->state); + /* Make sure read stats state is set, so that ndo_stop + * doesn't clear resources as they are read + */ + smp_mb__after_atomic(); + if (!test_bit(OCTEP_VF_DEV_STATE_OPEN, &oct->state)) { + clear_bit(OCTEP_VF_DEV_STATE_READ_STATS, &oct->state); + return; + } + tx_packets = 0; tx_bytes = 0; rx_packets = 0; @@ -807,6 +832,7 @@ static void octep_vf_get_stats64(struct net_device *netdev, stats->rx_missed_errors = oct->iface_rx_stats.dropped_pkts_fifo_full; stats->tx_dropped = oct->iface_tx_stats.dropped; } + clear_bit(OCTEP_VF_DEV_STATE_READ_STATS, &oct->state); } /** @@ -1140,6 +1166,9 @@ static int octep_vf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) dev_err(&pdev->dev, "Failed to register netdev\n"); goto delete_mbox; } + + clear_bit(OCTEP_VF_DEV_STATE_OPEN, &octep_vf_dev->state); + dev_info(&pdev->dev, "Device probe successful\n"); return 0; diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h index 5769f62545cd..692b3bf94722 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h @@ -213,6 +213,12 @@ struct octep_vf_fw_info { u16 tx_ol_flags; }; +/* Device state */ +enum octep_vf_dev_state { + OCTEP_VF_DEV_STATE_OPEN, + OCTEP_VF_DEV_STATE_READ_STATS, +}; + /* The Octeon device specific private data structure. * Each Octeon device has this structure to represent all its components. */ @@ -282,6 +288,9 @@ struct octep_vf_device { /* offset for iface stats */ u32 ctrl_mbox_ifstats_offset; + /* Device state */ + unsigned long state; + /* Negotiated Mbox version */ u32 mbox_neg_ver; From patchwork Tue Dec 3 07:21:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinas Rasheed X-Patchwork-Id: 13891783 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (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 247A2189F57; Tue, 3 Dec 2024 07:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210515; cv=none; b=BbObTD7jYvIGiyYn7jt3CB/QnkuyQnD8o4BdBCvhqBu9PRskYkMtamiPwar5BxxCygDAbdxSw40GceecZ+Fzjt2MH8MYo9VZie5SbUQafX7gKFMEt6hvCxDDc7AMO7hokvJCH778Q6KMtFxcucdJ4vbL5fslkEbJ//ZTFBCuDq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733210515; c=relaxed/simple; bh=B4ORKtmQbDZW6rXiKO+gEhBszYqvclrSSoGsvMz8erQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ouPbO11sRIJuhoRjwkCtOXNyElxl9YWlgRvtwQZzcuK8HyDHczdGQGj2ycOHI6ORAUAOF3gr1bNmcS17UZCJ3uold5W/+vcQOO/db5AqOkKE6bxf8jsREfyJGnR1qTuP8vuGsysGuf5pLJm3sjADwRteIk8u4vHCPzsk6yZAnMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=eQlD6yK2; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="eQlD6yK2" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B34pcmg024494; Mon, 2 Dec 2024 23:21:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=1 YFLRzd3emvRso5V0wEae5aHl+XO2hgus5vXr+N/jF0=; b=eQlD6yK2rrv7PdApz hE37RoG9ptc8rc2myZuWVLr9wgPFyhGq+BgfNztK10Vl9meMo0y9LcBloyOccqgz dvVqITL+ncC1jD+6MriTGGki29cN+UTROTIgStyQf5onHZ6C7eYbQUgrqcU/F19c YTP6VTT5CeAylNvKaspE58QW7dxdnyQ+FLYgRxNxDz+e41VnZFRC90XPms06FtZh yKPXVTiGszCSXE26lnZGKrUQdJwUFUBXJJ7JQEyyDA6HKkyTgWE0tXdz3It09Avh sdrBLt+iazr9L+F78Wgpssz57POZ4lbWgnF6yX9AoXE+VsRN2mHjBtLbw3K+Y7Vc rdFNQ== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 439t7y0c4h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Dec 2024 23:21:41 -0800 (PST) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 2 Dec 2024 23:21:41 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 2 Dec 2024 23:21:40 -0800 Received: from ubuntu-PowerEdge-T110-II.sclab.marvell.com (unknown [10.106.27.86]) by maili.marvell.com (Postfix) with ESMTP id 620925B6952; Mon, 2 Dec 2024 23:21:40 -0800 (PST) From: Shinas Rasheed To: , CC: , , , , , , , , , , Shinas Rasheed , Veerasenareddy Burru , Satananda Burla , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH net v1 4/4] octeon_ep_vf: remove firmware stats fetch in ndo_get_stats64 Date: Mon, 2 Dec 2024 23:21:30 -0800 Message-ID: <20241203072130.2316913-5-srasheed@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241203072130.2316913-1-srasheed@marvell.com> References: <20241203072130.2316913-1-srasheed@marvell.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: 0Lt8hKUCreRKGll-EGwCY_y_ggtomjBr X-Proofpoint-ORIG-GUID: 0Lt8hKUCreRKGll-EGwCY_y_ggtomjBr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 X-Patchwork-Delegate: kuba@kernel.org The per queue stats are available already and are retrieved from register reads during ndo_get_stats64. The firmware stats fetch call that happens in ndo_get_stats64() is currently not required Fixes: c3fad23cdc06 ("octeon_ep_vf: add support for ndo ops") Signed-off-by: Shinas Rasheed --- drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c index 12b95fb21e64..38e93d79ae59 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c @@ -824,14 +824,6 @@ static void octep_vf_get_stats64(struct net_device *netdev, stats->tx_bytes = tx_bytes; stats->rx_packets = rx_packets; stats->rx_bytes = rx_bytes; - if (!octep_vf_get_if_stats(oct)) { - stats->multicast = oct->iface_rx_stats.mcast_pkts; - stats->rx_errors = oct->iface_rx_stats.err_pkts; - stats->rx_dropped = oct->iface_rx_stats.dropped_pkts_fifo_full + - oct->iface_rx_stats.err_pkts; - stats->rx_missed_errors = oct->iface_rx_stats.dropped_pkts_fifo_full; - stats->tx_dropped = oct->iface_tx_stats.dropped; - } clear_bit(OCTEP_VF_DEV_STATE_READ_STATS, &oct->state); }