From: netdev-bot+sashiko@kernel.org
To: almasrymina@google.com
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
horms@kernel.org, shuah@kernel.org,
linux-kselftest@vger.kernel.org, sdf.kernel@gmail.com,
bobbyeshleman@meta.com, razor@blackwall.org,
daniel@iogearbox.net, dw@davidwei.uk, asml.silence@gmail.com,
axboe@kernel.dk, bestswngs@gmail.com, io-uring@vger.kernel.org,
hawk@kernel.org, ilias.apalodimas@linaro.org
Subject: Re: [PATCH net-next v5 4/6] net: devmem: synchronize and unmap all device bindings on unregister
Date: Sun, 06 Dec 2026 00:07:42 +0000 [thread overview]
Message-ID: <179651566257.3148.13711388561537542637@kernel.org> (raw)
In-Reply-To: <20261204231030.3815575-5-almasrymina@google.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Issue #1 in the commit message is not a real defect, and the new
synchronize_net() does not change what can happen.
--
net: devmem: synchronize and unmap all device bindings on unregister
This commit splits net_devmem_dev_unregister() into two passes with one
synchronize_net() between them. The first pass clears binding->vdev and
the NET_DEVMEM_BINDING_LIVE mark. The second pass unmaps every binding
whose binding->dev matches the unregistering device, including RX
bindings that still had LIVE set, and drops the netif_is_queue_leasee()
check.
> 1. For TX bindings, it clears NET_DEVMEM_BINDING_LIVE and immediately
> calls net_devmem_dmabuf_binding_unmap() without waiting for an RCU
> grace period, racing with in-flight net_devmem_get_binding() lookups
> (both direct on dev and leased via binding->vdev).
[ ... ]
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index 3a894ff06b32b..a395f100d2f33 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
[ ... ]
> + xa_unlock(&net_devmem_dmabuf_bindings);
> +
> + if (!unmap)
> + return;
> +
> + /* Ensure no tx net_devmem_get_binding() are in flight after the
> + * mark is cleared.
> + */
> + synchronize_net();
>
> - xa_unlock(&net_devmem_dmabuf_bindings);
> - if (!netif_is_queue_leasee(dev))
> + xa_lock(&net_devmem_dmabuf_bindings);
> + xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
> + if (READ_ONCE(binding->dev) == dev) {
> + xa_unlock(&net_devmem_dmabuf_bindings);
> net_devmem_dmabuf_binding_unmap(binding);
[Severity: Low]
Is the race in item 1 of the changelog accurate? The changelog doesn't
say what goes wrong when the unmap happens right after the LIVE mark is
cleared.
net_devmem_get_binding() reads the xarray entry, the LIVE mark, tx_vec,
net and uid. It compares the dev/vdev pointers and then takes a ref:
net/core/devmem.c:net_devmem_get_binding() {
...
if (unlikely(!dst_dev) ||
unlikely(dst_dev != READ_ONCE(binding->dev) &&
dst_dev != READ_ONCE(binding->vdev))) {
err = -ENODEV;
goto out_unlock;
}
if (!net_devmem_dmabuf_binding_get(binding)) {
...
}
It never reads binding->sgt or binding->attachment. Those are the only
fields net_devmem_dmabuf_binding_unmap() tears down.
A lookup that completed before __xa_clear_mark() also still returns a
referenced binding. tcp_sendmsg_locked() keeps using it until
net_devmem_dmabuf_binding_put(), and that can be after this second pass
has unmapped it, with or without the new synchronize_net(). So waiting
for in-flight lookups doesn't seem to change whether a binding can be
used after it is unmapped.
What keeps this safe looks the same as before the patch. The device is
already closed by the time reg_state is NETREG_UNREGISTERING. Also,
validate_xmit_unreadable_skb() drops skbs whose binding->dev no longer
matches, and this pass sets binding->dev to NULL:
net/core/dev.c:validate_xmit_unreadable_skb() {
...
if (net_is_devmem_iov(niov) &&
(net_devmem_iov_binding(niov)->direction != DMA_TO_DEVICE ||
READ_ONCE(net_devmem_iov_binding(niov)->dev) != dev))
goto out_free;
...
}
This also goes against commit ede1618064a9 ("net: devmem: detach TX
bindings on NETDEV_UNREGISTER"), which said:
No grace period is needed: the device is already closed, so nothing
hands the DMA addresses to the hardware anymore, and concurrent
senders only compare against binding->dev.
The changelog doesn't say why that reasoning no longer holds.
The v4 -> v5 notes say the barrier was added at a reviewer's request.
Could the commit message and the comment above synchronize_net() say
what it actually guarantees, which is that no new TX references are
taken after this point? As written, they suggest it closes a hazard
with the unmap. Later patches in the series leave this code unchanged.
> - xa_lock(&net_devmem_dmabuf_bindings);
> - WRITE_ONCE(binding->dev, NULL);
> + xa_lock(&net_devmem_dmabuf_bindings);
> + WRITE_ONCE(binding->dev, NULL);
> + }
> }
> xa_unlock(&net_devmem_dmabuf_bindings);
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204231030.3815575-1-almasrymina%40google.com
next prev parent reply other threads:[~2026-12-06 0:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 23:10 [PATCH net-next v5 0/6] net: devmem: support leased RX and TX queues on netdev unregister Mina Almasry
2026-12-04 23:10 ` [PATCH net-next v5 1/6] net: guard leased queue ops against physical " Mina Almasry
2026-12-06 0:07 ` netdev-bot+sashiko
2026-12-04 23:10 ` [PATCH net-next v5 2/6] net: devmem: fold net_devmem_lookup_dmabuf() into net_devmem_get_binding() Mina Almasry
2026-12-04 23:10 ` [PATCH net-next v5 3/6] net: devmem: resolve leased RX queues to physical device on bind Mina Almasry
2026-12-06 0:07 ` netdev-bot+sashiko
2026-12-04 23:10 ` [PATCH net-next v5 4/6] net: devmem: synchronize and unmap all device bindings on unregister Mina Almasry
2026-12-06 0:07 ` netdev-bot+sashiko [this message]
2026-12-04 23:10 ` [PATCH net-next v5 5/6] net: propagate busy status on memory provider uninstall Mina Almasry
2026-12-06 0:07 ` netdev-bot+sashiko
2026-12-04 23:10 ` [PATCH net-next v5 6/6] selftests: net: add leased devmem RX and TX netdev unregister tests Mina Almasry
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=179651566257.3148.13711388561537542637@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=almasrymina@google.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=bestswngs@gmail.com \
--cc=bobbyeshleman@meta.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=io-uring@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=sdf.kernel@gmail.com \
--cc=shuah@kernel.org \
--cc=willemb@google.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