From patchwork Fri Nov 19 09:05:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 338941 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAJ91r9s008763 for ; Fri, 19 Nov 2010 09:01:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752113Ab0KSJB1 (ORCPT ); Fri, 19 Nov 2010 04:01:27 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:52686 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751641Ab0KSJB0 (ORCPT ); Fri, 19 Nov 2010 04:01:26 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 8218D17070B; Fri, 19 Nov 2010 17:01:24 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id oAJ8ut3L018184; Fri, 19 Nov 2010 16:56:56 +0800 Received: from [10.167.225.99] ([10.167.225.99]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2010111917014106-59923 ; Fri, 19 Nov 2010 17:01:41 +0800 Message-ID: <4CE63DE2.9050408@cn.fujitsu.com> Date: Fri, 19 Nov 2010 17:05:38 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: Avi Kivity CC: Marcelo Tosatti , KVM , LKML Subject: [PATCH v3 6/6] KVM: MMU: delay flush all tlbs on sync_page path References: <4CE63CF4.80502@cn.fujitsu.com> In-Reply-To: <4CE63CF4.80502@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-11-19 17:01:41, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-11-19 17:01:45, Serialize complete at 2010-11-19 17:01:45 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 19 Nov 2010 09:01:55 +0000 (UTC) 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); } 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);