KVM: PPC: Fix IRQ race in magic page code
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest33 patches 6 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/33 | KVM: PPC: Implement kvmppc_xlate for all targetsarch/ arch/ arch/ | +72 | 0 replies | |
| 2/33 | KVM: PPC: Move kvmppc_ld/st to common codearch/ arch/ arch/ +2 more | +87 | 0 replies | |
| 3/33 | KVM: PPC: Remove kvmppc_bad_hva()arch/ | +1 | 0 replies | |
| 4/33 | KVM: PPC: Propagate kvmppc_xlate errors properlyarch/ | +10 | 0 replies | |
| 5/33 | KVM: PPC: Use kvm_read_guest in kvmppc_ldarch/ | +2 | 0 replies | |
| 6/33 | KVM: PPC: Handle magic page in kvmppc_ld/starch/ arch/ arch/ | +39 | 0 replies | |
| 7/33 | KVM: PPC: Separate loadstore emulation from priv emulationarch/ arch/ arch/ +2 more | +271 | 0 replies | |
| 8/33 | KVM: PPC: Introduce emulation for unprivileged instructionsarch/ arch/ | +52 | 0 replies | |
| 9/33 | KVM: PPC: Move critical section detection to common codearch/ arch/ arch/ | +27 | 0 replies | |
| 10/33 | KVM: PPC: Make critical section detection conditionalarch/ | +1 | 0 replies | |
| 11/33 | KVM: PPC: BookE: Use common critical section helperarch/ | +1 | 0 replies | |
| 12/33 | KVM: PPC: Emulate critical sections when we hit themarch/ arch/ arch/ +1 more | +74 | 0 replies | |
| 13/33 | KVM: PPC: Expose helper functions for data/inst faultsarch/ arch/ arch/ | +35 | 0 replies | |
| 14/33 | KVM: PPC: Add std instruction emulationarch/ arch/ | +87 | 0 replies | |
| 15/33 | KVM: PPC: Add stw instruction emulationarch/ | +5 | 0 replies | |
| 16/33 | KVM: PPC: Add ld instruction emulationarch/ | +67 | 0 replies | |
| 17/33 | KVM: PPC: Add lwz instruction emulationarch/ | +5 | 0 replies | |
| 18/33 | KVM: PPC: Add mfcr instruction emulationarch/ arch/ | +11 | 0 replies | |
| 19/33 | KVM: PPC: Add addis instruction emulationarch/ arch/ | +8 | 0 replies | |
| 20/33 | KVM: PPC: Add ori instruction emulationarch/ arch/ | +6 | 0 replies | |
| 21/33 | KVM: PPC: Add and instruction emulationarch/ arch/ | +49 | 0 replies | |
| 22/33 | KVM: PPC: Add andi. instruction emulationarch/ arch/ | +7 | 0 replies | |
| 23/33 | KVM: PPC: Add or instruction emulationarch/ arch/ | +9 | 0 replies | |
| 24/33 | KVM: PPC: Add cmpwi/cmpdi instruction emulationarch/ arch/ | +6 | 0 replies | |
| 25/33 | KVM: PPC: Add bc instruction emulationarch/ arch/ | +52 | 0 replies | |
| 26/33 | KVM: PPC: Add mtcrf instruction emulationarch/ arch/ | +26 | 0 replies | |
| 27/33 | KVM: PPC: Add xor instruction emulationarch/ arch/ | +9 | 0 replies | |
| 28/33 | KVM: PPC: Add oris instruction emulationarch/ arch/ | +6 | 0 replies | |
| 29/33 | KVM: PPC: Add rldicr/rldicl/rldic instruction emulationarch/ arch/ | +62 | 0 replies | |
| 30/33 | KVM: PPC: Add rlwimi instruction emulationarch/ arch/ | +35 | 0 replies | |
| 31/33 | KVM: PPC: Add rlwinm instruction emulationarch/ arch/ | +8 | 0 replies | |
| 32/33 | KVM: PPC: Handle NV registers in emulated critical sectionsarch/ arch/ arch/ | +21 | 0 replies | |
| 33/33 | KVM: PPC: Enable critical section emulationarch/ | +0 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 00/33] KVM: PPC: Fix IRQ race in magic page code
Howdy,
Ben reminded me a while back that we have a nasty race in our KVM PV code.
We replace a few instructions with longer streams of instructions to check whether it's necessary to trap out from it (like mtmsr, no need to trap if we only disable interrupts). During those replacement chunks we must not get any interrupts, because they might overwrite scratch space that we already used to save otherwise clobbered register state into.
So we have a thing called "critical sections" which allows us to atomically get in and out of "interrupt disabled" modes without touching MSR. When we are supposed to deliver an interrupt into the guest while we are in a critical section, we just don't inject the interrupt yet, but leave it be until the next trap.
However, we never really know when the next trap would be. For all we know it could be never. At this point we created a race that is a potential source for interrupt loss or at least deferral.
This patch set aims at solving the race. Instead of merely deferring an interrupt when we see such a situation, we go into a special instruction interpretation mode. In this mode, we interpret all PPC assembler instructions that happen until we are out of the critical section again, at which point we can now inject the interrupt.
This bug only affects KVM implementations that make use of the magic page, so e500v2, book3s_32 and book3s_64 PR KVM.
Alex
Alexander Graf (33):
KVM: PPC: Implement kvmppc_xlate for all targets
KVM: PPC: Move kvmppc_ld/st to common code
KVM: PPC: Remove kvmppc_bad_hva()
KVM: PPC: Propagate kvmppc_xlate errors properly
KVM: PPC: Use kvm_read_guest in kvmppc_ld
KVM: PPC: Handle magic page in kvmppc_ld/st
KVM: PPC: Separate loadstore emulation from priv emulation
KVM: PPC: Introduce emulation for unprivileged instructions
KVM: PPC: Move critical section detection to common code
KVM: PPC: Make critical section detection conditional
KVM: PPC: BookE: Use common critical section helper
KVM: PPC: Emulate critical sections when we hit them
KVM: PPC: Expose helper functions for data/inst faults
KVM: PPC: Add std instruction emulation
KVM: PPC: Add stw instruction emulation
KVM: PPC: Add ld instruction emulation
KVM: PPC: Add lwz instruction emulation
KVM: PPC: Add mfcr instruction emulation
KVM: PPC: Add addis instruction emulation
KVM: PPC: Add ori instruction emulation
KVM: PPC: Add and instruction emulation
KVM: PPC: Add andi. instruction emulation
KVM: PPC: Add or instruction emulation
KVM: PPC: Add cmpwi/cmpdi instruction emulation
KVM: PPC: Add bc instruction emulation
KVM: PPC: Add mtcrf instruction emulation
KVM: PPC: Add xor instruction emulation
KVM: PPC: Add oris instruction emulation
KVM: PPC: Add rldicr/rldicl/rldic instruction emulation
KVM: PPC: Add rlwimi instruction emulation
KVM: PPC: Add rlwinm instruction emulation
KVM: PPC: Handle NV registers in emulated critical sections
KVM: PPC: Enable critical section emulation
arch/powerpc/include/asm/kvm_book3s.h | 9 +- arch/powerpc/include/asm/kvm_booke.h | 10 + arch/powerpc/include/asm/kvm_host.h | 4 +- arch/powerpc/include/asm/kvm_ppc.h | 29 ++ arch/powerpc/include/asm/ppc-opcode.h | 14 + arch/powerpc/kvm/Makefile | 4 +- arch/powerpc/kvm/book3s.c | 142 ++------ arch/powerpc/kvm/book3s_pr.c | 16 +- arch/powerpc/kvm/booke.c | 120 +++++-- arch/powerpc/kvm/emulate.c | 656 ++++++++++++++++++++++++---------- arch/powerpc/kvm/emulate_loadstore.c | 266 ++++++++++++++ arch/powerpc/kvm/powerpc.c | 123 ++++++- 12 files changed, 1076 insertions(+), 317 deletions(-) create mode 100644 arch/powerpc/kvm/emulate_loadstore.c
Signature · 1 line
1.8.1.4