public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Avi Kivity <avi@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	KVM list <kvm@vger.kernel.org>,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: [PATCH 3/4] KVM: MMU: track dirty page in speculative path properly
Date: Tue, 13 Jul 2010 17:45:27 +0800	[thread overview]
Message-ID: <4C3C35B7.50101@cn.fujitsu.com> (raw)
In-Reply-To: <4C3C3518.7080505@cn.fujitsu.com>

In speculative path, the page is not real write-access, no need mark it
dirty, so clear dirty bit in this path and later examine this bit when
we release the page

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 arch/x86/kvm/mmu.c |   24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 67dbafa..5e9d4a0 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -315,21 +315,19 @@ static void set_spte_atomic(u64 *sptep, u64 new_spte)
 	pfn = spte_to_pfn(old_spte);
 	if (old_spte & shadow_accessed_mask)
 		kvm_set_pfn_accessed(pfn);
-	if (is_writable_pte(old_spte))
+
+	if ((shadow_dirty_mask && (old_spte & shadow_dirty_mask)) ||
+	      (!shadow_dirty_mask && is_writable_pte(old_spte)))
 		kvm_set_pfn_dirty(pfn);
 }
 
 static void update_spte(u64 *sptep, u64 new_spte)
 {
-	u64 old_spte;
-
-	if (!shadow_accessed_mask || (new_spte & shadow_accessed_mask)) {
+	if ((!shadow_accessed_mask || (new_spte & shadow_accessed_mask)) &&
+	      (!shadow_dirty_mask || (new_spte & shadow_dirty_mask)))
 		__set_spte(sptep, new_spte);
-	} else {
-		old_spte = __xchg_spte(sptep, new_spte);
-		if (old_spte & shadow_accessed_mask)
-			mark_page_accessed(pfn_to_page(spte_to_pfn(old_spte)));
-	}
+	else
+		set_spte_atomic(sptep, new_spte);
 }
 
 static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
@@ -745,7 +743,7 @@ static int rmap_write_protect(struct kvm *kvm, u64 gfn)
 		}
 		spte = rmap_next(kvm, rmapp, spte);
 	}
-	if (write_protected) {
+	if (!shadow_dirty_mask && write_protected) {
 		pfn_t pfn;
 
 		spte = rmap_next(kvm, rmapp, NULL);
@@ -1879,9 +1877,9 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
 	 * whether the guest actually used the pte (in order to detect
 	 * demand paging).
 	 */
-	spte = shadow_base_present_pte | shadow_dirty_mask;
+	spte = shadow_base_present_pte;
 	if (!speculative)
-		spte |= shadow_accessed_mask;
+		spte |= shadow_accessed_mask | shadow_dirty_mask;
 	if (!dirty)
 		pte_access &= ~ACC_WRITE_MASK;
 	if (pte_access & ACC_EXEC_MASK)
@@ -2007,7 +2005,7 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
 		if (rmap_count > RMAP_RECYCLE_THRESHOLD)
 			rmap_recycle(vcpu, sptep, gfn);
 	} else {
-		if (was_writable)
+		if (!shadow_dirty_mask && was_writable)
 			kvm_release_pfn_dirty(pfn);
 		else
 			kvm_release_pfn_clean(pfn);
-- 
1.6.1.2



  parent reply	other threads:[~2010-07-13  9:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-13  9:42 [PATCH 1/4] KVM: MMU: fix forgot reserved bits check in speculative path Xiao Guangrong
2010-07-13  9:43 ` [PATCH 2/4] KVM: MMU: cleanup spte update path Xiao Guangrong
2010-07-13  9:45 ` Xiao Guangrong [this message]
2010-07-13 22:05   ` [PATCH 3/4] KVM: MMU: track dirty page in speculative path properly Marcelo Tosatti
2010-07-14  1:24     ` Xiao Guangrong
2010-07-14 11:09       ` Marcelo Tosatti
2010-07-14 13:18         ` Xiao Guangrong
2010-07-14 14:06           ` Marcelo Tosatti
2010-07-14 14:25             ` Avi Kivity
2010-07-15  7:44             ` Xiao Guangrong
2010-07-15 16:40               ` Marcelo Tosatti
2010-07-16  1:58                 ` Xiao Guangrong
2010-07-14  5:53   ` Xiao Guangrong
2010-07-13  9:46 ` [PATCH 4/4] KVM: MMU: remove valueless output message Xiao Guangrong
2010-07-13 21:28 ` [PATCH 1/4] KVM: MMU: fix forgot reserved bits check in speculative path Marcelo Tosatti
2010-07-14  1:08   ` Xiao Guangrong
2010-07-14 13:06 ` Avi Kivity
2010-07-14 13:24   ` Xiao Guangrong
2010-07-14 14:27     ` Avi Kivity

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=4C3C35B7.50101@cn.fujitsu.com \
    --to=xiaoguangrong@cn.fujitsu.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.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