From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948034AbdEZPpg (ORCPT ); Fri, 26 May 2017 11:45:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47318 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752183AbdEZPpe (ORCPT ); Fri, 26 May 2017 11:45:34 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1B8BA2DC374 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1B8BA2DC374 Subject: Re: [PATCH] KVM: X86: Fix preempt the preemption timer cancel To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li References: <1495337552-78885-1-git-send-email-wanpeng.li@hotmail.com> From: Paolo Bonzini Message-ID: <9c21e92e-0754-7eda-76bc-2418abe8cd5b@redhat.com> Date: Fri, 26 May 2017 17:45:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <1495337552-78885-1-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 26 May 2017 15:45:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/05/2017 05:32, Wanpeng Li wrote: > vmx_cancel_hv_timer > vCPU0's vmx->hv_deadline_tsc = -1 > > preempt occur > > clear preemption timer field in CPU1's active vmcs > vCPU0's apic_timer.hv_timer_in_use = false > vmx_vcpu_run(vCPU0) > vmx_arm_hv_timer > if (vmx->hv_deadline_tsc == -1) > nothing change > > handle_preemption_timer(vCPU0) > kvm_lapic_expired_hv_timer > WARN_ON(!apic->lapic_timer.hv_timer_in_use); > > Preemption can occur during cancel preemption timer, and there will be inconsistent > status in lapic, vmx and vmcs field. This patch fixes it by disable preemption for > cancelling preemption timer. I see, so the purpose is to serialize against kvm_arch_vcpu_load. Nice catch, I've queued the patch for kvm/master. Paolo > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/lapic.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index c329d28..6e6f345 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1495,8 +1495,10 @@ EXPORT_SYMBOL_GPL(kvm_lapic_hv_timer_in_use); > > static void cancel_hv_timer(struct kvm_lapic *apic) > { > + preempt_disable(); > kvm_x86_ops->cancel_hv_timer(apic->vcpu); > apic->lapic_timer.hv_timer_in_use = false; > + preempt_enable(); > } > > static bool start_hv_timer(struct kvm_lapic *apic) > --