From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796401740; b=PRCqsZBSt2v4yH4HzhvCnmAT5yDhU7y1/Lqm+m4Axt2xd+dwodkdvuiw6II0cR+eMyvi 0r4fYk07osHNRIXUl9Fdyvrw/0EBhYmW6L3EajktC/QpfgCtEvUxBGxv8wqQid0MZE9Gs msOtFy+J/oT1xBOSWCrRBgLdm/SH2mYBRBUdaOnJg0nmypHCN/TJ3WQD8IRZ6Y9Bv+0Ng Lk6dYptqQ8ig3OZ81oJ8XsqdE82HaVAzJPW2isgziXAsyOzqxzVP/DspyrDF4G/mhfBbw iwzJbKGgnZQ9Vl7AVEYoYS51UYQu6andV9Aca2yoy9sDZo4Qhk5mu4/KIfVr1j94OEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796401740; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=1Ud4dvn9u/cjpiRk7P1/kyP2WDjiBqPwyne6ojP2FxI=; b=pjAePbK9j1XXnz6DuRWkT92ZqMoPKg31ERCMPXeLpirDL1IhDpFLaT80pa4f/ECviMQ9 s3gbHa8FVWz4PIY8unTEMFFhqLKyHDUCrE2I5jf83RiU2l50Of3ejd4hI5HWDWi4m/7tY h5yuxcQnu5DMxvyxHoZ+psEPwxXWRj12/4DJ+tJJ69DcZ7nIn4sMZCLYt0l03aT4VGzVI YXnrOFwsSHtpiZAzPp2Qae+RQYCnipe5bA6F4/vcgsDGxgMPtREjtwovd978+XBCrBVmM lvH9PovsUOmLXAS6yF8ires7RILEsZbUXAlz8DUpGDBJlhY1HcdC7oNncYhB63AVJfg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="hy/cWZ0Y"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 802C4606A32C; Fri, 4 Dec 2026 16:29:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hy/cWZ0Y Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0A841F00934; Fri, 4 Dec 2026 16:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796401740; bh=1Ud4dvn9u/cjpiRk7P1/kyP2WDjiBqPwyne6ojP2FxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hy/cWZ0YkGsNMMLTzLXKkellxsUOu9M0R9RS11kUEQPh8phqFK95rj/NMKBEJM+zk wa2IJnUnBrFHrNApyC1mYTMgPVubYeBdRqbh0rzFAJiaxd/kAY7hGyB4RAH8yvlMXo oZ6nkovLefv3a44oxmC5Yjxhz9wkotXLsIRjGCf18q52g2i4klGVbYBnQthcnqvudp ULU/n+6ls70TBLuGspMiBbBJfCA5YPZ3JTyttnG/X+eFbHMURDn8PqoHpROJKSexBY xuvvoLUZbyIlup8Vn8mAnpK7yj92maOmYilPrawE28A8HSqmDxVs6ytwVB+Ez52TU+ 0BYiyYqkIb7YQ== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Nikolay Aleksandrov , Andrew Lunn , Ilias Apalodimas , Magnus Karlsson , Maciej Fijalkowski , Donald Hunter , Alexander Duyck , Saeed Mahameed , Tariq Toukan , Mark Bloch , Leon Romanovsky , Shuah Khan , Jonathan Corbet , netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Simon Horman , Stanislav Fomichev , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , David Wei , Tao Cui , linux-kernel@vger.kernel.org, kernel-team@meta.com, "Mike Marciniszyn (Meta)" , linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan , Randy Dunlap , linux-doc@vger.kernel.org Subject: [PATCH net-next v2 09/15] eth: fbnic: Receive into XDP-only memory providers Date: Fri, 4 Dec 2026 17:27:14 +0100 Message-ID: <20261204162723.755897-10-bjorn@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204162723.755897-1-bjorn@kernel.org> References: <20261204162723.755897-1-bjorn@kernel.org> 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fbnic still handles RX heads by page address, so an XDP-only provider cannot back its RX pool. Let the header page pool take an XDP-only provider, and handle heads as netmem. The payload ring shares that pool, so both rings fill from the provider, and header-split packets reach the program as multi-buffer packets. Skip the prefetch of XDP-only heads, which may cost a page walk. Size the page pool of such a queue in the pages that the rings may post, as the provider checks that size against its chunks. A device that is down creates no page pool on ring changes, so refuse to grow its BDQs with -EBUSY while a queue has such a provider, rather than fail the next open. On a running device, the provider checks the new pool first. Signed-off-by: Björn Töpel --- Notes (v2changes): Changes in v2: - v1 patch 9, "eth: fbnic: Support XDP redirect", was posted to net-next on its own and is a dependency. - Refuse to grow the BDQs while the device is down and a queue has such a provider, as nothing checks them before the next open, and size the page pool for the provider in the pages that the BDQs post (Sashiko). - The message now says that the payload ring shares the header page pool, so both rings fill from the provider. .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 22 ++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 41 +++++++++++-------- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 8 ++++ 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c index 9714a89977fa..3355aadeb8ff 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "fbnic.h" #include "fbnic_netdev.h" @@ -341,6 +342,16 @@ static void fbnic_set_rings(struct fbnic_net *fbn, fbn->hds_thresh = kernel_ring->hds_thresh; } +static bool fbnic_has_xdp_only_mp(struct net_device *netdev) +{ + unsigned int i; + + for (i = 0; i < netdev->real_num_rx_queues; i++) + if (netif_rxq_has_xdp_only_mp(netdev, i)) + return true; + return false; +} + static int fbnic_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, struct kernel_ethtool_ringparam *kernel_ring, @@ -386,6 +397,17 @@ fbnic_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, } if (!netif_running(netdev)) { + /* No page pool lets the provider check larger rings before + * the device opens, which would then fail + */ + if (fbnic_bdq_pages(ring->rx_mini_pending, + ring->rx_jumbo_pending) > + fbnic_bdq_pages(fbn->hpq_size, fbn->ppq_size) && + fbnic_has_xdp_only_mp(netdev)) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot grow the BDQs while the device is down and a queue has an XDP-only memory provider"); + return -EBUSY; + } fbnic_set_rings(fbn, ring, kernel_ring); return 0; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index 9525ad2f7e14..22e9fa5f8f15 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -765,15 +765,14 @@ static void fbnic_page_pool_init(struct fbnic_ring *ring, unsigned int idx, rx_buf->netmem = netmem; } -static struct page * +static netmem_ref fbnic_page_pool_get_head(struct fbnic_q_triad *qt, unsigned int idx) { struct fbnic_rx_buf *rx_buf = &qt->sub0.rx_buf[idx]; rx_buf->pagecnt_bias--; - /* sub0 is always fed system pages, from the NAPI-level page_pool */ - return netmem_to_page(rx_buf->netmem); + return rx_buf->netmem; } static netmem_ref @@ -1001,13 +1000,12 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd, unsigned int len = FIELD_GET(FBNIC_RCD_AL_BUFF_LEN_MASK, rcd); unsigned int hdr_pg_idx = fbnic_rcd_bd_idx(&qt->sub0, rcd); unsigned int frame_sz, hdr_pg_start, hdr_pg_end, headroom; - unsigned char *hdr_start; - struct page *page; + netmem_ref netmem; /* data_hard_start should always be NULL when this is called */ WARN_ON_ONCE(pkt->buff.data_hard_start); - page = fbnic_page_pool_get_head(qt, hdr_pg_idx); + netmem = fbnic_page_pool_get_head(qt, hdr_pg_idx); /* Short-cut the end calculation if we know page is fully consumed */ hdr_pg_end = FIELD_GET(FBNIC_RCD_AL_PAGE_FIN, rcd) ? @@ -1020,15 +1018,20 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd, hdr_pg_start += fbnic_rcd_bd_page_offset(&qt->sub0, rcd); /* Sync DMA buffer */ - dma_sync_single_range_for_cpu(nv->dev, page_pool_get_dma_addr(page), + dma_sync_single_range_for_cpu(nv->dev, + page_pool_get_dma_addr_netmem(netmem), hdr_pg_start, frame_sz, DMA_BIDIRECTIONAL); /* Build frame around buffer */ - hdr_start = page_address(page) + hdr_pg_start; - net_prefetch(hdr_start + headroom); - xdp_prepare_buff(&pkt->buff, hdr_start, headroom, - len - FBNIC_RX_PAD, true); + xdp_prepare_buff(&pkt->buff, xdp_netmem_address(netmem) + hdr_pg_start, + headroom, len - FBNIC_RX_PAD, true); + pkt->head = netmem; + /* The kernel reads an XDP-only head only if the program does, and a + * prefetch may cost a page walk + */ + if (!netmem_is_net_iov(netmem)) + net_prefetch(pkt->buff.data); pkt->hwtstamp = 0; pkt->add_frag_failed = false; @@ -1072,8 +1075,6 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd, static void fbnic_put_pkt_buff(struct fbnic_q_triad *qt, struct fbnic_pkt_buff *pkt, int budget) { - struct page *page; - if (!pkt->buff.data_hard_start) return; @@ -1092,8 +1093,7 @@ static void fbnic_put_pkt_buff(struct fbnic_q_triad *qt, } } - page = virt_to_page(pkt->buff.data_hard_start); - page_pool_put_full_page(qt->sub0.page_pool, page, !!budget); + page_pool_put_full_netmem(qt->sub0.page_pool, pkt->head, !!budget); } static struct sk_buff *fbnic_build_skb(struct fbnic_napi_vector *nv, @@ -1612,7 +1612,8 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt, struct page_pool_params pp_params = { .order = 0, .flags = PP_FLAG_DMA_MAP | - PP_FLAG_DMA_SYNC_DEV, + PP_FLAG_DMA_SYNC_DEV | + PP_FLAG_ALLOW_XDP_ONLY_NETMEM, .pool_size = fbn->hpq_size + fbn->ppq_size, .nid = NUMA_NO_NODE, .dev = fbn->netdev->dev.parent, @@ -1632,8 +1633,14 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt, * NAPI_POLL_WEIGHT possibly make more sense? The question is how * may pages do we need to hold in reserve to get the best return * without hogging too much system memory. + * + * An XDP-only provider checks the size against its chunks, so it + * must see every page that the rings may post. */ - if (pp_params.pool_size > 32768) + if (netif_rxq_has_xdp_only_mp(fbn->netdev, rxq_idx)) + pp_params.pool_size = fbnic_bdq_pages(fbn->hpq_size, + fbn->ppq_size); + else if (pp_params.pool_size > 32768) pp_params.pool_size = 32768; pp = page_pool_create(&pp_params); diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h index a61ac2df7c03..03b668ff8a42 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -81,6 +81,7 @@ struct fbnic_net; struct fbnic_pkt_buff { struct xdp_buff buff; + netmem_ref head; ktime_t hwtstamp; bool add_frag_failed; }; @@ -185,6 +186,13 @@ static inline u16 fbnic_bd_page_count(const struct fbnic_ring *bdq) return 1U << bdq->bd_page_shift; } +static inline u32 fbnic_bdq_pages(u32 hpq_size, u32 ppq_size) +{ + u32 shift = ilog2(PAGE_SIZE / FBNIC_BD_PAGE_SIZE); + + return (hpq_size >> shift) + (ppq_size >> shift); +} + netdev_tx_t fbnic_xmit_frame(struct sk_buff *skb, struct net_device *dev); netdev_features_t fbnic_features_check(struct sk_buff *skb, struct net_device *dev, -- 2.56.1