mirror of
https://github.com/torvalds/linux.git
synced 2024-12-19 17:41:29 +00:00
28b92e09e2
With tk->wall_to_monotonic.tv_nsec being a 32-bit value on 32-bit systems, (tk->wall_to_monotonic.tv_nsec << tk->shift) in update_vsyscall() may lose upper bits or, worse, add them since compiler will do this: (u64)(tk->wall_to_monotonic.tv_nsec << tk->shift) instead of ((u64)tk->wall_to_monotonic.tv_nsec << tk->shift) So if, for example, tv_nsec is 0x800000 and shift is 8 we will end up with 0xffffffff80000000 instead of 0x80000000. And then we are stuck in the subsequent 'while' loop. We need an explicit cast. Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Link: http://lkml.kernel.org/r/1399648287-15178-1-git-send-email-boris.ostrovsky@oracle.com Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: <stable@vger.kernel.org> # v3.14 Signed-off-by: H. Peter Anvin <hpa@zytor.com>
70 lines
2.0 KiB
C
70 lines
2.0 KiB
C
/*
|
|
* Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
|
|
* Copyright 2003 Andi Kleen, SuSE Labs.
|
|
*
|
|
* Modified for x86 32 bit architecture by
|
|
* Stefani Seibold <stefani@seibold.net>
|
|
* sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany
|
|
*
|
|
* Thanks to hpa@transmeta.com for some useful hint.
|
|
* Special thanks to Ingo Molnar for his early experience with
|
|
* a different vsyscall implementation for Linux/IA32 and for the name.
|
|
*
|
|
*/
|
|
|
|
#include <linux/timekeeper_internal.h>
|
|
#include <asm/vgtod.h>
|
|
#include <asm/vvar.h>
|
|
|
|
DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
|
|
|
|
void update_vsyscall_tz(void)
|
|
{
|
|
vsyscall_gtod_data.tz_minuteswest = sys_tz.tz_minuteswest;
|
|
vsyscall_gtod_data.tz_dsttime = sys_tz.tz_dsttime;
|
|
}
|
|
|
|
void update_vsyscall(struct timekeeper *tk)
|
|
{
|
|
struct vsyscall_gtod_data *vdata = &vsyscall_gtod_data;
|
|
|
|
gtod_write_begin(vdata);
|
|
|
|
/* copy vsyscall data */
|
|
vdata->vclock_mode = tk->clock->archdata.vclock_mode;
|
|
vdata->cycle_last = tk->clock->cycle_last;
|
|
vdata->mask = tk->clock->mask;
|
|
vdata->mult = tk->mult;
|
|
vdata->shift = tk->shift;
|
|
|
|
vdata->wall_time_sec = tk->xtime_sec;
|
|
vdata->wall_time_snsec = tk->xtime_nsec;
|
|
|
|
vdata->monotonic_time_sec = tk->xtime_sec
|
|
+ tk->wall_to_monotonic.tv_sec;
|
|
vdata->monotonic_time_snsec = tk->xtime_nsec
|
|
+ ((u64)tk->wall_to_monotonic.tv_nsec
|
|
<< tk->shift);
|
|
while (vdata->monotonic_time_snsec >=
|
|
(((u64)NSEC_PER_SEC) << tk->shift)) {
|
|
vdata->monotonic_time_snsec -=
|
|
((u64)NSEC_PER_SEC) << tk->shift;
|
|
vdata->monotonic_time_sec++;
|
|
}
|
|
|
|
vdata->wall_time_coarse_sec = tk->xtime_sec;
|
|
vdata->wall_time_coarse_nsec = (long)(tk->xtime_nsec >> tk->shift);
|
|
|
|
vdata->monotonic_time_coarse_sec =
|
|
vdata->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec;
|
|
vdata->monotonic_time_coarse_nsec =
|
|
vdata->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
|
|
|
|
while (vdata->monotonic_time_coarse_nsec >= NSEC_PER_SEC) {
|
|
vdata->monotonic_time_coarse_nsec -= NSEC_PER_SEC;
|
|
vdata->monotonic_time_coarse_sec++;
|
|
}
|
|
|
|
gtod_write_end(vdata);
|
|
}
|