qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCH qemu 0/7] KVM: race-free exit from KVM_RUN without POSIX signals
Date: Wed, 15 Feb 2017 16:57:39 +0100	[thread overview]
Message-ID: <d1feeef5-0f3c-30e1-6a45-0e0c3fb618a2@redhat.com> (raw)
In-Reply-To: <20170210095012.16039-1-pbonzini@redhat.com>



On 10/02/2017 10:50, Paolo Bonzini wrote:
> 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.

This is needed to test these patches with the final version of the KVM part:

diff --git a/kvm-all.c b/kvm-all.c
index 083143f..c79833e 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1922,6 +1922,7 @@ static void kvm_eat_signals(CPUState *cpu)
     int r;
 
     if (kvm_immediate_exit) {
+        atomic_set(&cpu->kvm_run->immediate_exit, 0);
         return;
     }
 
Paolo

      parent reply	other threads:[~2017-02-15 15:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10  9:50 [Qemu-devel] [PATCH qemu 0/7] KVM: race-free exit from KVM_RUN without POSIX signals Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 1/7] cpus: remove ugly cast on sigbus_handler Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 2/7] KVM: x86: cleanup SIGBUS handlers Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 3/7] cpus: reorganize signal handling code Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 4/7] KVM: remove kvm_arch_on_sigbus Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 5/7] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 6/7] KVM: move SIG_IPI handling to kvm-all.c Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 7/7] KVM: use KVM_CAP_IMMEDIATE_EXIT Paolo Bonzini
2017-02-10 10:11 ` [Qemu-devel] [PATCH qemu 0/7] KVM: race-free exit from KVM_RUN without POSIX signals no-reply
2017-02-15 15:57 ` Paolo Bonzini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d1feeef5-0f3c-30e1-6a45-0e0c3fb618a2@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).