AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/14 22:43 flow patch-triage
3m Args:
null

Results:
{
  "EnableConfigs": [
    "NET_DEVMEM",
    "NETDEVSIM",
    "UDMABUF",
    "SYNC_FILE",
    "DEBUG_FS"
  ],
  "FocusSymbols": [
    "net_devmem_dev_unregister",
    "net_devmem_unbind_dmabuf",
    "net_devmem_bind_dmabuf",
    "net_devmem_lookup_dmabuf",
    "__net_devmem_dmabuf_binding_free",
    "netdev_nl_bind_rx_doit",
    "netdev_nl_bind_tx_doit",
    "nsim_pp_hold_write",
    "nsim_queue_mem_alloc",
    "nsim_do_psp"
  ],
  "KMSANReasoning": "The patch series implements lifecycle and detachment handling for devmem (dma-buf) bindings when net devices unregister (preventing use-after-free and dangling DMA buffer attachment references), along with support for netmem in netdevsim and associated selftests.\n\nKASAN vs KMSAN Applicability:\n- Primary risks: The potential failure modes introduced or modified by these changes involve resource lifetime management, concurrent access races, use-after-free on unregistered net devices / detached dmabuf structures, NULL pointer dereferences, or locking/deadlock issues. These memory safety bugs and synchronization issues are directly detected by KASAN and LOCKDEP.\n- Uninitialized memory / info-leaks: The changes do not introduce or alter any copying of kernel structures to user space, nor do they expose uninitialized padding or uninitialized memory in socket, netlink, or ioctl responses. All touched structures (such as `page_pool_params`) use designated initializers (zeroing unspecified fields), and loop indices are initialized properly.\n\nBecause no uninitialized memory risks or kernel-to-user info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series modifies the core networking devmem dmabuf subsystem (net/core/devmem.c) and netdevsim virtual driver to properly handle dmabuf unmapping and detaching upon network device unregistration, preventing use-after-free conditions. It alters locking, adds live binding tracking via xarray marks, updates devmem binding lookup and unbinding logic, and enables netdevsim support for unreadable netmem in page pools. This modifies reachable core networking and virtual device paths exercisable via generic Netlink and netdevice lifecycle operations in standard virtual environments.",
  "WorthFuzzing": true
}

1/1 2026/10/14 22:43 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 5c1e73fdbe1bc2f288495d4674c46085acfd2ee8\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Wed Oct 14 22:43:30 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c\nindex 5c55c308487b4..f87f5e037b6fb 100644\n--- a/drivers/net/netdevsim/bus.c\n+++ b/drivers/net/netdevsim/bus.c\n@@ -462,6 +462,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queu\n \tnsim_bus_dev-\u003eport_count = port_count;\n \tnsim_bus_dev-\u003enum_queues = num_queues;\n \tnsim_bus_dev-\u003einitial_net = current-\u003ensproxy-\u003enet_ns;\n+\tdma_coerce_mask_and_coherent(\u0026nsim_bus_dev-\u003edev, DMA_BIT_MASK(64));\n \t/* Disallow using nsim_bus_dev */\n \tsmp_store_release(\u0026nsim_bus_dev-\u003einit, false);\n \ndiff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c\nindex b4a99f3ceac60..357ea9e5623b3 100644\n--- a/drivers/net/netdevsim/netdev.c\n+++ b/drivers/net/netdevsim/netdev.c\n@@ -414,19 +414,27 @@ static int nsim_poll(struct napi_struct *napi, int budget)\n \treturn done;\n }\n \n-static int nsim_create_page_pool(struct page_pool **p, struct napi_struct *napi)\n+static int nsim_create_page_pool(struct net_device *dev, struct page_pool **p,\n+\t\t\t\t struct napi_struct *napi, int idx)\n {\n+\tstruct netdevsim *ns = netdev_priv(dev);\n \tstruct page_pool_params params = {\n \t\t.order = 0,\n \t\t.pool_size = NSIM_RING_SIZE,\n+\t\t.flags = PP_FLAG_ALLOW_UNREADABLE_NETMEM,\n+\t\t.max_len = PAGE_SIZE,\n \t\t.nid = NUMA_NO_NODE,\n-\t\t.dev = \u0026napi-\u003edev-\u003edev,\n+\t\t.dev = \u0026ns-\u003ensim_bus_dev-\u003edev,\n \t\t.napi = napi,\n \t\t.dma_dir = DMA_BIDIRECTIONAL,\n-\t\t.netdev = napi-\u003edev,\n+\t\t.netdev = dev,\n+\t\t.queue_idx = idx,\n \t};\n \tstruct page_pool *pool;\n \n+\tif (IS_ENABLED(CONFIG_HAS_DMA))\n+\t\tparams.flags |= PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;\n+\n \tpool = page_pool_create(\u0026params);\n \tif (IS_ERR(pool))\n \t\treturn PTR_ERR(pool);\n@@ -450,7 +458,7 @@ static int nsim_init_napi(struct netdevsim *ns)\n \tfor (i = 0; i \u003c dev-\u003enum_rx_queues; i++) {\n \t\trq = ns-\u003erq[i];\n \n-\t\terr = nsim_create_page_pool(\u0026rq-\u003epage_pool, \u0026rq-\u003enapi);\n+\t\terr = nsim_create_page_pool(dev, \u0026rq-\u003epage_pool, \u0026rq-\u003enapi, i);\n \t\tif (err)\n \t\t\tgoto err_pp_destroy;\n \t}\n@@ -762,14 +770,16 @@ nsim_queue_mem_alloc(struct net_device *dev,\n \tif (ns-\u003erq_reset_mode == 1) {\n \t\tif (!netif_running(ns-\u003enetdev))\n \t\t\treturn -ENETDOWN;\n-\t\treturn nsim_create_page_pool(\u0026qmem-\u003epp, \u0026ns-\u003erq[idx]-\u003enapi);\n+\t\treturn nsim_create_page_pool(dev, \u0026qmem-\u003epp,\n+\t\t\t\t\t     \u0026ns-\u003erq[idx]-\u003enapi, idx);\n \t}\n \n \tqmem-\u003erq = nsim_queue_alloc();\n \tif (!qmem-\u003erq)\n \t\treturn -ENOMEM;\n \n-\terr = nsim_create_page_pool(\u0026qmem-\u003erq-\u003epage_pool, \u0026qmem-\u003erq-\u003enapi);\n+\terr = nsim_create_page_pool(dev, \u0026qmem-\u003erq-\u003epage_pool, \u0026qmem-\u003erq-\u003enapi,\n+\t\t\t\t    idx);\n \tif (err)\n \t\tgoto err_free;\n \n@@ -929,12 +939,15 @@ nsim_pp_hold_write(struct file *file, const char __user *data,\n \t\treturn ret;\n \n \trtnl_lock();\n+\tnetdev_lock(ns-\u003enetdev);\n \tret = count;\n \tif (val == !!ns-\u003epage)\n \t\tgoto exit;\n \n \tif (!netif_running(ns-\u003enetdev) \u0026\u0026 val) {\n \t\tret = -ENETDOWN;\n+\t} else if (val \u0026\u0026 page_pool_is_unreadable(ns-\u003erq[0]-\u003epage_pool)) {\n+\t\tret = -EOPNOTSUPP;\n \t} else if (val) {\n \t\tns-\u003epage = page_pool_dev_alloc_pages(ns-\u003erq[0]-\u003epage_pool);\n \t\tif (!ns-\u003epage)\n@@ -946,6 +959,7 @@ nsim_pp_hold_write(struct file *file, const char __user *data,\n \t}\n \n exit:\n+\tnetdev_unlock(ns-\u003enetdev);\n \trtnl_unlock();\n \treturn ret;\n }\n@@ -1051,6 +1065,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)\n \tns-\u003enetdev-\u003enetdev_ops = \u0026nsim_netdev_ops;\n \tns-\u003enetdev-\u003estat_ops = \u0026nsim_stat_ops;\n \tns-\u003enetdev-\u003equeue_mgmt_ops = \u0026nsim_queue_mgmt_ops;\n+\tns-\u003enetdev-\u003enetmem_tx = NETMEM_TX_DMA;\n \tnetdev_lockdep_set_classes(ns-\u003enetdev);\n \n \terr = nsim_udp_tunnels_info_create(ns-\u003ensim_dev, ns-\u003enetdev);\ndiff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c\nindex 6b3532b5e360d..908cc0d391dc6 100644\n--- a/drivers/net/netdevsim/psp.c\n+++ b/drivers/net/netdevsim/psp.c\n@@ -86,6 +86,11 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,\n \t\t__wsum csum;\n \t\tint udplen;\n \n+\t\tif (!skb_frags_readable(skb)) {\n+\t\t\trc = SKB_DROP_REASON_PSP_OUTPUT;\n+\t\t\tgoto out_unlock;\n+\t\t}\n+\n \t\t/* Do not decapsulate. Receive the skb with the udp and psp\n \t\t * headers still there as if this is a normal udp packet.\n \t\t * psp_dev_encapsulate() sets udp checksum to 0, so we need to\ndiff --git a/net/core/devmem.c b/net/core/devmem.c\nindex f4d60654ce7fd..dd07203076808 100644\n--- a/net/core/devmem.c\n+++ b/net/core/devmem.c\n@@ -20,6 +20,7 @@\n #include \u003cnet/tcp.h\u003e\n #include \u003ctrace/events/page_pool.h\u003e\n \n+#include \"dev.h\"\n #include \"devmem.h\"\n #include \"mp_dmabuf_devmem.h\"\n #include \"page_pool_priv.h\"\n@@ -27,6 +28,8 @@\n /* Device memory support */\n \n static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);\n+#define NET_DEVMEM_BINDING_LIVE XA_MARK_1\n+static DEFINE_MUTEX(net_devmem_lock);\n \n static const struct memory_provider_ops dmabuf_devmem_ops;\n \n@@ -58,6 +61,21 @@ static void net_devmem_dmabuf_binding_release(struct percpu_ref *ref)\n \tschedule_work(\u0026binding-\u003eunbind_w);\n }\n \n+static void\n+net_devmem_dmabuf_binding_unmap(struct net_devmem_dmabuf_binding *binding)\n+{\n+\tlockdep_assert_held(\u0026binding-\u003elock);\n+\n+\tif (!binding-\u003esgt)\n+\t\treturn;\n+\n+\tdma_buf_unmap_attachment_unlocked(binding-\u003eattachment, binding-\u003esgt,\n+\t\t\t\t\t  binding-\u003edirection);\n+\tdma_buf_detach(binding-\u003edmabuf, binding-\u003eattachment);\n+\tbinding-\u003esgt = NULL;\n+\tbinding-\u003eattachment = NULL;\n+}\n+\n void __net_devmem_dmabuf_binding_free(struct work_struct *wq)\n {\n \tstruct net_devmem_dmabuf_binding *binding = container_of(wq, typeof(*binding), unbind_w);\n@@ -74,9 +92,13 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq)\n \t\t  size, avail))\n \t\tgen_pool_destroy(binding-\u003echunk_pool);\n \n-\tdma_buf_unmap_attachment_unlocked(binding-\u003eattachment, binding-\u003esgt,\n-\t\t\t\t\t  binding-\u003edirection);\n-\tdma_buf_detach(binding-\u003edmabuf, binding-\u003eattachment);\n+\tmutex_lock(\u0026net_devmem_lock);\n+\tmutex_lock(\u0026binding-\u003elock);\n+\tnet_devmem_dmabuf_binding_unmap(binding);\n+\tmutex_unlock(\u0026binding-\u003elock);\n+\txa_erase(\u0026net_devmem_dmabuf_bindings, binding-\u003eid);\n+\tmutex_unlock(\u0026net_devmem_lock);\n+\n \tdma_buf_put(binding-\u003edmabuf);\n \txa_destroy(\u0026binding-\u003ebound_rxqs);\n \tpercpu_ref_exit(\u0026binding-\u003eref);\n@@ -129,10 +151,11 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)\n \tunsigned long xa_idx;\n \tunsigned int rxq_idx;\n \n-\txa_erase(\u0026net_devmem_dmabuf_bindings, binding-\u003eid);\n+\txa_clear_mark(\u0026net_devmem_dmabuf_bindings, binding-\u003eid,\n+\t\t      NET_DEVMEM_BINDING_LIVE);\n \n \t/* Ensure no tx net_devmem_lookup_dmabuf() are in flight after the\n-\t * erase.\n+\t * mark is cleared.\n \t */\n \tsynchronize_net();\n \n@@ -153,6 +176,89 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)\n \tpercpu_ref_kill(\u0026binding-\u003eref);\n }\n \n+static void\n+net_devmem_dev_unregister_rx(struct net_devmem_dmabuf_binding *binding,\n+\t\t\t     unsigned long xa_idx, struct net_device *dev)\n+{\n+\tif (xa_get_mark(\u0026net_devmem_dmabuf_bindings, xa_idx,\n+\t\t\tNET_DEVMEM_BINDING_LIVE) ||\n+\t    READ_ONCE(binding-\u003edev) != dev)\n+\t\treturn;\n+\n+\tmutex_lock(\u0026binding-\u003elock);\n+\tWRITE_ONCE(binding-\u003edev, NULL);\n+\tif (!netif_is_queue_leasee(dev))\n+\t\tnet_devmem_dmabuf_binding_unmap(binding);\n+\tmutex_unlock(\u0026binding-\u003elock);\n+}\n+\n+static bool\n+net_devmem_dev_unregister_tx(struct net_devmem_dmabuf_binding *binding,\n+\t\t\t     unsigned long xa_idx, struct net_device *dev)\n+{\n+\tif (READ_ONCE(binding-\u003edev) == dev) {\n+\t\txa_clear_mark(\u0026net_devmem_dmabuf_bindings, xa_idx,\n+\t\t\t      NET_DEVMEM_BINDING_LIVE);\n+\n+\t\tmutex_lock(\u0026binding-\u003elock);\n+\t\tWRITE_ONCE(binding-\u003edev, NULL);\n+\t\tWRITE_ONCE(binding-\u003evdev, NULL);\n+\t\tmutex_unlock(\u0026binding-\u003elock);\n+\t\treturn true;\n+\t}\n+\n+\tif (READ_ONCE(binding-\u003evdev) == dev) {\n+\t\tmutex_lock(\u0026binding-\u003elock);\n+\t\tWRITE_ONCE(binding-\u003evdev, NULL);\n+\t\tmutex_unlock(\u0026binding-\u003elock);\n+\t}\n+\n+\treturn false;\n+}\n+\n+static void net_devmem_unmap_detached_tx(void)\n+{\n+\tstruct net_devmem_dmabuf_binding *binding;\n+\tunsigned long xa_idx;\n+\n+\t/* Ensure no tx net_devmem_lookup_dmabuf() or\n+\t * validate_xmit_unreadable_skb() are in flight after detach.\n+\t */\n+\tsynchronize_net();\n+\n+\txa_for_each(\u0026net_devmem_dmabuf_bindings, xa_idx, binding) {\n+\t\tif (binding-\u003edirection != DMA_TO_DEVICE ||\n+\t\t    READ_ONCE(binding-\u003edev))\n+\t\t\tcontinue;\n+\n+\t\tmutex_lock(\u0026binding-\u003elock);\n+\t\tnet_devmem_dmabuf_binding_unmap(binding);\n+\t\tmutex_unlock(\u0026binding-\u003elock);\n+\t}\n+}\n+\n+void net_devmem_dev_unregister(struct net_device *dev)\n+{\n+\tstruct net_devmem_dmabuf_binding *binding;\n+\tbool tx_detached = false;\n+\tunsigned long xa_idx;\n+\n+\tif (dev-\u003ereg_state != NETREG_UNREGISTERING)\n+\t\treturn;\n+\n+\tmutex_lock(\u0026net_devmem_lock);\n+\txa_for_each(\u0026net_devmem_dmabuf_bindings, xa_idx, binding) {\n+\t\tif (binding-\u003edirection == DMA_FROM_DEVICE)\n+\t\t\tnet_devmem_dev_unregister_rx(binding, xa_idx, dev);\n+\t\telse if (net_devmem_dev_unregister_tx(binding, xa_idx, dev))\n+\t\t\ttx_detached = true;\n+\t}\n+\n+\tif (tx_detached)\n+\t\tnet_devmem_unmap_detached_tx();\n+\tmutex_unlock(\u0026net_devmem_lock);\n+}\n+\n int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,\n \t\t\t\t    struct net_devmem_dmabuf_binding *binding,\n \t\t\t\t    struct netlink_ext_ack *extack)\n@@ -331,6 +437,8 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,\n \t\t\t      GFP_KERNEL);\n \tif (err \u003c 0)\n \t\tgoto err_free_chunks;\n+\txa_set_mark(\u0026net_devmem_dmabuf_bindings, binding-\u003eid,\n+\t\t    NET_DEVMEM_BINDING_LIVE);\n \n \tlist_add(\u0026binding-\u003elist, \u0026priv-\u003ebindings);\n \n@@ -359,9 +467,11 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,\n struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)\n {\n \tstruct net_devmem_dmabuf_binding *binding;\n+\tunsigned long xa_idx = id;\n \n \trcu_read_lock();\n-\tbinding = xa_load(\u0026net_devmem_dmabuf_bindings, id);\n+\tbinding = xa_find(\u0026net_devmem_dmabuf_bindings, \u0026xa_idx, id,\n+\t\t\t  NET_DEVMEM_BINDING_LIVE);\n \tif (binding) {\n \t\tif (!net_devmem_dmabuf_binding_get(binding))\n \t\t\tbinding = NULL;\n@@ -529,16 +639,19 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv,\n \tunsigned long xa_idx;\n \n \txa_for_each(\u0026binding-\u003ebound_rxqs, xa_idx, bound_rxq) {\n-\t\tif (bound_rxq == rxq) {\n-\t\t\txa_erase(\u0026binding-\u003ebound_rxqs, xa_idx);\n-\t\t\tif (xa_empty(\u0026binding-\u003ebound_rxqs)) {\n-\t\t\t\tmutex_lock(\u0026binding-\u003elock);\n-\t\t\t\tASSERT_EXCLUSIVE_WRITER(binding-\u003edev);\n-\t\t\t\tWRITE_ONCE(binding-\u003edev, NULL);\n-\t\t\t\tmutex_unlock(\u0026binding-\u003elock);\n-\t\t\t}\n-\t\t\tbreak;\n+\t\tif (bound_rxq != rxq)\n+\t\t\tcontinue;\n+\n+\t\txa_erase(\u0026binding-\u003ebound_rxqs, xa_idx);\n+\t\tif (xa_empty(\u0026binding-\u003ebound_rxqs)) {\n+\t\t\tmutex_lock(\u0026binding-\u003elock);\n+\t\t\tASSERT_EXCLUSIVE_WRITER(binding-\u003edev);\n+\t\t\tWRITE_ONCE(binding-\u003edev, NULL);\n+\t\t\tif (!rxq-\u003elease)\n+\t\t\t\tnet_devmem_dmabuf_binding_unmap(binding);\n+\t\t\tmutex_unlock(\u0026binding-\u003elock);\n \t\t}\n+\t\tbreak;\n \t}\n }\n \ndiff --git a/net/core/devmem.h b/net/core/devmem.h\nindex 4a293a7d1149c..5c47c8c3c7d2d 100644\n--- a/net/core/devmem.h\n+++ b/net/core/devmem.h\n@@ -27,7 +27,7 @@ struct net_devmem_dmabuf_binding {\n \t */\n \tvoid *vdev;\n \tstruct gen_pool *chunk_pool;\n-\t/* Protect dev */\n+\t/* Protect dev, attachment and sgt */\n \tstruct mutex lock;\n \n \t/* The user holds a ref (via the netlink API) for as long as they want\n@@ -38,7 +38,8 @@ struct net_devmem_dmabuf_binding {\n \t *\n \t * The binding undos itself and unmaps the underlying dmabuf once all\n \t * those refs are dropped and the binding is no longer desired or in\n-\t * use.\n+\t * use. The dmabuf may be unmapped earlier, when the device it is\n+\t * mapped for is unregistered.\n \t *\n \t * net_devmem_get_net_iov() on dmabuf net_iovs will increment this\n \t * reference, making sure that the binding remains alive until all the\n@@ -100,6 +101,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,\n \t\t       struct netlink_ext_ack *extack);\n struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id);\n void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding);\n+void net_devmem_dev_unregister(struct net_device *dev);\n int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,\n \t\t\t\t    struct net_devmem_dmabuf_binding *binding,\n \t\t\t\t    struct netlink_ext_ack *extack);\n@@ -196,6 +198,10 @@ net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)\n {\n }\n \n+static inline void net_devmem_dev_unregister(struct net_device *dev)\n+{\n+}\n+\n static inline int\n net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,\n \t\t\t\tstruct net_devmem_dmabuf_binding *binding,\ndiff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c\nindex 33b9f4eb9565a..b04e22937b789 100644\n--- a/net/core/netdev-genl.c\n+++ b/net/core/netdev-genl.c\n@@ -1488,6 +1488,7 @@ static int netdev_genl_netdevice_event(struct notifier_block *nb,\n \t\tbreak;\n \tcase NETDEV_UNREGISTER:\n \t\tnetdev_lock(netdev);\n+\t\tnet_devmem_dev_unregister(netdev);\n \t\tnetdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_DEL_NTF);\n \t\tnetdev_unlock(netdev);\n \t\tbreak;\ndiff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config\nindex 737e7e6327b37..1e21f0055a2c0 100644\n--- a/tools/testing/selftests/net/config\n+++ b/tools/testing/selftests/net/config\n@@ -11,6 +11,7 @@ CONFIG_CRYPTO_ARIA=y\n CONFIG_CRYPTO_CHACHA20POLY1305=m\n CONFIG_CRYPTO_SHA1=y\n CONFIG_CRYPTO_SM4_GENERIC=y\n+CONFIG_DEBUG_FS=y\n CONFIG_DEBUG_INFO_BTF=y\n CONFIG_DEBUG_INFO_BTF_MODULES=n\n CONFIG_DUMMY=y\n@@ -76,6 +77,7 @@ CONFIG_NET_CLS_BPF=m\n CONFIG_NET_CLS_FLOWER=m\n CONFIG_NET_CLS_MATCHALL=m\n CONFIG_NET_CLS_U32=m\n+CONFIG_NET_DEVMEM=y\n CONFIG_NETDEVSIM=m\n CONFIG_NET_DROP_MONITOR=m\n CONFIG_NETFILTER=y\n@@ -120,6 +122,7 @@ CONFIG_OPENVSWITCH=m\n CONFIG_PAGE_POOL_STATS=y\n CONFIG_PSAMPLE=m\n CONFIG_RPS=y\n+CONFIG_SYNC_FILE=y\n CONFIG_SYN_COOKIES=y\n CONFIG_SYSCTL=y\n CONFIG_SYSFS=y\n@@ -131,6 +134,7 @@ CONFIG_TEST_BPF=m\n CONFIG_TLS=m\n CONFIG_TRACEPOINTS=y\n CONFIG_TUN=y\n+CONFIG_UDMABUF=y\n CONFIG_USER_NS=y\n CONFIG_VETH=y\n CONFIG_VLAN_8021Q=y\ndiff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py\nindex ceb44c8e1fec5..988878b71358c 100755\n--- a/tools/testing/selftests/net/nl_netdev.py\n+++ b/tools/testing/selftests/net/nl_netdev.py\n@@ -6,10 +6,14 @@ Tests for the netdev netlink family.\n \"\"\"\n \n import errno\n+import fcntl\n+import mmap\n+import os\n+import struct\n from os import system\n-from lib.py import ksft_run, ksft_exit\n+from lib.py import ksft_run, ksft_exit, KsftFailEx, KsftSkipEx\n from lib.py import ksft_eq, ksft_ge, ksft_ne, ksft_raises, ksft_busy_wait\n-from lib.py import NetdevFamily, NetdevSimDev, NlError, defer, ip\n+from lib.py import EthtoolFamily, NetdevFamily, NetdevSimDev, NlError, defer, ip\n \n \n def empty_check(nf) -\u003e None:\n@@ -366,6 +370,119 @@ def page_pool_stats_ifindex_check(nf) -\u003e None:\n     ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.info.id')\n \n \n+def _udmabuf_create_ioctl() -\u003e int:\n+    \"\"\"Return UDMABUF_CREATE, _IOW('u', 0x42, struct udmabuf_create).\"\"\"\n+    machine = os.uname().machine\n+    if machine.startswith((\"alpha\", \"mips\", \"ppc\", \"powerpc\", \"sparc\")):\n+        ioc_write = 4 \u003c\u003c 29\n+    elif machine.startswith(\"parisc\"):\n+        ioc_write = 2 \u003c\u003c 30\n+    else:\n+        ioc_write = 1 \u003c\u003c 30\n+    return ioc_write | 24 \u003c\u003c 16 | ord(\"u\") \u003c\u003c 8 | 0x42\n+\n+\n+def _create_udmabuf(num_pages=64) -\u003e int:\n+    \"\"\"Create a sealed memfd-backed udmabuf fd for devmem tests.\"\"\"\n+    if not os.path.exists(\"/dev/udmabuf\"):\n+        raise KsftSkipEx(\"/dev/udmabuf is not available\")\n+\n+    size = num_pages * mmap.PAGESIZE\n+    memfd = os.memfd_create(\"devmem-ksft\", os.MFD_ALLOW_SEALING)\n+    try:\n+        os.ftruncate(memfd, size)\n+        fcntl.fcntl(memfd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_SHRINK)\n+        devfd = os.open(\"/dev/udmabuf\", os.O_RDWR)\n+        try:\n+            req = bytearray(struct.pack(\"IIQQ\", memfd, 0, 0, size))\n+            return fcntl.ioctl(devfd, _udmabuf_create_ioctl(), req)\n+        finally:\n+            os.close(devfd)\n+    finally:\n+        os.close(memfd)\n+\n+\n+def _dmabuf_attach_count(dmabuf_fd) -\u003e int:\n+    \"\"\"Return the number of devices attached to dmabuf_fd, from debugfs.\"\"\"\n+    path = \"/sys/kernel/debug/dma_buf/bufinfo\"\n+    try:\n+        with open(path, \"r\", encoding=\"utf-8\") as f:\n+            lines = f.read().splitlines()\n+    except OSError as e:\n+        raise KsftSkipEx(f\"{path} is not readable: {e}\") from e\n+\n+    ino = os.fstat(dmabuf_fd).st_ino\n+    found = False\n+    for line in lines:\n+        fields = line.split(\"\\t\")\n+        if not found:\n+            found = (len(fields) == 7 and fields[5].isdigit() and\n+                     int(fields[5]) == ino)\n+        elif line.startswith(\"Total \"):\n+            return int(line.split()[1])\n+    raise KsftFailEx(f\"dma-buf {ino} not found in {path}\")\n+\n+\n+def _devmem_bind(bind, attrs) -\u003e None:\n+    \"\"\"Run a devmem bind op, skip the test if the device can't do devmem.\"\"\"\n+    try:\n+        bind(attrs)\n+    except NlError as e:\n+        if e.error == errno.EOPNOTSUPP:\n+            raise KsftSkipEx(f\"devmem binding not supported: {e}\") from e\n+        raise\n+\n+\n+def devmem_bind_rx_unregister_check(_nf) -\u003e None:\n+    \"\"\"Verify RX devmem bindings detach dma_buf synchronously on netdev unregister.\"\"\"\n+    dmabuf_fd = _create_udmabuf()\n+    defer(os.close, dmabuf_fd)\n+    nf_priv = NetdevFamily()\n+    defer(nf_priv.close)\n+    nsimdev = NetdevSimDev(queue_count=2)\n+    defer(nsimdev.remove)\n+    nsim = nsimdev.nsims[0]\n+\n+    ip(f\"link set dev {nsim.ifname} up\")\n+    with EthtoolFamily() as ef:\n+        ef.rings_set({\"header\": {\"dev-index\": nsim.ifindex},\n+                      \"tcp-data-split\": \"enabled\"})\n+    _devmem_bind(nf_priv.bind_rx, {\n+        \"ifindex\": nsim.ifindex,\n+        \"fd\": dmabuf_fd,\n+        \"queues\": [{\"id\": 1, \"type\": \"rx\"}],\n+    })\n+    ksft_ge(_dmabuf_attach_count(dmabuf_fd), 1)\n+\n+    nsimdev.remove()\n+    ksft_eq(_dmabuf_attach_count(dmabuf_fd), 0)\n+\n+    nf_priv.close()\n+\n+\n+def devmem_bind_tx_unregister_check(_nf) -\u003e None:\n+    \"\"\"Verify TX devmem bindings detach cleanly on netdev unregister without UAF.\"\"\"\n+    dmabuf_fd = _create_udmabuf()\n+    defer(os.close, dmabuf_fd)\n+    nf_priv = NetdevFamily()\n+    defer(nf_priv.close)\n+    nsimdev = NetdevSimDev(queue_count=2)\n+    defer(nsimdev.remove)\n+    nsim = nsimdev.nsims[0]\n+\n+    ip(f\"link set dev {nsim.ifname} up\")\n+    _devmem_bind(nf_priv.bind_tx, {\n+        \"ifindex\": nsim.ifindex,\n+        \"fd\": dmabuf_fd,\n+    })\n+    ksft_ge(_dmabuf_attach_count(dmabuf_fd), 1)\n+\n+    nsimdev.remove()\n+    ksft_eq(_dmabuf_attach_count(dmabuf_fd), 0)\n+\n+    nf_priv.close()\n+\n+\n def main() -\u003e None:\n     \"\"\" Ksft boiler plate main \"\"\"\n     nf = NetdevFamily()\n@@ -379,7 +496,9 @@ def main() -\u003e None:\n               page_pool_check,\n               page_pool_dump_ifindex,\n               page_pool_ifindex_leak_check,\n-              page_pool_stats_ifindex_check\n+              page_pool_stats_ifindex_check,\n+              devmem_bind_rx_unregister_check,\n+              devmem_bind_tx_unregister_check\n               ],\n              args=(nf, ))\n     ksft_exit()\n"
}

2/1 2026/10/14 22:43 agent patch-evaluator
2m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "NET_DEVMEM",
    "NETDEVSIM",
    "UDMABUF",
    "SYNC_FILE",
    "DEBUG_FS"
  ],
  "FocusSymbols": [
    "net_devmem_dev_unregister",
    "net_devmem_unbind_dmabuf",
    "net_devmem_bind_dmabuf",
    "net_devmem_lookup_dmabuf",
    "__net_devmem_dmabuf_binding_free",
    "netdev_nl_bind_rx_doit",
    "netdev_nl_bind_tx_doit",
    "nsim_pp_hold_write",
    "nsim_queue_mem_alloc",
    "nsim_do_psp"
  ],
  "Reasoning": "The patch series modifies the core networking devmem dmabuf subsystem (net/core/devmem.c) and netdevsim virtual driver to properly handle dmabuf unmapping and detaching upon network device unregistration, preventing use-after-free conditions. It alters locking, adds live binding tracking via xarray marks, updates devmem binding lookup and unbinding logic, and enables netdevsim support for unreadable netmem in page pools. This modifies reachable core networking and virtual device paths exercisable via generic Netlink and netdevice lifecycle operations in standard virtual environments.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 5c1e73fdbe1bc2f288495d4674c46085acfd2ee8
Author: syz-cluster <triage@syzkaller.com>
Date:   Wed Oct 14 22:43:30 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index 5c55c308487b4..f87f5e037b6fb 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -462,6 +462,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queu
 	nsim_bus_dev->port_count = port_count;
 	nsim_bus_dev->num_queues = num_queues;
 	nsim_bus_dev->initial_net = current->nsproxy->net_ns;
+	dma_coerce_mask_and_coherent(&nsim_bus_dev->dev, DMA_BIT_MASK(64));
 	/* Disallow using nsim_bus_dev */
 	smp_store_release(&nsim_bus_dev->init, false);
 
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index b4a99f3ceac60..357ea9e5623b3 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -414,19 +414,27 @@ static int nsim_poll(struct napi_struct *napi, int budget)
 	return done;
 }
 
-static int nsim_create_page_pool(struct page_pool **p, struct napi_struct *napi)
+static int nsim_create_page_pool(struct net_device *dev, struct page_pool **p,
+				 struct napi_struct *napi, int idx)
 {
+	struct netdevsim *ns = netdev_priv(dev);
 	struct page_pool_params params = {
 		.order = 0,
 		.pool_size = NSIM_RING_SIZE,
+		.flags = PP_FLAG_ALLOW_UNREADABLE_NETMEM,
+		.max_len = PAGE_SIZE,
 		.nid = NUMA_NO_NODE,
-		.dev = &napi->dev->dev,
+		.dev = &ns->nsim_bus_dev->dev,
 		.napi = napi,
 		.dma_dir = DMA_BIDIRECTIONAL,
-		.netdev = napi->dev,
+		.netdev = dev,
+		.queue_idx = idx,
 	};
 	struct page_pool *pool;
 
+	if (IS_ENABLED(CONFIG_HAS_DMA))
+		params.flags |= PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
+
 	pool = page_pool_create(&params);
 	if (IS_ERR(pool))
 		return PTR_ERR(pool);
@@ -450,7 +458,7 @@ static int nsim_init_napi(struct netdevsim *ns)
 	for (i = 0; i < dev->num_rx_queues; i++) {
 		rq = ns->rq[i];
 
-		err = nsim_create_page_pool(&rq->page_pool, &rq->napi);
+		err = nsim_create_page_pool(dev, &rq->page_pool, &rq->napi, i);
 		if (err)
 			goto err_pp_destroy;
 	}
@@ -762,14 +770,16 @@ nsim_queue_mem_alloc(struct net_device *dev,
 	if (ns->rq_reset_mode == 1) {
 		if (!netif_running(ns->netdev))
 			return -ENETDOWN;
-		return nsim_create_page_pool(&qmem->pp, &ns->rq[idx]->napi);
+		return nsim_create_page_pool(dev, &qmem->pp,
+					     &ns->rq[idx]->napi, idx);
 	}
 
 	qmem->rq = nsim_queue_alloc();
 	if (!qmem->rq)
 		return -ENOMEM;
 
-	err = nsim_create_page_pool(&qmem->rq->page_pool, &qmem->rq->napi);
+	err = nsim_create_page_pool(dev, &qmem->rq->page_pool, &qmem->rq->napi,
+				    idx);
 	if (err)
 		goto err_free;
 
@@ -929,12 +939,15 @@ nsim_pp_hold_write(struct file *file, const char __user *data,
 		return ret;
 
 	rtnl_lock();
+	netdev_lock(ns->netdev);
 	ret = count;
 	if (val == !!ns->page)
 		goto exit;
 
 	if (!netif_running(ns->netdev) && val) {
 		ret = -ENETDOWN;
+	} else if (val && page_pool_is_unreadable(ns->rq[0]->page_pool)) {
+		ret = -EOPNOTSUPP;
 	} else if (val) {
 		ns->page = page_pool_dev_alloc_pages(ns->rq[0]->page_pool);
 		if (!ns->page)
@@ -946,6 +959,7 @@ nsim_pp_hold_write(struct file *file, const char __user *data,
 	}
 
 exit:
+	netdev_unlock(ns->netdev);
 	rtnl_unlock();
 	return ret;
 }
@@ -1051,6 +1065,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
 	ns->netdev->netdev_ops = &nsim_netdev_ops;
 	ns->netdev->stat_ops = &nsim_stat_ops;
 	ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops;
+	ns->netdev->netmem_tx = NETMEM_TX_DMA;
 	netdev_lockdep_set_classes(ns->netdev);
 
 	err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev);
diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c
index 6b3532b5e360d..908cc0d391dc6 100644
--- a/drivers/net/netdevsim/psp.c
+++ b/drivers/net/netdevsim/psp.c
@@ -86,6 +86,11 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
 		__wsum csum;
 		int udplen;
 
+		if (!skb_frags_readable(skb)) {
+			rc = SKB_DROP_REASON_PSP_OUTPUT;
+			goto out_unlock;
+		}
+
 		/* Do not decapsulate. Receive the skb with the udp and psp
 		 * headers still there as if this is a normal udp packet.
 		 * psp_dev_encapsulate() sets udp checksum to 0, so we need to
diff --git a/net/core/devmem.c b/net/core/devmem.c
index f4d60654ce7fd..dd07203076808 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -20,6 +20,7 @@
 #include <net/tcp.h>
 #include <trace/events/page_pool.h>
 
+#include "dev.h"
 #include "devmem.h"
 #include "mp_dmabuf_devmem.h"
 #include "page_pool_priv.h"
@@ -27,6 +28,8 @@
 /* Device memory support */
 
 static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);
+#define NET_DEVMEM_BINDING_LIVE XA_MARK_1
+static DEFINE_MUTEX(net_devmem_lock);
 
 static const struct memory_provider_ops dmabuf_devmem_ops;
 
@@ -58,6 +61,21 @@ static void net_devmem_dmabuf_binding_release(struct percpu_ref *ref)
 	schedule_work(&binding->unbind_w);
 }
 
+static void
+net_devmem_dmabuf_binding_unmap(struct net_devmem_dmabuf_binding *binding)
+{
+	lockdep_assert_held(&binding->lock);
+
+	if (!binding->sgt)
+		return;
+
+	dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt,
+					  binding->direction);
+	dma_buf_detach(binding->dmabuf, binding->attachment);
+	binding->sgt = NULL;
+	binding->attachment = NULL;
+}
+
 void __net_devmem_dmabuf_binding_free(struct work_struct *wq)
 {
 	struct net_devmem_dmabuf_binding *binding = container_of(wq, typeof(*binding), unbind_w);
@@ -74,9 +92,13 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq)
 		  size, avail))
 		gen_pool_destroy(binding->chunk_pool);
 
-	dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt,
-					  binding->direction);
-	dma_buf_detach(binding->dmabuf, binding->attachment);
+	mutex_lock(&net_devmem_lock);
+	mutex_lock(&binding->lock);
+	net_devmem_dmabuf_binding_unmap(binding);
+	mutex_unlock(&binding->lock);
+	xa_erase(&net_devmem_dmabuf_bindings, binding->id);
+	mutex_unlock(&net_devmem_lock);
+
 	dma_buf_put(binding->dmabuf);
 	xa_destroy(&binding->bound_rxqs);
 	percpu_ref_exit(&binding->ref);
@@ -129,10 +151,11 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
 	unsigned long xa_idx;
 	unsigned int rxq_idx;
 
-	xa_erase(&net_devmem_dmabuf_bindings, binding->id);
+	xa_clear_mark(&net_devmem_dmabuf_bindings, binding->id,
+		      NET_DEVMEM_BINDING_LIVE);
 
 	/* Ensure no tx net_devmem_lookup_dmabuf() are in flight after the
-	 * erase.
+	 * mark is cleared.
 	 */
 	synchronize_net();
 
@@ -153,6 +176,89 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
 	percpu_ref_kill(&binding->ref);
 }
 
+static void
+net_devmem_dev_unregister_rx(struct net_devmem_dmabuf_binding *binding,
+			     unsigned long xa_idx, struct net_device *dev)
+{
+	if (xa_get_mark(&net_devmem_dmabuf_bindings, xa_idx,
+			NET_DEVMEM_BINDING_LIVE) ||
+	    READ_ONCE(binding->dev) != dev)
+		return;
+
+	mutex_lock(&binding->lock);
+	WRITE_ONCE(binding->dev, NULL);
+	if (!netif_is_queue_leasee(dev))
+		net_devmem_dmabuf_binding_unmap(binding);
+	mutex_unlock(&binding->lock);
+}
+
+static bool
+net_devmem_dev_unregister_tx(struct net_devmem_dmabuf_binding *binding,
+			     unsigned long xa_idx, struct net_device *dev)
+{
+	if (READ_ONCE(binding->dev) == dev) {
+		xa_clear_mark(&net_devmem_dmabuf_bindings, xa_idx,
+			      NET_DEVMEM_BINDING_LIVE);
+
+		mutex_lock(&binding->lock);
+		WRITE_ONCE(binding->dev, NULL);
+		WRITE_ONCE(binding->vdev, NULL);
+		mutex_unlock(&binding->lock);
+		return true;
+	}
+
+	if (READ_ONCE(binding->vdev) == dev) {
+		mutex_lock(&binding->lock);
+		WRITE_ONCE(binding->vdev, NULL);
+		mutex_unlock(&binding->lock);
+	}
+
+	return false;
+}
+
+static void net_devmem_unmap_detached_tx(void)
+{
+	struct net_devmem_dmabuf_binding *binding;
+	unsigned long xa_idx;
+
+	/* Ensure no tx net_devmem_lookup_dmabuf() or
+	 * validate_xmit_unreadable_skb() are in flight after detach.
+	 */
+	synchronize_net();
+
+	xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
+		if (binding->direction != DMA_TO_DEVICE ||
+		    READ_ONCE(binding->dev))
+			continue;
+
+		mutex_lock(&binding->lock);
+		net_devmem_dmabuf_binding_unmap(binding);
+		mutex_unlock(&binding->lock);
+	}
+}
+
+void net_devmem_dev_unregister(struct net_device *dev)
+{
+	struct net_devmem_dmabuf_binding *binding;
+	bool tx_detached = false;
+	unsigned long xa_idx;
+
+	if (dev->reg_state != NETREG_UNREGISTERING)
+		return;
+
+	mutex_lock(&net_devmem_lock);
+	xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
+		if (binding->direction == DMA_FROM_DEVICE)
+			net_devmem_dev_unregister_rx(binding, xa_idx, dev);
+		else if (net_devmem_dev_unregister_tx(binding, xa_idx, dev))
+			tx_detached = true;
+	}
+
+	if (tx_detached)
+		net_devmem_unmap_detached_tx();
+	mutex_unlock(&net_devmem_lock);
+}
+
 int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				    struct net_devmem_dmabuf_binding *binding,
 				    struct netlink_ext_ack *extack)
@@ -331,6 +437,8 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 			      GFP_KERNEL);
 	if (err < 0)
 		goto err_free_chunks;
+	xa_set_mark(&net_devmem_dmabuf_bindings, binding->id,
+		    NET_DEVMEM_BINDING_LIVE);
 
 	list_add(&binding->list, &priv->bindings);
 
@@ -359,9 +467,11 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
 {
 	struct net_devmem_dmabuf_binding *binding;
+	unsigned long xa_idx = id;
 
 	rcu_read_lock();
-	binding = xa_load(&net_devmem_dmabuf_bindings, id);
+	binding = xa_find(&net_devmem_dmabuf_bindings, &xa_idx, id,
+			  NET_DEVMEM_BINDING_LIVE);
 	if (binding) {
 		if (!net_devmem_dmabuf_binding_get(binding))
 			binding = NULL;
@@ -529,16 +639,19 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv,
 	unsigned long xa_idx;
 
 	xa_for_each(&binding->bound_rxqs, xa_idx, bound_rxq) {
-		if (bound_rxq == rxq) {
-			xa_erase(&binding->bound_rxqs, xa_idx);
-			if (xa_empty(&binding->bound_rxqs)) {
-				mutex_lock(&binding->lock);
-				ASSERT_EXCLUSIVE_WRITER(binding->dev);
-				WRITE_ONCE(binding->dev, NULL);
-				mutex_unlock(&binding->lock);
-			}
-			break;
+		if (bound_rxq != rxq)
+			continue;
+
+		xa_erase(&binding->bound_rxqs, xa_idx);
+		if (xa_empty(&binding->bound_rxqs)) {
+			mutex_lock(&binding->lock);
+			ASSERT_EXCLUSIVE_WRITER(binding->dev);
+			WRITE_ONCE(binding->dev, NULL);
+			if (!rxq->lease)
+				net_devmem_dmabuf_binding_unmap(binding);
+			mutex_unlock(&binding->lock);
 		}
+		break;
 	}
 }
 
diff --git a/net/core/devmem.h b/net/core/devmem.h
index 4a293a7d1149c..5c47c8c3c7d2d 100644
--- a/net/core/devmem.h
+++ b/net/core/devmem.h
@@ -27,7 +27,7 @@ struct net_devmem_dmabuf_binding {
 	 */
 	void *vdev;
 	struct gen_pool *chunk_pool;
-	/* Protect dev */
+	/* Protect dev, attachment and sgt */
 	struct mutex lock;
 
 	/* The user holds a ref (via the netlink API) for as long as they want
@@ -38,7 +38,8 @@ struct net_devmem_dmabuf_binding {
 	 *
 	 * The binding undos itself and unmaps the underlying dmabuf once all
 	 * those refs are dropped and the binding is no longer desired or in
-	 * use.
+	 * use. The dmabuf may be unmapped earlier, when the device it is
+	 * mapped for is unregistered.
 	 *
 	 * net_devmem_get_net_iov() on dmabuf net_iovs will increment this
 	 * reference, making sure that the binding remains alive until all the
@@ -100,6 +101,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 		       struct netlink_ext_ack *extack);
 struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id);
 void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding);
+void net_devmem_dev_unregister(struct net_device *dev);
 int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				    struct net_devmem_dmabuf_binding *binding,
 				    struct netlink_ext_ack *extack);
@@ -196,6 +198,10 @@ net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
 {
 }
 
+static inline void net_devmem_dev_unregister(struct net_device *dev)
+{
+}
+
 static inline int
 net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				struct net_devmem_dmabuf_binding *binding,
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 33b9f4eb9565a..b04e22937b789 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -1488,6 +1488,7 @@ static int netdev_genl_netdevice_event(struct notifier_block *nb,
 		break;
 	case NETDEV_UNREGISTER:
 		netdev_lock(netdev);
+		net_devmem_dev_unregister(netdev);
 		netdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_DEL_NTF);
 		netdev_unlock(netdev);
 		break;
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index 737e7e6327b37..1e21f0055a2c0 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -11,6 +11,7 @@ CONFIG_CRYPTO_ARIA=y
 CONFIG_CRYPTO_CHACHA20POLY1305=m
 CONFIG_CRYPTO_SHA1=y
 CONFIG_CRYPTO_SM4_GENERIC=y
+CONFIG_DEBUG_FS=y
 CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_DUMMY=y
@@ -76,6 +77,7 @@ CONFIG_NET_CLS_BPF=m
 CONFIG_NET_CLS_FLOWER=m
 CONFIG_NET_CLS_MATCHALL=m
 CONFIG_NET_CLS_U32=m
+CONFIG_NET_DEVMEM=y
 CONFIG_NETDEVSIM=m
 CONFIG_NET_DROP_MONITOR=m
 CONFIG_NETFILTER=y
@@ -120,6 +122,7 @@ CONFIG_OPENVSWITCH=m
 CONFIG_PAGE_POOL_STATS=y
 CONFIG_PSAMPLE=m
 CONFIG_RPS=y
+CONFIG_SYNC_FILE=y
 CONFIG_SYN_COOKIES=y
 CONFIG_SYSCTL=y
 CONFIG_SYSFS=y
@@ -131,6 +134,7 @@ CONFIG_TEST_BPF=m
 CONFIG_TLS=m
 CONFIG_TRACEPOINTS=y
 CONFIG_TUN=y
+CONFIG_UDMABUF=y
 CONFIG_USER_NS=y
 CONFIG_VETH=y
 CONFIG_VLAN_8021Q=y
diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py
index ceb44c8e1fec5..988878b71358c 100755
--- a/tools/testing/selftests/net/nl_netdev.py
+++ b/tools/testing/selftests/net/nl_netdev.py
@@ -6,10 +6,14 @@ Tests for the netdev netlink family.
 """
 
 import errno
+import fcntl
+import mmap
+import os
+import struct
 from os import system
-from lib.py import ksft_run, ksft_exit
+from lib.py import ksft_run, ksft_exit, KsftFailEx, KsftSkipEx
 from lib.py import ksft_eq, ksft_ge, ksft_ne, ksft_raises, ksft_busy_wait
-from lib.py import NetdevFamily, NetdevSimDev, NlError, defer, ip
+from lib.py import EthtoolFamily, NetdevFamily, NetdevSimDev, NlError, defer, ip
 
 
 def empty_check(nf) -> None:
@@ -366,6 +370,119 @@ def page_pool_stats_ifindex_check(nf) -> None:
     ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.info.id')
 
 
+def _udmabuf_create_ioctl() -> int:
+    """Return UDMABUF_CREATE, _IOW('u', 0x42, struct udmabuf_create)."""
+    machine = os.uname().machine
+    if machine.startswith(("alpha", "mips", "ppc", "powerpc", "sparc")):
+        ioc_write = 4 << 29
+    elif machine.startswith("parisc"):
+        ioc_write = 2 << 30
+    else:
+        ioc_write = 1 << 30
+    return ioc_write | 24 << 16 | ord("u") << 8 | 0x42
+
+
+def _create_udmabuf(num_pages=64) -> int:
+    """Create a sealed memfd-backed udmabuf fd for devmem tests."""
+    if not os.path.exists("/dev/udmabuf"):
+        raise KsftSkipEx("/dev/udmabuf is not available")
+
+    size = num_pages * mmap.PAGESIZE
+    memfd = os.memfd_create("devmem-ksft", os.MFD_ALLOW_SEALING)
+    try:
+        os.ftruncate(memfd, size)
+        fcntl.fcntl(memfd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_SHRINK)
+        devfd = os.open("/dev/udmabuf", os.O_RDWR)
+        try:
+            req = bytearray(struct.pack("IIQQ", memfd, 0, 0, size))
+            return fcntl.ioctl(devfd, _udmabuf_create_ioctl(), req)
+        finally:
+            os.close(devfd)
+    finally:
+        os.close(memfd)
+
+
+def _dmabuf_attach_count(dmabuf_fd) -> int:
+    """Return the number of devices attached to dmabuf_fd, from debugfs."""
+    path = "/sys/kernel/debug/dma_buf/bufinfo"
+    try:
+        with open(path, "r", encoding="utf-8") as f:
+            lines = f.read().splitlines()
+    except OSError as e:
+        raise KsftSkipEx(f"{path} is not readable: {e}") from e
+
+    ino = os.fstat(dmabuf_fd).st_ino
+    found = False
+    for line in lines:
+        fields = line.split("\t")
+        if not found:
+            found = (len(fields) == 7 and fields[5].isdigit() and
+                     int(fields[5]) == ino)
+        elif line.startswith("Total "):
+            return int(line.split()[1])
+    raise KsftFailEx(f"dma-buf {ino} not found in {path}")
+
+
+def _devmem_bind(bind, attrs) -> None:
+    """Run a devmem bind op, skip the test if the device can't do devmem."""
+    try:
+        bind(attrs)
+    except NlError as e:
+        if e.error == errno.EOPNOTSUPP:
+            raise KsftSkipEx(f"devmem binding not supported: {e}") from e
+        raise
+
+
+def devmem_bind_rx_unregister_check(_nf) -> None:
+    """Verify RX devmem bindings detach dma_buf synchronously on netdev unregister."""
+    dmabuf_fd = _create_udmabuf()
+    defer(os.close, dmabuf_fd)
+    nf_priv = NetdevFamily()
+    defer(nf_priv.close)
+    nsimdev = NetdevSimDev(queue_count=2)
+    defer(nsimdev.remove)
+    nsim = nsimdev.nsims[0]
+
+    ip(f"link set dev {nsim.ifname} up")
+    with EthtoolFamily() as ef:
+        ef.rings_set({"header": {"dev-index": nsim.ifindex},
+                      "tcp-data-split": "enabled"})
+    _devmem_bind(nf_priv.bind_rx, {
+        "ifindex": nsim.ifindex,
+        "fd": dmabuf_fd,
+        "queues": [{"id": 1, "type": "rx"}],
+    })
+    ksft_ge(_dmabuf_attach_count(dmabuf_fd), 1)
+
+    nsimdev.remove()
+    ksft_eq(_dmabuf_attach_count(dmabuf_fd), 0)
+
+    nf_priv.close()
+
+
+def devmem_bind_tx_unregister_check(_nf) -> None:
+    """Verify TX devmem bindings detach cleanly on netdev unregister without UAF."""
+    dmabuf_fd = _create_udmabuf()
+    defer(os.close, dmabuf_fd)
+    nf_priv = NetdevFamily()
+    defer(nf_priv.close)
+    nsimdev = NetdevSimDev(queue_count=2)
+    defer(nsimdev.remove)
+    nsim = nsimdev.nsims[0]
+
+    ip(f"link set dev {nsim.ifname} up")
+    _devmem_bind(nf_priv.bind_tx, {
+        "ifindex": nsim.ifindex,
+        "fd": dmabuf_fd,
+    })
+    ksft_ge(_dmabuf_attach_count(dmabuf_fd), 1)
+
+    nsimdev.remove()
+    ksft_eq(_dmabuf_attach_count(dmabuf_fd), 0)
+
+    nf_priv.close()
+
+
 def main() -> None:
     """ Ksft boiler plate main """
     nf = NetdevFamily()
@@ -379,7 +496,9 @@ def main() -> None:
               page_pool_check,
               page_pool_dump_ifindex,
               page_pool_ifindex_leak_check,
-              page_pool_stats_ifindex_check
+              page_pool_stats_ifindex_check,
+              devmem_bind_rx_unregister_check,
+              devmem_bind_tx_unregister_check
               ],
              args=(nf, ))
     ksft_exit()

3/2 2026/10/14 22:43 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 10632
							output: 31
							thoughts: 836
						

Thoughts:
**Initial Assessment of a Linux Kernel Patch Series**

Okay, so I've got a patch series here for evaluation, targeting the Linux kernel. First things first, I need to understand the scope and implications. Let's break down the individual changes:

*   **`drivers/net/netdevsim/bus.c`**: Seems like we're setting up the DMA mask for the simulated network device's bus. Standard practice, making sure the device's DMA capabilities are correctly advertised. Nothing immediately alarming here.

*   **`drivers/net/netdevsim/netdev.c`**: This is where things get interesting.  We've got new flags and parameters being added to `nsim_create_page_pool`, specifically `PP_FLAG_ALLOW_UNREADABLE_NETMEM`, setting `max_len = PAGE_SIZE`, and introducing DMA-related flags. The use of `netdev_lock` in `nsim_pp_hold_write` with the unreadability check suggests synchronization around shared memory resources.  Setting `ns->netdev->netmem_tx = NETMEM_TX_DMA` strongly hints at DMA usage within the netdevsim device. This implies changes to memory management and access.

*   **`drivers/net/netdevsim/psp.c`**:  A check for unreadable SKB fragments (`!skb_frags_readable(skb)`) in `nsim_do_psp` suggests an interaction with the new page pool flags and unreadability. This reinforces my thought about memory access control and potential race conditions in the context of the simulated device.

*   **`net/core/devmem.c`**: This is the core of the matter.  Significant changes here. Locking, lifecycle management of devmem bindings, new marks (`NET_DEVMEM_BINDING_LIVE`), unmapping operations, and registration/unregistration logic tied to `NETDEV_UNREGISTER`.  We're dealing with the devmem subsystem, which I know is the relatively recent devmem TCP/dmabuf memory provider.  This is a critical area, affecting how we manage DMA-able memory buffers, especially for network traffic, so this needs to be examined very carefully.  The introduction of `net_devmem_lock` implies a need for concurrency control, a signal of an area where races can occur and memory issues can manifest.

*   **`net/core/devmem.h`**: Just a new prototype, so supporting the changes in .c.

*   **`net/core/netdev-genl.c`**:  A call to the new `net_devmem_dev_unregister` function on `NETDEV_UNREGISTER` signifies devmem is going to be cleaned up when a device is unregistered, which seems right and expected.

*   **Selftests**:  Good, they've been updated! This should provide some coverage for the new changes, although I'll have to assess if they cover all the crucial scenarios.

Alright, so the pieces are coming together. `netdevsim` is our simulated network device driver, a test and fuzzing tool. And `net/core/devmem.c` is the core devmem TCP/dmabuf memory provider. This is critical: `netdevsim` is apparently using the new `devmem` subsystem. Given that `netdev` and `devmem` are core networking components, and now they are being tied together, it's definitely in a reachable spot.

My initial hypothesis is that this patch series is enabling `netdevsim` to utilize the `devmem` subsystem for network memory management. This is important, because it leverages a common, recently added, and potentially more efficient memory management method, but the code and Kconfig *have* to be checked for correctness in detail, as well as testing, because it's a recent subsystem, which means risks are higher. This setup warrants a close inspection of the synchronization primitives and memory access patterns within `net/core/devmem.c` and their interactions with `netdevsim`. I need to dig into the `devmem` code itself to fully understand the implications. Time to check the code and Kconfig!



4/2 2026/10/14 22:43 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "config NET_DEVMEM",
  "PathPrefixes": [
    "net/core/"
  ]
}

Results:
{
  "error": "no matches"
}

5/2 2026/10/14 22:43 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 12411
							output: 28
							thoughts: 19
						

Thoughts:
Here's my thought process, as if I were considering this myself:

**Kconfig Dive for Memory Mapping Configuration**

Okay, so I need to figure out where the `NET_DEVMEM` or `devmem` options are defined within the kernel's configuration files. This implies I'm probably dealing with memory mapping for device access, likely related to network drivers or some other hardware interaction. I'll need to use the standard tools for navigating the Kconfig system to understand how these options are controlled and what dependencies or build-time considerations they influence. My goal is to determine the context and impact of these definitions.



6/2 2026/10/14 22:43 tool grepper
0m Args:
{
  "Expression": "NET_DEVMEM",
  "PathPrefixes": [
    "net/"
  ]
}

Results:
{
  "Output": "net/Kconfig=66=config SKB_EXTENSIONS\n--\nnet/Kconfig-68-\nnet/Kconfig:69:config NET_DEVMEM\nnet/Kconfig-70-\tdef_bool y\n--\nnet/core/Makefile=51=obj-$(CONFIG_NET_TEST) += net_test.o\nnet/core/Makefile:52:obj-$(CONFIG_NET_DEVMEM) += devmem.o\nnet/core/Makefile-53-obj-$(CONFIG_DEBUG_NET) += lock_debug.o\n--\nnet/core/devmem.c=30=static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);\nnet/core/devmem.c:31:#define NET_DEVMEM_BINDING_LIVE XA_MARK_1\nnet/core/devmem.c-32-static DEFINE_MUTEX(net_devmem_lock);\n--\nnet/core/devmem.c=148=void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)\n--\nnet/core/devmem.c-154-\txa_clear_mark(\u0026net_devmem_dmabuf_bindings, binding-\u003eid,\nnet/core/devmem.c:155:\t\t      NET_DEVMEM_BINDING_LIVE);\nnet/core/devmem.c-156-\n--\nnet/core/devmem.c=180=net_devmem_dev_unregister_rx(struct net_devmem_dmabuf_binding *binding,\n--\nnet/core/devmem.c-183-\tif (xa_get_mark(\u0026net_devmem_dmabuf_bindings, xa_idx,\nnet/core/devmem.c:184:\t\t\tNET_DEVMEM_BINDING_LIVE) ||\nnet/core/devmem.c-185-\t    READ_ONCE(binding-\u003edev) != dev)\n--\nnet/core/devmem.c=196=net_devmem_dev_unregister_tx(struct net_devmem_dmabuf_binding *binding,\n--\nnet/core/devmem.c-200-\t\txa_clear_mark(\u0026net_devmem_dmabuf_bindings, xa_idx,\nnet/core/devmem.c:201:\t\t\t      NET_DEVMEM_BINDING_LIVE);\nnet/core/devmem.c-202-\n--\nnet/core/devmem.c=295=net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,\n--\nnet/core/devmem.c-440-\txa_set_mark(\u0026net_devmem_dmabuf_bindings, binding-\u003eid,\nnet/core/devmem.c:441:\t\t    NET_DEVMEM_BINDING_LIVE);\nnet/core/devmem.c-442-\n--\nnet/core/devmem.c=467=struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)\n--\nnet/core/devmem.c-473-\tbinding = xa_find(\u0026net_devmem_dmabuf_bindings, \u0026xa_idx, id,\nnet/core/devmem.c:474:\t\t\t  NET_DEVMEM_BINDING_LIVE);\nnet/core/devmem.c-475-\tif (binding) {\n--\nnet/core/devmem.h-9- */\nnet/core/devmem.h:10:#ifndef _NET_DEVMEM_H\nnet/core/devmem.h:11:#define _NET_DEVMEM_H\nnet/core/devmem.h-12-\n--\nnet/core/devmem.h=18=struct net_devmem_dmabuf_binding {\n--\nnet/core/devmem.h-79-\nnet/core/devmem.h:80:#if defined(CONFIG_NET_DEVMEM)\nnet/core/devmem.h-81-/* Owner of the dma-buf chunks inserted into the gen pool. Each scatterlist\n--\nnet/core/devmem.h=248=net_devmem_iov_binding(const struct net_iov *niov)\n--\nnet/core/devmem.h-253-\nnet/core/devmem.h:254:#endif /* _NET_DEVMEM_H */\n--\nnet/core/mp_dmabuf_devmem.h-12-\nnet/core/mp_dmabuf_devmem.h:13:#if defined(CONFIG_NET_DEVMEM)\nnet/core/mp_dmabuf_devmem.h-14-int mp_dmabuf_devmem_init(struct page_pool *pool);\n"
}

7/2 2026/10/14 22:43 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 13794
							output: 31
							thoughts: 21
						

Thoughts:
Here's my thought process, as requested:

**Navigating the Kernel Configuration Landscape**

Okay, let's dive into this. I'm thinking, "right, I need to check something in the kernel configuration system, specifically within the `net/Kconfig` file." Now, rather than just blindly browsing, I'm going to pinpoint the relevant section. I seem to recall the area of interest being around line 69, so I'll keep that in mind. I'll utilize my tool of choice, probably `read-file` (or similar) to pull the contents of the file. That will enable me to efficiently inspect that specific region of `net/Kconfig` and grab the information I'm looking for. It's the most straightforward and precise way to approach this.



8/2 2026/10/14 22:43 tool read-file
0m Args:
{
  "File": "net/Kconfig",
  "FirstLine": 60,
  "LineCount": 30
}

Results:
{
  "Contents": "  60:\tconfig NET_REDIRECT\n  61:\t\tbool\n  62:\t\n  63:\tconfig SKB_DECRYPTED\n  64:\t\tbool\n  65:\t\n  66:\tconfig SKB_EXTENSIONS\n  67:\t\tbool\n  68:\t\n  69:\tconfig NET_DEVMEM\n  70:\t\tdef_bool y\n  71:\t\tselect GENERIC_ALLOCATOR\n  72:\t\tdepends on DMA_SHARED_BUFFER\n  73:\t\tdepends on PAGE_POOL\n  74:\t\n  75:\tconfig NET_SHAPER\n  76:\t\tbool\n  77:\t\n  78:\tconfig NET_CRC32C\n  79:\t\tbool\n  80:\t\tselect CRC32\n  81:\t\n  82:\tmenu \"Networking options\"\n  83:\t\n  84:\tsource \"net/packet/Kconfig\"\n  85:\tsource \"net/psp/Kconfig\"\n  86:\tsource \"net/unix/Kconfig\"\n  87:\tsource \"net/tls/Kconfig\"\n  88:\tsource \"net/xfrm/Kconfig\"\n  89:\tsource \"net/iucv/Kconfig\"\n"
}

9/2 2026/10/14 22:43 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 14336
							output: 34
							thoughts: 23
						

Thoughts:
Here's my thought process, as it went:

**Examining Kconfig for NETDEVSIM**

Okay, so I need to figure out how `NETDEVSIM` is configured within the kernel. My first instinct is to go directly to the source and check its configuration file. That means diving into the `drivers/net/netdevsim/Kconfig` file. That's usually the standard place for network device-related configuration options. By examining that `Kconfig` file, I should be able to see the dependencies, help text, default settings, and overall control flow for enabling or disabling `NETDEVSIM` within the build system. This will give me a very precise understanding of the option's purpose, how it interacts with other features, and how to control it in a configuration. Time to start digging!



10/2 2026/10/14 22:43 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "config NETDEVSIM",
  "PathPrefixes": [
    "drivers/net/netdevsim/"
  ]
}

Results:
{
  "error": "no matches"
}

11/2 2026/10/14 22:43 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 14582
							output: 30
							thoughts: 12
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Tracing the NETDEVSIM Definition**

Okay, so I need to get my bearings. The first thing I'm doing is trying to pinpoint the definition of "NETDEVSIM." I'm mentally parsing where this term is likely to be declared. Is it a macro, a type definition, a global variable, or a function? It could be anything. My immediate thought is to start with the obvious; I'm implicitly assuming a code-base of some reasonable size, where there will be documentation, code search tools, or a well-defined build process or dependency system I can leverage to find the origin of the term in use. I'll need to use these tools to locate its declaration, because this is the fundamental first step in understanding its scope, purpose, and potential impact on the system. I have a feeling this will involve some form of grep, `find`, or potentially a more sophisticated IDE search, depending on the environment I'm working in. The actual tool use is less important than making the choice to start the investigation here. This is the bedrock of understanding the meaning of this code.



12/2 2026/10/14 22:43 tool grepper
0m Args:
{
  "Expression": "config NETDEVSIM",
  "PathPrefixes": [
    "drivers/net/"
  ]
}

Results:
{
  "Output": "drivers/net/Kconfig=602=source \"drivers/net/hyperv/Kconfig\"\ndrivers/net/Kconfig-603-\ndrivers/net/Kconfig:604:config NETDEVSIM\ndrivers/net/Kconfig-605-\ttristate \"Simulated networking device\"\n"
}

13/2 2026/10/14 22:43 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 14959
							output: 34
							thoughts: 19
						

Thoughts:
Okay, let's dive into this. Here's my thought process on the matter:

**Analyzing the Kconfig File for Network Drivers**

Alright, I need to get a handle on the configuration options for network drivers. The best place to start is likely the `drivers/net/Kconfig` file, specifically around line 604. That area probably contains crucial definitions or dependencies for a key set of network-related features. I'm going to focus my attention there and see what insights I can glean about how these options are structured, and how the various network driver configurations relate to each other. I'm looking for the 'meat' of the configuration details, the dependencies, and any hints about how to extend or customize the network driver behavior. Time to delve into the code.



14/2 2026/10/14 22:43 tool read-file
0m Args:
{
  "File": "drivers/net/Kconfig",
  "FirstLine": 600,
  "LineCount": 25
}

Results:
{
  "Contents": " 600:\t\n 601:\tsource \"drivers/net/thunderbolt/Kconfig\"\n 602:\tsource \"drivers/net/hyperv/Kconfig\"\n 603:\t\n 604:\tconfig NETDEVSIM\n 605:\t\ttristate \"Simulated networking device\"\n 606:\t\tdepends on DEBUG_FS\n 607:\t\tdepends on INET\n 608:\t\tdepends on PSAMPLE || PSAMPLE=n\n 609:\t\tdepends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n\n 610:\t\tselect NET_DEVLINK\n 611:\t\tselect PAGE_POOL\n 612:\t\tselect NET_SHAPER\n 613:\t\thelp\n 614:\t\t  This driver is a developer testing tool and software model that can\n 615:\t\t  be used to test various control path networking APIs, especially\n 616:\t\t  HW-offload related.\n 617:\t\n 618:\t\t  To compile this driver as a module, choose M here: the module\n 619:\t\t  will be called netdevsim.\n 620:\t\n 621:\tconfig NET_FAILOVER\n 622:\t\ttristate \"Failover driver\"\n 623:\t\tselect FAILOVER\n 624:\t\thelp\n"
}

15/2 2026/10/14 22:43 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 15538
							output: 36
							thoughts: 729
						

Thoughts:
**Analyzing the Netdevsim/Devmem Interaction**

Okay, let's dive into this patch and understand how netdevsim and devmem are playing together here. My initial thought is to carefully analyze the diff, paying close attention to the functions being touched and their implications.

First, I see the changes in `drivers/net/netdevsim/bus.c`, specifically in `nsim_bus_dev_new`, where `dma_coerce_mask_and_coherent()` is being introduced with a DMA bit mask of 64. This immediately suggests a concern for DMA compatibility, potentially aiming to support larger transfers or addressing capabilities. I'll need to remember that as I move through the code.

Next, I am observing a bunch of changes in `drivers/net/netdevsim/netdev.c` inside of `nsim_create_page_pool`. A lot of work seems to be happening with page pools and flags: `PP_FLAG_ALLOW_UNREADABLE_NETMEM`, `PP_FLAG_DMA_MAP`, and `PP_FLAG_DMA_SYNC_DEV`. It looks like we're setting up the page pool with DMA considerations and potentially allowing for unreadable netmem in some scenarios. I'll need to investigate these flags further. The `nsim_init_napi` and `nsim_queue_mem_alloc` functions also use `nsim_create_page_pool`, so I'll need to keep an eye on how these are used in the broader picture. Also, `nsim_pp_hold_write` with the addition of a `netdev_lock` and the `page_pool_is_unreadable` check indicates there are changes to protect against race conditions. And finally, setting `ns->netdev->netmem_tx = NETMEM_TX_DMA` in `nsim_init_netdevsim` suggests DMA is being used for TX paths in this virtual device.

In `drivers/net/netdevsim/psp.c`, the `nsim_do_psp` function's check for `!skb_frags_readable(skb)` may be relevant in DMA-related scenarios.

Now, the meat of the matter seems to be happening in `net/core/devmem.c`. There are a number of new functions appearing: `net_devmem_dmabuf_binding_unmap`, `net_devmem_dev_unregister_rx`, `net_devmem_dev_unregister_tx`, `net_devmem_unmap_detached_tx`, `net_devmem_dev_unregister`. These are all clearly focused on managing the binding and unbinding of DMA buffers with devmem. The change from `xa_erase` to `xa_clear_mark` in `net_devmem_unbind_dmabuf`, the setting of the `NET_DEVMEM_BINDING_LIVE` mark in `net_devmem_bind_dmabuf`, and the use of marks with `xa_find` in `net_devmem_lookup_dmabuf` reveal the shift towards a more sophisticated state management system for these buffers. The call to `net_devmem_dmabuf_binding_unmap` from `mp_dmabuf_devmem_uninstall` suggests clean-up handling.

Finally, the `netdev_genl_netdevice_event` function in `net/core/netdev-genl.c` calling `net_devmem_dev_unregister` upon `NETDEV_UNREGISTER` indicates a tie-in with device unregistration, meaning we need to handle this as part of the teardown process for devmem-backed devices.

I need to read `net/core/devmem.c` more carefully to understand the exact mechanics of these new functions and the overall strategy here. This patch is definitely adding some crucial infrastructure for interfacing netdevsim with devmem, and my goal is to fully grasp its implications.



16/2 2026/10/14 22:44 tool read-file
0m Args:
{
  "File": "net/core/devmem.c",
  "FirstLine": 145,
  "LineCount": 85
}

Results:
{
  "Contents": " 145:\t\tgen_pool_free(binding-\u003echunk_pool, dma_addr, niov_size);\n 146:\t}\n 147:\t\n 148:\tvoid net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)\n 149:\t{\n 150:\t\tstruct netdev_rx_queue *rxq;\n 151:\t\tunsigned long xa_idx;\n 152:\t\tunsigned int rxq_idx;\n 153:\t\n 154:\t\txa_clear_mark(\u0026net_devmem_dmabuf_bindings, binding-\u003eid,\n 155:\t\t\t      NET_DEVMEM_BINDING_LIVE);\n 156:\t\n 157:\t\t/* Ensure no tx net_devmem_lookup_dmabuf() are in flight after the\n 158:\t\t * mark is cleared.\n 159:\t\t */\n 160:\t\tsynchronize_net();\n 161:\t\n 162:\t\tif (binding-\u003elist.next)\n 163:\t\t\tlist_del(\u0026binding-\u003elist);\n 164:\t\n 165:\t\txa_for_each(\u0026binding-\u003ebound_rxqs, xa_idx, rxq) {\n 166:\t\t\tconst struct pp_memory_provider_params mp_params = {\n 167:\t\t\t\t.mp_priv\t= binding,\n 168:\t\t\t\t.mp_ops\t\t= \u0026dmabuf_devmem_ops,\n 169:\t\t\t};\n 170:\t\n 171:\t\t\trxq_idx = get_netdev_rx_queue_index(rxq);\n 172:\t\n 173:\t\t\tnetif_mp_close_rxq(binding-\u003edev, rxq_idx, \u0026mp_params);\n 174:\t\t}\n 175:\t\n 176:\t\tpercpu_ref_kill(\u0026binding-\u003eref);\n 177:\t}\n 178:\t\n 179:\tstatic void\n 180:\tnet_devmem_dev_unregister_rx(struct net_devmem_dmabuf_binding *binding,\n 181:\t\t\t\t     unsigned long xa_idx, struct net_device *dev)\n 182:\t{\n 183:\t\tif (xa_get_mark(\u0026net_devmem_dmabuf_bindings, xa_idx,\n 184:\t\t\t\tNET_DEVMEM_BINDING_LIVE) ||\n 185:\t\t    READ_ONCE(binding-\u003edev) != dev)\n 186:\t\t\treturn;\n 187:\t\n 188:\t\tmutex_lock(\u0026binding-\u003elock);\n 189:\t\tWRITE_ONCE(binding-\u003edev, NULL);\n 190:\t\tif (!netif_is_queue_leasee(dev))\n 191:\t\t\tnet_devmem_dmabuf_binding_unmap(binding);\n 192:\t\tmutex_unlock(\u0026binding-\u003elock);\n 193:\t}\n 194:\t\n 195:\tstatic bool\n 196:\tnet_devmem_dev_unregister_tx(struct net_devmem_dmabuf_binding *binding,\n 197:\t\t\t\t     unsigned long xa_idx, struct net_device *dev)\n 198:\t{\n 199:\t\tif (READ_ONCE(binding-\u003edev) == dev) {\n 200:\t\t\txa_clear_mark(\u0026net_devmem_dmabuf_bindings, xa_idx,\n 201:\t\t\t\t      NET_DEVMEM_BINDING_LIVE);\n 202:\t\n 203:\t\t\tmutex_lock(\u0026binding-\u003elock);\n 204:\t\t\tWRITE_ONCE(binding-\u003edev, NULL);\n 205:\t\t\tWRITE_ONCE(binding-\u003evdev, NULL);\n 206:\t\t\tmutex_unlock(\u0026binding-\u003elock);\n 207:\t\t\treturn true;\n 208:\t\t}\n 209:\t\n 210:\t\tif (READ_ONCE(binding-\u003evdev) == dev) {\n 211:\t\t\tmutex_lock(\u0026binding-\u003elock);\n 212:\t\t\tWRITE_ONCE(binding-\u003evdev, NULL);\n 213:\t\t\tmutex_unlock(\u0026binding-\u003elock);\n 214:\t\t}\n 215:\t\n 216:\t\treturn false;\n 217:\t}\n 218:\t\n 219:\tstatic void net_devmem_unmap_detached_tx(void)\n 220:\t{\n 221:\t\tstruct net_devmem_dmabuf_binding *binding;\n 222:\t\tunsigned long xa_idx;\n 223:\t\n 224:\t\t/* Ensure no tx net_devmem_lookup_dmabuf() or\n 225:\t\t * validate_xmit_unreadable_skb() are in flight after detach.\n 226:\t\t */\n 227:\t\tsynchronize_net();\n 228:\t\n 229:\t\txa_for_each(\u0026net_devmem_dmabuf_bindings, xa_idx, binding) {\n"
}

17/2 2026/10/14 22:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 18468
							output: 35
							thoughts: 80
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach this task, walking through my thought process:

**Investigating DMA Buffer Binding in Network Device Memory**

Right, so the task at hand is to understand how these `net_devmem_bind_dmabuf` and `net_devmem_unbind_dmabuf` functions are being utilized. My first instinct, given the context of network devices and DMA, is to think Netlink. Specifically, the generic Netlink family for network devices seems highly relevant.  I immediately suspect that the `NETDEV_CMD_BIND_RX` and `NETDEV_CMD_BIND_TX` commands within that Netlink family are likely the key interaction points for this DMA buffer binding process. It's a very common pattern.

Okay, let’s confirm this. Let's fire up a quick `grep` for `net_devmem_bind_dmabuf` and see where it shows up in the codebase. That should give me a good starting point for mapping out the calling structure and interactions. I'll need to look at both the kernel side, and potentially the user space side, if the call is initiated from there.



18/2 2026/10/14 22:44 tool grepper
0m Args:
{
  "Expression": "net_devmem_bind_dmabuf",
  "PathPrefixes": [
    "net/core/"
  ]
}

Results:
{
  "Output": "net/core/devmem.c=240=void net_devmem_dev_unregister(struct net_device *dev)\n--\nnet/core/devmem.c-261-\nnet/core/devmem.c:262:int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,\nnet/core/devmem.c-263-\t\t\t\t    struct net_devmem_dmabuf_binding *binding,\n--\nnet/core/devmem.c=294=struct net_devmem_dmabuf_binding *\nnet/core/devmem.c:295:net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,\nnet/core/devmem.c-296-\t\t       struct device *dma_dev,\n--\nnet/core/devmem.h=95=struct net_devmem_dmabuf_binding *\nnet/core/devmem.h:96:net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,\nnet/core/devmem.h-97-\t\t       struct device *dma_dev,\n--\nnet/core/devmem.h=104=void net_devmem_dev_unregister(struct net_device *dev);\nnet/core/devmem.h:105:int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,\nnet/core/devmem.h-106-\t\t\t\t    struct net_devmem_dmabuf_binding *binding,\n--\nnet/core/devmem.h=179=static inline struct net_devmem_dmabuf_binding *\nnet/core/devmem.h:180:net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,\nnet/core/devmem.h-181-\t\t       struct device *dma_dev,\n--\nnet/core/devmem.h=205=static inline int\nnet/core/devmem.h:206:net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,\nnet/core/devmem.h-207-\t\t\t\tstruct net_devmem_dmabuf_binding *binding,\n--\nnet/core/netdev-genl.c=1013=int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/core/netdev-genl.c-1094-\nnet/core/netdev-genl.c:1095:\tbinding = net_devmem_bind_dmabuf(netdev, NULL, dma_dev, DMA_FROM_DEVICE,\nnet/core/netdev-genl.c-1096-\t\t\t\t\t dmabuf_fd, niov_shift, priv,\n--\nnet/core/netdev-genl.c-1103-\tfor_each_set_bit(rxq_idx, rxq_bitmap, netdev-\u003ereal_num_rx_queues) {\nnet/core/netdev-genl.c:1104:\t\terr = net_devmem_bind_dmabuf_to_queue(netdev, rxq_idx, binding,\nnet/core/netdev-genl.c-1105-\t\t\t\t\t\t      info-\u003eextack);\n--\nnet/core/netdev-genl.c=1177=int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)\n--\nnet/core/netdev-genl.c-1242-\nnet/core/netdev-genl.c:1243:\tbinding = net_devmem_bind_dmabuf(bind_dev,\nnet/core/netdev-genl.c-1244-\t\t\t\t\t bind_dev != netdev ? netdev : NULL,\n"
}

19/2 2026/10/14 22:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19846
							output: 29
							thoughts: 802
						

Thoughts:
**Reaching Critical Code: A Fuzzing Target Emerges**

Okay, so I'm looking at these handlers, `netdev_nl_bind_rx_doit` and `netdev_nl_bind_tx_doit`. They're generic netlink handlers. Pretty standard stuff, but what's interesting is they're accessible from userspace via netlink commands (`NETDEV_CMD_BIND_RX`, `NETDEV_CMD_BIND_TX`). Syzkaller's already using netlink sockets to test them, which immediately gets my attention. And then there's `netdevsim`, which can be instantiated through sysfs, netlink, rtnetlink, the mock bus, or even devlink.

Wait a second…can we actually *fuzz* `netdevsim` or devmem? This is key. Let's go back and review the Core Triage Philosophy and that crucial Positive/Negative Criteria. Reachability is always the primary gate. The philosophy states that fuzzing can only expose bugs that can execute in a standard virtualized environment like GCE or QEMU, and uses devices like USB gadgets, netdev, or tun/tap. The Core Subsystems involved are things like memory management, synchronization/locking, BPF, scheduler, core networking, VFS, or syscall handling. Also worth noting are Drivers accessible via virtual buses such as virtio, USB gadget, loopback, netlink, binder, sockets, etc.

Now, this patch modifies code in both of those categories! We have core networking with `net/core/devmem.c` and `net/core/netdev-genl.c`. But even more exciting, we're also touching the `drivers/net/netdevsim/` code. This is a software-simulated network device driver, specifically *designed* for testing and debugging, instantiated via sysfs, devlink, etc. – it's completely virtual and runs perfectly fine in QEMU/GCE! This patch also deals with devmem's dmabuf handling with functions like `net_devmem_dev_unregister()`, `net_devmem_unbind_dmabuf()`, `net_devmem_bind_dmabuf()`, `mp_dmabuf_devmem_uninstall()`, as well as locks like `net_devmem_lock`, `binding->lock`, dma unmap attachments, and unregistered net devices during devmem dmabuf bindings. And let's not forget the page pool in `netdevsim`, and the `PP_FLAG_ALLOW_UNREADABLE_NETMEM`, `netmem_tx = NETMEM_TX_DMA`, `page_pool_is_unreadable`. This is all *absolutely* reachable, executable code in both core networking and a virtual net driver!

Okay, *WorthFuzzing* is definitely `true` in my book.

Now, let's nail down those configurations. We need to be sure we can build a setup that enables this. First, we look at the relevant Kconfig files.

In `net/Kconfig`, we have `NET_DEVMEM`:

```
config NET_DEVMEM
	def_bool y
	select GENERIC_ALLOCATOR
	depends on DMA_SHARED_BUFFER
	depends on PAGE_POOL
```

Aha! `NET_DEVMEM` *depends* on both `DMA_SHARED_BUFFER` and `PAGE_POOL`. That's important. Then we check `NETDEVSIM` in `drivers/net/Kconfig`:

```
config NETDEVSIM
	tristate "Simulated networking device"
	depends on DEBUG_FS
	depends on INET
	depends on PSAMPLE || PSAMPLE=n
	depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n
	select NET_DEVLINK
	select PAGE_POOL
	select NET_SHAPER
```

`NETDEVSIM` *also* depends on `PAGE_POOL`, and further needs `NET_DEVLINK`. Excellent! Now, just to be thorough... Does `UDMABUF` play a part with `DMA_SHARED_BUFFER`, or user dmabuf creation? I should check `drivers/dma-buf/Kconfig` to be sure. But all in all, this looks incredibly promising. The stars seem to be aligning.



20/2 2026/10/14 22:44 tool grepper
0m Args:
{
  "Expression": "config DMA_SHARED_BUFFER",
  "PathPrefixes": [
    "drivers/"
  ]
}

Results:
{
  "Output": "drivers/base/Kconfig=213=source \"drivers/base/regmap/Kconfig\"\ndrivers/base/Kconfig-214-\ndrivers/base/Kconfig:215:config DMA_SHARED_BUFFER\ndrivers/base/Kconfig-216-\tbool\n"
}

21/2 2026/10/14 22:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21712
							output: 20
							thoughts: 13
						

Thoughts:
Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:

**Analyzing DMA_SHARED_BUFFER Usage**

Right, let's dive in. The first question I need to answer, immediately, is precisely *what* components, modules, or functions are accessing `DMA_SHARED_BUFFER`. I need a complete picture of its usage within the system. I'm not just interested in the definition, I need to know where it's being *selected*, where it's being *allocated* (if applicable, though I expect that's probably handled elsewhere), how it's being *initialized*, and most importantly, how and where it's being *used* in DMA operations. Is it a source buffer? A destination? Both?

I need to understand the data flow implications. I need to know the context of its selection; is it a compile-time option, a run-time configuration, or some sort of dynamic allocation based on system resources or other variables? Is there any logic involved in its selection? If so, what variables determine that logic?

Essentially, I'm setting out to perform a code archaeology dig. I'm going to look at the include files and then quickly move on to the code itself. Then I'll look for anything that relates to this specific buffer. I need to understand its behavior within the DMA framework. I'm looking for anything unusual or potentially problematic that might manifest due to this particular shared resource. Let's start digging.



22/2 2026/10/14 22:44 tool grepper
0m Args:
{
  "Expression": "select DMA_SHARED_BUFFER"
}

Results:
{
  "Output": "Documentation/driver-api/dma-buf.rst=65=Any exporters or users of the dma-buf buffer sharing framework must have a\nDocumentation/driver-api/dma-buf.rst:66:'select DMA_SHARED_BUFFER' in their respective Kconfigs.\nDocumentation/driver-api/dma-buf.rst-67-\n--\ndrivers/accel/habanalabs/Kconfig=6=config DRM_ACCEL_HABANALABS\n--\ndrivers/accel/habanalabs/Kconfig-12-\tselect HWMON\ndrivers/accel/habanalabs/Kconfig:13:\tselect DMA_SHARED_BUFFER\ndrivers/accel/habanalabs/Kconfig-14-\tselect CRC32\n--\ndrivers/dma-buf/Kconfig=4=config SYNC_FILE\n--\ndrivers/dma-buf/Kconfig-6-\tdefault n\ndrivers/dma-buf/Kconfig:7:\tselect DMA_SHARED_BUFFER\ndrivers/dma-buf/Kconfig-8-\thelp\n--\ndrivers/dma-buf/Kconfig=52=config DMABUF_KUNIT_TEST\n--\ndrivers/dma-buf/Kconfig-54-\tdepends on KUNIT\ndrivers/dma-buf/Kconfig:55:\tselect DMA_SHARED_BUFFER\ndrivers/dma-buf/Kconfig-56-\tdefault KUNIT_ALL_TESTS\n--\ndrivers/dma-buf/Kconfig=60=menuconfig DMABUF_HEAPS\ndrivers/dma-buf/Kconfig-61-\tbool \"DMA-BUF Userland Memory Heaps\"\ndrivers/dma-buf/Kconfig:62:\tselect DMA_SHARED_BUFFER\ndrivers/dma-buf/Kconfig-63-\thelp\n--\ndrivers/gpu/drm/Kconfig=8=menuconfig DRM\n--\ndrivers/gpu/drm/Kconfig-13-\tselect I2C\ndrivers/gpu/drm/Kconfig:14:\tselect DMA_SHARED_BUFFER\ndrivers/gpu/drm/Kconfig-15-\tselect SYNC_FILE\n--\ndrivers/gpu/host1x/Kconfig=6=config TEGRA_HOST1X\n--\ndrivers/gpu/host1x/Kconfig-8-\tdepends on ARCH_TEGRA || COMPILE_TEST\ndrivers/gpu/host1x/Kconfig:9:\tselect DMA_SHARED_BUFFER\ndrivers/gpu/host1x/Kconfig-10-\tselect TEGRA_HOST1X_CONTEXT_BUS\n--\ndrivers/iio/Kconfig=15=config IIO_BUFFER\ndrivers/iio/Kconfig-16-\tbool \"Enable buffer support within IIO\"\ndrivers/iio/Kconfig:17:\tselect DMA_SHARED_BUFFER\ndrivers/iio/Kconfig-18-\thelp\n--\ndrivers/infiniband/Kconfig=2=menuconfig INFINIBAND\n--\ndrivers/infiniband/Kconfig-7-\tdepends on !ALPHA\ndrivers/infiniband/Kconfig:8:\tselect DMA_SHARED_BUFFER\ndrivers/infiniband/Kconfig-9-\tselect IRQ_POLL\n--\ndrivers/infiniband/Kconfig=44=config INFINIBAND_USER_MEM\n--\ndrivers/infiniband/Kconfig-47-\tdepends on MMU\ndrivers/infiniband/Kconfig:48:\tselect DMA_SHARED_BUFFER\ndrivers/infiniband/Kconfig-49-\tdefault y\n--\ndrivers/iommu/iommufd/Kconfig=51=config IOMMUFD_TEST\n--\ndrivers/iommu/iommufd/Kconfig-56-\tdepends on IOMMU_PT_AMDV1=y || IOMMUFD=IOMMU_PT_AMDV1\ndrivers/iommu/iommufd/Kconfig:57:\tselect DMA_SHARED_BUFFER\ndrivers/iommu/iommufd/Kconfig-58-\tselect IOMMUFD_DRIVER\n--\ndrivers/media/common/videobuf2/Kconfig=3=config VIDEOBUF2_CORE\ndrivers/media/common/videobuf2/Kconfig:4:\tselect DMA_SHARED_BUFFER\ndrivers/media/common/videobuf2/Kconfig-5-\ttristate\n--\ndrivers/media/common/videobuf2/Kconfig=13=config VIDEOBUF2_DMA_CONTIG\n--\ndrivers/media/common/videobuf2/Kconfig-16-\tselect VIDEOBUF2_MEMOPS\ndrivers/media/common/videobuf2/Kconfig:17:\tselect DMA_SHARED_BUFFER\ndrivers/media/common/videobuf2/Kconfig-18-\ndrivers/media/common/videobuf2/Kconfig=19=config VIDEOBUF2_VMALLOC\n--\ndrivers/media/common/videobuf2/Kconfig-22-\tselect VIDEOBUF2_MEMOPS\ndrivers/media/common/videobuf2/Kconfig:23:\tselect DMA_SHARED_BUFFER\ndrivers/media/common/videobuf2/Kconfig-24-\n--\ndrivers/media/platform/nvidia/tegra-vde/Kconfig=1=config VIDEO_TEGRA_VDE\n--\ndrivers/media/platform/nvidia/tegra-vde/Kconfig-6-\tdepends on VIDEO_DEV\ndrivers/media/platform/nvidia/tegra-vde/Kconfig:7:\tselect DMA_SHARED_BUFFER\ndrivers/media/platform/nvidia/tegra-vde/Kconfig-8-\tselect IOMMU_IOVA\n--\ndrivers/misc/Kconfig=266=config QCOM_FASTRPC\n--\ndrivers/misc/Kconfig-269-\tdepends on RPMSG\ndrivers/misc/Kconfig:270:\tselect DMA_SHARED_BUFFER\ndrivers/misc/Kconfig-271-\tselect QCOM_SCM\n--\ndrivers/tee/Kconfig=3=menuconfig TEE\n--\ndrivers/tee/Kconfig-6-\tselect CRYPTO_LIB_SHA1\ndrivers/tee/Kconfig:7:\tselect DMA_SHARED_BUFFER\ndrivers/tee/Kconfig-8-\tselect GENERIC_ALLOCATOR\n--\ndrivers/usb/gadget/Kconfig=192=config USB_F_FS\ndrivers/usb/gadget/Kconfig:193:\tselect DMA_SHARED_BUFFER\ndrivers/usb/gadget/Kconfig-194-\ttristate\n--\ndrivers/xen/Kconfig=145=config XEN_GNTDEV_DMABUF\n--\ndrivers/xen/Kconfig-147-\tdepends on XEN_GNTDEV \u0026\u0026 XEN_GRANT_DMA_ALLOC\ndrivers/xen/Kconfig:148:\tselect DMA_SHARED_BUFFER\ndrivers/xen/Kconfig-149-\thelp\n--\nsamples/Kconfig=230=config SAMPLE_VFIO_MDEV_MBOCHS\n--\nsamples/Kconfig-233-\tselect VFIO_MDEV\nsamples/Kconfig:234:\tselect DMA_SHARED_BUFFER\nsamples/Kconfig-235-\thelp\n--\nsound/soc/fsl/Kconfig=6=config SND_SOC_FSL_ASRC\n--\nsound/soc/fsl/Kconfig-8-\tdepends on HAS_DMA\nsound/soc/fsl/Kconfig:9:\tselect DMA_SHARED_BUFFER\nsound/soc/fsl/Kconfig-10-\tselect REGMAP_MMIO\n"
}

23/2 2026/10/14 22:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23864
							output: 28
							thoughts: 134
						

Thoughts:
**Investigating DMA-BUF Configuration Dependencies**

Okay, let's break this down. Line 4 of `drivers/dma-buf/Kconfig` is key here: `SYNC_FILE` *selects* `DMA_SHARED_BUFFER`. That's important. I immediately want to understand the implications of this selection. I'm also noticing something interesting in the context of this patch, which is the addition of this configuration block in `tools/testing/selftests/net/config`:

```
+CONFIG_DEBUG_FS=y
+CONFIG_NET_DEVMEM=y
+CONFIG_SYNC_FILE=y
+CONFIG_UDMABUF=y
```

So, `SYNC_FILE` is enabled, and `UDMABUF` is also enabled. Given my knowledge of DMA-BUF and its associated concepts, `UDMABUF` also using dmabuf immediately clicks. I need to now verify this hypothesis. I'm going to jump straight to `drivers/dma-buf/Kconfig` and look into `UDMABUF`, let's see how `UDMABUF` is tied into this whole DMA-BUF ecosystem.



24/2 2026/10/14 22:44 tool grepper
0m Args:
{
  "Expression": "config UDMABUF",
  "PathPrefixes": [
    "drivers/"
  ]
}

Results:
{
  "Output": "drivers/dma-buf/Kconfig=20=config SW_SYNC\n--\ndrivers/dma-buf/Kconfig-32-\ndrivers/dma-buf/Kconfig:33:config UDMABUF\ndrivers/dma-buf/Kconfig-34-\tbool \"userspace dmabuf misc driver\"\n"
}

25/2 2026/10/14 22:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24371
							output: 36
							thoughts: 21
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into the DMA-BUF Kconfig**

Okay, time to dig into the `drivers/dma-buf/Kconfig` file. I'm specifically interested in line 33, hopefully that'll provide some clarity. I need to understand how certain DMA-BUF features are configured, and Kconfig is the usual place to start for kernel configuration. I expect it to describe the dependencies, defaults, and option relationships for those particular features. Hopefully it's well-commented. I'll be looking for any hints about the underlying logic or design choices. Let's see what we've got!



26/2 2026/10/14 22:44 tool read-file
0m Args:
{
  "File": "drivers/dma-buf/Kconfig",
  "FirstLine": 30,
  "LineCount": 20
}

Results:
{
  "Contents": "  30:\t\t  WARNING: improper use of this can result in deadlocking kernel\n  31:\t\t  drivers from userspace. Intended for test and debug only.\n  32:\t\n  33:\tconfig UDMABUF\n  34:\t\tbool \"userspace dmabuf misc driver\"\n  35:\t\tdefault n\n  36:\t\tdepends on DMA_SHARED_BUFFER\n  37:\t\tdepends on MEMFD_CREATE || COMPILE_TEST\n  38:\t\tdepends on MMU\n  39:\t\thelp\n  40:\t\t  A driver to let userspace turn memfd regions into dma-bufs.\n  41:\t\t  Qemu can use this to create host dmabufs for guest framebuffers.\n  42:\t\n  43:\tconfig DMABUF_DEBUG\n  44:\t\tbool \"DMA-BUF debug checks\"\n  45:\t\tdepends on DMA_SHARED_BUFFER\n  46:\t\tdefault y if DEBUG_KERNEL\n  47:\t\thelp\n  48:\t\t  This option enables additional checks for DMA-BUF importers and\n  49:\t\t  exporters. Specifically it validates that importers do not peek at the\n"
}

27/2 2026/10/14 22:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24861
							output: 46
							thoughts: 1142
						

Thoughts:
**Analyzing the Dependencies and Patchset**

Okay, let's break this down. First, I see that `CONFIG_NET_DEVMEM` relies on `DMA_SHARED_BUFFER` and `PAGE_POOL`. That's standard practice, makes sense. And `CONFIG_NETDEVSIM` needs `DEBUG_FS`, which is already in the dependency tree, along with `PAGE_POOL` and `NET_DEVLINK`. Good. Now, the key here is how we're getting dmabuf fds into userspace to leverage them with netlink via `bind_rx` / `bind_tx` and that's being enabled through `UDMABUF`, which allows userspace to create dmabufs from memfds.  `SYNC_FILE` further ties into this because it selects `DMA_SHARED_BUFFER`. I also note that `NET_DEVMEM` is, effectively, enabled if both `DMA_SHARED_BUFFER` and `PAGE_POOL` are enabled – that's a key observation. And finally, `NETDEVSIM` compiles the `drivers/net/netdevsim/` directory.

Now, let's dive into the patchset and pinpoint the `FocusSymbols`.

I'll go function by function:

1.  In `drivers/net/netdevsim/bus.c`, `nsim_bus_dev_new` is creating the bus device and calling `dma_coerce_mask_and_coherent`. Makes sense; that's the setup.

2.  `drivers/net/netdevsim/netdev.c` is more interesting:
    *   `nsim_create_page_pool`: A static helper creating the page pool with flags `PP_FLAG_ALLOW_UNREADABLE_NETMEM` and `PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV`. This is a crucial setup step.
    *   `nsim_init_napi`: Another static helper, likely related to NAPI initialization.
    *   `nsim_queue_mem_alloc`: This looks like the queue management op, assigned to `ndo_queue_mem_alloc`. This is where the page pool is accessed.
    *   `nsim_pp_hold_write`: This is related to sysfs/debugfs, for testing the page pool hold mechanism.
    *   `nsim_init_netdevsim`: Sets `netmem_tx = NETMEM_TX_DMA`, which is important for the DMA path.

3.  `drivers/net/netdevsim/psp.c`:
    *   `nsim_do_psp`: Checks `!skb_frags_readable(skb)`. This is likely a key check for the DMA path too.

4.  `net/core/devmem.c`: This is a core area, and it's where the focus needs to be:
    *   `net_devmem_dmabuf_binding_unmap`: static helper.
    *   `__net_devmem_dmabuf_binding_free`: workqueue callback for freeing dmabuf binding.
    *   `net_devmem_unbind_dmabuf`: An exported/global function called from netlink or socket unbinding. *That's important*.
    *   `net_devmem_dev_unregister_rx`, `net_devmem_dev_unregister_tx`, `net_devmem_unmap_detached_tx`: Static helpers.
    *   `net_devmem_dev_unregister`: An *exported/declared* function (in `devmem.h`) and called on `NETDEV_UNREGISTER`.  This is a critical unregister function.
    *   `net_devmem_bind_dmabuf`: A function called from `netdev_nl_bind_rx_doit` and `netdev_nl_bind_tx_doit`. *Very significant*: this is the key function for the netlink binding.
    *   `net_devmem_lookup_dmabuf`: Called during TX or queue binding. Another important lookup function.
    *   `mp_dmabuf_devmem_uninstall`: Either static or non-static op in memory provider.

5.  `net/core/netdev-genl.c`:
    *   `netdev_genl_netdevice_event`: This is the netdevice notifier callback. Receives `NETDEV_UNREGISTER` and calls `net_devmem_dev_unregister`. This is how unregistration is triggered.
    *   `netdev_nl_bind_rx_doit`, `netdev_nl_bind_tx


28/2 2026/10/14 22:44 tool grepper
0m Args:
{
  "Expression": "nsim_queue_mem_alloc|nsim_bus_dev_new",
  "PathPrefixes": [
    "drivers/net/netdevsim/"
  ]
}

Results:
{
  "Output": "drivers/net/netdevsim/bus.c=65=new_port_store(struct device *dev, struct device_attribute *attr,\n--\ndrivers/net/netdevsim/bus.c-100-\ndrivers/net/netdevsim/bus.c:101:static struct device_attribute nsim_bus_dev_new_port_attr = __ATTR_WO(new_port);\ndrivers/net/netdevsim/bus.c-102-\n--\ndrivers/net/netdevsim/bus.c=124=static struct attribute *nsim_bus_dev_attrs[] = {\ndrivers/net/netdevsim/bus.c-125-\t\u0026nsim_bus_dev_numvfs_attr.attr,\ndrivers/net/netdevsim/bus.c:126:\t\u0026nsim_bus_dev_new_port_attr.attr,\ndrivers/net/netdevsim/bus.c-127-\t\u0026nsim_bus_dev_del_port_attr.attr,\n--\ndrivers/net/netdevsim/bus.c=155=static struct nsim_bus_dev *\ndrivers/net/netdevsim/bus.c:156:nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queues);\ndrivers/net/netdevsim/bus.c-157-\n--\ndrivers/net/netdevsim/bus.c=159=new_device_store(const struct bus_type *bus, const char *buf, size_t count)\n--\ndrivers/net/netdevsim/bus.c-190-\ndrivers/net/netdevsim/bus.c:191:\tnsim_bus_dev = nsim_bus_dev_new(id, port_count, num_queues);\ndrivers/net/netdevsim/bus.c-192-\tif (IS_ERR(nsim_bus_dev)) {\n--\ndrivers/net/netdevsim/bus.c=446=static struct nsim_bus_dev *\ndrivers/net/netdevsim/bus.c:447:nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queues)\ndrivers/net/netdevsim/bus.c-448-{\n--\ndrivers/net/netdevsim/netdev.c=758=static int\ndrivers/net/netdevsim/netdev.c:759:nsim_queue_mem_alloc(struct net_device *dev,\ndrivers/net/netdevsim/netdev.c-760-\t\t     struct netdev_queue_config *qcfg,\n--\ndrivers/net/netdevsim/netdev.c=865=static const struct netdev_queue_mgmt_ops nsim_queue_mgmt_ops = {\ndrivers/net/netdevsim/netdev.c-866-\t.ndo_queue_mem_size\t= sizeof(struct nsim_queue_mem),\ndrivers/net/netdevsim/netdev.c:867:\t.ndo_queue_mem_alloc\t= nsim_queue_mem_alloc,\ndrivers/net/netdevsim/netdev.c-868-\t.ndo_queue_mem_free\t= nsim_queue_mem_free,\n"
}

29/2 2026/10/14 22:44 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27894
							output: 32
							thoughts: 260
						

Thoughts:
**My Line of Inquiry: Device Memory Binding**

Okay, so I'm looking at this `nsim_bus_dev_new` function. It's static, and it seems to be called from `new_device_store` which is tied to that sysfs entry `/sys/bus/netdevsim/new_device`. And then there's `nsim_queue_mem_alloc`, also static, assigned as `.ndo_queue_mem_alloc`. Now, let me think... these static functions, if they aren't inlined, they *should* appear as symbols in `kallsyms`, right? Unless they've been inlined, of course. But those non-static entry points, those are *definitely* going to be symbols.

Right, so where's this going? It seems like I need to look at the functions themselves and their callers. Let me quickly check `net_devmem_bind_dmabuf`, `net_devmem_unbind_dmabuf`, `net_devmem_dev_unregister`, `net_devmem_lookup_dmabuf`, and `__net_devmem_dmabuf_binding_free`. Gotta make sure I don't miss anything obvious.

Aha! And then it hits me! Those `netdev_nl_bind_rx_doit` and `netdev_nl_bind_tx_doit` functions in `net/core/netdev-genl.c`... they're the netlink entry points. They're what's triggering the device memory binding logic!

Okay, *now* I need to focus on `netdev_nl_bind_rx_doit` and `netdev_nl_bind_tx_doit`, because it seems like those are what I'm truly after here.



30/2 2026/10/14 22:45 tool grepper
0m Args:
{
  "Expression": "netdev_nl_bind_",
  "PathPrefixes": [
    "net/core/"
  ]
}

Results:
{
  "Output": "net/core/netdev-genl-gen.c=145=static const struct genl_split_ops netdev_nl_ops[] = {\n--\nnet/core/netdev-genl-gen.c-226-\t\t.cmd\t\t= NETDEV_CMD_BIND_RX,\nnet/core/netdev-genl-gen.c:227:\t\t.doit\t\t= netdev_nl_bind_rx_doit,\nnet/core/netdev-genl-gen.c-228-\t\t.policy\t\t= netdev_bind_rx_nl_policy,\n--\nnet/core/netdev-genl-gen.c-240-\t\t.cmd\t\t= NETDEV_CMD_BIND_TX,\nnet/core/netdev-genl-gen.c:241:\t\t.doit\t\t= netdev_nl_bind_tx_doit,\nnet/core/netdev-genl-gen.c-242-\t\t.policy\t\t= netdev_bind_tx_nl_policy,\n--\nnet/core/netdev-genl-gen.h=36=int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,\nnet/core/netdev-genl-gen.h-37-\t\t\t\tstruct netlink_callback *cb);\nnet/core/netdev-genl-gen.h:38:int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info);\nnet/core/netdev-genl-gen.h-39-int netdev_nl_napi_set_doit(struct sk_buff *skb, struct genl_info *info);\nnet/core/netdev-genl-gen.h:40:int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info);\nnet/core/netdev-genl-gen.h-41-int netdev_nl_queue_create_doit(struct sk_buff *skb, struct genl_info *info);\n--\nnet/core/netdev-genl.c=989=netdev_nl_get_dma_dev(struct net_device *netdev, unsigned long *rxq_bitmap,\n--\nnet/core/netdev-genl.c-1012-\nnet/core/netdev-genl.c:1013:int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)\nnet/core/netdev-genl.c-1014-{\n--\nnet/core/netdev-genl.c=1145=netdev_find_netmem_tx_dev(struct net_device *dev)\n--\nnet/core/netdev-genl.c-1176- */\nnet/core/netdev-genl.c:1177:int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)\nnet/core/netdev-genl.c-1178-{\n"
}

31/2 2026/10/14 22:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29360
							output: 40
							thoughts: 78
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Diving into Netdev Unregistration**

Okay, so I'm digging into how network devices are unregistered. My primary focus right now is figuring out the exact sequence of events that takes place when a device goes away. Specifically, I'm starting with the `netdev_genl_netdevice_event` function. It seems this is the central handler for network device events, and I expect it's the right place to start for unregistration. I see that it's handling the `NETDEV_UNREGISTER` event. Excellent. That's exactly what I'm looking for.

Now, let's trace the execution further. From what I see, `netdev_genl_netdevice_event` calls `net_devmem_dev_unregister(netdev)`. This looks promising. It's likely where the core memory management and device cleanup happens, given the `devmem` in the name.

To get a clearer picture of *that* function, I'll switch over to `net/core/netdev-genl.c` and specifically look at lines 1485-1498. I need to understand what `net_devmem_dev_unregister` actually *does*. Is it freeing memory, calling other cleanup routines, or possibly notifying other subsystems? Gotta see what's happening in there. Okay, let's get to it.



32/2 2026/10/14 22:45 tool read-file
0m Args:
{
  "File": "net/core/netdev-genl.c",
  "FirstLine": 1480,
  "LineCount": 25
}

Results:
{
  "Contents": "1480:\t{\n1481:\t\tstruct net_device *netdev = netdev_notifier_info_to_dev(ptr);\n1482:\t\n1483:\t\tswitch (event) {\n1484:\t\tcase NETDEV_REGISTER:\n1485:\t\t\tnetdev_lock_ops_to_full(netdev);\n1486:\t\t\tnetdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_ADD_NTF);\n1487:\t\t\tnetdev_unlock_full_to_ops(netdev);\n1488:\t\t\tbreak;\n1489:\t\tcase NETDEV_UNREGISTER:\n1490:\t\t\tnetdev_lock(netdev);\n1491:\t\t\tnet_devmem_dev_unregister(netdev);\n1492:\t\t\tnetdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_DEL_NTF);\n1493:\t\t\tnetdev_unlock(netdev);\n1494:\t\t\tbreak;\n1495:\t\tcase NETDEV_XDP_FEAT_CHANGE:\n1496:\t\t\tnetdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_CHANGE_NTF);\n1497:\t\t\tbreak;\n1498:\t\t}\n1499:\t\n1500:\t\treturn NOTIFY_OK;\n1501:\t}\n1502:\t\n1503:\tstatic struct notifier_block netdev_genl_nb = {\n1504:\t\t.notifier_call\t= netdev_genl_netdevice_event,\n"
}

33/2 2026/10/14 22:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30208
							output: 44
							thoughts: 707
						

Thoughts:
**Analyzing the DMA-Buf Attachment Lifecycle During Netdev Unregistration**

Okay, so I'm looking at how the kernel handles DMA-buf attachments during the `NETDEV_UNREGISTER` event. The flow is pretty clear: `netdev_genl_netdevice_event` triggers `net_devmem_dev_unregister(netdev)`. Diving into `net_devmem_dev_unregister`, I see it iterates through `net_devmem_dmabuf_bindings`. Crucially, it distinguishes between `DMA_FROM_DEVICE` and the other direction, likely `DMA_TO_DEVICE`. It calls `net_devmem_dev_unregister_rx` or `net_devmem_dev_unregister_tx` accordingly.

Now, the critical part is how the unmapping occurs. The `net_devmem_dmabuf_binding_unmap` function is key here. I spot `lockdep_assert_held(&binding->lock)`, indicating a lock is held, which is a good sign for preventing race conditions. This function unmaps the attachment using `dma_buf_unmap_attachment_unlocked` and detaches the DMA-buf.

I'm starting to see the implications here. Previously, the attachment unmapping was done asynchronously via a workqueue in `__net_devmem_dmabuf_binding_free` *after* all references dropped. The problem is if the network device unregistered *before* the workqueue fired, `binding->dev` might be freed before the binding, or there could be a use-after-free situation during the DMA unmap. It looks like the fix is to synchronize the detachment during unregistration, which makes sense. The commit message highlights this and mentions verifying both RX and TX paths to avoid UAF issues.

I'm also seeing that `netdevsim` has added support for devmem dmabuf. The introduction of `dma_coerce_mask_and_coherent` and flags like `PP_FLAG_ALLOW_UNREADABLE_NETMEM` catches my attention. The `page_pool_is_unreadable` check in `nsim_pp_hold_write` and the frags readable check in `nsim_do_psp` are interesting. I'll need to check the exact implementations of those functions to see how this integrates with the rest of the DMA-buf changes. Gotta see if those checks are playing nicely in the new detachment scheme.



34/2 2026/10/14 22:45 tool grepper
0m Args:
{
  "Expression": "nsim_pp_hold_write|nsim_do_psp",
  "PathPrefixes": [
    "drivers/net/netdevsim/"
  ]
}

Results:
{
  "Output": "drivers/net/netdevsim/netdev.c=123=static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)\n--\ndrivers/net/netdevsim/netdev.c-149-\ndrivers/net/netdevsim/netdev.c:150:\tdr = nsim_do_psp(skb, ns, peer_ns, \u0026psp_ext);\ndrivers/net/netdevsim/netdev.c-151-\tif (dr)\n--\ndrivers/net/netdevsim/netdev.c=929=static ssize_t\ndrivers/net/netdevsim/netdev.c:930:nsim_pp_hold_write(struct file *file, const char __user *data,\ndrivers/net/netdevsim/netdev.c-931-\t\t   size_t count, loff_t *ppos)\n--\ndrivers/net/netdevsim/netdev.c=967=static const struct file_operations nsim_pp_hold_fops = {\n--\ndrivers/net/netdevsim/netdev.c-969-\t.read = nsim_pp_hold_read,\ndrivers/net/netdevsim/netdev.c:970:\t.write = nsim_pp_hold_write,\ndrivers/net/netdevsim/netdev.c-971-\t.llseek = generic_file_llseek,\n--\ndrivers/net/netdevsim/netdevsim.h=454=enum skb_drop_reason\ndrivers/net/netdevsim/netdevsim.h:455:nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,\ndrivers/net/netdevsim/netdevsim.h-456-\t    struct netdevsim *peer_ns, struct skb_ext **psp_ext);\n--\ndrivers/net/netdevsim/netdevsim.h=460=static inline enum skb_drop_reason\ndrivers/net/netdevsim/netdevsim.h:461:nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,\ndrivers/net/netdevsim/netdevsim.h-462-\t    struct netdevsim *peer_ns, struct skb_ext **psp_ext)\n--\ndrivers/net/netdevsim/psp.c=17=enum skb_drop_reason\ndrivers/net/netdevsim/psp.c:18:nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,\ndrivers/net/netdevsim/psp.c-19-\t    struct netdevsim *peer_ns, struct skb_ext **psp_ext)\n"
}

35/2 2026/10/14 22:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32173
							output: 27
							thoughts: 414
						

Thoughts:
**Analyzing the Netdevsim PSP Crypto Offload**

Okay, let's dive into this `nsim_do_psp` function. Seems like it handles Platform Security Processor crypto offloading for `netdevsim`. Interesting! The function signature itself, with `sk_buff`, `netdevsim` pointers, and an `skb_ext` indicates we're dealing with packet processing and potentially memory management.

Right, the key check in `drivers/net/netdevsim/psp.c` is: `if (!skb_frags_readable(skb))`. If the SKB fragments aren't readable, we drop the packet with `SKB_DROP_REASON_PSP_OUTPUT`. This warrants further investigation. I need to understand what constitutes an unreadable fragment here. This will likely involve debugging or tracing the control flow that calls this function.

Now, let's pivot to the configuration aspects. `NET_DEVMEM` is relevant, I think. Wait, is it configurable by the user? Let's check the Kconfig file for `NET_DEVMEM`. Ah, it's `def_bool y`, meaning it's enabled by default, but it *depends* on `DMA_SHARED_BUFFER` and `PAGE_POOL`. That's the critical link.

So, how is `DMA_SHARED_BUFFER` enabled? Standard defconfigs use either `DRM`, `UDMABUF`, or `SYNC_FILE`. `UDMABUF` is excellent because userspace can create dmabufs via `/dev/udmabuf`, which likely implies the use of DMA buffers.

What about `PAGE_POOL`? That’s selected by `NETDEVSIM`, which makes sense, or directly via the `PAGE_POOL` Kconfig option. I need to refresh my memory on what `PAGE_POOL` provides. Let me consult the `net/core/Kconfig` file and re-examine the `PAGE_POOL` definition. That will give me a better understanding of how the `netdevsim` PSP crypto offload and the `skb_frags_readable` check interact with these memory management configurations.



36/2 2026/10/14 22:45 tool grepper
0m Args:
{
  "Expression": "config PAGE_POOL",
  "PathPrefixes": [
    "net/"
  ]
}

Results:
{
  "Output": "net/Kconfig=487=config NET_DEVLINK\n--\nnet/Kconfig-490-\nnet/Kconfig:491:config PAGE_POOL\nnet/Kconfig-492-\tbool\nnet/Kconfig-493-\nnet/Kconfig:494:config PAGE_POOL_STATS\nnet/Kconfig-495-\tdefault n\n"
}

37/2 2026/10/14 22:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33182
							output: 35
							thoughts: 334
						

Thoughts:
**Analyzing Kernel Configuration Dependencies**

Okay, here's the deal. I'm looking at `PAGE_POOL`, and it's a boolean option with no explicit prompt. That means it's likely being auto-selected by something, and `NETDEVSIM` caught my attention as a potential culprit. Let's see... I'll dive into `drivers/net/Kconfig` to check `NETDEVSIM`. Right, it depends on `DEBUG_FS` and `INET`, and it *selects* `NET_DEVLINK`, `PAGE_POOL`, and `NET_SHAPER`. So `NETDEVSIM` does indeed pull in `PAGE_POOL`.

Now, how does `NET_DEVMEM` fit into this? Ah, right... it requires `PAGE_POOL` (which `NETDEVSIM` handles) and `DMA_SHARED_BUFFER`. And it looks like either `UDMABUF` or `SYNC_FILE` is related to `DMA_SHARED_BUFFER`. I have to confirm whether `UDMABUF` *selects* it or just *depends* on it.

Alright, let's see. Line 36 of `drivers/dma-buf/Kconfig` confirms it: `UDMABUF` *depends* on `DMA_SHARED_BUFFER`. So, *who* is selecting `DMA_SHARED_BUFFER`? Let's check. Aha, `SYNC_FILE`, `DMABUF_HEAPS`, and `DRM` all *select* it. Time to double-check `drivers/dma-buf/Kconfig` for `SYNC_FILE` and `DMABUF_HEAPS` for more details.



38/2 2026/10/14 22:45 tool read-file
0m Args:
{
  "File": "drivers/dma-buf/Kconfig",
  "FirstLine": 1,
  "LineCount": 25
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tmenu \"DMABUF options\"\n   3:\t\n   4:\tconfig SYNC_FILE\n   5:\t\tbool \"Explicit Synchronization Framework\"\n   6:\t\tdefault n\n   7:\t\tselect DMA_SHARED_BUFFER\n   8:\t\thelp\n   9:\t\t  The Sync File Framework adds explicit synchronization via\n  10:\t\t  userspace. It enables send/receive 'struct dma_fence' objects to/from\n  11:\t\t  userspace via Sync File fds for synchronization between drivers via\n  12:\t\t  userspace components. It has been ported from Android.\n  13:\t\n  14:\t\t  The first and main user for this is graphics in which a fence is\n  15:\t\t  associated with a buffer. When a job is submitted to the GPU a fence\n  16:\t\t  is attached to the buffer and is transferred via userspace, using Sync\n  17:\t\t  Files fds, to the DRM driver for example. More details at\n  18:\t\t  Documentation/driver-api/sync_file.rst.\n  19:\t\n  20:\tconfig SW_SYNC\n  21:\t\tbool \"Sync File Validation Framework\"\n  22:\t\tdefault n\n  23:\t\tdepends on SYNC_FILE\n  24:\t\tdepends on DEBUG_FS\n  25:\t\thelp\n"
}

39/2 2026/10/14 22:45 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34266
							output: 305
							thoughts: 2678
						

Thoughts:
**Analysis of the Network Device Memory and Netdevsim Patch for Fuzzing Focus**

Alright, let's break this down. First, the patch triggers some dependencies: `SYNC_FILE` relies on `DMA_SHARED_BUFFER`, which in turn enables `UDMABUF`. Then, `NETDEVSIM` needs `DEBUG_FS` and `INET`. Looking at the patch, it seems the configurations added are `CONFIG_DEBUG_FS=y`, `CONFIG_NET_DEVMEM=y`, `CONFIG_SYNC_FILE=y`, and `CONFIG_UDMABUF=y`. We also know that `CONFIG_NETDEVSIM=m` was already present. So, the necessary configurations are `NETDEVMEM`, `NETDEVSIM`, `SYNC_FILE`, `UDMABUF`, and `DEBUG_FS`.

Now, we need to identify the right focus symbols, keeping in mind the guidelines. We need to avoid ubiquitous, frequently called functions and instead target specific feature logic and entry points. Looking at the changes, several functions in `net/core/devmem.c` are either added or modified: `net_devmem_dev_unregister`, `net_devmem_dmabuf_binding_unmap`, `net_devmem_unbind_dmabuf`, `net_devmem_bind_dmabuf`, `net_devmem_lookup_dmabuf`, and `__net_devmem_dmabuf_binding_free`. Also, the patch modifies `netdev_genl_netdevice_event` and adds `netdev_nl_bind_rx_doit` and `netdev_nl_bind_tx_doit` in `net/core/netdev-genl.c`. Finally, we have `nsim_pp_hold_write`, `nsim_queue_mem_alloc`, and `nsim_do_psp` in `drivers/net/netdevsim/`.

We need to double-check that these symbols are not overly generic. Examining the code, each appears to be specific to either devmem or netdevsim functionalities, which is exactly what we want. We must make sure the symbol names are exactly right. I went through the code and listed each one, checking spelling.

Looking more closely at `net/core/devmem.c`, other added functions include `net_devmem_dev_unregister_rx`, `net_devmem_dev_unregister_tx`, and `net_devmem_unmap_detached_tx`. I did not see any changes to `net_devmem_bind_dmabuf_to_queue`.

So the key configurations are the following:
`NET_DEVMEM`: the core devmem support
`NETDEVSIM`: the netdevsim driver
`UDMABUF`: the userspace dma-buf driver for devmem testing
`SYNC_FILE`: enables DMA_SHARED_BUFFER (required by NET_DEVMEM and UDMABUF)
`DEBUG_FS`: required by NETDEVSIM

This patch introduces crucial device unregistration handling for network device memory bindings to prevent use-after-free and dangling dma-buf attachments. The patch series also adds netdevsim support, making it well worth fuzzing. I'm satisfied. It introduces functions that can be reached and tested in QEMU environments.



40/2 2026/10/14 22:45 tool set-results
0m Args:
{
  "EnableConfigs": [
    "NET_DEVMEM",
    "NETDEVSIM",
    "UDMABUF",
    "SYNC_FILE",
    "DEBUG_FS"
  ],
  "FocusSymbols": [
    "net_devmem_dev_unregister",
    "net_devmem_unbind_dmabuf",
    "net_devmem_bind_dmabuf",
    "net_devmem_lookup_dmabuf",
    "__net_devmem_dmabuf_binding_free",
    "netdev_nl_bind_rx_doit",
    "netdev_nl_bind_tx_doit",
    "nsim_pp_hold_write",
    "nsim_queue_mem_alloc",
    "nsim_do_psp"
  ],
  "Reasoning": "The patch series modifies the core networking devmem dmabuf subsystem (net/core/devmem.c) and netdevsim virtual driver to properly handle dmabuf unmapping and detaching upon network device unregistration, preventing use-after-free conditions. It alters locking, adds live binding tracking via xarray marks, updates devmem binding lookup and unbinding logic, and enables netdevsim support for unreadable netmem in page pools. This modifies reachable core networking and virtual device paths exercisable via generic Netlink and netdevice lifecycle operations in standard virtual environments.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "NET_DEVMEM",
    "NETDEVSIM",
    "UDMABUF",
    "SYNC_FILE",
    "DEBUG_FS"
  ],
  "FocusSymbols": [
    "net_devmem_dev_unregister",
    "net_devmem_unbind_dmabuf",
    "net_devmem_bind_dmabuf",
    "net_devmem_lookup_dmabuf",
    "__net_devmem_dmabuf_binding_free",
    "netdev_nl_bind_rx_doit",
    "netdev_nl_bind_tx_doit",
    "nsim_pp_hold_write",
    "nsim_queue_mem_alloc",
    "nsim_do_psp"
  ],
  "Reasoning": "The patch series modifies the core networking devmem dmabuf subsystem (net/core/devmem.c) and netdevsim virtual driver to properly handle dmabuf unmapping and detaching upon network device unregistration, preventing use-after-free conditions. It alters locking, adds live binding tracking via xarray marks, updates devmem binding lookup and unbinding logic, and enables netdevsim support for unreadable netmem in page pools. This modifies reachable core networking and virtual device paths exercisable via generic Netlink and netdevice lifecycle operations in standard virtual environments.",
  "WorthFuzzing": true
}

41/1 2026/10/14 22:45 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

42/2 2026/10/14 22:45 agent kmsan-evaluator
0m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series implements lifecycle and detachment handling for devmem (dma-buf) bindings when net devices unregister (preventing use-after-free and dangling DMA buffer attachment references), along with support for netmem in netdevsim and associated selftests.\n\nKASAN vs KMSAN Applicability:\n- Primary risks: The potential failure modes introduced or modified by these changes involve resource lifetime management, concurrent access races, use-after-free on unregistered net devices / detached dmabuf structures, NULL pointer dereferences, or locking/deadlock issues. These memory safety bugs and synchronization issues are directly detected by KASAN and LOCKDEP.\n- Uninitialized memory / info-leaks: The changes do not introduce or alter any copying of kernel structures to user space, nor do they expose uninitialized padding or uninitialized memory in socket, netlink, or ioctl responses. All touched structures (such as `page_pool_params`) use designated initializers (zeroing unspecified fields), and loop indices are initialized properly.\n\nBecause no uninitialized memory risks or kernel-to-user info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 5c1e73fdbe1bc2f288495d4674c46085acfd2ee8
Author: syz-cluster <triage@syzkaller.com>
Date:   Wed Oct 14 22:43:30 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index 5c55c308487b4..f87f5e037b6fb 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -462,6 +462,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queu
 	nsim_bus_dev->port_count = port_count;
 	nsim_bus_dev->num_queues = num_queues;
 	nsim_bus_dev->initial_net = current->nsproxy->net_ns;
+	dma_coerce_mask_and_coherent(&nsim_bus_dev->dev, DMA_BIT_MASK(64));
 	/* Disallow using nsim_bus_dev */
 	smp_store_release(&nsim_bus_dev->init, false);
 
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index b4a99f3ceac60..357ea9e5623b3 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -414,19 +414,27 @@ static int nsim_poll(struct napi_struct *napi, int budget)
 	return done;
 }
 
-static int nsim_create_page_pool(struct page_pool **p, struct napi_struct *napi)
+static int nsim_create_page_pool(struct net_device *dev, struct page_pool **p,
+				 struct napi_struct *napi, int idx)
 {
+	struct netdevsim *ns = netdev_priv(dev);
 	struct page_pool_params params = {
 		.order = 0,
 		.pool_size = NSIM_RING_SIZE,
+		.flags = PP_FLAG_ALLOW_UNREADABLE_NETMEM,
+		.max_len = PAGE_SIZE,
 		.nid = NUMA_NO_NODE,
-		.dev = &napi->dev->dev,
+		.dev = &ns->nsim_bus_dev->dev,
 		.napi = napi,
 		.dma_dir = DMA_BIDIRECTIONAL,
-		.netdev = napi->dev,
+		.netdev = dev,
+		.queue_idx = idx,
 	};
 	struct page_pool *pool;
 
+	if (IS_ENABLED(CONFIG_HAS_DMA))
+		params.flags |= PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
+
 	pool = page_pool_create(&params);
 	if (IS_ERR(pool))
 		return PTR_ERR(pool);
@@ -450,7 +458,7 @@ static int nsim_init_napi(struct netdevsim *ns)
 	for (i = 0; i < dev->num_rx_queues; i++) {
 		rq = ns->rq[i];
 
-		err = nsim_create_page_pool(&rq->page_pool, &rq->napi);
+		err = nsim_create_page_pool(dev, &rq->page_pool, &rq->napi, i);
 		if (err)
 			goto err_pp_destroy;
 	}
@@ -762,14 +770,16 @@ nsim_queue_mem_alloc(struct net_device *dev,
 	if (ns->rq_reset_mode == 1) {
 		if (!netif_running(ns->netdev))
 			return -ENETDOWN;
-		return nsim_create_page_pool(&qmem->pp, &ns->rq[idx]->napi);
+		return nsim_create_page_pool(dev, &qmem->pp,
+					     &ns->rq[idx]->napi, idx);
 	}
 
 	qmem->rq = nsim_queue_alloc();
 	if (!qmem->rq)
 		return -ENOMEM;
 
-	err = nsim_create_page_pool(&qmem->rq->page_pool, &qmem->rq->napi);
+	err = nsim_create_page_pool(dev, &qmem->rq->page_pool, &qmem->rq->napi,
+				    idx);
 	if (err)
 		goto err_free;
 
@@ -929,12 +939,15 @@ nsim_pp_hold_write(struct file *file, const char __user *data,
 		return ret;
 
 	rtnl_lock();
+	netdev_lock(ns->netdev);
 	ret = count;
 	if (val == !!ns->page)
 		goto exit;
 
 	if (!netif_running(ns->netdev) && val) {
 		ret = -ENETDOWN;
+	} else if (val && page_pool_is_unreadable(ns->rq[0]->page_pool)) {
+		ret = -EOPNOTSUPP;
 	} else if (val) {
 		ns->page = page_pool_dev_alloc_pages(ns->rq[0]->page_pool);
 		if (!ns->page)
@@ -946,6 +959,7 @@ nsim_pp_hold_write(struct file *file, const char __user *data,
 	}
 
 exit:
+	netdev_unlock(ns->netdev);
 	rtnl_unlock();
 	return ret;
 }
@@ -1051,6 +1065,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
 	ns->netdev->netdev_ops = &nsim_netdev_ops;
 	ns->netdev->stat_ops = &nsim_stat_ops;
 	ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops;
+	ns->netdev->netmem_tx = NETMEM_TX_DMA;
 	netdev_lockdep_set_classes(ns->netdev);
 
 	err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev);
diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c
index 6b3532b5e360d..908cc0d391dc6 100644
--- a/drivers/net/netdevsim/psp.c
+++ b/drivers/net/netdevsim/psp.c
@@ -86,6 +86,11 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
 		__wsum csum;
 		int udplen;
 
+		if (!skb_frags_readable(skb)) {
+			rc = SKB_DROP_REASON_PSP_OUTPUT;
+			goto out_unlock;
+		}
+
 		/* Do not decapsulate. Receive the skb with the udp and psp
 		 * headers still there as if this is a normal udp packet.
 		 * psp_dev_encapsulate() sets udp checksum to 0, so we need to
diff --git a/net/core/devmem.c b/net/core/devmem.c
index f4d60654ce7fd..dd07203076808 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -20,6 +20,7 @@
 #include <net/tcp.h>
 #include <trace/events/page_pool.h>
 
+#include "dev.h"
 #include "devmem.h"
 #include "mp_dmabuf_devmem.h"
 #include "page_pool_priv.h"
@@ -27,6 +28,8 @@
 /* Device memory support */
 
 static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);
+#define NET_DEVMEM_BINDING_LIVE XA_MARK_1
+static DEFINE_MUTEX(net_devmem_lock);
 
 static const struct memory_provider_ops dmabuf_devmem_ops;
 
@@ -58,6 +61,21 @@ static void net_devmem_dmabuf_binding_release(struct percpu_ref *ref)
 	schedule_work(&binding->unbind_w);
 }
 
+static void
+net_devmem_dmabuf_binding_unmap(struct net_devmem_dmabuf_binding *binding)
+{
+	lockdep_assert_held(&binding->lock);
+
+	if (!binding->sgt)
+		return;
+
+	dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt,
+					  binding->direction);
+	dma_buf_detach(binding->dmabuf, binding->attachment);
+	binding->sgt = NULL;
+	binding->attachment = NULL;
+}
+
 void __net_devmem_dmabuf_binding_free(struct work_struct *wq)
 {
 	struct net_devmem_dmabuf_binding *binding = container_of(wq, typeof(*binding), unbind_w);
@@ -74,9 +92,13 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq)
 		  size, avail))
 		gen_pool_destroy(binding->chunk_pool);
 
-	dma_buf_unmap_attachment_unlocked(binding->attachment, binding->sgt,
-					  binding->direction);
-	dma_buf_detach(binding->dmabuf, binding->attachment);
+	mutex_lock(&net_devmem_lock);
+	mutex_lock(&binding->lock);
+	net_devmem_dmabuf_binding_unmap(binding);
+	mutex_unlock(&binding->lock);
+	xa_erase(&net_devmem_dmabuf_bindings, binding->id);
+	mutex_unlock(&net_devmem_lock);
+
 	dma_buf_put(binding->dmabuf);
 	xa_destroy(&binding->bound_rxqs);
 	percpu_ref_exit(&binding->ref);
@@ -129,10 +151,11 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
 	unsigned long xa_idx;
 	unsigned int rxq_idx;
 
-	xa_erase(&net_devmem_dmabuf_bindings, binding->id);
+	xa_clear_mark(&net_devmem_dmabuf_bindings, binding->id,
+		      NET_DEVMEM_BINDING_LIVE);
 
 	/* Ensure no tx net_devmem_lookup_dmabuf() are in flight after the
-	 * erase.
+	 * mark is cleared.
 	 */
 	synchronize_net();
 
@@ -153,6 +176,89 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
 	percpu_ref_kill(&binding->ref);
 }
 
+static void
+net_devmem_dev_unregister_rx(struct net_devmem_dmabuf_binding *binding,
+			     unsigned long xa_idx, struct net_device *dev)
+{
+	if (xa_get_mark(&net_devmem_dmabuf_bindings, xa_idx,
+			NET_DEVMEM_BINDING_LIVE) ||
+	    READ_ONCE(binding->dev) != dev)
+		return;
+
+	mutex_lock(&binding->lock);
+	WRITE_ONCE(binding->dev, NULL);
+	if (!netif_is_queue_leasee(dev))
+		net_devmem_dmabuf_binding_unmap(binding);
+	mutex_unlock(&binding->lock);
+}
+
+static bool
+net_devmem_dev_unregister_tx(struct net_devmem_dmabuf_binding *binding,
+			     unsigned long xa_idx, struct net_device *dev)
+{
+	if (READ_ONCE(binding->dev) == dev) {
+		xa_clear_mark(&net_devmem_dmabuf_bindings, xa_idx,
+			      NET_DEVMEM_BINDING_LIVE);
+
+		mutex_lock(&binding->lock);
+		WRITE_ONCE(binding->dev, NULL);
+		WRITE_ONCE(binding->vdev, NULL);
+		mutex_unlock(&binding->lock);
+		return true;
+	}
+
+	if (READ_ONCE(binding->vdev) == dev) {
+		mutex_lock(&binding->lock);
+		WRITE_ONCE(binding->vdev, NULL);
+		mutex_unlock(&binding->lock);
+	}
+
+	return false;
+}
+
+static void net_devmem_unmap_detached_tx(void)
+{
+	struct net_devmem_dmabuf_binding *binding;
+	unsigned long xa_idx;
+
+	/* Ensure no tx net_devmem_lookup_dmabuf() or
+	 * validate_xmit_unreadable_skb() are in flight after detach.
+	 */
+	synchronize_net();
+
+	xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
+		if (binding->direction != DMA_TO_DEVICE ||
+		    READ_ONCE(binding->dev))
+			continue;
+
+		mutex_lock(&binding->lock);
+		net_devmem_dmabuf_binding_unmap(binding);
+		mutex_unlock(&binding->lock);
+	}
+}
+
+void net_devmem_dev_unregister(struct net_device *dev)
+{
+	struct net_devmem_dmabuf_binding *binding;
+	bool tx_detached = false;
+	unsigned long xa_idx;
+
+	if (dev->reg_state != NETREG_UNREGISTERING)
+		return;
+
+	mutex_lock(&net_devmem_lock);
+	xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
+		if (binding->direction == DMA_FROM_DEVICE)
+			net_devmem_dev_unregister_rx(binding, xa_idx, dev);
+		else if (net_devmem_dev_unregister_tx(binding, xa_idx, dev))
+			tx_detached = true;
+	}
+
+	if (tx_detached)
+		net_devmem_unmap_detached_tx();
+	mutex_unlock(&net_devmem_lock);
+}
+
 int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				    struct net_devmem_dmabuf_binding *binding,
 				    struct netlink_ext_ack *extack)
@@ -331,6 +437,8 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 			      GFP_KERNEL);
 	if (err < 0)
 		goto err_free_chunks;
+	xa_set_mark(&net_devmem_dmabuf_bindings, binding->id,
+		    NET_DEVMEM_BINDING_LIVE);
 
 	list_add(&binding->list, &priv->bindings);
 
@@ -359,9 +467,11 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
 {
 	struct net_devmem_dmabuf_binding *binding;
+	unsigned long xa_idx = id;
 
 	rcu_read_lock();
-	binding = xa_load(&net_devmem_dmabuf_bindings, id);
+	binding = xa_find(&net_devmem_dmabuf_bindings, &xa_idx, id,
+			  NET_DEVMEM_BINDING_LIVE);
 	if (binding) {
 		if (!net_devmem_dmabuf_binding_get(binding))
 			binding = NULL;
@@ -529,16 +639,19 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv,
 	unsigned long xa_idx;
 
 	xa_for_each(&binding->bound_rxqs, xa_idx, bound_rxq) {
-		if (bound_rxq == rxq) {
-			xa_erase(&binding->bound_rxqs, xa_idx);
-			if (xa_empty(&binding->bound_rxqs)) {
-				mutex_lock(&binding->lock);
-				ASSERT_EXCLUSIVE_WRITER(binding->dev);
-				WRITE_ONCE(binding->dev, NULL);
-				mutex_unlock(&binding->lock);
-			}
-			break;
+		if (bound_rxq != rxq)
+			continue;
+
+		xa_erase(&binding->bound_rxqs, xa_idx);
+		if (xa_empty(&binding->bound_rxqs)) {
+			mutex_lock(&binding->lock);
+			ASSERT_EXCLUSIVE_WRITER(binding->dev);
+			WRITE_ONCE(binding->dev, NULL);
+			if (!rxq->lease)
+				net_devmem_dmabuf_binding_unmap(binding);
+			mutex_unlock(&binding->lock);
 		}
+		break;
 	}
 }
 
diff --git a/net/core/devmem.h b/net/core/devmem.h
index 4a293a7d1149c..5c47c8c3c7d2d 100644
--- a/net/core/devmem.h
+++ b/net/core/devmem.h
@@ -27,7 +27,7 @@ struct net_devmem_dmabuf_binding {
 	 */
 	void *vdev;
 	struct gen_pool *chunk_pool;
-	/* Protect dev */
+	/* Protect dev, attachment and sgt */
 	struct mutex lock;
 
 	/* The user holds a ref (via the netlink API) for as long as they want
@@ -38,7 +38,8 @@ struct net_devmem_dmabuf_binding {
 	 *
 	 * The binding undos itself and unmaps the underlying dmabuf once all
 	 * those refs are dropped and the binding is no longer desired or in
-	 * use.
+	 * use. The dmabuf may be unmapped earlier, when the device it is
+	 * mapped for is unregistered.
 	 *
 	 * net_devmem_get_net_iov() on dmabuf net_iovs will increment this
 	 * reference, making sure that the binding remains alive until all the
@@ -100,6 +101,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 		       struct netlink_ext_ack *extack);
 struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id);
 void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding);
+void net_devmem_dev_unregister(struct net_device *dev);
 int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				    struct net_devmem_dmabuf_binding *binding,
 				    struct netlink_ext_ack *extack);
@@ -196,6 +198,10 @@ net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding)
 {
 }
 
+static inline void net_devmem_dev_unregister(struct net_device *dev)
+{
+}
+
 static inline int
 net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				struct net_devmem_dmabuf_binding *binding,
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 33b9f4eb9565a..b04e22937b789 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -1488,6 +1488,7 @@ static int netdev_genl_netdevice_event(struct notifier_block *nb,
 		break;
 	case NETDEV_UNREGISTER:
 		netdev_lock(netdev);
+		net_devmem_dev_unregister(netdev);
 		netdev_genl_dev_notify(netdev, NETDEV_CMD_DEV_DEL_NTF);
 		netdev_unlock(netdev);
 		break;
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index 737e7e6327b37..1e21f0055a2c0 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -11,6 +11,7 @@ CONFIG_CRYPTO_ARIA=y
 CONFIG_CRYPTO_CHACHA20POLY1305=m
 CONFIG_CRYPTO_SHA1=y
 CONFIG_CRYPTO_SM4_GENERIC=y
+CONFIG_DEBUG_FS=y
 CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_DUMMY=y
@@ -76,6 +77,7 @@ CONFIG_NET_CLS_BPF=m
 CONFIG_NET_CLS_FLOWER=m
 CONFIG_NET_CLS_MATCHALL=m
 CONFIG_NET_CLS_U32=m
+CONFIG_NET_DEVMEM=y
 CONFIG_NETDEVSIM=m
 CONFIG_NET_DROP_MONITOR=m
 CONFIG_NETFILTER=y
@@ -120,6 +122,7 @@ CONFIG_OPENVSWITCH=m
 CONFIG_PAGE_POOL_STATS=y
 CONFIG_PSAMPLE=m
 CONFIG_RPS=y
+CONFIG_SYNC_FILE=y
 CONFIG_SYN_COOKIES=y
 CONFIG_SYSCTL=y
 CONFIG_SYSFS=y
@@ -131,6 +134,7 @@ CONFIG_TEST_BPF=m
 CONFIG_TLS=m
 CONFIG_TRACEPOINTS=y
 CONFIG_TUN=y
+CONFIG_UDMABUF=y
 CONFIG_USER_NS=y
 CONFIG_VETH=y
 CONFIG_VLAN_8021Q=y
diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py
index ceb44c8e1fec5..988878b71358c 100755
--- a/tools/testing/selftests/net/nl_netdev.py
+++ b/tools/testing/selftests/net/nl_netdev.py
@@ -6,10 +6,14 @@ Tests for the netdev netlink family.
 """
 
 import errno
+import fcntl
+import mmap
+import os
+import struct
 from os import system
-from lib.py import ksft_run, ksft_exit
+from lib.py import ksft_run, ksft_exit, KsftFailEx, KsftSkipEx
 from lib.py import ksft_eq, ksft_ge, ksft_ne, ksft_raises, ksft_busy_wait
-from lib.py import NetdevFamily, NetdevSimDev, NlError, defer, ip
+from lib.py import EthtoolFamily, NetdevFamily, NetdevSimDev, NlError, defer, ip
 
 
 def empty_check(nf) -> None:
@@ -366,6 +370,119 @@ def page_pool_stats_ifindex_check(nf) -> None:
     ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.info.id')
 
 
+def _udmabuf_create_ioctl() -> int:
+    """Return UDMABUF_CREATE, _IOW('u', 0x42, struct udmabuf_create)."""
+    machine = os.uname().machine
+    if machine.startswith(("alpha", "mips", "ppc", "powerpc", "sparc")):
+        ioc_write = 4 << 29
+    elif machine.startswith("parisc"):
+        ioc_write = 2 << 30
+    else:
+        ioc_write = 1 << 30
+    return ioc_write | 24 << 16 | ord("u") << 8 | 0x42
+
+
+def _create_udmabuf(num_pages=64) -> int:
+    """Create a sealed memfd-backed udmabuf fd for devmem tests."""
+    if not os.path.exists("/dev/udmabuf"):
+        raise KsftSkipEx("/dev/udmabuf is not available")
+
+    size = num_pages * mmap.PAGESIZE
+    memfd = os.memfd_create("devmem-ksft", os.MFD_ALLOW_SEALING)
+    try:
+        os.ftruncate(memfd, size)
+        fcntl.fcntl(memfd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_SHRINK)
+        devfd = os.open("/dev/udmabuf", os.O_RDWR)
+        try:
+            req = bytearray(struct.pack("IIQQ", memfd, 0, 0, size))
+            return fcntl.ioctl(devfd, _udmabuf_create_ioctl(), req)
+        finally:
+            os.close(devfd)
+    finally:
+        os.close(memfd)
+
+
+def _dmabuf_attach_count(dmabuf_fd) -> int:
+    """Return the number of devices attached to dmabuf_fd, from debugfs."""
+    path = "/sys/kernel/debug/dma_buf/bufinfo"
+    try:
+        with open(path, "r", encoding="utf-8") as f:
+            lines = f.read().splitlines()
+    except OSError as e:
+        raise KsftSkipEx(f"{path} is not readable: {e}") from e
+
+    ino = os.fstat(dmabuf_fd).st_ino
+    found = False
+    for line in lines:
+        fields = line.split("\t")
+        if not found:
+            found = (len(fields) == 7 and fields[5].isdigit() and
+                     int(fields[5]) == ino)
+        elif line.startswith("Total "):
+            return int(line.split()[1])
+    raise KsftFailEx(f"dma-buf {ino} not found in {path}")
+
+
+def _devmem_bind(bind, attrs) -> None:
+    """Run a devmem bind op, skip the test if the device can't do devmem."""
+    try:
+        bind(attrs)
+    except NlError as e:
+        if e.error == errno.EOPNOTSUPP:
+            raise KsftSkipEx(f"devmem binding not supported: {e}") from e
+        raise
+
+
+def devmem_bind_rx_unregister_check(_nf) -> None:
+    """Verify RX devmem bindings detach dma_buf synchronously on netdev unregister."""
+    dmabuf_fd = _create_udmabuf()
+    defer(os.close, dmabuf_fd)
+    nf_priv = NetdevFamily()
+    defer(nf_priv.close)
+    nsimdev = NetdevSimDev(queue_count=2)
+    defer(nsimdev.remove)
+    nsim = nsimdev.nsims[0]
+
+    ip(f"link set dev {nsim.ifname} up")
+    with EthtoolFamily() as ef:
+        ef.rings_set({"header": {"dev-index": nsim.ifindex},
+                      "tcp-data-split": "enabled"})
+    _devmem_bind(nf_priv.bind_rx, {
+        "ifindex": nsim.ifindex,
+        "fd": dmabuf_fd,
+        "queues": [{"id": 1, "type": "rx"}],
+    })
+    ksft_ge(_dmabuf_attach_count(dmabuf_fd), 1)
+
+    nsimdev.remove()
+    ksft_eq(_dmabuf_attach_count(dmabuf_fd), 0)
+
+    nf_priv.close()
+
+
+def devmem_bind_tx_unregister_check(_nf) -> None:
+    """Verify TX devmem bindings detach cleanly on netdev unregister without UAF."""
+    dmabuf_fd = _create_udmabuf()
+    defer(os.close, dmabuf_fd)
+    nf_priv = NetdevFamily()
+    defer(nf_priv.close)
+    nsimdev = NetdevSimDev(queue_count=2)
+    defer(nsimdev.remove)
+    nsim = nsimdev.nsims[0]
+
+    ip(f"link set dev {nsim.ifname} up")
+    _devmem_bind(nf_priv.bind_tx, {
+        "ifindex": nsim.ifindex,
+        "fd": dmabuf_fd,
+    })
+    ksft_ge(_dmabuf_attach_count(dmabuf_fd), 1)
+
+    nsimdev.remove()
+    ksft_eq(_dmabuf_attach_count(dmabuf_fd), 0)
+
+    nf_priv.close()
+
+
 def main() -> None:
     """ Ksft boiler plate main """
     nf = NetdevFamily()
@@ -379,7 +496,9 @@ def main() -> None:
               page_pool_check,
               page_pool_dump_ifindex,
               page_pool_ifindex_leak_check,
-              page_pool_stats_ifindex_check
+              page_pool_stats_ifindex_check,
+              devmem_bind_rx_unregister_check,
+              devmem_bind_tx_unregister_check
               ],
              args=(nf, ))
     ksft_exit()

43/3 2026/10/14 22:45 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 9844
							output: 31
							thoughts: 1719
						

Thoughts:
**KMSAN Evaluation for a Netdevsim/Devmem Patch**

Okay, let's break this down. My goal is to determine if this patch series warrants a dedicated KMSAN fuzzing session. I need to be sure it's *only* KMSAN that would catch a potential issue, given the resource cost.

First, I've got to understand what this patch is doing. From the initial analysis, it seems to be addressing device unregistration race conditions, potential use-after-free scenarios, and cleanup related to devmem (dma-buf) in the `netdevsim` and `devmem.c` code. The test `devmem_bind_tx_unregister_check` reinforces this understanding. Essentially, this patch is tightening up how devmem bindings are detached during netdev unregistration, aiming to prevent UAFs. Good.

Now, let's recall the difference between KMSAN and KASAN. KASAN is my go-to for out-of-bounds accesses, UAFs, and the like. KMSAN, on the other hand, is about catching reads of *uninitialized* memory, or kernel-to-user memory leaks. This is the crucial distinction. The prompt's rules are clear: I only need KMSAN if the patch introduces risks KMSAN *specifically* detects.

Let's carefully go through the code, part by part, in the light of the prompt's rules.

1.  `drivers/net/netdevsim/bus.c`: `dma_coerce_mask_and_coherent()` is simply setting a DMA mask. This doesn't scream uninitialized memory. It's safe to skip this one.

2.  `drivers/net/netdevsim/netdev.c`: The key here is the `params` struct initialization in `nsim_create_page_pool`. A *designated* initializer, as the code shows, is used. I'll need to double check the actual `struct page_pool_params` definition in `include/net/page_pool/types.h` to make sure there are no gotchas I am missing. As long as it's fully zeroed, I'm good here. It's a key data structure. If I were concerned, I would check where it is used. For now, it seems like a safe bet.

3.  `drivers/net/netdevsim/psp.c`: The check `if (!skb_frags_readable(skb))` doesn't seem directly related to uninitialized memory issues. It's more about data integrity or skb fragments. I'm going to pass.

4.  `net/core/devmem.c`: This part introduces a mutex (`net_devmem_lock`) and various unmap/unregister functions. The core of the changes seem focused on synchronization and cleanup. It's handling the binding and unbinding of DMA buffers to net devices. The `xa_erase` call and the locking seem relevant here. The patch includes clearing the `NET_DEVMEM_BINDING_LIVE` mark. The usage of `xa_find` with the `NET_DEVMEM_BINDING_LIVE` mark is important. I don't see any obvious introduction of *uninitialized* memory here. It's all about correct state transitions and locking to prevent races.

5. & 6. & 7. These files are providing support functions and testing infrastructure, but don't seem to introduce risks.

**Conclusion:**

Based on this analysis, I don't see any clear indicators that this patch introduces or exposes *uninitialized* memory risks that KMSAN *exclusively* would detect. The changes are primarily about synchronization, preventing use-after-frees, and cleaning up devmem bindings during unregistration. These issues should be caught by KASAN or other standard bug detectors. I'm confident in saying that a dedicated KMSAN fuzzing session isn't justified in this case.



44/3 2026/10/14 22:46 tool grepper
0m Args:
{
  "Expression": "struct page_pool_params",
  "PathPrefixes": [
    "include/net/"
  ]
}

Results:
{
  "Output": "include/net/page_pool/types.h=65=struct pp_alloc_cache {\n--\ninclude/net/page_pool/types.h-70-/**\ninclude/net/page_pool/types.h:71: * struct page_pool_params - page pool parameters\ninclude/net/page_pool/types.h-72- * @fast:\tparams accessed frequently on hotpath\n--\ninclude/net/page_pool/types.h-86- */\ninclude/net/page_pool/types.h:87:struct page_pool_params {\ninclude/net/page_pool/types.h-88-\tstruct_group_tagged(page_pool_params_fast, fast,\n--\ninclude/net/page_pool/types.h=176=struct page_pool {\ninclude/net/page_pool/types.h:177:\tstruct page_pool_params_fast p;\ninclude/net/page_pool/types.h-178-\n--\ninclude/net/page_pool/types.h-254-\t/* Slow/Control-path information follows */\ninclude/net/page_pool/types.h:255:\tstruct page_pool_params_slow slow;\ninclude/net/page_pool/types.h-256-\t/* User-facing fields, protected by page_pools_lock */\n--\ninclude/net/page_pool/types.h=268=netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool,\n--\ninclude/net/page_pool/types.h-270-\t\t\t\t       gfp_t gfp);\ninclude/net/page_pool/types.h:271:struct page_pool *page_pool_create(const struct page_pool_params *params);\ninclude/net/page_pool/types.h:272:struct page_pool *page_pool_create_percpu(const struct page_pool_params *params,\ninclude/net/page_pool/types.h-273-\t\t\t\t\t  int cpuid);\n"
}

45/3 2026/10/14 22:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 12957
							output: 37
							thoughts: 538
						

Thoughts:
**Analyzing Potential XArray Indexing Issues in Net Device Memory Management**

Okay, so I'm looking at this initialization of `struct page_pool_params` – designated initializers, so unmentioned fields are zeroed. Standard practice, nothing unexpected there. But now I'm digging into `net/core/devmem.c`. My focus is the XArray indexing.

I see `net_devmem_lookup_dmabuf` using `xa_find`. Here, `xa_idx` is directly initialized with the `id` passed to the function. Nothing surprising, as I'd expect.

But then I jump over to `net_devmem_dev_unregister`. This function iterates through the XArray using `xa_for_each`. I *know* that `xa_for_each`, as implemented, initializes the loop's `index` (which maps to `xa_idx` in our usage) to *zero* internally, regardless of what its initial value might be. This is a subtle point, but an important one for avoiding incorrect data retrieval. I need to make sure this is the intended behavior and that it's consistent with the intended use of the XArray. I need to verify that this is not an issue, so I'll check the definition of `xa_for_each` in `include/linux/xarray.h`. I'll look to see if this initialization is done as expected.



46/3 2026/10/14 22:46 tool grepper
0m Args:
{
  "Expression": "#define xa_for_each\\(",
  "PathPrefixes": [
    "include/linux/xarray.h"
  ]
}

Results:
{
  "Output": "include/linux/xarray.h=422=static inline bool xa_marked(const struct xarray *xa, xa_mark_t mark)\n--\ninclude/linux/xarray.h-503- */\ninclude/linux/xarray.h:504:#define xa_for_each(xa, index, entry) \\\ninclude/linux/xarray.h-505-\txa_for_each_start(xa, index, entry, 0)\n"
}

47/3 2026/10/14 22:46 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 13961
							output: 270
							thoughts: 1319
						

Thoughts:
**KMSAN Assessment: This Patch is a KASAN/LOCKDEP Win**

Okay, let's break this down. First, I see `xa_for_each` is used to iterate, setting the index to 0. Then, I'm checking `net_devmem_unmap_detached_tx`. The critical aspect is the `synchronize_net()` call *before* iterating. This tells me that the intent is to prevent concurrent access during the unmapping process. The mutex protection around `net_devmem_dmabuf_binding_unmap` further supports that this is a safe unmap. The core of this patch introduces a `net_devmem_dev_unregister` call within `NETDEV_UNREGISTER`, which calls `net_devmem_dmabuf_binding_unmap`. I'm going through the `net_devmem_dmabuf_binding_unmap` function, which, unmaps, detaches and sets pointers to NULL. That's a strong indicator that the focus here is preventing use-after-free and dangling pointers upon unregister. The unmap also sets the pointers to NULL, a good step to prevent the issues.

I'm thinking about the potential bugs: use-after-free, null pointer dereferences, locking/concurrency issues. But, wait, those are *exactly* the kind of issues that KASAN and LOCKDEP are designed to catch! KASAN is built for use-after-free, null pointer dereferences, and out-of-bounds access. And LOCKDEP handles the locking and deadlock issues.

Now, let's address the KMSAN angle. Does this touch uninitialized memory at all? It does not copy anything to user space, nor does it pass uninitialized stack or heap data. There are no uninitialized structures. The code explicitly prevents reading unreadable netmem buffers. I'm noting the explicit `!skb_frags_readable(skb)` check in `psp.c`. Excellent.

Now, I'm reviewing the KMSAN guidelines: The rule is, "THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN, LOCKDEP, OR OTHER STANDARD BUG DETECTORS". I remember that, that's crucial. I'm reading the sections outlining when KMSAN *is* needed: kernel structs to user space, uninitialized variable branching, and allocation issues. None of that applies here. This patch mainly handles lifecycle management, focusing on proper resource release and protection against use-after-free and dangling pointers on unregister.

So, let's clearly state the reasoning. This patch is about devmem (dmabuf) lifecycle during network device unregister. The goal is to safely unmap and detach, preventing use-after-free. These are issues detectable by KASAN and LOCKDEP. No user-space copy, no uninitialized conditionals, no allocation risks. I'm going to set `NeedsKMSAN=false`. It's a KASAN and LOCKDEP win!



48/3 2026/10/14 22:46 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series implements lifecycle and detachment handling for devmem (dma-buf) bindings when net devices unregister (preventing use-after-free and dangling DMA buffer attachment references), along with support for netmem in netdevsim and associated selftests.\n\nKASAN vs KMSAN Applicability:\n- Primary risks: The potential failure modes introduced or modified by these changes involve resource lifetime management, concurrent access races, use-after-free on unregistered net devices / detached dmabuf structures, NULL pointer dereferences, or locking/deadlock issues. These memory safety bugs and synchronization issues are directly detected by KASAN and LOCKDEP.\n- Uninitialized memory / info-leaks: The changes do not introduce or alter any copying of kernel structures to user space, nor do they expose uninitialized padding or uninitialized memory in socket, netlink, or ioctl responses. All touched structures (such as `page_pool_params`) use designated initializers (zeroing unspecified fields), and loop indices are initialized properly.\n\nBecause no uninitialized memory risks or kernel-to-user info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series implements lifecycle and detachment handling for devmem (dma-buf) bindings when net devices unregister (preventing use-after-free and dangling DMA buffer attachment references), along with support for netmem in netdevsim and associated selftests.\n\nKASAN vs KMSAN Applicability:\n- Primary risks: The potential failure modes introduced or modified by these changes involve resource lifetime management, concurrent access races, use-after-free on unregistered net devices / detached dmabuf structures, NULL pointer dereferences, or locking/deadlock issues. These memory safety bugs and synchronization issues are directly detected by KASAN and LOCKDEP.\n- Uninitialized memory / info-leaks: The changes do not introduce or alter any copying of kernel structures to user space, nor do they expose uninitialized padding or uninitialized memory in socket, netlink, or ioctl responses. All touched structures (such as `page_pool_params`) use designated initializers (zeroing unspecified fields), and loop indices are initialized properly.\n\nBecause no uninitialized memory risks or kernel-to-user info-leaks are introduced, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)