aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2008-03-23 09:06:23 -0400
committerAvi Kivity <avi@qumranet.com>2008-04-27 05:00:35 -0400
commit0b49ea8659fd3b5005823e02d2d0a775521770e5 (patch)
tree8ae968a018fac99eb923714e77ae87e02fe11d51 /arch/x86/kvm
parent855149aaa90016c576a0e684361a34f8047307d0 (diff)
KVM: MMU: Introduce and use spte_to_page()
Encapsulate the pte mask'n'shift in a function. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r--arch/x86/kvm/mmu.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index dd4b95b3896b..6fc342194dda 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -240,6 +240,13 @@ static int is_rmap_pte(u64 pte)
240 return is_shadow_present_pte(pte); 240 return is_shadow_present_pte(pte);
241} 241}
242 242
243static struct page *spte_to_page(u64 pte)
244{
245 hfn_t hfn = (pte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
246
247 return pfn_to_page(hfn);
248}
249
243static gfn_t pse36_gfn_delta(u32 gpte) 250static gfn_t pse36_gfn_delta(u32 gpte)
244{ 251{
245 int shift = 32 - PT32_DIR_PSE36_SHIFT - PAGE_SHIFT; 252 int shift = 32 - PT32_DIR_PSE36_SHIFT - PAGE_SHIFT;
@@ -541,7 +548,7 @@ static void rmap_remove(struct kvm *kvm, u64 *spte)
541 if (!is_rmap_pte(*spte)) 548 if (!is_rmap_pte(*spte))
542 return; 549 return;
543 sp = page_header(__pa(spte)); 550 sp = page_header(__pa(spte));
544 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT); 551 page = spte_to_page(*spte);
545 mark_page_accessed(page); 552 mark_page_accessed(page);
546 if (is_writeble_pte(*spte)) 553 if (is_writeble_pte(*spte))
547 kvm_release_page_dirty(page); 554 kvm_release_page_dirty(page);
@@ -630,7 +637,7 @@ static void rmap_write_protect(struct kvm *kvm, u64 gfn)
630 struct page *page; 637 struct page *page;
631 638
632 spte = rmap_next(kvm, rmapp, NULL); 639 spte = rmap_next(kvm, rmapp, NULL);
633 page = pfn_to_page((*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT); 640 page = spte_to_page(*spte);
634 SetPageDirty(page); 641 SetPageDirty(page);
635 } 642 }
636 643
@@ -1033,7 +1040,6 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
1033 u64 spte; 1040 u64 spte;
1034 int was_rmapped = 0; 1041 int was_rmapped = 0;
1035 int was_writeble = is_writeble_pte(*shadow_pte); 1042 int was_writeble = is_writeble_pte(*shadow_pte);
1036 hfn_t host_pfn = (*shadow_pte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
1037 1043
1038 pgprintk("%s: spte %llx access %x write_fault %d" 1044 pgprintk("%s: spte %llx access %x write_fault %d"
1039 " user_fault %d gfn %lx\n", 1045 " user_fault %d gfn %lx\n",
@@ -1051,9 +1057,10 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
1051 1057
1052 child = page_header(pte & PT64_BASE_ADDR_MASK); 1058 child = page_header(pte & PT64_BASE_ADDR_MASK);
1053 mmu_page_remove_parent_pte(child, shadow_pte); 1059 mmu_page_remove_parent_pte(child, shadow_pte);
1054 } else if (host_pfn != page_to_pfn(page)) { 1060 } else if (page != spte_to_page(*shadow_pte)) {
1055 pgprintk("hfn old %lx new %lx\n", 1061 pgprintk("hfn old %lx new %lx\n",
1056 host_pfn, page_to_pfn(page)); 1062 page_to_pfn(spte_to_page(*shadow_pte)),
1063 page_to_pfn(page));
1057 rmap_remove(vcpu->kvm, shadow_pte); 1064 rmap_remove(vcpu->kvm, shadow_pte);
1058 } else { 1065 } else {
1059 if (largepage) 1066 if (largepage)