[PATCH 00/33] KVM: PPC: Fix IRQ race in magic page code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux