kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/7] KVM: MMU: optimize pte write path if don't have protected sp
@ 2011-05-15 15:20 Xiao Guangrong
  2011-05-15 15:22 ` [PATCH v2 2/7] KVM: use __copy_to_user/__clear_user to write guest page Xiao Guangrong
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Xiao Guangrong @ 2011-05-15 15:20 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, LKML, KVM

Simply return from kvm_mmu_pte_write path if no shadow page is
write-protected, then we can avoid to walk all shadow pages and hold
mmu-lock

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 arch/x86/include/asm/kvm_host.h |    1 +
 arch/x86/kvm/mmu.c              |    9 +++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index d2ac8e2..152601a 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -441,6 +441,7 @@ struct kvm_arch {
 	unsigned int n_used_mmu_pages;
 	unsigned int n_requested_mmu_pages;
 	unsigned int n_max_mmu_pages;
+	unsigned int indirect_shadow_pages;
 	atomic_t invlpg_counter;
 	struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
 	/*
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 2841805..ad520d4 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -498,6 +498,7 @@ static void account_shadowed(struct kvm *kvm, gfn_t gfn)
 		linfo = lpage_info_slot(gfn, slot, i);
 		linfo->write_count += 1;
 	}
+	kvm->arch.indirect_shadow_pages++;
 }
 
 static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn)
@@ -513,6 +514,7 @@ static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn)
 		linfo->write_count -= 1;
 		WARN_ON(linfo->write_count < 0);
 	}
+	kvm->arch.indirect_shadow_pages--;
 }
 
 static int has_wrprotected_page(struct kvm *kvm,
@@ -3233,6 +3235,13 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 	int level, npte, invlpg_counter, r, flooded = 0;
 	bool remote_flush, local_flush, zap_page;
 
+	/*
+	 * If we don't have indirect shadow pages, it means no page is
+	 * write-protected, so we can exit simply.
+	 */
+	if (!ACCESS_ONCE(vcpu->kvm->arch.indirect_shadow_pages))
+		return;
+
 	zap_page = remote_flush = local_flush = false;
 	offset = offset_in_page(gpa);
 
-- 
1.7.4.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-05-20 21:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-15 15:20 [PATCH v2 1/7] KVM: MMU: optimize pte write path if don't have protected sp Xiao Guangrong
2011-05-15 15:22 ` [PATCH v2 2/7] KVM: use __copy_to_user/__clear_user to write guest page Xiao Guangrong
2011-05-15 15:25 ` [PATCH v2 3/7] KVM: fix uninitialized warning Xiao Guangrong
2011-05-15 15:26 ` [PATCH v2 4/7] KVM: MMU: abstract the operation of rmap Xiao Guangrong
2011-05-15 15:27 ` [PATCH v2 5/7] KVM: MMU: remove the arithmetic of parent pte rmap Xiao Guangrong
2011-05-15 15:27 ` [PATCH v2 6/7] KVM: MMU: cleanup for kvm_mmu_page_unlink_children Xiao Guangrong
2011-05-15 15:28 ` [PATCH v2 7/7] KVM: MMU: cleanup for dropping parent pte Xiao Guangrong
2011-05-16 11:25 ` [PATCH v2 1/7] KVM: MMU: optimize pte write path if don't have protected sp Avi Kivity
2011-05-18 13:12   ` Marcelo Tosatti
2011-05-18 13:20     ` Avi Kivity
2011-05-20 15:49 ` Marcelo Tosatti

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).