From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [PATCH v2] KVM: x86: reset lapic_timer.expired_tscdeadline at SET_LAPIC time Date: Mon, 20 Jun 2016 10:05:33 -0300 Message-ID: <20160620130531.GA8139@amt.cnet> References: <20160617234126.GA24514@amt.cnet> <6bc78368-d559-fa09-7e77-389b0e87d695@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm-devel , Paolo Bonzini To: Alan Jenkins Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40718 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753309AbcFTNG6 (ORCPT ); Mon, 20 Jun 2016 09:06:58 -0400 Content-Disposition: inline In-Reply-To: <6bc78368-d559-fa09-7e77-389b0e87d695@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: Alan Jenkins reports hang at https://bugzilla.redhat.com/show_bug.cgi?id=3D1337667, due to guest TSC being set far behind than lapic_timer.expired_tscdeadline, when restoring VM state on top of currently active VM. It is not possible to disable LAPIC timer advancement=20 (by setting lapic_timer.expired_tscdeadline =3D 0), at=20 guest TSC write because: * APIC write: expiration =3D 1000. * LAPIC tsc deadline code sets timer to 1000-30. * Timer fires at 970. * Guest writes TSC=3Dw. Guest fails to VM-entry to process signal to perform "vmload" in userspace. Case 1: w > 970: Guest entry can be performed. Case 2: w < 970: Guest entry should not be performed because "An interrupt is generated when the logical processor=E2=80=99s time-stamp counter equals or excee= ds the target value in the IA32_TSC_DEADLINE MSR." In case 2, hardware would not fire an interrupt. To fix the problem, disable timer advancement when=20 userspace sets the LAPIC state. Setting of APIC=20 resets all APIC state, including=20 any pending interrupt. Signed-off-by: Marcelo Tosatti Reported-by: Alan Jenkins --- v2: improve commit message diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ea306ad..89be6e9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2991,6 +2991,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vc= pu *vcpu, { kvm_apic_post_state_restore(vcpu, s); update_cr8_intercept(vcpu); + vcpu->arch.apic->lapic_timer.expired_tscdeadline =3D 0; =20 return 0; }