<div dir="auto"><div><br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat 1 Feb 2025, 10:03 Ariel Otilibili, <<a href="mailto:ariel.otilibili@6wind.com">ariel.otilibili@6wind.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Both legs of the loop share the same logic: the common parts are about<br>
reserving and filling both address and length into the description.<br>
<br>
This is moved into reserve_and_fill().<br>
<br>
Bugzilla ID: 1440<br>
Suggested-by: Maryam Tahhan <<a href="mailto:mtahhan@redhat.com" target="_blank" rel="noreferrer">mtahhan@redhat.com</a>><br>
Signed-off-by: Ariel Otilibili <<a href="mailto:ariel.otilibili@6wind.com" target="_blank" rel="noreferrer">ariel.otilibili@6wind.com</a>><br>
---<br>
drivers/net/af_xdp/rte_eth_af_xdp.c | 62 ++++++++++++++++-------------<br>
1 file changed, 34 insertions(+), 28 deletions(-)<br>
<br>
diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c<br>
index 092bcb73aa0a..840a12dbf508 100644<br>
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c<br>
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c<br>
@@ -536,6 +536,31 @@ kick_tx(struct pkt_tx_queue *txq, struct xsk_ring_cons *cq)<br>
}<br>
}<br>
<br>
+static inline struct xdp_desc *<br>
+reserve_and_fill(struct pkt_tx_queue *txq, struct rte_mbuf *mbuf,<br>
+ struct xsk_umem_info *umem)<br>
+{<br>
+ struct xdp_desc *desc = NULL;<br>
+ uint32_t *idx_tx = NULL;<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Took me a while to spot this but this needs to be a uint32_t not a pointer to uint32_t, because xsk_ring_prod__reserve() does not allocate memory for idx_tx it just expects to dereference a pointer to a uint32_t to store the index...</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ uint64_t addr, offset;<br>
+<br>
+ if (!xsk_ring_prod__reserve(&txq->tx, 1, idx_tx))<br>
+ goto out;<br>
+<br>
+ desc = xsk_ring_prod__tx_desc(&txq->tx, *idx_tx);<br>
+ desc->len = mbuf->pkt_len;<br>
+<br>
+ addr = (uint64_t)mbuf - (uint64_t)umem->buffer<br>
+ - umem->mb_pool->header_size;<br>
+ offset = rte_pktmbuf_mtod(mbuf, uint64_t) - (uint64_t)mbuf<br>
+ + umem->mb_pool->header_size;<br>
+ offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT;<br>
+ desc->addr = addr | offset;<br>
+<br>
+out:<br>
+ return desc;<br>
+}<br>
+<br><snip></blockquote></div></div></div>