From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Fabiano Rosas <farosas@suse.de>,
peterx@redhat.com, "Michael S. Tsirkin" <mst@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH for-12.0 3/6] hpet: Move VMSTATE_VALIDATE() check into post_load
Date: Fri, 20 Nov 2026 07:49:20 -0500 [thread overview]
Message-ID: <20261120124923.1656220-4-peterx@redhat.com> (raw)
In-Reply-To: <20261120124923.1656220-1-peterx@redhat.com>
To pave way for removing VMSTATE_VALIDATE(), move the usage of hpet into
post_load. To make it safer, loading the timers with the num_timers, then
only check against the wire number at last.
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
hw/timer/hpet.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 42285cff76..85cd26a454 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -254,25 +254,28 @@ static int hpet_pre_save(void *opaque)
return 0;
}
-static bool hpet_validate_num_timers(void *opaque, int version_id)
+static bool hpet_validate_num_timers(HPETState *s)
{
- HPETState *s = opaque;
-
return s->num_timers == s->num_timers_save;
}
-static int hpet_post_load(void *opaque, int version_id)
+static bool hpet_post_load(void *opaque, int version_id, Error **errp)
{
HPETState *s = opaque;
int i;
+ if (!hpet_validate_num_timers(s)) {
+ error_setg(errp, "num_timers must match");
+ return false;
+ }
+
for (i = 0; i < s->num_timers; i++) {
HPETTimer *t = &s->timer[i];
t->cmp64 = hpet_calculate_cmp64(t, s->hpet_counter, t->cmp);
t->last = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - NANOSECONDS_PER_SECOND;
}
- return 0;
+ return true;
}
static bool hpet_offset_needed(void *opaque)
@@ -332,14 +335,13 @@ static const VMStateDescription vmstate_hpet = {
.version_id = 2,
.minimum_version_id = 2,
.pre_save = hpet_pre_save,
- .post_load = hpet_post_load,
+ .post_load_errp = hpet_post_load,
.fields = (const VMStateField[]) {
VMSTATE_UINT64(config, HPETState),
VMSTATE_UINT64(isr, HPETState),
VMSTATE_UINT64(hpet_counter, HPETState),
VMSTATE_UINT8(num_timers_save, HPETState),
- VMSTATE_VALIDATE("num_timers must match", hpet_validate_num_timers),
- VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers_save, 0,
+ VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,
vmstate_hpet_timer, HPETTimer),
VMSTATE_END_OF_LIST()
},
--
2.56.0
next prev parent reply other threads:[~2026-11-20 12:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 12:49 [PATCH for-12.0 0/6] migration: Remove VMSTATE_VALIDATE() and VMS_MUST_EXIST Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 1/6] pcie/aer: Remove the usage of VMSTATE_VALIDATE() Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 2/6] hw/gpio/zaurus: Move VMSTATE_VALIDATE() check into post_load_errp() Peter Xu
2026-11-20 12:49 ` Peter Xu [this message]
2026-11-20 12:49 ` [PATCH for-12.0 4/6] arm/machine: Move all VMSTATE_VALIDATE() usages into post_load Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 5/6] rust: Replace vmstate_validate with post_load Peter Xu
2026-11-20 14:25 ` Zhao Liu
2026-11-20 15:43 ` Peter Xu
2026-11-20 12:49 ` [PATCH for-12.0 6/6] migration: Drop VMSTATE_VALIDATE() and VMS_MUST_EXIST 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=20261120124923.1656220-4-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=mst@redhat.com \
--cc=pbonzini@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.