From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L6up9Y8t; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 7AAC35A026D for ; Fri, 03 Apr 2026 08:20:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775197229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n7alWIIK1znBZavwYsdJE2qn6XGDFWqIexMK95FW2wk=; b=L6up9Y8theXlwWKhQtq/B/faX0Fkpj10iqeSXjzfaosey6OyjgrqN7tFVhWodH17ZjVNrF H1TcqIKcXtXhATxhJ/O3Q3ml3qQX4X1uZQPh3uHhbP7abmnuQi93x1tt2c38JffJ/stbUB MHi42G48h3q9EEpP54KnzUMF5B7W72M= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-q5iSooJYO0Sn7c-zrg_1yg-1; Fri, 03 Apr 2026 02:20:28 -0400 X-MC-Unique: q5iSooJYO0Sn7c-zrg_1yg-1 X-Mimecast-MFC-AGG-ID: q5iSooJYO0Sn7c-zrg_1yg_1775197227 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4362197d1easo1445748f8f.2 for ; Thu, 02 Apr 2026 23:20:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775197226; x=1775802026; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n7alWIIK1znBZavwYsdJE2qn6XGDFWqIexMK95FW2wk=; b=c5V+0p1jFdmttPT3C366RjDXAp5oF4GsD/l8kkP/lfZcvCvKuAcuWyPYGhqKljkHpR tx/N4V+eXmTExlN+/3pB4RU0Udrnw9nbuvjfgAkFUnsMbiSnGjxeyk/r/RhgkSrC7ve2 G4QquQTxfcz4yiZnwx4cTXGSlQet5P25C1ysKFT4yEq0WloJ8HWrIMW1hURO7CO4S9Sy QB7SzsuUqNFP3ESYFwv9hW/c3i1BCDD1McwTdUFVr4/aBjdV7Xym0RM9Vw+8HRGzuM0c vB8wlGeLFoW7TJrvh0zFEfQ8qM5dZ6hZRqYH5ibob5rSpf35xcY2fvx3HaVKx4EIieCZ Djiw== X-Gm-Message-State: AOJu0YyTrE+aX9n/x6eCKvD2aTh+QR3wqIn5gFzHkLnhu9Hc5ektlabD SVhjO7X0QBkULdl3FxwU//TKx9gP+O5iVceTfYVD+KeRu9nbJtxZeU+lWtz9VgKCSyPl73jGdYr y931JfOrhTtJHOrcKxFkPeVfMYfIr94/z+4U38gVz0CALUywa5C6W9v6WHSHrm/9wlpy4sXA70v 8OiHTh+OhJIbK6H500cJW/pfNzb8OUXZoCV86m X-Gm-Gg: ATEYQzxzheu4XPTZoGAgLE3JgQaJDer5bP2VGdoSGm/4VfyGYptxxgcmrBLb8Xadvpd zs2OM4a0LHm/QmkUFxRbnlQnkwB7OEI3dAjW2g5d/V/hWRnSKoDhkxw24Ai5kfEs97eWkLuzcZ9 Ny+OUsf4sAZ3IIS+p+7kmhJarCuX50sMPEMgIr6KZq/Rnn45cSTSfowyya42gY4P3hjkPNRrnLb 3TUiEhVC/M8CbIksRGeu5r2CJa84BqcXMMq3QJaajv/wKI6uQGoelFgeAKYzsbuR06tkzzU2QHv 0t046z28Wj3r7Ge2u802YZiVQLVrFZjBB4qsE1Wgt83g99NA8Hut9Y1dDK5v9KoPcmkpAuVyzb/ kxPJXv933FFWzvAq5MgR8c7jfryqc3yluIk3ERUzpsdgc1PiIYg== X-Received: by 2002:a05:600c:8710:b0:485:5ba3:37d8 with SMTP id 5b1f17b1804b1-488996b0589mr31632985e9.5.1775197224246; Thu, 02 Apr 2026 23:20:24 -0700 (PDT) X-Received: by 2002:a05:600c:8710:b0:485:5ba3:37d8 with SMTP id 5b1f17b1804b1-488996b0589mr31632365e9.5.1775197223589; Thu, 02 Apr 2026 23:20:23 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4888a626100sm203201465e9.1.2026.04.02.23.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 23:20:23 -0700 (PDT) From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH 03/10] vu_common: Move vnethdr setup into vu_flush() Message-ID: <20260403082022.22c563c6@elisabeth> In-Reply-To: <20260401191826.1782394-4-lvivier@redhat.com> References: <20260401191826.1782394-1-lvivier@redhat.com> <20260401191826.1782394-4-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Fri, 03 Apr 2026 08:20:22 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xTMbYY3zkRjMHS3kyjbxPvKhK11UdJjlo5OD38mghy0_1775197227 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 34GEVSLZLS7JXKC7PIAR5OPDL4FCO6YL X-Message-ID-Hash: 34GEVSLZLS7JXKC7PIAR5OPDL4FCO6YL X-MailFrom: sbrivio@redhat.com 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: On Wed, 1 Apr 2026 21:18:19 +0200 Laurent Vivier wrote: > Every caller of vu_flush() was calling vu_set_vnethdr() beforehand with > the same pattern. Move it into vu_flush(). > > 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. > > Signed-off-by: Laurent Vivier > --- > tcp_vu.c | 19 ++++++++----------- > udp_vu.c | 3 +-- > vu_common.c | 9 +++++---- > vu_common.h | 1 - > 4 files changed, 14 insertions(+), 18 deletions(-) > > 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_tap_conn *conn, int flags) > struct ethhdr *eh; > uint32_t seq; > int elem_cnt; > - int nb_ack; > int ret; > > hdrlen = tcp_vu_hdrlen(CONN_V6(conn)); > @@ -97,8 +96,6 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) > assert(flags_elem[0].in_sg[0].iov_len >= > MAX(hdrlen + sizeof(*opts), ETH_ZLEN + VNET_HLEN)); > > - vu_set_vnethdr(flags_elem[0].in_sg[0].iov_base, 1); > - > eh = vu_eth(flags_elem[0].in_sg[0].iov_base); > > 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 = optlen + hdrlen - VNET_HLEN; > vu_pad(&flags_elem[0].in_sg[0], l2len); > > + vu_flush(vdev, vq, flags_elem, 1); > + > if (*c->pcap) > pcap_iov(&flags_elem[0].in_sg[0], 1, VNET_HLEN); > - nb_ack = 1; > > if (flags & DUP_ACK) { > elem_cnt = vu_collect(vdev, vq, &flags_elem[1], 1, > @@ -157,14 +155,14 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_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); > > 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); > > return 0; > } > @@ -451,7 +449,6 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) > assert(frame_size >= hdrlen); > > dlen = frame_size - hdrlen; > - vu_set_vnethdr(iov->iov_base, buf_cnt); > > /* The IPv4 header checksum varies only with dlen */ > if (previous_dlen != dlen) > @@ -464,14 +461,14 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) > l2len = dlen + hdrlen - VNET_HLEN; > vu_pad(iov, l2len); > > + vu_flush(vdev, vq, &elem[head[i]], buf_cnt); > + > if (*c->pcap) > pcap_iov(iov, buf_cnt, VNET_HLEN); > > conn->seq_to_tap += dlen; > } > - > - /* send packets */ > - vu_flush(vdev, vq, elem, iov_cnt); > + vu_queue_notify(vdev, vq); If I understand correctly, this makes iov_cnt set by tcp_vu_sock_recv() redundant because you're now calling vu_flush() from inside the loop that iterates up to head_cnt (which is the only count we need to know). Maybe it would be clearer to have a patch in this series dropping iov_cnt as argument altogether (especially the commit message of that kind of change might make things clearer). > > conn_flag(c, conn, ACK_FROM_TAP_DUE); > > 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, struct vu_virtq *vq, int s, > l2len = *dlen + hdrlen - VNET_HLEN; > vu_pad(&iov_vu[0], l2len); > > - vu_set_vnethdr(iov_vu[0].iov_base, elem_used); > - > /* release unused buffers */ > vu_queue_rewind(vq, elem_cnt - elem_used); > > @@ -230,6 +228,7 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int 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_virtq *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_buffers) > +static void vu_set_vnethdr(struct virtio_net_hdr_mrg_rxbuf *vnethdr, > + int num_buffers) > { > vnethdr->hdr = 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_virtq *vq, > { > int i; > > + vu_set_vnethdr(elem[0].in_sg[0].iov_base, elem_cnt); > + > for (i = 0; i < elem_cnt; i++) { > size_t elem_size = iov_size(elem[i].in_sg, elem[i].in_num); > > @@ -146,7 +149,6 @@ void vu_flush(const struct vu_dev *vdev, struct vu_virtq *vq, > } > > vu_queue_flush(vdev, vq, elem_cnt); > - vu_queue_notify(vdev, vq); > } > > /** > @@ -260,8 +262,6 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) > goto err; > } > > - vu_set_vnethdr(in_sg[0].iov_base, elem_cnt); > - > total -= VNET_HLEN; > > /* copy data from the buffer to the iovec */ > @@ -271,6 +271,7 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) > pcap_iov(in_sg, in_total, VNET_HLEN); > > vu_flush(vdev, vq, elem, elem_cnt); > + vu_queue_notify(vdev, vq); > > trace("vhost-user sent %zu", total); > > 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_virtq *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_buffers); > 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, -- Stefano