From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751885AbcGGMaV (ORCPT ); Thu, 7 Jul 2016 08:30:21 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33798 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751030AbcGGMaJ (ORCPT ); Thu, 7 Jul 2016 08:30:09 -0400 Subject: Re: [PATCH v4 2/2] KVM: nVMX: Fix preemption timer bit set in vmcs02 even if L1 doesn't enable it To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <1467893939-3335-1-git-send-email-wanpeng.li@hotmail.com> <1467893939-3335-2-git-send-email-wanpeng.li@hotmail.com> Cc: Wanpeng Li , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Yunhong Jiang , Jan Kiszka , Haozhong Zhang From: Paolo Bonzini Message-ID: Date: Thu, 7 Jul 2016 14:29:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <1467893939-3335-2-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/07/2016 14:18, Wanpeng Li wrote: > From: Wanpeng Li > > We will go to vcpu_run() loop after L0 emulates VMRESUME which maybe > incur kvm_sched_out and kvm_sched_in operations since cond_resched() > will be called once need resched. Preemption timer will be reprogrammed > if vCPU is scheduled to a different pCPU. Then the preemption timer > bit of vmcs02 will be set if L0 enable preemption timer to run L1 even > if L1 doesn't enable preemption timer to run L2. > > This patch fix it by don't reprogram preemption timer of vmcs02 if L1's > vCPU is scheduled on diffent pCPU when we are in the way to vmresume > nested guest, and fallback to hrtimer based emulated method. > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Yunhong Jiang > Cc: Jan Kiszka > Cc: Haozhong Zhang > Signed-off-by: Wanpeng Li > --- > v3 -> v4: > * fallback to hrtimer based emulated method when in the way to vmresume nested guest > > arch/x86/kvm/x86.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 0cc6cf8..05137c0 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2743,8 +2743,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > mark_tsc_unstable("KVM discovered backwards TSC"); > > if (kvm_lapic_hv_timer_in_use(vcpu) && > + (is_guest_mode(vcpu) || > kvm_x86_ops->set_hv_timer(vcpu, > - kvm_get_lapic_tscdeadline_msr(vcpu))) > + kvm_get_lapic_tscdeadline_msr(vcpu)))) > kvm_lapic_switch_to_sw_timer(vcpu); > if (check_tsc_unstable()) { > u64 offset = kvm_compute_tsc_offset(vcpu, > Thanks, this is good as a fallback. I'll try to fix it by getting the pin-based execution controls right but if I fail this patch is okay. Reviewed-by: Paolo Bonzini