From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fabiano Rosas <farosas@suse.de>,
Peter Maydell <peter.maydell@linaro.org>,
Hanna Czenczek <hreitz@redhat.com>, Peter Xu <peterx@redhat.com>
Subject: [PULL 03/18] migration: Ensure vmstate_save() sets errp
Date: Wed, 30 Oct 2024 11:57:19 -0400 [thread overview]
Message-ID: <20241030155734.2141398-4-peterx@redhat.com> (raw)
In-Reply-To: <20241030155734.2141398-1-peterx@redhat.com>
From: Hanna Czenczek <hreitz@redhat.com>
migration/savevm.c contains some calls to vmstate_save() that are
followed by migrate_set_error() if the integer return value indicates an
error. migrate_set_error() requires that the `Error *` object passed to
it is set. Therefore, vmstate_save() is assumed to always set *errp on
error.
Right now, that assumption is not met: vmstate_save_state_v() (called
internally by vmstate_save()) will not set *errp if
vmstate_subsection_save() or vmsd->post_save() fail. Fix that by adding
an *errp parameter to vmstate_subsection_save(), and by generating a
generic error in case post_save() fails (as is already done for
pre_save()).
Without this patch, qemu will crash after vmstate_subsection_save() or
post_save() have failed inside of a vmstate_save() call (unless
migrate_set_error() then happen to discard the new error because
s->error is already set). This happens e.g. when receiving the state
from a virtio-fs back-end (virtiofsd) fails.
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Link: https://lore.kernel.org/r/20241015170437.310358-1-hreitz@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/vmstate.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/migration/vmstate.c b/migration/vmstate.c
index ff5d589a6d..fa002b24e8 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -22,7 +22,8 @@
#include "trace.h"
static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
- void *opaque, JSONWriter *vmdesc);
+ void *opaque, JSONWriter *vmdesc,
+ Error **errp);
static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque);
@@ -441,12 +442,13 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
json_writer_end_array(vmdesc);
}
- ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc);
+ ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc, errp);
if (vmsd->post_save) {
int ps_ret = vmsd->post_save(opaque);
- if (!ret) {
+ if (!ret && ps_ret) {
ret = ps_ret;
+ error_setg(errp, "post-save failed: %s", vmsd->name);
}
}
return ret;
@@ -518,7 +520,8 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
}
static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
- void *opaque, JSONWriter *vmdesc)
+ void *opaque, JSONWriter *vmdesc,
+ Error **errp)
{
const VMStateDescription * const *sub = vmsd->subsections;
bool vmdesc_has_subsections = false;
@@ -546,7 +549,7 @@ static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
qemu_put_byte(f, len);
qemu_put_buffer(f, (uint8_t *)vmsdsub->name, len);
qemu_put_be32(f, vmsdsub->version_id);
- ret = vmstate_save_state(f, vmsdsub, opaque, vmdesc);
+ ret = vmstate_save_state_with_err(f, vmsdsub, opaque, vmdesc, errp);
if (ret) {
return ret;
}
--
2.45.0
next prev parent reply other threads:[~2024-10-30 15:59 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-30 15:57 [PULL 00/18] Migration 20241030 patches Peter Xu
2024-10-30 15:57 ` [PULL 01/18] migration: Cleanup migrate_fd_cleanup() on accessing to_dst_file Peter Xu
2024-10-30 15:57 ` [PULL 02/18] migration: Put thread names together with macros Peter Xu
2024-10-30 15:57 ` Peter Xu [this message]
2024-10-30 15:57 ` [PULL 04/18] accel/tcg/icount-common: Remove the reference to the unused header file Peter Xu
2024-10-30 15:57 ` [PULL 05/18] migration: Stop CPU throttling conditionally Peter Xu
2024-10-30 15:57 ` [PULL 06/18] migration: Move cpu-throttole.c from system to migration Peter Xu
2024-10-30 15:57 ` [PULL 07/18] migration: Remove "rs" parameter in migration_bitmap_sync_precopy Peter Xu
2024-10-30 15:57 ` [PULL 08/18] migration: Support periodic RAMBlock dirty bitmap sync Peter Xu
2024-10-30 15:57 ` [PULL 09/18] tests/migration: Add case for periodic ramblock dirty sync Peter Xu
2024-10-30 15:57 ` [PULL 10/18] migration/dirtyrate: Silence warning about strcpy() on OpenBSD Peter Xu
2024-10-30 15:57 ` [PULL 11/18] migration: Deprecate query-migrationthreads command Peter Xu
2024-10-30 15:57 ` [PULL 12/18] migration: Take migration object refcount earlier for threads Peter Xu
2024-10-30 15:57 ` [PULL 13/18] migration: Unexport dirty_bitmap_mig_init() Peter Xu
2024-10-30 15:57 ` [PULL 14/18] migration: Unexport ram_mig_init() Peter Xu
2024-10-30 15:57 ` [PULL 15/18] migration: Drop migration_is_setup_or_active() Peter Xu
2024-10-30 15:57 ` [PULL 16/18] migration: Drop migration_is_idle() Peter Xu
2024-10-30 15:57 ` [PULL 17/18] migration/ram: Add load start trace event Peter Xu
2024-10-30 15:57 ` [PULL 18/18] migration/multifd: Zero p->flags before starting filling a packet Peter Xu
2024-10-31 13:28 ` [PULL 00/18] Migration 20241030 patches Peter Maydell
2024-10-31 14:50 ` Peter Xu
2024-10-31 14:52 ` Peter Maydell
2024-10-31 15:14 ` Peter Xu
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=20241030155734.2141398-4-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=hreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--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).