From: Paolo Bonzini <pbonzini@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: kvm@vger.kernel.org, Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH RFC] KVM: Fix race in apic->pending_events processing
Date: Fri, 31 May 2013 10:48:32 +0200 [thread overview]
Message-ID: <51A863E0.9080202@redhat.com> (raw)
In-Reply-To: <20130531043643.GA26250@redhat.com>
Il 31/05/2013 06:36, Gleb Natapov ha scritto:
> In my commit message there is two INITs in a row:
> vpu0: vcpu1:
> set INIT
> test_and_clear_bit(KVM_APIC_INIT)
> process INIT
> set INIT
> set SIPI
> test_and_clear_bit(KVM_APIC_SIPI)
> process SIPI
>
> Two INITs before SIPI are essential to trigger the bug
I see now. Let's draw pending_events as well:
event sent event processed pending_events
INIT INIT
INIT 0
INIT INIT
SIPI INIT|SIPI
SIPI INIT
INIT 0
Events are reordered, there is indeed a bug if the second INIT comes at
just the right time. With your patch:
event sent event processed pending_events
INIT INIT
INIT 0
INIT INIT
SIPI INIT|SIPI
SIPI, failed cmpxchg INIT|SIPI
INIT SIPI
SIPI SIPI
The patch introduces a spurious SIPI, that's worse than coalescing.
With my patch:
event sent event processed pending_events
INIT INIT
INIT 0
INIT INIT
SIPI INIT|SIPI
(failed cmpxchg) INIT|SIPI
INIT SIPI
SIPI 0
My patch looks better to me for this scenario.
> and coincidentally this is what spec advices to do.
The spec advises INIT-SIPI-SIPI, not INIT-INIT-SIPI. This is because
the first INIT may have been processed late, and SIPIs are masked if not
in wait-for-SIPI state. You need to send the second just in case. It
is not needed in KVM because INITs effectively unmask the SIPI
immediately, even though the INIT may take place a bit later.
The INIT-SIPI-SIPI sequence is handled correctly by KVM thanks to the
check on the mp-state. But your patch breaks another corner case:
event sent event processed pending_events
INIT INIT
INIT 0
SIPI SIPI
SIPI 0
SIPI SIPI
ignored SIPI SIPI
set_mp_state(INIT_RECEIVED) SIPI
SIPI 0
With my patch, or no patch at all:
event sent event processed pending_events
INIT INIT
INIT 0
SIPI SIPI
SIPI 0
SIPI SIPI
ignored SIPI 0
set_mp_state(INIT_RECEIVED) 0
Though perhaps the real bug here is in kvm_arch_vcpu_ioctl_setmp_state.
Setting the mp_state to anything bug SIPI_RECEIVED should clear the SIPI
event.
Paolo
>> event sent event processed pending_events
>> INIT INIT
>> SIPI INIT|SIPI
>> INIT SIPI
>> SIPI 0
>> INIT INIT
>> SIPI INIT|SIPI
>> INIT SIPI
>> SIPI 0
next prev parent reply other threads:[~2013-05-31 8:48 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-26 13:00 [PATCH RFC] KVM: Fix race in apic->pending_events processing Gleb Natapov
2013-05-28 10:56 ` Paolo Bonzini
2013-05-28 12:56 ` Gleb Natapov
2013-05-28 13:48 ` Paolo Bonzini
2013-05-28 15:00 ` Gleb Natapov
2013-05-28 16:33 ` Paolo Bonzini
2013-05-30 1:20 ` Gleb Natapov
2013-05-30 5:41 ` Paolo Bonzini
2013-05-30 6:01 ` Gleb Natapov
2013-05-30 6:31 ` Paolo Bonzini
2013-05-30 7:09 ` Gleb Natapov
2013-05-30 7:30 ` Paolo Bonzini
2013-05-30 12:34 ` Gleb Natapov
2013-05-30 12:58 ` Paolo Bonzini
2013-05-30 13:10 ` Gleb Natapov
2013-05-30 13:23 ` Paolo Bonzini
2013-05-30 13:35 ` Gleb Natapov
2013-05-30 14:15 ` Paolo Bonzini
2013-05-31 4:36 ` Gleb Natapov
2013-05-31 8:48 ` Paolo Bonzini [this message]
2013-05-31 9:18 ` Gleb Natapov
2013-05-31 9:48 ` Paolo Bonzini
2013-06-02 13:14 ` Gleb Natapov
2013-06-02 14:32 ` Paolo Bonzini
2013-06-02 17:33 ` Gleb Natapov
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=51A863E0.9080202@redhat.com \
--to=pbonzini@redhat.com \
--cc=gleb@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.