[PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs

Andrew Donnellan posted 2 patches 3 months ago
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(-)
[PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs
Posted by Andrew Donnellan 3 months ago
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
Re: [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs
Posted by Mark Rutland 2 months, 3 weeks ago
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
Re: [PATCH 0/2] KVM: s390: Fix latent guest entry/exit bugs
Posted by Janosch Frank 3 months ago
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>