From nobody Wed Aug 26 00:41:00 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=1783113841; cv=none; d=zohomail.com; s=zohoarc; b=Ly0WlC9GafAOwAh1CYwjgH6T9b6THjm6m9gRBGu53NDaC6+3dRyG8t015jNT4sDHLCZGYiAO54vNC4zqRdXKBcSk/8QPyR6HcVjgggtAqda9dP2L/GYO6iL/53PGhK6xrwsz3b49nsJEBfjzY+0a9AE+hrMM82GDbrj3H3hlPuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783113841; 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=Ort/pZQb4ierCrxm1j8Wvj2iLn37EL9Xs8ile8CK+5w=; b=JIB8zHSgT9PCrYqAaywpaT1PkFvN/qPkMINFf3uWcyw3Y9idAGP8f5ER2f9ZsOcNQhkvDQHd8CWZXDyjFFGMci82nWkJojKh1EPxq8oynrpamlcheQOLxSBf2Lqxbl+pavrd+m0dCAnOQOj+A90qrAtQu8SCEaOdvMllZ1tu/jE= 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 1783113841670300.47522228924095; Fri, 3 Jul 2026 14:24:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1353884.1609645 (Exim 4.92) (envelope-from ) id 1wflMP-0006D2-8H; Fri, 03 Jul 2026 21:23:45 +0000 Received: by outflank-mailman (output) from mailman id 1353884.1609645; Fri, 03 Jul 2026 21:23:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflMP-0006Cs-2Y; Fri, 03 Jul 2026 21:23:45 +0000 Received: by outflank-mailman (input) for mailman id 1353884; Fri, 03 Jul 2026 21:23:43 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflMN-0005qG-BT for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 21:23:43 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wflMM-000kw0-O4; Fri, 03 Jul 2026 23:23:42 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a48281c-2eae-0a2a0a5409dd-0a2a4504979a-10 for ; Fri, 03 Jul 2026 23:23:42 +0200 Received: from [90.155.92.199] (helo=desiato.infradead.org) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a48285d-a01d-0a2a45040019-5a9b5cc78d46-3 for ; Fri, 03 Jul 2026 23:23:42 +0200 Received: from [2001:8b0:10b:1::425] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.99.2 #2 (Red Hat Linux)) id 1wflKe-000000059OF-0vI4; Fri, 03 Jul 2026 21:23:11 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wflKX-00000001RQD-3BKG; 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=desiato.20200630 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=desiato.20200630; 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=Ort/pZQb4ierCrxm1j8Wvj2iLn37EL9Xs8ile8CK+5w=; b=iGUqq6bke/f9INoPyifWfn6tMr Dxx9c7T5UqI5UMg8YjyLmZpMVseB7N8tyabz9obX/dC+ngIU3yv1JHY3JTAWY6WngiA570Ryh4IOF b01mRW0I0bfTI3wDMXY7Yqmz4AqjFrVwhNTMruP7kS6z7gO1y/WKqWK9lLjnLOsgL2ks7g7OnG9iK 1C80or7kq0ERNDnGtFaUh3xmfdkYHkkAWlJ+T0ZNUpaqHxFoQDCFHBGH5vce0dCBsk83GzuL97PPe r2wTSTLoYRY1lpzZtdTadwaq2mg2QrWDju/Gu1EeSlgsy4TO/ncXhKlwClbwNm7lOreXmIVUpUc0Y cP23OeUg==; 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 35/36] KVM: x86: Remove pvclock_gtod_data and private timekeeping code Date: Fri, 3 Jul 2026 22:18:14 +0100 Message-ID: <20260703212145.343527-36-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 desiato.infradead.org. See http://www.infradead.org/rpr.html X-purgate-ID: tlsNG-ebf023/1783113822-AFD241CC-A09A4783/0/0 X-purgate-type: clean X-purgate-size: 6507 X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1783113842985158500 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Remove the now-unused KVM-private timekeeping infrastructure: - struct pvclock_clock and struct pvclock_gtod_data - update_pvclock_gtod() and its seqcount-protected state copy - read_tsc() (KVM's private TSC reader with cycle_last clamping) - vgettsc() (KVM's private clocksource interpolation) - do_kvmclock_base(), do_monotonic(), do_realtime() Signed-off-by: David Woodhouse Assisted-by: Kiro:claude-opus-4.6-1m --- arch/x86/kvm/x86.c | 178 +-------------------------------------------- 1 file changed, 1 insertion(+), 177 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c67655f8e078..58016af64932 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2347,58 +2347,6 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigne= d index, u64 *data) return kvm_set_msr_ignored_check(vcpu, index, *data, true); } =20 -struct pvclock_clock { - int vclock_mode; - u64 cycle_last; - u64 mask; - u32 mult; - u32 shift; - u64 base_cycles; - u64 offset; -}; - -struct pvclock_gtod_data { - seqcount_t seq; - - struct pvclock_clock clock; /* extract of a clocksource struct */ - struct pvclock_clock raw_clock; /* extract of a clocksource struct */ - - ktime_t offs_boot; - u64 wall_time_sec; -}; - -static struct pvclock_gtod_data pvclock_gtod_data; - -static void update_pvclock_gtod(struct timekeeper *tk) -{ - struct pvclock_gtod_data *vdata =3D &pvclock_gtod_data; - - write_seqcount_begin(&vdata->seq); - - /* copy pvclock gtod data */ - vdata->clock.vclock_mode =3D tk->tkr_mono.clock->vdso_clock_mode; - vdata->clock.cycle_last =3D tk->tkr_mono.cycle_last; - vdata->clock.mask =3D tk->tkr_mono.mask; - vdata->clock.mult =3D tk->tkr_mono.mult; - vdata->clock.shift =3D tk->tkr_mono.shift; - vdata->clock.base_cycles =3D tk->tkr_mono.xtime_nsec; - vdata->clock.offset =3D tk->tkr_mono.base; - - vdata->raw_clock.vclock_mode =3D tk->tkr_raw.clock->vdso_clock_mode; - vdata->raw_clock.cycle_last =3D tk->tkr_raw.cycle_last; - vdata->raw_clock.mask =3D tk->tkr_raw.mask; - vdata->raw_clock.mult =3D tk->tkr_raw.mult; - vdata->raw_clock.shift =3D tk->tkr_raw.shift; - vdata->raw_clock.base_cycles =3D tk->tkr_raw.xtime_nsec; - vdata->raw_clock.offset =3D tk->tkr_raw.base; - - vdata->wall_time_sec =3D tk->xtime_sec; - - vdata->offs_boot =3D tk->offs_boot; - - write_seqcount_end(&vdata->seq); -} - static s64 get_kvmclock_base_ns(void) { /* Count up from boot time, but with the frequency of the raw clock. */ @@ -3029,128 +2977,6 @@ static inline void adjust_tsc_offset_host(struct kv= m_vcpu *vcpu, s64 adjustment) =20 #ifdef CONFIG_X86_64 =20 -static u64 read_tsc(void) -{ - u64 ret =3D (u64)rdtsc_ordered(); - u64 last =3D pvclock_gtod_data.clock.cycle_last; - - if (likely(ret >=3D last)) - return ret; - - /* - * GCC likes to generate cmov here, but this branch is extremely - * predictable (it's just a function of time and the likely is - * very likely) and there's a data dependence, so force GCC - * to generate a branch instead. I don't barrier() because - * we don't actually need a barrier, and if this function - * ever gets inlined it will generate worse code. - */ - asm volatile (""); - return last; -} - -static inline u64 vgettsc(struct pvclock_clock *clock, u64 *tsc_timestamp, - int *mode) -{ - u64 tsc_pg_val; - long v; - - switch (clock->vclock_mode) { - case VDSO_CLOCKMODE_HVCLOCK: - if (hv_read_tsc_page_tsc(hv_get_tsc_page(), - tsc_timestamp, &tsc_pg_val)) { - /* TSC page valid */ - *mode =3D VDSO_CLOCKMODE_HVCLOCK; - v =3D (tsc_pg_val - clock->cycle_last) & - clock->mask; - } else { - /* TSC page invalid */ - *mode =3D VDSO_CLOCKMODE_NONE; - } - break; - case VDSO_CLOCKMODE_TSC: - *mode =3D VDSO_CLOCKMODE_TSC; - *tsc_timestamp =3D read_tsc(); - v =3D (*tsc_timestamp - clock->cycle_last) & - clock->mask; - break; - default: - *mode =3D VDSO_CLOCKMODE_NONE; - } - - if (*mode =3D=3D VDSO_CLOCKMODE_NONE) - *tsc_timestamp =3D v =3D 0; - - return v * clock->mult; -} - -/* - * As with get_kvmclock_base_ns(), this counts from boot time, at the - * frequency of CLOCK_MONOTONIC_RAW (hence adding gtos->offs_boot). - */ -static int do_kvmclock_base(s64 *t, u64 *tsc_timestamp) -{ - struct pvclock_gtod_data *gtod =3D &pvclock_gtod_data; - unsigned long seq; - int mode; - u64 ns; - - do { - seq =3D read_seqcount_begin(>od->seq); - ns =3D gtod->raw_clock.base_cycles; - ns +=3D vgettsc(>od->raw_clock, tsc_timestamp, &mode); - ns >>=3D gtod->raw_clock.shift; - ns +=3D ktime_to_ns(ktime_add(gtod->raw_clock.offset, gtod->offs_boot)); - } while (unlikely(read_seqcount_retry(>od->seq, seq))); - *t =3D ns; - - return mode; -} - -/* - * This calculates CLOCK_MONOTONIC at the time of the TSC snapshot, with - * no boot time offset. - */ -static int do_monotonic(s64 *t, u64 *tsc_timestamp) -{ - struct pvclock_gtod_data *gtod =3D &pvclock_gtod_data; - unsigned long seq; - int mode; - u64 ns; - - do { - seq =3D read_seqcount_begin(>od->seq); - ns =3D gtod->clock.base_cycles; - ns +=3D vgettsc(>od->clock, tsc_timestamp, &mode); - ns >>=3D gtod->clock.shift; - ns +=3D ktime_to_ns(gtod->clock.offset); - } while (unlikely(read_seqcount_retry(>od->seq, seq))); - *t =3D ns; - - return mode; -} - -static int do_realtime(struct timespec64 *ts, u64 *tsc_timestamp) -{ - struct pvclock_gtod_data *gtod =3D &pvclock_gtod_data; - unsigned long seq; - int mode; - u64 ns; - - do { - seq =3D read_seqcount_begin(>od->seq); - ts->tv_sec =3D gtod->wall_time_sec; - ns =3D gtod->clock.base_cycles; - ns +=3D vgettsc(>od->clock, tsc_timestamp, &mode); - ns >>=3D gtod->clock.shift; - } while (unlikely(read_seqcount_retry(>od->seq, seq))); - - ts->tv_sec +=3D __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); - ts->tv_nsec =3D ns; - - return mode; -} - /* * Calculates the kvmclock_base_ns (CLOCK_MONOTONIC_RAW + boot time) and * reports the TSC value from which it do so. Returns true if host is @@ -10394,11 +10220,9 @@ static DEFINE_IRQ_WORK(pvclock_irq_work, pvclock_i= rq_work_fn); static int pvclock_gtod_notify(struct notifier_block *nb, unsigned long un= used, void *priv) { +#ifdef CONFIG_X86_64 struct timekeeper *tk =3D priv; =20 - update_pvclock_gtod(tk); - -#ifdef CONFIG_X86_64 kvm_host_vclock_mode =3D tk->tkr_mono.clock->vdso_clock_mode; =20 --=20 2.54.0