From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 2/2 V2] KVM: LAPIC: cap __delay at lapic_timer_advance_ns Date: Mon, 20 Jun 2016 22:33:48 -0300 Message-ID: <20160621013345.GA27706@amt.cnet> References: <20160621012801.145630514@redhat.com> <20160621012829.699158610@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Paolo Bonzini , Radim Krcmar , Alan Jenkins To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:35987 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752289AbcFUBeb (ORCPT ); Mon, 20 Jun 2016 21:34:31 -0400 Content-Disposition: inline In-Reply-To: <20160621012829.699158610@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: The host timer which emulates the guest LAPIC TSC deadline timer has its expiration diminished by lapic_timer_advance_ns nanoseconds. Therefore if, at wait_lapic_expire, a difference larger than lapic_timer_advance_ns is encountered, delay at most lapic_timer_advance_ns. This fixes a problem where the guest can cause the host to delay for large amounts of time. Reported-by: Alan Jenkins Signed-off-by: Marcelo Tosatti --- v2: s/max/min/ ! Index: kvm/arch/x86/kvm/lapic.c =================================================================== --- kvm.orig/arch/x86/kvm/lapic.c +++ kvm/arch/x86/kvm/lapic.c @@ -1164,7 +1164,8 @@ void wait_lapic_expire(struct kvm_vcpu * /* __delay is delay_tsc whenever the hardware has TSC, thus always. */ if (guest_tsc < tsc_deadline) - __delay(tsc_deadline - guest_tsc); + __delay(min(tsc_deadline - guest_tsc, + nsec_to_cycles(vcpu, lapic_timer_advance_ns))); } static void start_apic_timer(struct kvm_lapic *apic)