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 3659B460A4 for ; 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 A944840EF0; Thu, 16 Jan 2025 23:26:45 +0100 (CET) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 6CB0C40ED0 for ; Thu, 16 Jan 2025 23:26:43 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21680814d42so23472755ad.2 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=vhdEWv36JSHzxRgQXIFhvS28LxcOf/2V7UnmCdpwneoe1Iy1ihZbfCv7VlS6Q5GcpS 46rmbEU/xPwSNlUiCJY6pCutmxmKYn1rLHt6vT5tU0ba56cWwT2MA0+EXtuBoir05Hrg UVhVUoZw9OTtYiIFPtnRAbRCWzsLVFrG8YaRzNrEHjlZJbTsNinXxCyekaH37MJtaJ5t u/8szYUhEuF1Ke7Aemes1udJnL1a9O3ouWIiyPIrC26eNtm+t0nFZgaxAOZKGBjKeynY H3yvOYAsxVow1M5YCNi3N2AXvgOuDaV0uNm1qjZMIiYNh0nEtqpuZIpSRWN6adZHONqz RvmA== X-Forwarded-Encrypted: i=1; AJvYcCXp+Oor7tlsW+/UCgYd8Lh9wn7iawFfMgX+deZaMw9koRjChY3WUWzSoD51vBIGvq1YIT+1NDI=@dpdk.org X-Gm-Message-State: AOJu0YxYckSFvjspKufviQLpYOkegcHAxGtsPeXkQena6fK8fT4cO/sd /lGn3uP2JmuH1KR14tp4yjic7QoqIz5T0o6rKAECD2e3mveQga4/iA3gAeqT+m0= X-Gm-Gg: ASbGncvEFpdc1yCch1H5z/+rQLkPzc21aSwwGwx95/EiBEl5E49DIIBTVpeBnYOvUE0 BwBUBvQQshsag4fMdFykl3vGqTTQXE8InBc/Yn0oil+UvSrSnAL73c7RDcCQDR/7ICLcoLCy3RG pIcUXOWA9Y+8/fQ6Z0/EV02mGC8QMoWys3eSBRPBo/jFSmkmns90L/IW4lsNb4soYzk0ETdz3Rj O+Qda+aQ5kijPfwJPVA/b/bztc5HPvUesN3iqQ1w9S/s8S0DbjEOr8fdOLkA2YX0szojt1LbmfD d/zBozhSVKYZhbsHLauv0Y43r1QdYjCXkQ== 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: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-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.