Move the code to validate an indirect shadow page (by verifying that the gpte
has not changed since it was fetched) into a helper.

Signed-off-by: Avi Kivity <[email protected]>
---
 arch/x86/kvm/paging_tmpl.h |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index cacb4f2..72f54fe 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -299,6 +299,23 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, 
struct kvm_mmu_page *sp,
                     gpte_to_gfn(gpte), pfn, true, true);
 }
 
+static bool FNAME(validate_indirect_spte)(struct kvm_vcpu *vcpu,
+                                         u64 *sptep, struct kvm_mmu_page *sp,
+                                         struct guest_walker *gw, int level)
+{
+       int r;
+       pt_element_t curr_pte;
+
+       r = kvm_read_guest_atomic(vcpu->kvm,
+                                 gw->pte_gpa[level - 2],
+                                 &curr_pte, sizeof(curr_pte));
+       if (r || curr_pte != gw->ptes[level - 2]) {
+               kvm_mmu_put_page(sp, sptep);
+               return false;
+       }
+       return true;
+}
+
 /*
  * Fetch a shadow pte for a specific level in the paging hierarchy.
  */
@@ -312,11 +329,9 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
        u64 *sptep = NULL;
        int direct;
        gfn_t table_gfn;
-       int r;
        int level;
        bool dirty = is_dirty_gpte(gw->ptes[gw->level - 1]);
        unsigned direct_access;
-       pt_element_t curr_pte;
        struct kvm_shadow_walk_iterator iterator;
 
        if (!is_present_gpte(gw->ptes[gw->level - 1]))
@@ -364,17 +379,13 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t 
addr,
                }
                sp = kvm_mmu_get_page(vcpu, table_gfn, addr, level-1,
                                               direct, access, sptep);
-               if (!direct) {
-                       r = kvm_read_guest_atomic(vcpu->kvm,
-                                                 gw->pte_gpa[level - 2],
-                                                 &curr_pte, sizeof(curr_pte));
-                       if (r || curr_pte != gw->ptes[level - 2]) {
-                               kvm_mmu_put_page(sp, sptep);
+               if (!direct)
+                       if (!FNAME(validate_indirect_spte)(vcpu, sptep, sp,
+                                                          gw, level)) {
                                kvm_release_pfn_clean(pfn);
                                sptep = NULL;
                                break;
                        }
-               }
 
                link_shadow_page(sptep, sp);
        }
-- 
1.7.1

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

Reply via email to