Add y2038 safe replacements for read_boot_clock(), read_persistent_clock() and update_persistent_clock()
Subsystems (6)
cover Add y2038 safe replacements for read_boot_clock(), read_persistent_clock() and update_persistent_clock()
From: Xunlei Pang <[email protected]>
read_boot_clock(), read_persistent_clock() and update_persistent_clock() all use timespec which may have "y2038 problem", thus we are planning on converting all of them to use timespec64.
The approach we're using is:
1) First of all, add the "__weak" implementaion of xxx_clock64() which uses xxx_clock() and timespec64.
Let's take read_persistent_clock() as an example. We can create its y2038-safe version below:
void __weak read_persistent_clock64(struct timespec64 *ts64)
{
struct timespec ts;
read_persistent_clock(&ts);
*ts64 = timespec_to_timespec64(ts);
} Then, replace all the call sites of xxx_clock() with xxx_clock64() except the one used by xxx_clock64().
2) Convert every architecture specific xxx_clock() to xxx_clock64() one by one. At this point, we can convert the three functions at a time if needed, because most time they're correlated.
3) Remove xxx_clock() after all its architecture specific implementations have been converted to use corresponding y2038 safe xxx_clock64().
This patchset firstly finished the step1 for all the three functions, then focused on read_boot_clock() which is simple to go on with step2 and step3 as a whole show.
As for read_persistent_clock() and update_persistent_clock() which are more complex, requiring many efforts to convert every architecture specific implementation gradually.
The approach used here is Suggested-by: "Arnd Bergmann <[email protected]>"
Xunlei Pang (8):
time: Add y2038 safe read_boot_clock64()
time: Add y2038 safe read_persistent_clock64()
time: Add y2038 safe update_persistent_clock64()
ARM: OMAP: 32k counter: Provide y2038-safe
omap_read_persistent_clock() replacement
ARM: tegra: clock: Provide y2038-safe tegra_read_persistent_clock()
replacement
ARM: time: Provide read_boot_clock64() and read_persistent_clock64()
s390: time: Provide read_boot_clock64() and read_persistent_clock64()
time: Remove read_boot_clock()
arch/arm/include/asm/mach/time.h | 3 +-- arch/arm/kernel/time.c | 6 +++--- arch/arm/plat-omap/counter_32k.c | 18 ++++++------------ arch/mips/lasat/sysctl.c | 4 ++-- arch/s390/include/asm/timex.h | 4 ++-- arch/s390/kernel/debug.c | 4 ++-- arch/s390/kernel/time.c | 6 +++--- drivers/clocksource/tegra20_timer.c | 15 +++++++-------- drivers/rtc/systohc.c | 2 +- include/linux/timekeeping.h | 4 +++- kernel/time/ntp.c | 13 ++++++++++++- kernel/time/timekeeping.c | 31 ++++++++++++++++--------------- 12 files changed, 58 insertions(+), 52 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/8 time: Add y2038 safe read_boot_clock64()
From: Xunlei Pang <[email protected]>
As part of addressing in-kernel y2038 issues, this patch adds read_boot_clock64() and replaces all the call sites of read_boot_clock() with this function. This is a __weak implementation, which simply calls the existing y2038 unsafe read_boot_clock().
This allows architecture specific implementations to be converted independently, and eventually the y2038 unsafe read_boot_clock() can be removed after all its architecture specific implementations have been converted to read_boot_clock64().
--- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
include/linux/timekeeping.h +1 -0
@@ -263,6 +263,7 @@ static inline bool has_persistent_clock(void)extern void read_persistent_clock (struct timespec *ts);extern void read_boot_clock (struct timespec *ts); +extern void read_boot_clock64 (struct timespec64 *ts);extern int update_persistent_clock (struct timespec now);
kernel/time/timekeeping.c +9 -2
@@ -1072,6 +1072,14 @@ void __weak read_boot_clock(struct timespec *ts) ts->tv_nsec =0 ; } +void __weak read_boot_clock64 (struct timespec64 *ts64) +{ +struct timespec ts; + +read_boot_clock (&ts); + *ts64 =timespec_to_timespec64 (ts); +} +/* * timekeeping_init - Initializes the clocksource and common timekeeping values */
@@ -1093,8 +1101,7 @@ void __init timekeeping_init(void) }else if (now.tv_sec || now.tv_nsec) persistent_clock_exist = true; -read_boot_clock (&ts); - boot =timespec_to_timespec64 (ts); +read_boot_clock64 (&boot);if (!timespec64_valid_strict (&boot)) {pr_warn ("WARNING: Boot clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n" );
Signature · 1 line
1.9.1
PATCH 2/8 time: Add y2038 safe read_persistent_clock64()
In reply to Xunlei PangFrom: Xunlei Pang <[email protected]>
As part of addressing in-kernel y2038 issues, this patch adds read_persistent_clock64() and replaces all the call sites of read_persistent_clock() with this function. This is a __weak implementation, which simply calls the existing y2038 unsafe read_persistent_clock().
This allows architecture specific implementations to be converted independently, and eventually the y2038 unsafe read_persistent_clock() can be removed after all its architecture specific implementations have been converted to read_persistent_clock64().
--- arch/mips/lasat/sysctl.c | 4 ++-- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 22 ++++++++++++---------- 3 files changed, 15 insertions(+), 12 deletions(-)
arch/mips/lasat/sysctl.c +2 -2
@@ -75,11 +75,11 @@ static int rtctmp;int proc_dolasatrtc (struct ctl_table *table,int write,void *buffer,size_t *lenp,loff_t *ppos) { -struct timespec ts; +struct timespec64 ts;int r;if (!write) { -read_persistent_clock (&ts); +read_persistent_clock64 (&ts); rtctmp = ts.tv_sec;/* check for time < 0 and set to 0 */ if (rtctmp <0 )
include/linux/timekeeping.h +1 -0
@@ -262,6 +262,7 @@ static inline bool has_persistent_clock(void) }extern void read_persistent_clock (struct timespec *ts); +extern void read_persistent_clock64 (struct timespec64 *ts);extern void read_boot_clock (struct timespec *ts);extern void read_boot_clock64 (struct timespec64 *ts);extern int update_persistent_clock (struct timespec now);
kernel/time/timekeeping.c +12 -10
@@ -1057,6 +1057,14 @@ void __weak read_persistent_clock(struct timespec *ts) ts->tv_nsec =0 ; } +void __weak read_persistent_clock64 (struct timespec64 *ts64) +{ +struct timespec ts; + +read_persistent_clock (&ts); + *ts64 =timespec_to_timespec64 (ts); +} +/** * read_boot_clock - Return time of the system start. *
@@ -1089,10 +1097,8 @@ void __init timekeeping_init(void)struct clocksource *clock;unsigned long flags;struct timespec64 now, boot, tmp; -struct timespec ts; -read_persistent_clock (&ts); - now =timespec_to_timespec64 (ts); +read_persistent_clock64 (&now);if (!timespec64_valid_strict (&now)) {pr_warn ("WARNING: Persistent clock returned invalid value!\n" " Check your CMOS/BIOS settings.\n" );
@@ -1163,7 +1169,7 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,* timekeeping_inject_sleeptime64 - Adds suspend interval to timeekeeping values * @delta: pointer to a timespec64 delta value * -* This hook is for architectures that cannot support read_persistent_clock +* This hook is for architectures that cannot support read_persistent_clock64 * because their RTC/persistent clock is only accessible when irqs are enabled. * * This function should only be called by rtc_resume(), and allows
@@ -1210,12 +1216,10 @@ void timekeeping_resume(void)struct clocksource *clock = tk->tkr.clock;unsigned long flags;struct timespec64 ts_new, ts_delta; -struct timespec tmp;cycle_t cycle_now, cycle_delta;bool suspendtime_found = false; -read_persistent_clock (&tmp); - ts_new =timespec_to_timespec64 (tmp); +read_persistent_clock64 (&ts_new);clockevents_resume ();clocksource_resume ();
@@ -1291,10 +1295,8 @@ int timekeeping_suspend(void)unsigned long flags;struct timespec64 delta, delta_delta;static struct timespec64 old_delta; -struct timespec tmp; -read_persistent_clock (&tmp); - timekeeping_suspend_time =timespec_to_timespec64 (tmp); +read_persistent_clock64 (&timekeeping_suspend_time);/* * On some systems the persistent_clock can not be detected at
Signature · 1 line
1.9.1
PATCH 3/8 time: Add y2038 safe update_persistent_clock64()
In reply to Xunlei PangFrom: Xunlei Pang <[email protected]>
As part of addressing in-kernel y2038 issues, this patch adds update_persistent_clock64() and replaces all the call sites of update_persistent_clock() with this function. This is a __weak implementation, which simply calls the existing y2038 unsafe update_persistent_clock().
This allows architecture specific implementations to be converted independently, and eventually y2038-unsafe update_persistent_clock() can be removed after all its architecture specific implementations have been converted to update_persistent_clock64().
--- drivers/rtc/systohc.c | 2 +- include/linux/timekeeping.h | 1 + kernel/time/ntp.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-)
drivers/rtc/systohc.c +1 -1
@@ -11,7 +11,7 @@* rtc_set_ntp_time - Save NTP synchronized time to the RTC * @now: Current time of day * -* Replacement for the NTP platform function update_persistent_clock +* Replacement for the NTP platform function update_persistent_clock64 * that stores time for later retrieval by rtc_hctosys. * * Returns 0 on successful RTC update, -ENODEV if a RTC update is not
include/linux/timekeeping.h +1 -0
@@ -266,6 +266,7 @@ extern void read_persistent_clock64(struct timespec64 *ts);extern void read_boot_clock (struct timespec *ts);extern void read_boot_clock64 (struct timespec64 *ts);extern int update_persistent_clock (struct timespec now); +extern int update_persistent_clock64 (struct timespec64 now);#endif
kernel/time/ntp.c +12 -1
@@ -459,6 +459,16 @@ out:return leap; } +#ifdef CONFIG_GENERIC_CMOS_UPDATE +int __weak update_persistent_clock64 (struct timespec64 now64) +{ +struct timespec now; + + now =timespec64_to_timespec (now64); +return update_persistent_clock (now); +} +#endif +#if defined(CONFIG_GENERIC_CMOS_UPDATE ) || defined(CONFIG_RTC_SYSTOHC )static void sync_cmos_clock (struct work_struct *work);
@@ -494,8 +504,9 @@ static void sync_cmos_clock(struct work_struct *work)if (persistent_clock_is_local) adjust.tv_sec -= (sys_tz.tz_minuteswest *60 );#ifdef CONFIG_GENERIC_CMOS_UPDATE - fail =update_persistent_clock (timespec64_to_timespec (adjust)); + fail =update_persistent_clock64 (adjust);#endif +#ifdef CONFIG_RTC_SYSTOHC if (fail == -ENODEV ) fail =rtc_set_ntp_time (adjust);
Signature · 1 line
1.9.1
PATCH 4/8 ARM: OMAP: 32k counter: Provide y2038-safe omap_read_persistent_clock() replacement
In reply to Xunlei PangFrom: Xunlei Pang <[email protected]>
As part of addressing "y2038 problem" for in-kernel uses, this patch adds the y2038-safe omap_read_persistent_clock64() using timespec64.
Because we rely on some subsequent changes to convert arm multiarch support, omap_read_persistent_clock() will be removed then.
Also remove the needless spinlock, because read_persistent_clock() doesn't run simultaneously.
--- arch/arm/plat-omap/counter_32k.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
arch/arm/plat-omap/counter_32k.c +12 -10
@@ -44,24 +44,20 @@ static u64 notrace omap_32k_read_sched_clock(void) }/** -* omap_read_persistent_clock - Return time from a persistent clock. +* omap_read_persistent_clock64 - Return time from a persistent clock. * * Reads the time from a source which isn't disabled during PM, the * 32k sync timer. Convert the cycles elapsed since last read into -* nsecs and adds to a monotonically increasing timespec. +* nsecs and adds to a monotonically increasing timespec64. */ -static struct timespec persistent_ts; +static struct timespec64 persistent_ts;static cycles_t cycles;static unsigned int persistent_mult, persistent_shift; -static DEFINE_SPINLOCK (read_persistent_clock_lock); -static void omap_read_persistent_clock (struct timespec *ts) +static void omap_read_persistent_clock64 (struct timespec64 *ts) {unsigned long long nsecs;cycles_t last_cycles; -unsigned long flags; - -spin_lock_irqsave (&read_persistent_clock_lock, flags); last_cycles = cycles; cycles = sync32k_cnt_reg ?readl_relaxed (sync32k_cnt_reg) :0 ;
@@ -69,11 +65,17 @@ static void omap_read_persistent_clock(struct timespec *ts) nsecs =clocksource_cyc2ns (cycles - last_cycles, persistent_mult, persistent_shift); -timespec_add_ns (&persistent_ts, nsecs); +timespec64_add_ns (&persistent_ts, nsecs); *ts = persistent_ts; +} + +static void omap_read_persistent_clock (struct timespec *ts) +{ +struct timespec64 ts64; -spin_unlock_irqrestore (&read_persistent_clock_lock, flags); +omap_read_persistent_clock64 (&ts64); + *ts =timespec64_to_timespec (ts64); }/**
Signature · 1 line
1.9.1
Re: [PATCH 4/8] ARM: OMAP: 32k counter: Provide y2038-safe omap_read_persistent_clock() replacement
Quoted 6 lines · Xunlei Pang
From: Xunlei Pang <[email protected]>
As part of addressing "y2038 problem" for in-kernel uses, this patch adds the y2038-safe
omap_read_persistent_clock64()using timespec64.
Quoted 7 lines
Because we rely on some subsequent changes to convert arm multiarch support,
omap_read_persistent_clock()will be removed then.Also remove the needless spinlock, because
read_persistent_clock()doesn't run simultaneously.Signed-off-by Xunlei Pang <[email protected]>
Looks OK to me:
Quoted 61 lines
--- arch/arm/plat-omap/counter_32k.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)arch/arm/plat-omap/counter_32k.c +12
-10@@ -44,24 +44,20 @@ static u64 notrace omap_32k_read_sched_clock(void) }/** -* omap_read_persistent_clock - Return time from a persistent clock. +* omap_read_persistent_clock64 - Return time from a persistent clock. * * Reads the time from a source which isn't disabled during PM, the * 32k sync timer. Convert the cycles elapsed since last read into -* nsecs and adds to a monotonically increasing timespec. +* nsecs and adds to a monotonically increasing timespec64. */ -static struct timespec persistent_ts; +static struct timespec64 persistent_ts;static cycles_t cycles;static unsigned int persistent_mult, persistent_shift; -static DEFINE_SPINLOCK (read_persistent_clock_lock); -static void omap_read_persistent_clock (struct timespec *ts) +static void omap_read_persistent_clock64 (struct timespec64 *ts) {unsigned long long nsecs;cycles_t last_cycles; -unsigned long flags; - -spin_lock_irqsave (&read_persistent_clock_lock, flags); last_cycles = cycles; cycles = sync32k_cnt_reg ?readl_relaxed (sync32k_cnt_reg) :0 ;@@ -69,11 +65,17 @@ static void omap_read_persistent_clock(struct timespec *ts) nsecs =clocksource_cyc2ns (cycles - last_cycles, persistent_mult, persistent_shift); -timespec_add_ns (&persistent_ts, nsecs); +timespec64_add_ns (&persistent_ts, nsecs); *ts = persistent_ts; +} + +static void omap_read_persistent_clock (struct timespec *ts) +{ +struct timespec64 ts64; -spin_unlock_irqrestore (&read_persistent_clock_lock, flags); +omap_read_persistent_clock64 (&ts64); + *ts =timespec64_to_timespec (ts64); }/** Signature · 1 line
1.9.1
Re: [PATCH 1/8] time: Add y2038 safe read_boot_clock64()
In reply to a message not in the archiveQuoted 1 line · On Wed, Mar 18, 2015 at 5:48 AM, <[email protected]> wrote:
Ping ...
Thanks for the reminder. Since there's not been any objections, I'm queuing this up.
thanks
-john