From: Sean Anderson <sean.anderson@linux.dev>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, Michal Simek <michal.simek@amd.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Andy Chiu <andy.chiu@sifive.com>,
Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH net v2] net: xilinx: axienet: Fix packet counting
Date: Tue, 10 Sep 2024 10:24:36 -0400 [thread overview]
Message-ID: <318a13f6-da2d-4ba4-a51c-2f8444444bbf@linux.dev> (raw)
In-Reply-To: <20240909180013.4e064fd5@kernel.org>
On 9/9/24 21:00, Jakub Kicinski wrote:
> 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 <sean.anderson@linux.dev>
>
>> 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
I read this but it was unclear to me because it seems oriented towards
"combined" NAPI instances, while we have separate instances for RX and
TX. So even for TX-only instances, we can ignore budget?
>> 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.
The relevant variable (number of descriptors handled) is no longer
returned to axienet_tx_poll, so it can't update the current descriptor
properly.
--Sean
>> + return packets;
>> }
>>
>> /**
next prev parent reply other threads:[~2024-09-10 14:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-06 16:42 [PATCH net v2] net: xilinx: axienet: Fix packet counting Sean Anderson
2024-09-06 17:44 ` Pandey, Radhey Shyam
2024-09-06 17:49 ` Sean Anderson
2024-09-10 1:00 ` Jakub Kicinski
2024-09-10 14:24 ` Sean Anderson [this message]
2024-09-10 14:39 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=318a13f6-da2d-4ba4-a51c-2f8444444bbf@linux.dev \
--to=sean.anderson@linux.dev \
--cc=andy.chiu@sifive.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=radhey.shyam.pandey@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.