Commit f59c1d2d authored by Avi Kivity's avatar Avi Kivity

KVM: MMU: Keep going on permission error

Real hardware disregards permission errors when computing page fault error
code bit 0 (page present).  Do the same.
Reviewed-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent b0eeec29
...@@ -119,21 +119,25 @@ static int FNAME(walk_addr)(struct guest_walker *walker, ...@@ -119,21 +119,25 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
{ {
pt_element_t pte; pt_element_t pte;
gfn_t table_gfn; gfn_t table_gfn;
unsigned index, pt_access, pte_access; unsigned index, pt_access, uninitialized_var(pte_access);
gpa_t pte_gpa; gpa_t pte_gpa;
int rsvd_fault = 0; bool eperm, present, rsvd_fault;
trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault, trace_kvm_mmu_pagetable_walk(addr, write_fault, user_fault,
fetch_fault); fetch_fault);
walk: walk:
present = true;
eperm = rsvd_fault = false;
walker->level = vcpu->arch.mmu.root_level; walker->level = vcpu->arch.mmu.root_level;
pte = vcpu->arch.cr3; pte = vcpu->arch.cr3;
#if PTTYPE == 64 #if PTTYPE == 64
if (!is_long_mode(vcpu)) { if (!is_long_mode(vcpu)) {
pte = kvm_pdptr_read(vcpu, (addr >> 30) & 3); pte = kvm_pdptr_read(vcpu, (addr >> 30) & 3);
trace_kvm_mmu_paging_element(pte, walker->level); trace_kvm_mmu_paging_element(pte, walker->level);
if (!is_present_gpte(pte)) if (!is_present_gpte(pte)) {
goto not_present; present = false;
goto error;
}
--walker->level; --walker->level;
} }
#endif #endif
...@@ -151,31 +155,36 @@ static int FNAME(walk_addr)(struct guest_walker *walker, ...@@ -151,31 +155,36 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
walker->table_gfn[walker->level - 1] = table_gfn; walker->table_gfn[walker->level - 1] = table_gfn;
walker->pte_gpa[walker->level - 1] = pte_gpa; walker->pte_gpa[walker->level - 1] = pte_gpa;
if (kvm_read_guest(vcpu->kvm, pte_gpa, &pte, sizeof(pte))) if (kvm_read_guest(vcpu->kvm, pte_gpa, &pte, sizeof(pte))) {
goto not_present; present = false;
break;
}
trace_kvm_mmu_paging_element(pte, walker->level); trace_kvm_mmu_paging_element(pte, walker->level);
if (!is_present_gpte(pte)) if (!is_present_gpte(pte)) {
goto not_present; present = false;
break;
}
rsvd_fault = is_rsvd_bits_set(vcpu, pte, walker->level); if (is_rsvd_bits_set(vcpu, pte, walker->level)) {
if (rsvd_fault) rsvd_fault = true;
goto access_error; break;
}
if (write_fault && !is_writable_pte(pte)) if (write_fault && !is_writable_pte(pte))
if (user_fault || is_write_protection(vcpu)) if (user_fault || is_write_protection(vcpu))
goto access_error; eperm = true;
if (user_fault && !(pte & PT_USER_MASK)) if (user_fault && !(pte & PT_USER_MASK))
goto access_error; eperm = true;
#if PTTYPE == 64 #if PTTYPE == 64
if (fetch_fault && (pte & PT64_NX_MASK)) if (fetch_fault && (pte & PT64_NX_MASK))
goto access_error; eperm = true;
#endif #endif
if (!(pte & PT_ACCESSED_MASK)) { if (!eperm && !rsvd_fault && !(pte & PT_ACCESSED_MASK)) {
trace_kvm_mmu_set_accessed_bit(table_gfn, index, trace_kvm_mmu_set_accessed_bit(table_gfn, index,
sizeof(pte)); sizeof(pte));
if (FNAME(cmpxchg_gpte)(vcpu->kvm, table_gfn, if (FNAME(cmpxchg_gpte)(vcpu->kvm, table_gfn,
...@@ -214,6 +223,9 @@ static int FNAME(walk_addr)(struct guest_walker *walker, ...@@ -214,6 +223,9 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
--walker->level; --walker->level;
} }
if (!present || eperm || rsvd_fault)
goto error;
if (write_fault && !is_dirty_gpte(pte)) { if (write_fault && !is_dirty_gpte(pte)) {
bool ret; bool ret;
...@@ -233,14 +245,10 @@ static int FNAME(walk_addr)(struct guest_walker *walker, ...@@ -233,14 +245,10 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
__func__, (u64)pte, pte_access, pt_access); __func__, (u64)pte, pte_access, pt_access);
return 1; return 1;
not_present: error:
walker->error_code = 0; walker->error_code = 0;
goto err; if (present)
walker->error_code |= PFERR_PRESENT_MASK;
access_error:
walker->error_code = PFERR_PRESENT_MASK;
err:
if (write_fault) if (write_fault)
walker->error_code |= PFERR_WRITE_MASK; walker->error_code |= PFERR_WRITE_MASK;
if (user_fault) if (user_fault)
......
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