From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754655AbcLNBkX (ORCPT ); Tue, 13 Dec 2016 20:40:23 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:32779 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752738AbcLNBkV (ORCPT ); Tue, 13 Dec 2016 20:40:21 -0500 Date: Wed, 14 Dec 2016 09:40:02 +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: <20161214014002.GI9728@tardis.cn.ibm.com> References: <20161213105646.9598-1-colin.king@canonical.com> <20161213171632.GA32535@leverpostej> <20161213183647.GD3924@linux.vnet.ibm.com> <20161214004755.GG9728@tardis.cn.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jQIvE3yXcK9X9HBh" Content-Disposition: inline In-Reply-To: <20161214004755.GG9728@tardis.cn.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 --jQIvE3yXcK9X9HBh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 14, 2016 at 08:47:55AM +0800, Boqun Feng wrote: > 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"M= ark 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->qsma= sk, > > > bit, cpu) > > > > > if (f(per_cpu_ptr(rsp->rda, cpu), isidle, m= axj)) > > > > > - mask |=3D 1 << bit; > > > > > + mask |=3D 1UL << bit; > > > > > > > > So as to match the rest of the code altered in commit bc75e99983df1= efd > > > > ("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))) \ > > > if (!cpu_possible(cpu)) \ > > > continue; \ > > > else > >=20 > > What is the purpose of the cpu_possible() check? > >=20 >=20 > To filter out CPUs in range [grplo, grphi] but not in cpu_possible_mask. >=20 Hmm.. if rcu_cpu_starting(cpu) is never called with "impossible" cpu, IOW, ->qsmask and ->expmask never mask "impossible" cpus, then this is just an over-care check. I think I probably will remove this check eventually, let me audit the code a little more for safety ;-) Regards, Boqun > Regards, > Boqun >=20 > > Thanx, Paul > >=20 > > > Typing from my cellphone, plz ignore the bad formatting ;-) > > >=20 > > > Regards, > > > Boqun > > >=20 > > > > Thanks, > > > > Mark. > >=20 --jQIvE3yXcK9X9HBh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAABCAAGBQJYUKLvAAoJEEl56MO1B/q4y8wIAI5qRf1vgaXWLK2KGOJN0gSJ o9wEDZGmtDv4Tjj0IKZE74UU64vxLx63Ai0zI/k4xkj1ksEHVMxnJB95VYYxdaCP 3xqPlbUOX8PQ3DY0ks/oiSNujBaHQVnvEgb1kf2/yVyT3hqF8k66g/YVZF6M+4vN Rrn77VKn/wvd5QVsougGeMXO14CtQSlEdTlhgSvEDCY2tJbSXC/F1K+ikr3jvPj5 uYJP+RxRGak3GnQG6MVZGkF5unOd5vTRcwMrQd0Q3DH95KKmYXtjZifW8srUih5Z kZqDvJxNbh6rUAfcwEddQctfYMzXvQs/znL1ySMFPwOpJPvtqSK1EWcGKl5q1Jo= =H8O1 -----END PGP SIGNATURE----- --jQIvE3yXcK9X9HBh--