All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: mtosatti@redhat.com, srutherford@google.com, rkrcmar@redhat.com
Subject: Re: [PATCH 2/4] KVM: document memory barriers for kvm->vcpus/kvm->online_vcpus
Date: Thu, 30 Jul 2015 14:46:12 +0200	[thread overview]
Message-ID: <55BA1C94.80200@redhat.com> (raw)
In-Reply-To: <55BA0D1D.7090002@de.ibm.com>



On 30/07/2015 13:40, Christian Borntraeger wrote:
>> > +	/* Pairs with smp_wmb() in kvm_vm_ioctl_create_vcpu, in case
>> > +	 * the caller has read kvm->online_vcpus before (as is the case
>> > +	 * for kvm_for_each_vcpu, for example).
>> > +	 */
>> >  	smp_rmb();
> Hmmm, wouldnt something like smp_mb__after_atomic
> 
>> >  	return kvm->vcpus[i];
>> >  }
>> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>> > index 8dc4828f623f..093b3d10b411 100644
>> > --- a/virt/kvm/kvm_main.c
>> > +++ b/virt/kvm/kvm_main.c
>> > @@ -2206,6 +2206,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
>> >  	}
>> > 
>> >  	kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
> and  smp_mb__before_atomic
> 
> be the better function?
> 
> 
>> > +
>> > +	/* Pairs with smp_rmb() in kvm_get_vcpu.  */
>> >  	smp_wmb();
>> >  	atomic_inc(&kvm->online_vcpus);

The difference between smp_rmb/smp_wmb on one side, and smp_mb on the
other side, is that smp_mb protects previous stores from subsequent loads.

smp_mb__before_atomic would be overkill for atomic_inc, where there's no
race involving the read of online_vcpus (there's only one writer and
it's protected by kvm->lock).  We only care about ordering the
kvm->vcpus store with the kvm->online_vcpus store.  One could use a
hypothetical smp_wmb__before_atomic(), but this is not a fast path and
IIRC only on ia64 it would be different from smp_wmb().

The "after_atomic" bit of smp_mb__after_atomic doesn't include
atomic_read/atomic_set, so it would not be good for kvm_get_vcpu.  But
there is also no previous store to order against, because
kvm->online_vcpus is only written in the KVM_CREATE_VCPU ioctl.  Thus
smp_rmb() is enough.

Paolo

  reply	other threads:[~2015-07-30 12:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-29 13:28 [PATCH 0/4] KVM: cleanups around memory barriers and irqchip_in_kernel Paolo Bonzini
2015-07-29 13:28 ` [PATCH 1/4] KVM: x86: remove unnecessary memory barriers for shared MSRs Paolo Bonzini
2015-07-29 13:28 ` [PATCH 2/4] KVM: document memory barriers for kvm->vcpus/kvm->online_vcpus Paolo Bonzini
2015-07-30 11:40   ` Christian Borntraeger
2015-07-30 12:46     ` Paolo Bonzini [this message]
2015-07-30 13:57       ` Christian Borntraeger
2015-07-30 14:02         ` Paolo Bonzini
2015-07-30 14:05           ` Christian Borntraeger
2015-07-29 13:28 ` [PATCH 3/4] KVM: i8254: remove unnecessary irqchip_in_kernel check Paolo Bonzini
2015-07-30  4:36   ` Steve Rutherford
2015-07-30  7:25     ` Paolo Bonzini
2015-07-29 13:28 ` [PATCH 4/4] KVM: x86: clean/fix memory barriers in irqchip_in_kernel Paolo Bonzini
2015-07-30  3:32   ` Steve Rutherford
2015-07-30  7:26     ` Paolo Bonzini

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=55BA1C94.80200@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=srutherford@google.com \
    /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.