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 v6 1/3] udp_vu: Allow virtqueue elements with multiple iovec entries
Date: Fri, 3 Apr 2026 17:18:23 +0200	[thread overview]
Message-ID: <032ffd0c-1f46-435b-adeb-7cceea4d30b7@redhat.com> (raw)
In-Reply-To: <20260403135309.1d84f5dd@elisabeth>

On 4/3/26 13:53, Stefano Brivio wrote:
> On Wed,  1 Apr 2026 21:23:24 +0200
> Laurent Vivier <lvivier@redhat.com> wrote:
> 
>> The previous code assumed a 1:1 mapping between virtqueue elements and
>> iovec entries (enforced by an assert).  Drop that assumption to allow
>> elements that span multiple iovecs: track elem_used separately by
>> walking the element list against the iov count returned after padding.
>> This also fixes vu_queue_rewind() and vu_flush() to use the element
>> count rather than the iov count.
>>
>> Use iov_tail_clone() in udp_vu_sock_recv() to handle header offset,
>> replacing the manual base/len adjustment and restore pattern.
>>
>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>> ---
>>   udp_vu.c | 29 ++++++++++++++---------------
>>   1 file changed, 14 insertions(+), 15 deletions(-)
>>
>> diff --git a/udp_vu.c b/udp_vu.c
>> index 30af64034516..5608a3a96ff5 100644
>> --- a/udp_vu.c
>> +++ b/udp_vu.c
>> @@ -64,30 +64,25 @@ static size_t udp_vu_hdrlen(bool v6)
>>    */
>>   static ssize_t udp_vu_sock_recv(struct iovec *iov, size_t *cnt, int s, bool v6)
>>   {
>> +	struct iovec msg_iov[*cnt];
> 
> Variable-length Arrays (VLAs) are allowed starting from C99 but we
> should really really avoid them. If 'cnt' is big enough, we risk
> writing all over the place. That's the main reason why they were more
> or less banned from the Linux kernel some years ago and eventually
> eradicated:

I can use alloca() if you prefer ;)

> 
>    https://lore.kernel.org/lkml/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com/
> 
>    https://lore.kernel.org/lkml/20181028172401.GA41102@beast/
> 
> Can we use VIRTQUEUE_MAX_SIZE as upper bound like udp_vu_sock_to_tap()
> does?

Yes, but the idea here is we have always *cnt < VIRTQUEUE_MAX_SIZE
(because the value comes from vu_collect() and in vu_collect():
*in_sg (&iov_cnt or *cnt) < max_in_sg (ARRAY_SIZE(iov_vu) or VIRTQUEUE_MAX_SIZE or 1024)

And vu_collect(), in this case, sets generally *in_sg to a value lower than 44:
we want to create a frame of ETH_MAX_MTU by coalescing kernel buffers of size ETH_FRAME_LEN)

For me 16 kB on the stack is a lot of memory (but I started programming on a 48 kB RAM 
computer...).

Thanks,
Laurent


  reply	other threads:[~2026-04-03 15:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01 19:23 [PATCH v6 0/3] vhost-user,udp: Handle multiple iovec entries per virtqueue element Laurent Vivier
2026-04-01 19:23 ` [PATCH v6 1/3] udp_vu: Allow virtqueue elements with multiple iovec entries Laurent Vivier
2026-04-03 11:53   ` Stefano Brivio
2026-04-03 15:18     ` Laurent Vivier [this message]
2026-04-03 16:59       ` Stefano Brivio
2026-04-03 17:14         ` Laurent Vivier
2026-04-01 19:23 ` [PATCH v6 2/3] iov: Introduce IOV_PUSH_HEADER() macro Laurent Vivier
2026-04-01 19:23 ` [PATCH v6 3/3] udp: Pass iov_tail to udp_update_hdr4()/udp_update_hdr6() Laurent Vivier
2026-04-03 11:53   ` Stefano Brivio

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=032ffd0c-1f46-435b-adeb-7cceea4d30b7@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).