From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5815D0EE00 for ; Tue, 25 Nov 2025 17:36:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 74A2860A7C; Tue, 25 Nov 2025 17:36:46 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id wjcuARG5kKl2; Tue, 25 Nov 2025 17:36:45 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org D607561214 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1764092205; bh=VyWl0VsD65iaDjHgSK7RhKJDS7JR4GokP9CY8Lvln3I=; h=From:To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=G8sPXYDV7NehrrCRWDz2AhNf8/XyJ9MdBeMt97zQvo/M3pg+sU7lBe5FI5lHV3zph hXtpYsVGonokeE1z2hxmWez8DVyAzQG5zs/D+VhLi5aPGgN2joh3cXRX1T0WhoaZDy sxQJVcrDae/Jfi9u/JSo5IReWIrjbkFVSyvPLHDGPg1L4mVxGEZMrbzFxEFSws6zFu 6DkBkv3msHB50h1JIRE+RJ7MF9kty/mtygUJnoOqPPWAtU7pVjLNFrAm7Oh//7ThDN HwLp1bzqvYCNHFDpauf/oPjBgoMwHeYtKg0/Qk72p4Gn8/iyVTmT1PlpvG4WYWCuCh zuoh2Q6vo7Amw== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id D607561214; Tue, 25 Nov 2025 17:36:45 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists1.osuosl.org (Postfix) with ESMTP id 0795C35C for ; Tue, 25 Nov 2025 17:36:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id EDC0440B32 for ; Tue, 25 Nov 2025 17:36:43 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id dHTT0BbCuY_i for ; Tue, 25 Nov 2025 17:36:43 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=192.198.163.12; helo=mgamail.intel.com; envelope-from=aleksander.lobakin@intel.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 29DA540678 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 29DA540678 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by smtp4.osuosl.org (Postfix) with ESMTPS id 29DA540678 for ; Tue, 25 Nov 2025 17:36:43 +0000 (UTC) X-CSE-ConnectionGUID: gv5bd1qTTKuDDjTuUvs1Kw== X-CSE-MsgGUID: 3w12lLYsSsWZPphpUyXuNw== X-IronPort-AV: E=McAfee;i="6800,10657,11624"; a="69979892" X-IronPort-AV: E=Sophos;i="6.20,226,1758610800"; d="scan'208";a="69979892" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2025 09:36:41 -0800 X-CSE-ConnectionGUID: lPf9As8yQfeQnFdQgUVrcA== X-CSE-MsgGUID: uG4UwnLnQmaHtDL2hWSgug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,226,1758610800"; d="scan'208";a="216040375" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmviesa002.fm.intel.com with ESMTP; 25 Nov 2025 09:36:38 -0800 From: Alexander Lobakin To: intel-wired-lan@lists.osuosl.org Cc: Alexander Lobakin , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jacob Keller , Aleksandr Loktionov , nxne.cnse.osdt.itp.upstreaming@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 25 Nov 2025 18:36:00 +0100 Message-ID: <20251125173603.3834486-3-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251125173603.3834486-1-aleksander.lobakin@intel.com> References: <20251125173603.3834486-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764092203; x=1795628203; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7JJU128tDJ+PyF5G7UAG3ifJrnbZV7vGBTPFHmlcVHc=; b=PpXZPmjra/+hgJ4s3i0ZU3RwynI1oWrD4ud/slIi6uM23vMcdQ5fNtVp MoGIZnVkgI66b2O+VKfOko0ItVRrEVd5UETPrQsz4+9hYxKUFaMVPAejI CpmkQ/UM2KhgFQS5ZRmdY0UwNdH3d4Gv8yY16JiMQ0UQ1bnCjjbitWgi6 dclI7N4uMGiCQxw+aqfP25O9sRxycDJQwiVjScMuEoJ3EG9v2qbqTcoFZ 1WQgEOMNxrn++rhj0FwZhcPGRcPBYzxBjP+kGqX7hd1MLTbZTMXu9ivA0 CglYusmAD9CUjzitY/JNxiMZEjgmWi0q04xAeFGLs7fzyHfgXJ4oxvezi w==; X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=intel.com X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=PpXZPmjr Subject: [Intel-wired-lan] [PATCH iwl-next 2/5] libeth: handle creating pools with unreadable buffers X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" 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 --- include/net/libeth/tx.h | 2 +- drivers/net/ethernet/intel/libeth/rx.c | 42 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) 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 diff --git a/drivers/net/ethernet/intel/libeth/rx.c b/drivers/net/ethernet/intel/libeth/rx.c index 8874b714cdcc..11e6e8f353ef 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,47 @@ 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 (!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 +204,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) -- 2.51.1