From: Ariel Otilibili <ariel.otilibili@6wind.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, Thomas Monjalon <thomas@monjalon.net>,
David Marchand <david.marchand@redhat.com>,
Ariel Otilibili <ariel.otilibili@6wind.com>,
Ciara Loftus <ciara.loftus@intel.com>,
Maryam Tahhan <mtahhan@redhat.com>,
Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH v4 2/2] net/af_xdp: Refactor af_xdp_tx_zc
Date: Thu, 30 Jan 2025 23:18:53 +0100 [thread overview]
Message-ID: <20250130221853.789366-3-ariel.otilibili@6wind.com> (raw)
In-Reply-To: <20250130221853.789366-1-ariel.otilibili@6wind.com>
Both legs of the loop share the same logic: the common parts are about
reserving and filling both address and length into the description.
This is moved into reserve_and_fill().
Bugzilla ID: 1440
Suggested-by: Maryam Tahhan <mtahhan@redhat.com>
Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>
---
drivers/net/af_xdp/rte_eth_af_xdp.c | 62 ++++++++++++++++-------------
1 file changed, 34 insertions(+), 28 deletions(-)
diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 092bcb73aa0a..3f5de4d9cbda 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -536,6 +536,31 @@ kick_tx(struct pkt_tx_queue *txq, struct xsk_ring_cons *cq)
}
}
+static inline struct xdp_desc*
+reserve_and_fill(struct pkt_tx_queue *txq, struct rte_mbuf *mbuf,
+ struct xsk_umem_info *umem)
+{
+ struct xdp_desc *desc = NULL;
+ uint32_t *idx_tx = NULL;
+ uint64_t addr, offset;
+
+ if (!xsk_ring_prod__reserve(&txq->tx, 1, idx_tx))
+ goto out;
+
+ desc = xsk_ring_prod__tx_desc(&txq->tx, *idx_tx);
+ desc->len = mbuf->pkt_len;
+
+ addr = (uint64_t)mbuf - (uint64_t)umem->buffer
+ - umem->mb_pool->header_size;
+ offset = rte_pktmbuf_mtod(mbuf, uint64_t) - (uint64_t)mbuf
+ + umem->mb_pool->header_size;
+ offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT;
+ desc->addr = addr | offset;
+
+out:
+ return desc;
+}
+
#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
static uint16_t
af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
@@ -545,10 +570,8 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
struct rte_mbuf *mbuf;
unsigned long tx_bytes = 0;
int i;
- uint32_t idx_tx;
uint16_t count = 0;
struct xdp_desc *desc;
- uint64_t addr, offset;
struct xsk_ring_cons *cq = &txq->pair->cq;
uint32_t free_thresh = cq->size >> 1;
@@ -559,21 +582,12 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
mbuf = bufs[i];
if (mbuf->pool == umem->mb_pool) {
- if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) {
+ if (!(desc = reserve_and_fill(txq, mbuf, umem))) {
kick_tx(txq, cq);
- if (!xsk_ring_prod__reserve(&txq->tx, 1,
- &idx_tx))
+ if (!(desc = reserve_and_fill(txq, mbuf, umem)))
goto out;
}
- desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx);
- desc->len = mbuf->pkt_len;
- addr = (uint64_t)mbuf - (uint64_t)umem->buffer -
- umem->mb_pool->header_size;
- offset = rte_pktmbuf_mtod(mbuf, uint64_t) -
- (uint64_t)mbuf +
- umem->mb_pool->header_size;
- offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT;
- desc->addr = addr | offset;
+
tx_bytes += desc->len;
count++;
} else {
@@ -584,26 +598,18 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
if (local_mbuf == NULL)
goto out;
- if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) {
+ if (!(desc = reserve_and_fill(txq, local_mbuf, umem))) {
rte_pktmbuf_free(local_mbuf);
goto out;
}
- desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx);
- desc->len = mbuf->pkt_len;
-
- addr = (uint64_t)local_mbuf - (uint64_t)umem->buffer -
- umem->mb_pool->header_size;
- offset = rte_pktmbuf_mtod(local_mbuf, uint64_t) -
- (uint64_t)local_mbuf +
- umem->mb_pool->header_size;
- pkt = xsk_umem__get_data(umem->buffer, addr + offset);
- offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT;
- desc->addr = addr | offset;
+ pkt = xsk_umem__get_data(umem->buffer,
+ (desc->addr & ~0xFFF)
+ + (desc->addr & 0xFFF));
rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
- desc->len);
- tx_bytes += desc->len;
+ desc->len);
rte_pktmbuf_free(mbuf);
+ tx_bytes += desc->len;
count++;
}
}
--
2.30.2
next prev parent reply other threads:[~2025-01-30 22:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 19:56 [PATCH 0/2] Fix use after free, and refactor af_xdp_tx_zc() Ariel Otilibili
2025-01-16 19:56 ` [PATCH 1/2] net/af_xdp: fix use after free in af_xdp_tx_zc() Ariel Otilibili
2025-01-30 18:24 ` Stephen Hemminger
2025-01-30 22:22 ` Ariel Otilibili
2025-01-16 19:56 ` [PATCH 2/2] net/af_xdp: Refactor af_xdp_tx_zc() Ariel Otilibili
2025-01-16 21:47 ` Stephen Hemminger
2025-01-16 22:20 ` Ariel Otilibili
2025-01-16 22:26 ` Stephen Hemminger
2025-01-16 22:36 ` Ariel Otilibili
2025-01-16 22:51 ` [PATCH v2 0/2] Fix use after free, and refactor af_xdp_tx_zc() Ariel Otilibili
2025-01-16 22:51 ` [PATCH v2 1/2] net/af_xdp: fix use after free in af_xdp_tx_zc() Ariel Otilibili
2025-01-20 14:54 ` Maryam Tahhan
2025-01-21 8:54 ` Ariel Otilibili
2025-01-16 22:51 ` [PATCH v2 2/2] net/af_xdp: Refactor af_xdp_tx_zc() Ariel Otilibili
2025-01-20 15:28 ` Maryam Tahhan
2025-01-21 8:57 ` Ariel Otilibili
2025-01-28 23:11 ` [PATCH v3 0/2] Fix use after free, and refactor af_xdp_tx_zc() Ariel Otilibili
2025-01-28 23:11 ` [PATCH v3 1/2] net/af_xdp: fix use after free in af_xdp_tx_zc() Ariel Otilibili
2025-01-28 23:11 ` [PATCH v3 2/2] net/af_xdp: Refactor af_xdp_tx_zc() Ariel Otilibili
2025-01-29 17:58 ` Maryam Tahhan
2025-01-30 23:06 ` Ariel Otilibili
2025-01-30 22:18 ` [PATCH v4 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-01-30 22:18 ` [PATCH v4 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-01-30 22:18 ` Ariel Otilibili [this message]
2025-01-30 23:55 ` [PATCH v4 2/2] net/af_xdp: Refactor af_xdp_tx_zc Stephen Hemminger
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=20250130221853.789366-3-ariel.otilibili@6wind.com \
--to=ariel.otilibili@6wind.com \
--cc=ciara.loftus@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=mtahhan@redhat.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/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).