Skip to content

kvm: fix latent guest entry/exit bugs

Mark Rutland lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest5 patches 6 repliesIn review
  2. v27 patches 33 repliesSuperseded
  3. v15 patches 33 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5kvm: add guest_state_{enter,exit}_irqoff()include/linux/kvm_host.h+109 -30 replies
2/5kvm/arm64: rework guest entry logicarch/arm64/kvm/arm.c+33 -180 replies
3/5kvm/x86: rework guest entry logicarch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c +1 more+7 -500 replies
4/5kvm/riscv: rework guest entry logicarch/riscv/kvm/vcpu.c+27 -170 replies
5/5kvm/mips: rework guest entry logicarch/mips/kvm/mips.c+46 -40 replies

Reviews trailers per patch

3 of 5 patches have a Reviewed-by or Acked-by.

PatchMarc ZyngierPaolo BonziniNicolas Saenz Julienne
1/5R-b R-b R-b
2/5R-b R-b
3/5A-b R-b
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v3 thread

Cover letter [PATCH v3 0/5] kvm: fix latent guest entry/exit bugs

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/[email protected]/
[2] https://lore.kernel.org/r/[email protected]/

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(-)
Signature · 1 line
2.30.2