migration: ram block cpr blockers

Unlike cpr-reboot mode, cpr-transfer mode cannot save volatile ram blocks
in the migration stream file and recreate them later, because the physical
memory for the blocks is pinned and registered for vfio.  Add a blocker
for volatile ram blocks.

Also add a blocker for RAM_GUEST_MEMFD.  Preserving guest_memfd may be
sufficient for CPR, but it has not been tested yet.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-ID: <1740667681-257312-1-git-send-email-steven.sistare@oracle.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
Steve Sistare 2025-02-27 06:48:01 -08:00 committed by Fabiano Rosas
parent d657a14de5
commit 094a3dbc55
4 changed files with 72 additions and 0 deletions

View file

@ -71,7 +71,10 @@
#include "qemu/pmem.h"
#include "qapi/qapi-types-migration.h"
#include "migration/blocker.h"
#include "migration/cpr.h"
#include "migration/options.h"
#include "migration/vmstate.h"
#include "qemu/range.h"
@ -1904,6 +1907,14 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
qemu_mutex_unlock_ramlist();
goto out_free;
}
error_setg(&new_block->cpr_blocker,
"Memory region %s uses guest_memfd, "
"which is not supported with CPR.",
memory_region_name(new_block->mr));
migrate_add_blocker_modes(&new_block->cpr_blocker, errp,
MIG_MODE_CPR_TRANSFER,
-1);
}
ram_size = (new_block->offset + new_block->max_length) >> TARGET_PAGE_BITS;
@ -4095,3 +4106,58 @@ bool ram_block_discard_is_required(void)
return qatomic_read(&ram_block_discard_required_cnt) ||
qatomic_read(&ram_block_coordinated_discard_required_cnt);
}
/*
* Return true if ram is compatible with CPR. Do not exclude rom,
* because the rom file could change in new QEMU.
*/
static bool ram_is_cpr_compatible(RAMBlock *rb)
{
MemoryRegion *mr = rb->mr;
if (!mr || !memory_region_is_ram(mr)) {
return true;
}
/* Ram device is remapped in new QEMU */
if (memory_region_is_ram_device(mr)) {
return true;
}
/*
* A file descriptor is passed to new QEMU and remapped, or its backing
* file is reopened and mapped. It must be shared to avoid COW.
*/
if (rb->fd >= 0 && qemu_ram_is_shared(rb)) {
return true;
}
return false;
}
/*
* Add a blocker for each volatile ram block. This function should only be
* called after we know that the block is migratable. Non-migratable blocks
* are either re-created in new QEMU, or are handled specially, or are covered
* by a device-level CPR blocker.
*/
void ram_block_add_cpr_blocker(RAMBlock *rb, Error **errp)
{
assert(qemu_ram_is_migratable(rb));
if (ram_is_cpr_compatible(rb)) {
return;
}
error_setg(&rb->cpr_blocker,
"Memory region %s is not compatible with CPR. share=on is "
"required for memory-backend objects, and aux-ram-share=on is "
"required.", memory_region_name(rb->mr));
migrate_add_blocker_modes(&rb->cpr_blocker, errp, MIG_MODE_CPR_TRANSFER,
-1);
}
void ram_block_del_cpr_blocker(RAMBlock *rb)
{
migrate_del_blocker(&rb->cpr_blocker);
}