Re: [PATCH v2 4/5] KVM: X86: TSCDEADLINE MSR emulation fastpath

From: Wanpeng Li
Date: Thu Apr 23 2020 - 05:54:32 EST


On Thu, 23 Apr 2020 at 17:39, Paolo Bonzini <pbonzini@xxxxxxxxxx> wrote:
>
> On 23/04/20 11:01, Wanpeng Li wrote:
> > +
> > +void kvm_set_lapic_tscdeadline_msr(struct kvm_vcpu *vcpu, u64 data)
> > +{
> > + if (__kvm_set_lapic_tscdeadline_msr(vcpu, data))
> > + start_apic_timer(vcpu->arch.apic);
> > +}
> > +
> > +int kvm_set_lapic_tscdeadline_msr_fast(struct kvm_vcpu *vcpu, u64 data)
> > +{
> > + struct kvm_lapic *apic = vcpu->arch.apic;
> > +
> > + if (__kvm_set_lapic_tscdeadline_msr(vcpu, data)) {
> > + atomic_set(&apic->lapic_timer.pending, 0);
> > + if (start_hv_timer(apic))
> > + return tscdeadline_expired_timer_fast(vcpu);
> > + }
> > +
> > + return 1;
> > }
> >
> > +static int tscdeadline_expired_timer_fast(struct kvm_vcpu *vcpu)
> > +{
> > + if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
> > + kvm_clear_request(KVM_REQ_PENDING_TIMER, vcpu);
> > + kvm_inject_apic_timer_irqs_fast(vcpu);
> > + atomic_set(&vcpu->arch.apic->lapic_timer.pending, 0);
> > + }
> > +
> > + return 0;
> > +}
>
> This could also be handled in apic_timer_expired. For example you can
> add an argument from_timer_fn and do
>
> if (!from_timer_fn) {
> WARN_ON(kvm_get_running_vcpu() != vcpu);
> kvm_inject_apic_timer_irqs_fast(vcpu);
> return;
> }
>
> if (kvm_use_posted_timer_interrupt(apic->vcpu)) {
> ...
> }
> atomic_inc(&apic->lapic_timer.pending);
> kvm_set_pending_timer(vcpu);
>
> and then you don't need kvm_set_lapic_tscdeadline_msr_fast and

I guess you mean don't need tscdeadline_expired_timer_fast().

Wanpeng