From nobody Wed Aug 26 18:58:07 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=1783113768; cv=none; d=zohomail.com; s=zohoarc; b=TNT4f39reYgEF7Xu9o10K4qvwlC8AjE71BKNnEOBN9r7enriOILuzLacewq/GiZuqCISLtMEQCep0Eag2/oo2ZbWHjgSr/ftctnlW3xXDbdtDGaag0tMv9J/aE/NLjxcsNECTovZbUl/yvDzrrGge2mgYrDmNpDkacqcw3LuVbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783113768; 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=s+7qUlbLcb8dcHIU9yxWWuYHzICS9PPJgOOAoGyBp5o=; b=IQ9P/D8mxtJ3u94g7rrH+FhnJprioJTAprxkq9gIvD8PfH7UKOaShycg+GCZLmnAHfOXg0tII9RwG4Ubmk5qVBVXj01rDdhAsQ2tFsZOPsAH6GDoPtyxJkMaT1OlqjgK3XaXKuVjHBeMjcPuBEoDVN0YOSXLZVrWgFDD5NeG+VM= 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 1783113768059698.4635720053033; Fri, 3 Jul 2026 14:22:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1353766.1609565 (Exim 4.92) (envelope-from ) id 1wflKz-0008Pk-M8; Fri, 03 Jul 2026 21:22:17 +0000 Received: by outflank-mailman (output) from mailman id 1353766.1609565; Fri, 03 Jul 2026 21:22:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflKz-0008M4-8j; Fri, 03 Jul 2026 21:22:17 +0000 Received: by outflank-mailman (input) for mailman id 1353766; Fri, 03 Jul 2026 21:22:15 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflKx-000876-Gu for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 21:22:15 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wflKw-00A7vt-U1; Fri, 03 Jul 2026 23:22:14 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a482804-e002-0a2a0a5209dd-0a2a4506d606-2 for ; Fri, 03 Jul 2026 23:22:14 +0200 Received: from [90.155.50.34] (helo=casper.infradead.org) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a482806-08de-0a2a45060019-5a9b3222ce6e-3 for ; Fri, 03 Jul 2026 23:22:14 +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 1wflKW-0000000AsY2-1TLA; Fri, 03 Jul 2026 21:21:48 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wflKW-00000001ROP-12v9; Fri, 03 Jul 2026 22:21:48 +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=s+7qUlbLcb8dcHIU9yxWWuYHzICS9PPJgOOAoGyBp5o=; b=HPj7neF/edX8jbo/JX8quja682 cEZuozcFmVKIQrBdJlzohG2fuYYQuNFcycqs5FWy96RgLuuCtsgPNENsXWM1BtzCtDYj1EbxULEiz FLnDUQn4MBs3GFp1PKN0NeVRrmqEWCnvYXdjIEPT0PPSKKwX+xlLnZfg37I9KK8Dp8hRsppgYkT8k sJz+4rBN3tgwri8rHwondVAyaMDPbqxGfNKNT1Mf5ShXTpgoE/LlIqlFF0q2ledbnIuzB0Z2Y/oK4 bMTCbCB/sTsOzQyuyvF7zwSQ3/zygcdDmM/tQILbMrqw5OpyejMR+PvuyewpDD3JmZASo2/07mat4 e/rL9FOw==; 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 10/36] KVM: x86: Avoid NTP frequency skew for KVM clock on 32-bit host Date: Fri, 3 Jul 2026 22:17:49 +0100 Message-ID: <20260703212145.343527-11-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-16d1c6/1783113734-4292368D-96F22E46/0/0 X-purgate-type: clean X-purgate-size: 3670 X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1783113768541158501 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Commit 53fafdbb8b21 ("KVM: x86: switch KVMCLOCK base to monotonic raw clock") did so only for 64-bit hosts, by capturing the boot offset from within the existing clocksource notifier update_pvclock_gtod(). That notifier was added in commit 16e8d74d2da9 ("KVM: x86: notifier for clocksource changes") but only on x86_64, because its original purpose was just to disable the "master clock" mode which is only supported on x86_64. Now that the notifier is used for more than disabling master clock mode, enable it for the 32-bit build too so that get_kvmclock_base_ns() can be unaffected by NTP sync on 32-bit too. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- arch/x86/kvm/x86.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 26b4649dfb94..21603feb44c5 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2342,7 +2342,6 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned= index, u64 *data) return kvm_set_msr_ignored_check(vcpu, index, *data, true); } =20 -#ifdef CONFIG_X86_64 struct pvclock_clock { int vclock_mode; u64 cycle_last; @@ -2400,13 +2399,6 @@ static s64 get_kvmclock_base_ns(void) /* Count up from boot time, but with the frequency of the raw clock. */ return ktime_to_ns(ktime_add(ktime_get_raw(), pvclock_gtod_data.offs_boot= )); } -#else -static s64 get_kvmclock_base_ns(void) -{ - /* Master clock not used, so we can just use CLOCK_BOOTTIME. */ - return ktime_get_boottime_ns(); -} -#endif =20 static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock, int se= c_hi_ofs) { @@ -10184,6 +10176,7 @@ static void pvclock_irq_work_fn(struct irq_work *w) } =20 static DEFINE_IRQ_WORK(pvclock_irq_work, pvclock_irq_work_fn); +#endif =20 /* * Notification about pvclock gtod data update. @@ -10191,26 +10184,26 @@ static DEFINE_IRQ_WORK(pvclock_irq_work, pvclock_= irq_work_fn); static int pvclock_gtod_notify(struct notifier_block *nb, unsigned long un= used, void *priv) { - struct pvclock_gtod_data *gtod =3D &pvclock_gtod_data; struct timekeeper *tk =3D priv; =20 update_pvclock_gtod(tk); =20 +#ifdef CONFIG_X86_64 /* * Disable master clock if host does not trust, or does not use, * TSC based clocksource. Delegate queue_work() to irq_work as * this is invoked with tk_core.seq write held. */ - if (!gtod_is_based_on_tsc(gtod->clock.vclock_mode) && + if (!gtod_is_based_on_tsc(pvclock_gtod_data.clock.vclock_mode) && atomic_read(&kvm_guest_has_master_clock) !=3D 0) irq_work_queue(&pvclock_irq_work); +#endif return 0; } =20 static struct notifier_block pvclock_gtod_notifier =3D { .notifier_call =3D pvclock_gtod_notify, }; -#endif =20 void kvm_setup_xss_caps(void) { @@ -10399,9 +10392,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *op= s) =20 if (pi_inject_timer =3D=3D -1) pi_inject_timer =3D housekeeping_enabled(HK_TYPE_TIMER); -#ifdef CONFIG_X86_64 pvclock_gtod_register_notifier(&pvclock_gtod_notifier); =20 +#ifdef CONFIG_X86_64 if (hypervisor_is_type(X86_HYPER_MS_HYPERV)) set_hv_tscchange_cb(kvm_hyperv_tsc_notifier); #endif @@ -10458,8 +10451,8 @@ void kvm_x86_vendor_exit(void) CPUFREQ_TRANSITION_NOTIFIER); cpuhp_remove_state_nocalls(CPUHP_AP_X86_KVM_CLK_ONLINE); } -#ifdef CONFIG_X86_64 pvclock_gtod_unregister_notifier(&pvclock_gtod_notifier); +#ifdef CONFIG_X86_64 irq_work_sync(&pvclock_irq_work); cancel_work_sync(&pvclock_gtod_work); #endif --=20 2.54.0