Re: [PATCH] kvm: hyper-v: Delay firing of expired stimers
From: DV
Date: Mon Nov 16 2026 - 12:28:58 EST
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