linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs
@ 2025-07-08  9:27 Andrew Donnellan
  2025-07-08  9:27 ` [PATCH 1/2] entry: Add arch_in_rcu_eqs() Andrew Donnellan
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Andrew Donnellan @ 2025-07-08  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: Mark Rutland, Christian Borntraeger, Frederic Weisbecker,
	Heiko Carstens, Janosch Frank, Paolo Bonzini, Paul E. McKenney,
	Sven Schnelle, Vasily Gorbik, Claudio Imbrenda, Alexander Gordeev,
	Andy Lutomirski, Peter Zijlstra, Thomas Gleixner

In [0], the guest_{enter,exit}_irqoff() helpers were deprecated, in favour
of guest_timing_{enter,exit}_irqoff() and
guest_context_{enter,exit}_irqoff(). This was to fix a number of latent
guest entry/exit bugs, relating to the enabling of interrupts during an
RCU extended quiescent state, instrumentation code, and correct handling
of lockdep and tracing.

However, while arm64, mips, riscv and x86 have been migrated to the new
helpers, s390 hasn't been. There was an initial attempt at [1] to do this,
but that didn't work for reasons discussed at [2].

Since then, Claudio Imbrenda has reworked much of the interrupt handling.
Moving interrupt handling into vcpu_post_run() avoids the issues in [2],
so we can now move to the new helpers.

I've rebased Mark's patches from [1]. kvm-unit-tests, the kvm selftests,
and IBM's internal test suites pass under debug_defconfig.

These patches do introduce some overhead - in my testing, a few of the
tests in the kvm-unit-tests exittime test suite appear 6-11% slower, but
some noticeable overhead may be unavoidable (we introduce a new function
call and the irq entry/exit paths change a bit).

[0] https://lore.kernel.org/lkml/20220201132926.3301912-1-mark.rutland@arm.com/
[1] https://lore.kernel.org/all/20220119105854.3160683-7-mark.rutland@arm.com/
[2] https://lore.kernel.org/all/a4a26805-3a56-d264-0a7e-60bed1ada9f3@linux.ibm.com/
[3] https://lore.kernel.org/all/20241022120601.167009-1-imbrenda@linux.ibm.com/

Mark Rutland (2):
  entry: Add arch_in_rcu_eqs()
  KVM: s390: Rework guest entry logic

 arch/s390/include/asm/entry-common.h | 10 ++++++
 arch/s390/include/asm/kvm_host.h     |  3 ++
 arch/s390/kvm/kvm-s390.c             | 51 +++++++++++++++++++++-------
 arch/s390/kvm/vsie.c                 | 17 ++++------
 include/linux/entry-common.h         | 16 +++++++++
 kernel/entry/common.c                |  3 +-
 6 files changed, 77 insertions(+), 23 deletions(-)

-- 
2.50.0

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

* [PATCH 1/2] entry: Add arch_in_rcu_eqs()
  2025-07-08  9:27 [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Andrew Donnellan
@ 2025-07-08  9:27 ` Andrew Donnellan
  2025-07-11 13:26   ` Peter Zijlstra
  2025-07-08  9:27 ` [PATCH 2/2] KVM: s390: Rework guest entry logic Andrew Donnellan
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Andrew Donnellan @ 2025-07-08  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: Mark Rutland, Christian Borntraeger, Frederic Weisbecker,
	Heiko Carstens, Janosch Frank, Paolo Bonzini, Paul E. McKenney,
	Sven Schnelle, Vasily Gorbik, Claudio Imbrenda, Alexander Gordeev,
	Andy Lutomirski, Peter Zijlstra, Thomas Gleixner

From: Mark Rutland <mark.rutland@arm.com>

All architectures have an interruptible RCU extended quiescent state
(EQS) as part of their idle sequences, where interrupts can occur
without RCU watching. Entry code must account for this and wake RCU as
necessary; the common entry code deals with this in irqentry_enter() by
treating any interrupt from an idle thread as potentially having
occurred within an EQS and waking RCU for the duration of the interrupt
via rcu_irq_enter() .. rcu_irq_exit().

Some architectures may have other interruptible EQSs which require
similar treatment. For example, on s390 it is necessary to enable
interrupts around guest entry in the middle of a period where core KVM
code has entered an EQS.

So that architectures can wake RCU in these cases, this patch adds a
new arch_in_rcu_eqs() hook to the common entry code which is checked in
addition to the existing is_idle_thread() check, with RCU woken if
either returns true. A default implementation is provided which always
returns false, which suffices for most architectures.

As no architectures currently implement arch_in_rcu_eqs(), there should
be no functional change as a result of this patch alone. A subsequent
patch will add an s390 implementation to fix a latent bug with missing
RCU wakeups.

[ajd@linux.ibm.com: rebase, fix commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
---
 include/linux/entry-common.h | 16 ++++++++++++++++
 kernel/entry/common.c        |  3 ++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index f94f3fdf15fc..3bf99cbad8a3 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -86,6 +86,22 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs);
 static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) {}
 #endif
 
+/**
+ * arch_in_rcu_eqs - Architecture specific check for RCU extended quiescent
+ * states.
+ *
+ * Returns: true if the CPU is potentially in an RCU EQS, false otherwise.
+ *
+ * Architectures only need to define this if threads other than the idle thread
+ * may have an interruptible EQS. This does not need to handle idle threads. It
+ * is safe to over-estimate at the cost of redundant RCU management work.
+ *
+ * Invoked from irqentry_enter()
+ */
+#ifndef arch_in_rcu_eqs
+static __always_inline bool arch_in_rcu_eqs(void) { return false; }
+#endif
+
 /**
  * enter_from_user_mode - Establish state when coming from user mode
  *
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index a8dd1f27417c..eb52d38e8099 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -220,7 +220,8 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)
 	 * TINY_RCU does not support EQS, so let the compiler eliminate
 	 * this part when enabled.
 	 */
-	if (!IS_ENABLED(CONFIG_TINY_RCU) && is_idle_task(current)) {
+	if (!IS_ENABLED(CONFIG_TINY_RCU) &&
+	    (is_idle_task(current) || arch_in_rcu_eqs())) {
 		/*
 		 * If RCU is not watching then the same careful
 		 * sequence vs. lockdep and tracing is required
-- 
2.50.0


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

* [PATCH 2/2] KVM: s390: Rework guest entry logic
  2025-07-08  9:27 [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Andrew Donnellan
  2025-07-08  9:27 ` [PATCH 1/2] entry: Add arch_in_rcu_eqs() Andrew Donnellan
@ 2025-07-08  9:27 ` Andrew Donnellan
  2025-07-09  9:22 ` [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Janosch Frank
  2025-07-16 11:05 ` Mark Rutland
  3 siblings, 0 replies; 6+ messages in thread
From: Andrew Donnellan @ 2025-07-08  9:27 UTC (permalink / raw)
  To: linux-kernel, linux-s390, kvm
  Cc: Mark Rutland, Christian Borntraeger, Frederic Weisbecker,
	Heiko Carstens, Janosch Frank, Paolo Bonzini, Paul E. McKenney,
	Sven Schnelle, Vasily Gorbik, Claudio Imbrenda, Alexander Gordeev,
	Andy Lutomirski, Peter Zijlstra, Thomas Gleixner

From: Mark Rutland <mark.rutland@arm.com>

In __vcpu_run() and do_vsie_run(), we enter an RCU extended quiescent
state (EQS) by calling guest_enter_irqoff(), which lasts until
__vcpu_run() calls guest_exit_irqoff(). However, between the two we
enable interrupts and may handle interrupts during the EQS. 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.

It is necessary to unmask (host) interrupts around entering the guest,
as entering the guest via SIE will not automatically unmask these. When
a host interrupt is taken from a guest, it is taken via its regular
host IRQ handler rather than being treated as a direct exit from SIE.
Due to this, we cannot simply mask interrupts around guest entry, and
must handle interrupts during this window, waking RCU as required.

Additionally, between guest_enter_irqoff() and guest_exit_irqoff(), we
use local_irq_enable() and local_irq_disable() to unmask interrupts,
violating the ordering requirements for RCU/lockdep/tracing around
entry/exit sequences. Further, since this occurs in an instrumentable
function, it's possible that instrumented code runs during this window,
with potential usage of RCU, etc.

To fix the RCU wakeup problem, an s390 implementation of
arch_in_rcu_eqs() is added which checks for PF_VCPU in current->flags.
PF_VCPU is set/cleared by guest_timing_{enter,exit}_irqoff(), which
surround the actual guest entry.

To fix the remaining issues, the lower-level guest entry logic is moved
into a shared noinstr helper function using the
guest_state_{enter,exit}_irqoff() helpers. These perform all the
lockdep/RCU/tracing manipulation necessary, but as sie64a() does not
enable/disable interrupts, we must do this explicitly with the
non-instrumented arch_local_irq_{enable,disable}() helpers:

        guest_state_enter_irqoff()

        arch_local_irq_enable();
        sie64a(...);
        arch_local_irq_disable();

        guest_state_exit_irqoff();

[ajd@linux.ibm.com: rebase, fix commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
---
 arch/s390/include/asm/entry-common.h | 10 ++++++
 arch/s390/include/asm/kvm_host.h     |  3 ++
 arch/s390/kvm/kvm-s390.c             | 51 +++++++++++++++++++++-------
 arch/s390/kvm/vsie.c                 | 17 ++++------
 4 files changed, 59 insertions(+), 22 deletions(-)

diff --git a/arch/s390/include/asm/entry-common.h b/arch/s390/include/asm/entry-common.h
index 35555c944630..979af986a8fe 100644
--- a/arch/s390/include/asm/entry-common.h
+++ b/arch/s390/include/asm/entry-common.h
@@ -59,4 +59,14 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
 
 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
 
+static __always_inline bool arch_in_rcu_eqs(void)
+{
+	if (IS_ENABLED(CONFIG_KVM))
+		return current->flags & PF_VCPU;
+
+	return false;
+}
+
+#define arch_in_rcu_eqs arch_in_rcu_eqs
+
 #endif
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index cb89e54ada25..f870d09515cc 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -716,6 +716,9 @@ extern char sie_exit;
 bool kvm_s390_pv_is_protected(struct kvm *kvm);
 bool kvm_s390_pv_cpu_is_protected(struct kvm_vcpu *vcpu);
 
+extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
+				   u64 *gprs, unsigned long gasce);
+
 extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
 extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
 
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index d5ad10791c25..bfe9ba5c4f45 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -5062,6 +5062,30 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)
 	return vcpu_post_run_handle_fault(vcpu);
 }
 
+int noinstr kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
+				    u64 *gprs, unsigned long gasce)
+{
+	int ret;
+
+	guest_state_enter_irqoff();
+
+	/*
+	 * The guest_state_{enter,exit}_irqoff() functions inform lockdep and
+	 * tracing that entry to the guest will enable host IRQs, and exit from
+	 * the guest will disable host IRQs.
+	 *
+	 * We must not use lockdep/tracing/RCU in this critical section, so we
+	 * use the low-level arch_local_irq_*() helpers to enable/disable IRQs.
+	 */
+	arch_local_irq_enable();
+	ret = sie64a(scb, gprs, gasce);
+	arch_local_irq_disable();
+
+	guest_state_exit_irqoff();
+
+	return ret;
+}
+
 #define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)
 static int __vcpu_run(struct kvm_vcpu *vcpu)
 {
@@ -5082,20 +5106,27 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
 		kvm_vcpu_srcu_read_unlock(vcpu);
 		/*
 		 * As PF_VCPU will be used in fault handler, between
-		 * guest_enter and guest_exit should be no uaccess.
+		 * guest_timing_enter_irqoff and guest_timing_exit_irqoff
+		 * should be no uaccess.
 		 */
-		local_irq_disable();
-		guest_enter_irqoff();
-		__disable_cpu_timer_accounting(vcpu);
-		local_irq_enable();
 		if (kvm_s390_pv_cpu_is_protected(vcpu)) {
 			memcpy(sie_page->pv_grregs,
 			       vcpu->run->s.regs.gprs,
 			       sizeof(sie_page->pv_grregs));
 		}
-		exit_reason = sie64a(vcpu->arch.sie_block,
-				     vcpu->run->s.regs.gprs,
-				     vcpu->arch.gmap->asce);
+
+		local_irq_disable();
+		guest_timing_enter_irqoff();
+		__disable_cpu_timer_accounting(vcpu);
+
+		exit_reason = kvm_s390_enter_exit_sie(vcpu->arch.sie_block,
+						      vcpu->run->s.regs.gprs,
+						      vcpu->arch.gmap->asce);
+
+		__enable_cpu_timer_accounting(vcpu);
+		guest_timing_exit_irqoff();
+		local_irq_enable();
+
 		if (kvm_s390_pv_cpu_is_protected(vcpu)) {
 			memcpy(vcpu->run->s.regs.gprs,
 			       sie_page->pv_grregs,
@@ -5111,10 +5142,6 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
 				vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK;
 			}
 		}
-		local_irq_disable();
-		__enable_cpu_timer_accounting(vcpu);
-		guest_exit_irqoff();
-		local_irq_enable();
 		kvm_vcpu_srcu_read_lock(vcpu);
 
 		rc = vcpu_post_run(vcpu, exit_reason);
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 13a9661d2b28..347268f89f2f 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -1170,10 +1170,6 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	    vcpu->arch.sie_block->fpf & FPF_BPBC)
 		set_thread_flag(TIF_ISOLATE_BP_GUEST);
 
-	local_irq_disable();
-	guest_enter_irqoff();
-	local_irq_enable();
-
 	/*
 	 * Simulate a SIE entry of the VCPU (see sie64a), so VCPU blocking
 	 * and VCPU requests also hinder the vSIE from running and lead
@@ -1183,15 +1179,16 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	vcpu->arch.sie_block->prog0c |= PROG_IN_SIE;
 	current->thread.gmap_int_code = 0;
 	barrier();
-	if (!kvm_s390_vcpu_sie_inhibited(vcpu))
-		rc = sie64a(scb_s, vcpu->run->s.regs.gprs, vsie_page->gmap->asce);
+	if (!kvm_s390_vcpu_sie_inhibited(vcpu)) {
+		local_irq_disable();
+		guest_timing_enter_irqoff();
+		rc = kvm_s390_enter_exit_sie(scb_s, vcpu->run->s.regs.gprs, vsie_page->gmap->asce);
+		guest_timing_exit_irqoff();
+		local_irq_enable();
+	}
 	barrier();
 	vcpu->arch.sie_block->prog0c &= ~PROG_IN_SIE;
 
-	local_irq_disable();
-	guest_exit_irqoff();
-	local_irq_enable();
-
 	/* restore guest state for bp isolation override */
 	if (!guest_bp_isolation)
 		clear_thread_flag(TIF_ISOLATE_BP_GUEST);
-- 
2.50.0

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

* Re: [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs
  2025-07-08  9:27 [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Andrew Donnellan
  2025-07-08  9:27 ` [PATCH 1/2] entry: Add arch_in_rcu_eqs() Andrew Donnellan
  2025-07-08  9:27 ` [PATCH 2/2] KVM: s390: Rework guest entry logic Andrew Donnellan
@ 2025-07-09  9:22 ` Janosch Frank
  2025-07-16 11:05 ` Mark Rutland
  3 siblings, 0 replies; 6+ messages in thread
From: Janosch Frank @ 2025-07-09  9:22 UTC (permalink / raw)
  To: Andrew Donnellan, linux-kernel, linux-s390, kvm
  Cc: Mark Rutland, Christian Borntraeger, Frederic Weisbecker,
	Heiko Carstens, Paolo Bonzini, Paul E. McKenney, Sven Schnelle,
	Vasily Gorbik, Claudio Imbrenda, Alexander Gordeev,
	Andy Lutomirski, Peter Zijlstra, Thomas Gleixner

On 7/8/25 11:27 AM, Andrew Donnellan wrote:
> In [0], the guest_{enter,exit}_irqoff() helpers were deprecated, in favour
> of guest_timing_{enter,exit}_irqoff() and
> guest_context_{enter,exit}_irqoff(). This was to fix a number of latent
> guest entry/exit bugs, relating to the enabling of interrupts during an
> RCU extended quiescent state, instrumentation code, and correct handling
> of lockdep and tracing.
> 
> However, while arm64, mips, riscv and x86 have been migrated to the new
> helpers, s390 hasn't been. There was an initial attempt at [1] to do this,
> but that didn't work for reasons discussed at [2].
> 
> Since then, Claudio Imbrenda has reworked much of the interrupt handling.
> Moving interrupt handling into vcpu_post_run() avoids the issues in [2],
> so we can now move to the new helpers.
> 
> I've rebased Mark's patches from [1]. kvm-unit-tests, the kvm selftests,
> and IBM's internal test suites pass under debug_defconfig.
> 
> These patches do introduce some overhead - in my testing, a few of the
> tests in the kvm-unit-tests exittime test suite appear 6-11% slower, but
> some noticeable overhead may be unavoidable (we introduce a new function
> call and the irq entry/exit paths change a bit).
> 

This series has been part of our CI runs for some while and hasn't 
caused issues.

Series:
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

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

* Re: [PATCH 1/2] entry: Add arch_in_rcu_eqs()
  2025-07-08  9:27 ` [PATCH 1/2] entry: Add arch_in_rcu_eqs() Andrew Donnellan
@ 2025-07-11 13:26   ` Peter Zijlstra
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Zijlstra @ 2025-07-11 13:26 UTC (permalink / raw)
  To: Andrew Donnellan
  Cc: linux-kernel, linux-s390, kvm, Mark Rutland,
	Christian Borntraeger, Frederic Weisbecker, Heiko Carstens,
	Janosch Frank, Paolo Bonzini, Paul E. McKenney, Sven Schnelle,
	Vasily Gorbik, Claudio Imbrenda, Alexander Gordeev,
	Andy Lutomirski, Thomas Gleixner

On Tue, Jul 08, 2025 at 07:27:41PM +1000, Andrew Donnellan wrote:
> From: Mark Rutland <mark.rutland@arm.com>
> 
> All architectures have an interruptible RCU extended quiescent state
> (EQS) as part of their idle sequences, where interrupts can occur
> without RCU watching. Entry code must account for this and wake RCU as
> necessary; the common entry code deals with this in irqentry_enter() by
> treating any interrupt from an idle thread as potentially having
> occurred within an EQS and waking RCU for the duration of the interrupt
> via rcu_irq_enter() .. rcu_irq_exit().
> 
> Some architectures may have other interruptible EQSs which require
> similar treatment. For example, on s390 it is necessary to enable
> interrupts around guest entry in the middle of a period where core KVM
> code has entered an EQS.
> 
> So that architectures can wake RCU in these cases, this patch adds a
> new arch_in_rcu_eqs() hook to the common entry code which is checked in
> addition to the existing is_idle_thread() check, with RCU woken if
> either returns true. A default implementation is provided which always
> returns false, which suffices for most architectures.
> 
> As no architectures currently implement arch_in_rcu_eqs(), there should
> be no functional change as a result of this patch alone. A subsequent
> patch will add an s390 implementation to fix a latent bug with missing
> RCU wakeups.
> 
> [ajd@linux.ibm.com: rebase, fix commit message]
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Paul E. McKenney <paulmck@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Sven Schnelle <svens@linux.ibm.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Alexander Gordeev <agordeev@linux.ibm.com>
> Cc: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
> Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> ---
>  include/linux/entry-common.h | 16 ++++++++++++++++
>  kernel/entry/common.c        |  3 ++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
> index f94f3fdf15fc..3bf99cbad8a3 100644
> --- a/include/linux/entry-common.h
> +++ b/include/linux/entry-common.h
> @@ -86,6 +86,22 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs);
>  static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) {}
>  #endif
>  
> +/**
> + * arch_in_rcu_eqs - Architecture specific check for RCU extended quiescent
> + * states.
> + *
> + * Returns: true if the CPU is potentially in an RCU EQS, false otherwise.
> + *
> + * Architectures only need to define this if threads other than the idle thread
> + * may have an interruptible EQS. This does not need to handle idle threads. It
> + * is safe to over-estimate at the cost of redundant RCU management work.
> + *
> + * Invoked from irqentry_enter()
> + */
> +#ifndef arch_in_rcu_eqs
> +static __always_inline bool arch_in_rcu_eqs(void) { return false; }
> +#endif
> +
>  /**
>   * enter_from_user_mode - Establish state when coming from user mode
>   *
> diff --git a/kernel/entry/common.c b/kernel/entry/common.c
> index a8dd1f27417c..eb52d38e8099 100644
> --- a/kernel/entry/common.c
> +++ b/kernel/entry/common.c
> @@ -220,7 +220,8 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)
>  	 * TINY_RCU does not support EQS, so let the compiler eliminate
>  	 * this part when enabled.
>  	 */
> -	if (!IS_ENABLED(CONFIG_TINY_RCU) && is_idle_task(current)) {
> +	if (!IS_ENABLED(CONFIG_TINY_RCU) &&
> +	    (is_idle_task(current) || arch_in_rcu_eqs())) {
>  		/*
>  		 * If RCU is not watching then the same careful
>  		 * sequence vs. lockdep and tracing is required
> -- 
> 2.50.0
> 

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

* Re: [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs
  2025-07-08  9:27 [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Andrew Donnellan
                   ` (2 preceding siblings ...)
  2025-07-09  9:22 ` [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Janosch Frank
@ 2025-07-16 11:05 ` Mark Rutland
  3 siblings, 0 replies; 6+ messages in thread
From: Mark Rutland @ 2025-07-16 11:05 UTC (permalink / raw)
  To: Andrew Donnellan
  Cc: linux-kernel, linux-s390, kvm, Christian Borntraeger,
	Frederic Weisbecker, Heiko Carstens, Janosch Frank, Paolo Bonzini,
	Paul E. McKenney, Sven Schnelle, Vasily Gorbik, Claudio Imbrenda,
	Alexander Gordeev, Andy Lutomirski, Peter Zijlstra,
	Thomas Gleixner

On Tue, Jul 08, 2025 at 07:27:40PM +1000, Andrew Donnellan wrote:
> In [0], the guest_{enter,exit}_irqoff() helpers were deprecated, in favour
> of guest_timing_{enter,exit}_irqoff() and
> guest_context_{enter,exit}_irqoff(). This was to fix a number of latent
> guest entry/exit bugs, relating to the enabling of interrupts during an
> RCU extended quiescent state, instrumentation code, and correct handling
> of lockdep and tracing.
> 
> However, while arm64, mips, riscv and x86 have been migrated to the new
> helpers, s390 hasn't been. There was an initial attempt at [1] to do this,
> but that didn't work for reasons discussed at [2].
> 
> Since then, Claudio Imbrenda has reworked much of the interrupt handling.
> Moving interrupt handling into vcpu_post_run() avoids the issues in [2],
> so we can now move to the new helpers.

Nice!

> I've rebased Mark's patches from [1]. kvm-unit-tests, the kvm selftests,
> and IBM's internal test suites pass under debug_defconfig.

I took a quick look at this and Claudio's preparatory work, and this all
looks like what I was hoping for back in one of the replies to [2]:

  https://lore.kernel.org/all/YerRbhqvJ5nEcQYT@FVFF77S0Q05N/

I am not aware of any additional problems, and this all looks good to
me. Thanks for picking this up!

Mark.

> These patches do introduce some overhead - in my testing, a few of the
> tests in the kvm-unit-tests exittime test suite appear 6-11% slower, but
> some noticeable overhead may be unavoidable (we introduce a new function
> call and the irq entry/exit paths change a bit).
> 
> [0] https://lore.kernel.org/lkml/20220201132926.3301912-1-mark.rutland@arm.com/
> [1] https://lore.kernel.org/all/20220119105854.3160683-7-mark.rutland@arm.com/
> [2] https://lore.kernel.org/all/a4a26805-3a56-d264-0a7e-60bed1ada9f3@linux.ibm.com/
> [3] https://lore.kernel.org/all/20241022120601.167009-1-imbrenda@linux.ibm.com/
> 
> Mark Rutland (2):
>   entry: Add arch_in_rcu_eqs()
>   KVM: s390: Rework guest entry logic
> 
>  arch/s390/include/asm/entry-common.h | 10 ++++++
>  arch/s390/include/asm/kvm_host.h     |  3 ++
>  arch/s390/kvm/kvm-s390.c             | 51 +++++++++++++++++++++-------
>  arch/s390/kvm/vsie.c                 | 17 ++++------
>  include/linux/entry-common.h         | 16 +++++++++
>  kernel/entry/common.c                |  3 +-
>  6 files changed, 77 insertions(+), 23 deletions(-)
> 
> -- 
> 2.50.0

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

end of thread, other threads:[~2025-07-16 11:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-08  9:27 [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Andrew Donnellan
2025-07-08  9:27 ` [PATCH 1/2] entry: Add arch_in_rcu_eqs() Andrew Donnellan
2025-07-11 13:26   ` Peter Zijlstra
2025-07-08  9:27 ` [PATCH 2/2] KVM: s390: Rework guest entry logic Andrew Donnellan
2025-07-09  9:22 ` [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs Janosch Frank
2025-07-16 11:05 ` Mark Rutland

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).