• Paul Mackerras's avatar
    KVM: PPC: Book3S HV: Make sure we don't miss dirty pages · 6c576e74
    Paul Mackerras authored
    Current, when testing whether a page is dirty (when constructing the
    bitmap for the KVM_GET_DIRTY_LOG ioctl), we test the C (changed) bit
    in the HPT entries mapping the page, and if it is 0, we consider the
    page to be clean.  However, the Power ISA doesn't require processors
    to set the C bit to 1 immediately when writing to a page, and in fact
    allows them to delay the writeback of the C bit until they receive a
    TLB invalidation for the page.  Thus it is possible that the page
    could be dirty and we miss it.
    
    Now, if there are vcpus running, this is not serious since the
    collection of the dirty log is racy already - some vcpu could dirty
    the page just after we check it.  But if there are no vcpus running we
    should return definitive results, in case we are in the final phase of
    migrating the guest.
    
    Also, if the permission bits in the HPTE don't allow writing, then we
    know that no CPU can set C.  If the HPTE was previously writable and
    the page was modified, any C bit writeback would have been flushed out
    by the tlbie that we did when changing the HPTE to read-only.
    
    Otherwise we need to do a TLB invalidation even if the C bit is 0, and
    then check the C bit.
    Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
    Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
    6c576e74
book3s_64_mmu_hv.c 42.9 KB