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=i/aFpjo9; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 6E1485A026F for ; Tue, 04 Nov 2025 18:27:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762277220; 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=h0uxhjHSbRM6jR4ftxD6YHXJTPMMCoptbaKcQvL289s=; b=i/aFpjo9tpU51ASalpVBVJyQRou6Ea7l9DkqX5DkGtFi0nKPVWsmVSRF/q1sAVK9O2hGyp ul0gr6/ZO0aoDP4F6Boz3ZJngpkA8obQH6hfkfuZ+YLeBfsnnQeQBfLl2oqWjOTFob87tt QGnEWmGe9Kwm/AYyDcwcTHvemy9EvY4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-zpCc832HOyeV96n0RI7Deg-1; Tue, 04 Nov 2025 12:26:59 -0500 X-MC-Unique: zpCc832HOyeV96n0RI7Deg-1 X-Mimecast-MFC-AGG-ID: zpCc832HOyeV96n0RI7Deg_1762277218 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-429ce8ac89bso1845195f8f.1 for ; Tue, 04 Nov 2025 09:26:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762277218; x=1762882018; 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=h0uxhjHSbRM6jR4ftxD6YHXJTPMMCoptbaKcQvL289s=; b=mAcNkVwgVk1nv/L1/NTthAyWVrrZLoX2tgry7t9IPiom/K82gug0Sm5n3MO8bW2D4n ZyWQsnHU2QrM2eniINkM/5DiSqb8M970XR/FYO6mQpoWnjMZxVTBThtR0p4iBjOSa/fF 39DQ4OYSK3ejsgjosW6NnlRcPv4G5yrgVy1tZOJU29fxOcDMlbnhYVi7pbI5hIRx7IoQ w/qVxxI9Zf9oBpgGNnd7yIf5h2sBTjB+zd1ca5JPizzsMrIrW/jR38Hv8B+FxhKgLWKM A4wV/HzPNz5evi7LkljjCHLQovNDwYUnCm6i/+CmqqOZbikgNmenDfod13x9atsbSGBm a0/Q== X-Gm-Message-State: AOJu0YwIaWlpAedcllC4q85Zx1UkB2TE+bLo4ZpE6ZSA+PCTWwyBa5DT MBHwREIPfF5CUmT9qKDraroWSjwy+ad3f2nX45r61OyEvUgWy9MR3YrBqsH+K27QTwBpvgGG2mF 7A5gE+481T3D4gTjpfLms44qCD7f6tGrP6ctRSX2Dun6ufaEMlS4S2A== X-Gm-Gg: ASbGncv6ywmFXw0OWjaZ71t3tgsBeKRJKWpMBoce19AJv/heeUTyyD+8cGD1Ra8f7zw JlBpRICKfKBp1Th1jncrt3yuGc4tDJojHK0tGhSCR7b7uJw8T9qUtxQ0MKCg+H3ecYN6IrDpPfo AI0PO0bcfMQyGq9cqtwKBPpeX2G6aJg0+x1aR54UBEZVebA84haP7FvSi2LV6k2ZCD+5sUAuiXk 3aq1WmCy5S4EHZfBOFwFgvFBvZ9NUe9XhwsH7pyrorkn3nAKOyuHKMbpyOaB7Nd3zGgurbj2aJM QEz3haLwsIZ7I2dnujQoTmeWBfElLgJw3MgVMpjYPUgfN6OndsdZjwUwLvGT0K+TC7VCqX39Kdi Eu4H4yE2WLcOC8nqNHNaZbl58ohQ= X-Received: by 2002:a05:6000:40c7:b0:426:f40a:7179 with SMTP id ffacd0b85a97d-429e32ebe9dmr78422f8f.26.1762277217738; Tue, 04 Nov 2025 09:26:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoBWWxGyInA7/aQ5yTs5EOjWTUhW1EB4Q9ylZAtEyGsbyHPFDDNKLyuejwwoGoHd+yvdqFNA== X-Received: by 2002:a05:6000:40c7:b0:426:f40a:7179 with SMTP id ffacd0b85a97d-429e32ebe9dmr78392f8f.26.1762277217192; Tue, 04 Nov 2025 09:26:57 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429dc1f5be4sm5480797f8f.31.2025.11.04.09.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 09:26:56 -0800 (PST) Date: Tue, 4 Nov 2025 18:26:55 +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: <20251104182655.7725424d@elisabeth> In-Reply-To: <7d5858a5-0e13-48cf-be9a-7cd7cb47202d@redhat.com> References: <20251103101612.1412079-1-sbrivio@redhat.com> <20251103101612.1412079-6-sbrivio@redhat.com> <9d79c64e-e222-4444-8677-81891cd8fea3@redhat.com> <20251104170943.51dd7d04@elisabeth> <7d5858a5-0e13-48cf-be9a-7cd7cb47202d@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: tjpzczdfje23wOrE0Q40_rlEu3F3nayMOXVJUAfDe4Y_1762277218 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: RJ54S7XH463TGCUTDCA7KCXE2KEUJSAM X-Message-ID-Hash: RJ54S7XH463TGCUTDCA7KCXE2KEUJSAM 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 17:28:52 +0100 Laurent Vivier wrote: > On 11/4/25 17:09, Stefano Brivio wrote: > > 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? > > in fact it's sizeof(void **) as iov[cnt - 1].iov_base is (void *) and you take &(void *). > > Normally gcc spits out warnings when we do .iov_base + .iov_len, but as you take address > of iov_base all is fine :P Ouch, wow, how does it even work? I checked captures of most functional tests with vhost-user, connections worked and the right ACK segments had the right amount of padding. I guess it's just that there was nothing fundamental at the resulting address and we already happened to have zeroes in the buffers. Thanks for spotting that, I'll fix in v2. -- Stefano