Netdev List
 help / color / mirror / Atom feed
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, horms@kernel.org,
	shuah@kernel.org, linux-kselftest@vger.kernel.org,
	bestswngs@gmail.com, daniel@iogearbox.net, razor@blackwall.org,
	dw@davidwei.uk, sdf.kernel@gmail.com, bobbyeshleman@meta.com,
	dtatulea@nvidia.com
Subject: Re: [PATCH net-next v4 5/7] net: devmem: always populate bind_dev and detach both devices on unregister
Date: Mon, 23 Nov 2026 04:59:26 +0000	[thread overview]
Message-ID: <179540996620.3135.3612533688050456273@kernel.org> (raw)
In-Reply-To: <20261120045918.1239746-6-almasrymina@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · 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] Undisclosed user-visible behaviour change for leased TX
  bindings.
- [Low] The commit message presents this patch as fixing 'issues' found
  by AI review of the earlier devmem unregister series, 'confirmed by…

--

net: devmem: always populate bind_dev and detach both devices on unregister

This patch always sets binding->bind_dev to the device that bind-rx or
bind-tx was called on. Socket teardown, queue close and queue uninstall
now use bind_dev, and net_devmem_dev_unregister() handles bind_dev and
map_dev separately, calling synchronize_net() before unmapping when
map_dev unregisters. net_devmem_get_binding() also now requires map_dev
to be non-NULL.

> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index 6f85b90950f8b..80c3e149cd762 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c

[ ... ]

> @@ -252,20 +255,33 @@ void net_devmem_dev_unregister(struct net_device *dev)
>  
>  	xa_lock(&net_devmem_dmabuf_bindings);
>  	xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
> -		if (binding->direction == DMA_FROM_DEVICE) {
> -			if (READ_ONCE(binding->map_dev) != dev ||
> -			    xa_get_mark(&net_devmem_dmabuf_bindings, xa_idx,
> -					NET_DEVMEM_BINDING_LIVE))
> -				continue;
> -		} else {
> -			if (READ_ONCE(binding->bind_dev) == dev)
> +		if (READ_ONCE(binding->bind_dev) == dev) {
> +			__xa_clear_mark(&net_devmem_dmabuf_bindings, xa_idx,
> +					NET_DEVMEM_BINDING_LIVE);
> +			if (xa_empty(&binding->bound_rxqs) ||
> +			    !netif_is_queue_leasee(dev))
>  				WRITE_ONCE(binding->bind_dev, NULL);
> -			if (READ_ONCE(binding->map_dev) != dev)
> -				continue;
> -			WRITE_ONCE(binding->bind_dev, NULL);
> +		}

[Severity: Medium]
Does this change what happens to leased TX bindings when only the virtual
device goes away?

If bind-tx is called on a netkit device, netdev_find_netmem_tx_dev()
picks the physical NIC as map_dev, and bind_dev is now the netkit device.
When the netkit device is deleted and the physical NIC stays registered,
this first walk matches bind_dev == dev and clears
NET_DEVMEM_BINDING_LIVE.

After that, net_devmem_get_binding() fails here:

	binding = xa_find(&net_devmem_dmabuf_bindings, &xa_idx, dmabuf_id,
			  NET_DEVMEM_BINDING_LIVE);

So every later devmem sendmsg with that dmabuf id returns -EINVAL, even
when dst_dev == map_dev.

Before this patch, the code from ede1618064a9 ("net: devmem: detach TX
bindings on NETDEV_UNREGISTER") only cleared the virtual device pointer in
this case and left the binding live. That commit gave its reason as "only
clear binding->vdev so no new TX sends match the virtual device while
allowing in-flight TX packets on binding->dev to finish DMA safely".

TX bindings have an empty bound_rxqs, so bind_dev is cleared here anyway.
net_devmem_get_binding() would then only match map_dev. Does correctness
need the LIVE mark to be cleared in this case?

If the change is intended, could the commit message say that it reverses
the earlier design, and why? Right now it only says "first walk the
bindings to clear NET_DEVMEM_BINDING_LIVE to stop new lookups".

The same goes for the synchronize_net() added further down for the
map_dev case. ede1618064a9 said a grace period was not needed there.

This behaviour is still the same at the end of the series. The selftest
added later in the series (devmem_lease_bind_tx_unregister_check with
remove_virt_first) only checks the dmabuf attach count. It does not check
whether sends through the physical device still work.

[ ... ]

> @@ -568,9 +584,10 @@ struct net_devmem_dmabuf_binding *net_devmem_get_binding(struct sock *sk,
>  	 * net_device.
>  	 */
>  	dst_dev = dst_dev_rcu(dst);
> -	if (unlikely(!dst_dev) ||
> -	    unlikely(dst_dev != READ_ONCE(binding->map_dev) &&
> -		     dst_dev != READ_ONCE(binding->bind_dev))) {
> +	map_dev = READ_ONCE(binding->map_dev);
> +	if (unlikely(!dst_dev || !map_dev ||
> +		     (dst_dev != map_dev &&
> +		      dst_dev != READ_ONCE(binding->bind_dev)))) {
>  		err = -ENODEV;
>  		goto out_unlock;
>  	}

[Severity: Low]
The commit message describes this check as:

    - Require binding->map_dev to remain non-NULL in
      net_devmem_get_binding() so TX lookups fail once map_dev unregisters
      even if bind_dev is still registered.

Is that different from the baseline behaviour? Before this patch,
net_devmem_dev_unregister() already cleared NET_DEVMEM_BINDING_LIVE for
TX bindings when the physical device unregistered. Lookups already failed
at xa_find().

With this patch, map_dev is only cleared in net_devmem_dev_unregister(),
and only after LIVE is cleared and synchronize_net() returns. So the
!map_dev test looks like defence in depth rather than a fix.

The message also says "These issues were discovered during AI code review
(Sashiko) ... and confirmed by code inspection". It does not name a
concrete failure at baseline.

At this commit, netdev_nl_bind_rx_doit() still passes netdev as both
map_dev and bind_dev. The rework seems to mostly prepare for the next
patch, "net: devmem: resolve physical map_dev for leased RX bindings",
which fixes the actual use-after-free.

This patch rewrites logic from c4466d2c3e77 ("net: devmem: unmap dma_buf
synchronously on queue uninstall") and ede1618064a9 ("net: devmem: detach
TX bindings on NETDEV_UNREGISTER"). Both of those carry Fixes: tags.
Should this patch carry Fixes: tags too, so stable backporters know
whether it has to go with them?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120045918.1239746-1-almasrymina%40google.com

  reply	other threads:[~2026-11-23  4:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  4:59 [PATCH net-next v4 0/7] net: devmem: support leased RX and TX queues on netdev unregister Mina Almasry
2026-11-20  4:59 ` [PATCH net-next v4 1/7] net: devmem: pass net_device pointer to net_devmem_lock_dev() Mina Almasry
2026-11-20  4:59 ` [PATCH net-next v4 2/7] net: devmem: rename binding dev and vdev to map_dev and bind_dev Mina Almasry
2026-11-20  4:59 ` [PATCH net-next v4 3/7] net: guard memory provider RX queue open and close on unregister Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko
2026-11-20  4:59 ` [PATCH net-next v4 4/7] net: devmem: fold net_devmem_lookup_dmabuf() into net_devmem_get_binding() Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko
2026-11-20  4:59 ` [PATCH net-next v4 5/7] net: devmem: always populate bind_dev and detach both devices on unregister Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko [this message]
2026-11-20  4:59 ` [PATCH net-next v4 6/7] net: devmem: resolve physical map_dev for leased RX bindings Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko
2026-11-20  4:59 ` [PATCH net-next v4 7/7] selftests: net: add leased devmem RX and TX netdev unregister tests Mina Almasry
2026-11-20 17:04 ` [PATCH net-next v4 0/7] net: devmem: support leased RX and TX queues on netdev unregister Stanislav Fomichev
2026-11-22  9:16 ` Nikolay Aleksandrov

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=179540996620.3135.3612533688050456273@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=almasrymina@google.com \
    --cc=bestswngs@gmail.com \
    --cc=bobbyeshleman@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=dw@davidwei.uk \
    --cc=edumazet@kernel.org \
    --cc=horms@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 \
    /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