In case we grow our RAM after ram_postcopy_incoming_init() (e.g., when synchronizing the RAM block state with the migration source), the resized part would not get discarded. Let's perform that when being notified about a resize while postcopy has been advised and the guest is not running yet.
Cc: "Dr. David Alan Gilbert" <dgilb...@redhat.com> Cc: Juan Quintela <quint...@redhat.com> Cc: Peter Xu <pet...@redhat.com> Signed-off-by: David Hildenbrand <da...@redhat.com> --- migration/ram.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 57f32011a3..cbd54947fb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3722,6 +3722,25 @@ static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host, return; } + /* + * Especially at the start of precopy on the migration target, before + * starting postcopy, we synchronize the RAM block sizes. Let's make sure + * that any resizes before starting the guest are properly handled by + * postcopy. Note: All other postcopy handling (e.g., registering handlers, + * disabling THP) happens after all resizes (e.g., during precopy) were + * performed. + */ + if (postcopy_is_advised() && !runstate_is_running()) { + /* Update what ram_postcopy_incoming_init()->init_range() does. */ + if (old_size < new_size) { + if (ram_discard_range(rb->idstr, old_size, new_size - old_size)) { + error_report("RAM block '%s' discard of resized RAM failed", + rb->idstr); + } + } + return; + } + /* * Some resizes are triggered on the migration target by precopy code, * when synchronizing RAM block sizes. In these cases, the VM is not -- 2.24.1