All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] time: Fix casting issue in tk_set_xtime and tk_xtime_add
@ 2012-07-23 20:22 John Stultz
  2012-07-24 12:08 ` Prarit Bhargava
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: John Stultz @ 2012-07-23 20:22 UTC (permalink / raw)
  To: LKML
  Cc: John Stultz, Ingo Molnar, Thomas Gleixner, Prarit Bhargava,
	Konrad Rzeszutek Wilk

Fix missing casts that can cause boot problems on 32bit systems,
most easily observed with Xen systems. This issue was introduced
w/ 1e75fa8be9fb61e1af46b5b3b176347a4c958ca1.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timekeeping.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index f045cc5..cf364db 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -108,13 +108,13 @@ static struct timespec tk_xtime(struct timekeeper *tk)
 static void tk_set_xtime(struct timekeeper *tk, const struct timespec *ts)
 {
 	tk->xtime_sec = ts->tv_sec;
-	tk->xtime_nsec = ts->tv_nsec << tk->shift;
+	tk->xtime_nsec = (u64)ts->tv_nsec << tk->shift;
 }
 
 static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts)
 {
 	tk->xtime_sec += ts->tv_sec;
-	tk->xtime_nsec += ts->tv_nsec << tk->shift;
+	tk->xtime_nsec += (u64)ts->tv_nsec << tk->shift;
 }
 
 /**
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] time: Fix casting issue in tk_set_xtime and tk_xtime_add
  2012-07-23 20:22 [PATCH] time: Fix casting issue in tk_set_xtime and tk_xtime_add John Stultz
@ 2012-07-24 12:08 ` Prarit Bhargava
  2012-07-24 14:55 ` [tip:timers/urgent] " tip-bot for John Stultz
  2012-08-19 20:09 ` [PATCH] time: Fix casting issue in timekeeping_forward_now Andreas Schwab
  2 siblings, 0 replies; 4+ messages in thread
From: Prarit Bhargava @ 2012-07-24 12:08 UTC (permalink / raw)
  To: John Stultz; +Cc: LKML, Ingo Molnar, Thomas Gleixner, Konrad Rzeszutek Wilk



On 07/23/2012 04:22 PM, John Stultz wrote:
> Fix missing casts that can cause boot problems on 32bit systems,
> most easily observed with Xen systems. This issue was introduced
> w/ 1e75fa8be9fb61e1af46b5b3b176347a4c958ca1.
> 
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Prarit Bhargava <prarit@redhat.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Signed-off-by: John Stultz <john.stultz@linaro.org>

Acked-by: Prarit Bhargava <prarit@redhat.com>

P.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:timers/urgent] time: Fix casting issue in tk_set_xtime and tk_xtime_add
  2012-07-23 20:22 [PATCH] time: Fix casting issue in tk_set_xtime and tk_xtime_add John Stultz
  2012-07-24 12:08 ` Prarit Bhargava
@ 2012-07-24 14:55 ` tip-bot for John Stultz
  2012-08-19 20:09 ` [PATCH] time: Fix casting issue in timekeeping_forward_now Andreas Schwab
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for John Stultz @ 2012-07-24 14:55 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, john.stultz, hpa, mingo, konrad.wilk, tglx, prarit

Commit-ID:  b44d50dcacea0d485ca2ff9140f8cc28ee22f28d
Gitweb:     http://git.kernel.org/tip/b44d50dcacea0d485ca2ff9140f8cc28ee22f28d
Author:     John Stultz <john.stultz@linaro.org>
AuthorDate: Mon, 23 Jul 2012 16:22:37 -0400
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 24 Jul 2012 16:48:45 +0200

time: Fix casting issue in tk_set_xtime and tk_xtime_add

commit 1e75fa8b (time: Condense timekeeper.xtime into xtime_sec)
introduced helper functions which apply a timespec to the core
internal timekeeper data. The internal storage type is u64. The
timespec tv_nsec value must be shifted before set or added to the
internal value. tv_nsec is a long, which is 32bit on a 32bit system,
so without casting tv_nsec to u64 we lose the bits which are shifted
over the 32bit boundary.

Add the proper typecasts.

Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Acked-by: Prarit Bhargava <prarit@redhat.com>
Link: http://lkml.kernel.org/r/1343074957-16541-1-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/time/timekeeping.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 5980e90..8f2aba1 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -108,13 +108,13 @@ static struct timespec tk_xtime(struct timekeeper *tk)
 static void tk_set_xtime(struct timekeeper *tk, const struct timespec *ts)
 {
 	tk->xtime_sec = ts->tv_sec;
-	tk->xtime_nsec = ts->tv_nsec << tk->shift;
+	tk->xtime_nsec = (u64)ts->tv_nsec << tk->shift;
 }
 
 static void tk_xtime_add(struct timekeeper *tk, const struct timespec *ts)
 {
 	tk->xtime_sec += ts->tv_sec;
-	tk->xtime_nsec += ts->tv_nsec << tk->shift;
+	tk->xtime_nsec += (u64)ts->tv_nsec << tk->shift;
 }
 
 /**

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] time: Fix casting issue in timekeeping_forward_now
  2012-07-23 20:22 [PATCH] time: Fix casting issue in tk_set_xtime and tk_xtime_add John Stultz
  2012-07-24 12:08 ` Prarit Bhargava
  2012-07-24 14:55 ` [tip:timers/urgent] " tip-bot for John Stultz
@ 2012-08-19 20:09 ` Andreas Schwab
  2 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2012-08-19 20:09 UTC (permalink / raw)
  To: John Stultz
  Cc: LKML, Ingo Molnar, Thomas Gleixner, Prarit Bhargava,
	Konrad Rzeszutek Wilk

arch_gettimeoffset returns a u32 value which when shifted by tk->shift can
overflow.  Cast it to u64 first.

Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
---
Found this by inspection, I don't know if any existing users of
ARCH_USES_GETTIMEOFFSET are affected.  In other words, this is untested,
but looks pretty obvious.

Can tk->shift be bigger than 30?  If so then the shifts in
update_wall_time need to be adjusted as well.

Andreas.

---
 kernel/time/timekeeping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index e16af19..8776d66 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -276,7 +276,7 @@ static void timekeeping_forward_now(struct timekeeper *tk)
 	tk->xtime_nsec += cycle_delta * tk->mult;
 
 	/* If arch requires, add in gettimeoffset() */
-	tk->xtime_nsec += arch_gettimeoffset() << tk->shift;
+	tk->xtime_nsec += (u64)arch_gettimeoffset() << tk->shift;
 
 	tk_normalize_xtime(tk);
 
-- 
1.7.11.5

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-08-19 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-23 20:22 [PATCH] time: Fix casting issue in tk_set_xtime and tk_xtime_add John Stultz
2012-07-24 12:08 ` Prarit Bhargava
2012-07-24 14:55 ` [tip:timers/urgent] " tip-bot for John Stultz
2012-08-19 20:09 ` [PATCH] time: Fix casting issue in timekeeping_forward_now Andreas Schwab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.