linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: Colin King <colin.king@canonical.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rcu: shift by 1UL rather than 1 to fix sign extension error
Date: Tue, 13 Dec 2016 07:05:35 -0800	[thread overview]
Message-ID: <20161213150535.GA3924@linux.vnet.ibm.com> (raw)
In-Reply-To: <20161213122542.GF9728@tardis.cn.ibm.com>

On Tue, Dec 13, 2016 at 08:25:42PM +0800, Boqun Feng wrote:
> On Tue, Dec 13, 2016 at 07:21:48PM +0800, Boqun Feng wrote:
> > On Tue, Dec 13, 2016 at 10:56:46AM +0000, Colin King wrote:
> > > From: Colin Ian King <colin.king@canonical.com>
> > > 
> > > 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.
> > > 
> > 
> > Right, you are, and the tool is ;-)
> > 
> > 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!
> > 
> > > 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 <colin.king@canonical.com>
> > 
> > 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?
> > 
> > TBH, this situation is kinda new to me, so if anyone has any suggestion,
> > please let me know ;-)
> > 
> > Regards,
> > Boqun
> > 
> > > ---
> > >  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;
> 
> Hmm.. Seems using BIT() here is a good idea, and maybe rename bit as
> grp_idx or something.

Well, "bit" could be a bit, or it could be the number of the bit.
Given that we have "mask", and given that we are shifting by it,
it has to be the number of the bit.

> Naming, naming, naming..

Often I think that the biggest problem with naming is putting too much
time into worrying about it.  ;-)

But if you want to change the name from "bit" to "bitno" or "bitnum"
as part of your updated patchset, I won't object.  The reason for
preferring either to "grp_idx" is that "bitno" goes well with "mask".
But as a general rule, I must follow the usual practice of not favoring
renaming patches.

							Thanx, Paul

> Regards,
> Boqun
> 
> > >  
> > >  		if (mask != 0) {
> > >  			/* Idle/offline CPUs, report (releases rnp->lock. */
> > > -- 
> > > 2.10.2
> > > 
> 
> 

  reply	other threads:[~2016-12-13 15:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 10:56 [PATCH] rcu: shift by 1UL rather than 1 to fix sign extension error Colin King
2016-12-13 11:21 ` Boqun Feng
2016-12-13 11:33   ` Colin Ian King
2016-12-13 15:00     ` Paul E. McKenney
2016-12-14 14:42     ` Boqun Feng
2016-12-14 14:54       ` Colin Ian King
2016-12-13 12:25   ` Boqun Feng
2016-12-13 15:05     ` Paul E. McKenney [this message]
2016-12-13 17:16 ` Mark Rutland
     [not found]   ` <CAL0jBu8ackxPrOALVnx96FSyD_-sZAAMySikqYw2uf8LEezr9g@mail.gmail.com>
2016-12-13 18:36     ` Paul E. McKenney
2016-12-14  0:47       ` Boqun Feng
2016-12-14  1:40         ` Boqun Feng
2016-12-14  4:13           ` Paul E. McKenney
2016-12-14 10:55           ` Mark Rutland
2016-12-14 13:03             ` Boqun Feng
2016-12-14  1:06     ` Boqun Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161213150535.GA3924@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=boqun.feng@gmail.com \
    --cc=colin.king@canonical.com \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).