From: Avihai Horon <avihaih@nvidia.com>
To: <qemu-devel@nongnu.org>
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Cédric Le Goater" <clg@redhat.com>,
"Peter Xu" <peterx@redhat.com>, "Fabiano Rosas" <farosas@suse.de>,
"Avihai Horon" <avihaih@nvidia.com>
Subject: [PATCH 2/3] vfio/migration: Refactor vfio_vmstate_change/_prepare() error reporting
Date: Sun, 20 Oct 2024 16:01:07 +0300 [thread overview]
Message-ID: <20241020130108.27148-3-avihaih@nvidia.com> (raw)
In-Reply-To: <20241020130108.27148-1-avihaih@nvidia.com>
When the VM is shut down vfio_vmstate_change/_prepare() are called to
transition the VFIO device state to STOP. They are called after
migration_shutdown() and thus, by this time, the migration object is
already freed (more specifically, MigrationState->qemu_file_lock is
already destroyed).
In this case, if there is an error in vfio_vmstate_change/_prepare(), it
calls migration_file_set_error() which tries to lock the already
destroyed MigrationState->qemu_file_lock, leading to the following
assert:
qemu-system-x86_64: ../util/qemu-thread-posix.c:92: qemu_mutex_lock_impl: Assertion `mutex->initialized' failed.
Fix this by not setting migration file error in the shut down flow.
Fixes: 20c64c8a51a4 ("migration: migration_file_set_error")
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
---
hw/vfio/migration.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 992dc3b102..1c44b036ea 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -783,6 +783,25 @@ static const SaveVMHandlers savevm_vfio_handlers = {
/* ---------------------------------------------------------------------- */
+static void vfio_vmstate_change_error_report(int ret, Error *err,
+ RunState state)
+{
+ if (state == RUN_STATE_SHUTDOWN) {
+ /*
+ * If VM is being shut down, migration object might have already been
+ * freed, so just report the error.
+ */
+ error_report_err(err);
+ return;
+ }
+
+ /*
+ * Migration should be aborted in this case, but vm_state_notify()
+ * currently does not support reporting failures.
+ */
+ migration_file_set_error(ret, err);
+}
+
static void vfio_vmstate_change_prepare(void *opaque, bool running,
RunState state)
{
@@ -798,11 +817,7 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,
ret = vfio_migration_set_state_or_reset(vbasedev, new_state, &local_err);
if (ret) {
- /*
- * Migration should be aborted in this case, but vm_state_notify()
- * currently does not support reporting failures.
- */
- migration_file_set_error(ret, local_err);
+ vfio_vmstate_change_error_report(ret, local_err, state);
}
trace_vfio_vmstate_change_prepare(vbasedev->name, running,
@@ -829,11 +844,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)
ret = vfio_migration_set_state_or_reset(vbasedev, new_state, &local_err);
if (ret) {
- /*
- * Migration should be aborted in this case, but vm_state_notify()
- * currently does not support reporting failures.
- */
- migration_file_set_error(ret, local_err);
+ vfio_vmstate_change_error_report(ret, local_err, state);
}
trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
--
2.40.1
next prev parent reply other threads:[~2024-10-20 13:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-20 13:01 [PATCH 0/3] vfio/migration: Some bug fixes and cleanups Avihai Horon
2024-10-20 13:01 ` [PATCH 1/3] vfio/migration: Report only stop-copy size in vfio_state_pending_exact() Avihai Horon
2024-10-21 6:48 ` Cédric Le Goater
2024-10-23 10:06 ` Cédric Le Goater
2024-10-25 15:18 ` Michael Tokarev
2024-10-25 16:09 ` Cédric Le Goater
2024-10-20 13:01 ` Avihai Horon [this message]
2024-10-21 15:14 ` [PATCH 2/3] vfio/migration: Refactor vfio_vmstate_change/_prepare() error reporting Cédric Le Goater
2024-10-21 15:50 ` Peter Xu
2024-10-21 16:43 ` Cédric Le Goater
2024-10-21 16:54 ` Peter Xu
2024-10-22 9:38 ` Avihai Horon via
2024-10-22 13:24 ` Cédric Le Goater
2024-10-22 14:21 ` Avihai Horon
2024-10-22 14:29 ` Peter Xu
2024-10-22 14:42 ` Cédric Le Goater
2024-10-22 16:10 ` Peter Xu
2024-10-20 13:01 ` [PATCH 3/3] vfio/migration: Change trace formats from hex to decimal Avihai Horon
2024-10-21 15:17 ` Cédric Le Goater
2024-10-23 15:08 ` [PATCH 0/3] vfio/migration: Some bug fixes and cleanups Cédric Le Goater
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=20241020130108.27148-3-avihaih@nvidia.com \
--to=avihaih@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).