Skip to content

Commit fdaa293

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Get CR0.WP from MMU, not vCPU, in shadow page fault
Use the current MMU instead of vCPU state to query CR0.WP when handling a page fault. In the nested NPT case, the current CR0.WP reflects L2, whereas the page fault is shadowing L1's NPT. Practically speaking, this is a nop a NPT walks are always user faults, but fix it up for consistency. Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20210622175739.3610207-53-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f82fdaf commit fdaa293

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

arch/x86/kvm/mmu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ static inline bool is_writable_pte(unsigned long pte)
165165
return pte & PT_WRITABLE_MASK;
166166
}
167167

168-
static inline bool is_write_protection(struct kvm_vcpu *vcpu)
169-
{
170-
return kvm_read_cr0_bits(vcpu, X86_CR0_WP);
171-
}
172-
173168
/*
174169
* Check if a given access (described through the I/D, W/R and U/S bits of a
175170
* page fault error code pfec) causes a permission fault with the given PTE

arch/x86/kvm/mmu/paging_tmpl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ FNAME(is_self_change_mapping)(struct kvm_vcpu *vcpu,
795795
bool self_changed = false;
796796

797797
if (!(walker->pte_access & ACC_WRITE_MASK ||
798-
(!is_write_protection(vcpu) && !user_fault)))
798+
(!is_cr0_wp(vcpu->arch.mmu) && !user_fault)))
799799
return false;
800800

801801
for (level = walker->level; level <= walker->max_level; level++) {
@@ -893,8 +893,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gpa_t addr, u32 error_code,
893893
* we will cache the incorrect access into mmio spte.
894894
*/
895895
if (write_fault && !(walker.pte_access & ACC_WRITE_MASK) &&
896-
!is_write_protection(vcpu) && !user_fault &&
897-
!is_noslot_pfn(pfn)) {
896+
!is_cr0_wp(vcpu->arch.mmu) && !user_fault && !is_noslot_pfn(pfn)) {
898897
walker.pte_access |= ACC_WRITE_MASK;
899898
walker.pte_access &= ~ACC_USER_MASK;
900899

0 commit comments

Comments
 (0)