public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 10/10] vhost-user: Centralise Ethernet frame padding in vu_collect() and vu_pad()
Date: Wed, 15 Apr 2026 12:46:50 +0200	[thread overview]
Message-ID: <9be96a62-779b-4ccf-8c3a-da555c9270c3@redhat.com> (raw)
In-Reply-To: <adimoK1DnZAMtpH2@zatzit>

On 4/10/26 09:28, David Gibson wrote:
> On Fri, Apr 03, 2026 at 06:38:11PM +0200, Laurent Vivier wrote:
>> The previous per-protocol padding done by vu_pad() in tcp_vu.c and
>> udp_vu.c was only correct for single-buffer frames: it assumed the
>> padding area always fell within the first iov, writing past its end
>> with a plain memset().
>>
>> It also required each caller to compute MAX(..., ETH_ZLEN + VNET_HLEN)
>> for vu_collect() and to call vu_pad() at the right point, duplicating
>> the minimum-size logic across protocols.
>>
>> Move the Ethernet minimum size enforcement into vu_collect() itself, so
>> that enough buffer space is always reserved for padding regardless of
>> the requested frame size.
>>
>> Rewrite vu_pad() to take a full iovec array and use iov_memset(),
>> making it safe for multi-buffer (mergeable rx buffer) frames.
>>
>> In tcp_vu_sock_recv(), replace iov_truncate() with iov_skip_bytes():
>> now that all consumers receive explicit data lengths, truncating the
>> iovecs is no longer needed.  In tcp_vu_data_from_sock(), cap each
>> frame's data length against the remaining bytes actually received from
>> the socket, so that the last partial frame gets correct headers and
>> sequence number advancement.
>>
>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>> ---
>>   iov.c       |  1 -
>>   tcp_vu.c    | 34 ++++++++++++++++++----------------
>>   udp_vu.c    | 14 ++++++++------
>>   vu_common.c | 31 +++++++++++++++----------------
>>   vu_common.h |  2 +-
>>   5 files changed, 42 insertions(+), 40 deletions(-)
>>
>> diff --git a/iov.c b/iov.c
>> index dabc4f1ceea3..28c6d40d2986 100644
>> --- a/iov.c
>> +++ b/iov.c
>> @@ -180,7 +180,6 @@ size_t iov_truncate(struct iovec *iov, size_t iov_cnt, size_t size)
>>    * 		Will write less than @length bytes if it runs out of space in
>>    * 		the iov
>>    */
>> -/* cppcheck-suppress unusedFunction */
>>   void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c,
>>   		size_t length)
>>   {
>> diff --git a/tcp_vu.c b/tcp_vu.c
>> index 8c1894dca7fe..2dfe14485eee 100644
>> --- a/tcp_vu.c
>> +++ b/tcp_vu.c
>> @@ -88,7 +88,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
>>   
>>   	elem_cnt = vu_collect(vdev, vq, &flags_elem[0], 1,
>>   			      &flags_iov[0], 1, NULL,
>> -			      MAX(hdrlen + sizeof(*opts), ETH_ZLEN + VNET_HLEN), NULL);
>> +			      hdrlen + sizeof(*opts), NULL);
>>   	if (elem_cnt != 1)
>>   		return -1;
>>   
>> @@ -128,8 +128,6 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
>>   		return ret;
>>   	}
>>   
>> -	l2len = hdrlen + optlen - VNET_HLEN;
>> -	iov_truncate(&flags_iov[0], 1, l2len + VNET_HLEN);
>>   	payload = IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen);
>>   
>>   	if (flags & KEEPALIVE)
>> @@ -138,17 +136,17 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
>>   	tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload,
>>   			 optlen, NULL, seq, !*c->pcap);
>>   
>> -	vu_pad(&flags_elem[0].in_sg[0], l2len);
>> -
>> +	vu_pad(flags_elem[0].in_sg, 1, hdrlen + optlen);
> 
> Is there a reason not to fold vu_pad() into vu_flush()?

Yes, vu_pad() needs iovec while vu_flush() takes elements.

See in TCP series, '[PATCH v5 3/4] tcp_vu: Support multibuffer frames in 
tcp_vu_sock_recv()' (20260403170419.3233031-4-lvivier@redhat.com):

     vu_pad(&iov[frame[i].idx_iovec], frame[i].num_iovec, dlen + hdrlen);
     vu_flush(vdev, vq, &elem[frame[i].idx_element], frame[i].num_element, dlen + hdrlen);

> 
>>   	vu_flush(vdev, vq, flags_elem, 1, hdrlen + optlen);
>>   

Thanks,
Laurent


      reply	other threads:[~2026-04-15 10:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03 16:38 [PATCH v2 00/10] vhost-user: Preparatory series for multiple iovec entries per virtqueue element Laurent Vivier
2026-04-03 16:38 ` [PATCH v2 01/10] iov: Introduce iov_memset() Laurent Vivier
2026-04-03 16:38 ` [PATCH v2 02/10] iov: Add iov_memcpy() to copy data between iovec arrays Laurent Vivier
2026-04-10  6:44   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 03/10] vu_common: Move vnethdr setup into vu_flush() Laurent Vivier
2026-04-10  6:47   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 04/10] udp_vu: Move virtqueue management from udp_vu_sock_recv() to its caller Laurent Vivier
2026-04-10  6:56   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 05/10] udp_vu: Pass iov explicitly to helpers instead of using file-scoped array Laurent Vivier
2026-04-10  6:59   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 06/10] checksum: Pass explicit L4 length to checksum functions Laurent Vivier
2026-04-10  7:12   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 07/10] pcap: Pass explicit L2 length to pcap_iov() Laurent Vivier
2026-04-10  7:17   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 08/10] vu_common: Pass explicit frame length to vu_flush() Laurent Vivier
2026-04-10  7:21   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 09/10] tcp: Pass explicit data length to tcp_fill_headers() Laurent Vivier
2026-04-10  7:23   ` David Gibson
2026-04-03 16:38 ` [PATCH v2 10/10] vhost-user: Centralise Ethernet frame padding in vu_collect() and vu_pad() Laurent Vivier
2026-04-10  7:28   ` David Gibson
2026-04-15 10:46     ` 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=9be96a62-779b-4ccf-8c3a-da555c9270c3@redhat.com \
    --to=lvivier@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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).