* [PATCH] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ
@ 2021-03-05 2:18 Sean Christopherson
2021-03-05 13:30 ` Paolo Bonzini
2021-03-12 1:05 ` Wanpeng Li
0 siblings, 2 replies; 3+ messages in thread
From: Sean Christopherson @ 2021-03-05 2:18 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel
When posting a deadline timer interrupt, open code the checks guarding
__kvm_wait_lapic_expire() in order to skip the lapic_timer_int_injected()
check in kvm_wait_lapic_expire(). The injection check will always fail
since the interrupt has not yet be injected. Moving the call after
injection would also be wrong as that wouldn't actually delay delivery
of the IRQ if it is indeed sent via posted interrupt.
Fixes: 010fd37fddf6 ("KVM: LAPIC: Reduce world switch latency caused by timer_advance_ns")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/lapic.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 45d40bfacb7c..cb8ebfaccfb6 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1642,7 +1642,16 @@ static void apic_timer_expired(struct kvm_lapic *apic, bool from_timer_fn)
}
if (kvm_use_posted_timer_interrupt(apic->vcpu)) {
- kvm_wait_lapic_expire(vcpu);
+ /*
+ * Ensure the guest's timer has truly expired before posting an
+ * interrupt. Open code the relevant checks to avoid querying
+ * lapic_timer_int_injected(), which will be false since the
+ * interrupt isn't yet injected. Waiting until after injecting
+ * is not an option since that won't help a posted interrupt.
+ */
+ if (vcpu->arch.apic->lapic_timer.expired_tscdeadline &&
+ vcpu->arch.apic->lapic_timer.timer_advance_ns)
+ __kvm_wait_lapic_expire(vcpu);
kvm_apic_inject_pending_timer_irqs(apic);
return;
}
--
2.30.1.766.gb4fecdf3b7-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ
2021-03-05 2:18 [PATCH] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ Sean Christopherson
@ 2021-03-05 13:30 ` Paolo Bonzini
2021-03-12 1:05 ` Wanpeng Li
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-03-05 13:30 UTC (permalink / raw)
To: Sean Christopherson
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel
On 05/03/21 03:18, Sean Christopherson wrote:
> When posting a deadline timer interrupt, open code the checks guarding
> __kvm_wait_lapic_expire() in order to skip the lapic_timer_int_injected()
> check in kvm_wait_lapic_expire(). The injection check will always fail
> since the interrupt has not yet be injected. Moving the call after
> injection would also be wrong as that wouldn't actually delay delivery
> of the IRQ if it is indeed sent via posted interrupt.
>
> Fixes: 010fd37fddf6 ("KVM: LAPIC: Reduce world switch latency caused by timer_advance_ns")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/lapic.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 45d40bfacb7c..cb8ebfaccfb6 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1642,7 +1642,16 @@ static void apic_timer_expired(struct kvm_lapic *apic, bool from_timer_fn)
> }
>
> if (kvm_use_posted_timer_interrupt(apic->vcpu)) {
> - kvm_wait_lapic_expire(vcpu);
> + /*
> + * Ensure the guest's timer has truly expired before posting an
> + * interrupt. Open code the relevant checks to avoid querying
> + * lapic_timer_int_injected(), which will be false since the
> + * interrupt isn't yet injected. Waiting until after injecting
> + * is not an option since that won't help a posted interrupt.
> + */
> + if (vcpu->arch.apic->lapic_timer.expired_tscdeadline &&
> + vcpu->arch.apic->lapic_timer.timer_advance_ns)
> + __kvm_wait_lapic_expire(vcpu);
> kvm_apic_inject_pending_timer_irqs(apic);
> return;
> }
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ
2021-03-05 2:18 [PATCH] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ Sean Christopherson
2021-03-05 13:30 ` Paolo Bonzini
@ 2021-03-12 1:05 ` Wanpeng Li
1 sibling, 0 replies; 3+ messages in thread
From: Wanpeng Li @ 2021-03-12 1:05 UTC (permalink / raw)
To: Sean Christopherson
Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, LKML
On Fri, 5 Mar 2021 at 10:19, Sean Christopherson <seanjc@google.com> wrote:
>
> When posting a deadline timer interrupt, open code the checks guarding
> __kvm_wait_lapic_expire() in order to skip the lapic_timer_int_injected()
> check in kvm_wait_lapic_expire(). The injection check will always fail
> since the interrupt has not yet be injected. Moving the call after
> injection would also be wrong as that wouldn't actually delay delivery
> of the IRQ if it is indeed sent via posted interrupt.
>
> Fixes: 010fd37fddf6 ("KVM: LAPIC: Reduce world switch latency caused by timer_advance_ns")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/lapic.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 45d40bfacb7c..cb8ebfaccfb6 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1642,7 +1642,16 @@ static void apic_timer_expired(struct kvm_lapic *apic, bool from_timer_fn)
> }
>
> if (kvm_use_posted_timer_interrupt(apic->vcpu)) {
> - kvm_wait_lapic_expire(vcpu);
> + /*
> + * Ensure the guest's timer has truly expired before posting an
> + * interrupt. Open code the relevant checks to avoid querying
> + * lapic_timer_int_injected(), which will be false since the
> + * interrupt isn't yet injected. Waiting until after injecting
> + * is not an option since that won't help a posted interrupt.
> + */
> + if (vcpu->arch.apic->lapic_timer.expired_tscdeadline &&
> + vcpu->arch.apic->lapic_timer.timer_advance_ns)
> + __kvm_wait_lapic_expire(vcpu);
Thanks for the fixing.
Wanpeng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-12 1:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 2:18 [PATCH] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ Sean Christopherson
2021-03-05 13:30 ` Paolo Bonzini
2021-03-12 1:05 ` Wanpeng Li
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.