From: Tony Breeds On platforms that copy sys_tz into the vdso (currently only x86_64, soon to include powerpc), it is possible for the vdso to get out of sync if a user calls (admittedly unusual) settimeofday(NULL, ptr). This patch adds a hook for architectures that set CONFIG_GENERIC_TIME_VSYSCALL to ensure when sys_tz is updated they can also updatee their copy in the vdso. Signed-off-by: Tony Breeds Cc: Andi Kleen Cc: Tony Luck Cc: John Stultz Cc: Paul Mackerras Cc: Benjamin Herrenschmidt Cc: Thomas Gleixner Signed-off-by: Andrew Morton --- arch/ia64/kernel/time.c | 5 +++++ arch/x86_64/kernel/vsyscall.c | 11 ++++++++++- include/linux/clocksource.h | 5 +++++ kernel/time.c | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff -puN arch/ia64/kernel/time.c~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday arch/ia64/kernel/time.c --- a/arch/ia64/kernel/time.c~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday +++ a/arch/ia64/kernel/time.c @@ -371,6 +371,11 @@ ia64_setup_printk_clock(void) ia64_printk_clock = ia64_itc_printk_clock; } +/* IA64 doesn't cache the timezone */ +void update_vsyscall_tz(void) +{ +} + void update_vsyscall(struct timespec *wall, struct clocksource *c) { unsigned long flags; diff -puN arch/x86_64/kernel/vsyscall.c~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday arch/x86_64/kernel/vsyscall.c --- a/arch/x86_64/kernel/vsyscall.c~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday +++ a/arch/x86_64/kernel/vsyscall.c @@ -66,6 +66,16 @@ struct vsyscall_gtod_data __vsyscall_gto .sysctl_enabled = 1, }; +void update_vsyscall_tz(void) +{ + unsigned long flags; + + write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags); + /* sys_tz has changed */ + vsyscall_gtod_data.sys_tz = sys_tz; + write_sequnlock_irqrestore(&vsyscall_gtod_data.lock, flags); +} + void update_vsyscall(struct timespec *wall_time, struct clocksource *clock) { unsigned long flags; @@ -79,7 +89,6 @@ void update_vsyscall(struct timespec *wa vsyscall_gtod_data.clock.shift = clock->shift; vsyscall_gtod_data.wall_time_sec = wall_time->tv_sec; vsyscall_gtod_data.wall_time_nsec = wall_time->tv_nsec; - vsyscall_gtod_data.sys_tz = sys_tz; vsyscall_gtod_data.wall_time_nsec = wall_time->tv_nsec; vsyscall_gtod_data.wall_to_monotonic = wall_to_monotonic; write_sequnlock_irqrestore(&vsyscall_gtod_data.lock, flags); diff -puN include/linux/clocksource.h~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday include/linux/clocksource.h --- a/include/linux/clocksource.h~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday +++ a/include/linux/clocksource.h @@ -222,10 +222,15 @@ extern void clocksource_touch_watchdog(v #ifdef CONFIG_GENERIC_TIME_VSYSCALL extern void update_vsyscall(struct timespec *ts, struct clocksource *c); +extern void update_vsyscall_tz(void); #else static inline void update_vsyscall(struct timespec *ts, struct clocksource *c) { } + +static inline void update_vsyscall_tz(void) +{ +} #endif #endif /* _LINUX_CLOCKSOURCE_H */ diff -puN kernel/time.c~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday kernel/time.c --- a/kernel/time.c~fix-discrepancy-between-vdso-based-gettimeofday-and-sys_gettimeofday +++ a/kernel/time.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -162,6 +163,7 @@ int do_sys_settimeofday(struct timespec if (tz) { /* SMP safe, global irq locking makes it work. */ sys_tz = *tz; + update_vsyscall_tz(); if (firsttime) { firsttime = 0; if (!tv) _