]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.10-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 May 2021 09:24:34 +0000 (11:24 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 May 2021 09:24:34 +0000 (11:24 +0200)
added patches:
context_tracking-move-guest-exit-context-tracking-to-separate-helpers.patch
context_tracking-move-guest-exit-vtime-accounting-to-separate-helpers.patch
kvm-x86-defer-vtime-accounting-til-after-irq-handling.patch

queue-5.10/context_tracking-move-guest-exit-context-tracking-to-separate-helpers.patch [new file with mode: 0644]
queue-5.10/context_tracking-move-guest-exit-vtime-accounting-to-separate-helpers.patch [new file with mode: 0644]
queue-5.10/kvm-x86-defer-vtime-accounting-til-after-irq-handling.patch [new file with mode: 0644]
queue-5.10/series

diff --git a/queue-5.10/context_tracking-move-guest-exit-context-tracking-to-separate-helpers.patch b/queue-5.10/context_tracking-move-guest-exit-context-tracking-to-separate-helpers.patch
new file mode 100644 (file)
index 0000000..6c2d812
--- /dev/null
@@ -0,0 +1,52 @@
+From 866a6dadbb027b2955a7ae00bab9705d382def12 Mon Sep 17 00:00:00 2001
+From: Wanpeng Li <wanpengli@tencent.com>
+Date: Tue, 4 May 2021 17:27:28 -0700
+Subject: context_tracking: Move guest exit context tracking to separate helpers
+
+From: Wanpeng Li <wanpengli@tencent.com>
+
+commit 866a6dadbb027b2955a7ae00bab9705d382def12 upstream.
+
+Provide separate context tracking helpers for guest exit, the standalone
+helpers will be called separately by KVM x86 in later patches to fix
+tick-based accounting.
+
+Suggested-by: Thomas Gleixner <tglx@linutronix.de>
+Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
+Co-developed-by: Sean Christopherson <seanjc@google.com>
+Signed-off-by: Sean Christopherson <seanjc@google.com>
+Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
+Link: https://lore.kernel.org/r/20210505002735.1684165-2-seanjc@google.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/context_tracking.h |    9 ++++++++-
+ 1 file changed, 8 insertions(+), 1 deletion(-)
+
+--- a/include/linux/context_tracking.h
++++ b/include/linux/context_tracking.h
+@@ -129,10 +129,15 @@ static __always_inline void guest_enter_
+       }
+ }
+-static __always_inline void guest_exit_irqoff(void)
++static __always_inline void context_tracking_guest_exit(void)
+ {
+       if (context_tracking_enabled())
+               __context_tracking_exit(CONTEXT_GUEST);
++}
++
++static __always_inline void guest_exit_irqoff(void)
++{
++      context_tracking_guest_exit();
+       instrumentation_begin();
+       if (vtime_accounting_enabled_this_cpu())
+@@ -157,6 +162,8 @@ static __always_inline void guest_enter_
+       instrumentation_end();
+ }
++static __always_inline void context_tracking_guest_exit(void) { }
++
+ static __always_inline void guest_exit_irqoff(void)
+ {
+       instrumentation_begin();
diff --git a/queue-5.10/context_tracking-move-guest-exit-vtime-accounting-to-separate-helpers.patch b/queue-5.10/context_tracking-move-guest-exit-vtime-accounting-to-separate-helpers.patch
new file mode 100644 (file)
index 0000000..cf823ae
--- /dev/null
@@ -0,0 +1,73 @@
+From 88d8220bbf06dd8045b2ac4be1046290eaa7773a Mon Sep 17 00:00:00 2001
+From: Wanpeng Li <wanpengli@tencent.com>
+Date: Tue, 4 May 2021 17:27:29 -0700
+Subject: context_tracking: Move guest exit vtime accounting to separate helpers
+
+From: Wanpeng Li <wanpengli@tencent.com>
+
+commit 88d8220bbf06dd8045b2ac4be1046290eaa7773a upstream.
+
+Provide separate vtime accounting functions for guest exit instead of
+open coding the logic within the context tracking code.  This will allow
+KVM x86 to handle vtime accounting slightly differently when using
+tick-based accounting.
+
+Suggested-by: Thomas Gleixner <tglx@linutronix.de>
+Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
+Co-developed-by: Sean Christopherson <seanjc@google.com>
+Signed-off-by: Sean Christopherson <seanjc@google.com>
+Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
+Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
+Link: https://lore.kernel.org/r/20210505002735.1684165-3-seanjc@google.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/context_tracking.h |   22 ++++++++++++++++------
+ 1 file changed, 16 insertions(+), 6 deletions(-)
+
+--- a/include/linux/context_tracking.h
++++ b/include/linux/context_tracking.h
+@@ -135,15 +135,20 @@ static __always_inline void context_trac
+               __context_tracking_exit(CONTEXT_GUEST);
+ }
+-static __always_inline void guest_exit_irqoff(void)
++static __always_inline void vtime_account_guest_exit(void)
+ {
+-      context_tracking_guest_exit();
+-
+-      instrumentation_begin();
+       if (vtime_accounting_enabled_this_cpu())
+               vtime_guest_exit(current);
+       else
+               current->flags &= ~PF_VCPU;
++}
++
++static __always_inline void guest_exit_irqoff(void)
++{
++      context_tracking_guest_exit();
++
++      instrumentation_begin();
++      vtime_account_guest_exit();
+       instrumentation_end();
+ }
+@@ -164,12 +169,17 @@ static __always_inline void guest_enter_
+ static __always_inline void context_tracking_guest_exit(void) { }
++static __always_inline void vtime_account_guest_exit(void)
++{
++      vtime_account_kernel(current);
++      current->flags &= ~PF_VCPU;
++}
++
+ static __always_inline void guest_exit_irqoff(void)
+ {
+       instrumentation_begin();
+       /* Flush the guest cputime we spent on the guest */
+-      vtime_account_kernel(current);
+-      current->flags &= ~PF_VCPU;
++      vtime_account_guest_exit();
+       instrumentation_end();
+ }
+ #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
diff --git a/queue-5.10/kvm-x86-defer-vtime-accounting-til-after-irq-handling.patch b/queue-5.10/kvm-x86-defer-vtime-accounting-til-after-irq-handling.patch
new file mode 100644 (file)
index 0000000..0a8b99a
--- /dev/null
@@ -0,0 +1,96 @@
+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: KVM: x86: Defer vtime accounting 'til after IRQ handling
+
+From: Wanpeng Li <wanpengli@tencent.com>
+
+commit 160457140187c5fb127b844e5a85f87f00a01b14 upstream.
+
+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
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/x86/kvm/svm/svm.c |    6 +++---
+ arch/x86/kvm/vmx/vmx.c |    6 +++---
+ arch/x86/kvm/x86.c     |    9 +++++++++
+ 3 files changed, 15 insertions(+), 6 deletions(-)
+
+--- a/arch/x86/kvm/svm/svm.c
++++ b/arch/x86/kvm/svm/svm.c
+@@ -3532,15 +3532,15 @@ static noinstr void svm_vcpu_enter_exit(
+        * 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();
+--- a/arch/x86/kvm/vmx/vmx.c
++++ b/arch/x86/kvm/vmx/vmx.c
+@@ -6640,15 +6640,15 @@ static noinstr void vmx_vcpu_enter_exit(
+        * 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();
+--- a/arch/x86/kvm/x86.c
++++ b/arch/x86/kvm/x86.c
+@@ -9063,6 +9063,15 @@ static int vcpu_enter_guest(struct kvm_v
+       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) {
index fe2006fd888ac99deadbae48eb706d75e27e94d1..b483908309d7ed233c8dc8f207e9e1853d35c48d 100644 (file)
@@ -1,3 +1,6 @@
 bpf-wrap-aux-data-inside-bpf_sanitize_info-container.patch
 bpf-fix-mask-direction-swap-upon-off-reg-sign-change.patch
 bpf-no-need-to-simulate-speculative-domain-for-immediates.patch
+context_tracking-move-guest-exit-context-tracking-to-separate-helpers.patch
+context_tracking-move-guest-exit-vtime-accounting-to-separate-helpers.patch
+kvm-x86-defer-vtime-accounting-til-after-irq-handling.patch