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/2026…%40google.com