netif_rxq_cleanup_unlease() currently discards the return value of __netif_mp_close_rxq(), so memory providers cannot tell whether closing a leased queue failed and hardware may still be using the page pool. Tracking failed closes in a local variable in net_devmem_unbind_dmabuf() is also insufficient once leased-queue uninstalls span multiple queues or precede userspace socket close. Pass a bool busy flag (!!err from __netif_mp_close_rxq()) through memory_provider_ops->uninstall() and record failed closes in a new binding->rxq_busy flag on struct net_devmem_dmabuf_binding. Both mp_dmabuf_devmem_uninstall() and net_devmem_unbind_dmabuf() then defer unmapping whenever any queue of the binding failed to close, leaving cleanup to net_devmem_dev_unregister() or __net_devmem_dmabuf_binding_free(). Existing io_uring/zcrx uninstall behavior is left unchanged. These issues were identified by code inspection while extending devmem unregister teardown to leased queues; they have not been observed in production or tested on real hardware. Verified with netdevsim and netkit selftests in nl_netdev.py and nk_qlease.py. Signed-off-by: Mina Almasry --- v4 -> v5: - Split out busy queue-close propagation into its own patch, adding bool busy to memory_provider_ops->uninstall() and binding->rxq_busy. --- include/net/page_pool/memory_provider.h | 7 ++++++- io_uring/zcrx.c | 3 ++- net/core/dev.c | 2 +- net/core/dev.h | 3 ++- net/core/devmem.c | 12 +++++++----- net/core/devmem.h | 1 + net/core/netdev_rx_queue.c | 10 ++++++---- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h index bceb5f7740e2f..82eac3feefc94 100644 --- a/include/net/page_pool/memory_provider.h +++ b/include/net/page_pool/memory_provider.h @@ -26,7 +26,12 @@ struct memory_provider_ops { void (*destroy)(struct page_pool *pool); int (*nl_fill)(void *mp_priv, struct sk_buff *rsp, struct netdev_rx_queue *rxq); - void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq); + /* Called under netdev_lock(rxq->dev) on device unregister or queue + * unlease. If @busy is true, closing @rxq failed and hardware may + * still be using the page pool. + */ + void (*uninstall)(void *mp_priv, struct netdev_rx_queue *rxq, + bool busy); }; bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr); diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 20597bfa146d6..ed44835a783b5 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -1457,7 +1457,8 @@ static int io_pp_nl_fill(void *mp_priv, struct sk_buff *rsp, return 0; } -static void io_pp_uninstall(void *mp_priv, struct netdev_rx_queue *rxq) +static void io_pp_uninstall(void *mp_priv, struct netdev_rx_queue *rxq, + bool busy) { struct io_zcrx_ifq *ifq = mp_priv; diff --git a/net/core/dev.c b/net/core/dev.c index b7757f91fdf92..55af817b61e5a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -12774,7 +12774,7 @@ static void dev_memory_provider_uninstall(struct net_device *dev) for (i = 0; i < dev->real_num_rx_queues; i++) { struct netdev_rx_queue *rxq = &dev->_rx[i]; - __netif_mp_uninstall_rxq(rxq, &rxq->mp_params); + __netif_mp_uninstall_rxq(rxq, &rxq->mp_params, false); } } diff --git a/net/core/dev.h b/net/core/dev.h index 183c580006b54..2132cbde9d232 100644 --- a/net/core/dev.h +++ b/net/core/dev.h @@ -127,7 +127,8 @@ int __netif_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, int __netif_mp_close_rxq(struct net_device *dev, unsigned int rxq_idx, const struct pp_memory_provider_params *old_p); void __netif_mp_uninstall_rxq(struct netdev_rx_queue *rxq, - const struct pp_memory_provider_params *p); + const struct pp_memory_provider_params *p, + bool busy); /* netdev management, shared between various uAPI entry points */ struct netdev_name_node { diff --git a/net/core/devmem.c b/net/core/devmem.c index a395f100d2f33..01621c0f8b485 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -206,7 +206,6 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) struct netdev_rx_queue *rxq; unsigned long xa_idx; unsigned int rxq_idx; - bool busy = false; xa_clear_mark(&net_devmem_dmabuf_bindings, binding->id, NET_DEVMEM_BINDING_LIVE); @@ -230,10 +229,11 @@ void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding) if (__netif_mp_close_rxq(binding->dev, rxq_idx, &mp_params)) - busy = true; + binding->rxq_busy = true; } - if (binding->direction == DMA_FROM_DEVICE && !busy) { + if (binding->direction == DMA_FROM_DEVICE && + !binding->rxq_busy) { net_devmem_dmabuf_binding_unmap(binding); WRITE_ONCE(binding->dev, NULL); } @@ -692,7 +692,7 @@ static int mp_dmabuf_devmem_nl_fill(void *mp_priv, struct sk_buff *rsp, } static void mp_dmabuf_devmem_uninstall(void *mp_priv, - struct netdev_rx_queue *rxq) + struct netdev_rx_queue *rxq, bool busy) { struct net_devmem_dmabuf_binding *binding = mp_priv; struct netdev_rx_queue *bound_rxq; @@ -702,8 +702,10 @@ static void mp_dmabuf_devmem_uninstall(void *mp_priv, if (bound_rxq != rxq) continue; + if (busy) + binding->rxq_busy = true; xa_erase(&binding->bound_rxqs, xa_idx); - if (xa_empty(&binding->bound_rxqs)) { + if (!binding->rxq_busy && xa_empty(&binding->bound_rxqs)) { net_devmem_dmabuf_binding_unmap(binding); ASSERT_EXCLUSIVE_WRITER(binding->dev); WRITE_ONCE(binding->dev, NULL); diff --git a/net/core/devmem.h b/net/core/devmem.h index 4036aab286c4d..cd65c16c4337d 100644 --- a/net/core/devmem.h +++ b/net/core/devmem.h @@ -83,6 +83,7 @@ struct net_devmem_dmabuf_binding { struct net_iov **tx_vec; unsigned int niov_shift; + bool rxq_busy; struct work_struct unbind_w; }; diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c index dc918f6cd4eeb..78eee3d243f75 100644 --- a/net/core/netdev_rx_queue.c +++ b/net/core/netdev_rx_queue.c @@ -338,7 +338,8 @@ int netif_mp_close_rxq(struct net_device *dev, unsigned int rxq_idx, } void __netif_mp_uninstall_rxq(struct netdev_rx_queue *rxq, - const struct pp_memory_provider_params *p) + const struct pp_memory_provider_params *p, + bool busy) { struct pp_memory_provider_params tmp = *p; @@ -347,7 +348,7 @@ void __netif_mp_uninstall_rxq(struct netdev_rx_queue *rxq, memset(&rxq->mp_params, 0, sizeof(rxq->mp_params)); if (tmp.mp_ops->uninstall) - tmp.mp_ops->uninstall(tmp.mp_priv, rxq); + tmp.mp_ops->uninstall(tmp.mp_priv, rxq, busy); } /* Clean up memory provider state when a queue lease is torn down. If @@ -362,10 +363,11 @@ static void netif_rxq_cleanup_unlease(struct netdev_rx_queue *phys_rxq) { unsigned int rxq_idx = get_netdev_rx_queue_index(phys_rxq); struct pp_memory_provider_params p = phys_rxq->mp_params; + int err; if (!p.mp_ops) return; - __netif_mp_close_rxq(phys_rxq->dev, rxq_idx, &p); - __netif_mp_uninstall_rxq(phys_rxq, &p); + err = __netif_mp_close_rxq(phys_rxq->dev, rxq_idx, &p); + __netif_mp_uninstall_rxq(phys_rxq, &p, !!err); } -- 2.56.1.915.g69d5ec7298-goog