qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH qemu 0/7] KVM: race-free exit from KVM_RUN without P


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH qemu 0/7] KVM: race-free exit from KVM_RUN without POSIX signals
Date: Fri, 10 Feb 2017 10:50:05 +0100

The purpose of the KVM_SET_SIGNAL_MASK API is to let userspace "kick"
a VCPU out of KVM_RUN through a POSIX signal.  A signal is attached
to a dummy signal handler; by blocking the signal outside KVM_RUN and
unblocking it inside, this possible race is closed:

          VCPU thread                     service thread
   --------------------------------------------------------------
        check flag
                                          set flag
                                          raise signal
        (signal handler does nothing)
        KVM_RUN

However, one issue with KVM_SET_SIGNAL_MASK is that it has to take
tsk->sighand->siglock on every KVM_RUN.  This lock is often on a
remote NUMA node, because it is on the node of a thread's creator.
Taking this lock can be very expensive if there are many userspace
exits (as is the case for SMP Windows VMs without Hyper-V reference
time counter).

As an alternative, we can put the flag directly in kvm_run so that
KVM can see it:

          VCPU thread                     service thread
   --------------------------------------------------------------
                                          raise signal
        signal handler
          set run->immediate_exit
        KVM_RUN
          check run->immediate_exit

This is what the last patch in this series does, together with
the corresponding kernel API.  The first six patches are a long
detour in the signal handling code, moving KVM-specific stuff
from cpus.c to kvm-all.c so that we have a better hook point for
KVM_CAP_IMMEDIATE_EXIT (patches 1-3, 6).

Because KVM_SET_SIGNAL_MASK is also unblocking SIGBUS so that
BUS_MCEERR_AR actions can be delivered via sigwait, we also have
to rewrite it (patch 4-5) to avoid sigwait, stowing the machine check
exception as soon as KVM_RUN exits and process it outside the signal
handler.

The seventh patch would of course be split between a linux-headers
update and the rest.

Paolo

ps: As an aside, I finally figured out how to test machine check
forwarding and I hope to write something about it.

Paolo Bonzini (7):
  cpus: remove ugly cast on sigbus_handler
  KVM: x86: cleanup SIGBUS handlers
  cpus: reorganize signal handling code
  KVM: remove kvm_arch_on_sigbus
  KVM: do not use sigtimedwait to catch SIGBUS
  KVM: move SIG_IPI handling to kvm-all.c
  KVM: use KVM_CAP_IMMEDIATE_EXIT

 cpus.c                    | 102 ++++++------------------------------
 include/qemu/compatfd.h   |  42 ---------------
 include/qemu/osdep.h      |  35 +++++++++++++
 include/sysemu/kvm.h      |  11 ++--
 kvm-all.c                 | 130 +++++++++++++++++++++++++++++++++++++++++++---
 kvm-stub.c                |  12 ++---
 linux-headers/linux/kvm.h |   4 +-
 main-loop.c               |   5 +-
 os-win32.c                |   7 +++
 target/arm/kvm.c          |  10 ----
 target/i386/kvm.c         |  81 ++++++++---------------------
 target/mips/kvm.c         |  12 -----
 target/ppc/kvm.c          |  10 ----
 target/s390x/kvm.c        |  10 ----
 util/compatfd.c           |   1 -
 util/oslib-posix.c        |  33 ++++++++++++
 16 files changed, 249 insertions(+), 256 deletions(-)
 delete mode 100644 include/qemu/compatfd.h

-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]