migration/ram: Handle RAM block resizes during postcopy
commit898ba906ccb85ba17d65e64a31cc13128803ef86
authorDavid Hildenbrand <david@redhat.com>
Thu, 29 Apr 2021 11:27:06 +0000 (29 13:27 +0200)
committerDr. David Alan Gilbert <dgilbert@redhat.com>
Thu, 13 May 2021 17:21:14 +0000 (13 18:21 +0100)
tree1093d1525e1588c44424e9f3663f6c29ceb1a2a9
parent6a23f6399a1f8807447f8680f80e4d536522683e
migration/ram: Handle RAM block resizes during postcopy

Resizing while migrating is dangerous and does not work as expected.
The whole migration code works with the usable_length of a ram block and
does not expect this value to change at random points in time.

In the case of postcopy, relying on used_length is racy as soon as the
guest is running. Also, when used_length changes we might leave the
uffd handler registered for some memory regions, reject valid pages
when migrating and fail when sending the recv bitmap to the source.

Resizing can be trigger *after* (but not during) a reset in
ACPI code by the guest
- hw/arm/virt-acpi-build.c:acpi_ram_update()
- hw/i386/acpi-build.c:acpi_ram_update()

Let's remember the original used_length in a separate variable and
use it in relevant postcopy code. Make sure to update it when we resize
during precopy, when synchronizing the RAM block sizes with the source.

Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20210429112708.12291-9-david@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
include/exec/ramblock.h
migration/postcopy-ram.c
migration/ram.c