Message ID | 1500936209-98069-1-git-send-email-wanpeng.li@hotmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
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);
2017-07-25 15:25 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>: > 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. I just send out v4 to fix it. Thanks for the review. Regards, Wanpeng Li > > 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); >
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 2819d4c..0d558c5 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1495,11 +1495,10 @@ EXPORT_SYMBOL_GPL(kvm_lapic_hv_timer_in_use); static void cancel_hv_timer(struct kvm_lapic *apic) { + WARN_ON(preemptible()); WARN_ON(!apic->lapic_timer.hv_timer_in_use); - 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) @@ -1552,18 +1551,25 @@ static void start_sw_timer(struct kvm_lapic *apic) static void restart_apic_timer(struct kvm_lapic *apic) { + preempt_disable(); if (!start_hv_timer(apic)) start_sw_timer(apic); + preempt_enable(); } void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu) { struct kvm_lapic *apic = vcpu->arch.apic; - 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_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);