Re: [PATCH v2] KVM: LAPIC: Fix lapic timer injection delay

From: Paolo Bonzini
Date: Tue Jun 27 2017 - 12:10:32 EST




On 23/06/2017 13:59, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@xxxxxxxxxxx>
>
> Linux as a guest will prevent to program the next event to the clock event
> device when the event is in the past. However, it is not guaranteed by all
> the guests, the guest like kvm-unit-tests/apic.flat will write current tsc
> value visible in guest to MSR_IA32_TSCDEADLINE, lapic timer which is emulated
> by vmx preemption timer will program the absolute target tsc value to vmcs
> preemption timer field w/ delta == 0, then plays a vmentry and an upcoming
> vmx preemption timer fire vmexit dance, the lapic timer injection is delayed
> for this duration. Actually the lapic timer which is emulated by hrtimer can
> handle this correctly.
>
> This patch fixes it by firing the lapic timer and injecting a timer interrupt
> immediately during the next vmentry if guest programs an expired timer to
> the emulated timer device. This saves ~300 cycles on the tsc_deadline_timer
> test of apic.flat.

If it doesn't matter for actual guests, I'd rather not complicate the logic.

Paolo