From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796425832; b=gwQF+ESZ4zlbgFlkVcGATz0nYEsd+EAwpSW6Xtg0AkQIVRN9YUKvRRJPbbZ3kHhTMsK5 lLEskV2tTCXWx/scFEwNk1O9MYiuod7NYRhOjzHIVdsLUN7mNrfINJKB43r7baTEe6WNI BMxrpoZkQE8eX2Z/NC96sEOgrUOOVWMtKo/1XgGYL+whNHAw6ZWqXKV2PbQjs8//sAhxi onFZM35g2VMsyO137zNAWg7KIynTfq0xbVfJXgyRxK6ddMvj0VAz/02GYjwsbmpS2rliY C1aV25ehj9HO0EZHBmqTJ5hODjtF4oWdgO5BxNy/JZOf9RFdjrYOb0maARKzByJBDCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796425832; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type; bh=ZP7aMaJCKxd5evXou+dLPmZ+FWNTyz3F4kjeImyjsrg=; b=OM9T8rmwswMHWmnYX4hB87XAENQhiLmI/fnVoHQjzHvt7XuqoGtRDfLRo/6vqs5xAjPH PL84xjkBEeXtDADE8FiOTAFtVsVQ68fQYH8CMx8mH73jJq3Uq7/Fn8dRXRm+NK+yjAbJy mALEM7C54d0eJ8ziY8AHnR5wIWxv5QSTMcoSTRtGdUKREkgmZZC4fS36T5RSANAW8LSkI TWQnknbN7LOZ1OSnCbOmEZAohc4HwktL4Luu69RczHaP9IINZ55kytPrfSC6PE/cjbBUp e8FWkHHX3xzN8VVQHFiBB3oLc31I2oQ0rbgAQOVB8kGiSFhc5HTpky7oqIvHbsJ6v9g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Juo1lkEm; arc=none smtp.remote-ip=74.125.82.197 Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 309A4606A322 for ; Fri, 4 Dec 2026 23:10:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 309A4606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Juo1lkEm Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-384c78aa0dbso2104358eec.0 for ; Fri, 04 Dec 2026 15:10:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796425831; x=1797030631; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZP7aMaJCKxd5evXou+dLPmZ+FWNTyz3F4kjeImyjsrg=; b=Juo1lkEmh/MdWzGtk/IU3GW8Uw+6DUNxIodHImhh+D4TU8Y0n2jr/CznrI1ah2HnJP IS4ov6JNC1jaPTY/nxlzqPjoHs1lAAac+k2jZt3ET/jcrUTb+IH9hPd7dZoHcLCjA/p3 h8Kqh4NtifU1agPXH9peyijVYoBqaGirJdSDPCnqIB5jj5Z4XkoRE2VvnICzlAHLLmzm rZFHGq+aOkcMyCSKMNh9uv339xvmUEBA/vfAguX8TsxGa9PSHovp/f5DjLmAWs+jv9U5 702RH8GTtJBb02LROHQeBe3gQwoU3vaWgXE/g/c8wv0AjIGR8RKnuZpTP8Ohmg0m9S8a Ircg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796425831; x=1797030631; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZP7aMaJCKxd5evXou+dLPmZ+FWNTyz3F4kjeImyjsrg=; b=GRiV9n65NKVe4DnXq7UJ6ARZTTB9oywUXDzZQzVApDLtR0Z8u7VGdbUkeyJL5m08Re mavKMgxyTKSqi6hz8om1oQg/mGxjn6FXrjtzotxu9FVomtqMilebaRNSigm+QYGd8UT8 gfs55kpi0f4ibDudKznp7VRt7EMHdRzCuDnPuiI2JZsWEWAXUryCGsCAetrOlELIp+1q kY2VE0BHDuSaeah2f70FF7V8J35i/R/wy/6JpAkvxb2nnyHPR3HrGNPrHInr+WxLXtr4 24RCbJWW9mAA00l5YyKfVrLYAsysSPIalAIbxWA8DUuei2aHPJYEVu++nwALn96WGHOH yw2g== X-Gm-Message-State: AB4q+uF9fwx7UnVa4cS6nzsxTpdzd9a1vWOb+CEhajoeYvJtkuU9tD7f D20FEo+HLIN/XqwUnKlfacZW+HDSl6MgPOJgqnz9bRWitArKdaXpg5YjrLRPDdYbW2ELzkCasvA 14uhXOvf/PlwE3hVqowvKg3WpPdu+Cpk7fQJ9qfwd3EaNvxKQXpaMvBoWByECnnxM82B6a+WcfO qNhBP6rCPhrQ2IVK7bBPP10RlIDKgh/e7Z0liuaz83ViAfcDyfWXWNq/V5JJqaF/8= X-Received: from dybnq7.prod.google.com ([2002:a05:7300:e507:b0:351:4a2a:1ece]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:830d:b0:386:c4bd:7ff0 with SMTP id 5a478bee46e88-3875212957fmr3140504eec.13.1796425830959; Fri, 04 Dec 2026 15:10:30 -0800 (PST) Date: Fri, 4 Dec 2026 23:10:24 +0000 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204231030.3815575-1-almasrymina@google.com> Subject: [PATCH net-next v5 0/6] net: devmem: support leased RX and TX queues on netdev unregister From: Mina Almasry To: netdev@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Shuah Khan , linux-kselftest@vger.kernel.org, Stanislav Fomichev , Bobby Eshleman , Nikolay Aleksandrov , Daniel Borkmann , David Wei , Pavel Begunkov , Jens Axboe , Weiming Shi , io-uring@vger.kernel.org, Jesper Dangaard Brouer , Ilias Apalodimas Content-Type: text/plain; charset="UTF-8" Support leased RX and TX devmem bindings when either the virtual device (e.g. netkit) or the physical backing net_device is unregistered, using a single-device design that resolves leased RX queues to their physical device and physical RX queue indices at bind-rx time: 1. Introduce netdev_lock_if_alive() and guard leased-queue operations (netdev_queue_get_dma_dev(), netif_mp_open_rxq(), netdev_nl_bind_tx_doit(), and __netif_mp_close_rxq()) against a physical backing device that has entered unregistration. 2. Fold net_devmem_lookup_dmabuf() into net_devmem_get_binding() so the xarray lookup, validation, device check, and reference acquisition run under a single rcu_read_lock() section. 3. Resolve leased RX queues to phys_dev and phys_rxq indices once at bind-rx time while holding netdev_lock(virt_dev) -> netdev_lock(phys_dev) continuously across DMA lookup, dmabuf mapping, and queue opens, storing phys_dev in binding->dev and phys_rxq in binding->bound_rxqs and clearing rxq->mp_params centrally in __netif_mp_uninstall_rxq(). 4. Update net_devmem_dev_unregister() to synchronize with in-flight TX net_devmem_get_binding() lookups via a single synchronize_net() and unmap all remaining bindings with binding->dev == dev (including live RX bindings whose close failed) while preserving TX binding->vdev behaviour on virtual device unregister. 5. Propagate a bool busy flag through memory_provider_ops->uninstall() into binding->rxq_busy so devmem defers DMA unmapping whenever any queue close fails. 6. Add kselftests in nl_netdev.py covering leased RX validation, RX virtual-first / physical-first / netns unregistration, and TX virtual-first / physical-first unregistration. These issues were discovered during code review (including Sashiko) of the earlier non-leased devmem unregister series and subsequent mailing list review, and confirmed by code inspection (not observed in production or tested on real hardware). Verified with netdevsim and netkit selftests in nl_netdev.py and nk_qlease.py. v5: - Rebase onto latest net-next/main. - Drop v4's dual-device bind_dev/map_dev split in favour of resolving leased RX queues to phys_dev and phys_rxq at bind-rx time while holding netdev_lock(virt_dev) -> netdev_lock(phys_dev) continuously (Willem). - Replace netif_lease_valid() with netdev_lock_if_alive() and guard netdev_queue_get_dma_dev(), netif_mp_open_rxq(), and netdev_nl_bind_tx_doit() (Paolo). - Clear rxq->mp_params centrally in __netif_mp_uninstall_rxq() and propagate a bool busy flag from netif_rxq_cleanup_unlease() through memory_provider_ops->uninstall() so devmem defers DMA unmapping on busy queue close failures while still unmapping on phys_dev unregister or binding free. - Preserve TX binding behaviour when the virtual device unregisters (clearing binding->vdev without tearing down the underlying physical TX mapping) (Paolo). - Expand nl_netdev.py selftests with negative leased-queue validation, netkit netns exit teardown, and TX virtual-first retention checks. - v4: https://lore.kernel.org/netdev/20261120045918.1239746-1-almasrymina@google.com/ v4: - Rebase onto latest net-next/main. - Fold net_devmem_lookup_dmabuf() into net_devmem_get_binding() under a single rcu_read_lock() (deferring net_devmem_dmabuf_binding_get() until after all checks pass) and update net_devmem_dev_unregister() to use a two-pass loop with a single synchronize_net() after clearing NET_DEVMEM_BINDING_LIVE and before unmapping bindings with map_dev == dev (Paolo). - Document issue discovery, validation, and testing in commit messages and the cover letter (netdev-bot+sinfo). - v3: https://lore.kernel.org/netdev/20261115022607.348112-1-almasrymina@google.com/ v3: - Rebase onto latest net-next/main. - Add netif_lease_valid() helper and keep lease validity checks in the lease-aware callers (netif_mp_open_rxq(), netif_mp_close_rxq(), netif_rxq_cleanup_unlease(), and net_devmem_bind_dmabuf()) rather than inside __netif_mp_open_rxq() / __netif_mp_close_rxq(), and document why mp_params is cleared directly when !netif_lease_valid(dev) (Stanislav, Sashiko). - Guard the bound_rxqs loop in net_devmem_unbind_dmabuf() with if (binding->bind_dev), keep the !netif_is_queue_leasee(dev) guard in net_devmem_dev_unregister() in patch 4/6 until patch 5/6 resolves binding->map_dev to the physical device so the series is bisectable at every commit, and document the use-after-free in dma_unmap_sg_attrs() on physical netdev teardown in patch 5/6 (Sashiko). - In nl_netdev.py, verify dmabuf and lease on the physical queue after binding, skip when queue_create returns EOPNOTSUPP, probe the physical device on EOPNOTSUPP so a broken lease lookup is not masked as SKIP, and clean up nk_ifname between loop iterations (Sashiko). - v2: https://lore.kernel.org/netdev/20261108055809.2122934-1-almasrymina@google.com/ v2: - Split patch 3/4 from v1 into 3 smaller commits (patches 3/6..5/6). - Clear rxq->mp_params and return 0 in __netif_mp_close_rxq() whenever dev is already unregistering, avoiding queue reconfiguration on an already-shut-down map_dev during cascaded lease teardown (Sashiko). - Drop unnecessary xa_erase() in net_devmem_unbind_dmabuf() and use a local map_dev variable in net_devmem_get_binding() (Stanislav). - Restore ASSERT_EXCLUSIVE_WRITER(binding->bind_dev) in mp_dmabuf_devmem_uninstall(), drop redundant bind_dev->reg_state check in net_devmem_bind_dmabuf(), and expand commit message rationale (Dragos, Stanislav). - v1: https://lore.kernel.org/netdev/20261103232659.1340283-1-almasrymina@google.com/ Mina Almasry (6): net: guard leased queue ops against physical netdev unregister net: devmem: fold net_devmem_lookup_dmabuf() into net_devmem_get_binding() net: devmem: resolve leased RX queues to physical device on bind net: devmem: synchronize and unmap all device bindings on unregister net: propagate busy status on memory provider uninstall selftests: net: add leased devmem RX and TX netdev unregister tests include/net/netdev_lock.h | 9 + include/net/page_pool/memory_provider.h | 7 +- io_uring/zcrx.c | 7 +- net/core/dev.c | 2 +- net/core/dev.h | 13 +- net/core/devmem.c | 114 ++++++------ net/core/devmem.h | 12 +- net/core/netdev-genl.c | 144 +++++++++++++-- net/core/netdev_queues.c | 7 +- net/core/netdev_rx_queue.c | 60 +++--- tools/testing/selftests/net/nl_netdev.py | 223 ++++++++++++++++++++++- 11 files changed, 477 insertions(+), 121 deletions(-) base-commit: d5cf954cebe4f175dfd834e1dc471a3aa203ec7d -- 2.56.1.915.g69d5ec7298-goog