* [PATCH] sched/deadline: fix one-bit signed bitfields to be unsigned
@ 2017-11-28 20:36 Jeff Kirsher
2017-11-29 4:07 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Kirsher @ 2017-11-28 20:36 UTC (permalink / raw)
To: mingo, peterz
Cc: Jacob Keller, linux-kernel, netdev, nhorman, sassmann, jogreene,
luca abeni, Jeff Kirsher
From: Jacob Keller <jacob.e.keller@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.keller@intel.com>
Cc: luca abeni <luca.abeni@santannapisa.it>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
include/linux/sched.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index a5dc7c98b0a2..21991d668d35 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -473,10 +473,10 @@ struct sched_dl_entity {
* conditions between the inactive timer handler and the wakeup
* code.
*/
- int dl_throttled : 1;
- int dl_boosted : 1;
- int dl_yielded : 1;
- int dl_non_contending : 1;
+ unsigned int dl_throttled : 1;
+ unsigned int dl_boosted : 1;
+ unsigned int dl_yielded : 1;
+ unsigned int dl_non_contending : 1;
/*
* Bandwidth enforcement timer. Each -deadline task has its
--
2.15.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sched/deadline: fix one-bit signed bitfields to be unsigned
2017-11-28 20:36 [PATCH] sched/deadline: fix one-bit signed bitfields to be unsigned Jeff Kirsher
@ 2017-11-29 4:07 ` Jakub Kicinski
2017-11-30 0:12 ` Keller, Jacob E
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2017-11-29 4:07 UTC (permalink / raw)
To: Jeff Kirsher
Cc: mingo, peterz, Jacob Keller, linux-kernel, netdev, nhorman,
sassmann, jogreene, luca abeni
On Tue, 28 Nov 2017 12:36:19 -0800, Jeff Kirsher wrote:
> From: Jacob Keller <jacob.e.keller@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.keller@intel.com>
> Cc: luca abeni <luca.abeni@santannapisa.it>
> Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
This is already in Linus's tree (I've been waiting for it to land as
well :))
commit aa5222e92f8000ed3c1c38dddf11c83222aadfb3
Author: Dan Carpenter <dan.carpenter@oracle.com>
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 <willy@infradead.org>
Reported-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Luca Abeni <luca.abeni@santannapisa.it>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: kernel-janitors@vger.kernel.org
Cc: luca abeni <luca.abeni@santannapisa.it>
Link: http://lkml.kernel.org/r/20171013070121.dzcncojuj2f4utij@mwanda
Signed-off-by: Ingo Molnar <mingo@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] sched/deadline: fix one-bit signed bitfields to be unsigned
2017-11-29 4:07 ` Jakub Kicinski
@ 2017-11-30 0:12 ` Keller, Jacob E
0 siblings, 0 replies; 3+ messages in thread
From: Keller, Jacob E @ 2017-11-30 0:12 UTC (permalink / raw)
To: Jakub Kicinski, Kirsher, Jeffrey T
Cc: mingo, peterz, linux-kernel, netdev, nhorman, sassmann, jogreene,
luca abeni
> -----Original Message-----
> From: Jakub Kicinski [mailto:kubakici@wp.pl]
> Sent: Tuesday, November 28, 2017 8:08 PM
> To: Kirsher, Jeffrey T <jeffrey.t.kirsher@intel.com>
> Cc: mingo@redhat.com; peterz@infradead.org; Keller, Jacob E
> <jacob.e.keller@intel.com>; linux-kernel@vger.kernel.org;
> netdev@vger.kernel.org; nhorman@redhat.com; sassmann@redhat.com;
> jogreene@redhat.com; luca abeni <luca.abeni@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.keller@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.keller@intel.com>
> > Cc: luca abeni <luca.abeni@santannapisa.it>
> > Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
> > Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
>
> This is already in Linus's tree (I've been waiting for it to land as
> well :))
>
Excellent.
Regards,
Jake
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-30 0:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-28 20:36 [PATCH] sched/deadline: fix one-bit signed bitfields to be unsigned Jeff Kirsher
2017-11-29 4:07 ` Jakub Kicinski
2017-11-30 0:12 ` Keller, Jacob E
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).