From patchwork Fri Jun 17 15:48:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102150 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp350683qgy; Fri, 17 Jun 2016 08:49:56 -0700 (PDT) X-Received: by 10.66.253.70 with SMTP id zy6mr2946367pac.55.1466178596637; Fri, 17 Jun 2016 08:49:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id al10si14921238pad.148.2016.06.17.08.49.56; Fri, 17 Jun 2016 08:49:56 -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 S1755725AbcFQPtn (ORCPT + 30 others); Fri, 17 Jun 2016 11:49:43 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:58952 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751058AbcFQPtl (ORCPT ); Fri, 17 Jun 2016 11:49:41 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue103) with ESMTPA (Nemesis) id 0M1ygd-1bYkhO3z7z-00u1UA; Fri, 17 Jun 2016 17:47:30 +0200 From: Arnd Bergmann To: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org Cc: y2038@lists.linaro.org, Arnd Bergmann , Xiao Guangrong , Andrey Smetanin , "Denis V. Lunev" , Haozhong Zhang , Feng Wu , Steve Rutherford , Andy Lutomirski , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] kvm: x86: use getboottime64 Date: Fri, 17 Jun 2016 17:48:56 +0200 Message-Id: <20160617154914.660326-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:+0bpUX8iaTr9WHRweflA2HJCbfTJ/AhiHgslniwrq+zRRoVnkRc b99zH/IklkjpiJx90b1DG19Na0luB9iJaAuViw1crP0yzBul2L9jOUUHza2vpF1IUV+Lqsj taeKE2UVwKx/Z9tWvMYeERvpnxo4ekVvF1iPc8DB7AF2PI1fqDsO3q+VD6zPB+L18LYUPZO e2eL24iy8QNAe5D4SAnhA== X-UI-Out-Filterresults: notjunk:1; V01:K0:5o1zWGGJRIc=:3f1nJIOqxqFcKF8kVeMgvE oEvLsDvn1rzmqlCH+rJ0pQ4wuzi3gLEVvRW2VOwgePrRjFgNZQwSfe0zXZJbJ530J/6hoBow4 GyIq3XW0UVLLDsO4tZLqHDo/fmYLmRyhca/OYGsc+eiOZtFVZv24UprcaxF4wOu2wFHU4UKXJ Mhi3iS4Qyq/armiTFQObzOc+raaiSDkIloPkHNsTGftRHdltPO9SXh1D6SS8OtX+JcNl56JMq Bry8Fqm/EK4PCiEgm/fZiFlEfUC7nMf13s+1IO62UtFrnHidYba6kWZBidApKtNE6CDHYifAz k5FNTzUzdoB0xD2QTbXXjIuqf1LZIs3jLSllD6AvwSciIuRBtQGqMwNW9neXTz2V0Rw/F7/lX 9eKGV5cPtWqMVGeHC8jgd7/ZTf85CZY8/px6AECbWwCv2fKD6OnS+7kvvjjd6AG93D+agLoge eBEOW30o1p7gRXa1Fx+nFfLrTzVAgyp2i+eRab++49PIhg4NpOKD0N9JJu1DFXERT1TBeKd7a Z+jxVlLodkQ9gglX8JkHRJGX8WWTs7lwQdLdcPf1430rzeQ4VGnrnnI4BZwVk4pqL2zpyBNPM nO7nH8A+PlSCRlxikohr0b8g7SCkcSolrB41fTtDFqbMVT8R1hcPB/wzY8XW/xx6BLE206A45 MJw1hitZs0SOFomfFIwliGqKeAidUiO7YRJurMWA/d+bnR7tbBl+8diAyw3CtFrfFeSk= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.9.0 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;