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=NhfypXtM; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id B1BF05A0274 for ; Mon, 02 Mar 2026 02:03:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1772413409; bh=R8gQ+ON37EBIzCF7q24yxaZoS7mGLcMP+kpjKWxjgmA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NhfypXtMSEhkfp7BRbKnFBoLa+ToBz5TO1h7AgRTDe8GTLAW4nE40h/M3p1I+Ghif IqnIpz4Q1R8UUL/RwOQLIX5G5LZ2710xhvEHe3iQCbdw0KZ47Q74QZ04viuXzMAZA8 YybloGunNHcPCrICGrlwq+KlnnRNym1YwlJCaFrBKwksu9C5eQMwB/o63f6PnjozXx sd80wrXC+IwC5pvtRiB2v1zdep8kzYk+bA9BXPxaVSiDaHb/92X4ipax3eYIbFIEyx t8P7ZCrbDdb7I+sB7JOdysNn62asSiGaLKSsMMrsZ285DM2IUn53QGwdzJ7H9zsQz9 Uj/jK1KPBM6/A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fPLKF3wh0z4w8w; Mon, 02 Mar 2026 12:03:29 +1100 (AEDT) Date: Mon, 2 Mar 2026 12:03:24 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 12/12] vhost-user,udp: Use 2 iovec entries per element Message-ID: References: <20260227140330.2216753-1-lvivier@redhat.com> <20260227140330.2216753-13-lvivier@redhat.com> MIME-Version: 1.0 In-Reply-To: <20260227140330.2216753-13-lvivier@redhat.com> 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 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="VdutJhbsop9ykW7e" Content-Disposition: inline Message-ID-Hash: 2TCLF3SEPBYXV6LJFOSZLINDGN55ESFM X-Message-ID-Hash: 2TCLF3SEPBYXV6LJFOSZLINDGN55ESFM 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: --VdutJhbsop9ykW7e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 27, 2026 at 03:03:30PM +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 Reviewed-by: David Gibson It looks like a reasonable short term fix for the specific iPXE problem. Longer term, having a fixed 2 iovecs per element still seems fragile, if we encounter some other occasionally-used guest side virtio driver which splits its Tx buffers up in an even weirder way. It would be nicer if we can actually take our cue from what the guest actually gives us. I'm not sure how feasible that is, though. > --- > udp_vu.c | 8 ++++---- > vu_common.c | 34 +++++++++++++++++++++++----------- > 2 files changed, 27 insertions(+), 15 deletions(-) >=20 > diff --git a/udp_vu.c b/udp_vu.c > index 7e486b74883e..13fea87e1b9f 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -34,7 +34,7 @@ > #include "vu_common.h" > =20 > static struct iovec iov_vu=09=09[VIRTQUEUE_MAX_SIZE]; > -static struct vu_virtq_element=09elem=09=09[VIRTQUEUE_MAX_SIZE]; > +static struct vu_virtq_element=09elem=09[VIRTQUEUE_MAX_SIZE / IOV_PER_EL= EM]; > =20 > /** > * udp_vu_hdrlen() - Sum size of all headers, from UDP to virtio-net > @@ -214,21 +214,21 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s,= int n, flow_sidx_t tosidx) > =09=09int elem_cnt, elem_used; > =09=09ssize_t dlen; > =20 > -=09=09vu_init_elem(elem, iov_vu, ARRAY_SIZE(elem), 1); > +=09=09vu_init_elem(elem, iov_vu, ARRAY_SIZE(elem), IOV_PER_ELEM); > =20 > =09=09elem_cnt =3D vu_collect(vdev, vq, elem, ARRAY_SIZE(elem), > =09=09=09=09 IP_MAX_MTU + ETH_HLEN + VNET_HLEN, NULL); > =09=09if (elem_cnt =3D=3D 0) > =09=09=09break; > =20 > -=09=09data =3D IOV_TAIL(iov_vu, elem_cnt, 0); > +=09=09data =3D IOV_TAIL(iov_vu, (size_t)(elem_cnt * IOV_PER_ELEM), 0); > =20 > =09=09dlen =3D udp_vu_sock_recv(&data, s, v6); > =09=09if (dlen < 0) { > =09=09=09vu_queue_rewind(vq, elem_cnt); > =09=09=09continue; > =09=09} > -=09=09elem_used =3D data.cnt; > +=09=09elem_used =3D DIV_ROUND_UP(data.cnt, IOV_PER_ELEM); > =20 > =09=09/* release unused buffers */ > =09=09vu_queue_rewind(vq, elem_cnt - elem_used); > diff --git a/vu_common.c b/vu_common.c > index 67d8f3e47338..3f50d31da633 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, > { > =09int i, j; > =20 > -=09for (i =3D 0, j =3D 0; i < elem_cnt; i++, j +=3D iov_per_elem) > +=09for (i =3D 0, j =3D 0; i < elem_cnt; i++, j +=3D iov_per_elem) { > +=09=09int k; > + > +=09=09for (k =3D 0; k < iov_per_elem; k++) { > +=09=09=09iov[j + k].iov_base =3D NULL; > +=09=09=09iov[j + k].iov_len =3D 0; > +=09=09} > =09=09vu_set_element(&elem[i], 0, NULL, iov_per_elem, &iov[j]); > +=09} > } > =20 > /** > @@ -88,7 +95,8 @@ int vu_collect(const struct vu_dev *vdev, struct vu_vir= tq *vq, > =09int elem_cnt =3D 0; > =20 > =09while (current_size < size && elem_cnt < max_elem) { > -=09=09struct iovec *iov; > +=09=09struct iov_tail tail; > +=09=09size_t elem_size; > =09=09int ret; > =20 > =09=09ret =3D vu_queue_pop(vdev, vq, &elem[elem_cnt]); > @@ -101,12 +109,14 @@ int vu_collect(const struct vu_dev *vdev, struct vu= _virtq *vq, > =09=09=09break; > =09=09} > =20 > -=09=09iov =3D &elem[elem_cnt].in_sg[0]; > +=09=09tail =3D IOV_TAIL(elem[elem_cnt].in_sg, elem[elem_cnt].in_num, 0); > +=09=09iov_tail_truncate(&tail, size - current_size); > +=09=09elem[elem_cnt].in_num =3D tail.cnt; > =20 > -=09=09if (iov->iov_len > size - current_size) > -=09=09=09iov->iov_len =3D size - current_size; > +=09=09elem_size =3D iov_size(elem[elem_cnt].in_sg, > +=09=09=09=09 elem[elem_cnt].in_num); > =20 > -=09=09current_size +=3D iov->iov_len; > +=09=09current_size +=3D elem_size; > =09=09elem_cnt++; > =20 > =09=09if (!vu_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) > @@ -153,8 +163,10 @@ void vu_flush(const struct vu_dev *vdev, struct vu_v= irtq *vq, > { > =09int i; > =20 > -=09for (i =3D 0; i < elem_cnt; i++) > -=09=09vu_queue_fill(vdev, vq, &elem[i], elem[i].in_sg[0].iov_len, i); > +=09for (i =3D 0; i < elem_cnt; i++) { > +=09=09size_t elem_size =3D iov_size(elem[i].in_sg, elem[i].in_num); > +=09=09vu_queue_fill(vdev, vq, &elem[i], elem_size, i); > +=09} > =20 > =09vu_queue_flush(vdev, vq, elem_cnt); > =09vu_queue_notify(vdev, vq); > @@ -253,7 +265,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > { > =09struct vu_dev *vdev =3D c->vdev; > =09struct vu_virtq *vq =3D &vdev->vq[VHOST_USER_RX_QUEUE]; > -=09struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE]; > +=09struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE / IOV_PER_ELEM]; > =09struct iovec in_sg[VIRTQUEUE_MAX_SIZE]; > =09struct iov_tail data; > =09size_t total; > @@ -267,7 +279,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > =09=09return -1; > =09} > =20 > -=09vu_init_elem(elem, in_sg, ARRAY_SIZE(elem), 1); > +=09vu_init_elem(elem, in_sg, ARRAY_SIZE(elem), IOV_PER_ELEM); > =20 > =09size +=3D VNET_HLEN; > =09elem_cnt =3D vu_collect(vdev, vq, elem, ARRAY_SIZE(elem), size, &tota= l); > @@ -277,7 +289,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > =09=09goto err; > =09} > =20 > -=09data =3D IOV_TAIL(&in_sg[0], elem_cnt, 0); > +=09data =3D IOV_TAIL(&in_sg[0], (size_t)(elem_cnt * IOV_PER_ELEM), 0); > =09vu_set_vnethdr(vdev, &data, elem_cnt); > =09total -=3D VNET_HLEN; > =20 > --=20 > 2.53.0 >=20 --=20 David Gibson (he or they)=09| I'll have my music baroque, and my code david AT gibson.dropbear.id.au=09| minimalist, thank you, not the other way =09=09=09=09| around. http://www.ozlabs.org/~dgibson --VdutJhbsop9ykW7e Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmk4dsACgkQzQJF27ox 2GePyg//TbJgbSmHJRMDm1Cx4GiwnivVbzB7iBTG2WhNC57QRzqZMdO6Izbk9PM7 oYGaU4rn+gu8+kLx4e7ZhSbygrT64baD2PpMMzcGkhWjR7g264WWMuQdu6s1NEt4 7zvUMboGPpekNksy+UlUBlq7UD3p+HiDlrnWtXsbh+g+I6f4vNtK1Qn8O+lbMLvm E1BLF0AqisCDagnkBcr8adfNQJQ3+VVGmqWqaUObg8VBiuNLI8lty0JXOoO6kyqu enjoy9WOV041RnKcWe7/XSy5M1pUg0xxBFlb87osSPuFkpah243BNeFtBzwuYwD+ bDYcl8A1e2UC47AbFH/rJcjt8gIzCM2qs8fUwHhAQs2qD/Nuo2QIMjWmEqds1m9+ rih4lthMfcfNefNgjWnsWooet6HBf54fPOzhtSVKlXJv7IqZV0IiO92xEnTifuGJ LZGZ1S9ozMFFYFK3YrNtJQtf72anEn8au4l+tWC8/XEfSMTOq+yZrWyC4Ia6QCpn jG3B166vKoqqyZJSGgXH2/Lr4n4FZasjUbNNKEAXJzohGsmawF3jtIk/zRemMrf7 XZ2SMIOb4Fp6pBqD9TeviLWIASrPCyrji4ozkui9/zH45q2YH50tG04VvGGH/TsU rH//DBdnbuO7YJU6oFb058/G9hEzwKRR/F+hCTB6hrUvRXuywOQ= =UD3k -----END PGP SIGNATURE----- --VdutJhbsop9ykW7e--