From: Frank Du <frank.du@intel.com>
To: dev@dpdk.org
Cc: ciara.loftus@intel.com, ferruh.yigit@amd.com, mb@smartsharesystems.com
Subject: [PATCH v5] net/af_xdp: parse umem map info from mempool range api
Date: Thu, 20 Jun 2024 11:25:23 +0800 [thread overview]
Message-ID: <20240620032523.440117-1-frank.du@intel.com> (raw)
In-Reply-To: <20240426005128.148730-1-frank.du@intel.com>
The current calculation assumes that the mbufs are contiguous. However,
this assumption is incorrect when the mbuf memory spans across huge page.
Correct to directly read with mempool get range API.
Fixes: d8a210774e1d ("net/af_xdp: support unaligned umem chunks")
Cc: stable@dpdk.org
Signed-off-by: Frank Du <frank.du@intel.com>
---
v2:
* Add virtual contiguous detect for for multiple memhdrs
v3:
* Use RTE_ALIGN_FLOOR to get the aligned addr
* Add check on the first memhdr of memory chunks
v4:
* Replace the iterating with simple nb_mem_chunks check
v5:
* Use rte_mempool_get_mem_range to query the mempool range
---
drivers/net/af_xdp/rte_eth_af_xdp.c | 42 ++++++++++++++---------------
1 file changed, 20 insertions(+), 22 deletions(-)
diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 4b282adb03..0bc0d9a55a 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -1067,19 +1067,6 @@ 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)
-{
- struct rte_mempool_memhdr *memhdr;
- uintptr_t memhdr_addr, aligned_addr;
-
- memhdr = STAILQ_FIRST(&mp->mem_list);
- memhdr_addr = (uintptr_t)memhdr->addr;
- aligned_addr = memhdr_addr & ~(getpagesize() - 1);
- *align = memhdr_addr - aligned_addr;
-
- return aligned_addr;
-}
-
/* Check if the netdev,qid context already exists */
static inline bool
ctx_exists(struct pkt_rx_queue *rxq, const char *ifname,
@@ -1150,9 +1137,10 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
.fill_size = ETH_AF_XDP_DFLT_NUM_DESCS * 2,
.comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
.flags = XDP_UMEM_UNALIGNED_CHUNK_FLAG};
- void *base_addr = NULL;
struct rte_mempool *mb_pool = rxq->mb_pool;
- uint64_t umem_size, align = 0;
+ void *aligned_addr;
+ uint64_t umem_size;
+ struct rte_mempool_mem_range_info range;
if (internals->shared_umem) {
if (get_shared_umem(rxq, internals->if_name, &umem) < 0)
@@ -1184,19 +1172,29 @@ 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;
-
- ret = xsk_umem__create(&umem->umem, base_addr, umem_size,
+ ret = rte_mempool_get_mem_range(mb_pool, &range);
+ if (ret < 0) {
+ AF_XDP_LOG(ERR, "Failed(%d) to get range from mempool\n", ret);
+ goto err;
+ }
+ if (!range.is_contiguous) {
+ AF_XDP_LOG(ERR, "Can't mapped to umem as mempool is not contiguous\n");
+ goto err;
+ }
+ /*
+ * umem requires the memory area be page aligned, safe to map with a large area as
+ * the memory pointer for each XSK TX/RX descriptor is derived from mbuf data area.
+ */
+ aligned_addr = (void *)RTE_ALIGN_FLOOR((uintptr_t)range.start, getpagesize());
+ umem_size = range.length + RTE_PTR_DIFF(range.start, aligned_addr);
+ ret = xsk_umem__create(&umem->umem, aligned_addr, umem_size,
&rxq->fq, &rxq->cq, &usr_config);
if (ret) {
AF_XDP_LOG(ERR, "Failed to create umem [%d]: [%s]\n",
errno, strerror(errno));
goto err;
}
- umem->buffer = base_addr;
+ umem->buffer = aligned_addr;
if (internals->shared_umem) {
umem->max_xsks = mb_pool->populated_size /
--
2.34.1
next prev parent reply other threads:[~2024-06-20 3:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 0:51 [PATCH] net/af_xdp: fix umem map size for zero copy Frank Du
2024-04-26 10:43 ` Loftus, Ciara
2024-04-28 0:46 ` Du, Frank
2024-04-30 9:22 ` Loftus, Ciara
2024-05-11 5:26 ` [PATCH v2] " Frank Du
2024-05-17 13:19 ` Loftus, Ciara
2024-05-20 1:28 ` Du, Frank
2024-05-21 15:43 ` Ferruh Yigit
2024-05-21 17:57 ` Ferruh Yigit
2024-05-22 1:25 ` Du, Frank
2024-05-22 7:26 ` Morten Brørup
2024-05-22 10:20 ` Ferruh Yigit
2024-05-23 6:56 ` Du, Frank
2024-05-23 7:40 ` Morten Brørup
2024-05-23 7:56 ` Du, Frank
2024-05-29 12:57 ` Loftus, Ciara
2024-05-29 14:16 ` Morten Brørup
2024-05-22 10:00 ` Ferruh Yigit
2024-05-22 11:03 ` Morten Brørup
2024-05-22 14:05 ` Ferruh Yigit
2024-05-23 6:53 ` [PATCH v3] " Frank Du
2024-05-23 8:07 ` [PATCH v4] " Frank Du
2024-05-23 9:22 ` Morten Brørup
2024-05-23 13:31 ` Ferruh Yigit
2024-05-24 1:05 ` Du, Frank
2024-05-24 5:30 ` Morten Brørup
2024-06-20 3:25 ` Frank Du [this message]
2024-06-20 7:10 ` [PATCH v5] net/af_xdp: parse umem map info from mempool range api Morten Brørup
2024-07-06 3:40 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240620032523.440117-1-frank.du@intel.com \
--to=frank.du@intel.com \
--cc=ciara.loftus@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=mb@smartsharesystems.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).