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=AXOd8WlM; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 7A3AF5A026D for ; Fri, 10 Apr 2026 08:47:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775803666; bh=ziEGj17zowBx6XmzTu6d5jV9DvfxdjTyGvnDrsDB0i8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AXOd8WlMWJg88yfLlrXcQ/5KP0MkgI7fyl8ZT4dSDn5RY/aMIMGUkt4MnAY5IQ7PA KTgG8x5Z7+P/3ukhkSO9lxSKSsi/qJ2icW8eehoP/QlF/vgcI3dQM4M3HcAHT3tf8f +06sYDCJ7XfX+3HrweG1e9anHt4vKh6kWciPRxweWqTBp32lw/jf2j73Xsjzs0yZgO 78BXYVhCSoWahp/AXdkUsiJSapVTA27ekcwx2CfjjsPikqopCgisp6DDvwrHDezpKI WkjzqGyjtYuKY20xRGW2QtJKyFQMNLfhhGG3+NSwG+RDv7nfYU+Gykn3zWZJoT1+gF P+wBkYDLpCZNw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fsS6V0x9Xz4wKw; Fri, 10 Apr 2026 16:47:46 +1000 (AEST) Date: Fri, 10 Apr 2026 16:47:41 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 03/10] vu_common: Move vnethdr setup into vu_flush() Message-ID: References: <20260403163811.3209635-1-lvivier@redhat.com> <20260403163811.3209635-4-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="tr/vYTm/SNnF8tnw" Content-Disposition: inline In-Reply-To: <20260403163811.3209635-4-lvivier@redhat.com> Message-ID-Hash: EV76NRDRQL36WY6HMET6QIL47IIZ4VP2 X-Message-ID-Hash: EV76NRDRQL36WY6HMET6QIL47IIZ4VP2 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: --tr/vYTm/SNnF8tnw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 03, 2026 at 06:38:04PM +0200, Laurent Vivier wrote: > Every caller of vu_flush() was calling vu_set_vnethdr() beforehand with > the same pattern. Move it into vu_flush(). >=20 > Remove vu_queue_notify() from vu_flush() and let callers invoke it > explicitly. This allows paths that perform multiple flushes, such as > tcp_vu_send_flag() and tcp_vu_data_from_sock(), to issue a single guest > notification at the end. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > tcp_vu.c | 19 ++++++++----------- > udp_vu.c | 3 +-- > vu_common.c | 9 +++++---- > vu_common.h | 1 - > 4 files changed, 14 insertions(+), 18 deletions(-) >=20 > diff --git a/tcp_vu.c b/tcp_vu.c > index dc0e17c0f03f..0cd01190d612 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -82,7 +82,6 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_ta= p_conn *conn, int flags) > struct ethhdr *eh; > uint32_t seq; > int elem_cnt; > - int nb_ack; > int ret; > =20 > hdrlen =3D tcp_vu_hdrlen(CONN_V6(conn)); > @@ -97,8 +96,6 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_ta= p_conn *conn, int flags) > assert(flags_elem[0].in_sg[0].iov_len >=3D > MAX(hdrlen + sizeof(*opts), ETH_ZLEN + VNET_HLEN)); > =20 > - vu_set_vnethdr(flags_elem[0].in_sg[0].iov_base, 1); > - > eh =3D vu_eth(flags_elem[0].in_sg[0].iov_base); > =20 > memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > @@ -143,9 +140,10 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp= _tap_conn *conn, int flags) > l2len =3D optlen + hdrlen - VNET_HLEN; > vu_pad(&flags_elem[0].in_sg[0], l2len); > =20 > + vu_flush(vdev, vq, flags_elem, 1); > + > if (*c->pcap) > pcap_iov(&flags_elem[0].in_sg[0], 1, VNET_HLEN); > - nb_ack =3D 1; > =20 > if (flags & DUP_ACK) { > elem_cnt =3D vu_collect(vdev, vq, &flags_elem[1], 1, > @@ -157,14 +155,14 @@ int tcp_vu_send_flag(const struct ctx *c, struct tc= p_tap_conn *conn, int flags) > memcpy(flags_elem[1].in_sg[0].iov_base, > flags_elem[0].in_sg[0].iov_base, > flags_elem[0].in_sg[0].iov_len); > - nb_ack++; > + > + vu_flush(vdev, vq, &flags_elem[1], 1); > =20 > if (*c->pcap) > pcap_iov(&flags_elem[1].in_sg[0], 1, VNET_HLEN); > } > } > - > - vu_flush(vdev, vq, flags_elem, nb_ack); > + vu_queue_notify(vdev, vq); > =20 > return 0; > } > @@ -451,7 +449,6 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct= tcp_tap_conn *conn) > assert(frame_size >=3D hdrlen); > =20 > dlen =3D frame_size - hdrlen; > - vu_set_vnethdr(iov->iov_base, buf_cnt); > =20 > /* The IPv4 header checksum varies only with dlen */ > if (previous_dlen !=3D dlen) > @@ -464,14 +461,14 @@ int tcp_vu_data_from_sock(const struct ctx *c, stru= ct tcp_tap_conn *conn) > l2len =3D dlen + hdrlen - VNET_HLEN; > vu_pad(iov, l2len); > =20 > + vu_flush(vdev, vq, &elem[head[i]], buf_cnt); > + > if (*c->pcap) > pcap_iov(iov, buf_cnt, VNET_HLEN); > =20 > conn->seq_to_tap +=3D dlen; > } > - > - /* send packets */ > - vu_flush(vdev, vq, elem, iov_cnt); > + vu_queue_notify(vdev, vq); > =20 > conn_flag(c, conn, ACK_FROM_TAP_DUE); > =20 > diff --git a/udp_vu.c b/udp_vu.c > index cc69654398f0..f8629af58ab5 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -124,8 +124,6 @@ static int udp_vu_sock_recv(const struct ctx *c, stru= ct vu_virtq *vq, int s, > l2len =3D *dlen + hdrlen - VNET_HLEN; > vu_pad(&iov_vu[0], l2len); > =20 > - vu_set_vnethdr(iov_vu[0].iov_base, elem_used); > - > /* release unused buffers */ > vu_queue_rewind(vq, elem_cnt - elem_used); > =20 > @@ -230,6 +228,7 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, i= nt n, flow_sidx_t tosidx) > pcap_iov(iov_vu, iov_used, VNET_HLEN); > } > vu_flush(vdev, vq, elem, iov_used); > + vu_queue_notify(vdev, vq); > } > } > } > diff --git a/vu_common.c b/vu_common.c > index 13b1e51001d4..57949ca32309 100644 > --- a/vu_common.c > +++ b/vu_common.c > @@ -118,7 +118,8 @@ int vu_collect(const struct vu_dev *vdev, struct vu_v= irtq *vq, > * @vnethdr: Address of the header to set > * @num_buffers: Number of guest buffers of the frame > */ > -void vu_set_vnethdr(struct virtio_net_hdr_mrg_rxbuf *vnethdr, int num_bu= ffers) > +static void vu_set_vnethdr(struct virtio_net_hdr_mrg_rxbuf *vnethdr, > + int num_buffers) > { > vnethdr->hdr =3D VU_HEADER; > /* Note: if VIRTIO_NET_F_MRG_RXBUF is not negotiated, > @@ -139,6 +140,8 @@ void vu_flush(const struct vu_dev *vdev, struct vu_vi= rtq *vq, > { > int i; > =20 > + vu_set_vnethdr(elem[0].in_sg[0].iov_base, elem_cnt); > + > for (i =3D 0; i < elem_cnt; i++) { > size_t elem_size =3D iov_size(elem[i].in_sg, elem[i].in_num); > =20 > @@ -146,7 +149,6 @@ void vu_flush(const struct vu_dev *vdev, struct vu_vi= rtq *vq, > } > =20 > vu_queue_flush(vdev, vq, elem_cnt); > - vu_queue_notify(vdev, vq); > } > =20 > /** > @@ -260,8 +262,6 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > goto err; > } > =20 > - vu_set_vnethdr(in_sg[0].iov_base, elem_cnt); > - > total -=3D VNET_HLEN; > =20 > /* copy data from the buffer to the iovec */ > @@ -271,6 +271,7 @@ int vu_send_single(const struct ctx *c, const void *b= uf, size_t size) > pcap_iov(in_sg, in_total, VNET_HLEN); > =20 > vu_flush(vdev, vq, elem, elem_cnt); > + vu_queue_notify(vdev, vq); > =20 > trace("vhost-user sent %zu", total); > =20 > diff --git a/vu_common.h b/vu_common.h > index 7b060eb6184f..4037ab765b7d 100644 > --- a/vu_common.h > +++ b/vu_common.h > @@ -39,7 +39,6 @@ int vu_collect(const struct vu_dev *vdev, struct vu_vir= tq *vq, > struct vu_virtq_element *elem, int max_elem, > struct iovec *in_sg, size_t max_in_sg, size_t *in_total, > size_t size, size_t *collected); > -void vu_set_vnethdr(struct virtio_net_hdr_mrg_rxbuf *vnethdr, int num_bu= ffers); > void vu_flush(const struct vu_dev *vdev, struct vu_virtq *vq, > struct vu_virtq_element *elem, int elem_cnt); > void vu_kick_cb(struct vu_dev *vdev, union epoll_ref ref, > --=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 --tr/vYTm/SNnF8tnw Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnYnQwACgkQzQJF27ox 2Gf7ug/9Gj2IMd5DMS8d63fDjLl7Il8S5UUM0VziT3xJMdl4OaB0JvvG9Kw58sdc 6hWIDyrg0oqGeFhLoFI87qhHp9wJtfCEYehZgxwVxaASPpVeHy/5ri+XhHQWqvA7 DHIQ5+fyEdhwCUg0fk714zHJ7klWGeEjAvZBQ2ju/CIjv5zGQUjTe56pjNWaSJFc owqtZJqcoL+T1lLZ+je43jVT+0beRYMxZa2B+hQwieDL9vL3Z2qG96ClNHESWcuZ 91flOEP13JuLhmQbYVH9oYK2NzAdWx0tItu1Fa4337q64UOsqvD0lXVjeranWGkI ISwBQEZQmRFR7NWSLh7YgTqpNvWZLX9jcYpITP8Qq89DELxipHMPGSfKXvZBIRpy oBrxwvHOs3W3gh3VoZ5tPc2iyFzsj3W9q3+SkvW23aiWH1V0GYeZaUZXEdRL5dlS KZC+HCk7TuGNwdQFOxscXuZxD/7O7KdVS7AAMSeXORjFcPAuF/UpSNs68LoN599J rCpMAigjUKUCb1WFVGtManRtKCtuMvz2+DDxdD99heamLuIoZVKDV3L9QP4vv0I9 qDw+N4NNHDLaifST1zZj3H2s/if/vs2Ca0aJ1uKsdITuauKea29B+PiHAX94YSv6 7uSjyq8SJtUqBH4HpIF+KFiggdmxKQqSYSpOSREgZPEzUL9l5sM= =ZwYH -----END PGP SIGNATURE----- --tr/vYTm/SNnF8tnw--