Skip to content

Commit 7c8a474

Browse files
dmatlackbonzini
authored andcommitted
KVM: x86/mmu: Fix write-protection of PTs mapped by the TDP MMU
When the TDP MMU is write-protection GFNs for page table protection (as opposed to for dirty logging, or due to the HVA not being writable), it checks if the SPTE is already write-protected and if so skips modifying the SPTE and the TLB flush. This behavior is incorrect because it fails to check if the SPTE is write-protected for page table protection, i.e. fails to check that MMU-writable is '0'. If the SPTE was write-protected for dirty logging but not page table protection, the SPTE could locklessly be made writable, and vCPUs could still be running with writable mappings cached in their TLB. Fix this by only skipping setting the SPTE if the SPTE is already write-protected *and* MMU-writable is already clear. Technically, checking only MMU-writable would suffice; a SPTE cannot be writable without MMU-writable being set. But check both to be paranoid and because it arguably yields more readable code. Fixes: 46044f7 ("kvm: x86/mmu: Support write protection for nesting in tdp MMU") Cc: stable@vger.kernel.org Signed-off-by: David Matlack <dmatlack@google.com> Message-Id: <20220113233020.3986005-2-dmatlack@google.com> Reviewed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 4732f24 commit 7c8a474

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎arch/x86/kvm/mmu/tdp_mmu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,12 +1442,12 @@ static bool write_protect_gfn(struct kvm *kvm, struct kvm_mmu_page *root,
14421442
!is_last_spte(iter.old_spte, iter.level))
14431443
continue;
14441444

1445-
if (!is_writable_pte(iter.old_spte))
1446-
break;
1447-
14481445
new_spte = iter.old_spte &
14491446
~(PT_WRITABLE_MASK | shadow_mmu_writable_mask);
14501447

1448+
if (new_spte == iter.old_spte)
1449+
break;
1450+
14511451
tdp_mmu_set_spte(kvm, &iter, new_spte);
14521452
spte_set = true;
14531453
}

0 commit comments

Comments
 (0)