• Sean Christopherson's avatar
    KVM: x86/mmu: Skip invalid TDP MMU roots when write-protecting SPTEs · d7461823
    Sean Christopherson authored
    When write-protecting SPTEs, don't process invalid roots as invalid roots
    are unreachable, i.e. can't be used to access guest memory and thus don't
    need to be write-protected.
    
    Note, this is *almost* a nop for kvm_tdp_mmu_clear_dirty_pt_masked(),
    which is called under slots_lock, i.e. is mutually exclusive with
    kvm_mmu_zap_all_fast().  But it's possible for something other than the
    "fast zap" thread to grab a reference to an invalid root and thus keep a
    root alive (but completely empty) after kvm_mmu_zap_all_fast() completes.
    
    The kvm_tdp_mmu_write_protect_gfn() case is more interesting as KVM write-
    protects SPTEs for reasons other than dirty logging, e.g. if a KVM creates
    a SPTE for a nested VM while a fast zap is in-progress.
    
    Add another TDP MMU iterator to visit only valid roots, and
    opportunistically convert kvm_tdp_mmu_get_vcpu_root_hpa() to said iterator.
    
    Link: https://lore.kernel.org/r/20240111020048.844847-6-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
    d7461823
tdp_mmu.c 55 KB