Skip to contentSkip to conversation

net: axienet: cap the TX poll return value at the NAPI budget

PATCH In review Sagi Maimon 4 participants 5 messages Sep 30 – Oct 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 net: axienet: cap the TX poll return value at the NAPI budget

axienet_tx_poll() reclaims every completed TX descriptor in one pass:
it passes lp->tx_bd_num to axienet_free_tx_chain() as the descriptor limit, and @budget is only used as the napi_consume_skb() bulk-free hint. It then returns the number of packets reclaimed, which is bounded by the ring size rather than by the budget, so the poll can report more work than it was given. This was seen after TX completion interrupts had not been taken for a while and a full ring was reclaimed at once:

eth0: NAPI poll function axienet_tx_poll+0x0/0x180 [xilinx_emac]
returned 96, exceeding its budget of 64.

netpoll is affected as well. poll_one_napi() polls with a budget of 0 to reclaim the TX path only, and warns once if any work is reported.

Keep reclaiming the whole ring and cap only the value returned. Documentation/networking/napi.rst allows a poll to process any number of TX completions; it is the reported work that must stay within the budget. Stopping the reclaim at the budget instead would also leave completed descriptors for a later poll, which does not come when napi_disable() is pending. When more than @budget packets were reclaimed, returning @budget keeps the poll scheduled, and the next poll completes NAPI and re-enables the interrupt as before. A budget of 0 now yields 0.

Fixes 5a6caa2cfabb ("net: xilinx: axienet: Fix packet counting")
Assisted-by LLM sparse

---

Notes:
Changes in v4:
- Different approach, as Paolo Abeni and the review of v3 suggested:
keep reclaiming the whole ring and cap only the value returned, instead of stopping the reclaim at the budget. napi.rst allows any number of TX completions per poll, and stopping early could leave completed descriptors behind while napi_disable() is pending.
- Subject changed to match; v1-v3 were "net: axienet: bound TX completion cleanup by the NAPI budget".
- Fixes: now names 5a6caa2cfabb, which made the return value unbounded (review of v3).
- Only axienet_tx_poll() and its kernel-doc change now.
- Suggested-by: Paolo Abeni.
- Build-tested only so far; v3 was tested on hardware, v4 not yet.
- v3: https://lore.kernel.org/netdev/[email protected]/

Changes in v3:
- Report no work for a budget of 0, so netpoll cannot trip the WARN_ONCE() in poll_one_napi().
- Add the Assisted-by: tag that v1 and v2 omitted.
- v2: https://lore.kernel.org/netdev/[email protected]/

Changes in v2:
- Treat a budget of 0 as no limit, so that netpoll still drains the TX ring.
- v1: https://lore.kernel.org/netdev/[email protected]/

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +8 -3
index 1722b7038f34..243b07fd5be8 100644
@@ -984,9 +984,9 @@ axienet_start_xmit_dmaengine(struct sk_buff *skb, struct net_device *ndev)
  * axienet_tx_poll - Invoked once a transmit is completed by the
  * Axi DMA Tx channel.
  * @napi:	Pointer to NAPI structure.
- * @budget:	Max number of TX packets to process.
+ * @budget:	NAPI budget, or 0 when polled by netpoll.
  *
- * Return: Number of TX packets processed.
+ * Return: Number of TX packets processed, capped at @budget.
  *
  * This function is invoked from the NAPI processing to notify the completion
  * of transmit operation. It clears fields in the corresponding Tx BDs and
@@ -1027,7 +1027,12 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget)
 		axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr);
 		spin_unlock_irq(&lp->tx_cr_lock);
 	}
-	return packets;
+
+	/* The whole ring was reclaimed above, which may be more than the
+	 * budget, but a poll must not report more work than it was given.
+	 * netpoll polls with a budget of 0 and expects no work reported.
+	 */
+	return min(packets, budget);
 }
 
 /**

base-commit: a7bfaba4823e3c165bb2004c74eff7c096672bc7

Signature · 1 line
2.47.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

Reviewed-by on v4 1/1
#2 lore raw
In reply to Sagi Maimon
Quoted 24 lines · Sagi Maimon

axienet_tx_poll() reclaims every completed TX descriptor in one pass:
it passes lp->tx_bd_num to axienet_free_tx_chain() as the descriptor limit, and @budget is only used as the napi_consume_skb() bulk-free hint. It then returns the number of packets reclaimed, which is bounded by the ring size rather than by the budget, so the poll can report more work than it was given. This was seen after TX completion interrupts had not been taken for a while and a full ring was reclaimed at once:

eth0: NAPI poll function axienet_tx_poll+0x0/0x180 [xilinx_emac]
returned 96, exceeding its budget of 64.

netpoll is affected as well. poll_one_napi() polls with a budget of 0 to reclaim the TX path only, and warns once if any work is reported.

Keep reclaiming the whole ring and cap only the value returned. Documentation/networking/napi.rst allows a poll to process any number of TX completions; it is the reported work that must stay within the budget. Stopping the reclaim at the budget instead would also leave completed descriptors for a later poll, which does not come when napi_disable() is pending. When more than @budget packets were reclaimed, returning @budget keeps the poll scheduled, and the next poll completes NAPI and re-enables the interrupt as before. A budget of 0 now yields 0.

Quoted 6 lines
Fixes 5a6caa2cfabb ("net: xilinx: axienet: Fix packet counting")
Assisted-by LLM sparse

---

LGTM

Thanks,
Suraj

Quoted 62 lines

Notes:
Changes in v4:
- Different approach, as Paolo Abeni and the review of v3 suggested:
keep reclaiming the whole ring and cap only the value returned, instead of stopping the reclaim at the budget. napi.rst allows any number of TX completions per poll, and stopping early could leave completed descriptors behind while napi_disable() is pending.
- Subject changed to match; v1-v3 were "net: axienet: bound TX completion cleanup by the NAPI budget".
- Fixes: now names 5a6caa2cfabb, which made the return value unbounded (review of v3).
- Only axienet_tx_poll() and its kernel-doc change now.
- Suggested-by: Paolo Abeni.
- Build-tested only so far; v3 was tested on hardware, v4 not yet.
- v3: https://lore.kernel.org/netdev/[email protected]/

Changes in v3:
- Report no work for a budget of 0, so netpoll cannot trip the WARN_ONCE() in poll_one_napi().
- Add the Assisted-by: tag that v1 and v2 omitted.
- v2: https://lore.kernel.org/netdev/[email protected]/

Changes in v2:
- Treat a budget of 0 as no limit, so that netpoll still drains the TX ring.
- v1: https://lore.kernel.org/netdev/[email protected]/

  drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +8 -3
index 1722b7038f34..243b07fd5be8 100644
@@ -984,9 +984,9 @@ axienet_start_xmit_dmaengine(struct sk_buff *skb, struct net_device *ndev)
   * axienet_tx_poll - Invoked once a transmit is completed by the
   * Axi DMA Tx channel.
   * @napi:	Pointer to NAPI structure.
- * @budget:	Max number of TX packets to process.
+ * @budget:	NAPI budget, or 0 when polled by netpoll.
   *
- * Return: Number of TX packets processed.
+ * Return: Number of TX packets processed, capped at @budget.
   *
   * This function is invoked from the NAPI processing to notify the completion
   * of transmit operation. It clears fields in the corresponding Tx BDs and
@@ -1027,7 +1027,12 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget)
  		axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr);
  		spin_unlock_irq(&lp->tx_cr_lock);
  	}
-	return packets;
+
+	/* The whole ring was reclaimed above, which may be more than the
+	 * budget, but a poll must not report more work than it was given.
+	 * netpoll polls with a budget of 0 and expects no work reported.
+	 */
+	return min(packets, budget);
  }
 
  /**

base-commit: a7bfaba4823e3c165bb2004c74eff7c096672bc7

maintainer
#3 lore raw
In reply to Sagi Maimon

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_tx_poll(struct napi_struct *napi, int budget) · line 1035

Quoted 11 lines · On Wed, 30 Sep 2026 10:15:36 +0300 Sagi Maimon wrote:
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -1
@@ -1027,7 +1027,12 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget)
 		axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr);
 		spin_unlock_irq(&lp->tx_cr_lock);
 	}
-	return packets;
+
+	/* The whole ring was reclaimed above, which may be more than the
+	 * budget, but a poll must not report more work than it was given.
+	 * netpoll polls with a budget of 0 and expects no work reported.
+	 */
+	return min(packets, budget);

Please take a look at commit a58cdf56b6e, that's the correct approach (incl. feeding 0 to napi_complete_done).

Signature · 1 line
pw-bot: cr
#4 lore raw
Quoted 16 lines · Jakub Kicinski

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_tx_poll(struct napi_struct *napi, int budget) · line 1035

Quoted 11 lines · On Wed, 30 Sep 2026 10:15:36 +0300 Sagi Maimon wrote:
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -1
@@ -1027,7 +1027,12 @@ static int axienet_tx_poll(struct napi_struct *napi, int budget)
              axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr);
              spin_unlock_irq(&lp->tx_cr_lock);
      }
-     return packets;
+
+     /* The whole ring was reclaimed above, which may be more than the
+      * budget, but a poll must not report more work than it was given.
+      * netpoll polls with a budget of 0 and expects no work reported.
+      */
+     return min(packets, budget);

Please take a look at commit a58cdf56b6e, that's the correct approach (incl. feeding 0 to napi_complete_done).

Thanks, that is cleaner. v5 does the same: it reclaims the ring, completes with napi_complete_done(napi, 0) when budget is non-zero, re-enables the TX interrupt and returns 0. It is posted as "net:
axienet: do not report TX completions as NAPI work".

Sagi

pw-bot: cr

Quoted 2 lines

--
pw-bot: cr