From: peterx@redhat.com
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Wei Wang <wei.w.wang@intel.com>, Lei Wang <lei4.wang@intel.com>,
Avihai Horon <avihaih@nvidia.com>,
Fabiano Rosas <farosas@suse.de>,
peterx@redhat.com, Prasad Pandit <ppandit@redhat.com>,
qemu-stable <qemu-stable@nongnu.org>
Subject: [PULL 1/2] migration/postcopy: ensure preempt channel is ready before loading states
Date: Sun, 7 Apr 2024 14:43:53 -0400 [thread overview]
Message-ID: <20240407184354.1839435-2-peterx@redhat.com> (raw)
In-Reply-To: <20240407184354.1839435-1-peterx@redhat.com>
From: Wei Wang <wei.w.wang@intel.com>
Before loading the guest states, ensure that the preempt channel has been
ready to use, as some of the states (e.g. via virtio_load) might trigger
page faults that will be handled through the preempt channel. So yield to
the main thread in the case that the channel create event hasn't been
dispatched.
Cc: qemu-stable <qemu-stable@nongnu.org>
Fixes: 9358982744 ("migration: Send requested page directly in rp-return thread")
Originally-by: Lei Wang <lei4.wang@intel.com>
Link: https://lore.kernel.org/all/9aa5d1be-7801-40dd-83fd-f7e041ced249@intel.com/T/
Signed-off-by: Lei Wang <lei4.wang@intel.com>
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
Link: https://lore.kernel.org/r/20240405034056.23933-1-wei.w.wang@intel.com
[peterx: add a todo section, add Fixes and copy stable for 8.0+]
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/savevm.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/migration/savevm.c b/migration/savevm.c
index 388d7af7cd..e7c1215671 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2342,6 +2342,27 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis)
QEMUFile *packf = qemu_file_new_input(QIO_CHANNEL(bioc));
+ /*
+ * Before loading the guest states, ensure that the preempt channel has
+ * been ready to use, as some of the states (e.g. via virtio_load) might
+ * trigger page faults that will be handled through the preempt channel.
+ * So yield to the main thread in the case that the channel create event
+ * hasn't been dispatched.
+ *
+ * TODO: if we can move migration loadvm out of main thread, then we
+ * won't block main thread from polling the accept() fds. We can drop
+ * this as a whole when that is done.
+ */
+ do {
+ if (!migrate_postcopy_preempt() || !qemu_in_coroutine() ||
+ mis->postcopy_qemufile_dst) {
+ break;
+ }
+
+ aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self());
+ qemu_coroutine_yield();
+ } while (1);
+
ret = qemu_loadvm_state_main(packf, mis);
trace_loadvm_handle_cmd_packaged_main(ret);
qemu_fclose(packf);
--
2.44.0
next prev parent reply other threads:[~2024-04-07 18:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-07 18:43 [PULL 0/2] Migration 20240407 patches peterx
2024-04-07 18:43 ` peterx [this message]
2024-04-07 18:43 ` [PULL 2/2] MAINTAINERS: Adjust migration documentation files peterx
2024-04-09 8:47 ` [PULL 0/2] Migration 20240407 patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240407184354.1839435-2-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=avihaih@nvidia.com \
--cc=farosas@suse.de \
--cc=lei4.wang@intel.com \
--cc=peter.maydell@linaro.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=wei.w.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).