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=hiJm66Ns; 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 7968E5A0274 for ; Wed, 13 May 2026 13:52:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778673163; 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=HVbBSwRBYyQOBOWmoMv/hS6eKYxIz3BT2qr+Kgt1l20=; b=hiJm66Nsb5hHSTHC2N+NeoSfY5iP2N9eKsvAyeo9tj4jR1jkC3JC3UYmvJMGQ/P9YKto9s w8yeyP5wwNKbnFBQutWXDTa6nNhtWoduo8Gb0YxqNaihX/N8fJ1DiW4lWYDu73ft/hRq6I AT2FxOsD3pFKVGXrpbpd05Mmdnf8Er0= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-Xl5GFkewPCOFY-tYn4J2vQ-1; Wed, 13 May 2026 07:52:40 -0400 X-MC-Unique: Xl5GFkewPCOFY-tYn4J2vQ-1 X-Mimecast-MFC-AGG-ID: Xl5GFkewPCOFY-tYn4J2vQ_1778673159 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8FF80180034C; Wed, 13 May 2026 11:52:39 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D804D1955D84; Wed, 13 May 2026 11:52:37 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v4 08/10] vu_common: Pass explicit frame length to vu_flush() Date: Wed, 13 May 2026 13:52:16 +0200 Message-ID: <20260513115218.1662850-9-lvivier@redhat.com> In-Reply-To: <20260513115218.1662850-1-lvivier@redhat.com> References: <20260513115218.1662850-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: z_c3rTnoVhTLtXZ5FwPKTlXyqXDQulrAiPkAwaNygw4_1778673159 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: XYW23JE5SIKX5TTFZUET72DDALBPAO37 X-Message-ID-Hash: XYW23JE5SIKX5TTFZUET72DDALBPAO37 X-MailFrom: lvivier@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: Laurent Vivier , David Gibson , Jon Maloy 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: Currently vu_flush() derives the frame size from the iov, but in preparation for iov arrays that may be larger than the actual frame, pass the total length (including vnet header) explicitly so that only the relevant portion is reported to the virtqueue. Ensure a minimum frame size of ETH_ZLEN + VNET_HLEN to handle short frames. All elements are still flushed to avoid descriptor leaks, but trailing elements beyond frame_len will report a zero length. Signed-off-by: Laurent Vivier Reviewed-by: David Gibson Reviewed-by: Jon Maloy --- tcp_vu.c | 6 +++--- udp_vu.c | 2 +- vu_common.c | 16 ++++++++++++---- vu_common.h | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tcp_vu.c b/tcp_vu.c index d6f38754859c..d744ec705911 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -142,7 +142,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) vu_pad(&flags_elem[0].in_sg[0], l2len); - vu_flush(vdev, vq, flags_elem, 1); + vu_flush(vdev, vq, flags_elem, 1, hdrlen + optlen); if (*c->pcap) pcap_iov(&flags_elem[0].in_sg[0], 1, VNET_HLEN, l2len); @@ -158,7 +158,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) flags_elem[0].in_sg[0].iov_base, flags_elem[0].in_sg[0].iov_len); - vu_flush(vdev, vq, &flags_elem[1], 1); + vu_flush(vdev, vq, &flags_elem[1], 1, hdrlen + optlen); if (*c->pcap) { pcap_iov(&flags_elem[1].in_sg[0], 1, VNET_HLEN, @@ -465,7 +465,7 @@ 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); + vu_flush(vdev, vq, &elem[head[i]], buf_cnt, dlen + hdrlen); if (*c->pcap) pcap_iov(iov, buf_cnt, VNET_HLEN, l2len); diff --git a/udp_vu.c b/udp_vu.c index 3ff643478616..3c9fff53324c 100644 --- a/udp_vu.c +++ b/udp_vu.c @@ -231,7 +231,7 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx) pcap_iov(iov_vu, iov_cnt, VNET_HLEN, hdrlen + dlen - VNET_HLEN); } - vu_flush(vdev, vq, elem, elem_used); + vu_flush(vdev, vq, elem, elem_used, hdrlen + dlen); vu_queue_notify(vdev, vq); } } diff --git a/vu_common.c b/vu_common.c index f254cb67ec78..704e908aa02c 100644 --- a/vu_common.c +++ b/vu_common.c @@ -134,18 +134,26 @@ static void vu_set_vnethdr(struct virtio_net_hdr_mrg_rxbuf *vnethdr, * @vq: vhost-user virtqueue * @elem: virtqueue elements array to send back to the virtqueue * @elem_cnt: Length of the array + * @frame_len: Total frame length including vnet header */ void vu_flush(const struct vu_dev *vdev, struct vu_virtq *vq, - struct vu_virtq_element *elem, int elem_cnt) + struct vu_virtq_element *elem, int elem_cnt, size_t frame_len) { + size_t len; int i; vu_set_vnethdr(elem[0].in_sg[0].iov_base, elem_cnt); + len = MAX(ETH_ZLEN + VNET_HLEN, frame_len); for (i = 0; i < elem_cnt; i++) { - size_t elem_size = iov_size(elem[i].in_sg, elem[i].in_num); + size_t elem_size, fill_size; - vu_queue_fill(vdev, vq, &elem[i], elem_size, i); + elem_size = iov_size(elem[i].in_sg, elem[i].in_num); + fill_size = MIN(elem_size, len); + + vu_queue_fill(vdev, vq, &elem[i], fill_size, i); + + len -= fill_size; } vu_queue_flush(vdev, vq, elem_cnt); @@ -270,7 +278,7 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) if (*c->pcap) pcap_iov(in_sg, in_total, VNET_HLEN, size); - vu_flush(vdev, vq, elem, elem_cnt); + vu_flush(vdev, vq, elem, elem_cnt, VNET_HLEN + size); vu_queue_notify(vdev, vq); trace("vhost-user sent %zu", total); diff --git a/vu_common.h b/vu_common.h index 4037ab765b7d..77d1849e6115 100644 --- a/vu_common.h +++ b/vu_common.h @@ -40,7 +40,7 @@ int vu_collect(const struct vu_dev *vdev, struct vu_virtq *vq, struct iovec *in_sg, size_t max_in_sg, size_t *in_total, size_t size, size_t *collected); void vu_flush(const struct vu_dev *vdev, struct vu_virtq *vq, - struct vu_virtq_element *elem, int elem_cnt); + struct vu_virtq_element *elem, int elem_cnt, size_t frame_len); void vu_kick_cb(struct vu_dev *vdev, union epoll_ref ref, const struct timespec *now); int vu_send_single(const struct ctx *c, const void *buf, size_t size); -- 2.54.0