From: netdev-bot+sashiko@kernel.org
To: janislacis06@gmail.com
Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, wellslutw@gmail.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done()
Date: Mon, 16 Nov 2026 02:22:57 +0000 [thread overview]
Message-ID: <179479577764.3136.18033299607451586926@kernel.org> (raw)
In-Reply-To: <20261114222744.535158-1-janislacis06@gmail.com>
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.
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.
> 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?
[Severity: High]
This isn't a bug introduced by this patch, but spl2sw_rx_poll() leaves a
broken ring slot behind when an RX buffer refill fails:
spl2sw_rx_poll() {
...
new_skb = netdev_alloc_skb(NULL, comm->rx_desc_buff_size);
if (unlikely(!new_skb)) {
desc->cmd2 = (rx_pos == comm->rx_desc_num[queue] - 1) ?
RXD_EOR : 0;
sinfo->skb = NULL;
sinfo->mapping = 0;
desc->addr1 = 0;
goto spl2sw_rx_poll_alloc_err;
}
...
}
The dma_mapping_error() branch does the same. Both jumps skip
desc->cmd1 = RXD_OWN, so cmd1 keeps the stale completed status the
hardware wrote, and nothing ever refills the slot.
After 15 more packets on that queue, rx_pos wraps back to this slot. The
RXD_OWN check doesn't stop the loop, and the stale status passes the
port, length and error checks:
dma_unmap_single(&comm->pdev->dev, sinfo->mapping,
comm->rx_desc_buff_size, DMA_FROM_DEVICE);
skb = sinfo->skb;
skb_put(skb, pkg_len - 4); /* Minus FCS */
Can this call dma_unmap_single() on mapping 0 and then skb_put() on a
NULL skb in the NET_RX softirq?
There is also a second path. On a TX timeout, spl2sw_mac_soft_reset()
calls spl2sw_rx_descs_flush(), which gives the slot back to the hardware
with RXD_OWN set:
rx_desc[j].addr1 = rx_skbinfo[j].mapping;
Could the hardware then DMA a received frame to bus address 0?
One fix would be to keep the old buffer in the ring and drop the packet
when the refill fails. Another would be to retry the refill on later
polls and never treat a slot without an skb as completed.
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but spl2sw_remove() frees the
rings that both poll functions use before it disables NAPI:
drivers/net/ethernet/sunplus/spl2sw_driver.c:spl2sw_remove() {
...
comm->enable = 0;
spl2sw_mac_hw_stop(comm);
spl2sw_descs_free(comm);
/* Disable and delete napi. */
napi_disable(&comm->rx_napi);
netif_napi_del(&comm->rx_napi);
napi_disable(&comm->tx_napi);
netif_napi_del(&comm->tx_napi);
...
}
spl2sw_descs_free() frees the RX skbs and rx_skb_info arrays, frees the
TX skbs in spl2sw_tx_descs_clean() without holding tx_lock, sets
comm->tx_desc and comm->rx_desc[i] to NULL and frees desc_base with
dma_free_coherent().
unregister_netdev() and spl2sw_mac_hw_stop() don't stop a NAPI instance
that is already scheduled. Only napi_disable() cancels the NAPI hrtimer.
With napi_defer_hard_irqs and gro_flush_timeout set,
napi_complete_done() keeps returning false and re-arms the timer.
napi_watchdog() then schedules the poll again with no interrupt needed.
Without those settings there is still a window if NAPI was scheduled just
before ndo_stop masked the interrupts.
If remove runs in that window, spl2sw_rx_poll() would do:
desc = comm->rx_desc[queue] + rx_pos;
cmd = desc->cmd1;
with a NULL comm->rx_desc[queue], and spl2sw_tx_poll() would read
comm->tx_desc[tx_done_pos].cmd1 the same way. A TX poll running at the
same time as spl2sw_tx_descs_clean() could also call dev_kfree_skb_irq()
on an skb that dev_kfree_skb_any() is already freeing.
This patch doesn't widen the window, since normal polls still complete
after one pass.
Should napi_disable() for both instances move before spl2sw_descs_free()?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114222744.535158-1-janislacis06%40gmail.com
prev parent reply other threads:[~2026-11-16 2:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 22:27 [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done() Janis Edvarts Lacis
2026-11-15 15:50 ` Andrew Lunn
2026-11-15 20:06 ` netdev-bot+sinfo
2026-11-16 2:22 ` netdev-bot+sashiko [this message]
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=179479577764.3136.18033299607451586926@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=janislacis06@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=wellslutw@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox