From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932941AbcLMLd4 (ORCPT ); Tue, 13 Dec 2016 06:33:56 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:44194 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932618AbcLMLdy (ORCPT ); Tue, 13 Dec 2016 06:33:54 -0500 Subject: Re: [PATCH] rcu: shift by 1UL rather than 1 to fix sign extension error To: Boqun Feng References: <20161213105646.9598-1-colin.king@canonical.com> <20161213112148.GE9728@tardis.cn.ibm.com> Cc: "Paul E . McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , linux-kernel@vger.kernel.org From: Colin Ian King Message-ID: <3607072d-2418-df43-fd9a-2708a95f97da@canonical.com> Date: Tue, 13 Dec 2016 11:33:19 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20161213112148.GE9728@tardis.cn.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CTSmBvi08JdUWsrsj2xbXOWBMPfjF0w3t" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --CTSmBvi08JdUWsrsj2xbXOWBMPfjF0w3t Content-Type: multipart/mixed; boundary="N3lND1jIsJbu9ENM6q97jNRox12F7Kx4E"; protected-headers="v1" From: Colin Ian King To: Boqun Feng Cc: "Paul E . McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , linux-kernel@vger.kernel.org Message-ID: <3607072d-2418-df43-fd9a-2708a95f97da@canonical.com> Subject: Re: [PATCH] rcu: shift by 1UL rather than 1 to fix sign extension error References: <20161213105646.9598-1-colin.king@canonical.com> <20161213112148.GE9728@tardis.cn.ibm.com> In-Reply-To: <20161213112148.GE9728@tardis.cn.ibm.com> --N3lND1jIsJbu9ENM6q97jNRox12F7Kx4E Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 13/12/16 11:21, Boqun Feng wrote: > On Tue, Dec 13, 2016 at 10:56:46AM +0000, Colin King wrote: >> From: Colin Ian King >> >> mask and bit are unsigned longs, so if bit is 31 we end up sign >> extending the 1 and mask ends up as 0xffffffff80000000. Fix this >> by explicitly adding integer suffix UL ensure 1 is a unsigned long >> rather than an signed int. >> >=20 > Right, you are, and the tool is ;-) >=20 > If @bit is greater than 32, we even got an undefined behavior in C ;-( > This is my careless mistake, thank you for finding it out and fix it! >=20 >> Issue found with static analysis with CoverityScan, CID 1388564 >> >> Fixes: 8965c3ce4718754db ("rcu: Use leaf_node_for_each_mask_possible_c= pu() in force_qs_rnp()") >> Signed-off-by: Colin Ian King >=20 > I think Paul only queued that for running tests and I have almost > finished a v2. I will fold your fix in my patch and add your SoB along > with mine, does that work for you? Sure, that's good with me. >=20 > TBH, this situation is kinda new to me, so if anyone has any suggestion= , > please let me know ;-) >=20 > Regards, > Boqun >=20 >> --- >> kernel/rcu/tree.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c >> index 10162ac..6ecedd8 100644 >> --- a/kernel/rcu/tree.c >> +++ b/kernel/rcu/tree.c >> @@ -3051,7 +3051,7 @@ static void force_qs_rnp(struct rcu_state *rsp, >> =20 >> leaf_node_for_each_mask_possible_cpu(rnp, rnp->qsmask, bit, cpu) >> if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj)) >> - mask |=3D 1 << bit; >> + mask |=3D 1UL << bit; >> =20 >> if (mask !=3D 0) { >> /* Idle/offline CPUs, report (releases rnp->lock. */ >> --=20 >> 2.10.2 >> --N3lND1jIsJbu9ENM6q97jNRox12F7Kx4E-- --CTSmBvi08JdUWsrsj2xbXOWBMPfjF0w3t Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQI2BAEBCAAgBQJYT9yAGRxjb2xpbi5raW5nQGNhbm9uaWNhbC5jb20ACgkQaMKH 38aoAiZu/g/+OMXApG4oX2b0cttNmNTKZURsE2bTPXIvuGYkEuhKgeiukxB7XX9R xKTLf7yxdqKU3/W3CkccK/lLwjEqfF/j78raTKTUO1JpnmpXb9FGbfKsm01o+yus VsYPm7JVFxLJyQsaIwyuiTk3f0MnAEQBUrk6Jr7G7iWukBYyOI6zLjp3QuAYQ6wn YHueiv/b8zdo9SROQQgkmlNxWgxRsY7O4omzutAHQbRaEwVufG+IbkSkav7fXkGU bazzNVibT/AiP1OETi5NKCEftKbt+GNo6Y/fkK/1FckNOIUkEd8UZZhyAkaXqlbo pq7xq9Kx+dDTb4oWCdh4kym9E18L3BH2P4HkYI/xhUjeElxMTOYhr2KYiDqKsnp3 sSaQBDQmgqEBTk7ZLDEOe3SlpPQxlEtUkOd4qrQE6XvgDYwFLksZm+2byPn9JCBW Iju5Fa5JF4MUp3SsNdreT2Ej9C0LGMEGqzM9M2DhjmoLgAEzwnJx82mdHAOJGMzS rw6nWQjOtU4ShGPzcdLRGjeQ9nQiOC34I28FMj9UnIk7fC5d0sM9pEFx0OQyURGs J2sk6BFLvszcUIpeLFsi0ja3W5AXcWQdSp8CPSPyiKSPT6IP4qnKwJ+K0DTExm9m Y6voe2UUI4gDc627rBH0HXGtlWDnL+CfM6ddy5VIEd7nfwKWXjJbdNg= =SHEl -----END PGP SIGNATURE----- --CTSmBvi08JdUWsrsj2xbXOWBMPfjF0w3t--