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=BYHmFvSb; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 9D3835A0265 for ; Thu, 12 Mar 2026 05:39:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773290383; bh=RNKjW3w/neWC2+KYNRaJU49fZtVxI6t4dHhmjeCtMKg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BYHmFvSbhzcb4sJdGHy7GcNYL3xBrr6TnfuisktHFCuEecFbT+go8FNbF3w2ccJ1l CQUs+XQ8xg9U9mca3NmYt272Z6uAvaKCtalTTtUhYck+ZSa/jp28EqLXfjC/eZPmKi 67p2QNKvOoIsQxfjgK+S/VCvDdluyroZfJUS66Zl44oK8N9mI0H+xYAlmQoq8SSP4B ofLgoZADtm6zeNuJtiuLwOFJbeIJrsWZArkLlR76uBGPpeaxzbwCmfuV81EvxOYGKW yrhT8sySjkk5sJYYmznab7NImnZBTCDup+2pDgENlOEvKNkA0NfgoDWmmecSGnkqM6 ukjAzI69mXouQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fWZf757Jlz4wD4; Thu, 12 Mar 2026 15:39:43 +1100 (AEDT) Date: Thu, 12 Mar 2026 15:39:38 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 13/13] vhost-user,udp: Use 2 iovec entries per element Message-ID: References: <20260309094744.1907754-1-lvivier@redhat.com> <20260309094744.1907754-14-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="G1C/FwAoLsqrCUhj" Content-Disposition: inline In-Reply-To: <20260309094744.1907754-14-lvivier@redhat.com> Message-ID-Hash: OFM5FYGN2LYLOEWQWKPKQTSMJ6NIT2VN X-Message-ID-Hash: OFM5FYGN2LYLOEWQWKPKQTSMJ6NIT2VN 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: --G1C/FwAoLsqrCUhj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 09, 2026 at 10:47:44AM +0100, Laurent Vivier wrote: > iPXE places the vnet header in one virtqueue descriptor and the payload > in another. When passt maps these descriptors, it needs two iovecs per > virtqueue element to handle this layout. >=20 > Without this, passt crashes with: >=20 > ASSERTION FAILED in virtqueue_map_desc (virtio.c:403): num_sg < max_num= _sg >=20 > Signed-off-by: Laurent Vivier > --- > udp_vu.c | 8 ++++---- > vu_common.c | 15 +++++++++++---- > 2 files changed, 15 insertions(+), 8 deletions(-) >=20 > diff --git a/udp_vu.c b/udp_vu.c > index cb5274aa1d81..47659b0402fd 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -34,7 +34,7 @@ > #include "vu_common.h" > =20 > static struct iovec iov_vu [VIRTQUEUE_MAX_SIZE]; > -static struct vu_virtq_element elem [VIRTQUEUE_MAX_SIZE]; > +static struct vu_virtq_element elem [VIRTQUEUE_MAX_SIZE / IOV_PER_ELEM]; The two level structure of the queues (array of elems, each pointing to an array of iovs) confuses me a bit. I would have thought that VIRTQUEUE_MAX_SIZE represented the maximum number of elements, even if those elements had multiple iovs. Can you enlighten me? > /** > * udp_vu_hdrlen() - Sum size of all headers, from UDP to virtio-net > @@ -214,20 +214,20 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s,= int n, flow_sidx_t tosidx) > size_t iov_cnt; > ssize_t dlen; > =20 > - vu_init_elem(elem, iov_vu, ARRAY_SIZE(elem), 1); > + vu_init_elem(elem, iov_vu, ARRAY_SIZE(elem), IOV_PER_ELEM); > =20 > elem_cnt =3D vu_collect(vdev, vq, elem, ARRAY_SIZE(elem), > IP_MAX_MTU + ETH_HLEN + VNET_HLEN, NULL); > if (elem_cnt =3D=3D 0) > break; > =20 > - iov_cnt =3D elem_cnt; > + iov_cnt =3D (size_t)elem_cnt * IOV_PER_ELEM; > dlen =3D udp_vu_sock_recv(iov_vu, &iov_cnt, s, v6); > if (dlen < 0) { > vu_queue_rewind(vq, elem_cnt); > break; > } > - elem_used =3D iov_cnt; > + elem_used =3D DIV_ROUND_UP(iov_cnt, IOV_PER_ELEM); > =20 > /* release unused buffers */ > vu_queue_rewind(vq, elem_cnt - elem_used); > diff --git a/vu_common.c b/vu_common.c > index 3225aca53ea6..a2867a293184 100644 > --- a/vu_common.c > +++ b/vu_common.c > @@ -63,8 +63,15 @@ void vu_init_elem(struct vu_virtq_element *elem, struc= t iovec *iov, > { > int i, j; > =20 > - for (i =3D 0, j =3D 0; i < elem_cnt; i++, j +=3D iov_per_elem) > + for (i =3D 0, j =3D 0; i < elem_cnt; i++, j +=3D iov_per_elem) { > + int k; > + > + for (k =3D 0; k < iov_per_elem; k++) { > + iov[j + k].iov_base =3D NULL; > + iov[j + k].iov_len =3D 0; > + } > vu_set_element(&elem[i], 0, NULL, iov_per_elem, &iov[j]); > + } > } > =20 > /** > @@ -272,7 +279,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > { > struct vu_dev *vdev =3D c->vdev; > struct vu_virtq *vq =3D &vdev->vq[VHOST_USER_RX_QUEUE]; > - struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE]; > + struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE / IOV_PER_ELEM]; > struct iovec in_sg[VIRTQUEUE_MAX_SIZE]; > struct iov_tail data; > size_t total; > @@ -286,7 +293,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > return -1; > } > =20 > - vu_init_elem(elem, in_sg, ARRAY_SIZE(elem), 1); > + vu_init_elem(elem, in_sg, ARRAY_SIZE(elem), IOV_PER_ELEM); > =20 > size +=3D VNET_HLEN; > elem_cnt =3D vu_collect(vdev, vq, elem, ARRAY_SIZE(elem), size, &total); > @@ -303,7 +310,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > } > elem_cnt =3D iov_truncate(in_sg, elem_cnt, size); > =20 > - data =3D IOV_TAIL(&in_sg[0], elem_cnt, 0); > + data =3D IOV_TAIL(&in_sg[0], (size_t)(elem_cnt * IOV_PER_ELEM), 0); > vu_set_vnethdr(&data, elem_cnt); > =20 > size -=3D VNET_HLEN; > --=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 --G1C/FwAoLsqrCUhj Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmyQ4kACgkQzQJF27ox 2GcjqRAAoWQu1lg3h6AoLfk0tOHMJAgamvksoWeqvEjOlaqLaYjtHdfZLbalQQGf oLcib8dMrDKzh7rlKI/czr7X8ehVKxdlzBKpkxyjuKNmHo+osPNsUhMvgD7eCuUc PfaDeEs4FGR5lKX/Dm+zKGKIpDsfl5FFFPySSyxkjeKQ7L+VeWWNxEW/ujLld5gs 5vjrDOSpjD2mCXaxPncFAoT6chysF3ZgqKBJ7bj6Y5MyHIfuvrjbO6wO94gN4tW9 EOU8NE4BhVatxgIkETmjql/py8ccnFIbNPGJqIy+HTlc8svqKdWE9Gtlwvx4EGWP Qggqlp5molPrfvD/9N2qde/2ji15MDKg4eya1SL0ycJuOZIQbyZqrOGwoPAOKowP 5c0sybEt0FMq5RG9RLQCGYWRIg12IF8elk13iW0p11kheac9kT0DuwuX2MIwOxp0 IbHrNJK3M7Lk4D3bEKOZfO4Bcq0EBPJlJuDJLPq6KQac0AUeksHklf+Gh6Vk1Gw0 Mnt0puVYdDs16ezXk63zDNL6dh/7oFotju+2U+6WyigOjkVGO8km3w30sdaNYMbj NTd2HDQ3J0bHm4+wIIJYdrxCmjijPKpesElbmvX+VU9GCvIVGCIPizG79aZJUO+A nAw+XzzZsp1eafpQXtQ3t+3Nrv703bkRjJ3C+SKJRoFDfksFbLI= =MtL3 -----END PGP SIGNATURE----- --G1C/FwAoLsqrCUhj--