From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=EkfQn2yn; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id BDFC25A0276 for ; Wed, 12 Feb 2025 01:57:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1739321833; bh=Q8K6LDiE9J1glJp7AWJ/Ntq9Pqg5QgRj1+xmYJ4czYU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EkfQn2ynf8N39ocE1Uz8v1p6AzyUiHktc4MAtk68MWYmDVTXV1Sa6KIpZUloBOtQp BmNOFveOlrpc6ZN0S9ehPd/Swu10Yc/P0jDCYw3fOs+HjOwDiArVlkHkpab/gDtdXq bMBjLXNkChSvbVhasK2kSRmzb6rz0vqYLPz4XAxgfPWIOHsaOI/cIA6YzI8nez5d9o v5Iq/FLpk/8i1BP7Cgt2BsfnN9D6hYbZ9BN6/oy6mtzSgB+q7Q2D1L9p2oFThgp1ZL fgHMwwt+yqF//CZvJP05Ry4x6I5vfC05zzav6xpunOoSJozIbj3lsrcGfxMOOEDz6t mhIDVmOJqrnNA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Yt0Jn1rMyz4wyk; Wed, 12 Feb 2025 11:57:13 +1100 (AEDT) Date: Wed, 12 Feb 2025 11:57:10 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] tcp_vu: Fix off-by one in header count array adjustment Message-ID: References: <20250211195133.198082-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Uk6zjKD/aJCqEW6Y" Content-Disposition: inline In-Reply-To: <20250211195133.198082-1-sbrivio@redhat.com> Message-ID-Hash: ZHXBQPRESOV2YCRWW67ZOPV6ZJULOLYL X-Message-ID-Hash: ZHXBQPRESOV2YCRWW67ZOPV6ZJULOLYL X-MailFrom: dgibson@gandalf.ozlabs.org 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, Laurent Vivier 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: --Uk6zjKD/aJCqEW6Y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 11, 2025 at 08:51:33PM +0100, Stefano Brivio wrote: > From: Laurent Vivier >=20 > Not entirely clear to me why, but Laurent proposed this patch to fix > an issue were we would end up with a zero buf_cnt in > tcp_vu_data_from_sock() and all sorts of weirdnesses. >=20 > Reported-by: David Gibson > [sbrivio: commit message, albeit not really descriptive] > Signed-off-by: Stefano Brivio I think I've understood the surrounding code enough to say, Reviewed-by: David Gibson and offer this possible description if we don't hear from Laurent in time. ### head_cnt represents the number of frames we're going to forward to the guest in tcp_vu_sock_recv(), each of which could require multiple buffers ("elements"). We initialise it with as many frames as we can find space for in vu buffers, and we then need to adjust it down to the number of frames we actually (partially) filled. We adjust it down based on number of individual buffers used by the data from recvmsg(). At this point 'i' is *one greater than* that number of buffers, so we need to discard all (unused) frames with a buffer index >=3D i, instead of > i. ### > --- > tcp_vu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/tcp_vu.c b/tcp_vu.c > index fad7065..0622f17 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -261,7 +261,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, > len -=3D iov->iov_len; > } > /* adjust head count */ > - while (head_cnt > 0 && head[head_cnt - 1] > i) > + while (head_cnt > 0 && head[head_cnt - 1] >=3D i) > head_cnt--; > /* mark end of array */ > head[head_cnt] =3D i; --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --Uk6zjKD/aJCqEW6Y Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmer8eUACgkQzQJF27ox 2Gc98Q//agg8wmA0kNllKQ7xSf018VfxHwaNataYxwJ6RzBjoNbM+pwZdXmlbA9O 8i4yihMVCCT3IGBxQY3xfjvbZ/155tOH6/hjc1RuPkQW3r2SC981+97HjGM2w8ym RxckeTGzI1da4T6GNf589yIOtywUR3RxZh8uY/ahjuBy67FjnDUFArcd0n+Fkloy m21pr01XvZ2l+TkD7LtQtjyn2BT65cxcHAQYzW0vgeDYfhR0WJIm7kaZ/SI114Em MjBZRYUbQ8PVSg8nUnAK3Mu8fuPWzNp1bt80K2IRqk8DR5qPQ0Hixd7e/VzfXHj2 lCddwgDR6TZeHG5nQv4gTWYaSfjcZTWReA95/KPWDkaBUm7JDwQ+BdLVZnSnKZbS lch19WzT52Hu9MSxqzOLc1m4WAUFMupdThl7PIHI9dv5EOjPAVAxQLNrAXB/FC4u DOf6Bp+FV53opo7mwWq0nbtdskBXZtkiUs/pMMw695PrOiuwXKnzpq07EL9qKf8U CXkt05ct5PLHq1OidBfVFGwM4wMrgldwUFYhbO+066BTSknGpfHHBeFwm0vTZUmw bsjQq61bZHuUO0uHMfQB/YXMRNZjSdUOJohl0Nb76Ij6qGh3n2Hhgmbuoze3MsfL 1NyVAtSIwpH5vN86pR3QlXZSBHK84N69I9Hdhtytrn55TzKGUGM= =gg4L -----END PGP SIGNATURE----- --Uk6zjKD/aJCqEW6Y--