From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796425837; b=XrgBj3N4IhiuuTvFHbHEQvgAHABE+lxLm/8RcOlJvSy2Er3TFZn7GO8/nWJ9cGXK1P17 iS0HmKdzARkeNu38H9LOxRlbHmTkafy/9E0i9HHcsFJCQNPyPCW7WZQDms73SMo6pZ2v1 aJt0074YpNg4fWIu0++hFzLK/hJEAuOI3iXWkR5bc2rXzwYYrWyj6WVHsVmHQai1RJt2w P1C0HS3/lgpqfYLs/arvE4Y14v1fkiHHFCHlA35PkthwI56hoirVRRGRi0DRagr+oK7Ji YUyY9WoVRZNk9IZ/vxGJLEnju0y+ZZcoHWmmtLlbqisWBR/sHQD9olmqoFTe9kNRS5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796425837; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=nXaRxSCqKSuRBV9uVaZSUtVg/L6RcSuphaOqhS/LDWs=; b=YT+ZQuBpeNX8th83zZsDTN5jnrMRIS648o/i4qA0l5k9IYPFXzEvOdB5+hr61Z0aPwc3 WCN3wkPp5OhorFFCRL/liS5uJArEkB1H1gpTeTxS+N4mnoGHt+MHnpp1NXBhB+BwAohUe w8BLYYkQsSnYxmfqXuRoyD0OndTM8oq3TtotvuK0tjPGtAJ8L6Dh0oIvmUvSOgBO8RTBD 47mthk5SePPGMT8ruZGckaRvC8Tgc8Q9ZaydlgRkfLHpQrjunE3OM+7JGlh39BFEvSHc9 8dBF9zcwlcDjoMoLgebGx54g8KX3obgsSrvfWJrlgLUtyLjhd/xsST63H5WL9LU3OUA== 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=WybKnQze; arc=none smtp.remote-ip=74.125.82.72 Received: from mail-dl1-f72.google.com (mail-dl1-f72.google.com [74.125.82.72]) (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 78C80606A334 for ; Fri, 4 Dec 2026 23:10:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 78C80606A334 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=WybKnQze Received: by mail-dl1-f72.google.com with SMTP id a92af1059eb24-1b5d5fa8e99so5038324c88.1 for ; Fri, 04 Dec 2026 15:10:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796425837; x=1797030637; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nXaRxSCqKSuRBV9uVaZSUtVg/L6RcSuphaOqhS/LDWs=; b=WybKnQzeBHNR/ve+a8lHNrfwGYIOjDlUwSVHy2bJIj+BGFYtsZRcAJO56U2uFUZzrz +7eNyYAk4KNIReRBTkAWVulIarKmwiiMqcceE8OLyF9DcHhH80c5iMnsGU0KiBg0bE2V QGlMB+qPsDBXqWT1VaOpSp8vD8J5snOjPttNN7Txxh6lrq9sB0MXcoMhRez63dj1A9// Cr6RT21Cq5pgdcLGPAzQ6Ct83eDd0f2hhIfT+aRf68sgNWMrgc0D9O1GjB3sWJm7LKi6 dtO6saMT9ghIC1L9CZe/DaXH0/HtzUnTJLPX1Q5j/DGrIkv68s0xi7yMFxgwiPfYikM0 EsnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796425837; x=1797030637; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nXaRxSCqKSuRBV9uVaZSUtVg/L6RcSuphaOqhS/LDWs=; b=neYomxYCJAw0DTENt4kBZzjnkAXpY7BxSgmEDKrdl2XhyhMm2VJoGOt9wfABU5A0pl 5ll+0/p2KjHywzM4H1mHA+/XmDShEwTk/8N7DId34tgCBTCIVI1U7qAz6cl8S0J6VWXb QhoD4dUvAxXyUMDJ8S9VlpJcdrEbeeiexm3WL0kdPIiA+dUd+o7NrRM/vz8atvn1pvHf dstMjtqvxXzNWiqXAX3od6zoeJuJfsgAt2xvSRNyTcI1+Be0wjIJS8eO7pBfu8PWn1u1 vDpTY3/hHzD6BZz6/bqJ4r08UGSI+aVzv5Xcmq9Qgm5oK4KLPGxdvzu7vM1eAotvbvC4 ulCQ== X-Gm-Message-State: APuU4Z+nMTP5XztUFSdZjzk5HL3Oqlva7Io2Vxm2wpmGLuw657jCgzxo GCbfdaqqVff3cmuATHMEi4c1mUKN3Awl1pmeYg9FXVb4kFp6Vhu+NMw/H8yq+jzcnTDFzoWBJ1e 7oltpXxyvMIikeiPTsnG4HNDlC1IMMBKhVi6NRAaXpNYpQdbmxzXB4UOgFyOhRHJCAsFLeqWm4X 5tVW3Yjfx9Hti1TLIm+g+WjUJcvSDsfOcBK3JTCbWEk2KMf8vJyoNb4cAMDOOixTQ= X-Received: from dlfz5-n2.prod.google.com ([2002:a05:701a:8445:20b0:1b5:d170:5d40]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:120:b0:1b5:e9d:c641 with SMTP id a92af1059eb24-1b5d70f2ce2mr4479256c88.18.1796425836137; Fri, 04 Dec 2026 15:10:36 -0800 (PST) Date: Fri, 4 Dec 2026 23:10:29 +0000 In-Reply-To: <20261204231030.3815575-1-almasrymina@google.com> 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 References: <20261204231030.3815575-1-almasrymina@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204231030.3815575-6-almasrymina@google.com> Subject: [PATCH net-next v5 5/6] net: propagate busy status on memory provider uninstall 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" 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