All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Lan Tianyu <tianyu.lan@intel.com>, Thomas Gleixner <tglx@linutronix.de>
Cc: gleb@kernel.org, mingo@redhat.com, hpa@zytor.com, x86@kernel.org,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: Remove redundant smp_mb() in the kvm_mmu_commit_zap_page()
Date: Fri, 4 Mar 2016 09:49:02 +0100	[thread overview]
Message-ID: <56D94BFE.1080406@redhat.com> (raw)
In-Reply-To: <56D9354E.9040908@intel.com>

On 04/03/2016 08:12, Lan Tianyu wrote:
> > >  	/*
> > > -	 * wmb: make sure everyone sees our modifications to the page tables
> > > -	 * rmb: make sure we see changes to vcpu->mode
> > 
> > You want to leave the comment explaining the memory barriers and tell that
> > kvm_flush_remote_tlbs() contains the smp_mb().
> 
> That sounds more reasonable. Will update. Thanks.

In fact, the reason for kvm_flush_remote_tlbs()'s barrier is exactly
what was in this comment.  So you can:

1) add a comment to kvm_flush_remote_tlbs like:

	/*
	 * We want to publish modifications to the page tables before reading
	 * mode.  Pairs with a memory barrier in arch-specific code.
	 * - x86: smp_mb__after_srcu_read_unlock in vcpu_enter_guest.
	 * - powerpc: smp_mb in kvmppc_prepare_to_enter.
	 */

2) add a comment to vcpu_enter_guest and kvmppc_prepare_to_enter, saying
that the memory barrier also orders the write to mode from any reads
to the page tables done while the VCPU is running.  In other words, on
entry a single memory barrier achieves two purposes (write ->mode before
reading requests, write ->mode before reading page tables).

The same should be true in kvm_flush_remote_tlbs().  So you may investigate
removing the barrier from kvm_flush_remote_tlbs, because
kvm_make_all_cpus_request already includes a memory barrier.  Like
Thomas suggested, leave a comment in kvm_flush_remote_tlbs(),
saying which memory barrier you are relying on and for what.

And finally, the memory barrier in kvm_make_all_cpus_request can become
smp_mb__after_atomic, which is free on x86.

Of course, all this should be done in at least three separate patches.

Thanks!

Paolo

  reply	other threads:[~2016-03-04  8:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04  1:35 [PATCH] KVM: Remove redundant smp_mb() in the kvm_mmu_commit_zap_page() Lan Tianyu
2016-03-04  7:21 ` Thomas Gleixner
2016-03-04  7:12   ` Lan Tianyu
2016-03-04  8:49     ` Paolo Bonzini [this message]
2016-03-08  8:36       ` Lan Tianyu
2016-03-08 15:27         ` Paolo Bonzini
2016-03-09  7:18           ` Lan Tianyu
2016-03-10 17:07             ` Paolo Bonzini
2016-03-10 18:08               ` Xiao Guangrong
2016-03-10 14:40           ` Xiao Guangrong
2016-03-10 15:26             ` Paolo Bonzini
2016-03-10 15:31               ` Paolo Bonzini
2016-03-10 15:45                 ` Xiao Guangrong
2016-03-10 16:04                   ` Paolo Bonzini
2016-03-10 17:57                     ` Xiao Guangrong
2016-03-11  1:13               ` Lan Tianyu
2016-03-04  8:04 ` Paolo Bonzini
2016-03-04 13:48   ` Xiao Guangrong

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=56D94BFE.1080406@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tianyu.lan@intel.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 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.