From: Marcelo Tosatti <mtosatti@redhat.com>
To: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Cc: Avi Kivity <avi@redhat.com>, KVM <kvm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 6/6] KVM: MMU: delay flush all tlbs on sync_page path
Date: Fri, 19 Nov 2010 14:11:18 -0200 [thread overview]
Message-ID: <20101119161118.GB20279@amt.cnet> (raw)
In-Reply-To: <4CE63DE2.9050408@cn.fujitsu.com>
On Fri, Nov 19, 2010 at 05:05:38PM +0800, Xiao Guangrong wrote:
> Quote from Avi:
> | I don't think we need to flush immediately; set a "tlb dirty" bit somewhere
> | that is cleareded when we flush the tlb. kvm_mmu_notifier_invalidate_page()
> | can consult the bit and force a flush if set.
>
> Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
> ---
> arch/x86/kvm/paging_tmpl.h | 4 ++--
> include/linux/kvm_host.h | 7 +++++++
> virt/kvm/kvm_main.c | 8 +++++++-
> 3 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
> index dfb906f..d5c302a 100644
> --- a/arch/x86/kvm/paging_tmpl.h
> +++ b/arch/x86/kvm/paging_tmpl.h
> @@ -781,14 +781,14 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
> gfn = gpte_to_gfn(gpte);
>
> if (FNAME(map_invalid_gpte)(vcpu, sp, &sp->spt[i], gpte)) {
> - kvm_flush_remote_tlbs(vcpu->kvm);
> + kvm_mark_tlbs_dirty(vcpu->kvm);
> continue;
> }
>
> if (gfn != sp->gfns[i]) {
> drop_spte(vcpu->kvm, &sp->spt[i],
> shadow_trap_nonpresent_pte);
> - kvm_flush_remote_tlbs(vcpu->kvm);
> + kvm_mark_tlbs_dirty(vcpu->kvm);
> continue;
> }
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 4bd663d..82d449b 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -249,6 +249,7 @@ struct kvm {
> struct mmu_notifier mmu_notifier;
> unsigned long mmu_notifier_seq;
> long mmu_notifier_count;
> + atomic_t tlbs_dirty;
> #endif
> };
>
> @@ -377,6 +378,12 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu);
> void kvm_resched(struct kvm_vcpu *vcpu);
> void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
> void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
> +
> +static inline void kvm_mark_tlbs_dirty(struct kvm *kvm)
> +{
> + atomic_inc(&kvm->tlbs_dirty);
> +}
> +
> void kvm_flush_remote_tlbs(struct kvm *kvm);
> void kvm_reload_remote_mmus(struct kvm *kvm);
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index fb93ff9..2962569 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -168,8 +168,12 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
>
> void kvm_flush_remote_tlbs(struct kvm *kvm)
> {
> + int dirty_count = atomic_read(&kvm->tlbs_dirty);
> +
> + smp_mb();
> if (make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
> ++kvm->stat.remote_tlb_flush;
> + atomic_sub(dirty_count, &kvm->tlbs_dirty);
> }
This is racy because kvm_flush_remote_tlbs might be called without
mmu_lock protection. You could decrease the counter on
invalidate_page/invalidate_range_start only, these are not fast paths
anyway.
>
> void kvm_reload_remote_mmus(struct kvm *kvm)
> @@ -249,7 +253,8 @@ static void kvm_mmu_notifier_invalidate_page(struct mmu_notifier *mn,
> idx = srcu_read_lock(&kvm->srcu);
> spin_lock(&kvm->mmu_lock);
> kvm->mmu_notifier_seq++;
> - need_tlb_flush = kvm_unmap_hva(kvm, address);
> + need_tlb_flush = kvm_unmap_hva(kvm, address) |
> + atomic_read(&kvm->tlbs_dirty);
> spin_unlock(&kvm->mmu_lock);
> srcu_read_unlock(&kvm->srcu, idx);
>
> @@ -293,6 +298,7 @@ static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
> kvm->mmu_notifier_count++;
> for (; start < end; start += PAGE_SIZE)
> need_tlb_flush |= kvm_unmap_hva(kvm, start);
> + need_tlb_flush |= atomic_read(&kvm->tlbs_dirty);
> spin_unlock(&kvm->mmu_lock);
> srcu_read_unlock(&kvm->srcu, idx);
>
next prev parent reply other threads:[~2010-11-19 16:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-19 9:01 [PATCH v3 1/6] KVM: MMU: fix forgot flush " Xiao Guangrong
2010-11-19 9:02 ` [PATCH v3 2/6] KVM: MMU: don't drop spte if overwrite it from W to RO Xiao Guangrong
2010-11-19 9:03 ` [PATCH v3 3/6] KVM: MMU: rename 'reset_host_protection' to 'host_writable' Xiao Guangrong
2010-11-19 9:04 ` [PATCH v3 4/6] KVM: MMU: remove 'clear_unsync' parameter Xiao Guangrong
2010-11-19 9:04 ` [PATCH v3 5/6] KVM: MMU: abstract invalid guest pte mapping Xiao Guangrong
2010-11-22 9:28 ` Avi Kivity
2010-11-22 10:18 ` Xiao Guangrong
2010-11-22 10:17 ` Avi Kivity
2010-11-23 3:08 ` Xiao Guangrong
2010-11-19 9:05 ` [PATCH v3 6/6] KVM: MMU: delay flush all tlbs on sync_page path Xiao Guangrong
2010-11-19 16:11 ` Marcelo Tosatti [this message]
2010-11-22 3:45 ` Xiao Guangrong
2010-11-22 14:19 ` Marcelo Tosatti
2010-11-22 21:46 ` Marcelo Tosatti
2010-11-23 3:13 ` Xiao Guangrong
2010-11-26 1:37 ` [PATCH v3 1/6] KVM: MMU: fix forgot flush " Xiao Guangrong
2010-11-26 14:29 ` Marcelo Tosatti
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=20101119161118.GB20279@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiaoguangrong@cn.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®