mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: DV <dv@etik.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Alexander Graf <graf@amazon.com>,
	Sean Christopherson <seanjc@google.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com,
	x86@kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	nh-open-source@amazon.com, gurugubs@amazon.com,
	jalliste@amazon.co.uk, Michael Kelley <mhklinux@outlook.com>,
	John Starks <jostarks@microsoft.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH] kvm: hyper-v: Delay firing of expired stimers
Date: Mon, 16 Nov 2026 18:28:36 +0100	[thread overview]
Message-ID: <999079c0-c728-445b-a122-720d93f112cc@etik.com> (raw)
In-Reply-To: <kupzev8hf8s.fsf@vkuznets-thinkpadx1carbongen12.rmtcz.csb>

On Mon, 16 Nov 2026, Vitaly Kuznetsov wrote:
> From what I remember, direct mode synthetic timers were added
> specifically to aid Hyper-V-on-KVM case as non-nested Windows was
> preferring non-direct version anyway. So I believe we need a fix and
> not 3).

Thanks, that rules out 3).

> I'm wondering if the issue is somewhat related to the nasty hack we
> put in commit 0469f2f7ab4c ("KVM: x86: hyper-v: Don't touch TSC page
> values when guest opted for re-enlightenment") but maybe hibernation
> is somewhat different. Or maybe we misunderstood the problem in the
> first place and only fixed one sympthom of it?

I don't think the hack itself is involved here, but your second guess
fits what I see.

The hack only takes effect once the guest has written
HV_X64_MSR_TSC_EMULATION_CONTROL. In the failing setup
hv-reenlightenment isn't exposed, so KVM recomputes the TSC page on
every masterclock update and every KVM_SET_CLOCK as usual. With
hv-reenlightenment on, X was 494.7 ms and the timers were just as
late. I didn't trace whether L1 wrote the MSR in that run, but it
wouldn't change the lag at boot: L1 enabling the page sets
HV_TSC_PAGE_GUEST_CHANGED, so the first setup is computed normally
either way.

What points to your second guess: X is already in kvmclock before the
guest runs its first instruction, so when L1 enables the TSC page,
KVM writes a tsc_offset of about -X into it. Yet on a boot with no
pause and no migration, L1's counts were still X too far out. If L1
used the values it read from the TSC page, even cached ones, it would
have been right at that point. So L1 seems to take L0's reference
time to be guest TSC / TSC frequency with no offset at all, perhaps
because on a Hyper-V host the two start together.

If so, the 2021 migration storm and this are the same assumption
broken in two ways. The hack keeps tsc_offset from changing after L1
has started, which helps on migration, but it can't help when
tsc_offset isn't zero to begin with. And without re-enlightenment,
nothing keeps it from changing on pause/resume, which matches the
virsh suspend result in my first mail.

If it helps, I can rerun with hv-reenlightenment on, trace whether L1
writes HV_X64_MSR_TSC_EMULATION_CONTROL, and repeat the suspend. If
the hack engages, I'd expect X to stay the same across the pause,
while the timers stay X late from boot.

As before, Claude Code did the code reading for this.

Thanks,
David

  reply	other threads:[~2026-11-16 17:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-15 14:15 Alexander Graf
2026-01-23 18:21 ` Sean Christopherson
2026-01-24 21:26   ` Alexander Graf
2026-01-26  9:41     ` Vitaly Kuznetsov
2026-11-07 16:22       ` DV
2026-11-16 17:12         ` Vitaly Kuznetsov
2026-11-16 17:28           ` DV [this message]
2026-01-24  0:37 ` David Woodhouse

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=999079c0-c728-445b-a122-720d93f112cc@etik.com \
    --to=dv@etik.com \
    --cc=dwmw2@infradead.org \
    --cc=graf@amazon.com \
    --cc=gurugubs@amazon.com \
    --cc=hpa@zytor.com \
    --cc=jalliste@amazon.co.uk \
    --cc=jostarks@microsoft.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=mtosatti@redhat.com \
    --cc=nh-open-source@amazon.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®