RE: [PATCH] sched/deadline: fix one-bit signed bitfields to be unsigned

2017-11-29 Thread Keller, Jacob E
> -Original Message-
> From: Jakub Kicinski [mailto:kubak...@wp.pl]
> Sent: Tuesday, November 28, 2017 8:08 PM
> To: Kirsher, Jeffrey T <jeffrey.t.kirs...@intel.com>
> Cc: mi...@redhat.com; pet...@infradead.org; Keller, Jacob E
> <jacob.e.kel...@intel.com>; linux-ker...@vger.kernel.org;
> netdev@vger.kernel.org; nhor...@redhat.com; sassm...@redhat.com;
> jogre...@redhat.com; luca abeni <luca.ab...@santannapisa.it>
> Subject: Re: [PATCH] sched/deadline: fix one-bit signed bitfields to be 
> unsigned
> 
> On Tue, 28 Nov 2017 12:36:19 -0800, Jeff Kirsher wrote:
> > From: Jacob Keller <jacob.e.kel...@intel.com>
> >
> > Commit 799ba82de01e ("sched/deadline: Use C bitfields for the state
> > flags", 2017-10-10) introduced the use of C bitfields for these
> > variables. However, sparse complains about them:
> >
> > ./include/linux/sched.h:476:62: error: dubious one-bit signed bitfield
> > ./include/linux/sched.h:477:62: error: dubious one-bit signed bitfield
> > ./include/linux/sched.h:478:62: error: dubious one-bit signed bitfield
> > ./include/linux/sched.h:479:62: error: dubious one-bit signed bitfield
> >
> > This is because a one-bit signed bitfield can only hold the values 0 and
> > -1, which can cause problems if the program expects to be able to
> > represent the value positive 1.
> >
> > In practice, this may not cause a bug since -1 would be considered
> > "true" in logical tests, however we should avoid the practice anyways.
> >
> > Fixes: 799ba82de01e ("sched/deadline: Use C bitfields for the state flags", 
> > 2017-
> 10-10)
> > Signed-off-by: Jacob Keller <jacob.e.kel...@intel.com>
> > Cc: luca abeni <luca.ab...@santannapisa.it>
> > Tested-by: Andrew Bowers <andrewx.bow...@intel.com>
> > Signed-off-by: Jeff Kirsher <jeffrey.t.kirs...@intel.com>
> 
> This is already in Linus's tree (I've been waiting for it to land as
> well :))
> 

Excellent.

Regards,
Jake


Re: [PATCH] sched/deadline: fix one-bit signed bitfields to be unsigned

2017-11-28 Thread Jakub Kicinski
On Tue, 28 Nov 2017 12:36:19 -0800, Jeff Kirsher wrote:
> From: Jacob Keller 
> 
> Commit 799ba82de01e ("sched/deadline: Use C bitfields for the state
> flags", 2017-10-10) introduced the use of C bitfields for these
> variables. However, sparse complains about them:
> 
> ./include/linux/sched.h:476:62: error: dubious one-bit signed bitfield
> ./include/linux/sched.h:477:62: error: dubious one-bit signed bitfield
> ./include/linux/sched.h:478:62: error: dubious one-bit signed bitfield
> ./include/linux/sched.h:479:62: error: dubious one-bit signed bitfield
> 
> This is because a one-bit signed bitfield can only hold the values 0 and
> -1, which can cause problems if the program expects to be able to
> represent the value positive 1.
> 
> In practice, this may not cause a bug since -1 would be considered
> "true" in logical tests, however we should avoid the practice anyways.
> 
> Fixes: 799ba82de01e ("sched/deadline: Use C bitfields for the state flags", 
> 2017-10-10)
> Signed-off-by: Jacob Keller 
> Cc: luca abeni 
> Tested-by: Andrew Bowers 
> Signed-off-by: Jeff Kirsher 

This is already in Linus's tree (I've been waiting for it to land as
well :))

commit aa5222e92f8000ed3c1c38dddf11c83222aadfb3
Author: Dan Carpenter 
Date:   Fri Oct 13 10:01:22 2017 +0300

sched/deadline: Don't use dubious signed bitfields

It doesn't cause a run-time bug, but these bitfields should be unsigned.
When it's signed ->dl_throttled is set to either 0 or -1, instead of
0 and 1 as expected.

The sched.h file is included into tons of places so Sparse generates
a flood of warnings like this:

  ./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield

Reported-by: Matthew Wilcox 
Reported-by: Xin Long 
Signed-off-by: Dan Carpenter 
Reviewed-by: Luca Abeni 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: kernel-janit...@vger.kernel.org
Cc: luca abeni 
Link: http://lkml.kernel.org/r/20171013070121.dzcncojuj2f4utij@mwanda
Signed-off-by: Ingo Molnar