diff mbox

[2/2,rebased] KVM: MMU: Introduce a helper to access lpage_info

Message ID 20101206011354.1321d3fa.takuya.yoshikawa@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Takuya Yoshikawa Dec. 5, 2010, 4:13 p.m. UTC
None
diff mbox

Patch

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index d75ba1e..e434503 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -476,6 +476,12 @@  static void kvm_mmu_page_set_gfn(struct kvm_mmu_page *sp, int index, gfn_t gfn)
 		sp->gfns[index] = gfn;
 }
 
+static unsigned long lpage_idx(gfn_t gfn, gfn_t base_gfn, int level)
+{
+	return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
+	       (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
+}
+
 /*
  * Return the pointer to the largepage write count for a given
  * gfn, handling slots that are not large page aligned.
@@ -484,10 +490,8 @@  static int *slot_largepage_idx(gfn_t gfn,
 			       struct kvm_memory_slot *slot,
 			       int level)
 {
-	unsigned long idx;
+	unsigned long idx = lpage_idx(gfn, slot->base_gfn, level);
 
-	idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
-	      (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
 	return &slot->lpage_info[level - 2][idx].write_count;
 }
 
@@ -591,8 +595,7 @@  static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level)
 	if (likely(level == PT_PAGE_TABLE_LEVEL))
 		return &slot->rmap[gfn - slot->base_gfn];
 
-	idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
-		(slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
+	idx = lpage_idx(gfn, slot->base_gfn, level);
 
 	return &slot->lpage_info[level - 2][idx].rmap_pde;
 }
@@ -887,11 +890,10 @@  static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
 
 			for (j = 0; j < KVM_NR_PAGE_SIZES - 1; ++j) {
 				unsigned long idx;
-				int sh;
 
-				sh = KVM_HPAGE_GFN_SHIFT(PT_DIRECTORY_LEVEL+j);
-				idx = ((memslot->base_gfn+gfn_offset) >> sh) -
-					(memslot->base_gfn >> sh);
+				idx = lpage_idx(memslot->base_gfn + gfn_offset,
+						memslot->base_gfn,
+						PT_DIRECTORY_LEVEL + j);
 				ret |= handler(kvm,
 					&memslot->lpage_info[j][idx].rmap_pde,
 					data);