hw/watchdog/wdt_imx2.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
The wdt_imx2 device has optional support for pretimeouts, which are
present on most i.MX SoCs but not on i.MX31. If the QOM property
'pretimeout-support' is not set to true then we don't create the
ptimer associated with that feature. However, the migration vmstate
unconditionally lists that ptimer, with the result that trying to
save the vmstate of an i.MX31-based machine like "kzm" will hit an
assertion.
Move the migration of 'itimer' into its own subsection which we only
send when pretimeout support is enabled.
This bug has existed in the code for a long time, but it was hidden
until commit d9abd0253be ("hw/watchdog/wdt_imx2: Remove redundant
attributes)" because a bug in the VMSTATE_PTIMER() macro together
with the fact that the vmstate_imx2_wdt version_id was 0 meant that
we weren't trying to migrate the device's ptimers at all, and so
we avoided the assertion (but didn't migrate correctly).
This is a migration compatibility break for this device, but it isn't
used in any versioned machine types, and we've already decided to
break compat on it this release cycle.
Fixes: daca13d495a11 ("hw/watchdog: Implement full i.MX watchdog support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4876
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Based-on: 20261106163657.3825938-1-peter.maydell@linaro.org
("Fix 'version' arg of VMSTATE_PTIMER")
-- the patch in that which sets minimum_version_id to 1 in
the wdt_imx2 vmstate would otherwise be a conflict
---
hw/watchdog/wdt_imx2.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/hw/watchdog/wdt_imx2.c b/hw/watchdog/wdt_imx2.c
index abb8edfae25..b4196de7021 100644
--- a/hw/watchdog/wdt_imx2.c
+++ b/hw/watchdog/wdt_imx2.c
@@ -221,13 +221,31 @@ static const MemoryRegionOps imx2_wdt_ops = {
},
};
-static const VMStateDescription vmstate_imx2_wdt = {
- .name = "imx2.wdt",
+static bool pretimeout_state_needed(void *opaque)
+{
+ /* The itimer is only present if pretimeout-support is enabled */
+ IMX2WdtState *s = opaque;
+
+ return s->pretimeout_support;
+}
+
+static const VMStateDescription vmstate_imx2_wdt_pretimeout = {
+ .name = "imx2.wdt/pretimeout",
.version_id = 1,
.minimum_version_id = 1,
+ .needed = pretimeout_state_needed,
+ .fields = (const VMStateField[]) {
+ VMSTATE_PTIMER(itimer, IMX2WdtState),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static const VMStateDescription vmstate_imx2_wdt = {
+ .name = "imx2.wdt",
+ .version_id = 2,
+ .minimum_version_id = 2,
.fields = (const VMStateField[]) {
VMSTATE_PTIMER(timer, IMX2WdtState),
- VMSTATE_PTIMER(itimer, IMX2WdtState),
VMSTATE_BOOL(wicr_locked, IMX2WdtState),
VMSTATE_BOOL(wcr_locked, IMX2WdtState),
VMSTATE_UINT16(wcr, IMX2WdtState),
@@ -236,6 +254,10 @@ static const VMStateDescription vmstate_imx2_wdt = {
VMSTATE_UINT16(wmcr, IMX2WdtState),
VMSTATE_UINT16(wicr, IMX2WdtState),
VMSTATE_END_OF_LIST()
+ },
+ .subsections = (const VMStateDescription * const []) {
+ &vmstate_imx2_wdt_pretimeout,
+ NULL
}
};
--
2.43.0
On Mon, 16 Nov 2026 at 11:46, Peter Maydell <peter.maydell@linaro.org> wrote:
> The wdt_imx2 device has optional support for pretimeouts, which are
> present on most i.MX SoCs but not on i.MX31. If the QOM property
> 'pretimeout-support' is not set to true then we don't create the
> ptimer associated with that feature. However, the migration vmstate
> unconditionally lists that ptimer, with the result that trying to
> save the vmstate of an i.MX31-based machine like "kzm" will hit an
> assertion.
>
> Move the migration of 'itimer' into its own subsection which we only
> send when pretimeout support is enabled.
>
> Fixes: daca13d495a11 ("hw/watchdog: Implement full i.MX watchdog support")
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4876
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
With this patch on master (97c88c61d45d), saving and loading a paused kzm
machine exits 0 instead of aborting in vmstate_save_vmsd_v().
Tested on Debian 13 x86_64.
Tested-by: Karl Mehltretter <kmehltretter@gmail.com>
Thanks,
Karl
© 2016 - 2026 Red Hat, Inc.