Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH] time: sched_clock: fix integer overflow

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


baruch at tkos

Jul 17, 2013, 2:46 AM

Post #1 of 4 (23 views)
Permalink
[PATCH] time: sched_clock: fix integer overflow

The expression '(1 << 32)' happens to evaluate as 0 on ARM, but it evaluates as
1 on xtensa and x86_64. This zeros sched_clock_mask, and breaks sched_clock().
Set the type of 1 to 'unsigned long long' to get the value we need.

Reported-by: Max Filippov <jcmvbkbc [at] gmail>
Tested-by: Max Filippov <jcmvbkbc [at] gmail>
Acked-by: Russell King <rmk+kernel [at] arm>
Signed-off-by: Baruch Siach <baruch [at] tkos>
---
kernel/time/sched_clock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
index a326f27..0b479a6 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -121,7 +121,7 @@ void __init setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate)
BUG_ON(bits > 32);
WARN_ON(!irqs_disabled());
read_sched_clock = read;
- sched_clock_mask = (1 << bits) - 1;
+ sched_clock_mask = (1ULL << bits) - 1;
cd.rate = rate;

/* calculate the mult/shift to convert counter ticks to ns. */
--
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


baruch at tkos

Jul 28, 2013, 10:59 PM

Post #2 of 4 (18 views)
Permalink
Re: [PATCH] time: sched_clock: fix integer overflow [In reply to]

Hi Thomas, John,

On Wed, Jul 17, 2013 at 12:46:53PM +0300, Baruch Siach wrote:
> The expression '(1 << 32)' happens to evaluate as 0 on ARM, but it evaluates as
> 1 on xtensa and x86_64. This zeros sched_clock_mask, and breaks sched_clock().
> Set the type of 1 to 'unsigned long long' to get the value we need.

Ping? -rc3 is out, and this bug (which currently breaks xtensa) is not fixed
yet. Please consider applying.

baruch

> Reported-by: Max Filippov <jcmvbkbc [at] gmail>
> Tested-by: Max Filippov <jcmvbkbc [at] gmail>
> Acked-by: Russell King <rmk+kernel [at] arm>
> Signed-off-by: Baruch Siach <baruch [at] tkos>
> ---
> kernel/time/sched_clock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
> index a326f27..0b479a6 100644
> --- a/kernel/time/sched_clock.c
> +++ b/kernel/time/sched_clock.c
> @@ -121,7 +121,7 @@ void __init setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate)
> BUG_ON(bits > 32);
> WARN_ON(!irqs_disabled());
> read_sched_clock = read;
> - sched_clock_mask = (1 << bits) - 1;
> + sched_clock_mask = (1ULL << bits) - 1;
> cd.rate = rate;
>
> /* calculate the mult/shift to convert counter ticks to ns. */
> --

--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch [at] tkos - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


sboyd at codeaurora

Jul 29, 2013, 11:41 AM

Post #3 of 4 (19 views)
Permalink
Re: [PATCH] time: sched_clock: fix integer overflow [In reply to]

On 07/28/13 22:59, Baruch Siach wrote:
> Hi Thomas, John,
>
> On Wed, Jul 17, 2013 at 12:46:53PM +0300, Baruch Siach wrote:
>> The expression '(1 << 32)' happens to evaluate as 0 on ARM, but it evaluates as
>> 1 on xtensa and x86_64. This zeros sched_clock_mask, and breaks sched_clock().
>> Set the type of 1 to 'unsigned long long' to get the value we need.
> Ping? -rc3 is out, and this bug (which currently breaks xtensa) is not fixed
> yet. Please consider applying.

Looks good to me.

Acked-by: Stephen Boyd <sboyd [at] codeaurora>

>
>> Reported-by: Max Filippov <jcmvbkbc [at] gmail>
>> Tested-by: Max Filippov <jcmvbkbc [at] gmail>
>> Acked-by: Russell King <rmk+kernel [at] arm>
>> Signed-off-by: Baruch Siach <baruch [at] tkos>
>> ---
>> kernel/time/sched_clock.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
>> index a326f27..0b479a6 100644
>> --- a/kernel/time/sched_clock.c
>> +++ b/kernel/time/sched_clock.c
>> @@ -121,7 +121,7 @@ void __init setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate)
>> BUG_ON(bits > 32);
>> WARN_ON(!irqs_disabled());
>> read_sched_clock = read;
>> - sched_clock_mask = (1 << bits) - 1;
>> + sched_clock_mask = (1ULL << bits) - 1;
>> cd.rate = rate;
>>
>> /* calculate the mult/shift to convert counter ticks to ns. */
>> --


--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


baruch at tkos

Aug 11, 2013, 8:03 PM

Post #4 of 4 (14 views)
Permalink
Re: [Linux-Xtensa] Re: [PATCH] time: sched_clock: fix integer overflow [In reply to]

Hi Thomas, John,

On Mon, Jul 29, 2013 at 08:59:39AM +0300, Baruch Siach wrote:
> On Wed, Jul 17, 2013 at 12:46:53PM +0300, Baruch Siach wrote:
> > The expression '(1 << 32)' happens to evaluate as 0 on ARM, but it evaluates as
> > 1 on xtensa and x86_64. This zeros sched_clock_mask, and breaks sched_clock().
> > Set the type of 1 to 'unsigned long long' to get the value we need.
>
> Ping? -rc3 is out, and this bug (which currently breaks xtensa) is not fixed
> yet. Please consider applying.

Sorry to bother again, but -rc5 is here and xtensa sched_clock is still
broken.

baruch

> > Reported-by: Max Filippov <jcmvbkbc [at] gmail>
> > Tested-by: Max Filippov <jcmvbkbc [at] gmail>
> > Acked-by: Russell King <rmk+kernel [at] arm>
> > Signed-off-by: Baruch Siach <baruch [at] tkos>
> > ---
> > kernel/time/sched_clock.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
> > index a326f27..0b479a6 100644
> > --- a/kernel/time/sched_clock.c
> > +++ b/kernel/time/sched_clock.c
> > @@ -121,7 +121,7 @@ void __init setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate)
> > BUG_ON(bits > 32);
> > WARN_ON(!irqs_disabled());
> > read_sched_clock = read;
> > - sched_clock_mask = (1 << bits) - 1;
> > + sched_clock_mask = (1ULL << bits) - 1;
> > cd.rate = rate;
> >
> > /* calculate the mult/shift to convert counter ticks to ns. */
> > --

--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch [at] tkos - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.