Migration 20240917 patches
The following changes since commit 2b81c046252fbfb375ad30632362fc16e6e22bd5:
Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2024-09-17 14:02:18 +0100)
are available in the Git repository at:
https://gitlab.com/peterx/qemu.git tags/migration-20240917-pull-request
for you to fetch changes up to 7b8b4c0e59d2b7928836072536a5528820d8a041:
migration/multifd: Fix rb->receivedmap cleanup race (2024-09-17 17:50:45 -0400)
----------------------------------------------------------------
Migration pull for 9.2
- Fabiano's patch to move two tests to slow tests.
- Peter's patch to fix qatzip builds
- Stefan's multifd-zstd fix on unsigned diff comparisons
- Fea's bug fix to consistently use memattrs when map() address space
- Fabiano's bug fix on multifd race condition against receivedmap
----------------------------------------------------------------
Fabiano Rosas (3):
tests/qtest/migration: Move a couple of slow tests under g_test_slow migration/savevm: Remove extra load cleanup calls migration/multifd: Fix rb->receivedmap cleanup race
Fea.Wang (1):
softmmu/physmem.c: Keep transaction attribute in address_space_map()
Peter Xu (1):
migration/multifd: Fix build for qatzip
Stefan Weil (1):
migration/multifd: Fix loop conditions in multifd_zstd_send_prepare
and multifd_zstd_recv
migration/migration.c | 5 +++++ migration/multifd-qatzip.c | 18 +++++++++--------- migration/multifd-zstd.c | 8 ++++---- migration/savevm.c | 8 ++++---- system/physmem.c | 2 +- tests/qtest/migration-test.c | 8 +++++--- 6 files changed, 28 insertions(+), 21 deletions(-)
Signature · 1 line
2.45.0
[PULL 6/6] migration/multifd: Fix rb->receivedmap cleanup race
From: Fabiano Rosas <[email protected]>
Fix a segmentation fault in multifd when rb->receivedmap is cleared too early.
After commit 5ef7e26bdb ("migration/multifd: solve zero page causing multiple page faults"), multifd started using the rb->receivedmap bitmap, which belongs to ram.c and is initialized and *freed* from the ram SaveVMHandlers.
Multifd threads are live until migration_incoming_state_destroy(), which is called after qemu_loadvm_state_cleanup(), leading to a crash when accessing rb->receivedmap.
process_incoming_migration_co() ...
qemu_loadvm_state() multifd_nocomp_recv()
qemu_loadvm_state_cleanup() ramblock_recv_bitmap_set_offset()
rb->receivedmap = NULL set_bit_atomic(..., rb->receivedmap) ...
migration_incoming_state_destroy()
multifd_recv_cleanup()
multifd_recv_terminate_threads(NULL)
Move the loadvm cleanup into migration_incoming_state_destroy(), after multifd_recv_cleanup() to ensure multifd threads have already exited when rb->receivedmap is cleared.
Adjust the postcopy listen thread comment to indicate that we still want to skip the cpu synchronization.
--- migration/migration.c | 5 +++++ migration/savevm.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
migration/migration.c +5 -0
@@ -378,6 +378,11 @@ void migration_incoming_state_destroy(void)struct MigrationIncomingState *mis =migration_incoming_get_current ();multifd_recv_cleanup (); +/* +* RAM state cleanup needs to happen after multifd cleanup, because +* multifd threads can use some of its states (receivedmap). +*/ +qemu_loadvm_state_cleanup ();if (mis->to_src_file) {/* Tell source that we are done */
migration/savevm.c +4 -2
@@ -2979,7 +2979,10 @@ int qemu_loadvm_state(QEMUFile *f)trace_qemu_loadvm_state_post_main (ret);if (mis->have_listen_thread) { -/* Listen thread still going, can't clean up yet */ +/* +* Postcopy listen thread still going, don't synchronize the +* cpus yet. +*/ return ret; }
@@ -3022,7 +3025,6 @@ int qemu_loadvm_state(QEMUFile *f) } } -qemu_loadvm_state_cleanup ();cpu_synchronize_all_post_init ();return ret;
Signature · 1 line
2.45.0
[PULL 1/6] tests/qtest/migration: Move a couple of slow tests under g_test_slow
In reply to Peter XuFrom: Fabiano Rosas <[email protected]>
The xbzrel and vcpu_dirty_limit are the two slowest tests from migration-test. Move them under g_test_slow() to save about 40s per run.
--- tests/qtest/migration-test.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tests/qtest/migration-test.c +5 -3
@@ -3803,8 +3803,10 @@ int main(int argc, char **argv)migration_test_add ("/migration/precopy/unix/plain" , test_precopy_unix_plain); -migration_test_add ("/migration/precopy/unix/xbzrle" , - test_precopy_unix_xbzrle); +if (g_test_slow ()) { +migration_test_add ("/migration/precopy/unix/xbzrle" , + test_precopy_unix_xbzrle); + }migration_test_add ("/migration/precopy/file" , test_precopy_file); migration_test_add("/migration/precopy/file/offset",
@@ -3979,7 +3981,7 @@ int main(int argc, char **argv)if (g_str_equal (arch,"x86_64" ) && has_kvm &&kvm_dirty_ring_supported ()) {migration_test_add ("/migration/dirty_ring" , test_precopy_unix_dirty_ring); -if (qtest_has_machine ("pc" )) { +if (qtest_has_machine ("pc" ) &&g_test_slow ()) {migration_test_add ("/migration/vcpu_dirty_limit" , test_vcpu_dirty_limit); }
Signature · 1 line
2.45.0
[PULL 5/6] migration/savevm: Remove extra load cleanup calls
In reply to Peter XuFrom: Fabiano Rosas <[email protected]>
There are two qemu_loadvm_state_cleanup() calls that were introduced when qemu_loadvm_state_setup() was still called before loading the configuration section, so there was state to be cleaned up if the header checks failed.
However, commit 9e14b84908 ("migration/savevm: load_header before load_setup") has moved that configuration section part to qemu_loadvm_state_header() which now happens before qemu_loadvm_state_setup().
Remove the cleanup calls that are now misplaced.
Note that we didn't use Fixes because it's benign to cleanup() even if setup() is not invoked. So this patch is not needed for stable, as it falls into cleanup category.
--- migration/savevm.c | 2 -- 1 file changed, 2 deletions(-)
migration/savevm.c +0 -2
@@ -2732,13 +2732,11 @@ static int qemu_loadvm_state_header(QEMUFile *f)if (migrate_get_current ()->send_configuration) {if (qemu_get_byte (f) !=QEMU_VM_CONFIGURATION ) {error_report ("Configuration section missing" ); -qemu_loadvm_state_cleanup ();return -EINVAL ; } ret =vmstate_load_state (f, &vmstate_configuration, &savevm_state,0 );if (ret) { -qemu_loadvm_state_cleanup ();return ret; } }
Signature · 1 line
2.45.0
[PULL 2/6] migration/multifd: Fix build for qatzip
In reply to Peter XuThe qatzip series was based on an older commit, it applied cleanly even though it has conflicts. Neither CI nor myself found the build will break as it's skipped by default when qatzip library was missing.
Fix the build issues. No need to copy stable as it just landed 9.2.
--- migration/multifd-qatzip.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
migration/multifd-qatzip.c +9 -9
@@ -160,7 +160,8 @@ static void qatzip_send_cleanup(MultiFDSendParams *p, Error **errp)*/ static int qatzip_send_prepare (MultiFDSendParams *p,Error **errp) { -MultiFDPages_t *pages = p->pages; +uint32_t page_size =multifd_ram_page_size (); +MultiFDPages_t *pages = &p->data->u.ram;QatzipData *q = p->compress_data;int ret;unsigned int in_len, out_len;
@@ -179,12 +180,12 @@ static int qatzip_send_prepare(MultiFDSendParams *p, Error **errp)* implementation. */ for (int i =0 ; i < pages->normal_num; i++) { -memcpy (q->in_buf + (i * p->page_size), +memcpy (q->in_buf + (i * page_size), pages->block->host + pages->offset[i], - p->page_size); + page_size); } - in_len = pages->normal_num * p->page_size; + in_len = pages->normal_num * page_size;if (in_len > q->in_len) {error_setg (errp,"multifd %u: unexpectedly large input" , p->id);return -1 ;
@@ -197,7 +198,7 @@ static int qatzip_send_prepare(MultiFDSendParams *p, Error **errp) p->id, ret);return -1 ; } -if (in_len != pages->normal_num * p->page_size) { +if (in_len != pages->normal_num * page_size) {error_setg (errp,"multifd %u: QATzip failed to compress all input" , p->id);return -1 ;
@@ -329,7 +330,8 @@ static int qatzip_recv(MultiFDRecvParams *p, Error **errp)int ret;unsigned int in_len, out_len;uint32_t in_size = p->next_packet_size; -uint32_t expected_size = p->normal_num * p->page_size; +uint32_t page_size =multifd_ram_page_size (); +uint32_t expected_size = p->normal_num * page_size;uint32_t flags = p->flags &MULTIFD_FLAG_COMPRESSION_MASK ;if (in_size > q->in_len) {
@@ -370,9 +372,7 @@ static int qatzip_recv(MultiFDRecvParams *p, Error **errp)/* Copy each page to its appropriate location. */ for (int i =0 ; i < p->normal_num; i++) { -memcpy (p->host + p->normal[i], - q->out_buf + p->page_size * i, - p->page_size); +memcpy (p->host + p->normal[i], q->out_buf + page_size * i, page_size); }return 0 ; }
Signature · 1 line
2.45.0
[PULL 4/6] softmmu/physmem.c: Keep transaction attribute in address_space_map()
In reply to Peter XuFrom: "Fea.Wang" <[email protected]>
The follow-up transactions may use the data in the attribution, so keep the value of attribution from the function parameter just as flatview_translate() above.
--- system/physmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
system/physmem.c +1 -1
@@ -3274,7 +3274,7 @@ void *address_space_map(AddressSpace *as, bounce->len = l;if (!is_write) { -flatview_read (fv, addr,MEMTXATTRS_UNSPECIFIED , +flatview_read (fv, addr, attrs, bounce->buffer, l); }
Signature · 1 line
2.45.0
[PULL 3/6] migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv
In reply to Peter XuFrom: Stefan Weil via <[email protected]>
GitHub's CodeQL reports four critical errors which are fixed by this commit:
Unsigned difference expression compared to zero
An expression (u - v > 0) with unsigned values u, v is only false if u == v, so all changed expressions did not work as expected.
--- migration/multifd-zstd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
migration/multifd-zstd.c +4 -4
@@ -123,9 +123,9 @@ static int multifd_zstd_send_prepare(MultiFDSendParams *p, Error **errp)*/ do { ret =ZSTD_compressStream2 (z->zcs, &z->out, &z->in, flush); - }while (ret >0 && (z->in.size - z->in.pos >0 ) - && (z->out.size - z->out.pos >0 )); -if (ret >0 && (z->in.size - z->in.pos >0 )) { + }while (ret >0 && (z->in.size > z->in.pos) + && (z->out.size > z->out.pos)); +if (ret >0 && (z->in.size > z->in.pos)) {error_setg (errp,"multifd %u: compressStream buffer too small" , p->id);return -1 ;
@@ -243,7 +243,7 @@ static int multifd_zstd_recv(MultiFDRecvParams *p, Error **errp)*/ do { ret =ZSTD_decompressStream (z->zds, &z->out, &z->in); - }while (ret >0 && (z->in.size - z->in.pos >0 ) + }while (ret >0 && (z->in.size > z->in.pos) && (z->out.pos < page_size));if (ret >0 && (z->out.pos < page_size)) { error_setg(errp, "multifd %u: decompressStream buffer too small",
Signature · 1 line
2.45.0
Re: [PULL 3/6] migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv
Am 17.09.24 um 23:55 schrieb Peter Xu:
Quoted 1 line
From: Stefan Weil via <[email protected]>
How can I avoid that my author name/email is changed so often?
Will this be fixed automatically before the commit is merged?
Stefan
Re: [PULL 3/6] migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv
Quoted 8 lines · Stefan Weil
Am 17.09.24 um 23:55 schrieb Peter Xu:
Quoted 1 line
From: Stefan Weil via <[email protected]>
How can I avoid that my author name/email is changed so often?
Will this be fixed automatically before the commit is merged?
Hmm, this is pretty weird, as I actually did see this checkpatch error, then I should have manually fixed the --author of your commit after queued, as it was indeed mangled in the original patch:
https://lore.kernel.org/all/[email protected]/
However it doesn't seem like working.. I checked again, that checkpatch uses --no-mailmap so it still shows the mangled email.. I fixed it again locally, then the error is gone.
Sorry, I don't know what happened, and why I used to fix it the same way (that is, "git commit --author "XXX" --amend) but it didn't work last time (but I guess .mailmap made it harder for me to recognize..).
It seems that we already have this:
commit 5204b499a6cae4dfd9fe762d5e6e82224892383b
Author: Philippe Mathieu-Daudé <[email protected]> Date: Thu Dec 8 16:55:35 2022 +0100
mailmap: Fix Stefan Weil author email
So I assume even if Peter applies this PR it'll still show correct.
However if you (or Peter, any of you) prefer me to resend a pull, I can do that too. Let me know.
Thanks,
Signature · 1 line
Peter Xu
Quoted 32 lines · Peter Xu
The following changes since commit
2b81c046252fbfb375ad30632362fc16e6e22bd5:Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2024-09-17 14:02:18 +0100)
are available in the Git repository at:
https://gitlab.com/peterx/qemu.git tags/migration-20240917-pull-request
for you to fetch changes up to
7b8b4c0e59d2b7928836072536a5528820d8a041:migration/multifd: Fix
rb->receivedmapcleanup race (2024-09-17 17:50:45 -0400)----------------------------------------------------------------
Migration pull for 9.2- Fabiano's patch to move two tests to slow tests.
- Peter's patch to fix qatzip builds
- Stefan's multifd-zstd fix on unsigned diff comparisons
- Fea's bug fix to consistently use memattrs whenmap()address space
- Fabiano's bug fix on multifd race condition against receivedmap----------------------------------------------------------------
Fabiano Rosas (3):
tests/qtest/migration: Move a couple of slow tests underg_test_slowmigration/savevm: Remove extra load cleanup calls migration/multifd: Fixrb->receivedmapcleanup raceFea.Wang (1):
softmmu/physmem.c: Keep transaction attribute inaddress_space_map()
Quoted 6 lines
Peter Xu (1):
migration/multifd: Fix build for qatzipStefan Weil (1):
migration/multifd: Fix loop conditions inmultifd_zstd_send_prepare
andmultifd_zstd_recv
ERROR: pull request includes commits attributed to list
specifically:
commit ebb47ddce00a1d681124f2e248022a0a5310daa8
Author: Stefan Weil via <[email protected]> migration/multifd: Fix loop conditions in multifd_zstd_send_prepare and multifd_zstd_recv
(git log --no-mailmap will show you this. The check in my scripting that catches it is:
if git shortlog --author='qemu-.*@nongnu\.org' master..staging | grep .; then
echo "ERROR: pull request includes commits attributed to list" exit 1
fi
if you want to automate finding it.)
Can you fix this and resend, please?
thanks
-- PMM
Quoted 55 lines · Peter Maydell
Quoted 32 lines · Peter Xu
The following changes since commit
2b81c046252fbfb375ad30632362fc16e6e22bd5:Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2024-09-17 14:02:18 +0100)
are available in the Git repository at:
https://gitlab.com/peterx/qemu.git tags/migration-20240917-pull-request
for you to fetch changes up to
7b8b4c0e59d2b7928836072536a5528820d8a041:migration/multifd: Fix
rb->receivedmapcleanup race (2024-09-17 17:50:45 -0400)----------------------------------------------------------------
Migration pull for 9.2- Fabiano's patch to move two tests to slow tests.
- Peter's patch to fix qatzip builds
- Stefan's multifd-zstd fix on unsigned diff comparisons
- Fea's bug fix to consistently use memattrs whenmap()address space
- Fabiano's bug fix on multifd race condition against receivedmap----------------------------------------------------------------
Fabiano Rosas (3):
tests/qtest/migration: Move a couple of slow tests underg_test_slowmigration/savevm: Remove extra load cleanup calls migration/multifd: Fixrb->receivedmapcleanup raceFea.Wang (1):
softmmu/physmem.c: Keep transaction attribute inaddress_space_map()Quoted 6 lines
Peter Xu (1):
migration/multifd: Fix build for qatzipStefan Weil (1):
migration/multifd: Fix loop conditions inmultifd_zstd_send_prepare
andmultifd_zstd_recvERROR: pull request includes commits attributed to list
specifically:
commitebb47ddce00a1d681124f2e248022a0a5310daa8
Author: Stefan Weil via <[email protected]> migration/multifd: Fix loop conditions inmultifd_zstd_send_prepareandmultifd_zstd_recv(git log --no-mailmap will show you this. The check in my scripting that catches it is:
if git shortlog --author='qemu-.*@nongnu\.org' master..staging | grep .; then
echo "ERROR: pull request includes commits attributed to list" exit 1
fi
Quoted 3 lines
if you want to automate finding it.)
Can you fix this and resend, please?
Yep, will resend, sorry for the noise.
Signature · 1 line
Peter Xu