]> err.no Git - linux-2.6/blobdiff - drivers/kvm/paging_tmpl.h
[POWERPC] spu sched: static timeslicing for SCHED_RR contexts
[linux-2.6] / drivers / kvm / paging_tmpl.h
index afcd2a8f45bbc5d42c2fb97ca0dacae45a9abe59..b6b90e9e13013eeab29adc4bc30c5cb1657f5732 100644 (file)
@@ -71,7 +71,7 @@ struct guest_walker {
  */
 static int FNAME(walk_addr)(struct guest_walker *walker,
                            struct kvm_vcpu *vcpu, gva_t addr,
-                           int write_fault, int user_fault)
+                           int write_fault, int user_fault, int fetch_fault)
 {
        hpa_t hpa;
        struct kvm_memory_slot *slot;
@@ -123,6 +123,11 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
                if (user_fault && !(*ptep & PT_USER_MASK))
                        goto access_error;
 
+#if PTTYPE == 64
+               if (fetch_fault && is_nx(vcpu) && (*ptep & PT64_NX_MASK))
+                       goto access_error;
+#endif
+
                if (!(*ptep & PT_ACCESSED_MASK))
                        *ptep |= PT_ACCESSED_MASK;      /* avoid rmw */
 
@@ -169,6 +174,8 @@ err:
                walker->error_code |= PFERR_WRITE_MASK;
        if (user_fault)
                walker->error_code |= PFERR_USER_MASK;
+       if (fetch_fault)
+               walker->error_code |= PFERR_FETCH_MASK;
        return 0;
 }
 
@@ -372,6 +379,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
 {
        int write_fault = error_code & PFERR_WRITE_MASK;
        int user_fault = error_code & PFERR_USER_MASK;
+       int fetch_fault = error_code & PFERR_FETCH_MASK;
        struct guest_walker walker;
        u64 *shadow_pte;
        int fixed;
@@ -388,7 +396,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
        /*
         * Look up the shadow pte for the faulting address.
         */
-       r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault);
+       r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault,
+                            fetch_fault);
 
        /*
         * The page is not mapped by the guest.  Let the guest handle it.
@@ -434,31 +443,17 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
 static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
 {
        struct guest_walker walker;
-       pt_element_t guest_pte;
-       gpa_t gpa;
-
-       FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0);
-       guest_pte = *walker.ptep;
-       FNAME(release_walker)(&walker);
-
-       if (!is_present_pte(guest_pte))
-               return UNMAPPED_GVA;
-
-       if (walker.level == PT_DIRECTORY_LEVEL) {
-               ASSERT((guest_pte & PT_PAGE_SIZE_MASK));
-               ASSERT(PTTYPE == 64 || is_pse(vcpu));
+       gpa_t gpa = UNMAPPED_GVA;
+       int r;
 
-               gpa = (guest_pte & PT_DIR_BASE_ADDR_MASK) | (vaddr &
-                       (PT_LEVEL_MASK(PT_PAGE_TABLE_LEVEL) | ~PAGE_MASK));
+       r = FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0);
 
-               if (PTTYPE == 32 && is_cpuid_PSE36())
-                       gpa |= (guest_pte & PT32_DIR_PSE36_MASK) <<
-                                       (32 - PT32_DIR_PSE36_SHIFT);
-       } else {
-               gpa = (guest_pte & PT_BASE_ADDR_MASK);
-               gpa |= (vaddr & ~PAGE_MASK);
+       if (r) {
+               gpa = (gpa_t)walker.gfn << PAGE_SHIFT;
+               gpa |= vaddr & ~PAGE_MASK;
        }
 
+       FNAME(release_walker)(&walker);
        return gpa;
 }