From: netdev-bot+sashiko@kernel.org
To: mika.westerberg@linux.intel.com
Cc: netdev@vger.kernel.org, YehezkelShB@gmail.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com
Subject: Re: [PATCH v2 1/3] net: thunderbolt: Stop queueing Rx buffers if allocation fails
Date: Fri, 20 Nov 2026 05:29:03 +0000 [thread overview]
Message-ID: <179515254314.3136.10991358568283987720@kernel.org> (raw)
In-Reply-To: <20261116142613.876208-2-mika.westerberg@linux.intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] This patch moves NAPI enable/disable into the connection
lifecycle, but the new code is not serialized with teardown.
--
net: thunderbolt: Stop queueing Rx buffers if allocation fails
When Rx buffer allocation fails, tbnet_alloc_rx_buffers() no longer frees
buffers that are already queued, and the callers are updated to match.
If tbnet_poll() cannot refill the ring, it keeps polling so it can retry.
NAPI enable/disable moves out of ndo_open/ndo_stop and into the connection
lifecycle: it is enabled after the rings are primed and disabled before
they are stopped.
Closes: https://sashiko.dev/#/patchset/20260902082128.1148463-1-mika.westerberg%40linux.intel.com
> diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c
> index cf51b9c39f4ee..1593ad76e645a 100644
> --- a/drivers/net/thunderbolt/main.c
> +++ b/drivers/net/thunderbolt/main.c
[ ... ]
> @@ -366,6 +368,21 @@ static void tbnet_free_buffers(struct tbnet_ring *ring)
> ring->prod = 0;
> }
>
> +static inline void tbnet_napi_enable(struct tbnet *net)
> +{
> + napi_enable(&net->napi);
> + net->napi_enabled = true;
> + /* Run once in case an Rx interrupt arrived while NAPI was disabled */
> + napi_schedule(&net->napi);
> +}
> +
> +static inline void tbnet_napi_disable(struct tbnet *net)
> +{
> + if (net->napi_enabled)
> + napi_disable(&net->napi);
> + net->napi_enabled = false;
> +}
> +
> static void tbnet_tear_down(struct tbnet *net, bool send_logout)
> {
> netif_carrier_off(net->dev);
> @@ -404,6 +421,8 @@ static void tbnet_tear_down(struct tbnet *net, bool send_logout)
> if (ret)
> netdev_warn(net->dev, "failed to disable DMA paths\n");
>
> + tbnet_napi_disable(net);
> +
> tb_ring_stop(net->rx_ring.ring);
> tb_ring_stop(net->tx_ring.ring);
> tbnet_free_buffers(&net->rx_ring);
[ ... ]
> @@ -678,7 +702,9 @@ static void tbnet_connected_work(struct work_struct *work)
>
> ret = tbnet_alloc_tx_buffers(net);
> if (ret)
> - goto err_free_rx_buffers;
> + goto err_stop_rings;
> +
> + tbnet_napi_enable(net);
[Severity: Medium]
Is this tbnet_napi_enable() serialized against tbnet_tear_down()?
tbnet_connected_work() reads login_sent && login_received once under
connection_lock and then drops the lock. Nothing checks the state again
before the rings are restarted and NAPI is enabled here.
On the teardown side, stop_login() calls
cancel_work_sync(&net->connected_work) before tbnet_tear_down() takes
connection_lock. A TBIP_LOGIN from the peer can still queue connected_work
after that point:
tbnet_handle_packet()
mutex_lock(&net->connection_lock);
net->login_received = true;
net->remote_transmit_path = pkg->transmit_path;
...
mutex_unlock(&net->connection_lock);
queue_work(system_long_wq, &net->connected_work);
This can happen on the disconnect_work path (peer LOGOUT followed by
LOGIN), or during suspend while netif_running() is still true. If
connected_work gets connection_lock first, it sees connected == true,
because login_sent is still set from the old session.
If the peer reuses the same HopID, tbnet_tear_down() disables NAPI, stops
the rings, frees the buffers, releases the HopID and clears both login
flags. connected_work then allocates the HopID, restarts the rings and
calls tbnet_napi_enable(). NAPI is now enabled while login_sent and
login_received are both false.
The next tbnet_stop()->tbnet_tear_down() then skips the block guarded by:
if (net->login_sent && net->login_received) {
So neither tbnet_napi_disable() nor tb_ring_stop() runs. Because this
patch removes the unconditional napi_disable() from tbnet_stop(),
tb_ring_free() runs and net->rx_ring.ring is set to NULL while NAPI is
still enabled.
Could an already scheduled or busy-poll tbnet_poll() then run against a
freed or NULL Rx ring? On the next ndo_open, would napi_enable() on an
already enabled NAPI hit the BUG_ON(!test_bit(NAPI_STATE_SCHED, &val)) in
napi_enable_locked()?
If the peer's new LOGIN carries a different transmit_path,
tb_xdomain_alloc_in_hopid() succeeds right away, and connected_work can
run at the same time as the locked part of tbnet_tear_down().
tbnet_napi_enable() can then run before tbnet_napi_disable(), which calls
napi_enable() on an enabled NAPI. Or it can run after it, in which case
napi_schedule() lets tbnet_poll() run at the same time as tb_ring_stop()
and tbnet_free_buffers(&net->rx_ring).
Does that match this part of the commit message?
We prevent tbnet_poll() from being called when the connection
is torn down and buffers are released by disabling NAPI before the rings
are stopped
napi_enabled is a plain bool. It is written in tbnet_connected_work()
(including the err_napi path) without connection_lock, and read and
cleared in tbnet_tear_down() under connection_lock. Can it reliably track
whether NAPI is enabled?
The race between connected_work and tbnet_tear_down() itself seems to
predate this patch: rings could already be restarted with the login flags
cleared. This patch adds NAPI enable/disable to that unserialized handoff
and drops the unconditional napi_disable() from tbnet_stop().
Would it help to re-check the connection state and do the ring start and
NAPI enable under connection_lock (or with a generation/state check)? Or
to make the NAPI disable in tbnet_tear_down() independent of the login
flag test?
>
> ret = tb_xdomain_enable_paths(net->xd, net->local_transmit_path,
> net->tx_ring.ring->hop,
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116142613.876208-1-mika.westerberg%40linux.intel.com
next prev parent reply other threads:[~2026-11-20 5:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 14:26 [PATCH v2 0/3] net: thunderbolt: Various fixes Mika Westerberg
2026-11-16 14:26 ` [PATCH v2 1/3] net: thunderbolt: Stop queueing Rx buffers if allocation fails Mika Westerberg
2026-11-20 5:29 ` netdev-bot+sashiko [this message]
2026-11-16 14:26 ` [PATCH v2 2/3] net: thunderbolt: Prevent Tx descriptor leak in tbnet_start_xmit() Mika Westerberg
2026-11-16 14:26 ` [PATCH v2 3/3] net: thunderbolt: Free partially completed skb when the link is torn down Mika Westerberg
2026-11-20 5:29 ` netdev-bot+sashiko
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=179515254314.3136.10991358568283987720@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=YehezkelShB@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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