Re: [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done()

From: Janis Edvarts Lacis

Date: Mon Nov 16 2026 - 16:43:32 EST


On 16 Nov 02:22, netdev-bot+sashiko@xxxxxxxxxx wrote:
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 (2) · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch uses `budget_left > 0` in spl2sw_rx_poll() as the
only sign that all work is done.
- [Low] The commit message says what changes but not what goes wrong
today.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
spl2sw_remove() frees the descriptor rings and buffers before it…
- [High] This problem wasn't introduced by this patch, but
spl2sw_rx_poll() leaves a broken ring slot behind when it fails to…

--

net: ethernet: sunplus: check budget before calling napi_complete_done()

This commit replaces napi_complete() with napi_complete_done() in the
spl2sw RX and TX poll functions. NAPI is only completed when budget_left
is greater than zero. The RX/TX interrupt is only unmasked when
napi_complete_done() returns true.

Sunplus drivers currently do napi_complete() after each rx/tx poll is
done without checking whether budget was exhausted or not. Interrupts
are also unmasked before the call to napi_complete().

[Severity: Low]
Can the budget actually be exhausted here in normal operation?

spl2sw_probe() registers both NAPI instances with netif_napi_add(), so
they use NAPI_POLL_WEIGHT (64). spl2sw_rx_poll() handles at most
rx_desc_num[0] + rx_desc_num[1] = 32 descriptors per call, because the
inner loop is bounded by num < rx_count. spl2sw_tx_poll() holds tx_lock
and reclaims at most TX_DESC_NUM = 16 descriptors.

That means budget_left is always > 0 for polls from net_rx_action(). The
new check only changes anything for budget 0 (netpoll's poll_one_napi())
or a small busy-poll budget.

In those cases the old napi_complete() already did nothing, because
napi_complete_done() returns false right away when NAPIF_STATE_NPSVC or
NAPIF_STATE_IN_BUSY_POLL is set. The only visible effect of the old code
was that MAC_INT_RX/MAC_INT_TX got unmasked while netpoll or busy-poll
owned the instance.

Netpoll can invoke napi->poll() with budget = 0. In that case,
napi_complete() already returns false because NAPI_STATE_NPSVC is set.
However, the old code ignores its return value and unconditionally
unmasks interrupts.

This patch avoids calling completion with a zero budget and moves
interrupt unmasking after napi_complete_done(), making it conditional
on successful completion, as documented.


Could the commit message describe that actual impact, so the Fixes: tag
and a stable backport can be judged?

I do not have the hardware necessary, this patch is not tested on real
hardware.

This note is in the commit body rather than below the --- line, so it
would end up in git history.

Shouldn't it? Documentation/process/maintainer-netdev.rst, under “Bug fixes”, requires describing how the fix was tested. I included the lack of hardware
testing in the commit message to make it explicit that it has not been
tested on hardware.


diff --git a/drivers/net/ethernet/sunplus/spl2sw_int.c b/drivers/net/ethernet/sunplus/spl2sw_int.c
index a37c9a4c281f0..1aada11429d4d 100644
--- a/drivers/net/ethernet/sunplus/spl2sw_int.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_int.c
@@ -125,13 +125,14 @@ int spl2sw_rx_poll(struct napi_struct *napi, int budget)
h_desc = comm->rx_desc[queue] + rx_pos;
}

- spin_lock_irqsave(&comm->int_mask_lock, flags);
- mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
- mask &= ~MAC_INT_RX;
- writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
- spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+ if (budget_left > 0 && napi_complete_done(napi, budget - budget_left)) {

[Severity: Medium]
Is budget_left > 0 enough to show that all RX work is done? Normal polls
never bring it to 0, but spl2sw_rx_poll() can still stop while completed
descriptors are pending.

The first case is the high-priority early break in the low-priority loop:

if (queue == 1 && !(h_desc->cmd1 & RXD_OWN))
break;

queue 1 is the last queue (RX_DESC_QUEUE_NUM == 2), so this goes straight
to the completion check while new high-priority packets are waiting.

The second case is a queue's inner loop stopping at the ring limit:

for (num = 0; num < rx_count && budget_left; num++) {

Descriptors given back with RXD_OWN earlier in the loop may already have
been refilled by the hardware.

In both cases the poll returns less than budget, calls
napi_complete_done() and clears MAC_INT_RX in L2SW_SW_INT_MASK_0 while
work is still pending. Documentation/networking/napi.rst says a poll with
outstanding work should return exactly budget and not complete.

The cost depends on whether L2SW_SW_INT_STATUS_0 latches RX events while
masked. If it does, this costs an extra interrupt round-trip. If it
doesn't, the pending packets wait for the next RX event.

Would it work better to track these more-work conditions explicitly and
return budget in those cases, instead of relying on budget_left alone?

Agreed. This seems to be a separate issue, the old version also did call
the napi_complete(), even if the work was not 'done'. To fix this, the
solution could be to iterate while budget_left > 0 and one of the queues
has packets to process, but this does seem like a big change that should
not be done by me as I can't test it properly.

Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114222744.535158-1-janislacis06%40gmail.com