diff mbox

softlockup: stop softlockup messages due to touch_ts math overflow

Message ID 1268152639.1715.92.camel@lenovo
State Accepted
Delegated to: Andy Whitcroft
Headers show

Commit Message

Colin Ian King March 9, 2010, 4:37 p.m. UTC
Hi,

This patch will fix a math overflow error that causes spurious soft
lockup error messages. It catches a corner case, for example, just when
the TSC heads towards a 64 bit wrap-around when the upper 32 bits are
set to 0xffffffff.  While this normally does not happen (since it
requires an uptime of possibly thousands of years, it may happen if the
TSC warps during S3).

If this looks sane, I'll sent it upstream.

Colin

Comments

Stefan Bader March 9, 2010, 5:48 p.m. UTC | #1
Colin Ian King wrote:
> Hi,
> 
> This patch will fix a math overflow error that causes spurious soft
> lockup error messages. It catches a corner case, for example, just when
> the TSC heads towards a 64 bit wrap-around when the upper 32 bits are
> set to 0xffffffff.  While this normally does not happen (since it
> requires an uptime of possibly thousands of years, it may happen if the
> TSC warps during S3).
> 
> If this looks sane, I'll sent it upstream.
> 
> Colin
> 
It looks like a sensible way to fix this. Upstream opinion may vary...

Stefan
Colin Ian King March 9, 2010, 5:59 p.m. UTC | #2
On Tue, 2010-03-09 at 18:48 +0100, Stefan Bader wrote:
> Colin Ian King wrote:
> > Hi,
> > 
> > This patch will fix a math overflow error that causes spurious soft
> > lockup error messages. It catches a corner case, for example, just when
> > the TSC heads towards a 64 bit wrap-around when the upper 32 bits are
> > set to 0xffffffff.  While this normally does not happen (since it
> > requires an uptime of possibly thousands of years, it may happen if the
> > TSC warps during S3).
> > 
> > If this looks sane, I'll sent it upstream.
> > 
> > Colin
> > 
> It looks like a sensible way to fix this. Upstream opinion may vary...

Indeed, that's why if anyone has any smart ideas about how to do this in
an efficient manner w/o the need to cast to 64 bits I would appreciate
it!
> 
> Stefan
>
Andy Whitcroft March 18, 2010, 5:46 a.m. UTC | #3
On Tue, Mar 09, 2010 at 04:37:19PM +0000, Colin Ian King wrote:
> Hi,
> 
> This patch will fix a math overflow error that causes spurious soft
> lockup error messages. It catches a corner case, for example, just when
> the TSC heads towards a 64 bit wrap-around when the upper 32 bits are
> set to 0xffffffff.  While this normally does not happen (since it
> requires an uptime of possibly thousands of years, it may happen if the
> TSC warps during S3).

Can't you rewrite this:

	if ((unsigned long long)now <= 
	    ((unsigned long long)touch_ts + softlockup_thresh))
		return;

as below and avoid the cast?

     if ((now - touch_ts) <= softlockup_threash)

-apw
diff mbox

Patch

From 2eca87a1eab20d49ee4edceb1642325bd81ec020 Mon Sep 17 00:00:00 2001
From: Colin Ian King <colin.king@canonical.com>
Date: Tue, 9 Mar 2010 16:19:18 +0000
Subject: [PATCH] softlockup: stop softlockup messages due to touch_ts math overflow

Ensure math does not overflow when touch_ts is close to the upper
bounds. This occurs when the top 32 bits of the TSC reach 0xffffffff
causing additions to touch_ts to overflow and this in turn generates
spurious softlockup warnings.

While this normally does not happen (since it requires an uptime of
possibly thousands of years, it may happen if the TSC warps during S3).

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 kernel/softlockup.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/softlockup.c b/kernel/softlockup.c
index 0d4c789..463652e 100644
--- a/kernel/softlockup.c
+++ b/kernel/softlockup.c
@@ -155,11 +155,13 @@  void softlockup_tick(void)
 	 * Wake up the high-prio watchdog task twice per
 	 * threshold timespan.
 	 */
-	if (now > touch_ts + softlockup_thresh/2)
+	if ((unsigned long long)now >
+	    (unsigned long long)touch_ts + softlockup_thresh/2)
 		wake_up_process(per_cpu(softlockup_watchdog, this_cpu));

 	/* Warn about unreasonable delays: */
-	if (now <= (touch_ts + softlockup_thresh))
+	if ((unsigned long long)now <= 
+	    ((unsigned long long)touch_ts + softlockup_thresh))
 		return;
 
 	per_cpu(softlockup_print_ts, this_cpu) = touch_ts;
-- 
1.6.3.3