From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 42C615A0277 for ; Fri, 8 Mar 2024 02:17:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709860635; bh=MlZKiuOFMgYfscWV7NId7u+rQHtP2ZPaMvQg1ekUbjU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JCz86chofUOboQ7Gbd2+uLOmoN3Udt2hJZH7w6LTTGbcbVv1S5erw2x9FdbPCAmXQ /s7VLbkjGExJ8+bR5tdLMCR/xhEjcva9Pwy96NIp0mrPfdchQ0IEp68NVCzidXFggS 7kC7TAbNhiQKPcdHev16zWBn4JwB6+r7EgHg1Me1BN3BhEpDsdracyf7VjwKpzYPBB gR+/vZBvfADMmXkR5W4qYTWfBbG3daYsjYyoFTeaxpJh7O2tVAUD9Arlt9VnskXBQO hm838kQ9hF+iU7ModNXsQI6zJ5/xqFQ2JxqPIuYebosDBoY/ANeP620uWA/kZGbrKc T20W52JZKihxQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TrSvH46msz4wcK; Fri, 8 Mar 2024 12:17:15 +1100 (AEDT) Date: Fri, 8 Mar 2024 11:55:32 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] ip: Use regular htons() for non-constant protocol number in L2_BUF_IP4_PSUM Message-ID: References: <20240306070836.3417504-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="BjbOGXXetLllJ6vO" Content-Disposition: inline In-Reply-To: <20240306070836.3417504-1-sbrivio@redhat.com> Message-ID-Hash: 3W3LSYPYMB6FVTACYYNDGWDNWEZDHWS2 X-Message-ID-Hash: 3W3LSYPYMB6FVTACYYNDGWDNWEZDHWS2 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: --BjbOGXXetLllJ6vO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 06, 2024 at 08:08:36AM +0100, Stefano Brivio wrote: > instead of htons_constant(), which is for... constants. >=20 > Fixes: 5bf200ae8a1a ("tcp, udp: Don't include destination address in part= ially precomputed csums") > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson It seems to get the job done, at what's probably negligible practical cost. My perfectionist side has some misgivings: AIUI, the point of htons_constant() isn't so much that it *requires* a constant, but that because it's open-coded in plain arithmetic operations the compiler will be able to constant fold it, if it is invoked with a constant parameter. Since htons() is a library function, it probably can't be elided in that way. The cost of htons_constant() is that it may be a less optimal implementation when the calculation really does need to be done at runtime. I'm still a bit baffled at that Coverity warning: I can't see why it doesn't preclude any situation where you want to write out calculations for clarity, even though you know the result will be a constant (and you expect the compiler to fold it). > --- > ip.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/ip.h b/ip.h > index 9be4778..b9aedf6 100644 > --- a/ip.h > +++ b/ip.h > @@ -38,7 +38,7 @@ > .daddr =3D 0, \ > } > #define L2_BUF_IP4_PSUM(proto) ((uint32_t)htons_constant(0x4500) + \ > - (uint32_t)htons_constant(0xff00 | (proto))) > + (uint32_t)htons(0xff00 | (proto))) > =20 > #define L2_BUF_IP6_INIT(proto) \ > { \ --=20 David Gibson | 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 --BjbOGXXetLllJ6vO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXqYgMACgkQzQJF27ox 2GevCA/7BloZOJsTcRF3DKi8JWRdioFadveRZ++SlyLIOo2mx3b4OJKRa7D+axiW eus0QOplmq4GV90pBqwhXBK4KptTe43jbNJTQ7M8lwB6GoERBa+Y3bhSxwKnE/Op KEyCVBH5TxjyfVvEcaK3QUo/7cAXMrC4ZXZHmfQ4uToIQ3jYKw85wYFvdTaQsPi3 UJsKazYqtzSyV3BY+IpALvU1aePiUamUQ7ozrTdlmjAbXuDzFh3cVsQH9cn7U4+7 T2HCgQMXu390ZGpqtwI5F+VVwE/9i6O5EeNdpktuPmuvG+fX5efgLKXWXigDF0vn ld1U0DR/+AN2sxz5TV0CmbdaVp+2mnDYaoV4RtJ+arh5jzsNUYdJYvKsmIMufwfw z4ch3HiIpao1HxTMgCc+bbfXUX73nRPAZkQ2JRR4EDxkv7a3FpcIUYXogeR9s311 4N2WnFcu58XcXgMOlqlBX/9LljFHlLX81MM4K9u0mBanbQh/fGVujFstwHvGVjbc bZRVJctNv0Zb4ehLQ6p6zes3nClywrcnojwm+5R6EEMhXKOQpmvoJb4BoXkhUqKC o8AFRQnU+E9YR+UQWQZ1SAZay5ZTuaEeYdBHFPOiKBeEUfdMm76XNehNnfngOZJ+ QKcMSuaA+TR3Hfge1pDxfU7tCm8T0aC0YmtuTmMIFfz2zYg1uc0= =LeIx -----END PGP SIGNATURE----- --BjbOGXXetLllJ6vO--