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 C35F8460A8; Thu, 16 Jan 2025 22:48:10 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ADDAB40ED4; Thu, 16 Jan 2025 22:47:52 +0100 (CET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id 1543140ED0 for ; Thu, 16 Jan 2025 22:47:50 +0100 (CET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2162c0f6a39so50284115ad.0 for ; Thu, 16 Jan 2025 13:47:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737064070; x=1737668870; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=r2bkkyzjdsNDBGKe/JlN4221WI2Adi1Xi10kV5a6NKs=; b=bgSP9rGSMl5y+BLvoDMJZ5ZkavcQM3Rr4YUaRcEKeZNhrJducHB/r0YN8ExrM2Ex/o ifF4nOR8xfVojwaWE1FLT2f5fIAl5pwKfFmlGRyTGNbHj02pYbedwodfT1L3eBAyCbWw tdOxOgKYOZl0TShnnceSSyAxxqV6wKijr+24GHzEy1QrFJHwrCKaAfe+5clNVnnkYF/9 to+BQ38tsXVUMXjysXGH3cZ7nYiya45YDoDkKxOburiXrXmt8eYn1Etbc5S9LwL1TUvp wadqN5AJAooxNoEYi8HTJI5LzM1k8eoUDGuxLX9eWB3b5lWQbOef8w/fQSjwYWfhQhwW l8oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737064070; x=1737668870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r2bkkyzjdsNDBGKe/JlN4221WI2Adi1Xi10kV5a6NKs=; b=nANYobSe8E7gc1hBV1jgd6b0MKF+yRwTRRZk6baTM7Ri0vZBEs7DGTQAKqtXRTGrVL Sj4XKXDG2pVT95IpWR3U/Hl1R+MS2H/8p4Qy9BxbGLWVRE4B/K6Ncj8kfxwXa1SUX0a+ aspNhQToyUV7XAo3nse6X+vgYtcwZQ1/1T5A1u7ofIg/8VYtWYauWaSft3H4K9YAWWw1 +uYNptVHnSd8uvmIhYYZoZxT8Gbyqt7dczfQB7il5WefEEEifaS9hAi3kleG1Pl1PA7n n6nfnMkZ+7CwRqK+UfFokmd1sl8VsTimQ2UVx0JvZLZzODvbrcCgwUI4doPwKg8i2dR7 mL4g== X-Gm-Message-State: AOJu0Yz4+5RGF8kpsQwnmgu+6enEzcR5RgLxAqkZg5zNMXmgpibJMkTl cQ2p7nRUCDK2QBpPwdC13FtJegi9Le5fYsqMvXGlKdq811kscto7Yd2lHhE10Ug= X-Gm-Gg: ASbGncspGBdOc73nhsFJjDDHILlSaNAwWHClapGcmLmOCr/xkRgn1+txLdbMbkkXv3d d9G2HNn8QlNyoh6JbCegGS0hOa0zQtm/m5wvTt3rHZQ+yPZw9UgkPcnb3C/ISTqtXkgOFveOASi XJQEm1N64cKYoxwlRN0bNqtkwwZ8g8AutvFWlW7XNYdXNOJNqW5smAOhyr299/cVfDNrRNq+X+R +prrFQuDNNMg7gHBg6DfVdOxK7nwb+/gJlFC0NiBZ35KrosHzYjdiN7O8BLWGqtyXRJVfZGn3cV UfVtrr1xA/bKPaz6lfbi+btKOCWFkihmxg== X-Google-Smtp-Source: AGHT+IG3SiHRJoBwtmr1+W+aGVlzKWAMvRTOOBBYdgf2KtsMKDB6KUPpQKSPyxCzv/tp42tHOO55aA== X-Received: by 2002:a05:6a20:7495:b0:1d9:a94:feec with SMTP id adf61e73a8af0-1eb215cf0a2mr245673637.2.1737064069824; Thu, 16 Jan 2025 13:47:49 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab9d5335sm464268b3a.110.2025.01.16.13.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 13:47:49 -0800 (PST) Date: Thu, 16 Jan 2025 13:47:46 -0800 From: Stephen Hemminger To: Ariel Otilibili Cc: dev@dpdk.org, stable@dpdk.org, Thomas Monjalon , David Marchand , Ciara Loftus , Maryam Tahhan Subject: Re: [PATCH 2/2] net/af_xdp: Refactor af_xdp_tx_zc() Message-ID: <20250116134746.2c0b1a7e@hermes.local> In-Reply-To: <20250116195640.68885-3-ariel.otilibili@6wind.com> References: <20250116195640.68885-1-ariel.otilibili@6wind.com> <20250116195640.68885-3-ariel.otilibili@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Thu, 16 Jan 2025 20:56:39 +0100 Ariel Otilibili 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 > --- > 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