From: Stephen Hemminger <stephen@networkplumber.org>
To: Ariel Otilibili <ariel.otilibili@6wind.com>
Cc: dev@dpdk.org, stable@dpdk.org,
Thomas Monjalon <thomas@monjalon.net>,
David Marchand <david.marchand@redhat.com>,
Ciara Loftus <ciara.loftus@intel.com>,
Maryam Tahhan <mtahhan@redhat.com>
Subject: Re: [PATCH 2/2] net/af_xdp: Refactor af_xdp_tx_zc()
Date: Thu, 16 Jan 2025 13:47:46 -0800 [thread overview]
Message-ID: <20250116134746.2c0b1a7e@hermes.local> (raw)
In-Reply-To: <20250116195640.68885-3-ariel.otilibili@6wind.com>
On Thu, 16 Jan 2025 20:56:39 +0100
Ariel Otilibili <ariel.otilibili@6wind.com> wrote:
> Both branches of the loop share the same logic. Now each one is a
> goto dispatcher; either to out (end of function), or to
> stats (continuation of the loop).
>
> Bugzilla ID: 1440
> Depends-on: patch-1 ("net/af_xdp: fix use after free in af_xdp_tx_zc()")
> Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>
> ---
> drivers/net/af_xdp/rte_eth_af_xdp.c | 57 ++++++++++++++---------------
> 1 file changed, 27 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
> index 4326a29f7042..8b42704b6d9f 100644
> --- a/drivers/net/af_xdp/rte_eth_af_xdp.c
> +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
> @@ -551,6 +551,7 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> uint64_t addr, offset;
> struct xsk_ring_cons *cq = &txq->pair->cq;
> uint32_t free_thresh = cq->size >> 1;
> + struct rte_mbuf *local_mbuf = NULL;
>
> if (xsk_cons_nb_avail(cq, free_thresh) >= free_thresh)
> pull_umem_cq(umem, XSK_RING_CONS__DEFAULT_NUM_DESCS, cq);
> @@ -565,21 +566,10 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> &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;
> - tx_bytes += mbuf->pkt_len;
> - count++;
> +
> + goto stats;
> } else {
> - struct rte_mbuf *local_mbuf =
> - rte_pktmbuf_alloc(umem->mb_pool);
> - void *pkt;
> + local_mbuf = rte_pktmbuf_alloc(umem->mb_pool);
>
> if (local_mbuf == NULL)
> goto out;
> @@ -589,23 +579,30 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> 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;
> - rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
> - desc->len);
> - tx_bytes += mbuf->pkt_len;
> - rte_pktmbuf_free(mbuf);
> - count++;
> + goto stats;
> }
> +stats:
> + struct rte_mbuf *tmp;
> + void *pkt;
> + tmp = mbuf->pool == umem->mb_pool ? mbuf : local_mbuf;
> +
> + desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx);
> + desc->len = mbuf->pkt_len;
> +
> + addr = (uint64_t)tmp - (uint64_t)umem->buffer - umem->mb_pool->header_size;
> + offset = rte_pktmbuf_mtod(tmp, uint64_t) - (uint64_t)tmp + umem->mb_pool->header_size;
> + offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT;
> + desc->addr = addr | offset;
> +
> + if (mbuf->pool == umem->mb_pool) {
> + tx_bytes += mbuf->pkt_len;
> + } else {
> + pkt = xsk_umem__get_data(umem->buffer, addr + offset);
> + rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), desc->len);
> + tx_bytes += mbuf->pkt_len;
> + rte_pktmbuf_free(mbuf);
> + }
> + count++;
> }
>
> out:
Indentation here is wrong, and looks suspect.
Either stats tag should be outside of loop
Or stats is inside loop, and both of those goto's are unnecessary
next prev parent reply other threads:[~2025-01-16 21:48 UTC|newest]
Thread overview: 67+ 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 [this message]
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 ` [PATCH v4 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-01-30 23:55 ` Stephen Hemminger
2025-01-31 18:36 ` Ariel Otilibili
2025-01-31 18:34 ` [PATCH v5 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-01-31 18:34 ` [PATCH v5 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-01-31 18:34 ` [PATCH v5 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-01-31 23:10 ` [PATCH v6 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-01-31 23:10 ` [PATCH v6 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-01-31 23:10 ` [PATCH v6 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-02-24 19:25 ` Stephen Hemminger
2025-02-26 20:12 ` Ariel Otilibili
2025-02-01 10:02 ` [PATCH v7 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-02-01 10:02 ` [PATCH v7 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-02-01 10:03 ` [PATCH v7 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-02-04 13:39 ` Maryam Tahhan
2025-02-06 1:09 ` Maryam Tahhan
2025-02-06 1:17 ` Maryam Tahhan
2025-02-06 18:06 ` Ariel Otilibili
2025-02-06 2:08 ` Maryam Tahhan
2025-02-06 17:56 ` Ariel Otilibili
2025-02-06 20:46 ` [PATCH v8 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-02-06 20:46 ` [PATCH v8 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-02-06 20:46 ` [PATCH v8 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-02-06 21:42 ` Stephen Hemminger
2025-02-07 9:18 ` Maryam Tahhan
2025-02-07 7:09 ` Maryam Tahhan
2025-02-07 10:48 ` Ariel Otilibili
2025-02-07 10:45 ` [PATCH v9 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-02-07 10:45 ` [PATCH v9 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-02-07 10:45 ` [PATCH v9 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-02-07 11:13 ` Maryam Tahhan
2025-02-07 12:33 ` Ariel Otilibili
2025-02-13 11:17 ` Ariel Otilibili
2025-02-13 17:04 ` Stephen Hemminger
2025-02-19 13:25 ` Maryam Tahhan
2025-02-23 21:52 ` [PATCH v10 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-02-23 21:52 ` [PATCH v10 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-02-23 21:52 ` [PATCH v10 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-02-26 19:55 ` [PATCH v11 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-02-26 19:55 ` [PATCH v11 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-02-26 19:55 ` [PATCH v11 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
2025-02-26 20:08 ` [PATCH v12 0/2] Fix use after free, and refactor af_xdp_tx_zc Ariel Otilibili
2025-02-26 20:08 ` [PATCH v12 1/2] net/af_xdp: Fix use after free in af_xdp_tx_zc Ariel Otilibili
2025-02-26 20:08 ` [PATCH v12 2/2] net/af_xdp: Refactor af_xdp_tx_zc Ariel Otilibili
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=20250116134746.2c0b1a7e@hermes.local \
--to=stephen@networkplumber.org \
--cc=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=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).