KVM: PPC: Book3S HV: Make sure we don't miss dirty pages
authorPaul Mackerras <paulus@samba.org>
Mon, 26 May 2014 09:48:39 +0000 (19:48 +1000)
committerAlexander Graf <agraf@suse.de>
Fri, 30 May 2014 12:26:29 +0000 (14:26 +0200)
commit6c576e74fd91b93ca1eedcd9eb5200171d2ba32b
tree6b7563c0ef1a9b9f1166ea3b594220de96c7981a
parent687414bebe30d59c766b682cf86b1c5fa92d7af9
KVM: PPC: Book3S HV: Make sure we don't miss dirty pages

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: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
arch/powerpc/kvm/book3s_64_mmu_hv.c