From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=H6o3r8LQ; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 77BD15A026D for ; Fri, 10 Apr 2026 09:00:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775804399; bh=8ulTIKYRHcWL7Wwfz+jy5+Su+CPDa9OrWzQIWXCHV4U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H6o3r8LQPMoufaMqOVR3WqlqiZFoKQPzWugAbYdmyVnM7zepwmCRo/Wo24XZTS5ni IVhA3ztaP2sOUWRqXY5WkllxWYzqx4b4gKMCm5EdJtd43pAZxsZUITaFUhnJ/gJw+a NSXexfB9EZ+Ts0+8gwx+1V6Ad+RhDgL3UmdPRAEhTR6HYZtXvBeWT79PeywXAAnJIf +CcRPBiNXxXeNhjsDcsat/2YGVV1FPF/S919pQ61YhdY060XO0voDDd4QERsrSmKKi scQ8BIAWRHOowskivGuUbBNhqP0xX6uvjq39BZttkLNqFTwqPqAyR+e/qQvC5edZaS sny6IiJ0qMbJA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fsSNb0pcNz4wLn; Fri, 10 Apr 2026 16:59:59 +1000 (AEST) Date: Fri, 10 Apr 2026 16:59:54 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 05/10] udp_vu: Pass iov explicitly to helpers instead of using file-scoped array Message-ID: References: <20260403163811.3209635-1-lvivier@redhat.com> <20260403163811.3209635-6-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="gVH/5sne0GCqRcnZ" Content-Disposition: inline In-Reply-To: <20260403163811.3209635-6-lvivier@redhat.com> Message-ID-Hash: OZ7WITL2342Q5OMTRMRQX6OGOCRJOXMD X-Message-ID-Hash: OZ7WITL2342Q5OMTRMRQX6OGOCRJOXMD X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --gVH/5sne0GCqRcnZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 03, 2026 at 06:38:06PM +0200, Laurent Vivier wrote: > udp_vu_sock_recv(), udp_vu_prepare(), and udp_vu_csum() all operated on > the file-scoped iov_vu[] array directly. Pass iov and count as explicit > parameters instead, and move iov_vu[] and elem[] to function-local > statics in udp_vu_sock_to_tap(), the only function that needs them. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson One cosmetic nit noted. > --- > udp_vu.c | 64 +++++++++++++++++++++++++++++--------------------------- > 1 file changed, 33 insertions(+), 31 deletions(-) >=20 > diff --git a/udp_vu.c b/udp_vu.c > index 34f39e1256f8..9688fe1fdc5c 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -33,9 +33,6 @@ > #include "udp_vu.h" > #include "vu_common.h" > =20 > -static struct iovec iov_vu [VIRTQUEUE_MAX_SIZE]; > -static struct vu_virtq_element elem [VIRTQUEUE_MAX_SIZE]; > - > /** > * udp_vu_hdrlen() - Sum size of all headers, from UDP to virtio-net > * @v6: Set for IPv6 packet > @@ -58,14 +55,14 @@ static size_t udp_vu_hdrlen(bool v6) > =20 > /** > * udp_vu_sock_recv() - Receive datagrams from socket into vhost-user bu= ffers > + * @iov: IO vector for the frame (in/out) > + * @cnt: Number of IO vector entries (in/out) Nit: this new description loses some details about the value of *@cnt on output. > * @s: Socket to receive from > * @v6: Set for IPv6 connections > - * @iov_cnt: Number of collected iov in iov_vu (input) > - * Number of iov entries used to store the datagram (output) > * > * Return: size of received data, -1 on error > */ > -static ssize_t udp_vu_sock_recv(int s, bool v6, size_t *iov_cnt) > +static ssize_t udp_vu_sock_recv(struct iovec *iov, size_t *cnt, int s, b= ool v6) > { > struct msghdr msg =3D { 0 }; > size_t hdrlen, l2len; > @@ -75,27 +72,27 @@ static ssize_t udp_vu_sock_recv(int s, bool v6, size_= t *iov_cnt) > hdrlen =3D udp_vu_hdrlen(v6); > =20 > /* reserve space for the headers */ > - assert(iov_vu[0].iov_len >=3D MAX(hdrlen, ETH_ZLEN + VNET_HLEN)); > - iov_vu[0].iov_base =3D (char *)iov_vu[0].iov_base + hdrlen; > - iov_vu[0].iov_len -=3D hdrlen; > + assert(iov[0].iov_len >=3D MAX(hdrlen, ETH_ZLEN + VNET_HLEN)); > + iov[0].iov_base =3D (char *)iov[0].iov_base + hdrlen; > + iov[0].iov_len -=3D hdrlen; > =20 > /* read data from the socket */ > - msg.msg_iov =3D iov_vu; > - msg.msg_iovlen =3D *iov_cnt; > + msg.msg_iov =3D iov; > + msg.msg_iovlen =3D *cnt; > =20 > dlen =3D recvmsg(s, &msg, 0); > if (dlen < 0) > return -1; > =20 > /* restore the pointer to the headers address */ > - iov_vu[0].iov_base =3D (char *)iov_vu[0].iov_base - hdrlen; > - iov_vu[0].iov_len +=3D hdrlen; > + iov[0].iov_base =3D (char *)iov[0].iov_base - hdrlen; > + iov[0].iov_len +=3D hdrlen; > =20 > - *iov_cnt =3D iov_truncate(iov_vu, *iov_cnt, dlen + hdrlen); > + *cnt =3D iov_truncate(iov, *cnt, dlen + hdrlen); > =20 > /* pad frame to 60 bytes: first buffer is at least ETH_ZLEN long */ > l2len =3D dlen + hdrlen - VNET_HLEN; > - vu_pad(&iov_vu[0], l2len); > + vu_pad(&iov[0], l2len); > =20 > return dlen; > } > @@ -103,27 +100,28 @@ static ssize_t udp_vu_sock_recv(int s, bool v6, siz= e_t *iov_cnt) > /** > * udp_vu_prepare() - Prepare the packet header > * @c: Execution context > + * @iov: IO vector for the frame (including vnet header) > * @toside: Address information for one side of the flow > * @dlen: Packet data length > * > * Return: Layer-4 length > */ > -static size_t udp_vu_prepare(const struct ctx *c, > +static size_t udp_vu_prepare(const struct ctx *c, const struct iovec *io= v, > const struct flowside *toside, ssize_t dlen) > { > struct ethhdr *eh; > size_t l4len; > =20 > /* ethernet header */ > - eh =3D vu_eth(iov_vu[0].iov_base); > + eh =3D vu_eth(iov[0].iov_base); > =20 > memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > memcpy(eh->h_source, c->our_tap_mac, sizeof(eh->h_source)); > =20 > /* initialize header */ > if (inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)) { > - struct iphdr *iph =3D vu_ip(iov_vu[0].iov_base); > - struct udp_payload_t *bp =3D vu_payloadv4(iov_vu[0].iov_base); > + struct iphdr *iph =3D vu_ip(iov[0].iov_base); > + struct udp_payload_t *bp =3D vu_payloadv4(iov[0].iov_base); > =20 > eh->h_proto =3D htons(ETH_P_IP); > =20 > @@ -131,8 +129,8 @@ static size_t udp_vu_prepare(const struct ctx *c, > =20 > l4len =3D udp_update_hdr4(iph, bp, toside, dlen, true); > } else { > - struct ipv6hdr *ip6h =3D vu_ip(iov_vu[0].iov_base); > - struct udp_payload_t *bp =3D vu_payloadv6(iov_vu[0].iov_base); > + struct ipv6hdr *ip6h =3D vu_ip(iov[0].iov_base); > + struct udp_payload_t *bp =3D vu_payloadv6(iov[0].iov_base); > =20 > eh->h_proto =3D htons(ETH_P_IPV6); > =20 > @@ -147,23 +145,25 @@ static size_t udp_vu_prepare(const struct ctx *c, > /** > * udp_vu_csum() - Calculate and set checksum for a UDP packet > * @toside: Address information for one side of the flow > - * @iov_used: Number of used iov_vu items > + * @iov: IO vector for the frame > + * @cnt: Number of IO vector entries > */ > -static void udp_vu_csum(const struct flowside *toside, int iov_used) > +static void udp_vu_csum(const struct flowside *toside, const struct iove= c *iov, > + size_t cnt) > { > const struct in_addr *src4 =3D inany_v4(&toside->oaddr); > const struct in_addr *dst4 =3D inany_v4(&toside->eaddr); > - char *base =3D iov_vu[0].iov_base; > + char *base =3D iov[0].iov_base; > struct udp_payload_t *bp; > struct iov_tail data; > =20 > if (src4 && dst4) { > bp =3D vu_payloadv4(base); > - data =3D IOV_TAIL(iov_vu, iov_used, (char *)&bp->data - base); > + data =3D IOV_TAIL(iov, cnt, (char *)&bp->data - base); > csum_udp4(&bp->uh, *src4, *dst4, &data); > } else { > bp =3D vu_payloadv6(base); > - data =3D IOV_TAIL(iov_vu, iov_used, (char *)&bp->data - base); > + data =3D IOV_TAIL(iov, cnt, (char *)&bp->data - base); > csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, &data); > } > } > @@ -178,7 +178,9 @@ static void udp_vu_csum(const struct flowside *toside= , int iov_used) > void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t t= osidx) > { > const struct flowside *toside =3D flowside_at_sidx(tosidx); > + static struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE]; > bool v6 =3D !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); > + static struct iovec iov_vu[VIRTQUEUE_MAX_SIZE]; > struct vu_dev *vdev =3D c->vdev; > struct vu_virtq *vq =3D &vdev->vq[VHOST_USER_RX_QUEUE]; > int i; > @@ -211,9 +213,9 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, i= nt n, flow_sidx_t tosidx) > =20 > assert((size_t)elem_cnt =3D=3D iov_cnt); /* one iovec per element */ > =20 > - dlen =3D udp_vu_sock_recv(s, v6, &iov_cnt); > + dlen =3D udp_vu_sock_recv(iov_vu, &iov_cnt, s, v6); > if (dlen < 0) { > - vu_queue_rewind(vq, iov_cnt); > + vu_queue_rewind(vq, elem_cnt); > break; > } > =20 > @@ -223,12 +225,12 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s,= int n, flow_sidx_t tosidx) > vu_queue_rewind(vq, elem_cnt - elem_used); > =20 > if (iov_cnt > 0) { > - udp_vu_prepare(c, toside, dlen); > + udp_vu_prepare(c, iov_vu, toside, dlen); > if (*c->pcap) { > - udp_vu_csum(toside, iov_cnt); > + udp_vu_csum(toside, iov_vu, iov_cnt); > pcap_iov(iov_vu, iov_cnt, VNET_HLEN); > } <> - vu_flush(vdev, vq, elem, iov_cnt); > + vu_flush(vdev, vq, elem, elem_used); > vu_queue_notify(vdev, vq); > } > } > --=20 > 2.53.0 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --gVH/5sne0GCqRcnZ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnYn+kACgkQzQJF27ox 2Gdbpw/+O9iZ2QfUC87OXI1S1Ugyc40PiJtpUBi+WUAcxSMm8ub7zINQMa3r1ox1 Tu9i8xAMawbSGz5i7hZAInS6R07BFWEPt6+ZhaHdiC7sr9hbzFsQwnxqrntILFJD qkiy0KQsXOTwEP35bSQpuFuqi3c4zDmAxdfTjIAI/HBzHPKI06MUSVKCXpUJAgXg bpPVvLp01zTSw83z+YfRPDvLu+KHA40ey72LUCt2Lv4KmBlPewe/DGEUa0zuerQ1 OLqE8/eZ4RmLfs052LD2gupguuWLCgOcFOLoANQvKu8IKpONtGh6TDKvYBluH0PO XE5HA+TkjMcbIk03MN8rdoZ9TtobGKCAE9w/BtILCLeLdnM1qKXlStunLkcRXyib VBgfAaABAeoHrTNoL586z5LyCwQylTFAQcw+RxT0Ly9FDTr6Pb/q8MJJV3l/GvF2 7D4KkZcjUpuxmopz3kLAmYiUdrIuDbWimo+sRBaWG27twp7qfslPRPYn7RYFMNi8 j/4HC4dr8ru6rE0sWExkoov0lH4R3ou9zYIA+vMaR1aBs4M425eUyT5Re8csIq6w qIF2+vOhyuIm+LzUP2hkX4RtGz0tAfCx5ryQlknF55joe7Q3zhEgHPUiwFC0OXdJ hF06f/i7Mg1VRyDmaFHbqg1Pg5lTmxuUexPE4CadsWNw/2xm5is= =pAUN -----END PGP SIGNATURE----- --gVH/5sne0GCqRcnZ--