From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Juraj Marcin <jmarcin@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
peterx@redhat.com, Fabiano Rosas <farosas@suse.de>,
Gavin Shan <gshan@redhat.com>
Subject: [PATCH for-12.0 v2 7/9] arm/machine: Convert cpu_post_load() to take Error**
Date: Thu, 26 Nov 2026 18:16:29 -0500 [thread overview]
Message-ID: <20261126231631.3392756-8-peterx@redhat.com> (raw)
In-Reply-To: <20261126231631.3392756-1-peterx@redhat.com>
Convert it to post_load_errp() version, so as to be able to report verbose
errors when hit.
A few things to mention:
- The old "fail" count won't work with Error**, switch to fail and return
immediately, assuming we should stop migration immediately hitting the
1st error.
- Alone the way, handle_cpreg_only_in_incoming_stream() return value is
flipped to make it match QEMU's normal coding style (return true for
success, false for error, not vice versa).
- Provide simple error strings for the cases where the lower function
doesn't yet take an Error**.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
target/arm/machine.c | 52 ++++++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 23 deletions(-)
diff --git a/target/arm/machine.c b/target/arm/machine.c
index 02a2b78506..e86fa85a9b 100644
--- a/target/arm/machine.c
+++ b/target/arm/machine.c
@@ -11,6 +11,7 @@
#include "migration/qemu-file-types.h"
#include "migration/vmstate.h"
#include "target/arm/gtimer.h"
+#include "qapi/error.h"
static bool vfp_needed(void *opaque)
{
@@ -1151,10 +1152,11 @@ static void handle_cpreg_missing_in_incoming_stream(ARMCPU *cpu, uint64_t kvmidx
* Handle the situation where @kvmidx is in the incoming
* stream but not on destination. This fails the migration if
* no cpreg mig tolerance is matched for this @kvmidx
- * Return true if the migration should eventually fail
+ * Return true if success, false otherwise.
*/
static bool
-handle_cpreg_only_in_incoming_stream(ARMCPU *cpu, uint64_t kvmidx, uint64_t value)
+handle_cpreg_only_in_incoming_stream(ARMCPU *cpu, uint64_t kvmidx, uint64_t value,
+ Error **errp)
{
g_autofree gchar *name = print_register_name(kvmidx);
@@ -1163,18 +1165,17 @@ handle_cpreg_only_in_incoming_stream(ARMCPU *cpu, uint64_t kvmidx, uint64_t valu
arm_cpu_match_cpreg_mig_tolerance(cpu, kvmidx,
value, 0, ToleranceOnlySrcTestValue)) {
trace_tolerate_cpreg_only_in_incoming_stream(name);
- return false;
+ return true;
}
- error_report("%s: %s in the incoming stream but unknown on the "
- "destination: fail migration", __func__, name);
- return true;
+ error_setg(errp, "cpreg %s in the incoming stream but unknown on the "
+ "destination", name);
+ return false;
}
-static int cpu_post_load(void *opaque, int version_id)
+static bool cpu_post_load(void *opaque, int version_id, Error **errp)
{
ARMCPU *cpu = opaque;
CPUARMState *env = &cpu->env;
- bool fail = false;
bool ignore_s_regs;
int i, v;
@@ -1229,9 +1230,11 @@ static int cpu_post_load(void *opaque, int version_id)
continue;
}
if (cpu->cpreg_vmstate_indexes[v] < cpu->cpreg_indexes[i]) {
- fail = handle_cpreg_only_in_incoming_stream(cpu,
- cpu->cpreg_vmstate_indexes[v],
- cpu->cpreg_vmstate_values[v]);
+ if (!handle_cpreg_only_in_incoming_stream(
+ cpu, cpu->cpreg_vmstate_indexes[v],
+ cpu->cpreg_vmstate_values[v], errp)) {
+ return false;
+ }
v++;
continue;
}
@@ -1278,21 +1281,22 @@ static int cpu_post_load(void *opaque, int version_id)
* still regs in the input stream, continue parsing the vmstate array
*/
for ( ; v < cpu->cpreg_vmstate_array_len; v++) {
- fail = handle_cpreg_only_in_incoming_stream(cpu,
- cpu->cpreg_vmstate_indexes[v],
- cpu->cpreg_vmstate_values[v]);
- }
- if (fail) {
- return -1;
+ if (!handle_cpreg_only_in_incoming_stream(
+ cpu, cpu->cpreg_vmstate_indexes[v],
+ cpu->cpreg_vmstate_values[v], errp)) {
+ return false;
+ }
}
if (kvm_enabled()) {
if (!kvm_arm_cpu_post_load(cpu)) {
- return -1;
+ error_setg(errp, "kvm_arm_cpu_post_load() failed");
+ return false;
}
} else {
if (!write_list_to_cpustate(cpu)) {
- return -1;
+ error_setg(errp, "write_list_to_cpustate() failed");
+ return false;
}
}
@@ -1307,7 +1311,8 @@ static int cpu_post_load(void *opaque, int version_id)
* thumb_tr_translate_insn().
*/
if (!is_a64(env) && env->thumb && (env->regs[15] & 1)) {
- return -1;
+ error_setg(errp, "Misaligned thumb pc");
+ return false;
}
if (tcg_enabled()) {
@@ -1325,7 +1330,8 @@ static int cpu_post_load(void *opaque, int version_id)
FPCR_LTPSIZE_SHIFT, FPCR_LTPSIZE_LENGTH) != 4 ||
extract32(env->v7m.fpdscr[M_REG_S],
FPCR_LTPSIZE_SHIFT, FPCR_LTPSIZE_LENGTH) != 4) {
- return -1;
+ error_setg(errp, "Bogus fpdscr[] values");
+ return false;
}
}
@@ -1337,7 +1343,7 @@ static int cpu_post_load(void *opaque, int version_id)
arm_rebuild_hflags(env);
}
- return 0;
+ return true;
}
const VMStateDescription vmstate_arm_cpu = {
@@ -1347,7 +1353,7 @@ const VMStateDescription vmstate_arm_cpu = {
.pre_save = cpu_pre_save,
.post_save = cpu_post_save,
.pre_load = cpu_pre_load,
- .post_load = cpu_post_load,
+ .post_load_errp = cpu_post_load,
.fields = (const VMStateField[]) {
VMSTATE_UINT32_ARRAY(env.regs, ARMCPU, 16),
VMSTATE_UINT64_ARRAY(env.xregs, ARMCPU, 32),
--
2.56.0
next prev parent reply other threads:[~2026-11-26 23:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 23:16 [PATCH for-12.0 v2 0/9] migration: Remove VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 1/9] rust/migration: Allow usize as the length of a varray Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 2/9] rust/hpet: Move vmstate_validate!() check into post_load Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 3/9] rust/migration: Remove vmstate_validate!() macro and test Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 4/9] pcie/aer: Remove the usage of VMSTATE_VALIDATE() Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 5/9] hw/gpio/zaurus: Move VMSTATE_VALIDATE() check into post_load_errp() Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 6/9] hpet: Move VMSTATE_VALIDATE() check into post_load Peter Xu
2026-11-26 23:16 ` Peter Xu [this message]
2026-11-27 13:22 ` [PATCH for-12.0 v2 7/9] arm/machine: Convert cpu_post_load() to take Error** Fabiano Rosas
2026-11-27 14:23 ` Peter Xu
2026-11-27 14:44 ` Peter Maydell
2026-11-27 17:00 ` Eric Auger
2026-11-26 23:16 ` [PATCH for-12.0 v2 8/9] arm/machine: Move all VMSTATE_VALIDATE() usages into post_load Peter Xu
2026-11-27 13:41 ` Fabiano Rosas
2026-11-27 13:50 ` Peter Maydell
2026-11-27 14:29 ` Peter Xu
2026-11-26 23:16 ` [PATCH for-12.0 v2 9/9] migration: Drop VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-27 14:16 ` Fabiano Rosas
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=20261126231631.3392756-8-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=gshan@redhat.com \
--cc=jmarcin@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.