Skip to content

Commit 7a98205

Browse files
Xiao Guangrongbonzini
authored andcommitted
KVM: MMU: fix permission_fault()
kvm-unit-tests complained about the PFEC is not set properly, e.g,: test pte.rw pte.d pte.nx pde.p pde.rw pde.pse user fetch: FAIL: error code 15 expected 5 Dump mapping: address: 0x123400000000 ------L4: 3e95007 ------L3: 3e96007 ------L2: 2000083 It's caused by the reason that PFEC returned to guest is copied from the PFEC triggered by shadow page table This patch fixes it and makes the logic of updating errcode more clean Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com> [Do not assume pfec.p=1. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 4a6cd3b commit 7a98205

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

arch/x86/kvm/mmu.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
173173
int index = (pfec >> 1) +
174174
(smap >> (X86_EFLAGS_AC_BIT - PFERR_RSVD_BIT + 1));
175175
bool fault = (mmu->permissions[index] >> pte_access) & 1;
176+
u32 errcode = PFERR_PRESENT_MASK;
176177

177178
WARN_ON(pfec & (PFERR_PK_MASK | PFERR_RSVD_MASK));
178-
pfec |= PFERR_PRESENT_MASK;
179-
180179
if (unlikely(mmu->pkru_mask)) {
181180
u32 pkru_bits, offset;
182181

@@ -189,15 +188,15 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
189188
pkru_bits = (kvm_read_pkru(vcpu) >> (pte_pkey * 2)) & 3;
190189

191190
/* clear present bit, replace PFEC.RSVD with ACC_USER_MASK. */
192-
offset = pfec - 1 +
191+
offset = (pfec & ~1) +
193192
((pte_access & PT_USER_MASK) << (PFERR_RSVD_BIT - PT_USER_SHIFT));
194193

195194
pkru_bits &= mmu->pkru_mask >> offset;
196-
pfec |= -pkru_bits & PFERR_PK_MASK;
195+
errcode |= -pkru_bits & PFERR_PK_MASK;
197196
fault |= (pkru_bits != 0);
198197
}
199198

200-
return -(uint32_t)fault & pfec;
199+
return -(u32)fault & errcode;
201200
}
202201

203202
void kvm_mmu_invalidate_zap_all_pages(struct kvm *kvm);

arch/x86/kvm/paging_tmpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
360360
goto error;
361361

362362
if (unlikely(is_rsvd_bits_set(mmu, pte, walker->level))) {
363-
errcode |= PFERR_RSVD_MASK | PFERR_PRESENT_MASK;
363+
errcode = PFERR_RSVD_MASK | PFERR_PRESENT_MASK;
364364
goto error;
365365
}
366366

0 commit comments

Comments
 (0)