kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] KVM: x86: hyper-v: TSC page fixes
@ 2021-03-16 14:37 Vitaly Kuznetsov
  2021-03-16 14:37 ` [PATCH v2 1/4] KVM: x86: hyper-v: Limit guest to writing zero to HV_X64_MSR_TSC_EMULATION_STATUS Vitaly Kuznetsov
                   ` (4 more replies)
  0 siblings, 5 replies; 22+ messages in thread
From: Vitaly Kuznetsov @ 2021-03-16 14:37 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Marcelo Tosatti

Changes since v1:
- Invalidate TSC page from kvm_gen_update_masterclock() instead of calling
 kvm_hv_setup_tsc_page() for all vCPUs [Paolo]
- Set hv->hv_tsc_page_status = HV_TSC_PAGE_UNSET when TSC page is disabled
 with MSR write. Check both HV_TSC_PAGE_BROKEN/HV_TSC_PAGE_UNSET states
 in kvm_hv_setup_tsc_page()/kvm_hv_invalidate_tsc_page().
- Check for HV_TSC_PAGE_SET state instead of '!hv->tsc_ref.tsc_sequence' in
 get_time_ref_counter().

Original description:

I'm investigating an issue when Linux guest on nested Hyper-V on KVM 
(WSL2 on Win10 on KVM to be precise) hangs after L1 KVM is migrated. Trace
shows us that L2 is trying to set L1's Synthetic Timer and reacting to
this Hyper-V sets Synthetic Timer in KVM but the target value it sets is
always slightly in the past, this causes the timer to expire immediately
and an interrupt storm is thus observed. L2 is not making much forward
progress.

The issue is only observed when re-enlightenment is exposed to L1. KVM
doesn't really support re-enlightenment notifications upon migration,
userspace is supposed to expose it only when TSC scaling is supported
on the destination host. Without re-enlightenment exposed, Hyper-V will
not expose stable TSC page clocksource to its L2s. The issue is observed
when migration happens between hosts supporting TSC scaling. Rumor has it
that it is possible to reproduce the problem even when migrating locally
to the same host, though, I wasn't really able to.

The current speculation is that when Hyper-V is migrated, it uses stale
(cached) TSC page values to compute the difference between its own
clocksource (provided by KVM) and its guests' TSC pages to program
synthetic timers and in some cases, when TSC page is updated, this puts all
stimer expirations in the past. This, in its turn, causes an interrupt
storms (both L0-L1 and L1->L2 as Hyper-V mirrors stimer expirations into
L2).

The proposed fix is to skip updating TSC page clocksource when guest opted
for re-enlightenment notifications (PATCH4). Patches 1-3 are slightly
related fixes to the (mostly theoretical) issues I've stumbled upon while
working on the problem.

Vitaly Kuznetsov (4):
  KVM: x86: hyper-v: Limit guest to writing zero to
    HV_X64_MSR_TSC_EMULATION_STATUS
  KVM: x86: hyper-v: Prevent using not-yet-updated TSC page by secondary
    CPUs
  KVM: x86: hyper-v: Track Hyper-V TSC page status
  KVM: x86: hyper-v: Don't touch TSC page values when guest opted for
    re-enlightenment

 arch/x86/include/asm/kvm_host.h | 10 ++++
 arch/x86/kvm/hyperv.c           | 91 +++++++++++++++++++++++++++++----
 arch/x86/kvm/hyperv.h           |  1 +
 arch/x86/kvm/x86.c              |  2 +
 4 files changed, 94 insertions(+), 10 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2021-03-19  9:36 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 14:37 [PATCH v2 0/4] KVM: x86: hyper-v: TSC page fixes Vitaly Kuznetsov
2021-03-16 14:37 ` [PATCH v2 1/4] KVM: x86: hyper-v: Limit guest to writing zero to HV_X64_MSR_TSC_EMULATION_STATUS Vitaly Kuznetsov
2021-03-16 14:37 ` [PATCH v2 2/4] KVM: x86: hyper-v: Prevent using not-yet-updated TSC page by secondary CPUs Vitaly Kuznetsov
2021-03-18 17:02   ` Marcelo Tosatti
2021-03-18 18:04     ` Marcelo Tosatti
2021-03-18 18:05       ` Paolo Bonzini
2021-03-18 18:30         ` Marcelo Tosatti
2021-03-19  9:29           ` Vitaly Kuznetsov
2021-03-16 14:37 ` [PATCH v2 3/4] KVM: x86: hyper-v: Track Hyper-V TSC page status Vitaly Kuznetsov
2021-03-17  8:07   ` Paolo Bonzini
2021-03-17 11:19     ` [PATCH v2 5/4] KVM: x86: hyper-v: Briefly document enum hv_tsc_page_status Vitaly Kuznetsov
2021-03-16 14:37 ` [PATCH v2 4/4] KVM: x86: hyper-v: Don't touch TSC page values when guest opted for re-enlightenment Vitaly Kuznetsov
2021-03-18 14:09 ` [PATCH v2 6/4] selftests: kvm: Add basic Hyper-V clocksources tests Vitaly Kuznetsov
2021-03-18 14:26   ` Paolo Bonzini
2021-03-18 14:52     ` Vitaly Kuznetsov
2021-03-18 15:01       ` Paolo Bonzini
2021-03-18 15:23         ` Vitaly Kuznetsov
2021-03-18 15:27   ` Paolo Bonzini
2021-03-18 16:57   ` Marcelo Tosatti
2021-03-18 17:50     ` Paolo Bonzini
2021-03-18 17:55       ` Marcelo Tosatti
2021-03-19  9:35         ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).