Re: [PATCH v2] KVM: LAPIC: Narrow down the kick target vCPU
From: Wanpeng Li
Date: Mon Aug 24 2020 - 01:15:23 EST
On Mon, 24 Aug 2020 at 09:03, Wanpeng Li <kernellwp@xxxxxxxxx> wrote:
>
> From: Wanpeng Li <wanpengli@xxxxxxxxxxx>
>
> The kick after setting KVM_REQ_PENDING_TIMER is used to handle the timer
> fires on a different pCPU which vCPU is running on, this kick is expensive
> since memory barrier, rcu, preemption disable/enable operations. We don't
> need this kick when injecting already-expired timer, we also should call
> out the VMX preemption timer case, which also passes from_timer_fn=false
> but doesn't need a kick because kvm_lapic_expired_hv_timer() is called
> from the target vCPU.
>
I miss Sean's reviewed-by tag.
Reviewed-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
> Signed-off-by: Wanpeng Li <wanpengli@xxxxxxxxxxx>
> ---
> v1 -> v2:
> * update patch subject and changelog
> * open code kvm_set_pending_timer()
>
> arch/x86/kvm/lapic.c | 4 +++-
> arch/x86/kvm/x86.c | 6 ------
> arch/x86/kvm/x86.h | 1 -
> 3 files changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 248095a..97f1dbf 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1642,7 +1642,9 @@ static void apic_timer_expired(struct kvm_lapic *apic, bool from_timer_fn)
> }
>
> atomic_inc(&apic->lapic_timer.pending);
> - kvm_set_pending_timer(vcpu);
> + kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
> + if (from_timer_fn)
> + kvm_vcpu_kick(vcpu);
> }
>
> static void start_sw_tscdeadline(struct kvm_lapic *apic)
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 599d732..51b74d0 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1778,12 +1778,6 @@ static s64 get_kvmclock_base_ns(void)
> }
> #endif
>
> -void kvm_set_pending_timer(struct kvm_vcpu *vcpu)
> -{
> - kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
> - kvm_vcpu_kick(vcpu);
> -}
> -
> static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
> {
> int version;
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 995ab69..ea20b8b 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -246,7 +246,6 @@ static inline bool kvm_vcpu_latch_init(struct kvm_vcpu *vcpu)
> return is_smm(vcpu) || kvm_x86_ops.apic_init_signal_blocked(vcpu);
> }
>
> -void kvm_set_pending_timer(struct kvm_vcpu *vcpu);
> void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
>
> void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr);
> --
> 2.7.4
>