Netdev List
 help / color / mirror / Atom feed
From: Mina Almasry <almasrymina@google.com>
To: netdev@vger.kernel.org
Cc: Mina Almasry <almasrymina@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
	 linux-kselftest@vger.kernel.org,
	Stanislav Fomichev <sdf.kernel@gmail.com>,
	 Bobby Eshleman <bobbyeshleman@meta.com>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	David Wei <dw@davidwei.uk>,
	 Pavel Begunkov <asml.silence@gmail.com>,
	Jens Axboe <axboe@kernel.dk>,  Weiming Shi <bestswngs@gmail.com>,
	io-uring@vger.kernel.org,
	 Jesper Dangaard Brouer <hawk@kernel.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>
Subject: [PATCH net-next v5 0/6] net: devmem: support leased RX and TX queues on netdev unregister
Date: Fri,  4 Dec 2026 23:10:24 +0000	[thread overview]
Message-ID: <20261204231030.3815575-1-almasrymina@google.com> (raw)

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


             reply	other threads:[~2026-12-04 23:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 23:10 Mina Almasry [this message]
2026-12-04 23:10 ` [PATCH net-next v5 1/6] net: guard leased queue ops against physical netdev unregister Mina Almasry
2026-12-04 23:10 ` [PATCH net-next v5 2/6] net: devmem: fold net_devmem_lookup_dmabuf() into net_devmem_get_binding() Mina Almasry
2026-12-04 23:10 ` [PATCH net-next v5 3/6] net: devmem: resolve leased RX queues to physical device on bind Mina Almasry
2026-12-04 23:10 ` [PATCH net-next v5 4/6] net: devmem: synchronize and unmap all device bindings on unregister Mina Almasry
2026-12-04 23:10 ` [PATCH net-next v5 5/6] net: propagate busy status on memory provider uninstall Mina Almasry
2026-12-04 23:10 ` [PATCH net-next v5 6/6] selftests: net: add leased devmem RX and TX netdev unregister tests Mina Almasry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204231030.3815575-1-almasrymina@google.com \
    --to=almasrymina@google.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=bestswngs@gmail.com \
    --cc=bobbyeshleman@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dw@davidwei.uk \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=io-uring@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=sdf.kernel@gmail.com \
    --cc=shuah@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox