From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753087AbcLNAsT (ORCPT ); Tue, 13 Dec 2016 19:48:19 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35776 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751985AbcLNAsS (ORCPT ); Tue, 13 Dec 2016 19:48:18 -0500 Date: Wed, 14 Dec 2016 08:47:55 +0800 From: Boqun Feng To: "Paul E. McKenney" Cc: Mark Rutland , Mathieu Desnoyers , Josh Triplett , 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: <20161214004755.GG9728@tardis.cn.ibm.com> References: <20161213105646.9598-1-colin.king@canonical.com> <20161213171632.GA32535@leverpostej> <20161213183647.GD3924@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3607uds81ZQvwCD0" Content-Disposition: inline In-Reply-To: <20161213183647.GD3924@linux.vnet.ibm.com> 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 --3607uds81ZQvwCD0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Dec 13, 2016 at 10:36:47AM -0800, Paul E. McKenney wrote: > 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"Mar= k 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 *rs= p, > > > > > > > > leaf_node_for_each_mask_possible_cpu(rnp, rnp->qsmask, > > bit, cpu) > > > > if (f(per_cpu_ptr(rsp->rda, cpu), isidle, max= j)) > > > > - 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, c= pu) > > > 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(ma= sk)); \ > > (cpu) >=3D (rnp)->grplo && (cpu) <=3D (rnp)->grphi; \ > > (cpu) =3D (rnp)->grplo + find _next_bit(mask, ..., > > leaf_node_cpu_bit(rnp, cpu) + 1))) \ > > if (!cpu_possible(cpu)) \ > > continue; \ > > else >=20 > What is the purpose of the cpu_possible() check? >=20 To filter out CPUs in range [grplo, grphi] but not in cpu_possible_mask. Regards, Boqun > Thanx, Paul >=20 > > Typing from my cellphone, plz ignore the bad formatting ;-) > >=20 > > Regards, > > Boqun > >=20 > > > Thanks, > > > Mark. >=20 --3607uds81ZQvwCD0 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAABCAAGBQJYUJa2AAoJEEl56MO1B/q41SAIAKOPu2TeRQzSCjShzqQAIvED lPO7MZ29EiHcVv0TqUZI2slKw2SraA7KMid0jiRdkAkla+473KrcoNUixTBV11r4 TXTSZcxKZU8H2Ti9JjB/+g/D0P1wqhTjyXiEbL7SvlqsviocrgKFetjgPTrOuUIo C3OcCXuqYfWt5WSJDj/Wl9JsnRjoxgmdAUT/6ymTMBLhPRNJXgxL0uJ5xMLx1efS MoZ8cBRCBsA/U/5Vwf3OwEIEBS5uBAboPFfw1dVGynp+kYhjlX1XI8TuG7Ad2WhU KilYV6jkaAXM1zM8M8E1+DmfWrMMQnTyPFswQMpinzNn141U+yekPAyfaa/hggc= =BElF -----END PGP SIGNATURE----- --3607uds81ZQvwCD0--