From nobody Mon May 6 06:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495801579987650.7276428654003; Fri, 26 May 2017 05:26:19 -0700 (PDT) Received: from localhost ([::1]:36500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEEJt-0005t5-PR for importer@patchew.org; Fri, 26 May 2017 08:26:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEEJA-0005aj-NA for qemu-devel@nongnu.org; Fri, 26 May 2017 08:25:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dEEJ6-0006UW-O3 for qemu-devel@nongnu.org; Fri, 26 May 2017 08:25:32 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:44475 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dEEJ6-0006U8-Ck for qemu-devel@nongnu.org; Fri, 26 May 2017 08:25:28 -0400 Received: from dptest2.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v4QCPMnk022026; Fri, 26 May 2017 15:25:23 +0300 (MSK) From: Denis Plotnikov To: pbonzini@redhat.com, mtosatti@redhat.com Date: Fri, 26 May 2017 15:25:22 +0300 Message-Id: <1495801522-27628-1-git-send-email-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v2] kvmclock: update system_time_msr address forcibly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rkagan@virtuozzo.com, dplotnikov@virtuozzo.com, qemu-devel@nongnu.org, den@virtuozzo.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do an update of system_time_msr address every time before reading the value of tsc_timestamp from guest's kvmclock page. There is no other code paths which ensure that qemu has an up-to-date value of system_time_msr. So, force this update on guest's tsc_timestamp reading. This bug causes effect on those nested setups which turn off TPR access interception for L2 guests and that access being intercepted by L0 doesn't show up in L1. Linux bootstrap initiate kvmclock before APIC initializing causing TPR acce= ss. That's why on L1 guests, having TPR interception turned on for L2, the effe= ct of the bug is not revealed. This patch fixes this problem by making sure it knows the correct system_time_msr address every time it is needed. Signed-off-by: Denis Plotnikov Reviewed-by: Roman Kagan --- hw/i386/kvm/clock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 0f75dd3..875d85f 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -61,6 +61,8 @@ static uint64_t kvmclock_current_nsec(KVMClockState *s) uint64_t nsec_hi; uint64_t nsec; =20 + cpu_synchronize_state(cpu); + if (!(env->system_time_msr & 1ULL)) { /* KVM clock not active */ return 0; --=20 2.7.4