All of lore.kernel.org
 help / color / mirror / Atom feed
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: Thu, 30 May 2013 15:23:35 +0200	[thread overview]
Message-ID: <51A752D7.1020809@redhat.com> (raw)
In-Reply-To: <20130530131054.GB5495@redhat.com>

Il 30/05/2013 15:10, Gleb Natapov ha scritto:
> On Thu, May 30, 2013 at 02:58:09PM +0200, Paolo Bonzini wrote:
>> Il 30/05/2013 14:34, Gleb Natapov ha scritto:
>>>>>>>
>>>>>>> Ah, we check kvm_apic_has_events() in runnable. Then yes, we will not
>>>>>>> lose the event.
>>>>>
>>>>> Ok, then I'd prefer to have the cmpxchg directly in the if, as in
>>>>> http://article.gmane.org/gmane.comp.emulators.kvm.devel/110505
>>>>>
>>> I still do not. Both of them are tricky, mine does not coalesce events
>>> needlessly.
>>
>> Agreed that both are tricky, but I don't think my patch is coalescing
>> events.  If you have
>>
>>     INIT    SIPI     INIT     SIPI
>>                   ^                           ^
>>                   INIT bit cleared here       SIPI bit checked here
>>
> Not sure I understand what you are trying to say here.

I'll redo the picture below.

>> my patch KVM sees apic_events = INIT | SIPI and deduces that the SIPI
>> bit was set by the second SIPI, not by the first.  In fact the first
>> SIPI was cancelled by the second INIT, and thus should not be processed
>> at all.
> That is called coalesced.

Coalescing would be something like INIT SIPI SIPI -> INIT SIPI.  This is
not coalescing, it is proper detection of a cancelled SIPI.  We have:

   event sent           event processed            pending_events
    INIT                                                 INIT
    SIPI                                               INIT|SIPI
                             INIT                        SIPI
XX  INIT                                                 INIT
    SIPI                                               INIT|SIPI
YY                           SIPI                      INIT|SIPI
                        failed cmpxchg                 INIT|SIPI
                             INIT                        SIPI
                             SIPI                          0

At the line I marked with YY, you're processing an interrupt that is not
anymore in the pending_events.  It was dropped at point XX.

With my patch it is:


   event sent           event processed            pending_events
    INIT                                                 INIT
    SIPI                                               INIT|SIPI
                             INIT                        SIPI
XX  INIT                                                 INIT
    SIPI                                               INIT|SIPI
                       failed cmpxchg                 INIT|SIPI
                             INIT                        SIPI
                             SIPI                         0

>> Instead, with your patch KVM will service all four events; strictly
>> speaking it is wrong to service the first SIPI, which is why I prefer
>> having the cmpxchg in the beginning.
>
> Why is it wrong?

Because the first SIPI was dropped atomically with the triggering of the
second INIT, it's as if you were handling it twice.

Paolo

  reply	other threads:[~2013-05-30 13:23 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 [this message]
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
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=51A752D7.1020809@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.