linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs
@ 2022-02-01 13:29 Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 1/5] kvm: add guest_state_{enter,exit}_irqoff() Mark Rutland
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Mark Rutland @ 2022-02-01 13:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	borntraeger, bp, catalin.marinas, chenhuacai, dave.hansen,
	frederic, hca, james.morse, jmattson, joro, mark.rutland, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	pbonzini, seanjc, suzuki.poulose, svens, tglx, tsbogend,
	vkuznets, wanpengli, will

Several architectures have latent bugs around guest entry/exit,
including:

1) Enabling interrupts during an RCU EQS, allowing interrupt handlers to
   run without RCU watching.

2) Using (potentially) instrumented code between guest_enter() and
   guest_exit(), allowing instrumentation handlers to run without RCU
   watching.

3) Not informing lockdep and tracing about interrupt masking, or
   informing in an incorrect order (e.g. relative to entering/exiting an
   RCU EQS).

4) Unbalanced entry/exit accounting in some cases (which may or may not
   result in functional problems).

Overall, the architectures affected are:

  arm64, mips, powerpc, riscv, s390, x86

This series reworks the common code to make handling these issues
earier, and for the following architectures fixes those issues by
conversion to new helper functions:

  arm64, mips, riscv, x86

The core, arm64, and x86 patches have reviews from the relevant
maintainers, and I think those are good-to-go. I have not yet had
acks/reviews for the mips and riscv patches. I'm fairly certain the
riscv patch is correct by virtue of it being so simple, and I'm
relatively confident that the mips patch is correct (though I may have
missed additional issues), but I have no way of testing either so I've
placed them at the end of the series where they can easily be dropped if
necessary.

This series does NOT fix the following architectures, which will need
more substantial changes to architecture-specific entry logic and/or
sequencing:

  powerpc, s390

... and I assume it would be preferable to fix the common code and
simple cases now, such that those can be addressed in subsequent
follow-ups.

Since v1 [1]:
* Add arch_in_rcu_eqs()
* Convert s390
* Rename exit_to_guest_mode() -> guest_state_enter_irqoff()
* Rename enter_from_guest_mode() -> guest_state_exit_irqoff()
* Various commit message cleanups

Since v2 [2]:
* Rebase to v5.17-rc2
* Fixup mips exit handling
* Drop arch_in_rcu_eqs() & s390 patches

I've pushed the series (based on v5.17-rc2) to my kvm/entry-rework branch:

  https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/entry-rework
  git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git kvm/entry-rework

This version of the series is tagged as kvm-entry-rework-20220201.

[1] https://lore.kernel.org/r/20220111153539.2532246-1-mark.rutland@arm.com/
[2] https://lore.kernel.org/r/20220119105854.3160683-1-mark.rutland@arm.com/

Thanks,


Mark Rutland (5):
  kvm: add guest_state_{enter,exit}_irqoff()
  kvm/arm64: rework guest entry logic
  kvm/x86: rework guest entry logic
  kvm/riscv: rework guest entry logic
  kvm/mips: rework guest entry logic

 arch/arm64/kvm/arm.c     |  51 +++++++++++-------
 arch/mips/kvm/mips.c     |  50 +++++++++++++++--
 arch/riscv/kvm/vcpu.c    |  44 +++++++++------
 arch/x86/kvm/svm/svm.c   |   4 +-
 arch/x86/kvm/vmx/vmx.c   |   4 +-
 arch/x86/kvm/x86.c       |   4 +-
 arch/x86/kvm/x86.h       |  45 ----------------
 include/linux/kvm_host.h | 112 +++++++++++++++++++++++++++++++++++++--
 8 files changed, 222 insertions(+), 92 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/5] kvm: add guest_state_{enter,exit}_irqoff()
  2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
@ 2022-02-01 13:29 ` Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 2/5] kvm/arm64: rework guest entry logic Mark Rutland
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Mark Rutland @ 2022-02-01 13:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	borntraeger, bp, catalin.marinas, chenhuacai, dave.hansen,
	frederic, hca, james.morse, jmattson, joro, mark.rutland, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	pbonzini, seanjc, suzuki.poulose, svens, tglx, tsbogend,
	vkuznets, wanpengli, will

When transitioning to/from guest mode, it is necessary to inform
lockdep, tracing, and RCU in a specific order, similar to the
requirements for transitions to/from user mode. Additionally, it is
necessary to perform vtime accounting for a window around running the
guest, with RCU enabled, such that timer interrupts taken from the guest
can be accounted as guest time.

Most architectures don't handle all the necessary pieces, and a have a
number of common bugs, including unsafe usage of RCU during the window
between guest_enter() and guest_exit().

On x86, this was dealt with across commits:

  87fa7f3e98a1310e ("x86/kvm: Move context tracking where it belongs")
  0642391e2139a2c1 ("x86/kvm/vmx: Add hardirq tracing to guest enter/exit")
  9fc975e9efd03e57 ("x86/kvm/svm: Add hardirq tracing on guest enter/exit")
  3ebccdf373c21d86 ("x86/kvm/vmx: Move guest enter/exit into .noinstr.text")
  135961e0a7d555fc ("x86/kvm/svm: Move guest enter/exit into .noinstr.text")
  160457140187c5fb ("KVM: x86: Defer vtime accounting 'til after IRQ handling")
  bc908e091b326467 ("KVM: x86: Consolidate guest enter/exit logic to common helpers")

... but those fixes are specific to x86, and as the resulting logic
(while correct) is split across generic helper functions and
x86-specific helper functions, it is difficult to see that the
entry/exit accounting is balanced.

This patch adds generic helpers which architectures can use to handle
guest entry/exit consistently and correctly. The guest_{enter,exit}()
helpers are split into guest_timing_{enter,exit}() to perform vtime
accounting, and guest_context_{enter,exit}() to perform the necessary
context tracking and RCU management. The existing guest_{enter,exit}()
heleprs are left as wrappers of these.

Atop this, new guest_state_enter_irqoff() and guest_state_exit_irqoff()
helpers are added to handle the ordering of lockdep, tracing, and RCU
manageent. These are inteneded to mirror exit_to_user_mode() and
enter_from_user_mode().

Subsequent patches will migrate architectures over to the new helpers,
following a sequence:

	guest_timing_enter_irqoff();

	guest_state_enter_irqoff();
	< run the vcpu >
	guest_state_exit_irqoff();

	< take any pending IRQs >

	guest_timing_exit_irqoff();

This sequences handles all of the above correctly, and more clearly
balances the entry and exit portions, making it easier to understand.

The existing helpers are marked as deprecated, and will be removed once
all architectures have been converted.

There should be no functional change as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
---
 include/linux/kvm_host.h | 112 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 109 insertions(+), 3 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 06912d6b39d05..f11039944c08f 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -29,7 +29,9 @@
 #include <linux/refcount.h>
 #include <linux/nospec.h>
 #include <linux/notifier.h>
+#include <linux/ftrace.h>
 #include <linux/hashtable.h>
+#include <linux/instrumentation.h>
 #include <linux/interval_tree.h>
 #include <linux/rbtree.h>
 #include <linux/xarray.h>
@@ -368,8 +370,11 @@ struct kvm_vcpu {
 	u64 last_used_slot_gen;
 };
 
-/* must be called with irqs disabled */
-static __always_inline void guest_enter_irqoff(void)
+/*
+ * Start accounting time towards a guest.
+ * Must be called before entering guest context.
+ */
+static __always_inline void guest_timing_enter_irqoff(void)
 {
 	/*
 	 * This is running in ioctl context so its safe to assume that it's the
@@ -378,7 +383,18 @@ static __always_inline void guest_enter_irqoff(void)
 	instrumentation_begin();
 	vtime_account_guest_enter();
 	instrumentation_end();
+}
 
+/*
+ * Enter guest context and enter an RCU extended quiescent state.
+ *
+ * Between guest_context_enter_irqoff() and guest_context_exit_irqoff() it is
+ * unsafe to use any code which may directly or indirectly use RCU, tracing
+ * (including IRQ flag tracing), or lockdep. All code in this period must be
+ * non-instrumentable.
+ */
+static __always_inline void guest_context_enter_irqoff(void)
+{
 	/*
 	 * KVM does not hold any references to rcu protected data when it
 	 * switches CPU into a guest mode. In fact switching to a guest mode
@@ -394,16 +410,79 @@ static __always_inline void guest_enter_irqoff(void)
 	}
 }
 
-static __always_inline void guest_exit_irqoff(void)
+/*
+ * Deprecated. Architectures should move to guest_timing_enter_irqoff() and
+ * guest_state_enter_irqoff().
+ */
+static __always_inline void guest_enter_irqoff(void)
+{
+	guest_timing_enter_irqoff();
+	guest_context_enter_irqoff();
+}
+
+/**
+ * guest_state_enter_irqoff - Fixup state when entering a guest
+ *
+ * Entry to a guest will enable interrupts, but the kernel state is interrupts
+ * disabled when this is invoked. Also tell RCU about it.
+ *
+ * 1) Trace interrupts on state
+ * 2) Invoke context tracking if enabled to adjust RCU state
+ * 3) Tell lockdep that interrupts are enabled
+ *
+ * Invoked from architecture specific code before entering a guest.
+ * Must be called with interrupts disabled and the caller must be
+ * non-instrumentable.
+ * The caller has to invoke guest_timing_enter_irqoff() before this.
+ *
+ * Note: this is analogous to exit_to_user_mode().
+ */
+static __always_inline void guest_state_enter_irqoff(void)
+{
+	instrumentation_begin();
+	trace_hardirqs_on_prepare();
+	lockdep_hardirqs_on_prepare(CALLER_ADDR0);
+	instrumentation_end();
+
+	guest_context_enter_irqoff();
+	lockdep_hardirqs_on(CALLER_ADDR0);
+}
+
+/*
+ * Exit guest context and exit an RCU extended quiescent state.
+ *
+ * Between guest_context_enter_irqoff() and guest_context_exit_irqoff() it is
+ * unsafe to use any code which may directly or indirectly use RCU, tracing
+ * (including IRQ flag tracing), or lockdep. All code in this period must be
+ * non-instrumentable.
+ */
+static __always_inline void guest_context_exit_irqoff(void)
 {
 	context_tracking_guest_exit();
+}
 
+/*
+ * Stop accounting time towards a guest.
+ * Must be called after exiting guest context.
+ */
+static __always_inline void guest_timing_exit_irqoff(void)
+{
 	instrumentation_begin();
 	/* Flush the guest cputime we spent on the guest */
 	vtime_account_guest_exit();
 	instrumentation_end();
 }
 
+/*
+ * Deprecated. Architectures should move to guest_state_exit_irqoff() and
+ * guest_timing_exit_irqoff().
+ */
+static __always_inline void guest_exit_irqoff(void)
+{
+	guest_context_exit_irqoff();
+	guest_timing_exit_irqoff();
+}
+
 static inline void guest_exit(void)
 {
 	unsigned long flags;
@@ -413,6 +492,33 @@ static inline void guest_exit(void)
 	local_irq_restore(flags);
 }
 
+/**
+ * guest_state_exit_irqoff - Establish state when returning from guest mode
+ *
+ * Entry from a guest disables interrupts, but guest mode is traced as
+ * interrupts enabled. Also with NO_HZ_FULL RCU might be idle.
+ *
+ * 1) Tell lockdep that interrupts are disabled
+ * 2) Invoke context tracking if enabled to reactivate RCU
+ * 3) Trace interrupts off state
+ *
+ * Invoked from architecture specific code after exiting a guest.
+ * Must be invoked with interrupts disabled and the caller must be
+ * non-instrumentable.
+ * The caller has to invoke guest_timing_exit_irqoff() after this.
+ *
+ * Note: this is analogous to enter_from_user_mode().
+ */
+static __always_inline void guest_state_exit_irqoff(void)
+{
+	lockdep_hardirqs_off(CALLER_ADDR0);
+	guest_context_exit_irqoff();
+
+	instrumentation_begin();
+	trace_hardirqs_off_finish();
+	instrumentation_end();
+}
+
 static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
 {
 	/*
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/5] kvm/arm64: rework guest entry logic
  2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 1/5] kvm: add guest_state_{enter,exit}_irqoff() Mark Rutland
@ 2022-02-01 13:29 ` Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 3/5] kvm/x86: " Mark Rutland
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Mark Rutland @ 2022-02-01 13:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	borntraeger, bp, catalin.marinas, chenhuacai, dave.hansen,
	frederic, hca, james.morse, jmattson, joro, mark.rutland, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	pbonzini, seanjc, suzuki.poulose, svens, tglx, tsbogend,
	vkuznets, wanpengli, will

In kvm_arch_vcpu_ioctl_run() we enter an RCU extended quiescent state
(EQS) by calling guest_enter_irqoff(), and unmasked IRQs prior to
exiting the EQS by calling guest_exit(). As the IRQ entry code will not
wake RCU in this case, we may run the core IRQ code and IRQ handler
without RCU watching, leading to various potential problems.

Additionally, we do not inform lockdep or tracing that interrupts will
be enabled during guest execution, which caan lead to misleading traces
and warnings that interrupts have been enabled for overly-long periods.

This patch fixes these issues by using the new timing and context
entry/exit helpers to ensure that interrupts are handled during guest
vtime but with RCU watching, with a sequence:

	guest_timing_enter_irqoff();

	guest_state_enter_irqoff();
	< run the vcpu >
	guest_state_exit_irqoff();

	< take any pending IRQs >

	guest_timing_exit_irqoff();

Since instrumentation may make use of RCU, we must also ensure that no
instrumented code is run during the EQS. I've split out the critical
section into a new kvm_arm_enter_exit_vcpu() helper which is marked
noinstr.

Fixes: 1b3d546daf85ed2b ("arm/arm64: KVM: Properly account for guest CPU time")
Reported-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
Cc: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: James Morse <james.morse@arm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/kvm/arm.c | 51 ++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index a4a0063df456c..ecc5958e27fe2 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -797,6 +797,24 @@ static bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu, int *ret)
 			xfer_to_guest_mode_work_pending();
 }
 
+/*
+ * Actually run the vCPU, entering an RCU extended quiescent state (EQS) while
+ * the vCPU is running.
+ *
+ * This must be noinstr as instrumentation may make use of RCU, and this is not
+ * safe during the EQS.
+ */
+static int noinstr kvm_arm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
+{
+	int ret;
+
+	guest_state_enter_irqoff();
+	ret = kvm_call_hyp_ret(__kvm_vcpu_run, vcpu);
+	guest_state_exit_irqoff();
+
+	return ret;
+}
+
 /**
  * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
  * @vcpu:	The VCPU pointer
@@ -881,9 +899,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		 * Enter the guest
 		 */
 		trace_kvm_entry(*vcpu_pc(vcpu));
-		guest_enter_irqoff();
+		guest_timing_enter_irqoff();
 
-		ret = kvm_call_hyp_ret(__kvm_vcpu_run, vcpu);
+		ret = kvm_arm_vcpu_enter_exit(vcpu);
 
 		vcpu->mode = OUTSIDE_GUEST_MODE;
 		vcpu->stat.exits++;
@@ -918,26 +936,23 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		kvm_arch_vcpu_ctxsync_fp(vcpu);
 
 		/*
-		 * We may have taken a host interrupt in HYP mode (ie
-		 * while executing the guest). This interrupt is still
-		 * pending, as we haven't serviced it yet!
+		 * We must ensure that any pending interrupts are taken before
+		 * we exit guest timing so that timer ticks are accounted as
+		 * guest time. Transiently unmask interrupts so that any
+		 * pending interrupts are taken.
 		 *
-		 * We're now back in SVC mode, with interrupts
-		 * disabled.  Enabling the interrupts now will have
-		 * the effect of taking the interrupt again, in SVC
-		 * mode this time.
+		 * Per ARM DDI 0487G.b section D1.13.4, an ISB (or other
+		 * context synchronization event) is necessary to ensure that
+		 * pending interrupts are taken.
 		 */
 		local_irq_enable();
+		isb();
+		local_irq_disable();
+
+		guest_timing_exit_irqoff();
+
+		local_irq_enable();
 
-		/*
-		 * We do local_irq_enable() before calling guest_exit() so
-		 * that if a timer interrupt hits while running the guest we
-		 * account that tick as being spent in the guest.  We enable
-		 * preemption after calling guest_exit() so that if we get
-		 * preempted we make sure ticks after that is not counted as
-		 * guest time.
-		 */
-		guest_exit();
 		trace_kvm_exit(ret, kvm_vcpu_trap_get_class(vcpu), *vcpu_pc(vcpu));
 
 		/* Exit types that need handling before we can be preempted */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/5] kvm/x86: rework guest entry logic
  2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 1/5] kvm: add guest_state_{enter,exit}_irqoff() Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 2/5] kvm/arm64: rework guest entry logic Mark Rutland
@ 2022-02-01 13:29 ` Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 4/5] kvm/riscv: " Mark Rutland
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Mark Rutland @ 2022-02-01 13:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	borntraeger, bp, catalin.marinas, chenhuacai, dave.hansen,
	frederic, hca, james.morse, jmattson, joro, mark.rutland, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	pbonzini, seanjc, suzuki.poulose, svens, tglx, tsbogend,
	vkuznets, wanpengli, will

For consistency and clarity, migrate x86 over to the generic helpers for
guest timing and lockdep/RCU/tracing management, and remove the
x86-specific helpers.

Prior to this patch, the guest timing was entered in
kvm_guest_enter_irqoff() (called by svm_vcpu_enter_exit() and
svm_vcpu_enter_exit()), and was exited by the call to
vtime_account_guest_exit() within vcpu_enter_guest().

To minimize duplication and to more clearly balance entry and exit, both
entry and exit of guest timing are placed in vcpu_enter_guest(), using
the new guest_timing_{enter,exit}_irqoff() helpers. When context
tracking is used a small amount of additional time will be accounted
towards guests; tick-based accounting is unnaffected as IRQs are
disabled at this point and not enabled until after the return from the
guest.

This also corrects (benign) mis-balanced context tracking accounting
introduced in commits:

  ae95f566b3d22ade ("KVM: X86: TSCDEADLINE MSR emulation fastpath")
  26efe2fd92e50822 ("KVM: VMX: Handle preemption timer fastpath")

Where KVM can enter a guest multiple times, calling vtime_guest_enter()
without a corresponding call to vtime_account_guest_exit(), and with
vtime_account_system() called when vtime_account_guest() should be used.
As account_system_time() checks PF_VCPU and calls account_guest_time(),
this doesn't result in any functional problem, but is unnecessarily
confusing.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jim Mattson <jmattson@google.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/svm/svm.c |  4 ++--
 arch/x86/kvm/vmx/vmx.c |  4 ++--
 arch/x86/kvm/x86.c     |  4 +++-
 arch/x86/kvm/x86.h     | 45 ------------------------------------------
 4 files changed, 7 insertions(+), 50 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 6d97629655e3d..d988fddd143f8 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3615,7 +3615,7 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
 	struct vcpu_svm *svm = to_svm(vcpu);
 	unsigned long vmcb_pa = svm->current_vmcb->pa;
 
-	kvm_guest_enter_irqoff();
+	guest_state_enter_irqoff();
 
 	if (sev_es_guest(vcpu->kvm)) {
 		__svm_sev_es_vcpu_run(vmcb_pa);
@@ -3635,7 +3635,7 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
 		vmload(__sme_page_pa(sd->save_area));
 	}
 
-	kvm_guest_exit_irqoff();
+	guest_state_exit_irqoff();
 }
 
 static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index aca3ae2a02f34..950ef25ec8a50 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6754,7 +6754,7 @@ static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
 static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
 					struct vcpu_vmx *vmx)
 {
-	kvm_guest_enter_irqoff();
+	guest_state_enter_irqoff();
 
 	/* L1D Flush includes CPU buffer clear to mitigate MDS */
 	if (static_branch_unlikely(&vmx_l1d_should_flush))
@@ -6770,7 +6770,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
 
 	vcpu->arch.cr2 = native_read_cr2();
 
-	kvm_guest_exit_irqoff();
+	guest_state_exit_irqoff();
 }
 
 static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 74b53a16f38a7..8e8c8e53880c0 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10041,6 +10041,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 		set_debugreg(0, 7);
 	}
 
+	guest_timing_enter_irqoff();
+
 	for (;;) {
 		/*
 		 * Assert that vCPU vs. VM APICv state is consistent.  An APICv
@@ -10125,7 +10127,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 	 * of accounting via context tracking, but the loss of accuracy is
 	 * acceptable for all known use cases.
 	 */
-	vtime_account_guest_exit();
+	guest_timing_exit_irqoff();
 
 	if (lapic_in_kernel(vcpu)) {
 		s64 delta = vcpu->arch.apic->lapic_timer.advance_expire_delta;
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 635b75f9e1454..767ec7f995160 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -10,51 +10,6 @@
 
 void kvm_spurious_fault(void);
 
-static __always_inline void kvm_guest_enter_irqoff(void)
-{
-	/*
-	 * VMENTER enables interrupts (host state), but the kernel state is
-	 * interrupts disabled when this is invoked. Also tell RCU about
-	 * it. This is the same logic as for exit_to_user_mode().
-	 *
-	 * This ensures that e.g. latency analysis on the host observes
-	 * guest mode as interrupt enabled.
-	 *
-	 * guest_enter_irqoff() informs context tracking about the
-	 * transition to guest mode and if enabled adjusts RCU state
-	 * accordingly.
-	 */
-	instrumentation_begin();
-	trace_hardirqs_on_prepare();
-	lockdep_hardirqs_on_prepare(CALLER_ADDR0);
-	instrumentation_end();
-
-	guest_enter_irqoff();
-	lockdep_hardirqs_on(CALLER_ADDR0);
-}
-
-static __always_inline void kvm_guest_exit_irqoff(void)
-{
-	/*
-	 * VMEXIT disables interrupts (host state), but tracing and lockdep
-	 * have them in state 'on' as recorded before entering guest mode.
-	 * Same as enter_from_user_mode().
-	 *
-	 * context_tracking_guest_exit() restores host context and reinstates
-	 * RCU if enabled and required.
-	 *
-	 * This needs to be done immediately after VM-Exit, before any code
-	 * that might contain tracepoints or call out to the greater world,
-	 * e.g. before x86_spec_ctrl_restore_host().
-	 */
-	lockdep_hardirqs_off(CALLER_ADDR0);
-	context_tracking_guest_exit();
-
-	instrumentation_begin();
-	trace_hardirqs_off_finish();
-	instrumentation_end();
-}
-
 #define KVM_NESTED_VMENTER_CONSISTENCY_CHECK(consistency_check)		\
 ({									\
 	bool failed = (consistency_check);				\
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 4/5] kvm/riscv: rework guest entry logic
  2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
                   ` (2 preceding siblings ...)
  2022-02-01 13:29 ` [PATCH v3 3/5] kvm/x86: " Mark Rutland
@ 2022-02-01 13:29 ` Mark Rutland
  2022-02-01 13:29 ` [PATCH v3 5/5] kvm/mips: " Mark Rutland
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Mark Rutland @ 2022-02-01 13:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	borntraeger, bp, catalin.marinas, chenhuacai, dave.hansen,
	frederic, hca, james.morse, jmattson, joro, mark.rutland, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	pbonzini, seanjc, suzuki.poulose, svens, tglx, tsbogend,
	vkuznets, wanpengli, will

In kvm_arch_vcpu_ioctl_run() we enter an RCU extended quiescent state
(EQS) by calling guest_enter_irqoff(), and unmask IRQs prior to exiting
the EQS by calling guest_exit(). As the IRQ entry code will not wake RCU
in this case, we may run the core IRQ code and IRQ handler without RCU
watching, leading to various potential problems.

Additionally, we do not inform lockdep or tracing that interrupts will
be enabled during guest execution, which caan lead to misleading traces
and warnings that interrupts have been enabled for overly-long periods.

This patch fixes these issues by using the new timing and context
entry/exit helpers to ensure that interrupts are handled during guest
vtime but with RCU watching, with a sequence:

	guest_timing_enter_irqoff();

	guest_state_enter_irqoff();
	< run the vcpu >
	guest_state_exit_irqoff();

	< take any pending IRQs >

	guest_timing_exit_irqoff();

Since instrumentation may make use of RCU, we must also ensure that no
instrumented code is run during the EQS. I've split out the critical
section into a new kvm_riscv_enter_exit_vcpu() helper which is marked
noinstr.

Fixes: 99cdc6c18c2d815e ("RISC-V: Add initial skeletal KVM support")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Anup Patel <anup@brainfault.org>
Cc: Atish Patra <atishp@atishpatra.org>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
---
 arch/riscv/kvm/vcpu.c | 44 ++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index 0c5239e057215..f64f620573787 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -699,6 +699,20 @@ static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu)
 	csr_write(CSR_HVIP, csr->hvip);
 }
 
+/*
+ * Actually run the vCPU, entering an RCU extended quiescent state (EQS) while
+ * the vCPU is running.
+ *
+ * This must be noinstr as instrumentation may make use of RCU, and this is not
+ * safe during the EQS.
+ */
+static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu)
+{
+	guest_state_enter_irqoff();
+	__kvm_riscv_switch_to(&vcpu->arch);
+	guest_state_exit_irqoff();
+}
+
 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 {
 	int ret;
@@ -790,9 +804,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 			continue;
 		}
 
-		guest_enter_irqoff();
+		guest_timing_enter_irqoff();
 
-		__kvm_riscv_switch_to(&vcpu->arch);
+		kvm_riscv_vcpu_enter_exit(vcpu);
 
 		vcpu->mode = OUTSIDE_GUEST_MODE;
 		vcpu->stat.exits++;
@@ -812,25 +826,21 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		kvm_riscv_vcpu_sync_interrupts(vcpu);
 
 		/*
-		 * We may have taken a host interrupt in VS/VU-mode (i.e.
-		 * while executing the guest). This interrupt is still
-		 * pending, as we haven't serviced it yet!
+		 * We must ensure that any pending interrupts are taken before
+		 * we exit guest timing so that timer ticks are accounted as
+		 * guest time. Transiently unmask interrupts so that any
+		 * pending interrupts are taken.
 		 *
-		 * We're now back in HS-mode with interrupts disabled
-		 * so enabling the interrupts now will have the effect
-		 * of taking the interrupt again, in HS-mode this time.
+		 * There's no barrier which ensures that pending interrupts are
+		 * recognised, so we just hope that the CPU takes any pending
+		 * interrupts between the enable and disable.
 		 */
 		local_irq_enable();
+		local_irq_disable();
 
-		/*
-		 * We do local_irq_enable() before calling guest_exit() so
-		 * that if a timer interrupt hits while running the guest
-		 * we account that tick as being spent in the guest. We
-		 * enable preemption after calling guest_exit() so that if
-		 * we get preempted we make sure ticks after that is not
-		 * counted as guest time.
-		 */
-		guest_exit();
+		guest_timing_exit_irqoff();
+
+		local_irq_enable();
 
 		preempt_enable();
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 5/5] kvm/mips: rework guest entry logic
  2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
                   ` (3 preceding siblings ...)
  2022-02-01 13:29 ` [PATCH v3 4/5] kvm/riscv: " Mark Rutland
@ 2022-02-01 13:29 ` Mark Rutland
  2022-02-01 14:02 ` [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Christian Borntraeger
  2022-02-01 15:59 ` Paolo Bonzini
  6 siblings, 0 replies; 12+ messages in thread
From: Mark Rutland @ 2022-02-01 13:29 UTC (permalink / raw)
  To: linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	borntraeger, bp, catalin.marinas, chenhuacai, dave.hansen,
	frederic, hca, james.morse, jmattson, joro, mark.rutland, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	pbonzini, seanjc, suzuki.poulose, svens, tglx, tsbogend,
	vkuznets, wanpengli, will

In kvm_arch_vcpu_ioctl_run() we use guest_enter_irqoff() and
guest_exit_irqoff() directly, with interrupts masked between these. As
we don't handle any timer ticks during this window, we will not account
time spent within the guest as guest time, which is unfortunate.

Additionally, we do not inform lockdep or tracing that interrupts will
be enabled during guest execution, which caan lead to misleading traces
and warnings that interrupts have been enabled for overly-long periods.

This patch fixes these issues by using the new timing and context
entry/exit helpers to ensure that interrupts are handled during guest
vtime but with RCU watching, with a sequence:

	guest_timing_enter_irqoff();

	guest_state_enter_irqoff();
	< run the vcpu >
	guest_state_exit_irqoff();

	< take any pending IRQs >

	guest_timing_exit_irqoff();

In addition, as guest exits during the "run the vcpu" step are handled
by kvm_mips_handle_exit(), a wrapper function is added which ensures
that such exists are handled with a sequence:

	guest_state_exit_irqoff();
	< handle the exit >
	guest_state_enter_irqoff();

This means that exits which stop the vCPU running will have a redundant
guest_state_enter_irqoff() .. guest_state_exit_irqoff() sequence, which
can be addressed with future rework.

Since instrumentation may make use of RCU, we must also ensure that no
instrumented code is run during the EQS. I've split out the critical
section into a new kvm_mips_enter_exit_vcpu() helper which is marked
noinstr.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/kvm/mips.c | 50 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index e59cb6246f763..a25e0b73ee704 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -414,6 +414,24 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 	return -ENOIOCTLCMD;
 }
 
+/*
+ * Actually run the vCPU, entering an RCU extended quiescent state (EQS) while
+ * the vCPU is running.
+ *
+ * This must be noinstr as instrumentation may make use of RCU, and this is not
+ * safe during the EQS.
+ */
+static int noinstr kvm_mips_vcpu_enter_exit(struct kvm_vcpu *vcpu)
+{
+	int ret;
+
+	guest_state_enter_irqoff();
+	ret = kvm_mips_callbacks->vcpu_run(vcpu);
+	guest_state_exit_irqoff();
+
+	return ret;
+}
+
 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 {
 	int r = -EINTR;
@@ -434,7 +452,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 	lose_fpu(1);
 
 	local_irq_disable();
-	guest_enter_irqoff();
+	guest_timing_enter_irqoff();
 	trace_kvm_enter(vcpu);
 
 	/*
@@ -445,10 +463,23 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 	 */
 	smp_store_mb(vcpu->mode, IN_GUEST_MODE);
 
-	r = kvm_mips_callbacks->vcpu_run(vcpu);
+	r = kvm_mips_vcpu_enter_exit(vcpu);
+
+	/*
+	 * We must ensure that any pending interrupts are taken before
+	 * we exit guest timing so that timer ticks are accounted as
+	 * guest time. Transiently unmask interrupts so that any
+	 * pending interrupts are taken.
+	 *
+	 * TODO: is there a barrier which ensures that pending interrupts are
+	 * recognised? Currently this just hopes that the CPU takes any pending
+	 * interrupts between the enable and disable.
+	 */
+	local_irq_enable();
+	local_irq_disable();
 
 	trace_kvm_out(vcpu);
-	guest_exit_irqoff();
+	guest_timing_exit_irqoff();
 	local_irq_enable();
 
 out:
@@ -1168,7 +1199,7 @@ static void kvm_mips_set_c0_status(void)
 /*
  * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
  */
-int kvm_mips_handle_exit(struct kvm_vcpu *vcpu)
+static int __kvm_mips_handle_exit(struct kvm_vcpu *vcpu)
 {
 	struct kvm_run *run = vcpu->run;
 	u32 cause = vcpu->arch.host_cp0_cause;
@@ -1357,6 +1388,17 @@ int kvm_mips_handle_exit(struct kvm_vcpu *vcpu)
 	return ret;
 }
 
+int noinstr kvm_mips_handle_exit(struct kvm_vcpu *vcpu)
+{
+	int ret;
+
+	guest_state_exit_irqoff();
+	ret = __kvm_mips_handle_exit(vcpu);
+	guest_state_enter_irqoff();
+
+	return ret;
+}
+
 /* Enable FPU for guest and restore context */
 void kvm_own_fpu(struct kvm_vcpu *vcpu)
 {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs
  2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
                   ` (4 preceding siblings ...)
  2022-02-01 13:29 ` [PATCH v3 5/5] kvm/mips: " Mark Rutland
@ 2022-02-01 14:02 ` Christian Borntraeger
  2022-02-01 15:59 ` Paolo Bonzini
  6 siblings, 0 replies; 12+ messages in thread
From: Christian Borntraeger @ 2022-02-01 14:02 UTC (permalink / raw)
  To: Mark Rutland, linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	bp, catalin.marinas, chenhuacai, dave.hansen, frederic, hca,
	james.morse, jmattson, joro, maz, mingo, mpe, nsaenzju, palmer,
	paulmck, paulus, paul.walmsley, pbonzini, seanjc, suzuki.poulose,
	svens, tglx, tsbogend, vkuznets, wanpengli, will



Am 01.02.22 um 14:29 schrieb Mark Rutland:
> Several architectures have latent bugs around guest entry/exit,
> including:

Thanks for looking into this.

> 
> 1) Enabling interrupts during an RCU EQS, allowing interrupt handlers to
>     run without RCU watching.
> 
> 2) Using (potentially) instrumented code between guest_enter() and
>     guest_exit(), allowing instrumentation handlers to run without RCU
>     watching.
> 
> 3) Not informing lockdep and tracing about interrupt masking, or
>     informing in an incorrect order (e.g. relative to entering/exiting an
>     RCU EQS).
> 
> 4) Unbalanced entry/exit accounting in some cases (which may or may not
>     result in functional problems).
> 
> Overall, the architectures affected are:
> 
>    arm64, mips, powerpc, riscv, s390, x86
> 
> This series reworks the common code to make handling these issues
> earier, and for the following architectures fixes those issues by
> conversion to new helper functions:
> 
>    arm64, mips, riscv, x86
> 
> The core, arm64, and x86 patches have reviews from the relevant
> maintainers, and I think those are good-to-go. I have not yet had
> acks/reviews for the mips and riscv patches. I'm fairly certain the
> riscv patch is correct by virtue of it being so simple, and I'm
> relatively confident that the mips patch is correct (though I may have
> missed additional issues), but I have no way of testing either so I've
> placed them at the end of the series where they can easily be dropped if
> necessary.
> 
> This series does NOT fix the following architectures, which will need
> more substantial changes to architecture-specific entry logic and/or
> sequencing:
> 
>    powerpc, s390

Right, s390 is more complicated as we need to modify the page fault handling.
For the time being we should be as bad/good as before with the deprecated old
guest_enter/exit_irqoff. I will test this to be sure.


> 
> ... and I assume it would be preferable to fix the common code and
> simple cases now, such that those can be addressed in subsequent
> follow-ups.
> 
> Since v1 [1]:
> * Add arch_in_rcu_eqs()
> * Convert s390
> * Rename exit_to_guest_mode() -> guest_state_enter_irqoff()
> * Rename enter_from_guest_mode() -> guest_state_exit_irqoff()
> * Various commit message cleanups
> 
> Since v2 [2]:
> * Rebase to v5.17-rc2
> * Fixup mips exit handling
> * Drop arch_in_rcu_eqs() & s390 patches
> 
> I've pushed the series (based on v5.17-rc2) to my kvm/entry-rework branch:
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/entry-rework
>    git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git kvm/entry-rework
> 
> This version of the series is tagged as kvm-entry-rework-20220201.
> 
> [1] https://lore.kernel.org/r/20220111153539.2532246-1-mark.rutland@arm.com/
> [2] https://lore.kernel.org/r/20220119105854.3160683-1-mark.rutland@arm.com/
> 
> Thanks,
> 
> 
> Mark Rutland (5):
>    kvm: add guest_state_{enter,exit}_irqoff()
>    kvm/arm64: rework guest entry logic
>    kvm/x86: rework guest entry logic
>    kvm/riscv: rework guest entry logic
>    kvm/mips: rework guest entry logic
> 
>   arch/arm64/kvm/arm.c     |  51 +++++++++++-------
>   arch/mips/kvm/mips.c     |  50 +++++++++++++++--
>   arch/riscv/kvm/vcpu.c    |  44 +++++++++------
>   arch/x86/kvm/svm/svm.c   |   4 +-
>   arch/x86/kvm/vmx/vmx.c   |   4 +-
>   arch/x86/kvm/x86.c       |   4 +-
>   arch/x86/kvm/x86.h       |  45 ----------------
>   include/linux/kvm_host.h | 112 +++++++++++++++++++++++++++++++++++++--
>   8 files changed, 222 insertions(+), 92 deletions(-)
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs
  2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
                   ` (5 preceding siblings ...)
  2022-02-01 14:02 ` [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Christian Borntraeger
@ 2022-02-01 15:59 ` Paolo Bonzini
  2022-02-01 16:22   ` Marc Zyngier
  2022-02-01 16:22   ` Mark Rutland
  6 siblings, 2 replies; 12+ messages in thread
From: Paolo Bonzini @ 2022-02-01 15:59 UTC (permalink / raw)
  To: Mark Rutland, linux-kernel
  Cc: aleksandar.qemu.devel, alexandru.elisei, anup, aou, atishp, benh,
	borntraeger, bp, catalin.marinas, chenhuacai, dave.hansen,
	frederic, hca, james.morse, jmattson, joro, maz, mingo, mpe,
	nsaenzju, palmer, paulmck, paulus, paul.walmsley, seanjc,
	suzuki.poulose, svens, tglx, tsbogend, vkuznets, wanpengli, will

On 2/1/22 14:29, Mark Rutland wrote:
> I've pushed the series (based on v5.17-rc2) to my kvm/entry-rework branch:
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/entry-rework
>    git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git kvm/entry-rework

Thanks!  I cherry-picked the basic, x86 and mips patches to kvm.git's 
master branch (I did not use your branch in order to leave arm64 and 
riscv to the respective maintainers).

Paolo

> This version of the series is tagged as kvm-entry-rework-20220201.
> 
> [1] https://lore.kernel.org/r/20220111153539.2532246-1-mark.rutland@arm.com/
> [2] https://lore.kernel.org/r/20220119105854.3160683-1-mark.rutland@arm.com/
> 
> Thanks,
> 
> 
> Mark Rutland (5):
>    kvm: add guest_state_{enter,exit}_irqoff()
>    kvm/arm64: rework guest entry logic
>    kvm/x86: rework guest entry logic
>    kvm/riscv: rework guest entry logic
>    kvm/mips: rework guest entry logic
> 
>   arch/arm64/kvm/arm.c     |  51 +++++++++++-------
>   arch/mips/kvm/mips.c     |  50 +++++++++++++++--
>   arch/riscv/kvm/vcpu.c    |  44 +++++++++------
>   arch/x86/kvm/svm/svm.c   |   4 +-
>   arch/x86/kvm/vmx/vmx.c   |   4 +-
>   arch/x86/kvm/x86.c       |   4 +-
>   arch/x86/kvm/x86.h       |  45 ----------------
>   include/linux/kvm_host.h | 112 +++++++++++++++++++++++++++++++++++++--
>   8 files changed, 222 insertions(+), 92 deletions(-)
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs
  2022-02-01 15:59 ` Paolo Bonzini
@ 2022-02-01 16:22   ` Marc Zyngier
  2022-02-01 16:22   ` Mark Rutland
  1 sibling, 0 replies; 12+ messages in thread
From: Marc Zyngier @ 2022-02-01 16:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Mark Rutland, linux-kernel, aleksandar.qemu.devel,
	alexandru.elisei, anup, aou, atishp, benh, borntraeger, bp,
	catalin.marinas, chenhuacai, dave.hansen, frederic, hca,
	james.morse, jmattson, joro, mingo, mpe, nsaenzju, palmer,
	paulmck, paulus, paul.walmsley, seanjc, suzuki.poulose, svens,
	tglx, tsbogend, vkuznets, wanpengli, will

On Tue, 01 Feb 2022 15:59:47 +0000,
Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> On 2/1/22 14:29, Mark Rutland wrote:
> > I've pushed the series (based on v5.17-rc2) to my kvm/entry-rework branch:
> > 
> >    https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/entry-rework
> >    git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git kvm/entry-rework
> 
> Thanks!  I cherry-picked the basic, x86 and mips patches to kvm.git's
> master branch (I did not use your branch in order to leave arm64 and
> riscv to the respective maintainers).

How do you want to play this one? I was expecting a stable base
(containing only the initial patch) on top of a common tag (like
-rc1).

Or do you expect arm64 and riscv to have their own copy of patch #1?

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs
  2022-02-01 15:59 ` Paolo Bonzini
  2022-02-01 16:22   ` Marc Zyngier
@ 2022-02-01 16:22   ` Mark Rutland
  2022-02-01 17:10     ` Paolo Bonzini
  1 sibling, 1 reply; 12+ messages in thread
From: Mark Rutland @ 2022-02-01 16:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: linux-kernel, aleksandar.qemu.devel, alexandru.elisei, anup, aou,
	atishp, benh, borntraeger, bp, catalin.marinas, chenhuacai,
	dave.hansen, frederic, hca, james.morse, jmattson, joro, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	seanjc, suzuki.poulose, svens, tglx, tsbogend, vkuznets,
	wanpengli, will

On Tue, Feb 01, 2022 at 04:59:47PM +0100, Paolo Bonzini wrote:
> On 2/1/22 14:29, Mark Rutland wrote:
> > I've pushed the series (based on v5.17-rc2) to my kvm/entry-rework branch:
> > 
> >    https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/entry-rework
> >    git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git kvm/entry-rework
> 
> Thanks!  I cherry-picked the basic, x86 and mips patches to kvm.git's master
> branch (I did not use your branch in order to leave arm64 and riscv to the
> respective maintainers).

Since everything's dependent upon that core patch, IIUC that's going to make it
a pain for them to queue things.

How are you expecting the arm64 and riscv maintainers to queue things? Queue
their own copies of that core patch?

Thanks,
Mark.

> Paolo
> 
> > This version of the series is tagged as kvm-entry-rework-20220201.
> > 
> > [1] https://lore.kernel.org/r/20220111153539.2532246-1-mark.rutland@arm.com/
> > [2] https://lore.kernel.org/r/20220119105854.3160683-1-mark.rutland@arm.com/
> > 
> > Thanks,
> > 
> > 
> > Mark Rutland (5):
> >    kvm: add guest_state_{enter,exit}_irqoff()
> >    kvm/arm64: rework guest entry logic
> >    kvm/x86: rework guest entry logic
> >    kvm/riscv: rework guest entry logic
> >    kvm/mips: rework guest entry logic
> > 
> >   arch/arm64/kvm/arm.c     |  51 +++++++++++-------
> >   arch/mips/kvm/mips.c     |  50 +++++++++++++++--
> >   arch/riscv/kvm/vcpu.c    |  44 +++++++++------
> >   arch/x86/kvm/svm/svm.c   |   4 +-
> >   arch/x86/kvm/vmx/vmx.c   |   4 +-
> >   arch/x86/kvm/x86.c       |   4 +-
> >   arch/x86/kvm/x86.h       |  45 ----------------
> >   include/linux/kvm_host.h | 112 +++++++++++++++++++++++++++++++++++++--
> >   8 files changed, 222 insertions(+), 92 deletions(-)
> > 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs
  2022-02-01 16:22   ` Mark Rutland
@ 2022-02-01 17:10     ` Paolo Bonzini
  2022-02-01 17:48       ` Marc Zyngier
  0 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2022-02-01 17:10 UTC (permalink / raw)
  To: Mark Rutland
  Cc: linux-kernel, aleksandar.qemu.devel, alexandru.elisei, anup, aou,
	atishp, benh, borntraeger, bp, catalin.marinas, chenhuacai,
	dave.hansen, frederic, hca, james.morse, jmattson, joro, maz,
	mingo, mpe, nsaenzju, palmer, paulmck, paulus, paul.walmsley,
	seanjc, suzuki.poulose, svens, tglx, tsbogend, vkuznets,
	wanpengli, will

On 2/1/22 17:22, Mark Rutland wrote:
> On Tue, Feb 01, 2022 at 04:59:47PM +0100, Paolo Bonzini wrote:
>> On 2/1/22 14:29, Mark Rutland wrote:
>>> I've pushed the series (based on v5.17-rc2) to my kvm/entry-rework branch:
>>>
>>>     https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/entry-rework
>>>     git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git kvm/entry-rework
>>
>> Thanks!  I cherry-picked the basic, x86 and mips patches to kvm.git's master
>> branch (I did not use your branch in order to leave arm64 and riscv to the
>> respective maintainers).
> 
> Since everything's dependent upon that core patch, IIUC that's going to make it
> a pain for them to queue things.
> 
> How are you expecting the arm64 and riscv maintainers to queue things? Queue
> their own copies of that core patch?

The kvm.git master branch has a stable commit id, so the KVM/ARM and 
KVM/RISCV maintainers can just base their pull request to me on it. 
Alternatively, if they prefer it that way, I can get it quickly to Linus.

Paolo


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs
  2022-02-01 17:10     ` Paolo Bonzini
@ 2022-02-01 17:48       ` Marc Zyngier
  0 siblings, 0 replies; 12+ messages in thread
From: Marc Zyngier @ 2022-02-01 17:48 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Mark Rutland, linux-kernel, aleksandar.qemu.devel,
	alexandru.elisei, anup, aou, atishp, benh, borntraeger, bp,
	catalin.marinas, chenhuacai, dave.hansen, frederic, hca,
	james.morse, jmattson, joro, mingo, mpe, nsaenzju, palmer,
	paulmck, paulus, paul.walmsley, seanjc, suzuki.poulose, svens,
	tglx, tsbogend, vkuznets, wanpengli, will

On Tue, 01 Feb 2022 17:10:35 +0000,
Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> On 2/1/22 17:22, Mark Rutland wrote:
> > On Tue, Feb 01, 2022 at 04:59:47PM +0100, Paolo Bonzini wrote:
> >> On 2/1/22 14:29, Mark Rutland wrote:
> >>> I've pushed the series (based on v5.17-rc2) to my kvm/entry-rework branch:
> >>> 
> >>>     https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/entry-rework
> >>>     git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git kvm/entry-rework
> >> 
> >> Thanks!  I cherry-picked the basic, x86 and mips patches to kvm.git's master
> >> branch (I did not use your branch in order to leave arm64 and riscv to the
> >> respective maintainers).
> > 
> > Since everything's dependent upon that core patch, IIUC that's going to make it
> > a pain for them to queue things.
> > 
> > How are you expecting the arm64 and riscv maintainers to queue things? Queue
> > their own copies of that core patch?
> 
> The kvm.git master branch has a stable commit id, so the KVM/ARM and
> KVM/RISCV maintainers can just base their pull request to me on
> it. Alternatively, if they prefer it that way, I can get it quickly to
> Linus.

In which case, please add the arm64 patch to the mix. I'm not rebasing
my current queue.

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-02-01 17:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 13:29 [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
2022-02-01 13:29 ` [PATCH v3 1/5] kvm: add guest_state_{enter,exit}_irqoff() Mark Rutland
2022-02-01 13:29 ` [PATCH v3 2/5] kvm/arm64: rework guest entry logic Mark Rutland
2022-02-01 13:29 ` [PATCH v3 3/5] kvm/x86: " Mark Rutland
2022-02-01 13:29 ` [PATCH v3 4/5] kvm/riscv: " Mark Rutland
2022-02-01 13:29 ` [PATCH v3 5/5] kvm/mips: " Mark Rutland
2022-02-01 14:02 ` [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs Christian Borntraeger
2022-02-01 15:59 ` Paolo Bonzini
2022-02-01 16:22   ` Marc Zyngier
2022-02-01 16:22   ` Mark Rutland
2022-02-01 17:10     ` Paolo Bonzini
2022-02-01 17:48       ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).