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=202602 header.b=RoF2mPvC; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 6D6875A0265 for ; Fri, 06 Mar 2026 13:08:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1772798882; bh=QCYCtGTdjZbTdz82AGSYnoD7/UwUkYWrvLz/fTb6tf4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RoF2mPvCzl8IlFFWgUMDO5JHNmGIlK8t97/Q4ueiuhKIcRT47SKRTbyLlyTFnYRcQ XVghxFXC75/QR0JmLtU3FE+NXz9PcLbsfuwpNPa/0Qeu3ZRA8TMMG7rivyqrDoesgV Uxs04fapEy84EgHsMCFK+PIzw4/bpc6aotBWJ6tJmp1/CtEkGLYS9y1JK4l/r6Euzs 6ej00Z1q9u7c4S3vAuUqEiVR6Dr53IqBfH1CaRFMgY3ntuC5baGGC5KI6F92LCNbvM 1x/PrX/1fv0nnS1eFXiosV7vw55To7Q9xwuPYQxh0gB8uGb2BjErHJQqD0jAr03WDq lU2n+kxPMeQuQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fS4tB2TRqz4wCm; Fri, 06 Mar 2026 23:08:02 +1100 (AEDT) Date: Fri, 6 Mar 2026 23:05:38 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] tcp: Avoid comparison of expressions with different signedness in RTT_SET() Message-ID: References: <20260304163232.2440892-1-sbrivio@redhat.com> <20260306080122.22ff92e4@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4ouSC51N02yaoPZ/" Content-Disposition: inline In-Reply-To: <20260306080122.22ff92e4@elisabeth> Message-ID-Hash: 4IBER3YOOKUXZET2QM4IT3UPPKPJ7Z5P X-Message-ID-Hash: 4IBER3YOOKUXZET2QM4IT3UPPKPJ7Z5P 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 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: --4ouSC51N02yaoPZ/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 06, 2026 at 08:02:26AM +0100, Stefano Brivio wrote: > On Thu, 5 Mar 2026 13:32:08 +1100 > David Gibson wrote: >=20 > > On Wed, Mar 04, 2026 at 05:32:32PM +0100, Stefano Brivio wrote: > > > With gcc 14.2, building against musl 1.2.5 (slightly outdated Alpine > > > on x86_64): > > >=20 > > > tcp.c: In function 'tcp_update_seqack_wnd': > > > util.h:40:39: warning: comparison of integer expressions of different= signedness: 'unsigned int' and 'int' [-Wsign-compare] > > > 40 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) > > > | ^ > > > tcp_conn.h:63:26: note: in expansion of macro 'MIN' > > > 63 | (conn->rtt_exp =3D MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt = / RTT_STORE_MIN)))) > > > | ^~~ > > > tcp.c:1234:17: note: in expansion of macro 'RTT_SET' > > > 1234 | RTT_SET(conn, tinfo->tcpi_rtt); > > > | ^~~~~~~ > > > util.h:40:54: warning: operand of '?:' changes signedness from 'int' = to 'unsigned int' due to unsignedness of other operand [-Wsign-compare] > > > 40 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) > > > | ^~~ > > > tcp_conn.h:63:26: note: in expansion of macro 'MIN' > > > 63 | (conn->rtt_exp =3D MIN(RTT_EXP_MAX, ilog2(MAX(1, rtt = / RTT_STORE_MIN)))) > > > | ^~~ > > > tcp.c:1234:17: note: in expansion of macro 'RTT_SET' > > > 1234 | RTT_SET(conn, tinfo->tcpi_rtt); > > > | ^~~~~~~ > > >=20 > > > for some reason, that's not reported by gcc with glibc. > > >=20 > > > Cast the result of ilog2() to unsigned before using it, as it's always > > > positive the way we're using it. Should this ever break this for > > > whatever unlikely reason, RTT_EXP_MAX is the fallback value we want to > > > use anyway. > > >=20 > > > Fixes: 000601ba86da ("tcp: Adaptive interval based on RTT for socket-= side acknowledgement checks") > > > Signed-off-by: Stefano Brivio =20 > >=20 > > This is correct, so > >=20 > > Reviewed-by: David Gibson > >=20 > > It's kind of inelegant, though - ilog2() only returns a signed to > > report an error case, which we avoid with the MAX inside the argument. > > That's not a super obvious connection. I guess we could do: > >=20 > > (unsigned)MAX(0, ilog2(rtt / RTT_STORE_MIN)) > >=20 > > which should be equivalent and makes it slightly more obvious that the > > cast is safe. Not sure if it's really an improvement, though. >=20 > Right, yes, at this point I guess it's clearer. Changed to that in v2. Ok. > > This is the only user of ilog2(), so we could also consider replacing > > it with a version that explicitly clamps its argument to >=3D 1 and > > returns unsigned. >=20 > I thought about doing that, but on the other hand we would have a > rather arithmetic function returning an obviously wrong value for some > arguments, which doesn't sound great either. Yeah, fair point. --=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 --4ouSC51N02yaoPZ/ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmqwwoACgkQzQJF27ox 2Gc2fg/+NW3PEIFzcNgx5bItRe418WaoBEvLyylzap9TWW2/RPQ0BJt9b26RssZQ WD0lh37PkrlSBvl/WRvVjNO8tpQ5l2X5WZGX/tXUJbre92DA9ffzVp1/zzZ2wnk4 kFvCIs+fHxNgPyQlVsLnrbkIAakrUDHCo5cmqao5oIDcuCj9f6U66ZJz2s2cImBl HAW0ubVAxfYVv5bt/NZeDMkTzXqTJDXMVhjl683AFd+CjZygo9ZKPbgiCXwf2bc+ RJmWbMkTawLnTsYcepZDt0tFs01hZkgNx7da2deBDMM0+B2gC69q6hd2jMDVX6ec RczTpBZKiNf3XzXjp+VVFcH1x+p4Z0PJJQpR7kqUo3qIKbJztSJg0NSLReu8gqRQ Fn7oo2RzX7zbsKFaY7a94eEsl0XW4OZbvcJlzdPSshxQPoxnkJFAT/znxqisugTp 5IclyWQ6EEY4a4T9MZ4wlj4d4Y9Mz89LklwBN//mufHa6kBTnLeu3lfRXS4ufxBp PIROcXu1Sa1PwkUQPp7fAaoIP7dHlQBNYLgxLaKE7OmeHO7YVKOu07i5fMerHwc/ 833PhcXkio9jp0ME8y6KdVHv4t8+QQwOV4XnNK2n0bcCQtGXLCkR/SdA3ByaHO/I OpRG4BKRRjbkM7WDf+Z/p3bBSjNbgne9goVXuBsS7OKXaqZUJUg= =IZu4 -----END PGP SIGNATURE----- --4ouSC51N02yaoPZ/--