• Junaid Shahid's avatar
    kvm: x86: mmu: Always flush TLBs when enabling dirty logging · b64d740e
    Junaid Shahid authored
    When A/D bits are not available, KVM uses a software access tracking
    mechanism, which involves making the SPTEs inaccessible. However,
    the clear_young() MMU notifier does not flush TLBs. So it is possible
    that there may still be stale, potentially writable, TLB entries.
    This is usually fine, but can be problematic when enabling dirty
    logging, because it currently only does a TLB flush if any SPTEs were
    modified. But if all SPTEs are in access-tracked state, then there
    won't be a TLB flush, which means that the guest could still possibly
    write to memory and not have it reflected in the dirty bitmap.
    
    So just unconditionally flush the TLBs when enabling dirty logging.
    As an alternative, KVM could explicitly check the MMU-Writable bit when
    write-protecting SPTEs to decide if a flush is needed (instead of
    checking the Writable bit), but given that a flush almost always happens
    anyway, so just making it unconditional seems simpler.
    Signed-off-by: default avatarJunaid Shahid <junaids@google.com>
    Message-Id: <20220810224939.2611160-1-junaids@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    b64d740e
x86.c 354 KB