KVM: PPC: Book3S HV: Fix two bugs in dirty-page tracking

The first bug is that we are testing the C (changed) bit in the hashed
page table without first doing a tlbie.  The architecture allows the
update of the C bit to happen at any time up until we do a tlbie for
the page.  However, we don't want to do a tlbie for every page on every
pass of a migration operation.  Thus we do the tlbie if there are no
vcpus currently running, which would indicate the final phase of
migration.  If any vcpus are running then reading the dirty log is
already racy because pages could get dirtied immediately after we
check them.  Also, we don't need to do the tlbie if the HPT entry
doesn't allow writing, since in that case the C bit can not get set.

The second bug is that in the case where we see a dirty 16MB page
followed by a dirty 4kB page (both mapping to the same guest real
address), we return 1 rather than 16MB / PAGE_SIZE.  The return value,
indicating the number of dirty pages, needs to reflect the largest
dirty page we come across, not the last dirty page we see.

Fixes: 109551 (this time for sure)

Signed-off-by: Paul Mackerras <paulus@samba.org>
1 file changed