From patchwork Thu May 4 15:35: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: 90128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp417611vqo; Thu, 4 May 2023 08:42:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4k1laQpanznLWYLYM477VlcbswPpZpzGbDPHGNNsNGvdvM7PhRM7CfWYt8qOf8KxEUOcXz X-Received: by 2002:a05:6a20:3d8c:b0:f3:c08:cdef with SMTP id s12-20020a056a203d8c00b000f30c08cdefmr3294056pzi.58.1683214941967; Thu, 04 May 2023 08:42:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683214941; cv=pass; d=google.com; s=arc-20160816; b=Ei5sH5Njz2UhYqWwXCFpIWghMS+KlREnv4o3cmFVFSPjP/usChuamxvmvqPHlXDyIk +StPWDEpD8CDdrDLkA0mPRJo2Qy08zEKm63u/UZSwM/+pUIISw5Zv3iuphMi0+QOMIiF lUzLZPXSx87Bj374xkz8u3MK/as3LH9GRlQCJLYGIkV/178sx5Jrgn9VoXVeOeoZ2RVG JyiYkT5rEm4ZqpT4nKm9jCYqGMu2RiQXdSIsUaE4LKC+hGw0CQx7nMC+JORQcjHbynFQ oLqryo3Yqxr7K+RbI6x3kIQi+sezxDBzUGF5gQNew2Y9JUmjdPjOrgELDLGMGcZn2gCb 58jQ== 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=1JAvUmbK2XBC5GjxHBQdwJN4Yw6X4HgzA0V6CVFo9Ig=; b=m6AH2OyfmHaw3VtWjRyvdEAZsJIZcq9RjGGfSL8cj3aDZSppmpoODKPuV27wc9byNr BlKj8NC81z/4gts+xT1BI69D0kJxgeqe/4KMEhLf0mMzFeGGOr4kOUGYQi9xNnZwyGRg rZiwDQJwl+Gj5P6fhIEkczmSArHhj3nf9aVYJ0tbuSATnVBO49XoY/URPM/x0dAi4CDC YfZxJ0VL/vVrS3Comb+iWjFqjiJQVhAn3bxVRcl3PLa2q69mGv1BeNKzUizblKXBIANZ BAXKSaYjVW/aSbpCETn/RDgdD6MUKYILYy8KocDXVcd4nlxaQZRrTxeX9JF5EqqEZK0Y 29fQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=HYxHSaXc; 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 u63-20020a638542000000b004fae5f0895dsi30606280pgd.45.2023.05.04.08.42.08; Thu, 04 May 2023 08:42:21 -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=HYxHSaXc; 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 S231437AbjEDPfo (ORCPT + 99 others); Thu, 4 May 2023 11:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjEDPfm (ORCPT ); Thu, 4 May 2023 11:35:42 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2087.outbound.protection.outlook.com [40.107.8.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6C72E40; Thu, 4 May 2023 08:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V/aaibR+kK8cF7CMxP2DpPhjfQmPAqPe5p57NJzBKLxFqJ1BXk0pFXLE0PMTGOqkY+fhUOmk/pQj9XLFH37HwujxxbWmPIrLu5tt80PeX8v+ExdAi2B7alJKZJBZMPkUF0Gn/7xP7W5paNCT2dMn0/VF9GyjZlJG9oqtNonaomOoweos+pak20B1VyJdX9up2EDmRhOoGoyMGsXvvqrJfxINZzrBZRgKf8Ath5evxig/Y8IYv2aRtzxACrZNXPJRi/L2irnWahzdagQmSPrNzH/dDx70jkn8DZdLbi82JV4zNfZnrY7Whi7eOkIpw0V7CnjeV0bxgIBamBcQyc/fjg== 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=1JAvUmbK2XBC5GjxHBQdwJN4Yw6X4HgzA0V6CVFo9Ig=; b=oLf77msRhUmD1Wsmme3uIKnTLT87RgdgfqjIWtJZaqdP4zVAwLJFturbP9iRNvaVEo1rOJ5Jd8LbNdnTEzHnA+Sd4TTVWL+MMwwdpgtHesJLHhk1mLqHEFskVT8daj81Nr1vV2vlJRIooRlyiR9osz8x24iot65mAs6nnYnDdFiCycapbxRbBKIYRmBdipQFpHA+ZZbhGl7LQwgCq9qi2e42PV1QUfuk9FDeB1oACVX+WPY249pwZRBbcPYjpbmnQFQhwX2b6NoTeA22jikJkLyH/XWloBL2ZyPKxOMPqFEz8I2YX37d68o5eW8atFeWwW9kkD3DCH16rjqF1mIsVQ== 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=1JAvUmbK2XBC5GjxHBQdwJN4Yw6X4HgzA0V6CVFo9Ig=; b=HYxHSaXcjAaGmWLQetEXKZhb7j/RyjG1snDm8/rTDGjb8doJwhw0dTzKr0eoVwoSP6BN4n8a4/BfLBufMKblzq6ZHkqxw3+fLpnNhbZM2frrs29GH1YIyBtAJi/RYeivrphp2/gJzLx5CUpMQrVTeM0cz5gzNMchiP8VQO8hrjc= 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 VE1PR04MB7245.eurprd04.prod.outlook.com (2603:10a6:800:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.26; Thu, 4 May 2023 15:35:38 +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.6363.022; Thu, 4 May 2023 15:35:38 +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 v3 net 1/1] net: fec: correct the counting of XDP sent frames Date: Thu, 4 May 2023 10:35:17 -0500 Message-Id: <20230504153517.816636-1-shenwei.wang@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BYAPR05CA0060.namprd05.prod.outlook.com (2603:10b6:a03:74::37) To PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9185:EE_|VE1PR04MB7245:EE_ X-MS-Office365-Filtering-Correlation-Id: 92e17222-5a23-441b-cd58-08db4cb5361a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jLdrwbpNG5MIzVC2laVhdkMLYpLglpSKY8ucUz9hHq/Sxb6PGYaX8iOmxzjPD4zffZ9L0MCFpmqHvDnYadJMWNGGjj8i/pNT2oasEekYpqfV7WJonk5EzjRdoe4upVIftGl1mR0JtDGWVBygTZ3/eUdW6zb+LWmPbGVlPiVzAIU88ns/Aua2cP4XYoJJSA2CaV5NMFRcl0ZhPCyWEKqnCiyoujXUfbbd0E8l0FzO2B9SN2qDWmO1Xdi7Gro6Mo5BosaHzq8gSV2hby/RWuVtV+AR4b+9FqgH4nbNtbxJb7P8w9PTWkw678hqSawtmSQ06JSMxHb7RywTRG9j0x3nFSRuuMPLn2ETQ4szBjRZafJ9zu4L/ZCjqX1drzQgpjhV+Um1EKf9tNwBfK/2KV9Q6Jn8/016mdo2ucaF+HNFZaTlIuMZpzohD4LT+tseex0HlC/hCekTyqNRMuJhLY8czUqtcFSBUmS5bm2WZwqlAm73wqj8oyVdndLym763pBnQHHMQ3zgLjLJPlCZkEsksc2LQvfK3DlA1gfhlZ100/USmscQzT4Uq3KOOJZbdMTtWc2+oasPBjO2SqlQbKja06KfUoB/qA09GITytgEg5g1kjRhX7yFKxzgyzzEycGDOM 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)(376002)(346002)(366004)(39860400002)(136003)(396003)(451199021)(38100700002)(6666004)(38350700002)(110136005)(478600001)(86362001)(83380400001)(55236004)(26005)(1076003)(186003)(6506007)(6512007)(2616005)(36756003)(6486002)(52116002)(54906003)(5660300002)(8676002)(41300700001)(8936002)(44832011)(7416002)(2906002)(66556008)(316002)(66476007)(66946007)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0YDjKE+g1xxwAApswedzZo2yEbWF2ZEvaW076N6Q2mNeZ5YD7yKisYoEzGkkSNDekHsf5N82DiVLEADhyWtiua6xxdyboJlTpgyResQ4Vqo1RcRkMsbnsIW0ahbONmxEe8HM1KgaESruHJKTcqvZeP0KMQVDqLYqA379cCwbVWgDo2POPxzdJWnJlyKEbaZCbL+QMhVeF4RtCWepmqJfOpBzHrb4NpKtlcJOED3XoXe97o+1eb7VRA8JBwQv6AHb35xFKyzdqiT9TWHDCbySHMUDwS6Gh/6iYgrTB05O6cftFOASQiz2DSorGTLnO2p43nFgFG85Ejfi1gT+CyxZdog8fONhXLHyO9zUGDRzvFQShwMtHfhFFwUIIEGnAQrbCFS7/o1wOEkkqmw0lRpN0F7Vysl7izl6axTRu0V6dMJi/sw30W9eNpJvptY1GnnUUmQdCW4fXvG39DMePFLkyk4i1/6qy7ZM8XTfzzM2Lj+5JRqHqjH5iXvGyaXQgktbGHcGEKPnxJZuYsaMPdxm0vPQosm+8OC9S+R8CHrbiBOhkJElk2Cdckf6p67r2mCqkWN7xcWPzKQDWLw8lKfc27bVQaKn8jA1MEZfECLEc5mR53/c5nEcOLIc7+JkvV/8ImdOSfbYTVY/IcASNdoYGwAE13Kmrfq8UK1DzdrnrW2ZnqTW0ex3rXcRMeD63K+KJqEClhakeyq3cmQh74fc/fQz/nPSQcuGT0N4Kh+IjBaSzx8fONdTIIlMAEfZsGWkmHHbYrhRawZ+y2+aOw2zXWuOqrI5xB5eHW8SY3arGeIYABGIxt7LUv8Jn4Aaj6uVrQIwTwlbZ/CzGg6pR2qcXyySo1Gcj/PtOi4Jc95YBU9M5AcE4yh8JD16BZ55Q0N6/FC12mbSfonOTekMOPvWPgAwUMx5RX59zpVIotY8wwR14iL2uklSLezle3rqACopJnd44ZtZnRZDhpPkSysTCqpCaXHqOvtUat0n6yTYE72O55U+25b7MkmVDx7glBgvziD1VNYyy0+91XP7XAgxNuQo/UkIOOxbx7q2jz6Y7NmDszCUxWLm24B8h64NhIylMmp5kOj3quqwcGyG5QWrkvr1cyqvYiKQ774x99Y9OLxjbOjFGnwYHiuYZ931h9GWH77ktaH95SCIZM4h6ytc4JhkKiKxtyhEARtDIXcHxLMWJzU/O41zL78AKr3wgwb6bgMTVr3Ie+BlIbmO3yw9nACGnQA+bhSxK/tLZ9Nxlexi4k9CLDdboVpdsxLGVz0/eLPgAKYLdpPxfAKZsOwE160A22oQ5coqvIkWEcGRH9L06CMbu8VPWzyWhk1Nb/MCSmGCJkSnPTbj3lEVY4Gupeh8L8fLMerW5FZy+MS6SUpih+DwscUdgtHaW87LUA5xdvM4y/UVIUksYLZd2yJFwtfQn2mxEjW8gsovBj6FG3NZvDH1S3i8Ji5v+CAzg52ALFCBlTBqkV9j2TN5PfYdKKXn8+j64ReTcYTMUJax3bSe9nKzNEDqoveQYqiq8RHfxvYpLhMSSNW2GMyOVY+vDofMwQMftOWKURFpqTPHJ1VRuhPM1mTGa1c7RyH38xZ7 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92e17222-5a23-441b-cd58-08db4cb5361a X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9185.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2023 15:35:38.6296 (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: 7W7+hYC1BW2/zGIwvT8zeJ/VlAE1oVyDxD88JvukNOaHhQMgqdiAAknR5AJduJUWgXuclOSzOoKwJzfxAHEQIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7245 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, URIBL_BLOCKED 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?1764978790942543365?= X-GMAIL-MSGID: =?utf-8?q?1764978790942543365?= 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 Reviewed-by: Leon Romanovsky --- v3: - resend the v2 fix for "net" as the standalone patch. 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 = {