From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751664AbcFWRPZ (ORCPT ); Thu, 23 Jun 2016 13:15:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56369 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751476AbcFWRPX (ORCPT ); Thu, 23 Jun 2016 13:15:23 -0400 Subject: Re: [PATCH] kvm: x86: use getboottime64 To: Arnd Bergmann , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org References: <20160617154914.660326-1-arnd@arndb.de> Cc: y2038@lists.linaro.org, Xiao Guangrong , Andrey Smetanin , "Denis V. Lunev" , Haozhong Zhang , Feng Wu , Steve Rutherford , Andy Lutomirski , kvm@vger.kernel.org, linux-kernel@vger.kernel.org From: Paolo Bonzini Message-ID: Date: Thu, 23 Jun 2016 19:15:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20160617154914.660326-1-arnd@arndb.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 23 Jun 2016 17:15:22 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/06/2016 17:48, Arnd Bergmann wrote: > KVM reads the current boottime value as a struct timespec in order to > calculate the guest wallclock time, resulting in an overflow in 2038 > on 32-bit systems. > > The data then gets passed as an unsigned 32-bit number to the guest, > and that in turn overflows in 2106. > > We cannot do much about the second overflow, which affects both 32-bit > and 64-bit hosts, but we can ensure that they both behave the same > way and don't overflow until 2106, by using getboottime64() to read > a timespec64 value. > > Signed-off-by: Arnd Bergmann > --- > arch/x86/kvm/x86.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 53241618e3c9..f79c86510408 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1163,7 +1163,7 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) > int version; > int r; > struct pvclock_wall_clock wc; > - struct timespec boot; > + struct timespec64 boot; > > if (!wall_clock) > return; > @@ -1186,13 +1186,13 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) > * wall clock specified here. guest system time equals host > * system time for us, thus we must fill in host boot time here. > */ > - getboottime(&boot); > + getboottime64(&boot); > > if (kvm->arch.kvmclock_offset) { > - struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset); > - boot = timespec_sub(boot, ts); > + struct timespec64 ts = ns_to_timespec64(kvm->arch.kvmclock_offset); > + boot = timespec64_sub(boot, ts); > } > - wc.sec = boot.tv_sec; > + wc.sec = (u32)boot.tv_sec; /* overflow in 2106 guest time */ > wc.nsec = boot.tv_nsec; > wc.version = version; > > Queued, thanks. Paolo