From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC868EDE984 for ; Tue, 10 Sep 2024 01:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=x8LWTaVZ8tlenxBXctbKWGhmw6qTBWXQHf1Ys5ileH0=; b=N6JRHukXJ1QW+UDzTv88DTl6WL p1oO2Sm5QTPlWlC14Gs1N4txyL1SIIc7hZH5Q+LlrAxub37g52IvjiESZcKrf/BqWwAe9qeHPa0aK PP+IpOSBne+ylkOoK6KOLav5TfySc8vaF7huSYn3wWj2NI2Rt+/11XgIc2C6aYLvSs/W6Jd01wgDV hzDiBGivcQrrsfL1YekhDdEF6evEO+Sd9SaTjgKredLQdhEsuYfSUkz1T186xxfShSuXni0sypu4b TkezgLC+tvCJjmHoOVtMoRZ0AjCfsPYGCyNrZk3xyKQnOsQJMCETkd/ohjwX4BwqSSccE6wcCjvDx C7w+Jtsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snpFv-00000003kBR-3XlS; Tue, 10 Sep 2024 01:01:19 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1snpEu-00000003k3N-1AQQ for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2024 01:00:17 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1F6E55C028F; Tue, 10 Sep 2024 01:00:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B558AC4CEC5; Tue, 10 Sep 2024 01:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725930015; bh=SUdXRn9fT8xAK9XCVBGuRHOj94ZKDCFNTwX+df/geuM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TJKQwfWr1s/IiWCJ9IX8tXA55cfO5GmNez7wRtwzDX1v/x/RpQWrpOXSVqM+M5Sho ewAWblGD9FetgxKsyGEXuoFOlCBMwUjjNiWuwIVzDWhFr2HKuS4WYIPaEXZwATaXKO SbWIDTK8uFCE9m9RqBjVmq2QRrh3Hj0FxI4aLazPCgxV1mJzuRkruT+BD4Yi5dVZ+S cKDy3qUqmjknryi2j4DhgdDEktM+fra0o2Qii+QhGXumfwNgpkErZ/4Guvr1KZUwql tpURNxPTCIjb0dhaekANCUy3YvMCD6xjjHzsSugfAoKmDKvn2Dda3lhShsfRqj49pl /fnWZZRCVZfTg== Date: Mon, 9 Sep 2024 18:00:13 -0700 From: Jakub Kicinski To: Sean Anderson Cc: Radhey Shyam Pandey , "David S . Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, Michal Simek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andy Chiu , Daniel Borkmann Subject: Re: [PATCH net v2] net: xilinx: axienet: Fix packet counting Message-ID: <20240909180013.4e064fd5@kernel.org> In-Reply-To: <20240906164227.505984-1-sean.anderson@linux.dev> References: <20240906164227.505984-1-sean.anderson@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_180016_461128_845EB10C X-CRM114-Status: GOOD ( 23.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 6 Sep 2024 12:42:27 -0400 Sean Anderson wrote: > axienet_free_tx_chain returns the number of DMA descriptors it's > handled. However, axienet_tx_poll treats the return as the number of > packets. When scatter-gather SKBs are enabled, a single packet may use > multiple DMA descriptors, which causes incorrect packet counts. Fix this > by explicitly keepting track of the number of packets processed as > separate from the DMA descriptors. > > Fixes: 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver") > Signed-off-by: Sean Anderson > diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > index 9aeb7b9f3ae4..556033849d55 100644 > --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > @@ -670,21 +670,21 @@ static int axienet_device_reset(struct net_device *ndev) > * @force: Whether to clean descriptors even if not complete > * @sizep: Pointer to a u32 filled with the total sum of all bytes > * in all cleaned-up descriptors. Ignored if NULL. > - * @budget: NAPI budget (use 0 when not called from NAPI poll) > + * @budget: NAPI budget (use INT_MAX when not called from NAPI poll) use INT_MAX and force=true when ... ? To make sure the dependency is clear. But actually... > * > * Would either be called after a successful transmit operation, or after > * there was an error when setting up the chain. > - * Returns the number of descriptors handled. > + * Returns the number of packets handled. > */ > static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd, > int nr_bds, bool force, u32 *sizep, int budget) > { > struct axidma_bd *cur_p; > unsigned int status; > + int i, packets = 0; > dma_addr_t phys; > - int i; > > - for (i = 0; i < nr_bds; i++) { > + for (i = 0; i < nr_bds && packets < budget; i++) { why are you doing this? To make sure drivers doesn't complete more than "budget" Tx skbs? The budget is really for Rx, for Tx you can use a reasonable fixed value, independent of what budget core passes in, e.g. 128. See: https://www.kernel.org/doc/html/next/networking/napi.html#datapath-api > cur_p = &lp->tx_bd_v[(first_bd + i) % lp->tx_bd_num]; > status = cur_p->status; > > @@ -701,8 +701,10 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd, > (cur_p->cntrl & XAXIDMA_BD_CTRL_LENGTH_MASK), > DMA_TO_DEVICE); > > - if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK)) > - napi_consume_skb(cur_p->skb, budget); > + if (cur_p->skb && (status & XAXIDMA_BD_STS_COMPLETE_MASK)) { > + napi_consume_skb(cur_p->skb, force ? 0 : budget); > + packets++; > + } > > cur_p->app0 = 0; > cur_p->app1 = 0; > @@ -718,7 +720,13 @@ static int axienet_free_tx_chain(struct axienet_local *lp, u32 first_bd, > *sizep += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK; > } > > - return i; > + if (!force) { > + lp->tx_bd_ci += i; > + if (lp->tx_bd_ci >= lp->tx_bd_num) > + lp->tx_bd_ci %= lp->tx_bd_num; > + } Moving this chunk into axienet_free_tx_chain() is a noop, right? Please avoid code cleanups in fixes. > + return packets; > } > > /** -- pw-bot: cr