From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5EE8C43FEF; Sat, 11 May 2024 07:42:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2C1A140293; Sat, 11 May 2024 07:42:33 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by mails.dpdk.org (Postfix) with ESMTP id E07ED40261 for ; Sat, 11 May 2024 07:42:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715406151; x=1746942151; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ws1Q9YQemwTBLPvlqpQYFhrORBkNACM4GrpEvog4gfY=; b=BQFeOmuV43kftYTnaQK2LPEovjf4enrx2569rQ/G2WdqY5KkqMKyC4+J KJ7RtzbZ/0ReEo/OhCtuVWMyv69f7IqodLL4d1KJ1DU5fw3NkhbU+bWhf bR8r06Kuk+yoVJuKI46a1UZDOvYEEDamu7jr/803m52UlKUj6xD4F16zT 67ho110b5ayLO2QiIQaD48Zic4XVHGL5VuXYiLeCpac58g+Pblscb5gvj IwT+B8/MPO9oslRiGEQ75QZSSx+HpiWlfetDxLrxpALx5lxEty5wRbo6l hYUcCuuecfbmPSwxqBXLVi0nWCj25T0wujuSTOS76aBofd9Am/k+z4b3O g==; X-CSE-ConnectionGUID: C4T5QsyCQjuClPuuv2vcgQ== X-CSE-MsgGUID: jEJgo2BYTlq9JjAx3JOYQA== X-IronPort-AV: E=McAfee;i="6600,9927,11069"; a="11627531" X-IronPort-AV: E=Sophos;i="6.08,153,1712646000"; d="scan'208";a="11627531" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2024 22:42:30 -0700 X-CSE-ConnectionGUID: VuCTljLOStacenHL17qyUg== X-CSE-MsgGUID: HXAYhmDyR8mvIl/YEV5jEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,153,1712646000"; d="scan'208";a="34509707" Received: from media-frankdu-kahawai-node2.sh.intel.com ([10.67.119.123]) by orviesa003.jf.intel.com with ESMTP; 10 May 2024 22:42:28 -0700 From: Frank Du To: dev@dpdk.org Cc: ciara.loftus@intel.com Subject: [PATCH v2] net/af_xdp: fix umem map size for zero copy Date: Sat, 11 May 2024 13:26:18 +0800 Message-Id: <20240511052618.1890677-1-frank.du@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240426005128.148730-1-frank.du@intel.com> References: <20240426005128.148730-1-frank.du@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The current calculation assumes that the mbufs are contiguous. However, this assumption is incorrect when the memory spans across a huge page. Correct to directly read the size from the mempool memory chunks. Signed-off-by: Frank Du --- v2: * Add virtual contiguous detect for for multiple memhdrs. --- drivers/net/af_xdp/rte_eth_af_xdp.c | 34 ++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c index 268a130c49..7456108d6d 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -1039,16 +1039,35 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused, } #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG) -static inline uintptr_t get_base_addr(struct rte_mempool *mp, uint64_t *align) +static inline uintptr_t get_memhdr_info(struct rte_mempool *mp, uint64_t *align, size_t *len) { - struct rte_mempool_memhdr *memhdr; + struct rte_mempool_memhdr *memhdr, *next; uintptr_t memhdr_addr, aligned_addr; + size_t memhdr_len = 0; + /* get the mempool base addr and align */ memhdr = STAILQ_FIRST(&mp->mem_list); memhdr_addr = (uintptr_t)memhdr->addr; aligned_addr = memhdr_addr & ~(getpagesize() - 1); *align = memhdr_addr - aligned_addr; + memhdr_len += memhdr->len; + + /* check if virtual contiguous memory for multiple memhdrs */ + next = STAILQ_NEXT(memhdr, next); + while (next != NULL) { + if ((uintptr_t)next->addr != (uintptr_t)memhdr->addr + memhdr->len) { + AF_XDP_LOG(ERR, "memory chunks not virtual contiguous, " + "next: %p, cur: %p(len: %" PRId64 " )\n", + next->addr, memhdr->addr, memhdr->len); + return 0; + } + /* virtual contiguous */ + memhdr = next; + memhdr_len += memhdr->len; + next = STAILQ_NEXT(memhdr, next); + } + *len = memhdr_len; return aligned_addr; } @@ -1125,6 +1144,7 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals, void *base_addr = NULL; struct rte_mempool *mb_pool = rxq->mb_pool; uint64_t umem_size, align = 0; + size_t len = 0; if (internals->shared_umem) { if (get_shared_umem(rxq, internals->if_name, &umem) < 0) @@ -1156,10 +1176,12 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals, } umem->mb_pool = mb_pool; - base_addr = (void *)get_base_addr(mb_pool, &align); - umem_size = (uint64_t)mb_pool->populated_size * - (uint64_t)usr_config.frame_size + - align; + base_addr = (void *)get_memhdr_info(mb_pool, &align, &len); + if (!base_addr) { + AF_XDP_LOG(ERR, "Failed to parse memhdr info from pool\n"); + goto err; + } + umem_size = (uint64_t)len + align; ret = xsk_umem__create(&umem->umem, base_addr, umem_size, &rxq->fq, &rxq->cq, &usr_config); -- 2.34.1