From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754625AbcLNBGy (ORCPT ); Tue, 13 Dec 2016 20:06:54 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33459 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754604AbcLNBGx (ORCPT ); Tue, 13 Dec 2016 20:06:53 -0500 Date: Wed, 14 Dec 2016 09:06:33 +0800 From: Boqun Feng To: Mark Rutland Cc: Mathieu Desnoyers , Josh Triplett , "Paul E . McKenney" , Colin King , Lai Jiangshan , Steven Rostedt , linux-kernel@vger.kernel.org Subject: Re: [PATCH] rcu: shift by 1UL rather than 1 to fix sign extension error Message-ID: <20161214010633.GH9728@tardis.cn.ibm.com> References: <20161213105646.9598-1-colin.king@canonical.com> <20161213171632.GA32535@leverpostej> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ZYOWEO2dMm2Af3e3" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ZYOWEO2dMm2Af3e3 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 14, 2016 at 02:09:27AM +0800, Boqun Feng wrote: > 2016=E5=B9=B412=E6=9C=8814=E6=97=A5 =E4=B8=8A=E5=8D=881:17=EF=BC=8C"Mark = Rutland" =E5=86=99=E9=81=93=EF=BC=9A > > > > Hi, > > > > 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. > > > > > > Issue found with static analysis with CoverityScan, CID 1388564 > > > > > > Fixes: 8965c3ce4718754db ("rcu: Use > leaf_node_for_each_mask_possible_cpu() in force_qs_rnp()") > > > Signed-off-by: Colin Ian King > > > --- > > > 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, > > > > > > 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; > > > > So as to match the rest of the code altered in commit bc75e99983df1efd > > ("rcu: Correctly handle sparse possible cpus"), and regardless of > > naming, I think it'd be nicer to use leaf_node_cpu_bit(), e.g. > > > > leaf_node_for_each_mask_possible_cpu(rnp, rnp->qsmask, bit, cpu) > > if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj)) > > mask |=3D leaf_node_cpu_bit(rnp, cpu); > > > > IMO, it would be nice to hide the iterator bit somehow, to match > > for_each_leaf_node_possible_cpu(), which this largely looks similar to > > otherwise. > > >=20 > Good point. ;-) >=20 > We can >=20 > #define for_each_leaf_node_cpu(rnp, mask, cpu) \ > for((cpu) =3D (rnp)->grplo + find _first_bit(mask, MASK_BITS(mask= )); \ > (cpu) >=3D (rnp)->grplo && (cpu) <=3D (rnp)->grphi; \ > (cpu) =3D (rnp)->grplo + find _next_bit(mask, ..., > leaf_node_cpu_bit(rnp, cpu) + 1))) \ Oops, this part is wrong.. > if (!cpu_possible(cpu)) \ > continue; \ > else >=20 Fixed version: /* * Iterate over all possible CPUs a leaf RCU node which are still masked in * @mask. * * Note @rnp has to be a leaf node and @mask has to belong to @rnp. */ #define for_each_leaf_node_cpu(rnp, mask, cpu) \ for ((cpu) =3D (rnp)->grplo + find_first_bit(&(mask), MASK_BITS(mask)); \ (cpu) >=3D (rnp)->grplo && (cpu) <=3D (rnp)->grphi; \ (cpu) =3D (rnp)->grplo + find_next_bit(&(mask), MASK_BITS(mask), \ (cpu) - (rnp)->grplo + 1)) \ if (!cpu_possible(cpu)) \ continue; \ else Regards, Boqun > Typing from my cellphone, plz ignore the bad formatting ;-) >=20 > Regards, > Boqun >=20 > > Thanks, > > Mark. --ZYOWEO2dMm2Af3e3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAABCAAGBQJYUJsVAAoJEEl56MO1B/q4UMcH/1m8QUORQJpCygD0rQdlXMzf W26sbB1mU+vaY21Br58o/BotrErKhefIzX7CCMgVxT+uaN17dpO9f0GmNkZ4qoJM XYC5vPIJVH1F3IiBR9xboFo6prSeqLndY4tvZYC/E0nE9Q5jEFqyJjIvCnbFsswm YGNC9pHjUewC0kniJZZHL3vfN3efRog/RAh+7kXqrZ11no6oV1Gj8yYA8KV2/QuR FD4oEzThh8LFqYeXnLilCR8xS7GjDQi2TnOnXR7gJXODdVEcoirCJZHf2rmog0Fh h5yaEq7lJjmTjZiNtG07VWM3D+5LzaKVrQ7ZhNarrXxb4CHQq6qPbqHnIn1xnmo= =bf5+ -----END PGP SIGNATURE----- --ZYOWEO2dMm2Af3e3--