• Sean Christopherson's avatar
    KVM: x86/mmu: Add lockdep assert to enforce safe usage of kvm_unmap_gfn_range() · 28cf4978
    Sean Christopherson authored
    Add a lockdep assertion in kvm_unmap_gfn_range() to ensure that either
    mmu_invalidate_in_progress is elevated, or that the range is being zapped
    due to memslot removal (loosely detected by slots_lock being held).
    Zapping SPTEs without mmu_invalidate_{in_progress,seq} protection is unsafe
    as KVM's page fault path snapshots state before acquiring mmu_lock, and
    thus can create SPTEs with stale information if vCPUs aren't forced to
    retry faults (due to seeing an in-progress or past MMU invalidation).
    
    Memslot removal is a special case, as the memslot is retrieved outside of
    mmu_invalidate_seq, i.e. doesn't use the "standard" protections, and
    instead relies on SRCU synchronization to ensure any in-flight page faults
    are fully resolved before zapping SPTEs.
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Message-ID: <20241009192345.1148353-3-seanjc@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    28cf4978
mmu.c 218 KB