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=hfBtWvKq; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 61E445A0626 for ; Fri, 03 Apr 2026 12:25:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775211941; 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:autocrypt:autocrypt; bh=X/tq4w39+s6AvZsnGlKBxd8v/JEUWlGebgerYcrx2Z0=; b=hfBtWvKqd9oaBTVET/xnNk7vqDU3mG/yy0lwyAmOrbFhk1DQGVtdZqvWxX6JUTyQBKQZoP rxF4M0+zCw3GdKwXIPjICTXgZKRAzhdUPbwEpptp4+Su5acflTo2RpO/Y/4zxLG7i3dkyz efdCAXgOGIIwV/cWbrA3ga77LehGZ+I= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-tknK2SB9MjCx_Yux8l148w-1; Fri, 03 Apr 2026 06:25:40 -0400 X-MC-Unique: tknK2SB9MjCx_Yux8l148w-1 X-Mimecast-MFC-AGG-ID: tknK2SB9MjCx_Yux8l148w_1775211939 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4837b6f6b93so20947855e9.3 for ; Fri, 03 Apr 2026 03:25:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775211939; x=1775816739; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=X/tq4w39+s6AvZsnGlKBxd8v/JEUWlGebgerYcrx2Z0=; b=n1TLwcZQNQdkZTKku4ge8fvAhSHa1yYLfw0VdabvGoviVis90cLnUsFY6IuLsFzZKe 6AMQUxT/HfijD8DmTq0oZAT96JIvO1+FLicDAE9MyMaunOVXhzvpLx75ayb7woCi1Elk DAV//EgzoZLNN9BU12/fcfIijtOUhEuU4V2JT5ueo12kD+ut2WU1cF7Gu/AUVd/7fxDx Qw701DxdmVhA+WcJ8hDKuEmFOoqFmYER6yqbK/+d7gVrdRaD/TuFVsAlQ+4tykE2mZ/P +S+oGHyTcs3ZzSrptv6zK7qPLivWgpSDVklfTha7YrGgS9wKnftMZFbMndqfsZPSHGwF GgYQ== X-Gm-Message-State: AOJu0YxeVkryrZTddiR7RjYzKP85mi0qhSIJRlJyWVUsHZSvdQir7ur3 4CCeHQOOowRKuaggCewZM5KcJjMFI3dMo4Xrpp4ziV6c7G4U9fyLCt3eIzDbSLiup/JbHekfN9h DQJVIKmb3bJ2glUG14RxoLNnwBoKPOk2oT5NjnuMN44ahPno8r6W2mw== X-Gm-Gg: ATEYQzzgjzjI83dQEBGpy52KZ6TlQ0V5I8RROBu9WYa+STLMmiR+fUNW6jEhVmwk69G gWktG1nsBNKt8Tjjz03dzfPVYyngPIeTHjaK1X/om6YYBooxVyooQZoQZ6b9x16GXrHlNX+A73d TlHPbIGFnBCTqamAGjWW+Qe+5bPRVkQv+9jfJ8d2XZ4MYGeChiztRdPEC/BHE+jo7AvapUDolnT 7J6Lt73TcMKqDiB5TNBWLOeYosDBu0cCOF3dkioG/xtTmPj5gW2jzi7BrMNOfgySuThdPlcoMCT wUPmkENXyDYjArJtX0fG1k3h+StdGgjmhh37/n2Yhz2J0LltPJDp4TtODCvJgVwwnZEQp9GwEGv ID7Ieke8EplNpqjXDBbQMjf9YZSuITO9B8BMOJ9t+vO6b7Xan4pl3bT0= X-Received: by 2002:a05:600c:c8d:b0:486:ffa3:594 with SMTP id 5b1f17b1804b1-488997a6883mr36740625e9.23.1775211938763; Fri, 03 Apr 2026 03:25:38 -0700 (PDT) X-Received: by 2002:a05:600c:c8d:b0:486:ffa3:594 with SMTP id 5b1f17b1804b1-488997a6883mr36740215e9.23.1775211938174; Fri, 03 Apr 2026 03:25:38 -0700 (PDT) Received: from [192.168.100.100] (82-64-211-94.subs.proxad.net. [82.64.211.94]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48897fd5f3csm28422805e9.2.2026.04.03.03.25.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Apr 2026 03:25:37 -0700 (PDT) Message-ID: <385c54b8-4bc7-4a8f-af21-94696eaed75d@redhat.com> Date: Fri, 3 Apr 2026 12:25:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 10/10] vhost-user: Centralise Ethernet frame padding in vu_collect() and vu_pad() To: Stefano Brivio References: <20260401191826.1782394-1-lvivier@redhat.com> <20260401191826.1782394-11-lvivier@redhat.com> <20260403082052.3cfebb68@elisabeth> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; keydata= xsFNBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJJJfphbbv82glIC/Ei4Ky8BwZkUuXd7d5NFJKC9/GDrbWdj75cDNQx UZ9XXbXEKY9MHX83Uy7JFoiFDMOVHn55HnncflUncO0zDzY7CxFeQFwYRbsCXOUL9yBtqLer Ky8/yjBskIlNrp0uQSt9LMoMsdSjYLYhvk1StsNPg74+s4u0Q6z45+l8RAsgLw5OLtTa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Bp P4W98bXCBIuQgs2m+OflERv5c3Ojldp04/S4NEjXEYRWdiCxN7ca5iPml5gLtuvhJMSy36gl U6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2TxL8enfx40PrfbDtWwqRID3WY8jLrjKfTd R3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPM oDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: <20260403082052.3cfebb68@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: SqGp0ioCoycFbYRFp5Z2DZ3rHc6ACSN6ODn_e9f-zQ4_1775211939 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: FUSI5OXRVPBIYCEVBJ5GN4W7F2VRHI4L X-Message-ID-Hash: FUSI5OXRVPBIYCEVBJ5GN4W7F2VRHI4L 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: passt-dev@passt.top 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: On 4/3/26 08:20, Stefano Brivio wrote: > On Wed, 1 Apr 2026 21:18:26 +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 >> --- >> iov.c | 1 - >> tcp_vu.c | 29 ++++++++++++++--------------- >> udp_vu.c | 14 ++++++++------ >> vu_common.c | 32 +++++++++++++++----------------- >> vu_common.h | 2 +- >> 5 files changed, 38 insertions(+), 40 deletions(-) >> >> diff --git a/iov.c b/iov.c >> index 83b683f3976a..2289b425529e 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 ae79a6d856b0..cae6926334b9 100644 >> --- a/tcp_vu.c >> +++ b/tcp_vu.c >> @@ -72,12 +72,12 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) >> struct vu_dev *vdev = c->vdev; >> struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; >> struct vu_virtq_element flags_elem[2]; >> - size_t optlen, hdrlen, l2len; >> struct ipv6hdr *ip6h = NULL; >> struct iphdr *ip4h = NULL; >> struct iovec flags_iov[2]; >> struct tcp_syn_opts *opts; >> struct iov_tail payload; >> + size_t optlen, hdrlen; >> struct tcphdr *th; >> struct ethhdr *eh; >> uint32_t seq; >> @@ -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,7 +128,6 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) >> return ret; >> } >> >> - iov_truncate(&flags_iov[0], 1, hdrlen + optlen); >> payload = IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen); >> >> if (flags & KEEPALIVE) >> @@ -137,9 +136,7 @@ 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); >> >> - l2len = optlen + hdrlen - VNET_HLEN; >> - vu_pad(&flags_elem[0].in_sg[0], l2len); >> - >> + vu_pad(flags_elem[0].in_sg, 1, hdrlen + optlen); >> vu_flush(vdev, vq, flags_elem, 1, hdrlen + optlen); >> >> if (*c->pcap) >> @@ -149,7 +146,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) >> if (flags & DUP_ACK) { >> elem_cnt = vu_collect(vdev, vq, &flags_elem[1], 1, >> &flags_iov[1], 1, NULL, >> - flags_elem[0].in_sg[0].iov_len, NULL); >> + hdrlen + optlen, NULL); >> if (elem_cnt == 1 && >> flags_elem[1].in_sg[0].iov_len >= >> flags_elem[0].in_sg[0].iov_len) { >> @@ -213,7 +210,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, >> ARRAY_SIZE(elem) - elem_cnt, >> &iov_vu[DISCARD_IOV_NUM + iov_used], >> VIRTQUEUE_MAX_SIZE - iov_used, &in_total, >> - MAX(MIN(mss, fillsize) + hdrlen, ETH_ZLEN + VNET_HLEN), >> + MIN(mss, fillsize) + hdrlen, >> &frame_size); >> if (cnt == 0) >> break; >> @@ -249,8 +246,11 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, >> if (!peek_offset_cap) >> ret -= already_sent; >> >> - /* adjust iov number and length of the last iov */ >> - i = iov_truncate(&iov_vu[DISCARD_IOV_NUM], iov_used, ret); >> + i = iov_skip_bytes(&iov_vu[DISCARD_IOV_NUM], iov_used, >> + MAX(hdrlen + ret, VNET_HLEN + ETH_ZLEN), >> + NULL); > > Nit: this should be aligned like this: > > i = iov_skip_bytes(&iov_vu[DISCARD_IOV_NUM], iov_used, > MAX(hdrlen + ret, VNET_HLEN + ETH_ZLEN), > NULL); > >> + if ((size_t)i < iov_used) >> + i++; > > I'm a bit lost here. I see that this increment restores the > iov_truncate() convention of returning the number of iov items (which iov_truncate() was truncating the iovec array (reducing the cnt and iov_len of the last iovec) to fit the actual size of the data. Here we are counting the number of elements: we have collected more elements than needed to store the data, so we need to know how many we use to give back the unused to the virtio-queue. Again, the confusing point is that we have the same number of elements as the number of iovec. It's fixed in the following series. > we need later), but... what happens if we have i >= iov_used (even > though my assumption is that it should never happen)? We're throwing > away data? >i cannot be greater than iov_used. if i == iov_used, it means we need all the elements. Thanks, Laurent