From patchwork Fri Oct 13 18:37:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 115824 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp1015505edb; Fri, 13 Oct 2017 11:41:05 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBcW1Rhuv7L7aNr0upnCBi3X1bvwuUAY3BTpLWC5mJ3NWEyIQgyK+A/CLHsMPxDCPHsdMDM X-Received: by 10.159.229.194 with SMTP id t2mr2161582plq.296.1507920065242; Fri, 13 Oct 2017 11:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507920065; cv=none; d=google.com; s=arc-20160816; b=IPlsjTKH4NaGH9HqvzlkWSap9IWzmqEc2Qt1L1FJ/P06tQUtlDIclsnYiFzfwk/OsO sf1jU0IhnThdqziQj+9gH8ipFfIsVhr1DfwD603PUIiI2xkwDcwcPZvmhUyp4y3NdQ9H HflE0G4JXEgkqNnIyv2C/rU+xiQogA4hjoN8MQ38sCsGrz8M3lqaFU9vSj5URdU4oIKx MHXJULGe7ECvjjOyRdWycf4B7LhSkR5oTpOn0XrSYlSmUxKjUxBM5KDC27sTR1ocuhxF 2s8TWCNL3IEqw4WfHVQQVVgBFDUha43E+a+rmETxsCLEmFczLBcCKjEX0yiIP6wXhxqf nyeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QxCIJPW2fqQ/Kbd8gjL9W1YVeYJfu/HVk/WGDDYkYOE=; b=a93j2wjtH85hxFOZ8kC6oRR+fHL6Mq4kGgCQYWYzAeSME5PlV5Gq2rQCJ5b2Tx6g2Z LLbs8b3u723+9bLGP83K8/Km8kfdu858g1M8AqBD/5SWqpcDe55Es9RFAxOz/99sDdxW fSI5qXnI19IidQCz+fYbFwQRDNrfnqY3vNDGZVrbOgwpY7HvBSd5BDbhlOXOXVrtCJ6/ TBoz7Uek7oja4WVBgtlYskHcEFerbRrI77VBFghblZ6OOA61mQDk8f3rh//YxJGrY6db DTeqa5aTSPA9iAh4g7Wdh+fvGRqN+KQ44fQcs6kdb7F3s5gn8ZuyUlzehn3kaZEskVuh NDAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f34si960537ple.458.2017.10.13.11.41.04; Fri, 13 Oct 2017 11:41:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752845AbdJMSlD (ORCPT + 27 others); Fri, 13 Oct 2017 14:41:03 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:54229 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751367AbdJMSlA (ORCPT ); Fri, 13 Oct 2017 14:41:00 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0MTeXQ-1dcmXj2Uvg-00QQER; Fri, 13 Oct 2017 20:39:39 +0200 From: Arnd Bergmann To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org Cc: y2038@lists.linaro.org, Arnd Bergmann , Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Boris Ostrovsky , Juergen Gross , Marcos Paulo de Souza , Dmitry Torokhov , John Stultz , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH] x86: convert x86_platform_ops to timespec64 Date: Fri, 13 Oct 2017 20:37:35 +0200 Message-Id: <20171013183933.3757079-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:BQeGuHHixNoDdN3zp1BFNp9ecXimuYauKABE+JbnrOxSThcjemk QaN6Pbr53KwDI1eFDU1pX6s6WXBG3HQnPnhls1MidyLrHBodM7OmlRqBhPvAW3Pah6/WJwK FswHOGavmQqBSdPWuN9xTrJ2K8dhuRaY3OzQbsi8NfLDlkeL8L6jTEQtH8A9JcVVInDwrYY kIr6nnWbKoXoTNQ0KLUbQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:XvaQf7DdQlw=:gVZF3Ndv1fen+Xwb63rMKv L8RIk1nVo3aeUGmPiq5NlUqzrHUsgSQEpnf33xrW0VzaHdIFR5Nj0D5Prmhao3al5ChP4FpVX edNbbZmxyvkDZYQg3Up8E6T6piYhIH3pMeMfuoRta894Brz2ouaoQhaKI9H4goZFnLzg83+d/ bNQ+uD4U2Wg8h70Zb63iF6vQHkfy5RIYeu+vj1KcptAzzcTI6e8eYzxV7u+6Zyx6VlToLb6yr v3WHzj8vMOyyO8xY+QVSR8A2nH7RT7aEGgwSM4rui1K2YpD6602OTcZv/nDct80Sf/Ss9TjIG Mu0l8IjZ+aDW0y8Oiukpr1WMt/V8syL4jeASmkJ3T/eEVZyzis2C7LTeqqY1Shsf8FnZyVo3v 6lUOuA6Ee/5x0gavYEFzPQA3qITvHfX0+Z79H2i5TkJ7cNMosepVaapI7ShASMCEjC/LrasMC HqhoBpj+09XnSjLxezKEmraPDMKYk1A3hMiYqxI9qIRoKA/ZJt7JtY0Z6U4jR1wYUxPKrEKlM QcJfnulCleBD6RlgG9MMaOTNU5KuEUWpS2k+ZSoyDiwU4zR2Alh7swPWHr3mB+DwYaORlxTgx Zrnc1xsF0223m7UhPTxrHLxM7RQJr9twtL1JeyDk6/q0vR1eSgrIGCkuSthqn4hzU8Zop4PUK vwOOH0zA4iH5AeJiZHB/yG6Rd5Xd5ZwDSRWLCzCBggEadjIw1ZeFTqUFPkd+fEtOuDBrUAPi/ HOrlHt5yvW0x/JrGHfCIQZcP/aHA1GXWUc2kdA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Arnd Bergmann --- 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(-) -- 2.9.0 Reviewed-by: Boris Ostrovsky diff --git a/arch/x86/include/asm/intel_mid_vrtc.h b/arch/x86/include/asm/intel_mid_vrtc.h index 86ff4685c409..19202320f0be 100644 --- a/arch/x86/include/asm/intel_mid_vrtc.h +++ b/arch/x86/include/asm/intel_mid_vrtc.h @@ -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 diff --git a/arch/x86/include/asm/mc146818rtc.h b/arch/x86/include/asm/mc146818rtc.h index 24acd9ba7837..1b574e5eb3b2 100644 --- a/arch/x86/include/asm/mc146818rtc.h +++ b/arch/x86/include/asm/mc146818rtc.h @@ -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 diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h index 448cfe1b48cf..fc3138fd3aff 100644 --- a/arch/x86/include/asm/pvclock.h +++ b/arch/x86/include/asm/pvclock.h @@ -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); diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index f45acdf45957..0c5007b72916 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -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); diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index d88967659098..01c76e8cd4be 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -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; } diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c index 5c3f6d6a5078..1a7084ad07b9 100644 --- a/arch/x86/kernel/pvclock.c +++ b/arch/x86/kernel/pvclock.c @@ -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); } diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index 5b21cb7d84d6..f5a687c38c6d 100644 --- a/arch/x86/kernel/rtc.c +++ b/arch/x86/kernel/rtc.c @@ -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); } diff --git a/arch/x86/platform/intel-mid/intel_mid_vrtc.c b/arch/x86/platform/intel-mid/intel_mid_vrtc.c index 58024862a7eb..d68b9b10481d 100644 --- a/arch/x86/platform/intel-mid/intel_mid_vrtc.c +++ b/arch/x86/platform/intel-mid/intel_mid_vrtc.c @@ -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; } diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 1ecb05db3632..b1eed21a7b46 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -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);