diff options
author | Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> | 2010-09-28 05:03:14 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-10-24 04:53:14 -0400 |
commit | 3377078027dc54dc2a5acb2efa09587e7ac1cbd9 (patch) | |
tree | 284154c590eee075db3164a6ad9315072f3daa10 /arch/x86/kvm/paging_tmpl.h | |
parent | 6903074c367cfb13166c2974d6a886fdc7a00d21 (diff) |
KVM: MMU: move access code parsing to FNAME(walk_addr) function
Move access code parsing from caller site to FNAME(walk_addr) function
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/paging_tmpl.h')
-rw-r--r-- | arch/x86/kvm/paging_tmpl.h | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index a83ff3794055..9a5f7bb5f840 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h | |||
@@ -116,16 +116,18 @@ static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte) | |||
116 | */ | 116 | */ |
117 | static int FNAME(walk_addr_generic)(struct guest_walker *walker, | 117 | static int FNAME(walk_addr_generic)(struct guest_walker *walker, |
118 | struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, | 118 | struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, |
119 | gva_t addr, int write_fault, | 119 | gva_t addr, u32 access) |
120 | int user_fault, int fetch_fault) | ||
121 | { | 120 | { |
122 | pt_element_t pte; | 121 | pt_element_t pte; |
123 | gfn_t table_gfn; | 122 | gfn_t table_gfn; |
124 | unsigned index, pt_access, uninitialized_var(pte_access); | 123 | unsigned index, pt_access, uninitialized_var(pte_access); |
125 | gpa_t pte_gpa; | 124 | gpa_t pte_gpa; |
126 | bool eperm, present, rsvd_fault; | 125 | bool eperm, present, rsvd_fault; |
127 | int offset; | 126 | int offset, write_fault, user_fault, fetch_fault; |
128 | u32 access = 0; | 127 | |
128 | write_fault = access & PFERR_WRITE_MASK; | ||
129 | user_fault = access & PFERR_USER_MASK; | ||
130 | fetch_fault = access & PFERR_FETCH_MASK; | ||
129 | 131 | ||
130 | trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault, | 132 | trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault, |
131 | fetch_fault); | 133 | fetch_fault); |
@@ -215,6 +217,7 @@ walk: | |||
215 | int lvl = walker->level; | 217 | int lvl = walker->level; |
216 | gpa_t real_gpa; | 218 | gpa_t real_gpa; |
217 | gfn_t gfn; | 219 | gfn_t gfn; |
220 | u32 ac; | ||
218 | 221 | ||
219 | gfn = gpte_to_gfn_lvl(pte, lvl); | 222 | gfn = gpte_to_gfn_lvl(pte, lvl); |
220 | gfn += (addr & PT_LVL_OFFSET_MASK(lvl)) >> PAGE_SHIFT; | 223 | gfn += (addr & PT_LVL_OFFSET_MASK(lvl)) >> PAGE_SHIFT; |
@@ -224,10 +227,10 @@ walk: | |||
224 | is_cpuid_PSE36()) | 227 | is_cpuid_PSE36()) |
225 | gfn += pse36_gfn_delta(pte); | 228 | gfn += pse36_gfn_delta(pte); |
226 | 229 | ||
227 | access |= write_fault | fetch_fault | user_fault; | 230 | ac = write_fault | fetch_fault | user_fault; |
228 | 231 | ||
229 | real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(gfn), | 232 | real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(gfn), |
230 | access); | 233 | ac); |
231 | if (real_gpa == UNMAPPED_GVA) | 234 | if (real_gpa == UNMAPPED_GVA) |
232 | return 0; | 235 | return 0; |
233 | 236 | ||
@@ -282,21 +285,18 @@ error: | |||
282 | } | 285 | } |
283 | 286 | ||
284 | static int FNAME(walk_addr)(struct guest_walker *walker, | 287 | static int FNAME(walk_addr)(struct guest_walker *walker, |
285 | struct kvm_vcpu *vcpu, gva_t addr, | 288 | struct kvm_vcpu *vcpu, gva_t addr, u32 access) |
286 | int write_fault, int user_fault, int fetch_fault) | ||
287 | { | 289 | { |
288 | return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.mmu, addr, | 290 | return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.mmu, addr, |
289 | write_fault, user_fault, fetch_fault); | 291 | access); |
290 | } | 292 | } |
291 | 293 | ||
292 | static int FNAME(walk_addr_nested)(struct guest_walker *walker, | 294 | static int FNAME(walk_addr_nested)(struct guest_walker *walker, |
293 | struct kvm_vcpu *vcpu, gva_t addr, | 295 | struct kvm_vcpu *vcpu, gva_t addr, |
294 | int write_fault, int user_fault, | 296 | u32 access) |
295 | int fetch_fault) | ||
296 | { | 297 | { |
297 | return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.nested_mmu, | 298 | return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.nested_mmu, |
298 | addr, write_fault, user_fault, | 299 | addr, access); |
299 | fetch_fault); | ||
300 | } | 300 | } |
301 | 301 | ||
302 | static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, | 302 | static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, |
@@ -532,7 +532,6 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, | |||
532 | { | 532 | { |
533 | int write_fault = error_code & PFERR_WRITE_MASK; | 533 | int write_fault = error_code & PFERR_WRITE_MASK; |
534 | int user_fault = error_code & PFERR_USER_MASK; | 534 | int user_fault = error_code & PFERR_USER_MASK; |
535 | int fetch_fault = error_code & PFERR_FETCH_MASK; | ||
536 | struct guest_walker walker; | 535 | struct guest_walker walker; |
537 | u64 *sptep; | 536 | u64 *sptep; |
538 | int write_pt = 0; | 537 | int write_pt = 0; |
@@ -550,8 +549,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, | |||
550 | /* | 549 | /* |
551 | * Look up the guest pte for the faulting address. | 550 | * Look up the guest pte for the faulting address. |
552 | */ | 551 | */ |
553 | r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault, | 552 | r = FNAME(walk_addr)(&walker, vcpu, addr, error_code); |
554 | fetch_fault); | ||
555 | 553 | ||
556 | /* | 554 | /* |
557 | * The page is not mapped by the guest. Let the guest handle it. | 555 | * The page is not mapped by the guest. Let the guest handle it. |
@@ -669,10 +667,7 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access, | |||
669 | gpa_t gpa = UNMAPPED_GVA; | 667 | gpa_t gpa = UNMAPPED_GVA; |
670 | int r; | 668 | int r; |
671 | 669 | ||
672 | r = FNAME(walk_addr)(&walker, vcpu, vaddr, | 670 | r = FNAME(walk_addr)(&walker, vcpu, vaddr, access); |
673 | access & PFERR_WRITE_MASK, | ||
674 | access & PFERR_USER_MASK, | ||
675 | access & PFERR_FETCH_MASK); | ||
676 | 671 | ||
677 | if (r) { | 672 | if (r) { |
678 | gpa = gfn_to_gpa(walker.gfn); | 673 | gpa = gfn_to_gpa(walker.gfn); |
@@ -690,10 +685,7 @@ static gpa_t FNAME(gva_to_gpa_nested)(struct kvm_vcpu *vcpu, gva_t vaddr, | |||
690 | gpa_t gpa = UNMAPPED_GVA; | 685 | gpa_t gpa = UNMAPPED_GVA; |
691 | int r; | 686 | int r; |
692 | 687 | ||
693 | r = FNAME(walk_addr_nested)(&walker, vcpu, vaddr, | 688 | r = FNAME(walk_addr_nested)(&walker, vcpu, vaddr, access); |
694 | access & PFERR_WRITE_MASK, | ||
695 | access & PFERR_USER_MASK, | ||
696 | access & PFERR_FETCH_MASK); | ||
697 | 689 | ||
698 | if (r) { | 690 | if (r) { |
699 | gpa = gfn_to_gpa(walker.gfn); | 691 | gpa = gfn_to_gpa(walker.gfn); |