It can calculate the base gpa of the specified shadow page on any level,
let it instead of FNAME(get_level1_sp_gpa)

Signed-off-by: Xiao Guangrong <xiaoguangr...@linux.vnet.ibm.com>
---
 arch/x86/kvm/paging_tmpl.h |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index b9fd1c4..f0fbde3 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -558,6 +558,16 @@ out_gpte_changed:
        return NULL;
 }

+static gpa_t FNAME(get_sp_gpa)(struct kvm_mmu_page *sp)
+{
+       int offset, shift;
+
+       shift = PAGE_SHIFT - (PT_LEVEL_BITS - PT64_LEVEL_BITS) * sp->role.level;
+       offset = sp->role.quadrant << shift;
+
+       return gfn_to_gpa(sp->gfn) + offset;
+}
+
 /*
  * Page fault handler.  There are several causes for a page fault:
  *   - there is no shadow pte for the guest pte
@@ -659,18 +669,6 @@ out_unlock:
        return 0;
 }

-static gpa_t FNAME(get_level1_sp_gpa)(struct kvm_mmu_page *sp)
-{
-       int offset = 0;
-
-       WARN_ON(sp->role.level != 1);
-
-       if (PTTYPE == 32)
-               offset = sp->role.quadrant << PT64_LEVEL_BITS;
-
-       return gfn_to_gpa(sp->gfn) + offset * sizeof(pt_element_t);
-}
-
 static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
 {
        struct kvm_shadow_walk_iterator iterator;
@@ -699,7 +697,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
                        if (!sp->unsync)
                                break;

-                       pte_gpa = FNAME(get_level1_sp_gpa)(sp);
+                       pte_gpa = FNAME(get_sp_gpa)(sp);
                        pte_gpa += (sptep - sp->spt) * sizeof(pt_element_t);

                        if (mmu_page_zap_pte(vcpu->kvm, sp, sptep))
@@ -780,7 +778,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct 
kvm_mmu_page *sp)
        /* direct kvm_mmu_page can not be unsync. */
        BUG_ON(sp->role.direct);

-       first_pte_gpa = FNAME(get_level1_sp_gpa)(sp);
+       first_pte_gpa = FNAME(get_sp_gpa)(sp);

        for (i = 0; i < PT64_ENT_PER_PAGE; i++) {
                unsigned pte_access;
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to