Skip to contentSkip to conversation

KVM: MMU: simple cleanups

PATCH Applied Xiao Guangrong 3 participants 6 messages Feb 5, 2013 – Feb 8, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover KVM: MMU: simple cleanups

There are the simple cleanups for MMU, no function / logic changed.

Marcelo, Gleb, please apply them after applying
"[PATCH v3] KVM: MMU: lazily drop large spte"

Changelog:
no change, just split them from the previous patchset for good review.

Thanks!

#1 lore raw

PATCH v3 1/3 KVM: MMU: cleanup mapping-level

Use min() to cleanup mapping_level

---
 arch/x86/kvm/mmu.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu.c +1 -2
index ff2fc80..fe877da 100644
@@ -832,8 +832,7 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)
 	if (host_level == PT_PAGE_TABLE_LEVEL)
 		return host_level;
 
-	max_level = kvm_x86_ops->get_lpage_level() < host_level ?
-		kvm_x86_ops->get_lpage_level() : host_level;
+	max_level = min(kvm_x86_ops->get_lpage_level(), host_level);
 
 	for (level = PT_DIRECTORY_LEVEL; level <= max_level; ++level)
 		if (has_wrprotected_page(vcpu->kvm, large_gfn, level))
Signature · 1 line
1.7.7.6
#2 lore raw

PATCH v3 2/3 KVM: MMU: remove pt_access in mmu_set_spte

In reply to Xiao Guangrong

It is only used in debug code, so drop it

---
 arch/x86/kvm/mmu.c         |   17 +++++++----------
 arch/x86/kvm/paging_tmpl.h |    9 ++++-----
 2 files changed, 11 insertions(+), 15 deletions(-)
arch/x86/kvm/mmu.c +7 -10
index fe877da..2112c1b 100644
@@ -2403,16 +2403,15 @@ done:
 }
 
 static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
-			 unsigned pt_access, unsigned pte_access,
-			 int write_fault, int *emulate, int level, gfn_t gfn,
-			 pfn_t pfn, bool speculative, bool host_writable)
+			 unsigned pte_access, int write_fault, int *emulate,
+			 int level, gfn_t gfn, pfn_t pfn, bool speculative,
+			 bool host_writable)
 {
 	int was_rmapped = 0;
 	int rmap_count;
 
-	pgprintk("%s: spte %llx access %x write_fault %d gfn %llx\n",
-		 __func__, *sptep, pt_access,
-		 write_fault, gfn);
+	pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
+		 *sptep, write_fault, gfn);
 
 	if (is_rmap_spte(*sptep)) {
 		/*
@@ -2528,7 +2527,7 @@ static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu,
 		return -1;
 
 	for (i = 0; i < ret; i++, gfn++, start++)
-		mmu_set_spte(vcpu, start, ACC_ALL, access, 0, NULL,
+		mmu_set_spte(vcpu, start, access, 0, NULL,
 			     sp->role.level, gfn, page_to_pfn(pages[i]),
 			     true, true);
 
@@ -2589,9 +2588,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
 
 	for_each_shadow_entry(vcpu, (u64)gfn << PAGE_SHIFT, iterator) {
 		if (iterator.level == level) {
-			unsigned pte_access = ACC_ALL;
-
-			mmu_set_spte(vcpu, iterator.sptep, ACC_ALL, pte_access,
+			mmu_set_spte(vcpu, iterator.sptep, ACC_ALL,
 				     write, &emulate, level, gfn, pfn,
 				     prefault, map_writable);
 			direct_pte_prefetch(vcpu, iterator.sptep);
arch/x86/kvm/paging_tmpl.h +4 -5
index 34c5c99..105dd5b 100644
@@ -326,8 +326,8 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
 	 * we call mmu_set_spte() with host_writable = true because
 	 * pte_prefetch_gfn_to_pfn always gets a writable pfn.
 	 */
-	mmu_set_spte(vcpu, spte, sp->role.access, pte_access, 0,
-		     NULL, PT_PAGE_TABLE_LEVEL, gfn, pfn, true, true);
+	mmu_set_spte(vcpu, spte, pte_access, 0, NULL, PT_PAGE_TABLE_LEVEL,
+		     gfn, pfn, true, true);
 
 	return true;
 }
@@ -470,9 +470,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
 	}
 
 	clear_sp_write_flooding_count(it.sptep);
-	mmu_set_spte(vcpu, it.sptep, access, gw->pte_access,
-		     write_fault, &emulate, it.level,
-		     gw->gfn, pfn, prefault, map_writable);
+	mmu_set_spte(vcpu, it.sptep, gw->pte_access, write_fault, &emulate,
+		     it.level, gw->gfn, pfn, prefault, map_writable);
 	FNAME(pte_prefetch)(vcpu, gw, it.sptep);
 
 	return emulate;
Signature · 1 line
1.7.7.6
#3 lore raw

PATCH v3 3/3 KVM: MMU: cleanup __direct_map

In reply to Xiao Guangrong

Use link_shadow_page to link the sp to the spte in __direct_map

---
 arch/x86/kvm/mmu.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
arch/x86/kvm/mmu.c +4 -8
index 2112c1b..8041454 100644
@@ -1961,9 +1961,9 @@ static void link_shadow_page(u64 *sptep, struct kvm_mmu_page *sp)
 {
 	u64 spte;
 
-	spte = __pa(sp->spt)
-		| PT_PRESENT_MASK | PT_ACCESSED_MASK
-		| PT_WRITABLE_MASK | PT_USER_MASK;
+	spte = __pa(sp->spt) | PT_PRESENT_MASK | PT_WRITABLE_MASK |
+	       shadow_user_mask | shadow_x_mask | shadow_accessed_mask;
+
 	mmu_spte_set(sptep, spte);
 }
 
@@ -2607,11 +2607,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
 					      iterator.level - 1,
 					      1, ACC_ALL, iterator.sptep);
 
-			mmu_spte_set(iterator.sptep,
-				     __pa(sp->spt)
-				     | PT_PRESENT_MASK | PT_WRITABLE_MASK
-				     | shadow_user_mask | shadow_x_mask
-				     | shadow_accessed_mask);
+			link_shadow_page(iterator.sptep, sp);
 		}
 	}
 	return emulate;
Signature · 1 line
1.7.7.6
Reviewed-by on the v3 series
#4 lore raw
In reply to Xiao Guangrong
Quoted 9 lines · Xiao Guangrong

There are the simple cleanups for MMU, no function / logic changed.

Marcelo, Gleb, please apply them after applying
"[PATCH v3] KVM: MMU: lazily drop large spte"

Changelog:
no change, just split them from the previous patchset for good review.

Thanks!

--
Gleb.

#5 lore raw
In reply to Xiao Guangrong
Quoted 9 lines · Xiao Guangrong

There are the simple cleanups for MMU, no function / logic changed.

Marcelo, Gleb, please apply them after applying
"[PATCH v3] KVM: MMU: lazily drop large spte"

Changelog:
no change, just split them from the previous patchset for good review.

Thanks!

Applied, thanks.