* FAILED: patch "[PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling" failed to apply to 5.10-stable tree
@ 2021-05-14 15:37 gregkh
2021-05-26 6:08 ` Jack Wang
0 siblings, 1 reply; 5+ messages in thread
From: gregkh @ 2021-05-14 15:37 UTC (permalink / raw)
To: wanpengli, seanjc, tglx; +Cc: stable
The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 160457140187c5fb127b844e5a85f87f00a01b14 Mon Sep 17 00:00:00 2001
From: Wanpeng Li <wanpengli@tencent.com>
Date: Tue, 4 May 2021 17:27:30 -0700
Subject: [PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling
Defer the call to account guest time until after servicing any IRQ(s)
that happened in the guest or immediately after VM-Exit. Tick-based
accounting of vCPU time relies on PF_VCPU being set when the tick IRQ
handler runs, and IRQs are blocked throughout the main sequence of
vcpu_enter_guest(), including the call into vendor code to actually
enter and exit the guest.
This fixes a bug where reported guest time remains '0', even when
running an infinite loop in the guest:
https://bugzilla.kernel.org/show_bug.cgi?id=209831
Fixes: 87fa7f3e98a131 ("x86/kvm: Move context tracking where it belongs")
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Co-developed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20210505002735.1684165-4-seanjc@google.com
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 9790c73f2a32..c400def6220b 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3753,15 +3753,15 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
* have them in state 'on' as recorded before entering guest mode.
* Same as enter_from_user_mode().
*
- * guest_exit_irqoff() restores host context and reinstates RCU if
- * enabled and required.
+ * context_tracking_guest_exit() restores host context and reinstates
+ * RCU if enabled and required.
*
* This needs to be done before the below as native_read_msr()
* contains a tracepoint and x86_spec_ctrl_restore_host() calls
* into world and some more.
*/
lockdep_hardirqs_off(CALLER_ADDR0);
- guest_exit_irqoff();
+ context_tracking_guest_exit();
instrumentation_begin();
trace_hardirqs_off_finish();
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index b21d751407b5..e108fb47855b 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6703,15 +6703,15 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
* have them in state 'on' as recorded before entering guest mode.
* Same as enter_from_user_mode().
*
- * guest_exit_irqoff() restores host context and reinstates RCU if
- * enabled and required.
+ * context_tracking_guest_exit() restores host context and reinstates
+ * RCU if enabled and required.
*
* This needs to be done before the below as native_read_msr()
* contains a tracepoint and x86_spec_ctrl_restore_host() calls
* into world and some more.
*/
lockdep_hardirqs_off(CALLER_ADDR0);
- guest_exit_irqoff();
+ context_tracking_guest_exit();
instrumentation_begin();
trace_hardirqs_off_finish();
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index cebdaa1e3cf5..6eda2834fc05 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9315,6 +9315,15 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
local_irq_disable();
kvm_after_interrupt(vcpu);
+ /*
+ * Wait until after servicing IRQs to account guest time so that any
+ * ticks that occurred while running the guest are properly accounted
+ * to the guest. Waiting until IRQs are enabled degrades the accuracy
+ * of accounting via context tracking, but the loss of accuracy is
+ * acceptable for all known use cases.
+ */
+ vtime_account_guest_exit();
+
if (lapic_in_kernel(vcpu)) {
s64 delta = vcpu->arch.apic->lapic_timer.advance_expire_delta;
if (delta != S64_MIN) {
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: FAILED: patch "[PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling" failed to apply to 5.10-stable tree
2021-05-14 15:37 FAILED: patch "[PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling" failed to apply to 5.10-stable tree gregkh
@ 2021-05-26 6:08 ` Jack Wang
2021-05-27 9:18 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Jack Wang @ 2021-05-26 6:08 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: wanpengli, seanjc, tglx, stable
<gregkh@linuxfoundation.org> 于2021年5月14日周五 下午9:32写道:
>
>
> The patch below does not apply to the 5.10-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
If I first apply 866a6dadbb02 ("context_tracking: Move guest exit
context tracking to separate helpers")
and 88d8220bbf06 ("context_tracking: Move guest exit vtime accounting
to separate helpers")
then I can apply this commit cleanly to latest 5.10.y, I suppose it
will work for 5.12.
>
> thanks,
>
> greg k-h
Thanks!
Jack Wang
>
> ------------------ original commit in Linus's tree ------------------
>
> From 160457140187c5fb127b844e5a85f87f00a01b14 Mon Sep 17 00:00:00 2001
> From: Wanpeng Li <wanpengli@tencent.com>
> Date: Tue, 4 May 2021 17:27:30 -0700
> Subject: [PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling
>
> Defer the call to account guest time until after servicing any IRQ(s)
> that happened in the guest or immediately after VM-Exit. Tick-based
> accounting of vCPU time relies on PF_VCPU being set when the tick IRQ
> handler runs, and IRQs are blocked throughout the main sequence of
> vcpu_enter_guest(), including the call into vendor code to actually
> enter and exit the guest.
>
> This fixes a bug where reported guest time remains '0', even when
> running an infinite loop in the guest:
>
> https://bugzilla.kernel.org/show_bug.cgi?id=209831
>
> Fixes: 87fa7f3e98a131 ("x86/kvm: Move context tracking where it belongs")
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Co-developed-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: stable@vger.kernel.org
> Link: https://lore.kernel.org/r/20210505002735.1684165-4-seanjc@google.com
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 9790c73f2a32..c400def6220b 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3753,15 +3753,15 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
> * have them in state 'on' as recorded before entering guest mode.
> * Same as enter_from_user_mode().
> *
> - * guest_exit_irqoff() restores host context and reinstates RCU if
> - * enabled and required.
> + * context_tracking_guest_exit() restores host context and reinstates
> + * RCU if enabled and required.
> *
> * This needs to be done before the below as native_read_msr()
> * contains a tracepoint and x86_spec_ctrl_restore_host() calls
> * into world and some more.
> */
> lockdep_hardirqs_off(CALLER_ADDR0);
> - guest_exit_irqoff();
> + context_tracking_guest_exit();
>
> instrumentation_begin();
> trace_hardirqs_off_finish();
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index b21d751407b5..e108fb47855b 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6703,15 +6703,15 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
> * have them in state 'on' as recorded before entering guest mode.
> * Same as enter_from_user_mode().
> *
> - * guest_exit_irqoff() restores host context and reinstates RCU if
> - * enabled and required.
> + * context_tracking_guest_exit() restores host context and reinstates
> + * RCU if enabled and required.
> *
> * This needs to be done before the below as native_read_msr()
> * contains a tracepoint and x86_spec_ctrl_restore_host() calls
> * into world and some more.
> */
> lockdep_hardirqs_off(CALLER_ADDR0);
> - guest_exit_irqoff();
> + context_tracking_guest_exit();
>
> instrumentation_begin();
> trace_hardirqs_off_finish();
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index cebdaa1e3cf5..6eda2834fc05 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9315,6 +9315,15 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
> local_irq_disable();
> kvm_after_interrupt(vcpu);
>
> + /*
> + * Wait until after servicing IRQs to account guest time so that any
> + * ticks that occurred while running the guest are properly accounted
> + * to the guest. Waiting until IRQs are enabled degrades the accuracy
> + * of accounting via context tracking, but the loss of accuracy is
> + * acceptable for all known use cases.
> + */
> + vtime_account_guest_exit();
> +
> if (lapic_in_kernel(vcpu)) {
> s64 delta = vcpu->arch.apic->lapic_timer.advance_expire_delta;
> if (delta != S64_MIN) {
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: FAILED: patch "[PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling" failed to apply to 5.10-stable tree
2021-05-26 6:08 ` Jack Wang
@ 2021-05-27 9:18 ` Greg Kroah-Hartman
2021-05-27 15:25 ` Sean Christopherson
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2021-05-27 9:18 UTC (permalink / raw)
To: Jack Wang; +Cc: wanpengli, seanjc, tglx, stable
On Wed, May 26, 2021 at 08:08:09AM +0200, Jack Wang wrote:
> <gregkh@linuxfoundation.org> 于2021年5月14日周五 下午9:32写道:
> >
> >
> > The patch below does not apply to the 5.10-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
>
> If I first apply 866a6dadbb02 ("context_tracking: Move guest exit
> context tracking to separate helpers")
> and 88d8220bbf06 ("context_tracking: Move guest exit vtime accounting
> to separate helpers")
>
> then I can apply this commit cleanly to latest 5.10.y, I suppose it
> will work for 5.12.
That worked, thanks! Now queued up.
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: FAILED: patch "[PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling" failed to apply to 5.10-stable tree
2021-05-27 9:18 ` Greg Kroah-Hartman
@ 2021-05-27 15:25 ` Sean Christopherson
2021-05-27 15:43 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2021-05-27 15:25 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Jack Wang, wanpengli, tglx, stable
On Thu, May 27, 2021, Greg Kroah-Hartman wrote:
> On Wed, May 26, 2021 at 08:08:09AM +0200, Jack Wang wrote:
> > <gregkh@linuxfoundation.org> 于2021年5月14日周五 下午9:32写道:
> > >
> > >
> > > The patch below does not apply to the 5.10-stable tree.
> > > If someone wants it applied there, or to any other stable or longterm
> > > tree, then please email the backport, including the original git commit
> > > id to <stable@vger.kernel.org>.
> >
> > If I first apply 866a6dadbb02 ("context_tracking: Move guest exit
> > context tracking to separate helpers")
> > and 88d8220bbf06 ("context_tracking: Move guest exit vtime accounting
> > to separate helpers")
> >
> > then I can apply this commit cleanly to latest 5.10.y, I suppose it
> > will work for 5.12.
Thanks much!
> That worked, thanks! Now queued up.
To not mess up in the future, I assume known dependencies should be tagged
"Cc: stable...", even if the dependencies aren't technically bug fixes?
The plan all along was that all three patches would have to be picked up, but
apparently I thought that would happen automagically.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: FAILED: patch "[PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling" failed to apply to 5.10-stable tree
2021-05-27 15:25 ` Sean Christopherson
@ 2021-05-27 15:43 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2021-05-27 15:43 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Jack Wang, wanpengli, tglx, stable
On Thu, May 27, 2021 at 03:25:33PM +0000, Sean Christopherson wrote:
> On Thu, May 27, 2021, Greg Kroah-Hartman wrote:
> > On Wed, May 26, 2021 at 08:08:09AM +0200, Jack Wang wrote:
> > > <gregkh@linuxfoundation.org> 于2021年5月14日周五 下午9:32写道:
> > > >
> > > >
> > > > The patch below does not apply to the 5.10-stable tree.
> > > > If someone wants it applied there, or to any other stable or longterm
> > > > tree, then please email the backport, including the original git commit
> > > > id to <stable@vger.kernel.org>.
> > >
> > > If I first apply 866a6dadbb02 ("context_tracking: Move guest exit
> > > context tracking to separate helpers")
> > > and 88d8220bbf06 ("context_tracking: Move guest exit vtime accounting
> > > to separate helpers")
> > >
> > > then I can apply this commit cleanly to latest 5.10.y, I suppose it
> > > will work for 5.12.
>
> Thanks much!
>
> > That worked, thanks! Now queued up.
>
> To not mess up in the future, I assume known dependencies should be tagged
> "Cc: stable...", even if the dependencies aren't technically bug fixes?
Yes, the documentation shows also how to do this semi-automatically:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-27 15:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 15:37 FAILED: patch "[PATCH] KVM: x86: Defer vtime accounting 'til after IRQ handling" failed to apply to 5.10-stable tree gregkh
2021-05-26 6:08 ` Jack Wang
2021-05-27 9:18 ` Greg Kroah-Hartman
2021-05-27 15:25 ` Sean Christopherson
2021-05-27 15:43 ` Greg Kroah-Hartman
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.