Skip to contentSkip to conversation

x86: convert x86_platform_ops to timespec64

PATCH Superseded Arnd Bergmann 4 participants 13 messages Oct 13, 2017 – Oct 16, 2017

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: convert x86_platform_ops to timespec64

The x86 platform operations are fairly isolated, so we can change them from using timespec to timespec64. I checked that All the users and callers are safe, and there is only one critical function that is broken beyond 2106:

pvclock_read_wallclock() uses a 32-bit number of seconds since the epoch to communicate the boot time between host and guest in a virtual environment. This will work until 2106, but we should ideally find a replacement anyway. I've added a comment about it there.

---
 arch/x86/include/asm/intel_mid_vrtc.h        |  4 ++--
 arch/x86/include/asm/mc146818rtc.h           |  4 ++--
 arch/x86/include/asm/pvclock.h               |  2 +-
 arch/x86/include/asm/x86_init.h              |  6 +++---
 arch/x86/kernel/kvmclock.c                   |  4 ++--
 arch/x86/kernel/pvclock.c                    | 12 +++++++++---
 arch/x86/kernel/rtc.c                        | 16 ++++++++--------
 arch/x86/platform/intel-mid/intel_mid_vrtc.c | 10 +++++-----
 arch/x86/xen/time.c                          | 10 +++++-----
 9 files changed, 37 insertions(+), 31 deletions(-)
arch/x86/include/asm/intel_mid_vrtc.h +2 -2
index 86ff4685c409..19202320f0be 100644
@@ -3,7 +3,7 @@
 
 extern unsigned char vrtc_cmos_read(unsigned char reg);
 extern void vrtc_cmos_write(unsigned char val, unsigned char reg);
-extern void vrtc_get_time(struct timespec *now);
-extern int vrtc_set_mmss(const struct timespec *now);
+extern void vrtc_get_time(struct timespec64 *now);
+extern int vrtc_set_mmss(const struct timespec64 *now);
 
 #endif
arch/x86/include/asm/mc146818rtc.h +2 -2
index 24acd9ba7837..1b574e5eb3b2 100644
@@ -94,8 +94,8 @@ static inline unsigned char current_lock_cmos_reg(void)
 unsigned char rtc_cmos_read(unsigned char addr);
 void rtc_cmos_write(unsigned char val, unsigned char addr);
 
-extern int mach_set_rtc_mmss(const struct timespec *now);
-extern void mach_get_cmos_time(struct timespec *now);
+extern int mach_set_rtc_mmss(const struct timespec64 *now);
+extern void mach_get_cmos_time(struct timespec64 *now);
 
 #define RTC_IRQ 8
 
arch/x86/include/asm/pvclock.h +1 -1
index 448cfe1b48cf..fc3138fd3aff 100644
@@ -20,7 +20,7 @@ void pvclock_set_flags(u8 flags);
 unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src);
 void pvclock_read_wallclock(struct pvclock_wall_clock *wall,
 			    struct pvclock_vcpu_time_info *vcpu,
-			    struct timespec *ts);
+			    struct timespec64 *ts);
 void pvclock_resume(void);
 
 void pvclock_touch_watchdogs(void);
arch/x86/include/asm/x86_init.h +3 -3
index f45acdf45957..0c5007b72916 100644
@@ -141,7 +141,7 @@ struct x86_cpuinit_ops {
 	void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
 };
 
-struct timespec;
+struct timespec64;
 
 /**
  * struct x86_legacy_devices - legacy x86 devices
@@ -223,8 +223,8 @@ struct x86_legacy_features {
 struct x86_platform_ops {
 	unsigned long (*calibrate_cpu)(void);
 	unsigned long (*calibrate_tsc)(void);
-	void (*get_wallclock)(struct timespec *ts);
-	int (*set_wallclock)(const struct timespec *ts);
+	void (*get_wallclock)(struct timespec64 *ts);
+	int (*set_wallclock)(const struct timespec64 *ts);
 	void (*iommu_shutdown)(void);
 	bool (*is_untracked_pat_range)(u64 start, u64 end);
 	void (*nmi_init)(void);
arch/x86/kernel/kvmclock.c +2 -2
index d88967659098..01c76e8cd4be 100644
@@ -58,7 +58,7 @@ EXPORT_SYMBOL_GPL(pvclock_pvti_cpu0_va);
  * have elapsed since the hypervisor wrote the data. So we try to account for
  * that with system time
  */
-static void kvm_get_wallclock(struct timespec *now)
+static void kvm_get_wallclock(struct timespec64 *now)
 {
 	struct pvclock_vcpu_time_info *vcpu_time;
 	int low, high;
@@ -77,7 +77,7 @@ static void kvm_get_wallclock(struct timespec *now)
 	put_cpu();
 }
 
-static int kvm_set_wallclock(const struct timespec *now)
+static int kvm_set_wallclock(const struct timespec64 *now)
 {
 	return -1;
 }
arch/x86/kernel/pvclock.c +9 -3
index 5c3f6d6a5078..1a7084ad07b9 100644
@@ -121,11 +121,11 @@ u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
 
 void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
 			    struct pvclock_vcpu_time_info *vcpu_time,
-			    struct timespec *ts)
+			    struct timespec64 *ts)
 {
 	u32 version;
 	u64 delta;
-	struct timespec now;
+	struct timespec64 now;
 
 	/* get wallclock at system boot */
 	do {
@@ -136,11 +136,17 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
 		rmb();		/* fetch time before checking version */
 	} while ((wall_clock->version & 1) || (version != wall_clock->version));
 
+	/*
+	 * Note: wall_clock->sec is a u32 value, so it can only store dates
+	 * between 1970 and 2106. To allow times beyond that, we need to
+	 * create a new hypercall interface with an extended pvclock_wall_clock
+	 * structure like ARM has.
+	 */
 	delta = pvclock_clocksource_read(vcpu_time);	/* time since system boot */
 	delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;
 
 	now.tv_nsec = do_div(delta, NSEC_PER_SEC);
 	now.tv_sec = delta;
 
-	set_normalized_timespec(ts, now.tv_sec, now.tv_nsec);
+	set_normalized_timespec64(ts, now.tv_sec, now.tv_nsec);
 }
arch/x86/kernel/rtc.c +8 -8
index 5b21cb7d84d6..f5a687c38c6d 100644
@@ -38,13 +38,13 @@ EXPORT_SYMBOL(rtc_lock);
  * jump to the next second precisely 500 ms later. Check the Motorola
  * MC146818A or Dallas DS12887 data sheet for details.
  */
-int mach_set_rtc_mmss(const struct timespec *now)
+int mach_set_rtc_mmss(const struct timespec64 *now)
 {
-	unsigned long nowtime = now->tv_sec;
+	time64_t nowtime = now->tv_sec;
 	struct rtc_time tm;
 	int retval = 0;
 
-	rtc_time_to_tm(nowtime, &tm);
+	rtc_time64_to_tm(nowtime, &tm);
 	if (!rtc_valid_tm(&tm)) {
 		retval = mc146818_set_time(&tm);
 		if (retval)
@@ -52,14 +52,14 @@ int mach_set_rtc_mmss(const struct timespec *now)
 			       __func__, retval);
 	} else {
 		printk(KERN_ERR
-		       "%s: Invalid RTC value: write of %lx to RTC failed\n",
+		       "%s: Invalid RTC value: write of %llx to RTC failed\n",
 			__func__, nowtime);
 		retval = -EINVAL;
 	}
 	return retval;
 }
 
-void mach_get_cmos_time(struct timespec *now)
+void mach_get_cmos_time(struct timespec64 *now)
 {
 	unsigned int status, year, mon, day, hour, min, sec, century = 0;
 	unsigned long flags;
@@ -117,7 +117,7 @@ void mach_get_cmos_time(struct timespec *now)
 	} else
 		year += CMOS_YEARS_OFFS;
 
-	now->tv_sec = mktime(year, mon, day, hour, min, sec);
+	now->tv_sec = mktime64(year, mon, day, hour, min, sec);
 	now->tv_nsec = 0;
 }
 
@@ -144,13 +144,13 @@ void rtc_cmos_write(unsigned char val, unsigned char addr)
 }
 EXPORT_SYMBOL(rtc_cmos_write);
 
-int update_persistent_clock(struct timespec now)
+int update_persistent_clock64(struct timespec64 now)
 {
 	return x86_platform.set_wallclock(&now);
 }
 
 /* not static: needed by APM */
-void read_persistent_clock(struct timespec *ts)
+void read_persistent_clock64(struct timespec64 *ts)
 {
 	x86_platform.get_wallclock(ts);
 }
arch/x86/platform/intel-mid/intel_mid_vrtc.c +5 -5
index 58024862a7eb..d68b9b10481d 100644
@@ -57,7 +57,7 @@ void vrtc_cmos_write(unsigned char val, unsigned char reg)
 }
 EXPORT_SYMBOL_GPL(vrtc_cmos_write);
 
-void vrtc_get_time(struct timespec *now)
+void vrtc_get_time(struct timespec64 *now)
 {
 	u8 sec, min, hour, mday, mon;
 	unsigned long flags;
@@ -83,18 +83,18 @@ void vrtc_get_time(struct timespec *now)
 	pr_info("vRTC: sec: %d min: %d hour: %d day: %d "
 		"mon: %d year: %d\n", sec, min, hour, mday, mon, year);
 
-	now->tv_sec = mktime(year, mon, mday, hour, min, sec);
+	now->tv_sec = mktime64(year, mon, mday, hour, min, sec);
 	now->tv_nsec = 0;
 }
 
-int vrtc_set_mmss(const struct timespec *now)
+int vrtc_set_mmss(const struct timespec64 *now)
 {
 	unsigned long flags;
 	struct rtc_time tm;
 	int year;
 	int retval = 0;
 
-	rtc_time_to_tm(now->tv_sec, &tm);
+	rtc_time64_to_tm(now->tv_sec, &tm);
 	if (!rtc_valid_tm(&tm) && tm.tm_year >= 72) {
 		/*
 		 * tm.year is the number of years since 1900, and the
@@ -110,7 +110,7 @@ int vrtc_set_mmss(const struct timespec *now)
 		vrtc_cmos_write(tm.tm_sec, RTC_SECONDS);
 		spin_unlock_irqrestore(&rtc_lock, flags);
 	} else {
-		pr_err("%s: Invalid vRTC value: write of %lx to vRTC failed\n",
+		pr_err("%s: Invalid vRTC value: write of %llx to vRTC failed\n",
 			__func__, now->tv_sec);
 		retval = -EINVAL;
 	}
arch/x86/xen/time.c +5 -5
index 1ecb05db3632..b1eed21a7b46 100644
@@ -56,7 +56,7 @@ static u64 xen_clocksource_get_cycles(struct clocksource *cs)
 	return xen_clocksource_read();
 }
 
-static void xen_read_wallclock(struct timespec *ts)
+static void xen_read_wallclock(struct timespec64 *ts)
 {
 	struct shared_info *s = HYPERVISOR_shared_info;
 	struct pvclock_wall_clock *wall_clock = &(s->wc);
@@ -67,12 +67,12 @@ static void xen_read_wallclock(struct timespec *ts)
 	put_cpu_var(xen_vcpu);
 }
 
-static void xen_get_wallclock(struct timespec *now)
+static void xen_get_wallclock(struct timespec64 *now)
 {
 	xen_read_wallclock(now);
 }
 
-static int xen_set_wallclock(const struct timespec *now)
+static int xen_set_wallclock(const struct timespec64 *now)
 {
 	return -1;
 }
@@ -373,7 +373,7 @@ static const struct pv_time_ops xen_time_ops __initconst = {
 static void __init xen_time_init(void)
 {
 	int cpu = smp_processor_id();
-	struct timespec tp;
+	struct timespec64 tp;
 
 	/* As Dom0 is never moved, no penalty on using TSC there */
 	if (xen_initial_domain())
@@ -391,7 +391,7 @@ static void __init xen_time_init(void)
 
 	/* Set initial system time with full resolution */
 	xen_read_wallclock(&tp);
-	do_settimeofday(&tp);
+	do_settimeofday64(&tp);
 
 	setup_force_cpu_cap(X86_FEATURE_TSC);
 
Signature · 7 lines
2.9.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Arnd Bergmann

The x86 platform operations are fairly isolated, so we can change them from using timespec to timespec64. I checked that All the users and callers are safe, and there is only one critical function that is broken beyond 2106:

pvclock_read_wallclock() uses a 32-bit number of seconds since the epoch to communicate the boot time between host and guest in a virtual environment. This will work until 2106, but we should ideally find a replacement anyway. I've added a comment about it there.

Quoted 11 lines
---
 arch/x86/include/asm/intel_mid_vrtc.h        |  4 ++--
 arch/x86/include/asm/mc146818rtc.h           |  4 ++--
 arch/x86/include/asm/pvclock.h               |  2 +-
 arch/x86/include/asm/x86_init.h              |  6 +++---
 arch/x86/kernel/kvmclock.c                   |  4 ++--
 arch/x86/kernel/pvclock.c                    | 12 +++++++++---
 arch/x86/kernel/rtc.c                        | 16 ++++++++--------
 arch/x86/platform/intel-mid/intel_mid_vrtc.c | 10 +++++-----
 arch/x86/xen/time.c                          | 10 +++++-----
 9 files changed, 37 insertions(+), 31 deletions(-)

Xen bits:

with a couple of nits:

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 144

Quoted 10 lines
arch/x86/kernel/pvclock.c +6 -0
@@ -136,11 +136,17 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
 		rmb();		/* fetch time before checking version */
 	} while ((wall_clock->version & 1) || (version != wall_clock->version));
 
+	/*
+	 * Note: wall_clock->sec is a u32 value, so it can only store dates
+	 * between 1970 and 2106. To allow times beyond that, we need to
+	 * create a new hypercall interface with an extended pvclock_wall_clock
+	 * structure like ARM has.
+	 */

I think this comment block should be moved up above 'now.tv_sec = wall_clock->sec;'

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 146

Quoted 2 lines
arch/x86/kernel/pvclock.c +0 -0
 	delta = pvclock_clocksource_read(vcpu_time);	/* time since system boot */
 	delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;

Now that tv_sec is a 64-bit quantity the cast can be dropped.

-boris

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,

Quoted 8 lines
arch/x86/kernel/pvclock.c +1 -1
 	now.tv_nsec = do_div(delta, NSEC_PER_SEC);
 	now.tv_sec = delta;
 
-	set_normalized_timespec(ts, now.tv_sec, now.tv_nsec);
+	set_normalized_timespec64(ts, now.tv_sec, now.tv_nsec);
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann

The x86 platform operations are fairly isolated, so we can change them from using timespec to timespec64. I checked that All the users and callers are safe, and there is only one critical function that is broken beyond 2106:

pvclock_read_wallclock() uses a 32-bit number of seconds since the epoch to communicate the boot time between host and guest in a virtual environment. This will work until 2106, but we should ideally find a replacement anyway. I've added a comment about it there.

Quoted 11 lines
---
 arch/x86/include/asm/intel_mid_vrtc.h        |  4 ++--
 arch/x86/include/asm/mc146818rtc.h           |  4 ++--
 arch/x86/include/asm/pvclock.h               |  2 +-
 arch/x86/include/asm/x86_init.h              |  6 +++---
 arch/x86/kernel/kvmclock.c                   |  4 ++--
 arch/x86/kernel/pvclock.c                    | 12 +++++++++---
 arch/x86/kernel/rtc.c                        | 16 ++++++++--------
 arch/x86/platform/intel-mid/intel_mid_vrtc.c | 10 +++++-----
 arch/x86/xen/time.c                          | 10 +++++-----
 9 files changed, 37 insertions(+), 31 deletions(-)

Xen bits:

with a couple of nits:

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 144

Quoted 10 lines
arch/x86/kernel/pvclock.c +6 -0
@@ -136,11 +136,17 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
 		rmb();		/* fetch time before checking version */
 	} while ((wall_clock->version & 1) || (version != wall_clock->version));
 
+	/*
+	 * Note: wall_clock->sec is a u32 value, so it can only store dates
+	 * between 1970 and 2106. To allow times beyond that, we need to
+	 * create a new hypercall interface with an extended pvclock_wall_clock
+	 * structure like ARM has.
+	 */

I think this comment block should be moved up above 'now.tv_sec = wall_clock->sec;'

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 146

Quoted 2 lines
arch/x86/kernel/pvclock.c +0 -0
 	delta = pvclock_clocksource_read(vcpu_time);	/* time since system boot */
 	delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;

Now that tv_sec is a 64-bit quantity the cast can be dropped.

-boris

Quoted 8 lines
arch/x86/kernel/pvclock.c +1 -1
 	now.tv_nsec = do_div(delta, NSEC_PER_SEC);
 	now.tv_sec = delta;
 
-	set_normalized_timespec(ts, now.tv_sec, now.tv_nsec);
+	set_normalized_timespec64(ts, now.tv_sec, now.tv_nsec);
 }
 
#11 lore raw
In reply to Arnd Bergmann
url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/x86-convert-x86_platform_ops-to-timespec64/20171016-091601 config: x86_64-allmodconfig (attached as .config) compiler: gcc-6 (Debian…

Hi Arnd,

[auto build test ERROR on tip/x86/core]
[also build test ERROR on v4.14-rc5 next-20171013]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/x86-convert-x86_platform_ops-to-timespec64/20171016-091601
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

arch/x86/xen/time.c: In function 'xen_init_time_ops':

>> arch/x86/xen/time.c:418:29: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     x86_platform.get_wallclock = xen_get_wallclock;
                                ^
   arch/x86/xen/time.c:421:30: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
      x86_platform.set_wallclock = xen_set_wallclock;
                                 ^
   arch/x86/xen/time.c: In function 'xen_hvm_init_time_ops':
   arch/x86/xen/time.c:458:29: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     x86_platform.get_wallclock = xen_get_wallclock;
                                ^
   arch/x86/xen/time.c:459:29: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     x86_platform.set_wallclock = xen_set_wallclock;
                                ^
   cc1: some warnings being treated as errors
--
   In file included from include/linux/printk.h:6:0,
                    from include/linux/kernel.h:13,
                    from arch/x86/platform/intel-mid/intel_mid_vrtc.c:20:
   arch/x86/platform/intel-mid/intel_mid_vrtc.c: In function 'vrtc_set_mmss':
>> include/linux/kern_levels.h:4:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 3 has type '__kernel_time_t {aka const long int}' [-Wformat=]
    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/kern_levels.h:10:18: note: in expansion of macro 'KERN_SOH'
    #define KERN_ERR KERN_SOH "3" /* error conditions */
                     ^~~~~~~~
   include/linux/printk.h:301:9: note: in expansion of macro 'KERN_ERR'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
            ^~~~~~~~
>> arch/x86/platform/intel-mid/intel_mid_vrtc.c:113:3: note: in expansion of macro 'pr_err'

pr_err("%s: Invalid vRTC value: write of %llx to vRTC failed\n", ^~~~~~
--
In file included from include/linux/printk.h:6:0,

                    from include/linux/kernel.h:13,
                    from arch/x86//platform/intel-mid/intel_mid_vrtc.c:20:
   arch/x86//platform/intel-mid/intel_mid_vrtc.c: In function 'vrtc_set_mmss':
>> include/linux/kern_levels.h:4:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 3 has type '__kernel_time_t {aka const long int}' [-Wformat=]
    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/kern_levels.h:10:18: note: in expansion of macro 'KERN_SOH'
    #define KERN_ERR KERN_SOH "3" /* error conditions */
                     ^~~~~~~~
   include/linux/printk.h:301:9: note: in expansion of macro 'KERN_ERR'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
            ^~~~~~~~

arch/x86//platform/intel-mid/intel_mid_vrtc.c:113:3: note: in expansion of macro 'pr_err'
pr_err("%s: Invalid vRTC value: write of %llx to vRTC failed\n",
^~~~~~

vim +418 arch/x86/xen/time.c

409771d2 Stefano Stabellini 2010-05-14  408  
d162809f Boris Ostrovsky    2017-05-03  409  void __ref xen_init_time_ops(void)
409771d2 Stefano Stabellini 2010-05-14  410  {
409771d2 Stefano Stabellini 2010-05-14  411  	pv_time_ops = xen_time_ops;
409771d2 Stefano Stabellini 2010-05-14  412  
409771d2 Stefano Stabellini 2010-05-14  413  	x86_init.timers.timer_init = xen_time_init;
409771d2 Stefano Stabellini 2010-05-14  414  	x86_init.timers.setup_percpu_clockev = x86_init_noop;
409771d2 Stefano Stabellini 2010-05-14  415  	x86_cpuinit.setup_percpu_clockev = x86_init_noop;
409771d2 Stefano Stabellini 2010-05-14  416  
409771d2 Stefano Stabellini 2010-05-14  417  	x86_platform.calibrate_tsc = xen_tsc_khz;
409771d2 Stefano Stabellini 2010-05-14 @418  	x86_platform.get_wallclock = xen_get_wallclock;
47433b8c David Vrabel       2013-06-27  419  	/* Dom0 uses the native method to set the hardware RTC. */
47433b8c David Vrabel       2013-06-27  420  	if (!xen_initial_domain())
409771d2 Stefano Stabellini 2010-05-14  421  		x86_platform.set_wallclock = xen_set_wallclock;
409771d2 Stefano Stabellini 2010-05-14  422  }

409771d2 Stefano Stabellini 2010-05-14 423

:::::: The code at line 418 was first introduced by commit
:::::: 409771d258e9dd71c30f3c9520fd2b796ffc40f0 x86: Use xen_vcpuop_clockevent, xen_clocksource and xen wallclock.

:::::: TO: Stefano Stabellini <[email protected]> :::::: CC: Jeremy Fitzhardinge <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#12 lore raw
In reply to Arnd Bergmann
url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/x86-convert-x86_platform_ops-to-timespec64/20171016-091601 config: x86_64-allmodconfig (attached as .config) compiler: gcc-6 (Debian…

Hi Arnd,

[auto build test ERROR on tip/x86/core]
[also build test ERROR on v4.14-rc5 next-20171013]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/x86-convert-x86_platform_ops-to-timespec64/20171016-091601
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

arch/x86/xen/time.c: In function 'xen_init_time_ops':

>> arch/x86/xen/time.c:418:29: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     x86_platform.get_wallclock = xen_get_wallclock;
                                ^
   arch/x86/xen/time.c:421:30: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
      x86_platform.set_wallclock = xen_set_wallclock;
                                 ^
   arch/x86/xen/time.c: In function 'xen_hvm_init_time_ops':
   arch/x86/xen/time.c:458:29: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     x86_platform.get_wallclock = xen_get_wallclock;
                                ^
   arch/x86/xen/time.c:459:29: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     x86_platform.set_wallclock = xen_set_wallclock;
                                ^
   cc1: some warnings being treated as errors
--
   In file included from include/linux/printk.h:6:0,
                    from include/linux/kernel.h:13,
                    from arch/x86/platform/intel-mid/intel_mid_vrtc.c:20:
   arch/x86/platform/intel-mid/intel_mid_vrtc.c: In function 'vrtc_set_mmss':
>> include/linux/kern_levels.h:4:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 3 has type '__kernel_time_t {aka const long int}' [-Wformat=]
    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/kern_levels.h:10:18: note: in expansion of macro 'KERN_SOH'
    #define KERN_ERR KERN_SOH "3" /* error conditions */
                     ^~~~~~~~
   include/linux/printk.h:301:9: note: in expansion of macro 'KERN_ERR'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
            ^~~~~~~~
>> arch/x86/platform/intel-mid/intel_mid_vrtc.c:113:3: note: in expansion of macro 'pr_err'

pr_err("%s: Invalid vRTC value: write of %llx to vRTC failed\n", ^~~~~~
--
In file included from include/linux/printk.h:6:0,

                    from include/linux/kernel.h:13,
                    from arch/x86//platform/intel-mid/intel_mid_vrtc.c:20:
   arch/x86//platform/intel-mid/intel_mid_vrtc.c: In function 'vrtc_set_mmss':
>> include/linux/kern_levels.h:4:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 3 has type '__kernel_time_t {aka const long int}' [-Wformat=]
    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/kern_levels.h:10:18: note: in expansion of macro 'KERN_SOH'
    #define KERN_ERR KERN_SOH "3" /* error conditions */
                     ^~~~~~~~
   include/linux/printk.h:301:9: note: in expansion of macro 'KERN_ERR'
     printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
            ^~~~~~~~

arch/x86//platform/intel-mid/intel_mid_vrtc.c:113:3: note: in expansion of macro 'pr_err'
pr_err("%s: Invalid vRTC value: write of %llx to vRTC failed\n",
^~~~~~

vim +418 arch/x86/xen/time.c

409771d2 Stefano Stabellini 2010-05-14  408  
d162809f Boris Ostrovsky    2017-05-03  409  void __ref xen_init_time_ops(void)
409771d2 Stefano Stabellini 2010-05-14  410  {
409771d2 Stefano Stabellini 2010-05-14  411  	pv_time_ops = xen_time_ops;
409771d2 Stefano Stabellini 2010-05-14  412  
409771d2 Stefano Stabellini 2010-05-14  413  	x86_init.timers.timer_init = xen_time_init;
409771d2 Stefano Stabellini 2010-05-14  414  	x86_init.timers.setup_percpu_clockev = x86_init_noop;
409771d2 Stefano Stabellini 2010-05-14  415  	x86_cpuinit.setup_percpu_clockev = x86_init_noop;
409771d2 Stefano Stabellini 2010-05-14  416  
409771d2 Stefano Stabellini 2010-05-14  417  	x86_platform.calibrate_tsc = xen_tsc_khz;
409771d2 Stefano Stabellini 2010-05-14 @418  	x86_platform.get_wallclock = xen_get_wallclock;
47433b8c David Vrabel       2013-06-27  419  	/* Dom0 uses the native method to set the hardware RTC. */
47433b8c David Vrabel       2013-06-27  420  	if (!xen_initial_domain())
409771d2 Stefano Stabellini 2010-05-14  421  		x86_platform.set_wallclock = xen_set_wallclock;
409771d2 Stefano Stabellini 2010-05-14  422  }

409771d2 Stefano Stabellini 2010-05-14 423

:::::: The code at line 418 was first introduced by commit
:::::: 409771d258e9dd71c30f3c9520fd2b796ffc40f0 x86: Use xen_vcpuop_clockevent, xen_clocksource and xen wallclock.

:::::: TO: Stefano Stabellini <[email protected]> :::::: CC: Jeremy Fitzhardinge <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
In reply to Boris Ostrovsky
Quoted 25 lines · Boris Ostrovsky
Quoted 12 lines · Arnd Bergmann

The x86 platform operations are fairly isolated, so we can change them from using timespec to timespec64. I checked that All the users and callers are safe, and there is only one critical function that is broken beyond 2106:

pvclock_read_wallclock() uses a 32-bit number of seconds since the epoch to communicate the boot time between host and guest in a virtual environment. This will work until 2106, but we should ideally find a replacement anyway. I've added a comment about it there.

Quoted 11 lines
---
 arch/x86/include/asm/intel_mid_vrtc.h        |  4 ++--
 arch/x86/include/asm/mc146818rtc.h           |  4 ++--
 arch/x86/include/asm/pvclock.h               |  2 +-
 arch/x86/include/asm/x86_init.h              |  6 +++---
 arch/x86/kernel/kvmclock.c                   |  4 ++--
 arch/x86/kernel/pvclock.c                    | 12 +++++++++---
 arch/x86/kernel/rtc.c                        | 16 ++++++++--------
 arch/x86/platform/intel-mid/intel_mid_vrtc.c | 10 +++++-----
 arch/x86/xen/time.c                          | 10 +++++-----
 9 files changed, 37 insertions(+), 31 deletions(-)
Quoted 2 lines

Xen bits:

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

Should we add a new version now and deprecate the existing one, or do you think that y2106 is far enough out that we should just ignore the problem?

Quoted 6 lines

with a couple of nits:

Quoted 4 lines
arch/x86/kernel/pvclock.c +0 -0
@@ -136,11 +136,17 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
              rmb();          /* fetch time before checking version */
      } while ((wall_clock->version & 1) || (version != wall_clock->version));
 
Quoted 9 lines

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 144

Quoted 6 lines
arch/x86/kernel/pvclock.c +6 -0
+     /*
+      * Note: wall_clock->sec is a u32 value, so it can only store dates
+      * between 1970 and 2106. To allow times beyond that, we need to
+      * create a new hypercall interface with an extended pvclock_wall_clock
+      * structure like ARM has.
+      */

I think this comment block should be moved up above 'now.tv_sec = wall_clock->sec;'

right, changed.

Quoted 4 lines

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 146

Quoted 2 lines
arch/x86/kernel/pvclock.c +0 -0
      delta = pvclock_clocksource_read(vcpu_time);    /* time since system boot */
      delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;

Now that tv_sec is a 64-bit quantity the cast can be dropped.

Ok dropped. In the meantime I had noticed two more problems with the patch that I did not see earlier when I tested with another patch applied as well. The kbuild test robot reported the exact same problems, and I've done a few hundred randconfig builds without the other patch now, so I'm fairly confident that there are no other problems like those.

I'll follow up with a v2 patch soon.

Arnd
_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038

#10 lore raw
In reply to Boris Ostrovsky
Quoted 25 lines · Boris Ostrovsky
Quoted 12 lines · Arnd Bergmann

The x86 platform operations are fairly isolated, so we can change them from using timespec to timespec64. I checked that All the users and callers are safe, and there is only one critical function that is broken beyond 2106:

pvclock_read_wallclock() uses a 32-bit number of seconds since the epoch to communicate the boot time between host and guest in a virtual environment. This will work until 2106, but we should ideally find a replacement anyway. I've added a comment about it there.

Quoted 11 lines
---
 arch/x86/include/asm/intel_mid_vrtc.h        |  4 ++--
 arch/x86/include/asm/mc146818rtc.h           |  4 ++--
 arch/x86/include/asm/pvclock.h               |  2 +-
 arch/x86/include/asm/x86_init.h              |  6 +++---
 arch/x86/kernel/kvmclock.c                   |  4 ++--
 arch/x86/kernel/pvclock.c                    | 12 +++++++++---
 arch/x86/kernel/rtc.c                        | 16 ++++++++--------
 arch/x86/platform/intel-mid/intel_mid_vrtc.c | 10 +++++-----
 arch/x86/xen/time.c                          | 10 +++++-----
 9 files changed, 37 insertions(+), 31 deletions(-)
Quoted 2 lines

Xen bits:

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

Should we add a new version now and deprecate the existing one, or do you think that y2106 is far enough out that we should just ignore the problem?

Quoted 6 lines

with a couple of nits:

Quoted 4 lines
arch/x86/kernel/pvclock.c +0 -0
@@ -136,11 +136,17 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
              rmb();          /* fetch time before checking version */
      } while ((wall_clock->version & 1) || (version != wall_clock->version));
 
Quoted 9 lines

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 144

Quoted 6 lines
arch/x86/kernel/pvclock.c +6 -0
+     /*
+      * Note: wall_clock->sec is a u32 value, so it can only store dates
+      * between 1970 and 2106. To allow times beyond that, we need to
+      * create a new hypercall interface with an extended pvclock_wall_clock
+      * structure like ARM has.
+      */

I think this comment block should be moved up above 'now.tv_sec = wall_clock->sec;'

right, changed.

Quoted 4 lines

arch/x86/kernel/pvclock.c void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, · line 146

Quoted 2 lines
arch/x86/kernel/pvclock.c +0 -0
      delta = pvclock_clocksource_read(vcpu_time);    /* time since system boot */
      delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;

Now that tv_sec is a 64-bit quantity the cast can be dropped.

Ok dropped. In the meantime I had noticed two more problems with the patch that I did not see earlier when I tested with another patch applied as well. The kbuild test robot reported the exact same problems, and I've done a few hundred randconfig builds without the other patch now, so I'm fairly confident that there are no other problems like those.

I'll follow up with a v2 patch soon.

Arnd

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

maintainer
#4 lore raw
In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

It has to be done separately for each hypervisor.

In KVM, for example, it is probably best to abandon pvclock_read_wallclock altogether, and instead use the recently introduced KVM_HC_CLOCK_PAIRING hypercall. drivers/ptp/ptp_kvm.c is already using it and it's y2106 safe.

Paolo

Quoted 3 lines

Should we add a new version now and deprecate the existing one, or do you think that y2106 is far enough out that we should just ignore the problem?

maintainer
#9 lore raw
In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

It has to be done separately for each hypervisor.

In KVM, for example, it is probably best to abandon pvclock_read_wallclock altogether, and instead use the recently introduced KVM_HC_CLOCK_PAIRING hypercall. drivers/ptp/ptp_kvm.c is already using it and it's y2106 safe.

Paolo

Quoted 3 lines

Should we add a new version now and deprecate the existing one, or do you think that y2106 is far enough out that we should just ignore the problem?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
In reply to Paolo Bonzini
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · Arnd Bergmann

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

Quoted 6 lines

It has to be done separately for each hypervisor.

In KVM, for example, it is probably best to abandon pvclock_read_wallclock altogether, and instead use the recently introduced KVM_HC_CLOCK_PAIRING hypercall. drivers/ptp/ptp_kvm.c is already using it and it's y2106 safe.

Right, makes sense. I see that this interface is currently implemented only for 64-bit x86 in kvm_emulate_hypercall(). Could this be extended to x86-32 and the non-x86 architectures as well?

Arnd
_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038

#8 lore raw
In reply to Paolo Bonzini
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · Arnd Bergmann

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

Quoted 6 lines

It has to be done separately for each hypervisor.

In KVM, for example, it is probably best to abandon pvclock_read_wallclock altogether, and instead use the recently introduced KVM_HC_CLOCK_PAIRING hypercall. drivers/ptp/ptp_kvm.c is already using it and it's y2106 safe.

Right, makes sense. I see that this interface is currently implemented only for 64-bit x86 in kvm_emulate_hypercall(). Could this be extended to x86-32 and the non-x86 architectures as well?

Arnd

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

maintainer
#6 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · Arnd Bergmann

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

It has to be done separately for each hypervisor.

Quoted 8 lines
Quoted 4 lines

In KVM, for example, it is probably best to abandon pvclock_read_wallclock altogether, and instead use the recently introduced KVM_HC_CLOCK_PAIRING hypercall. drivers/ptp/ptp_kvm.c is already using it and it's y2106 safe.

Right, makes sense. I see that this interface is currently implemented only for 64-bit x86 in kvm_emulate_hypercall(). Could this be extended to x86-32 and the non-x86 architectures as well?

Yes, it could be implemented for x86-32 too. The whole pvclock concept however is specific to x86.

Paolo

maintainer
#7 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · Arnd Bergmann

Thanks!

Since you've looked at it overall, do you have an opinion on the question how to fix the PV interface to deal with the pvclock_wall_clock overflow?

It has to be done separately for each hypervisor.

Quoted 8 lines
Quoted 4 lines

In KVM, for example, it is probably best to abandon pvclock_read_wallclock altogether, and instead use the recently introduced KVM_HC_CLOCK_PAIRING hypercall. drivers/ptp/ptp_kvm.c is already using it and it's y2106 safe.

Right, makes sense. I see that this interface is currently implemented only for 64-bit x86 in kvm_emulate_hypercall(). Could this be extended to x86-32 and the non-x86 architectures as well?

Yes, it could be implemented for x86-32 too. The whole pvclock concept however is specific to x86.

Paolo

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel