On Fri, May 08, 2026 at 01:47:17PM -0700, Jakub Kicinski wrote:
> On Thu, 07 May 2026 19:27:48 -0700 Bobby Eshleman wrote:
> > +   /* Virtual device (e.g. netkit) the user called bind-tx on. Must be
> > +    * NETMEM_TX_NO_DMA.
> > +    */
> > +   struct net_device *vdev;
> 
> AI keeps complaining that we don't hold a reference to this dev which 
> I think is fine, we're just comparing pointers. Could we maybe make this
> a void pointer and mention in the comment that we treat it as "best
> effort cookie" (better phrasing welcome).
> 
> Or we should wipe these vdev pointers when vdevs disappear, not sure
> how hard that'd be (or whether it's worth the extra state).

My guess is this would probably be the simplest way?

diff --git a/net/core/devmem.c b/net/core/devmem.c
index 644c286b778f..e28fae14c687 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -533,3 +533,38 @@ static const struct memory_provider_ops dmabuf_devmem_ops 
= {
        .nl_fill                = mp_dmabuf_devmem_nl_fill,
        .uninstall              = mp_dmabuf_devmem_uninstall,
 };
+
+static int net_devmem_netdev_event(struct notifier_block *nb,
+                                  unsigned long event, void *ptr)
+{
+       struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+       struct net_devmem_dmabuf_binding *binding;
+       unsigned long id;
+
+       if (event != NETDEV_UNREGISTER)
+               return NOTIFY_DONE;
+
+       xa_for_each(&net_devmem_dmabuf_bindings, id, binding) {
+               if (!net_devmem_dmabuf_binding_get(binding))
+                       continue;
+               mutex_lock(&binding->lock);
+               if (READ_ONCE(binding->vdev) == dev) {
+                       ASSERT_EXCLUSIVE_WRITER(binding->vdev);
+                       WRITE_ONCE(binding->vdev, NULL);
+               }
+               mutex_unlock(&binding->lock);
+               net_devmem_dmabuf_binding_put(binding);
+       }
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block net_devmem_netdev_nb = {
+       .notifier_call = net_devmem_netdev_event,
+};
+
+static int __init net_devmem_init(void)
+{
+       return register_netdevice_notifier(&net_devmem_netdev_nb);
+}
+subsys_initcall(net_devmem_init);


I'm open to either approach. The void* + comment is good too, IMHO.  For
the notifier, I'd probably want to add a test too ensure sendmsg() kicks
back after the device is removed.

Best,
Bobby

Reply via email to