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 37C68460A5; Thu, 16 Jan 2025 23:27:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D0AC840ED0; Thu, 16 Jan 2025 23:26:44 +0100 (CET) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 6B48E40696 for ; Thu, 16 Jan 2025 23:26:43 +0100 (CET) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-21a7ed0155cso23038955ad.3 for ; Thu, 16 Jan 2025 14:26:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737066402; x=1737671202; 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=g1o7x5mwdBhtJmhhBfka/25lCvnPU2yppg5Z60novuI=; b=yfG0RKT9kvp/Gw19IpuSoOExDfoLd+kwfNt8lehblFObiT50d+OFBfgt3Gr6fpzmh9 S1cdpERm3Mzs/0P4KXNKjPX/kTy4ES061NW1MWGslwt/xY/xhi37QYTAWPrVbSB3ceAJ IUGaPz4GUYRtVwC5IMaknRpqe+q5Oy0fA9TRsxcvvNAhIyaQboW2aSn6FK3otKFQjAiG +VPa8+kVBynaleTWVeJ05xvMC4wj2QSLWupZeCgylMGCcmHuxxDPDQHNl7sjdQjmhMye U9wXOMUJWdBxrVyGjvlbmZl9LghNvWZ9nTNguQacsBEWTpOLVYIiKccYkUnL1EOO7s+r ZJjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737066402; x=1737671202; 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=g1o7x5mwdBhtJmhhBfka/25lCvnPU2yppg5Z60novuI=; b=OS2J7o6fq1y2usXBOGnNmipqClLtsLWqi2os730jFktefggJoSUc7UAnz/Y1axIACP RSV1Bgk8jEg9Sqh6DzYbEW0fmdGvB9+lNYlRSPftRmDAuUbrMPx2W7fzO5C1iQLYRao2 XAC76LmOkd/U8I3/VSaavAds6J0OiXV6rANTLrhiO+TQLD0yw3ui4QU3fox0vosH5RPU YS/xH6INknkYL40vfbET6icUhFurIYqhhe2rLmtUNHiIvqFQ4MbuLEeFlJHJgHLqFXs5 1tNt5WS4pWLpDLKNTWHdTA15BFZGN59kvhF5CXCt0VlPUNcn8eoND00occoAqiyqmza1 u1fA== X-Gm-Message-State: AOJu0YypwiAE65DOb/PT1PxY8qttff18CgQhuSlqQ4MPAdr6U7/ZXNC7 j4s2514xaeI0v4mEd8Sv/2daqciccx4msIUPHHe4kFTKsEPGa++DwTH9pzoKCcs= X-Gm-Gg: ASbGncuOKnNw8iW1zhDuh45+84DdBbNtALeJwe6F8P856a+J14Ap9HOFkCZ53VqyyUu TRdeGzNqe935r3bNEQ+7qI/jNBbxJpyEB2pezPWbZrT1SPTkmCJzU0TdoZh0wFGQXZu12iI8lVo ml/5/OR67Uq9IcT1Dk4mKiiFiNuZtQrAw3yMVN4pbEV+E5N5Pb606x2ZEmYjNsGdtBVc23N1nQ2 rzwAhvHmivmvY8HxaUYXaTO+BimbxFejigB5o7sUBDGVe4d1CWsYfCJd3donJyBx7m15OvRxgl5 HP/yJOLFBca1hqncHoJxrS0NvlIOzGPV1A== X-Google-Smtp-Source: AGHT+IHHdKSELv9Uu9Z1VquIh8DD2HOxuoJ0nuI3FEsCMFIcTNkOTnAylq0191xt6klK4Jyo/FaCTA== X-Received: by 2002:a05:6a20:12c2:b0:1e1:ffec:b1bf with SMTP id adf61e73a8af0-1eb2159bf90mr403027637.26.1737066402337; Thu, 16 Jan 2025 14:26:42 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab7f3025sm533177b3a.12.2025.01.16.14.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 14:26:42 -0800 (PST) Date: Thu, 16 Jan 2025 14:26:40 -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: <20250116142640.26391bf0@hermes.local> In-Reply-To: References: <20250116195640.68885-1-ariel.otilibili@6wind.com> <20250116195640.68885-3-ariel.otilibili@6wind.com> <20250116134746.2c0b1a7e@hermes.local> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 23:20:06 +0100 Ariel Otilibili wrote: > Hi Stephen, >=20 > On Thu, Jan 16, 2025 at 10:47=E2=80=AFPM Stephen Hemminger < > stephen@networkplumber.org> wrote: =20 >=20 > > On Thu, 16 Jan 2025 20:56:39 +0100 > > Ariel Otilibili wrote: > > =20 > > > 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 =20 > > b/drivers/net/af_xdp/rte_eth_af_xdp.c =20 > > > 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,= =20 > > uint16_t nb_pkts) =20 > > > uint64_t addr, offset; > > > struct xsk_ring_cons *cq =3D &txq->pair->cq; > > > uint32_t free_thresh =3D cq->size >> 1; > > > + struct rte_mbuf *local_mbuf =3D NULL; > > > > > > if (xsk_cons_nb_avail(cq, free_thresh) >=3D 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 **buf= s, =20 > > uint16_t nb_pkts) =20 > > > &idx_tx)) > > > goto out; > > > } > > > - desc =3D xsk_ring_prod__tx_desc(&txq->tx, idx_t= x); > > > - desc->len =3D mbuf->pkt_len; > > > - addr =3D (uint64_t)mbuf - (uint64_t)umem->buffe= r - > > > - umem->mb_pool->header_size; > > > - offset =3D rte_pktmbuf_mtod(mbuf, uint64_t) - > > > - (uint64_t)mbuf + > > > - umem->mb_pool->header_size; > > > - offset =3D offset << XSK_UNALIGNED_BUF_OFFSET_S= HIFT; > > > - desc->addr =3D addr | offset; > > > - tx_bytes +=3D mbuf->pkt_len; > > > - count++; > > > + > > > + goto stats; > > > } else { > > > - struct rte_mbuf *local_mbuf =3D > > > - rte_pktmbuf_alloc(umem->mb_pool= ); > > > - void *pkt; > > > + local_mbuf =3D rte_pktmbuf_alloc(umem->mb_pool); > > > > > > if (local_mbuf =3D=3D NULL) > > > goto out; > > > @@ -589,23 +579,30 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **buf= s, =20 > > uint16_t nb_pkts) =20 > > > goto out; > > > } > > > > > > - desc =3D xsk_ring_prod__tx_desc(&txq->tx, idx_t= x); > > > - desc->len =3D mbuf->pkt_len; > > > - > > > - addr =3D (uint64_t)local_mbuf - =20 > > (uint64_t)umem->buffer - =20 > > > - umem->mb_pool->header_size; > > > - offset =3D rte_pktmbuf_mtod(local_mbuf, uint64_= t) - > > > - (uint64_t)local_mbuf + > > > - umem->mb_pool->header_size; > > > - pkt =3D xsk_umem__get_data(umem->buffer, addr += =20 > > offset); =20 > > > - offset =3D offset << XSK_UNALIGNED_BUF_OFFSET_S= HIFT; > > > - desc->addr =3D addr | offset; > > > - rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), > > > - desc->len); > > > - tx_bytes +=3D mbuf->pkt_len; > > > - rte_pktmbuf_free(mbuf); > > > - count++; > > > + goto stats; > > > } > > > +stats: > > > + struct rte_mbuf *tmp; > > > + void *pkt; > > > + tmp =3D mbuf->pool =3D=3D umem->mb_pool ? mbuf : local_mbuf; > > > + > > > + desc =3D xsk_ring_prod__tx_desc(&txq->tx, idx_tx); > > > + desc->len =3D mbuf->pkt_len; > > > + > > > + addr =3D (uint64_t)tmp - (uint64_t)umem->buffer - =20 > > umem->mb_pool->header_size; =20 > > > + offset =3D rte_pktmbuf_mtod(tmp, uint64_t) - (uint64_t)tmp + =20 > > umem->mb_pool->header_size; =20 > > > + offset =3D offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; > > > + desc->addr =3D addr | offset; > > > + > > > + if (mbuf->pool =3D=3D umem->mb_pool) { > > > + tx_bytes +=3D mbuf->pkt_len; > > > + } else { > > > + pkt =3D xsk_umem__get_data(umem->buffer, addr + offset); > > > + rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), desc->l= en); > > > + tx_bytes +=3D mbuf->pkt_len; > > > + rte_pktmbuf_free(mbuf); > > > + } > > > + count++; > > > } > > > > > > out: =20 > > > > 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 > > =20 > Thanks for the feedback; I am pushing a new series with an extra tab. > So it be obvious that stats belongs to the the loop. But the the goto;s aren't needed? Both legs of the If would fall through to that location.