public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 2/2] tcp_vu, udp_vu: Account for virtio net header in minimum frame size
Date: Mon, 23 Feb 2026 11:06:30 +0100	[thread overview]
Message-ID: <eb0fbd09-6af3-44e9-8730-1a403ff7edb0@redhat.com> (raw)
In-Reply-To: <6bdd7a8c-bdcb-43d8-a03f-d0a2f9468316@vivier.eu>

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 <lvivier@redhat.com> 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 <lvivier@redhat.com>
>>> ---
>>>   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


      reply	other threads:[~2026-02-23 10:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-12 11:39 [PATCH 0/2] Fix minimum frame size checks in vhost-user paths Laurent Vivier
2026-02-12 11:39 ` [PATCH 1/2] virtio: Introduce VNET_HLEN macro for virtio net header length Laurent Vivier
2026-02-13 11:47   ` Stefano Brivio
2026-02-12 11:39 ` [PATCH 2/2] tcp_vu, udp_vu: Account for virtio net header in minimum frame size Laurent Vivier
2026-02-13 11:48   ` Stefano Brivio
2026-02-15 10:56   ` Stefano Brivio
2026-02-23  9:57     ` Laurent Vivier
2026-02-23 10:06       ` Laurent Vivier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb0fbd09-6af3-44e9-8730-1a403ff7edb0@redhat.com \
    --to=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).