Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6615425CFF; Fri, 6 Feb 2026 17:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770400157; cv=none; b=OfHSsPV7h8MZM8ce60q6+e0/JD+P6dINtz5qok0MA0Jw68pvmeWF3h/lMH4YhXrfo/6ER6XDpn+3iQe4f2c5TwWmt/7SvNqwmnn0nYTZv8GbzvFGFLTYklQd5d8ogn0w+SQyZBDPHdg4BaA//v4rrFYKva/44w4q6i74r9SqABQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770400157; c=relaxed/simple; bh=9KoUZ4n3Q6vcElaEEvNlgpvkHxIrb0eKKjOiQKJSycE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tgISqTPuOv2DMoRZwDSlTu/cwLEZP05rc9ZmXLF5u+/PYfzmM+DBu99oK90g5QeHtyALr8gcEuOVaiT5zO18MHuj6JSDl0Vdek/16ywcQxq22y6Dpp1Ukop/bTKYMKQDaeC72NDJMMpseS4wTds9g8nKKY9Q44rcCFthNU3412Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Y96RH8Kl; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Y96RH8Kl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770400158; x=1801936158; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9KoUZ4n3Q6vcElaEEvNlgpvkHxIrb0eKKjOiQKJSycE=; b=Y96RH8KlKRGVkOWtmKLxOISMLgWjEu+m6jodq/Pvc77PPW4CTdFL7zCu Zk26HROaE5bWp6jSsQYpC5V/Rf3Iz1WXD5wCQaTSGI3ZJNilMTgC2QKIA /HeHMKmsBxla3dmA0jyzG2lsTWT6OQ6Er7zb8dt55Cg/eGR35rIdhS1aN 55YjucH5A+0BCTvhbS5ulgLCMj5ElKA0AilF2nQgYmiKjVC8zNh2BN64Y Mc2D5609zU01QNriMjVO5fGOJ2ISGvgltiFPdgVuPEfgwNhQ3STQcNvhj Jg1mpwXM7XrUSTyAOBw5qYulyaUCZKNRCV6b5gQhKuROCW7J+6xyoquCk Q==; X-CSE-ConnectionGUID: uAtjyolxRVWxrhi6092htA== X-CSE-MsgGUID: AQKlwJa6SsKMjsGL1TOhsw== X-IronPort-AV: E=McAfee;i="6800,10657,11693"; a="71793103" X-IronPort-AV: E=Sophos;i="6.21,276,1763452800"; d="scan'208";a="71793103" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2026 09:49:18 -0800 X-CSE-ConnectionGUID: 8QfX1ObpQt6BgqtyQHbUXg== X-CSE-MsgGUID: Ha4RopxGReGkHkn9qhHJXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,276,1763452800"; d="scan'208";a="215495396" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa004.fm.intel.com with ESMTP; 06 Feb 2026 09:49:17 -0800 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Alexander Lobakin , anthony.l.nguyen@intel.com, jacob.e.keller@intel.com, nxne.cnse.osdt.itp.upstreaming@intel.com, horms@kernel.org, maciej.fijalkowski@intel.com, magnus.karlsson@intel.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, bpf@vger.kernel.org, Aleksandr Loktionov , Alexander Nowlin Subject: [PATCH net-next 2/9] libeth: handle creating pools with unreadable buffers Date: Fri, 6 Feb 2026 09:48:59 -0800 Message-ID: <20260206174910.4066255-3-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260206174910.4066255-1-anthony.l.nguyen@intel.com> References: <20260206174910.4066255-1-anthony.l.nguyen@intel.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Alexander Lobakin libeth uses netmems for quite some time already, so in order to support unreadable frags / memory providers, it only needs to set PP_FLAG_ALLOW_UNREADABLE_NETMEM when needed. Also add a couple sanity checks to make sure the driver didn't mess up the configuration options and, in case when an MP is installed, return the truesize always equal to PAGE_SIZE, so that libeth_rx_alloc() will never try to allocate frags. Memory providers manage buffers on their own and expect 1:1 buffer / HW Rx descriptor association. Bonus: mention in the libeth_sqe_type description that LIBETH_SQE_EMPTY should also be used for netmem Tx SQEs -- they don't need DMA unmapping. Reviewed-by: Jacob Keller Reviewed-by: Aleksandr Loktionov Signed-off-by: Alexander Lobakin Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/libeth/rx.c | 45 ++++++++++++++++++++++++++ include/net/libeth/tx.h | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/libeth/rx.c b/drivers/net/ethernet/intel/libeth/rx.c index 8874b714cdcc..7492af5f764c 100644 --- a/drivers/net/ethernet/intel/libeth/rx.c +++ b/drivers/net/ethernet/intel/libeth/rx.c @@ -6,6 +6,7 @@ #include #include +#include /* Rx buffer management */ @@ -139,9 +140,50 @@ static bool libeth_rx_page_pool_params_zc(struct libeth_fq *fq, fq->buf_len = clamp(mtu, LIBETH_RX_BUF_STRIDE, max); fq->truesize = fq->buf_len; + /* + * Allow frags only for kernel pages. `fq->truesize == pp->max_len` + * will always fall back to regular page_pool_alloc_netmems() + * regardless of the MTU / FQ buffer size. + */ + if (pp->flags & PP_FLAG_ALLOW_UNREADABLE_NETMEM) + fq->truesize = pp->max_len; + return true; } +/** + * libeth_rx_page_pool_check_unread - check input params for unreadable MPs + * @fq: buffer queue to check + * @pp: &page_pool_params for the queue + * + * Make sure we don't create an invalid pool with full-frame unreadable + * buffers, bidirectional unreadable buffers or so, and configure the + * ZC payload pool accordingly. + * + * Return: true on success, false on invalid input params. + */ +static bool libeth_rx_page_pool_check_unread(const struct libeth_fq *fq, + struct page_pool_params *pp) +{ + if (!pp->netdev) + return true; + + if (!netif_rxq_has_unreadable_mp(pp->netdev, pp->queue_idx)) + return true; + + /* For now, the core stack doesn't allow XDP with unreadable frags */ + if (fq->xdp) + return false; + + /* It should be either a header pool or a ZC payload pool */ + if (fq->type == LIBETH_FQE_HDR) + return !fq->hsplit; + + pp->flags |= PP_FLAG_ALLOW_UNREADABLE_NETMEM; + + return fq->hsplit; +} + /** * libeth_rx_fq_create - create a PP with the default libeth settings * @fq: buffer queue struct to fill @@ -165,6 +207,9 @@ int libeth_rx_fq_create(struct libeth_fq *fq, struct napi_struct *napi) struct page_pool *pool; int ret; + if (!libeth_rx_page_pool_check_unread(fq, &pp)) + return -EINVAL; + pp.dma_dir = fq->xdp ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE; if (!fq->hsplit) diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h index c3db5c6f1641..a66fc2b3a114 100644 --- a/include/net/libeth/tx.h +++ b/include/net/libeth/tx.h @@ -12,7 +12,7 @@ /** * enum libeth_sqe_type - type of &libeth_sqe to act on Tx completion - * @LIBETH_SQE_EMPTY: unused/empty OR XDP_TX/XSk frame, no action required + * @LIBETH_SQE_EMPTY: empty OR netmem/XDP_TX/XSk frame, no action required * @LIBETH_SQE_CTX: context descriptor with empty SQE, no action required * @LIBETH_SQE_SLAB: kmalloc-allocated buffer, unmap and kfree() * @LIBETH_SQE_FRAG: mapped skb frag, only unmap DMA -- 2.47.1