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: Sun, 02 Jun 2013 16:32:25 +0200 [thread overview]
Message-ID: <51AB5779.80101@redhat.com> (raw)
In-Reply-To: <20130602131442.GF24773@redhat.com>
Il 02/06/2013 15:14, Gleb Natapov ha scritto:
>> Can you show what is the case in my patch where you have coalescing? I
> You'ev said it in some of your emails. Quoting:
> " INIT-INIT-SIPI-INIT-SIPI
>
> your version would do many SIPIs, while mine would do just one."
Cancelling is very different from coalescing. In the implementation we
chose, we have "two wires" to the processor; an INIT interrupt means
"bring SIPI wire to 0 and INIT to 1", while a SIPI means "leave INIT
wire aside and bring the SIPI wire to 1". If the target processor does
not sense in time that the SIPI wire is high, the signal is lost.
Coalescing means that INIT-INIT or SIPI-SIPI becomes a single SIPI.
That is happening no matter what, because we have two bits not a queue.
So let's settle this as a simple disagreement on terms and move on.
> There is nothing "surprising" in it for me. Really it is so subjection
> that arguing about it is waste of everybody time and energy. So if we
> want to continue have fun arguing about it lets move to some real patch
> problems/benefits.
Good idea. :)
> So what I didn't like from the start about
> pending_events is that it introduces two locked instruction on each
> interrupt injection path, your patch makes it worse by change one of
> those locked instruction to cmpxchg, while mine actually removes one.
A cmpxchg is not more expensive than a test_and_clear_bit. A cmpxchg
loop would be worse, of course.
> But I think we can do even better and get rid of both of them for common
> case and do only one locked inst while there are events pending, but
> this is slow path so less important:
It looks indeed better than both alternatives. It doesn't do the
coalescing that worries you, and I can understand it relatively easily
as "latching" the contents of pending_events at the beginning of
kvm_apic_accept_events. Very good idea!
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 9d75193..3e0e85a 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1850,11 +1850,14 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
> {
> struct kvm_lapic *apic = vcpu->arch.apic;
> unsigned int sipi_vector;
> + unsigned long pe;
>
> - if (!kvm_vcpu_has_lapic(vcpu))
> + if (!kvm_vcpu_has_lapic(vcpu) || !apic->pending_events)
> return;
FWIW, this optimization is independent of the other change. It would
work even on top of the current code. But of course there is no need to
split it into a separate patch.
Paolo
> - if (test_and_clear_bit(KVM_APIC_INIT, &apic->pending_events)) {
> + pe = xchg(&apic->pending_events, 0);
> +
> + if (test_bit(KVM_APIC_INIT, &pe)) {
> kvm_lapic_reset(vcpu);
> kvm_vcpu_reset(vcpu);
> if (kvm_vcpu_is_bsp(apic->vcpu))
> @@ -1862,7 +1865,7 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
> else
> vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED;
> }
> - if (test_and_clear_bit(KVM_APIC_SIPI, &apic->pending_events) &&
> + if (test_bit(KVM_APIC_SIPI, &pe) &&
> vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) {
> /* evaluate pending_events before reading the vector */
> smp_rmb();
> --
> Gleb.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2013-06-02 14:32 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
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 [this message]
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=51AB5779.80101@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.