kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: linmiaohe <linmiaohe@huawei.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com,
	wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org,
	tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	hpa@zytor.com
Subject: Re: [PATCH] KVM: apic: reuse smp_wmb() in kvm_make_request()
Date: Thu, 6 Feb 2020 07:05:23 -0800	[thread overview]
Message-ID: <20200206150523.GA13067@linux.intel.com> (raw)
In-Reply-To: <87d0asgfh5.fsf@vitty.brq.redhat.com>

On Thu, Feb 06, 2020 at 11:47:02AM +0100, Vitaly Kuznetsov wrote:
> linmiaohe <linmiaohe@huawei.com> writes:
> 
> > From: Miaohe Lin <linmiaohe@huawei.com>
> >
> > There is already an smp_mb() barrier in kvm_make_request(). We reuse it
> > here.
> >
> > Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> > ---
> >  arch/x86/kvm/lapic.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> > index eafc631d305c..ea871206a370 100644
> > --- a/arch/x86/kvm/lapic.c
> > +++ b/arch/x86/kvm/lapic.c
> > @@ -1080,9 +1080,12 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
> >  			result = 1;
> >  			/* assumes that there are only KVM_APIC_INIT/SIPI */
> >  			apic->pending_events = (1UL << KVM_APIC_INIT);
> > -			/* make sure pending_events is visible before sending
> > -			 * the request */
> > -			smp_wmb();
> > +			/*
> > +			 * Make sure pending_events is visible before sending
> > +			 * the request.
> > +			 * There is already an smp_wmb() in kvm_make_request(),
> > +			 * we reuse that barrier here.
> > +			 */
> 
> Let me suggest an alternative wording,
> 
> "kvm_make_request() provides smp_wmb() so pending_events changes are
> guaranteed to be visible"
> 
> But there is nothing wrong with yours, it's just longer than it could be
> :-)

I usually lean in favor of more comments, but in thise case I'd vote to
drop the comment altogether.  There are lots of places that rely on the
smp_wmb() in kvm_make_request() without a comment, e.g. the cases for
APIC_DM_STARTUP and APIC_DM_REMRD in this same switch, kvm_inject_nmi(),
etc...  One might wonder what makes INIT special.

And on the flip side, APIC_DM_STARTUP is a good example of when a
smp_wmb()/smp_rmb() is needed and commented correctly (though calling out
the exactly location of the other half would be helpful).

> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> 
> >  			kvm_make_request(KVM_REQ_EVENT, vcpu);
> >  			kvm_vcpu_kick(vcpu);
> >  		}
> 
> -- 
> Vitaly
> 

  reply	other threads:[~2020-02-06 15:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06  1:59 [PATCH] KVM: apic: reuse smp_wmb() in kvm_make_request() linmiaohe
2020-02-06 10:47 ` Vitaly Kuznetsov
2020-02-06 15:05   ` Sean Christopherson [this message]
2020-02-07  2:59 linmiaohe

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=20200206150523.GA13067@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@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 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).