From nobody Wed Aug 26 00:53:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=infradead.org ARC-Seal: i=1; a=rsa-sha256; t=1783113765; cv=none; d=zohomail.com; s=zohoarc; b=XmI0ab8YcSC8dyxMRrK4kS+LezcKaEuAedGALQPj3qvNSeAmdTia8rs3VyN3W5mzMkAqCF1NFuu2Tyy3+uojcdyy1JVhEg0npMGN1AMc6wYdfsnXdlcQFMRX1AOdkXV5MzJn4oZPAp6R5L0kaSkOOpl8TsHTT8HJRowCCGlACz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783113765; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=Uf6PMMgja7l0D+gznz6ziYSzcjhgw4gAMyV+QMwIS4w=; b=n5LJoiq+KULt+sPkkFvvQYtLTMPnUAhPZtx+YwEqJWeESWkakzxb9hPcJmteChLZEGGgoA3sRe8YDvijIwEIm8bB4D4/ErsTOsrO2MJQeaq5vCn+4yprtPUxy+ZUw1SiJ2JG9QPYG+G+0x5DQlcvY3FzUnxG7l6hdzYeRuTSEx4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1783113765725597.7036216627645; Fri, 3 Jul 2026 14:22:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1353754.1609489 (Exim 4.92) (envelope-from ) id 1wflKp-00067k-QD; Fri, 03 Jul 2026 21:22:07 +0000 Received: by outflank-mailman (output) from mailman id 1353754.1609489; Fri, 03 Jul 2026 21:22:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflKp-00065J-Ii; Fri, 03 Jul 2026 21:22:07 +0000 Received: by outflank-mailman (input) for mailman id 1353754; Fri, 03 Jul 2026 21:22:06 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflKn-0005Py-Su for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 21:22:05 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wflKn-00A7vt-9e; Fri, 03 Jul 2026 23:22:05 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a4827a3-e002-0a2a0a5209dd-0a2a4507d220-28 for ; Fri, 03 Jul 2026 23:22:05 +0200 Received: from [90.155.50.34] (helo=casper.infradead.org) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a4827fc-9c8e-0a2a45070019-5a9b322282c8-3 for ; Fri, 03 Jul 2026 23:22:05 +0200 Received: from [2001:8b0:10b:1::425] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wflKX-0000000AsYE-1AzU; Fri, 03 Jul 2026 21:21:49 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wflKX-00000001RPT-0m6V; Fri, 03 Jul 2026 22:21:49 +0100 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=casper.20170209 header.d=infradead.org header.i="@infradead.org" header.h="Sender:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description; bh=Uf6PMMgja7l0D+gznz6ziYSzcjhgw4gAMyV+QMwIS4w=; b=hb/nvHEGmIkkWSIO9fLFyYkl6P lhXj0DAUVaYTNlSjh9Ss2Uc7JqT+E0mDSgQF6HZZfS6Uhrl3pFZMXnt57qYqdw8l/FXZns/+M5YY/ kKM4u3aIR9pCz2XESpfpAi5/Bi1spkdEUwrRa0uWaWvhfktAKSlCmqIgUEiL+l3J8ZMFmlO8ZLLj5 rdW5ORlo4NyoFiq4LVYWiKqBt5CXZNjaAWZ5DKCm0b5O9mq3eWA3bDwiSAPZNZ/Abx6a7eMs3duc3 /POuQuY/i9iQJJ3zU2Q5BVdFKXYQi8EURSyU73jVB+7z0aOV1hkkdmaUMI8Kzbxa0vw9EnSuOEcRF Rl2ZUp/w==; From: David Woodhouse To: Paolo Bonzini , Jonathan Corbet , Shuah Khan , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Vitaly Kuznetsov , Juergen Gross , Boris Ostrovsky , David Woodhouse , Paul Durrant , Jonathan Cameron , Sascha Bischoff , Marc Zyngier , Joey Gouly , Jack Allister , Dongli Zhang , joe.jin@oracle.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-kselftest@vger.kernel.org Subject: [PATCH v6 25/36] KVM: x86: Avoid gratuitous global clock updates Date: Fri, 3 Jul 2026 22:18:04 +0100 Message-ID: <20260703212145.343527-26-dwmw2@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260703212145.343527-1-dwmw2@infradead.org> References: <20260703212145.343527-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-purgate-ID: tlsNG-ef75cf/1783113725-FD12E25E-AC831E57/0/0 X-purgate-type: clean X-purgate-size: 2448 X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1783113766510158500 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Eliminate two sources of unnecessary KVM_REQ_GLOBAL_CLOCK_UPDATE: 1. kvm_write_system_time(): The global clock update was a workaround for ever-drifting clocks based on the host's CLOCK_MONOTONIC subject to NTP skew. Now that the KVM clock uses CLOCK_MONOTONIC_RAW, the clock does not drift with NTP corrections and there is no need to synchronize all vCPUs on boot or resume. Use KVM_REQ_CLOCK_UPDATE on the vCPU itself, and only when the clock is being enabled, not disabled. 2. kvm_arch_vcpu_load(): In master clock mode, migration between pCPUs does not require any clock update since the master clock reference is shared. Only request a local KVM_REQ_CLOCK_UPDATE for the vCPU's first-ever load (vcpu->cpu =3D=3D -1) to generate initial pvclock params. In non-master-clock mode, keep the global update to synchronize all vCPUs. Signed-off-by: David Woodhouse --- arch/x86/kvm/x86.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f8883c3b8ed2..2a1e1a1ab6ee 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2457,13 +2457,13 @@ static void kvm_write_system_time(struct kvm_vcpu *= vcpu, gpa_t system_time, } =20 vcpu->arch.time =3D system_time; - kvm_make_request(KVM_REQ_GLOBAL_CLOCK_UPDATE, vcpu); =20 /* we verify if the enable bit is set... */ - if (system_time & 1) + if (system_time & 1) { kvm_gpc_activate(&vcpu->arch.pv_time, system_time & ~1ULL, sizeof(struct pvclock_vcpu_time_info)); - else + kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); + } else kvm_gpc_deactivate(&vcpu->arch.pv_time); =20 return; @@ -5355,13 +5355,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int = cpu) * On a host with synchronized TSC, there is no need to update * kvmclock on vcpu->cpu migration */ - if (!vcpu->kvm->arch.use_master_clock || vcpu->cpu =3D=3D -1) { + if (!vcpu->kvm->arch.use_master_clock) { if (__ratelimit(&vcpu->kvm->arch.kvmclock_update_rs)) kvm_make_request(KVM_REQ_GLOBAL_CLOCK_UPDATE, vcpu); else kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); - } - + } else if (vcpu->cpu =3D=3D -1) + kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); if (vcpu->cpu !=3D cpu) kvm_make_request(KVM_REQ_MIGRATE_TIMER, vcpu); vcpu->cpu =3D cpu; --=20 2.54.0