On 2/23/26 10:57, Laurent Vivier wrote:
On 2/15/26 11:56, Stefano Brivio wrote:
On Thu, 12 Feb 2026 12:39:32 +0100 Laurent Vivier
wrote: In the vhost-user paths, the buffers provided by the virtio queue include the virtio net header (VNET_HLEN) prepended to the Ethernet frame. The minimum size checks using ETH_ZLEN must therefore account for this additional header length, otherwise we underestimate the minimum buffer size needed.
Use ETH_ZLEN + VNET_HLEN instead of bare ETH_ZLEN in vu_collect() calls and the corresponding ASSERT() checks.
Fixes: 0cb8f9003654 ("tcp, udp: Pad batched frames for vhost-user modes to 60 bytes (802.3 minimum)") Signed-off-by: Laurent Vivier
--- tcp_vu.c | 8 ++++---- udp_vu.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tcp_vu.c b/tcp_vu.c index f7bda4943e43..2d593d534d68 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -90,12 +90,12 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) vu_set_element(&flags_elem[0], NULL, &flags_iov[0]); elem_cnt = vu_collect(vdev, vq, &flags_elem[0], 1, - MAX(hdrlen + sizeof(*opts), ETH_ZLEN), NULL); + MAX(hdrlen + sizeof(*opts), ETH_ZLEN + VNET_HLEN), NULL); if (elem_cnt != 1) return -1; ASSERT(flags_elem[0].in_sg[0].iov_len >= - MAX(hdrlen + sizeof(*opts), ETH_ZLEN)); + MAX(hdrlen + sizeof(*opts), ETH_ZLEN + VNET_HLEN)); vu_set_vnethdr(vdev, flags_elem[0].in_sg[0].iov_base, 1); @@ -208,7 +208,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, cnt = vu_collect(vdev, vq, &elem[elem_cnt], VIRTQUEUE_MAX_SIZE - elem_cnt, - MAX(MIN(mss, fillsize) + hdrlen, ETH_ZLEN), + MAX(MIN(mss, fillsize) + hdrlen, ETH_ZLEN + VNET_HLEN), &frame_size); if (cnt == 0) break; @@ -302,7 +302,7 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, /* we guess the first iovec provided by the guest can embed * all the headers needed by L2 frame, including any padding */ - ASSERT(iov[0].iov_len >= MAX(hdrlen, ETH_ZLEN)); + ASSERT(iov[0].iov_len >= MAX(hdrlen, ETH_ZLEN + VNET_HLEN));
This triggers in the passt_vu_in_ns/tcp, "TCP/IPv4: host to guest: big transfer" test case, that is, the first time we connect to the guest (probably on the initial SYN segment).
I didn't check why.
After tcp_vu_sock_recv(), iov[0].iov_len is set to the size of hdrlen + received data, it's why in tcp_vu_prepare() iov_len can be shorter than expected. As the actual buffer size is already guaranteed by vu_collect(), I think the ASSERT() should be reverted to ASSERT(iov[0].iov_len >= hdrlen).
Moreover there is a problem with vu_pad() in tcp_vu.c that includes the VNET_HLEN (it should not), see udp_vu.c
In fact, the padding is wrong in udp_vu.c, not in tcp_vu.c Thanks, Laurent