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=BmjAyySc; 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 80AB45A026F for ; Tue, 04 Nov 2025 17:09:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762272588; 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; bh=wSg0avwAUqynTxjaU1zXKBEdcaaLqBFa1bToSG85REk=; b=BmjAyySc3NyhMFwc7WWZN1lfugqSgggHXfE+Lv2dxUW9uRR/h7/ZsKRrDCgZK8TjdQKDZs J+6y9VgXre5phudtxlgkKndhvaazz+3SB8+UZkTFmABS7MyjTgjl32DnoIJW0Jpoh6Vpc+ 4b+Kawr2gSEn46bTFwXCSyKNDSIfWCQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-4EUailONO625zQ8wH-no2Q-1; Tue, 04 Nov 2025 11:09:47 -0500 X-MC-Unique: 4EUailONO625zQ8wH-no2Q-1 X-Mimecast-MFC-AGG-ID: 4EUailONO625zQ8wH-no2Q_1762272586 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-470fd92ad57so67604525e9.3 for ; Tue, 04 Nov 2025 08:09:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762272586; x=1762877386; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wSg0avwAUqynTxjaU1zXKBEdcaaLqBFa1bToSG85REk=; b=K2mpbo6CHrvwDPJCfAKZQvzhD5xi1G0lYOBaFR7bJllrHDp22d0SWXKSpgrIwSTSc6 xM0kgk6sUbgCDwPklL0U/asigc8QCHH3fX40rjs53HaVZs2ENkQXbMzBr/Wc0uF6zq7g YJeU+jnP1prH8/CqaMTEOs1GD28BN0wJCcTRph2ZCpopZgp802b+ThPEbNuyw8YZGRTN HAOG92jMiwfK5J0iQATciNLooi9eKuIWdtZfeXyl7dSETBKTM+R0dPbPQlBfOvHfmjv+ hUHZWa4ZZoVxPGQ+cxeC9I6+fjVVB/MkteXj5D4Vj0bqCSX8y4wXeVJ+pUSzdoUa3tVN gsHA== X-Gm-Message-State: AOJu0YwMJPv6j5ggIbrkAsdLO9epYs+AR4MUJ3KCfhPv/rNyIHQ6LVBy VmBocwfLaDHo4wA0p3lTx+59tfGYV8thz97P56TAR+PAmRKxIFGpyBQMceApRkwwhxBp/hPQqYa 5kTZFYGXQhTRBgHLCbvLC1gdkIBHW1tyrYpaEIHTutqIfVXlYrfWqUw== X-Gm-Gg: ASbGncvhEw4wNh7Gor27Fl+qwmnIGyQe5JuDQ5fx5pXCGMrRxXIzxQsARzyWPH/msQg a3/v68jESgwFuDH2SxESP8HOhE9l1koGqXuhnF1J44hsacAryrCLLs3R6gaBtwjCZBsn+YwVSSX KMEDNg88y2vD+QihiU/kfu37eQe7P3CD1HhH9fsaMl/ZksAFrcz1Lpm0YhKZeVG2varXB6E9ppQ m29VBeWEBigea1J1xNmsBTG72+QehsADbAIui5F3qxI9+BQ4IEL5twITXuorOX5XivUfiX3GLIu UuFuyhBQeRO87tRYOElqiqnBkqv+/c31Hde1PS8BRKeDuWE9zF2uPKJoTzSFvpDi+aoFujbVNku lN3jPidfGZJPkrt6LTx/Nm5IaRXA= X-Received: by 2002:a05:600d:4393:b0:475:de14:db25 with SMTP id 5b1f17b1804b1-477331eb282mr118568805e9.28.1762272585564; Tue, 04 Nov 2025 08:09:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IF94IjGwyHgAlRAAGxGqIBI3ZUcneopSdhD5+b1DCs3rWOPlyfpH39QRKVEuBrEadCLcI2vQA== X-Received: by 2002:a05:600d:4393:b0:475:de14:db25 with SMTP id 5b1f17b1804b1-477331eb282mr118568415e9.28.1762272585045; Tue, 04 Nov 2025 08:09:45 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4773c3a77b1sm221965965e9.17.2025.11.04.08.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:09:44 -0800 (PST) Date: Tue, 4 Nov 2025 17:09:43 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [RFC PATCH 5/5] tcp, udp: Pad batched frames for vhost-user modes to 60 bytes (802.3 minimum) Message-ID: <20251104170943.51dd7d04@elisabeth> In-Reply-To: <9d79c64e-e222-4444-8677-81891cd8fea3@redhat.com> References: <20251103101612.1412079-1-sbrivio@redhat.com> <20251103101612.1412079-6-sbrivio@redhat.com> <9d79c64e-e222-4444-8677-81891cd8fea3@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zmN5XYS0X8w0m0JaBhfysG4le8tNdZlc4dEiW6P6-Gs_1762272586 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 6HFQLZ7F365TLIOGEHNGYFT5WB4UKTLV X-Message-ID-Hash: 6HFQLZ7F365TLIOGEHNGYFT5WB4UKTLV X-MailFrom: sbrivio@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, David Gibson 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 Tue, 4 Nov 2025 16:50:43 +0100 Laurent Vivier wrote: > On 11/3/25 11:16, Stefano Brivio wrote: > > For both TCP and UDP, we request vhost-user buffers that are large > > enough to reach ETH_ZLEN (60 bytes), so padding is just a matter of > > increasing the appropriate iov_len and clearing bytes in the buffer > > as needed. > > > > Link: https://bugs.passt.top/show_bug.cgi?id=166 > > Signed-off-by: Stefano Brivio > > --- > > tcp.c | 2 -- > > tcp_internal.h | 1 + > > tcp_vu.c | 27 +++++++++++++++++++++++++++ > > udp_vu.c | 11 ++++++++++- > > 4 files changed, 38 insertions(+), 3 deletions(-) > > > > diff --git a/tcp.c b/tcp.c > > index e91c0cf..039688d 100644 > > --- a/tcp.c > > +++ b/tcp.c > > @@ -335,8 +335,6 @@ enum { > > }; > > #endif > > > > -/* MSS rounding: see SET_MSS() */ > > -#define MSS_DEFAULT 536 > > #define WINDOW_DEFAULT 14600 /* RFC 6928 */ > > > > #define ACK_INTERVAL 10 /* ms */ > > diff --git a/tcp_internal.h b/tcp_internal.h > > index 5f8fb35..d2295c9 100644 > > --- a/tcp_internal.h > > +++ b/tcp_internal.h > > @@ -12,6 +12,7 @@ > > #define BUF_DISCARD_SIZE (1 << 20) > > #define DISCARD_IOV_NUM DIV_ROUND_UP(MAX_WINDOW, BUF_DISCARD_SIZE) > > > > +#define MSS_DEFAULT /* and minimum */ 536 /* as it comes from minimum MTU */ > > #define MSS4 ROUND_DOWN(IP_MAX_MTU - \ > > sizeof(struct tcphdr) - \ > > sizeof(struct iphdr), \ > > diff --git a/tcp_vu.c b/tcp_vu.c > > index 1c81ce3..7239401 100644 > > --- a/tcp_vu.c > > +++ b/tcp_vu.c > > @@ -60,6 +60,29 @@ static size_t tcp_vu_hdrlen(bool v6) > > return hdrlen; > > } > > > > +/** > > + * tcp_vu_pad() - Pad 802.3 frame to minimum length (60 bytes) if needed > > + * @iov: iovec array storing 802.3 frame with TCP segment inside > > + * @cnt: Number of entries in @iov > > + */ > > +static void tcp_vu_pad(struct iovec *iov, size_t cnt) > > +{ > > + size_t l2len, pad; > > + > > + ASSERT(iov_size(iov, cnt) >= sizeof(struct virtio_net_hdr_mrg_rxbuf)); > > + l2len = iov_size(iov, cnt) - sizeof(struct virtio_net_hdr_mrg_rxbuf); > > + if (l2len >= ETH_ZLEN) > > + return; > > + > > + pad = ETH_ZLEN - l2len; > > + > > + /* tcp_vu_sock_recv() requests at least MSS-sized vhost-user buffers */ > > + static_assert(ETH_ZLEN <= MSS_DEFAULT); > > + > > + memset(&iov[cnt - 1].iov_base + iov[cnt - 1].iov_len, 0, pad); > > I think it should be > > memset((char *)iov[cnt - 1].iov_base + iov[cnt - 1].iov_len, 0, pad); Right, thanks, I always forget that sizeof(void) being 1 is a gcc extension: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html What's rather confusing, actually, is that even if I explicitly enable -Wpointer-arith, I don't get a warning for that. Any clue? > > > + iov[cnt - 1].iov_len += pad; > > +} > > + > > /** > > * tcp_vu_send_flag() - Send segment with flags to vhost-user (no payload) > > * @c: Execution context > > @@ -138,6 +161,8 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) > > tcp_fill_headers(c, conn, NULL, eh, ip4h, ip6h, th, &payload, > > NULL, seq, !*c->pcap); > > > > + tcp_vu_pad(&flags_elem[0].in_sg[0], 1); > > + > > if (*c->pcap) { > > pcap_iov(&flags_elem[0].in_sg[0], 1, > > sizeof(struct virtio_net_hdr_mrg_rxbuf)); > > @@ -456,6 +481,8 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) > > > > tcp_vu_prepare(c, conn, iov, buf_cnt, &check, !*c->pcap, push); > > > > + tcp_vu_pad(iov, buf_cnt); > > + > > if (*c->pcap) { > > pcap_iov(iov, buf_cnt, > > sizeof(struct virtio_net_hdr_mrg_rxbuf)); > > diff --git a/udp_vu.c b/udp_vu.c > > index 099677f..1b60860 100644 > > --- a/udp_vu.c > > +++ b/udp_vu.c > > @@ -72,8 +72,8 @@ static int udp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, int s, > > { > > const struct vu_dev *vdev = c->vdev; > > int iov_cnt, idx, iov_used; > > + size_t off, hdrlen, l2len; > > struct msghdr msg = { 0 }; > > - size_t off, hdrlen; > > > > ASSERT(!c->no_udp); > > > > @@ -116,6 +116,15 @@ static int udp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, int s, > > iov_vu[idx].iov_len = off; > > iov_used = idx + !!off; > > > > + /* pad 802.3 frame to 60 bytes if needed */ > > + l2len = *dlen + hdrlen - sizeof(struct virtio_net_hdr_mrg_rxbuf); > > + if (l2len < ETH_ZLEN) { > > + size_t pad = ETH_ZLEN - l2len; > > + > > + iov_vu[idx].iov_len += pad; > > + memset(&iov_vu[idx].iov_base + off, 0, pad); > > It should be: > > memset((char *)iov_vu[idx].iov_base + off, 0, pad); Fixing as well. > Perhaps clearer to write (off is not obvious, we need to check above): > > memset((char *)iov_vu[idx].iov_base + iov_vu[idx].iov_len, 0, pad); > iov_vu[idx].iov_len += pad; Definitely. I'll change this in v2. -- Stefano