Snapshots made with mapped-ram and x-ignore-shared flags are not parsed properly.
Co-authored-by: Peter Xu <[email protected]> Signed-off-by: Pawel Zmarzly <[email protected]> --- migration/ram.c | 21 +++++++++++---------- tests/qtest/migration/file-tests.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 29f016cb25..7d024b88b5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4205,6 +4205,17 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) assert(block); + if (migrate_ignore_shared()) { + hwaddr addr = qemu_get_be64(f); + if (migrate_ram_is_ignored(block) && + block->mr->addr != addr) { + error_report("Mismatched GPAs for block %s " + "%" PRId64 "!= %" PRId64, block->idstr, + (uint64_t)addr, (uint64_t)block->mr->addr); + return -EINVAL; + } + } + if (migrate_mapped_ram()) { parse_ramblock_mapped_ram(f, block, length, &local_err); if (local_err) { @@ -4244,16 +4255,6 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) return -EINVAL; } } - if (migrate_ignore_shared()) { - hwaddr addr = qemu_get_be64(f); - if (migrate_ram_is_ignored(block) && - block->mr->addr != addr) { - error_report("Mismatched GPAs for block %s " - "%" PRId64 "!= %" PRId64, block->idstr, - (uint64_t)addr, (uint64_t)block->mr->addr); - return -EINVAL; - } - } ret = rdma_block_notification_handle(f, block->idstr); if (ret < 0) { qemu_file_set_error(f, ret); diff --git a/tests/qtest/migration/file-tests.c b/tests/qtest/migration/file-tests.c index 4d78ce0855..c196a703ff 100644 --- a/tests/qtest/migration/file-tests.c +++ b/tests/qtest/migration/file-tests.c @@ -303,6 +303,22 @@ static void migration_test_add_file_smoke(MigrationTestEnv *env) test_multifd_file_mapped_ram_dio); } +static void test_precopy_file_mapped_ram_ignore_shared(void) +{ + g_autofree char *uri = g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args = { + .connect_uri = uri, + .listen_uri = "defer", + .start = { + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] = true, + .caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED] = true, + }, + }; + + test_file_common(&args, true); +} + void migration_test_add_file(MigrationTestEnv *env) { tmpfs = env->tmpfs; @@ -329,6 +345,8 @@ void migration_test_add_file(MigrationTestEnv *env) migration_test_add("/migration/multifd/file/mapped-ram", test_multifd_file_mapped_ram); + migration_test_add("/migration/multifd/file/mapped-ram/ignore-shared", + test_precopy_file_mapped_ram_ignore_shared); migration_test_add("/migration/multifd/file/mapped-ram/live", test_multifd_file_mapped_ram_live); -- 2.52.0
