From patchwork Thu Oct 10 09:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Fang X-Patchwork-Id: 13829862 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013059.outbound.protection.outlook.com [52.101.67.59]) (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 1381D1BBBFE for ; Thu, 10 Oct 2024 09:35:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728552959; cv=fail; b=DwCfU6i7wna+LGJ72kXgwPglQIXRnQjQyVjG7c6oLnb6ZIThRXhJLW0PD4yuI3DSaFdl1mUGKSLn7JvAaLShBRobE41A5YnwEEFFeKGvq4L+yaKmb6PwindTyPdolK/KQTCjrHScF95HTuG+UgppS01JJRSKKMVG7VX3gXhS7YI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728552959; c=relaxed/simple; bh=W7yEJpYb3Pu9CzMvGRlij/dsgM37cXfZu5kHjh1UUZU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Lu/6ShuVdk4M21U2CJdGSXxqw8w+z//9OAW4u3sy8xCJok/JusXqBMgMhHhnZH6hasZkgzO7+q5GtiOmbAIUpuu0jgZeeU7iu5g8jGErHYXNoiMQgWr84raoNf8napjEFhMYEHdlrRV1RZv36aCUEAVBvkzr/Z+nAuGvb+2SGFI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=nlPyGZRf; arc=fail smtp.client-ip=52.101.67.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="nlPyGZRf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=E4/Gm/DHIwq4blZakzLofMsD5PG3mCNoRsZql/50b3AOmEjyvzyMZpAEew41M8yySFUnLWxB3exuQuzeSs53eCINnM9JRSf3Kj6h1qNT6lCSAfiZYQVufZqlea+LKeJmY5Jtfhyc6VIH4txSZYlR2JpbHBIReT3uMec1+I3B/kPIJ912DiHPQVd/q+uZLA2QEfmCDMHd14+XRk4jkPN1INn7TFgFc//DF6lwBiJP294O48nqm78+ePM6k0K6J5O+TOzHwPtS/cL3MhFXpbbyx08MrM5y60iKXu8YKM00xuAAmoIhrFEP64ZnPSFBuL04GCNgDWFD70JYvh+MHQecrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5a0+mRL4Rvw6pF64IM1ITWNwXZ3Cwy27hVi6eNOR7j4=; b=Ph6NxvjB5b9AwfeIaDxe9fCsrfWWrlhRhhDy3sBfyLrfH9sYQMu31jNI0fBOszV6pF9zgJltxns+/tZqcEqi6rHhotTtYyzc02KVErs7JWPIMdMS7sst9NGiWQyqkB8t7MUmsQbyh2gJtcfO33zSxqxHdy+o2Qiw6QvXdYRMGbfOkFG/K/IWpaJYVcHzV8k82a82A9vrtN7RxImuaSP7QjIErUzMcpcf4/nXkwHxiCtVoauaHfURqplJSGwtBcOGGViXjy4sT5sZTfsAR2KZMmfiDMDIzeIYdAMSivGyTd2TivhRkndDH5zXydZa1n3HbGByQz5rGNysgOIuypvz8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5a0+mRL4Rvw6pF64IM1ITWNwXZ3Cwy27hVi6eNOR7j4=; b=nlPyGZRfwZD1A/HSGongaBiF4CB/ZwQWpLNwAmKDOcixAoJYkzJALLGpsI3sGmO2RX8LEtYbZ9p+LYnVu7ZRMYIoBk+6TV2WUBGreLZ+oi6X0GNOE1+QEcjXhBLLBaPWF4wFG6xyMkguPnZECFAPOveHbCO5loV+EjcdMBCilG88gpjj7RepY5bBPZQJh2TulZjHWc0xoVqjzy8lnwYFwWK7sHjlLe+OAmv843ghUk6Pna5LL1tyE3cM4r7E/gxDPDrjZarK85bklF6tq/8sjc/O6G5udllRdk49r16zofuGuSJ2gtTl5I4tW7bWxFUDZpJpPVnIas7JT38BCDW0/g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) by VI0PR04MB10856.eurprd04.prod.outlook.com (2603:10a6:800:267::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Thu, 10 Oct 2024 09:35:53 +0000 Received: from PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db]) by PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db%7]) with mapi id 15.20.8026.019; Thu, 10 Oct 2024 09:35:53 +0000 From: Wei Fang To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, claudiu.manoil@nxp.com, vladimir.oltean@nxp.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org, imx@lists.linux.dev, rkannoth@marvell.com, maciej.fijalkowski@intel.com, sbhatta@marvell.com Subject: [PATCH v4 net 4/4] net: enetc: disable NAPI after all rings are disabled Date: Thu, 10 Oct 2024 17:20:56 +0800 Message-Id: <20241010092056.298128-5-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010092056.298128-1-wei.fang@nxp.com> References: <20241010092056.298128-1-wei.fang@nxp.com> X-ClientProxiedBy: SI2PR01CA0002.apcprd01.prod.exchangelabs.com (2603:1096:4:191::21) To PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8510:EE_|VI0PR04MB10856:EE_ X-MS-Office365-Filtering-Correlation-Id: 9818f9c4-8b3c-45ad-5d41-08dce90eef81 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|52116014|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: wpZFHm31TXjiVFkT2VZayFKNKTW1QK0djibfcOwq/0XXkDwbKMFH0pSNF9qQyWqyWrjYkOrG4wum8QhMd6irMZnz/iQw80oMgT4uiIldVjzglEv7P2piAfG5Bu57qxCpWcDGmMWOuCOhuxqxs3x8UyLlbt+zeqeoDpK3QZmpAlyhnjkZugNxVDHdnii3W4TUFY1/8jVOOT5XoSdoKhctGrEjAgJs9FZvrDyLBcX5BwzE9zXiOLYprfs7P4ZdgU+Gezu1mk7Ilnz7EJl5WCR90YkSyO/LjXppte14nqD5AC9licK2dZ+OpcpuO2p/jR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255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8510.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(52116014)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B48Af+RGk5ALOTsJfkxHyNG1hYpftN/ds7h+xJrvPWBO329+zQ5zD2PlTvbVO3O/kbpRAvSzCovQGwK8T8WMrvy53V3DSIGppzigPdeXpstxgJ7YIQMDqVzVVtohEnQG8gaGEQ6jiGAo97QVBo59ZhTW7yfJvuIPhv3pVE+U0UTZ3fhjcEBnyH3YWtBSQZvBOa8wIOSd6tjMCK5f/Y0d40v6/IXdB9lEnk3U9XJ970CkKWCAzIurv0pPa3p9/TRVyH6b1EY7GM0Vty4D2ojOuOxGMZ/yc7jGIPInV0l7OPoD0xQVl6NTXK/4/+VV8Vos79eTyekxRkm21vE5u8klMm6YMr/X3gQ4NXG6s7BN1aHQ+4LW0bG3Kogp7OljyrYXzikl6zTqqoZmvNCmhNEAA2LO9loCQtbeqB98Es7WbpXNQX98bGRGpKgnumtUcOsTm7xvAk/Q56HUBVF0SfhT0spj4QWAYLKcdI8S7XzZcyDQ3h9+4I9Eu+g7KfY57GlqKWR88mi7DRLuM5NONWffBck8dwa9yG2siT0x+2Zl13ZACkD9EZXW5pM59EJSLWCaIQXeKl7C8JgYlHBTLhs1ca8aZdj6A1LFtai0xZ/8bDuin8/21y8w+Ph6c5osM3tlH5bjdVoj3q9Uw+OsuXVsutmjIHLu/Oyvy5ARbtF86QF/+SUIabkJgoi1MCODm57DgXR7yfHg3Vvkgd/lW0xG0JaPwvlDfXUXfR4Q9t5pGa9El0jRKVqNWQsdqdw2OiNFuv+p5LSLCTTMeB/K0QauZym6pVmC0OhEh/y5sJXiZWZLxGJq5hyO+BKQOlHHxVD5LfHuBdWoQgpqqs4D4A/QUw1Vxn7F7/BSQOlHIX5K1N/bVhsiwnyVd7VODlYU/qxHH5u+/G4Wh/NDPBnd62Raz4xK+xBKEiIdWbMhnInrxu07RxtAPeFirmp3kdA/NQE7Sc9mK+QIabSltzYwPn6WnU+RH0931TvCgJGSIhp60xfZppx5mRD+WM6Zf9PTbIu2HCNYNQ/8jF27DaxW94wLvi+URZuPvbj/570/3C4mWm3WPXOuHCN6XWQDOfa/TLK3w3BZKIf9jP6MtLregaWniZgdXVoVkJJ7yEnah3Da7dc2q5J7RMugGNP7i/D8sHoKLv2QYajfYGPUX51NYlDvoKKhN/oimEKGmvAsA+EMs3AZ1xiHVtrygeZSWzNd80SmhkjjKg3Q9nt4OXzPJgr7Tgchl4TiTk53PcDtWbdJLnYqY68KrkmRpDkDvfL4GP48CDgl4EPP6g8ZzXgaNyXGwaoqN1HgZHLdkjWOipgh1V8znsEkuOc+DTKXq9X+qEqzG0W3rVW5NBO/MnfPhnl7VBfpmakuUo99mIpKmaKqoU/4MQZmwCzf+TFgJyyTJ6H7UGX3f/puOasBqyNea+MswlOw2g4avsuNG4Czk/+0mm9Ki0ua0la5FP7t2Jsf8FR42vsHZv17jYpMRE3W+AmpIQ5J1FDFNu4nIx/ZRCoS8iRsxMMzh/Hk4fM9ecB+H1pfH3jB/F1nGUEh9x1cZZJgbPwr6KFFnYYFY1GeZRYITuT8b5GtJOb6nAaTVAHQvzoM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9818f9c4-8b3c-45ad-5d41-08dce90eef81 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 09:35:53.9062 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5Y8BrQL1m3jsuCTyKcLY7fl+EfEb2v0TpsbzTXVKToJiVDE11CSHI5ECsPW3vNxJaXlEdYMltFS28sRJVgSK8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR04MB10856 When running "xdp-bench tx eno0" to test the XDP_TX feature of ENETC on LS1028A, it was found that if the command was re-run multiple times, Rx could not receive the frames, and the result of xdp-bench showed that the rx rate was 0. root@ls1028ardb:~# ./xdp-bench tx eno0 Hairpinning (XDP_TX) packets on eno0 (ifindex 3; driver fsl_enetc) Summary 2046 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s Summary 0 rx/s 0 err,drop/s By observing the Rx PIR and CIR registers, CIR is always 0x7FF and PIR is always 0x7FE, which means that the Rx ring is full and can no longer accommodate other Rx frames. Therefore, the problem is caused by the Rx BD ring not being cleaned up. Further analysis of the code revealed that the Rx BD ring will only be cleaned if the "cleaned_cnt > xdp_tx_in_flight" condition is met. Therefore, some debug logs were added to the driver and the current values of cleaned_cnt and xdp_tx_in_flight were printed when the Rx BD ring was full. The logs are as follows. [ 178.762419] [XDP TX] >> cleaned_cnt:1728, xdp_tx_in_flight:2140 [ 178.771387] [XDP TX] >> cleaned_cnt:1941, xdp_tx_in_flight:2110 [ 178.776058] [XDP TX] >> cleaned_cnt:1792, xdp_tx_in_flight:2110 From the results, the max value of xdp_tx_in_flight has reached 2140. However, the size of the Rx BD ring is only 2048. So xdp_tx_in_flight did not drop to 0 after enetc_stop() is called and the driver does not clear it. The root cause is that NAPI is disabled too aggressively, without having waited for the pending XDP_TX frames to be transmitted, and their buffers recycled, so that xdp_tx_in_flight cannot naturally drop to 0. Later, enetc_free_tx_ring() does free those stale, unsent XDP_TX packets, but it is not coded up to also reset xdp_tx_in_flight, hence the manifestation of the bug. One option would be to cover this extra condition in enetc_free_tx_ring(), but now that the ENETC_TX_DOWN exists, we have created a window at the beginning of enetc_stop() where NAPI can still be scheduled, but any concurrent enqueue will be blocked. Therefore, enetc_wait_bdrs() and enetc_disable_tx_bdrs() can be called with NAPI still scheduled, and it is guaranteed that this will not wait indefinitely, but instead give us an indication that the pending TX frames have orderly dropped to zero. Only then should we call napi_disable(). This way, enetc_free_tx_ring() becomes entirely redundant and can be dropped as part of subsequent cleanup. The change also refactors enetc_start() so that it looks like the mirror opposite procedure of enetc_stop(). Fixes: ff58fda09096 ("net: enetc: prioritize ability to go down over packet processing") Cc: stable@vger.kernel.org Signed-off-by: Wei Fang Reviewed-by: Vladimir Oltean Tested-by: Vladimir Oltean --- v2 changes: 1. Modify the titile and rephrase the commit meesage. 2. Use the new solution as described in the title v3: no changes. v4 changes: 1. Modify the title and rephrase the commit message. --- drivers/net/ethernet/freescale/enetc/enetc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 52da10f62430..c09370eab319 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -2474,8 +2474,6 @@ void enetc_start(struct net_device *ndev) enetc_setup_interrupts(priv); - enetc_enable_tx_bdrs(priv); - for (i = 0; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev, ENETC_BDR_INT_BASE_IDX + i); @@ -2484,6 +2482,8 @@ void enetc_start(struct net_device *ndev) enable_irq(irq); } + enetc_enable_tx_bdrs(priv); + enetc_enable_rx_bdrs(priv); netif_tx_start_all_queues(ndev); @@ -2552,6 +2552,10 @@ void enetc_stop(struct net_device *ndev) enetc_disable_rx_bdrs(priv); + enetc_wait_bdrs(priv); + + enetc_disable_tx_bdrs(priv); + for (i = 0; i < priv->bdr_int_num; i++) { int irq = pci_irq_vector(priv->si->pdev, ENETC_BDR_INT_BASE_IDX + i); @@ -2561,10 +2565,6 @@ void enetc_stop(struct net_device *ndev) napi_disable(&priv->int_vector[i]->napi); } - enetc_wait_bdrs(priv); - - enetc_disable_tx_bdrs(priv); - enetc_clear_interrupts(priv); } EXPORT_SYMBOL_GPL(enetc_stop);