From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750882AbdGYHZS (ORCPT ); Tue, 25 Jul 2017 03:25:18 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:33283 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750781AbdGYHZQ (ORCPT ); Tue, 25 Jul 2017 03:25:16 -0400 Subject: Re: [PATCH v3] KVM: LAPIC: Fix reentrancy issues with preempt notifiers To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li References: <1500936209-98069-1-git-send-email-wanpeng.li@hotmail.com> From: Paolo Bonzini Message-ID: <18bcec8d-07ab-d523-5569-46319a04a1dd@redhat.com> Date: Tue, 25 Jul 2017 09:25:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1500936209-98069-1-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/07/2017 00:43, Wanpeng Li wrote: > - WARN_ON(!apic->lapic_timer.hv_timer_in_use); > + preempt_disable(); > + /* The preempt notifier has called apic_timer_expired already */ > + if (!apic->lapic_timer.hv_timer_in_use) > + goto out; > WARN_ON(swait_active(&vcpu->wq)); > cancel_hv_timer(apic); > apic_timer_expired(apic); > +out: > + preempt_enable(); If apic_timer_expired was called, and the timer is in periodic mode, it has already set the hv timer. Should the out label be really at the end of the function, after the timer is restarted? Otherwise you can call advance_periodic_timer_expiration twice. Thanks, Paolo > > if (apic_lvtt_period(apic) && apic->lapic_timer.period) { > advance_periodic_target_expiration(apic); > @@ -1582,9 +1588,11 @@ void kvm_lapic_switch_to_sw_timer(struct kvm_vcpu *vcpu) > { > struct kvm_lapic *apic = vcpu->arch.apic; > > + preempt_disable(); > /* Possibly the TSC deadline timer is not enabled yet */ > if (apic->lapic_timer.hv_timer_in_use) > start_sw_timer(apic); > + preempt_enable(); > } > EXPORT_SYMBOL_GPL(kvm_lapic_switch_to_sw_timer);