From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754756AbcLNENX (ORCPT ); Tue, 13 Dec 2016 23:13:23 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51233 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753311AbcLNENV (ORCPT ); Tue, 13 Dec 2016 23:13:21 -0500 Date: Tue, 13 Dec 2016 20:13:15 -0800 From: "Paul E. McKenney" To: Boqun Feng 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 Reply-To: paulmck@linux.vnet.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> <20161214014002.GI9728@tardis.cn.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20161214014002.GI9728@tardis.cn.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16121404-0028-0000-0000-0000064081AF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006245; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000196; SDB=6.00793543; UDB=6.00384745; IPR=6.00571346; BA=6.00004963; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013620; XFM=3.00000011; UTC=2016-12-14 04:13:18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16121404-0029-0000-0000-000031A0112D Message-Id: <20161214041315.GI3924@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-12-14_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1612140070 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 14, 2016 at 09:40:02AM +0800, Boqun Feng wrote: > 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年12月14日 上午1:17,"Mark Rutland" 写道: > > > > > > > > > > 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 |= 1 << bit; > > > > > > + mask |= 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 |= 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. > > > > > > > > Good point. ;-) > > > > > > > > We can > > > > > > > > #define for_each_leaf_node_cpu(rnp, mask, cpu) \ > > > > for((cpu) = (rnp)->grplo + find _first_bit(mask, MASK_BITS(mask)); \ > > > > (cpu) >= (rnp)->grplo && (cpu) <= (rnp)->grphi; \ > > > > (cpu) = (rnp)->grplo + find _next_bit(mask, ..., > > > > leaf_node_cpu_bit(rnp, cpu) + 1))) \ > > > > if (!cpu_possible(cpu)) \ > > > > continue; \ > > > > else > > > > > > What is the purpose of the cpu_possible() check? > > > > > > > To filter out CPUs in range [grplo, grphi] but not in cpu_possible_mask. > > > > 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 ;-) Much better! ;-) Thanx, Paul > Regards, > Boqun > > > Regards, > > Boqun > > > > > Thanx, Paul > > > > > > > Typing from my cellphone, plz ignore the bad formatting ;-) > > > > > > > > Regards, > > > > Boqun > > > > > > > > > Thanks, > > > > > Mark. > > > > >