• Sean Christopherson's avatar
    KVM: x86/mmu: Defer TLB flush to caller when freeing TDP MMU shadow pages · bb95dfb9
    Sean Christopherson authored
    Defer TLB flushes to the caller when freeing TDP MMU shadow pages instead
    of immediately flushing.  Because the shadow pages are freed in an RCU
    callback, so long as at least one CPU holds RCU, all CPUs are protected.
    For vCPUs running in the guest, i.e. consuming TLB entries, KVM only
    needs to ensure the caller services the pending TLB flush before dropping
    its RCU protections.  I.e. use the caller's RCU as a proxy for all vCPUs
    running in the guest.
    
    Deferring the flushes allows batching flushes, e.g. when installing a
    1gb hugepage and zapping a pile of SPs.  And when zapping an entire root,
    deferring flushes allows skipping the flush entirely (because flushes are
    not needed in that case).
    
    Avoiding flushes when zapping an entire root is especially important as
    synchronizing with other CPUs via IPI after zapping every shadow page can
    cause significant performance issues for large VMs.  The issue is
    exacerbated by KVM zapping entire top-level entries without dropping
    RCU protection, which can lead to RCU stalls even when zapping roots
    backing relatively "small" amounts of guest memory, e.g. 2tb.  Removing
    the IPI bottleneck largely mitigates the RCU issues, though it's likely
    still a problem for 5-level paging.  A future patch will further address
    the problem by zapping roots in multiple passes to avoid holding RCU for
    an extended duration.
    Reviewed-by: default avatarBen Gardon <bgardon@google.com>
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Message-Id: <20220226001546.360188-20-seanjc@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    bb95dfb9
tdp_iter.h 2.7 KB