public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>,
	kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: x86: Optimize mmio spte zapping when creating/moving memslot
Date: Tue, 12 Mar 2013 22:40:12 -0300	[thread overview]
Message-ID: <20130313014012.GA21171@amt.cnet> (raw)
In-Reply-To: <20130312120622.GZ11223@redhat.com>

On Tue, Mar 12, 2013 at 02:06:22PM +0200, Gleb Natapov wrote:
> On Tue, Mar 12, 2013 at 05:45:30PM +0900, Takuya Yoshikawa wrote:
> > When we create or move a memory slot, we need to zap mmio sptes.
> > Currently, zap_all() is used for this and this is causing two problems:
> >  - extra page faults after zapping mmu pages
> >  - long mmu_lock hold time during zapping mmu pages
> > 
> > For the latter, Marcelo reported a disastrous mmu_lock hold time during
> > hot-plug, which made the guest unresponsive for a long time.
> > 
> > This patch takes a simple way to fix these problems: do not zap mmu
> > pages unless they are marked mmio cached.  On our test box, this took
> > only 50us for the 4GB guest and we did not see ms of mmu_lock hold time
> > any more.
> > 
> > Note that we still need to do zap_all() for other cases.  So another
> > work is also needed: Xiao's work may be the one.
> > 
> > Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
> > ---
> >  arch/x86/include/asm/kvm_host.h |    1 +
> >  arch/x86/kvm/mmu.c              |   18 ++++++++++++++++++
> >  arch/x86/kvm/x86.c              |    2 +-
> >  3 files changed, 20 insertions(+), 1 deletions(-)
> > 
> > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> > index b84310a..028b03f 100644
> > --- a/arch/x86/include/asm/kvm_host.h
> > +++ b/arch/x86/include/asm/kvm_host.h
> > @@ -768,6 +768,7 @@ void kvm_mmu_write_protect_pt_masked(struct kvm *kvm,
> >  				     struct kvm_memory_slot *slot,
> >  				     gfn_t gfn_offset, unsigned long mask);
> >  void kvm_mmu_zap_all(struct kvm *kvm);
> > +void kvm_mmu_zap_mmio_sptes(struct kvm *kvm);
> >  unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm);
> >  void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
> >  
> > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> > index de45ec1..c1a9b7b 100644
> > --- a/arch/x86/kvm/mmu.c
> > +++ b/arch/x86/kvm/mmu.c
> > @@ -4189,6 +4189,24 @@ restart:
> >  	spin_unlock(&kvm->mmu_lock);
> >  }
> >  
> > +void kvm_mmu_zap_mmio_sptes(struct kvm *kvm)
> > +{
> > +	struct kvm_mmu_page *sp, *node;
> > +	LIST_HEAD(invalid_list);
> > +
> > +	spin_lock(&kvm->mmu_lock);
> > +restart:
> > +	list_for_each_entry_safe(sp, node, &kvm->arch.active_mmu_pages, link) {
> > +		if (!sp->mmio_cached)
> > +			continue;
> > +		if (kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list))
> > +			goto restart;
> > +	}
> > +
> > +	kvm_mmu_commit_zap_page(kvm, &invalid_list);
> > +	spin_unlock(&kvm->mmu_lock);
> > +}
> > +
> >  static int mmu_shrink(struct shrinker *shrink, struct shrink_control *sc)
> >  {
> >  	struct kvm *kvm;
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 35b4912..16b6df2 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -6969,7 +6969,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
> >  	 * mmio sptes.
> >  	 */
> >  	if ((change == KVM_MR_CREATE) || (change == KVM_MR_MOVE)) {
> I wonder why check for KVM_MR_MOVE here. For KVM_MR_MOVE
> kvm_mmu_zap_all() should be called and it is indeed called by the common code.

Its per memslot, the common code flush:

kvm_arch_flush_shadow_memslot(kvm, slot);


  reply	other threads:[~2013-03-13  1:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-12  8:43 [PATCH 0/2] KVM: Optimize mmio spte zapping when creating/moving memslot Takuya Yoshikawa
2013-03-12  8:44 ` [PATCH 1/2] KVM: MMU: Mark sp mmio cached when creating mmio spte Takuya Yoshikawa
2013-03-13  5:06   ` Xiao Guangrong
2013-03-13  7:28     ` Takuya Yoshikawa
2013-03-13  7:42       ` Xiao Guangrong
2013-03-13 12:33         ` Gleb Natapov
2013-03-13 12:42           ` Xiao Guangrong
2013-03-13 13:40             ` Takuya Yoshikawa
2013-03-13 14:05               ` Xiao Guangrong
2013-03-14  1:58                 ` Marcelo Tosatti
2013-03-14  2:26                   ` Takuya Yoshikawa
2013-03-14  2:39                     ` Marcelo Tosatti
2013-03-14  5:36                       ` Xiao Guangrong
2013-03-14  5:13                   ` Xiao Guangrong
2013-03-14  5:45                     ` Xiao Guangrong
2013-03-16  2:01                     ` Takuya Yoshikawa
2013-03-12  8:45 ` [PATCH 2/2] KVM: x86: Optimize mmio spte zapping when creating/moving memslot Takuya Yoshikawa
2013-03-12 12:06   ` Gleb Natapov
2013-03-13  1:40     ` Marcelo Tosatti [this message]
2013-03-13  1:41 ` [PATCH 0/2] KVM: " Marcelo Tosatti
2013-03-14  8:23 ` 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=20130313014012.GA21171@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=yoshikawa_takuya_b1@lab.ntt.co.jp \
    /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