From: sashiko-bot@kernel.org
To: "David Woodhouse" <dwmw2@infradead.org>
Cc: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org
Subject: Re: [PATCH v2 2/3] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource
Date: Fri, 05 Jun 2026 09:58:27 +0000 [thread overview]
Message-ID: <20260605095827.6563E1F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260604095755.64849-3-dwmw2@infradead.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm_clock_get_cycles_snapshot() unconditionally returns raw TSC cycles and bypasses the global last_value monotonicity clamp, breaking timekeeping on hosts with unstable TSCs.
--
commit 6dc8b64e567331ab0edc9710a62a9a13cd0b8811
Author: David Woodhouse <dwmw@amazon.co.uk>
x86/kvmclock: Implement read_snapshot() for kvmclock clocksource
This commit implements the read_snapshot() callback for the kvmclock
clocksource. This allows returning both the kvmclock nanosecond value
and the raw TSC value used to compute it.
> diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
> index b5991d53fc0ea..cb3d0ca1fa225 100644
> --- a/arch/x86/kernel/kvmclock.c
> +++ b/arch/x86/kernel/kvmclock.c
[ ... ]
> @@ -87,6 +87,27 @@ static u64 kvm_clock_get_cycles(struct clocksource *cs)
> return kvm_clock_read();
> }
>
> +static u64 kvm_clock_get_cycles_snapshot(struct clocksource *cs,
> + struct clocksource_hw_snapshot *chs)
> +{
> + struct pvclock_vcpu_time_info *src;
> + unsigned version;
> + u64 ret, tsc;
> +
> + preempt_disable_notrace();
> + src = this_cpu_pvti();
> + do {
> + version = pvclock_read_begin(src);
> + tsc = rdtsc_ordered();
> + ret = __pvclock_read_cycles(src, tsc);
> + } while (pvclock_read_retry(src, version));
> + preempt_enable_notrace();
> +
> + chs->hw_cycles = tsc;
> + chs->hw_csid = CSID_X86_TSC;
[Severity: High]
Does this open-coded read loop bypass the fallback monotonic clamping used in
the standard kvm-clock read path?
The standard path (__pvclock_clocksource_read) enforces clock monotonicity
by clamping to a globally shared last_value accumulator when
PVCLOCK_TSC_STABLE_BIT is not set.
Without this check and clamping logic, if a vCPU migrates to a host with an
unsynchronized or slower TSC, could the snapshot return a derived time that
goes backwards relative to the timekeeper's cycle_last?
Also, by unconditionally returning CSID_X86_TSC and the raw hardware cycles
even when the host marks the TSC as unstable, does this incorrectly trick
cross-timestamping consumers into assuming they have a reliable, synchronized
hardware timestamp?
> + return ret;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604095755.64849-1-dwmw2@infradead.org?part=2
next prev parent reply other threads:[~2026-06-05 9:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 9:35 [PATCH v2 0/3] timekeeping: Implement and use read_snapshot() functionality David Woodhouse
2026-06-04 9:35 ` [PATCH v2 1/3] clocksource/hyperv: Implement read_snapshot() for TSC page clocksource David Woodhouse
2026-06-05 9:58 ` sashiko-bot
2026-06-04 9:35 ` [PATCH v2 2/3] x86/kvmclock: Implement read_snapshot() for kvmclock clocksource David Woodhouse
2026-06-05 9:58 ` sashiko-bot [this message]
2026-06-04 9:35 ` [PATCH v2 3/3] ptp: vmclock: Use hw_cycles from snapshot for precise TSC pairing David Woodhouse
2026-06-05 9:58 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260605095827.6563E1F00898@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox