Commit 33770780 authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Avi Kivity

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: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 6903074c
...@@ -116,16 +116,18 @@ static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte) ...@@ -116,16 +116,18 @@ static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte)
*/ */
static int FNAME(walk_addr_generic)(struct guest_walker *walker, static int FNAME(walk_addr_generic)(struct guest_walker *walker,
struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
gva_t addr, int write_fault, gva_t addr, u32 access)
int user_fault, int fetch_fault)
{ {
pt_element_t pte; pt_element_t pte;
gfn_t table_gfn; gfn_t table_gfn;
unsigned index, pt_access, uninitialized_var(pte_access); unsigned index, pt_access, uninitialized_var(pte_access);
gpa_t pte_gpa; gpa_t pte_gpa;
bool eperm, present, rsvd_fault; bool eperm, present, rsvd_fault;
int offset; int offset, write_fault, user_fault, fetch_fault;
u32 access = 0;
write_fault = access & PFERR_WRITE_MASK;
user_fault = access & PFERR_USER_MASK;
fetch_fault = access & PFERR_FETCH_MASK;
trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault, trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault,
fetch_fault); fetch_fault);
...@@ -215,6 +217,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, ...@@ -215,6 +217,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
int lvl = walker->level; int lvl = walker->level;
gpa_t real_gpa; gpa_t real_gpa;
gfn_t gfn; gfn_t gfn;
u32 ac;
gfn = gpte_to_gfn_lvl(pte, lvl); gfn = gpte_to_gfn_lvl(pte, lvl);
gfn += (addr & PT_LVL_OFFSET_MASK(lvl)) >> PAGE_SHIFT; gfn += (addr & PT_LVL_OFFSET_MASK(lvl)) >> PAGE_SHIFT;
...@@ -224,10 +227,10 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, ...@@ -224,10 +227,10 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
is_cpuid_PSE36()) is_cpuid_PSE36())
gfn += pse36_gfn_delta(pte); gfn += pse36_gfn_delta(pte);
access |= write_fault | fetch_fault | user_fault; ac = write_fault | fetch_fault | user_fault;
real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(gfn), real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(gfn),
access); ac);
if (real_gpa == UNMAPPED_GVA) if (real_gpa == UNMAPPED_GVA)
return 0; return 0;
...@@ -282,21 +285,18 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, ...@@ -282,21 +285,18 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
} }
static int FNAME(walk_addr)(struct guest_walker *walker, static int FNAME(walk_addr)(struct guest_walker *walker,
struct kvm_vcpu *vcpu, gva_t addr, struct kvm_vcpu *vcpu, gva_t addr, u32 access)
int write_fault, int user_fault, int fetch_fault)
{ {
return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.mmu, addr, return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.mmu, addr,
write_fault, user_fault, fetch_fault); access);
} }
static int FNAME(walk_addr_nested)(struct guest_walker *walker, static int FNAME(walk_addr_nested)(struct guest_walker *walker,
struct kvm_vcpu *vcpu, gva_t addr, struct kvm_vcpu *vcpu, gva_t addr,
int write_fault, int user_fault, u32 access)
int fetch_fault)
{ {
return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.nested_mmu, return FNAME(walk_addr_generic)(walker, vcpu, &vcpu->arch.nested_mmu,
addr, write_fault, user_fault, addr, access);
fetch_fault);
} }
static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, 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,7 +532,6 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
{ {
int write_fault = error_code & PFERR_WRITE_MASK; int write_fault = error_code & PFERR_WRITE_MASK;
int user_fault = error_code & PFERR_USER_MASK; int user_fault = error_code & PFERR_USER_MASK;
int fetch_fault = error_code & PFERR_FETCH_MASK;
struct guest_walker walker; struct guest_walker walker;
u64 *sptep; u64 *sptep;
int write_pt = 0; int write_pt = 0;
...@@ -550,8 +549,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, ...@@ -550,8 +549,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
/* /*
* Look up the guest pte for the faulting address. * Look up the guest pte for the faulting address.
*/ */
r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault, r = FNAME(walk_addr)(&walker, vcpu, addr, error_code);
fetch_fault);
/* /*
* The page is not mapped by the guest. Let the guest handle it. * 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,10 +667,7 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr, u32 access,
gpa_t gpa = UNMAPPED_GVA; gpa_t gpa = UNMAPPED_GVA;
int r; int r;
r = FNAME(walk_addr)(&walker, vcpu, vaddr, r = FNAME(walk_addr)(&walker, vcpu, vaddr, access);
access & PFERR_WRITE_MASK,
access & PFERR_USER_MASK,
access & PFERR_FETCH_MASK);
if (r) { if (r) {
gpa = gfn_to_gpa(walker.gfn); 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,10 +685,7 @@ static gpa_t FNAME(gva_to_gpa_nested)(struct kvm_vcpu *vcpu, gva_t vaddr,
gpa_t gpa = UNMAPPED_GVA; gpa_t gpa = UNMAPPED_GVA;
int r; int r;
r = FNAME(walk_addr_nested)(&walker, vcpu, vaddr, r = FNAME(walk_addr_nested)(&walker, vcpu, vaddr, access);
access & PFERR_WRITE_MASK,
access & PFERR_USER_MASK,
access & PFERR_FETCH_MASK);
if (r) { if (r) {
gpa = gfn_to_gpa(walker.gfn); gpa = gfn_to_gpa(walker.gfn);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment