From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (unknown [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 02378460A4; Thu, 16 Jan 2025 23:52:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 534BD410FA; Thu, 16 Jan 2025 23:52:02 +0100 (CET) Received: from mail-ej1-f99.google.com (mail-ej1-f99.google.com [209.85.218.99]) by mails.dpdk.org (Postfix) with ESMTP id 2D550410EA for ; Thu, 16 Jan 2025 23:52:00 +0100 (CET) Received: by mail-ej1-f99.google.com with SMTP id a640c23a62f3a-ab2bb0822a4so285368266b.3 for ; Thu, 16 Jan 2025 14:52:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1737067920; x=1737672720; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=03nC1mQTnebuTI9Y0aOnKm9tjWxSzXscSWzUGlGh1xE=; b=gSSSXS+xfyNg71xz2zVYFel9tyYzZENs7ONh8RaVoKjT2n8SFGWYFxsc+yVL0Y7G1w Wv8YeNZ50qbFlPl08RPhc5JvPRDl5MdK74PrW5kw5Lfa8LnQKvNCcRxto3HmlvdneC65 EOMY4i82L++yrc2Xo6hn3SpgBXlM6oj0MME85uazYX6iCzAiXxURzPKQZ9+ttgoxvNIQ AIt0LCqj9ZEdAUHDjfy7UUzFh4j1ICb0aEnUTnWkW5nekbx2Psae5VeNSXLa4Vh6StkV W3B9TFNHkGXHZslLL3nkR6h5fQgATn3eMJHSn/Al2vI5rxMqP35mOc7rAiqIyg6OksqL GL2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737067920; x=1737672720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=03nC1mQTnebuTI9Y0aOnKm9tjWxSzXscSWzUGlGh1xE=; b=gBKuSFLuRmB2eDh8shFsaMtkb9sG2dDI/xDPudFE5QtZ+SrpGb/nk13VyapWIf0JeN ahEhp48P5u5lMw8NKn+xo54BugLF61+cMAyU4ys5mNrwMyTnmYznjoR/eLzbuX7B4/5L MIMmIFU7IK0Tj66H2cnaOFCQwtKbyug+4iNiS/AyLqqT4QkX/+kokssmriRbh7NKtnH9 mTMn3F4XX4cHo4wvPmUA0y7AyRAgZJ9id9pyZWpnWch9FyuabZYpE6CDD7P6Hu+ptrhL xkspzM9f3ZTjYmsHKmGWmnLwUb96bV9KjFTKBNREMijjaCJj/InHdKTVHH8m/mTZn05q ykoA== X-Gm-Message-State: AOJu0Yx/vdiNdxNyXyhb7oDxhYnDXtUVWAGPLxkDRr46baTR+aDrgYVL 3fvKQjvH1WEZF/kVt44FQU7Ebp5ITf7NjhpMS2n1WvUHYmdgS7EDV1AbEzqTU4fAmqTlLsyps+D zkGKgHQTA1o5MBR0ulO6RonoS7+PkiyhLcY85W6Au X-Gm-Gg: ASbGncts4A70eA9aBoeW5R/YpvStQHKXrcChUfEnIIgvnibWNlJNhpi1xqKQCRwtJhz 2K57PwoftM+dPgrxR9mv1DqK2j70eyPtZviog/XkfKw9Na+M14SMyLsskmnm1l5V9Y57RYRrmaG cK7CBSHQbpz+GdC5/yKXTHlbYPDyt0tqI5TCzMBqFTjkbv0QsMLpwgQbmXifKonZ+cHsGTTmafq COVuoePS/TRv1GtG79YSfOp57aq0ZcTl+dNo6r1wOFnJezsXAQcUgOuKZzPVOcLtAlWYpQmmlrM Mz8gAMlF+YCOACPjwXewD0K1GA== X-Google-Smtp-Source: AGHT+IEJYr3tnJxliCS4BcpIHPkWDIcRcVUn0NRGX0K3KSZfylPdgZfNv4huSjd89xRNdmC35dcMckLez2hk X-Received: by 2002:a17:907:7ba2:b0:aa6:b63a:4521 with SMTP id a640c23a62f3a-ab38b1100cemr48605466b.15.1737067919814; Thu, 16 Jan 2025 14:51:59 -0800 (PST) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id a640c23a62f3a-ab384d87a8asm2266766b.10.2025.01.16.14.51.59; Thu, 16 Jan 2025 14:51:59 -0800 (PST) X-Relaying-Domain: 6wind.com Received: from localhost (rainbow.dev.6wind.com [10.17.1.165]) by smtpservice.6wind.com (Postfix) with ESMTP id A468911D49; Thu, 16 Jan 2025 23:51:59 +0100 (CET) From: Ariel Otilibili To: dev@dpdk.org Cc: stable@dpdk.org, Stephen Hemminger , Thomas Monjalon , David Marchand , Ariel Otilibili , Ciara Loftus , Maryam Tahhan Subject: [PATCH v2 2/2] net/af_xdp: Refactor af_xdp_tx_zc() Date: Thu, 16 Jan 2025 23:51:51 +0100 Message-Id: <20250116225151.188214-3-ariel.otilibili@6wind.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20250116225151.188214-1-ariel.otilibili@6wind.com> References: <20250116195640.68885-1-ariel.otilibili@6wind.com> <20250116225151.188214-1-ariel.otilibili@6wind.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 Both legs of the loop share the same logic: either to go out of the function, or to fall through to the next instructions. Depends-on: patch-1 ("net/af_xdp: fix use after free in af_xdp_tx_zc()") Bugzilla ID: 1440 Signed-off-by: Ariel Otilibili --- drivers/net/af_xdp/rte_eth_af_xdp.c | 47 +++++++++++++---------------- 1 file changed, 21 insertions(+), 26 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..b1de47a41eb3 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,8 @@ 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++; } 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; @@ -588,24 +576,31 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) rte_pktmbuf_free(local_mbuf); goto out; } + } - desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx); - desc->len = mbuf->pkt_len; + 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)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; + 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); - offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; - desc->addr = addr | offset; - rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), - desc->len); + rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), desc->len); tx_bytes += mbuf->pkt_len; rte_pktmbuf_free(mbuf); - count++; } + count++; } out: -- 2.30.2