From patchwork Tue May 2 22:08:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 89464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp925510vqo; Tue, 2 May 2023 15:12:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QtB1EQwJpX3ERhXOtNO8epod2Sb8xHa13KpfT9tursaWqK68u6tbCP+DazG7wpU0gzvB9 X-Received: by 2002:a17:903:120a:b0:1ab:c48:1de9 with SMTP id l10-20020a170903120a00b001ab0c481de9mr3806345plh.65.1683065545997; Tue, 02 May 2023 15:12:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683065545; cv=pass; d=google.com; s=arc-20160816; b=G33C9NEb3DUO6fR35h+bp4DzWubn8eyqAZH/xHkzEs1ctIgwQ+4a3+CeGvch55c0HD PLSGlAc4V0rAPHaZ4LVaSWKaUMv6H1wed+S/xZgxdQsxLl8PsdCYK4QqhG1vzP9qcxL/ V9YCw/RD/hYRYhs3lGBwA2Zr+wFPSmTxd01pys0O660edhGzPbiAkTUrwdv98UpU+AXs hcBF9NDYL5NtZzkV/v9EzbaLQQB6vn/WO90EUKhm2T3GlTguWxu1Xxy8hMTzFwqYoeH0 n8Tg/0viKwfQPLhYpR+eJcBdLj0LSplGFEy6SfwBslEAcbHZhVT8J9NA3R1mR3T9OFiU Nzkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=w4ZbOXrqg0Z9bC3JJvm08i9JMWY4/r6DFAeHr8jsRxk=; b=zF4oZBpDTbYo71Gq1ki6wIbXHUprPUOz63TdRfsp8rlHXtJ+nwiS4UYWqQiqmqiyJj DVRiboll+oKr9fLRnhThfPyh2kkkb96SDaD00GdfUvBiM2yMNickOK1hEkz8/f39YBGf 7PJHx9xooBn/HzDeo+blfx7o9C2r++2FJzwpBOBRjZ7SDfS5Qij7OtuG9IvqeXBESPpO 3RxkFgf7dZxvgI1aRywEiV0VUVbIz5MP+SCElRLYbeTN73FZ2x6S6IvE2xCYmyRnVtjt wkqwGPjfOwwZB5MR8P8jimhvan/hk6Mldr6yzS+A5MOKNJbMoF95CtiXDrj6770oswfU 1OWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=nBqvhrhg; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a1709028bcb00b001a961300697si24237314plo.589.2023.05.02.15.12.11; Tue, 02 May 2023 15:12:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=nBqvhrhg; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229482AbjEBWIo (ORCPT + 99 others); Tue, 2 May 2023 18:08:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjEBWIm (ORCPT ); Tue, 2 May 2023 18:08:42 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2089.outbound.protection.outlook.com [40.107.20.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34E92198C; Tue, 2 May 2023 15:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m7X8kjZTkBPIaV8XFWQdS0xPLjX8HSOm/qtOY4Mb5hI9i6sYl8PlTzjO/OE8PadLs2lojQtBh8+DiuCnT6Uf/hOPjoeWdNYV6z7sGV0rML1JA0NS3Mw9sLZO99XrDW5FCeEZSiorXGWTy2dE/5sRkX75ajbRxSdKno5j/0S05O1d2f4UjuixaI815kuiW4jLI3CPXe1RMPHGnwziMQq1WShLLtgv+Xy9zf+kEkmhe5qnIHK3Auoqx+2rEqYhCtLGi1wpN1uFMB9Ol8C2xvWgE/TXZ4YgDbL6z2PevsNKP2kNR+4g+vNTqibwnR+UKK75m8O8HEtaUyZ3ym+kkGFYEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=w4ZbOXrqg0Z9bC3JJvm08i9JMWY4/r6DFAeHr8jsRxk=; b=Se6pfkTaKuxaqQ+iiRpz6fTjT4I8KF8ASxEP0wfh5RHI6B+0ODl+AEglJb/voaD5YuuQ5JsRbdd0JQCuiYHD4/ur/fAi5lgn5ZT8/1nTV1DeansoXrCw+DP4RL1qKBbbbibM1slBbYp7uct4TeKWMNOzPDSt2p1eE+4hu7Y+cN9NnRs7CJR5AzAbwidL57r5ynrCfooidbFMMYbYv0xm+zW+FaLPduBtJS/STCJC9SRy89qELiWqpN/bh4kQq/wG/9kEqofUw0L2F+wRx9Dxvhj5xRa/FFK4niPjuflP0X+fPwLXuXhLMbG+gNPh5CjJKTdJuuuzxRHOeHlQktPg/g== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w4ZbOXrqg0Z9bC3JJvm08i9JMWY4/r6DFAeHr8jsRxk=; b=nBqvhrhgtd8ZAM8UKMvhpKJnDz5H1aX7l5TxpsmGzWva4sJ7OqWoFgm0tP/utqALwrU31Vh45TnL5WVjjn7GuHJTin82Z4lL78psKaLsy5tIb5UTFpf5GWpN6/2e9Y78dBtxn2xZyx3rJTaLjfZ68wE9TGwwiOIh2BNGhj/Z47g= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) by PA4PR04MB8016.eurprd04.prod.outlook.com (2603:10a6:102:cb::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 22:08:37 +0000 Received: from PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::28fb:82ec:7a6:62f3]) by PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::28fb:82ec:7a6:62f3%5]) with mapi id 15.20.6340.031; Tue, 2 May 2023 22:08:37 +0000 From: Shenwei Wang To: Wei Fang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Shenwei Wang , Clark Wang , NXP Linux Team , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Alexander Lobakin , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Gagandeep Singh Subject: [PATCH v2 net 1/2] net: fec: correct the counting of XDP sent frames Date: Tue, 2 May 2023 17:08:17 -0500 Message-Id: <20230502220818.691444-1-shenwei.wang@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BY3PR05CA0048.namprd05.prod.outlook.com (2603:10b6:a03:39b::23) To PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9185:EE_|PA4PR04MB8016:EE_ X-MS-Office365-Filtering-Correlation-Id: cd6484fb-6171-446d-88d6-08db4b59c717 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ukEsdoEn8mSp0sGrbKhYPuzCO6BRVXQOFof/YO0ltoUKAGChj1ZUmrv3rTEOmGe/nsbn9tQbVmdTh6LtfKptGRA3LSPu9690k5NBxjQwsB8TEV0LAmExT4tYtmNvJg88FCdFku6USn4eNCnXHDlldZotX/Clu23z+68/oTANJzn7WGMyooKsogVjMOozj2hrKkr/aksI85791+u6g8DajXv6/IfP3OL4i1QAp4tU0qmZfTF/jXpZGZtTt7yphZC6zPWVYmvGz+FOejK5vEjxoczlgZG7MhRLc7qjwgh3dY1Mui/uByksczYBSJjCGGyUGwftx5Ja96RZl8QnT5E3+PgbOTb8gjt4wiUV6UcvXlFBvCL+DqzFwEXiBmLSdpRtmSS0NUNNgsTP4EBFNu/fmCo7nLZ+863+XcqaTlgm76qwxT14/RSpWy+STLLXXKILih8Iz+fzYDh7VcM6B3bLgqTIEO+5ikwFHzG8pRMPlBJ9LIfIJL2aJLwlBcmEu0AMBj2r/fJOiQn4yTpy+5ZnpjPzPGjAOTFauSJNH8vhcsAcmhJEus4iLMXeJ8RzZdEWaHXNk7W2yyRk0BJ8wBCB2jJr6+yYA+pVSLjVYfajlYxMdFjgDVnUW3GbTQHiiLQ6 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9185.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(136003)(376002)(366004)(396003)(451199021)(54906003)(2616005)(478600001)(83380400001)(6486002)(6666004)(6506007)(26005)(1076003)(6512007)(52116002)(110136005)(4326008)(66946007)(66556008)(66476007)(316002)(55236004)(186003)(7416002)(41300700001)(8676002)(5660300002)(8936002)(44832011)(38350700002)(38100700002)(2906002)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q9irMVYgWNQzMg8AH1Z7dKKxyKbhElIWhCSNHgE62holld/dCCG0GJrQY7/HpYpPMGMg0uh2SrurtG+36DkDZVPAEG+P//tIudE3zgoYADd8s5wMFY5ud+btVGOrphxlnD1BNFUwpa2Jmxq+pg+7f5kARbgTVjYzYEC9s04SLt3WvCsMySxmbXdnE5UqUdJ4KhKXBEjCN9ZbpSvQDLTBnTtPzl7+VScTLGCXb+/4dUGZi66b6BMA2rS707mNiJ30ndmHH/ykp2kJ/wuJaaEtm94uWdYNe9us5GRykTAhjTanxUJrsK73KXUeYYJk/7q1gZnHLig7xNjpQFBZ+nXTAHvC9SMFpKZqDI8kNCLvwia/hRvtmbChrRrulxRAK6uvqmPxHZh5kRVUxovn7exrK/k/EgwJL4bjGJ/4JS45lZ5CezwE3bTgjBBgC8IrlDvB5Pm94ePHHlgYyocMJ4KMtCxt0QT8p4fhgp2DcHjMg+MWK5wJ61q+Pm5Q7NU2dFahDkNR6eC4LsbyqlcsM79MwZUh6Cf1EXUxu0GnizrzSLdTloI7s/Pe7+Sxobmfys1NzsdHGeZWciJWpQYWQNmCmJ2jLpbPTE0RUxpFjaYuGAJv+0RgYd35fW4o6tt0xY2JIUtVMe7wlODs0Tvh0J6E72AAV4MHR6u+Tc3ta4FC7mTDPhdmGxSzSq06nzRzbOdVzjBfxCx1mTkX6CuXnB6JVwYzPeM77/RJZ2L6d1lmQ4xCyr4nmg2McBJmtFl8choUzfM32yj/CQnrmcuKzLBqYM/+qC7ik58luQPtzGvXoU46XObNX9PA6D2ZX6W16GYMRazgK08nmIyUqPzAbt18pHl6oo5E3CrCad2DZ7nL8RY6cuPil0z6PkxVsoVE2VkME7xHZzQ23qUWsHell6hq59JX1+QlvUWwxydy8h7iu2xW9EC+w5xtAE1lv0TyVSxfZH30KeH4/wwCl7ihBv4hZ7CbvleUXS6YjrYk2aanss0u61CIE8wkwOgidFK3xBkUc8acnIqpvwTWpuCnT62q9JTQhViOvmYSqpRSfeUdMCaNPIyX+aRGMEkNeCOAJuxEAInTNjEq9MKrbjLCinTuFPSEBaWeuIrGrs1c+FoPDyKAW43e9Z9wu+oYQ+aiL34BguZQRUibfKEJ5WPD4OMQQ9i7uokxMPqiy6Bm2VLoXYq7KSQ7MXnZIhWl4epxsWWZ85tVxDVcwmJfBlRXCwq2hHiJwLrX9AjSmkOgzP6/7k1jxEClUUXczSH9ppmNsphHMD84o4zBIsMHH+T7ai8RW+UQoF/appW8hPcTskG7HpLFofLINKHzbmFvojIOd+zfrH1bnHCMAoG2uIhr58Vpyc/34P21ynOuD+zlIi+2oWDPwwBB+FpyA+VKCrNr0yGiEoOpyaiaXuRlxC7cbZebsbMeOHQNig7Rhk1g1mP72SnUpFI2dGRXOTRyX81fvMGLiq9XrB3bPcFiOXhwrLmWmIIb2bTYjOSkdqJrrK5+cwP7CUVqnlwbjOoQRBA6W/i2qIE3qIil6dZk/3DQy9GGAwG/0NY439lgK7Q5QW5Ifh1zpg6dEwTS8+tfOgqFM2DE X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd6484fb-6171-446d-88d6-08db4b59c717 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9185.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 22:08:36.8719 (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: 2oJIMDiWlqq1OEXQ1mXgZ3Oxvp7XtXkoOgOrzSNZah+jcFBh3v9OKABmnidhCscVr4V4kVfxcNlQHswVWZcA1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB8016 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764822137968306560?= X-GMAIL-MSGID: =?utf-8?q?1764822137968306560?= In the current xdp_xmit implementation, if any single frame fails to transmit due to insufficient buffer descriptors, the function nevertheless reports success in sending all frames. This results in erroneously indicating that frames were transmitted when in fact they were dropped. This patch fixes the issue by ensureing the return value properly indicates the actual number of frames successfully transmitted, rather than potentially reporting success for all frames when some could not transmit. Fixes: 6d6b39f180b8 ("net: fec: add initial XDP support") Signed-off-by: Gagandeep Singh Signed-off-by: Shenwei Wang --- v2: - only keep the bug fix part of codes according to Horatiu's comments. - restructure the functions to avoid the forward declaration. drivers/net/ethernet/freescale/fec_main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) -- 2.34.1 diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 160c1b3525f5..42ec6ca3bf03 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3798,7 +3798,8 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, entries_free = fec_enet_get_free_txdesc_num(txq); if (entries_free < MAX_SKB_FRAGS + 1) { netdev_err(fep->netdev, "NOT enough BD for SG!\n"); - return NETDEV_TX_OK; + xdp_return_frame(frame); + return NETDEV_TX_BUSY; } /* Fill in a Tx ring entry */ @@ -3856,6 +3857,7 @@ static int fec_enet_xdp_xmit(struct net_device *dev, struct fec_enet_private *fep = netdev_priv(dev); struct fec_enet_priv_tx_q *txq; int cpu = smp_processor_id(); + unsigned int sent_frames = 0; struct netdev_queue *nq; unsigned int queue; int i; @@ -3866,8 +3868,11 @@ static int fec_enet_xdp_xmit(struct net_device *dev, __netif_tx_lock(nq, cpu); - for (i = 0; i < num_frames; i++) - fec_enet_txq_xmit_frame(fep, txq, frames[i]); + for (i = 0; i < num_frames; i++) { + if (fec_enet_txq_xmit_frame(fep, txq, frames[i]) != 0) + break; + sent_frames++; + } /* Make sure the update to bdp and tx_skbuff are performed. */ wmb(); @@ -3877,7 +3882,7 @@ static int fec_enet_xdp_xmit(struct net_device *dev, __netif_tx_unlock(nq); - return num_frames; + return sent_frames; } static const struct net_device_ops fec_netdev_ops = {