KVM: s390: updates for 6.17
Subsystems (4)
Janosch Frank
maintainerPaolo,
here are two fix patches that cleanup s390 guest entry. They've been part of our CI runs for a couple of weeks now.
These patches went through a couple of hands before hitting our next branch [1]. Additionally Stephen found and fixed a merge conflict witha70e9f647f50 ("entry: Split generic entry into generic exception and syscall entry")[2]
Please pull.
Cheers,
Janosch
---
The following changes since commit e04c78d86a9699d136910cfc0bdcf01087e3267e:
Linux 6.16-rc2 (2025-06-15 13:49:41 -0700)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-6.17-1
for you to fetch changes up to 57d88f02eb4449d96dfee3af4b7cd4287998bdbd:
KVM: s390: Rework guest entry logic (2025-07-21 13:01:03 +0000)
---
[1] https://lore.kernel.org/linux-s390/[email protected]/
[2] https://lore.kernel.org/linux-next/[email protected]/
---
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(-)
Signature · 1 line
2.50.1
Janosch Frank
maintainer[GIT PULL 2/2] KVM: s390: Rework guest entry logic
From: Mark Rutland <[email protected]>
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();[[email protected]: rebase, fix commit message]
Message-ID: <[email protected]>
--- 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(-)
arch/s390/include/asm/entry-common.h +10 -0
@@ -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
arch/s390/include/asm/kvm_host.h +3 -0
@@ -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);
arch/s390/kvm/kvm-s390.c +39 -12
75 lines not on this page · raw message
arch/s390/kvm/vsie.c +7 -10
@@ -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 );
Signature · 1 line
2.50.1
Janosch Frank
maintainer[GIT PULL 1/2] entry: Add arch_in_rcu_eqs()
In reply to Janosch FrankFrom: Mark Rutland <[email protected]>
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.
[[email protected]: rebase, fix commit message]
Message-ID: <[email protected]>
--- include/linux/entry-common.h | 16 ++++++++++++++++ kernel/entry/common.c | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-)
include/linux/entry-common.h +16 -0
@@ -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 *
kernel/entry/common.c +2 -1
@@ -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
Signature · 1 line
2.50.1
Paolo Bonzini
maintainerQuoted 11 lines · Janosch Frank
Paolo,
here are two fix patches that cleanup s390 guest entry. They've been part of our CI runs for a couple of weeks now.
These patches went through a couple of hands before hitting our next branch [1]. Additionally Stephen found and fixed a merge conflict with
a70e9f647f50("entry: Split generic entry into generic exception and syscall entry")[2]Please pull.
Done, thanks. Linus has already pulled the tip tree, so I've described Stephen's fix in my own pull request.
Paolo
Quoted 39 lines
Cheers,
Janosch---
The following changes since commit
e04c78d86a9699d136910cfc0bdcf01087e3267e:Linux 6.16-rc2 (2025-06-15 13:49:41 -0700)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-6.17-1
for you to fetch changes up to
57d88f02eb4449d96dfee3af4b7cd4287998bdbd:KVM: s390: Rework guest entry logic (2025-07-21 13:01:03 +0000)
---
[1] https://lore.kernel.org/linux-s390/[email protected]/
[2] https://lore.kernel.org/linux-next/[email protected]/---
Mark Rutland (2):
entry: Addarch_in_rcu_eqs()
KVM: s390: Rework guest entry logicarch/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.1
Paul E. McKenney
Reviewed-byRe: [GIT PULL 1/2] entry: Add arch_in_rcu_eqs()
In reply to Janosch FrankQuoted 47 lines · Janosch Frank
From: Mark Rutland <[email protected]>
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 viarcu_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 existingis_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.[[email protected]: rebase, fix commit message]
Signed-off-by Mark Rutland <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Christian Borntraeger <[email protected]>Cc Heiko Carstens <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Sven Schnelle <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Claudio Imbrenda <[email protected]>Cc Vasily Gorbik <[email protected]>Cc Alexander Gordeev <[email protected]>Cc Janosch Frank <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>Signed-off-by Andrew Donnellan <[email protected]>Reviewed-by Janosch Frank <[email protected]>Signed-off-by Janosch Frank <[email protected]>
Quoted 1 line
Message-ID: <[email protected]>
Quoted 49 lines
--- include/linux/entry-common.h | 16 ++++++++++++++++ kernel/entry/common.c | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-)include/linux/entry-common.h +16
-0@@ -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 * kernel/entry/common.c +2
-1@@ -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 Signature · 1 line
2.50.1