@samitouri / QOSamiQemu / commits / 33db64cf28

hw/ide: restore the power-on device state before loading

Loading a snapshot reuses the IDEState of the machine it is loaded into: load_snapshot() resets the machine and then feeds the stream into the existing devices. The reset does not help, as ide_reset() restores the logical CHS translation only when the guest asked for power-on defaults to be reverted with SET FEATURES 0xCC. A guest that replaced the translation with INITIALIZE DEVICE PARAMETERS therefore keeps it across the load of a snapshot taken before it did, while the restored guest expects the geometry of that moment. Every CHS access then lands on a sector other than the one asked for, with no error reported. s->reset_reverts survives a load the same way. Add a pre_load restoring the defaults, which docs/devel/migration/main.rst recommends for state a stream need not carry, and which the following subsections rely on. The RESET_TYPE_SNAPSHOT_LOAD marking that reset would be another way to recognise the case, but no IDE controller can see it while they all use device_class_set_legacy_reset(). Cc: John Snow <jsnow@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Cc: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Fixes: 176e4961bb33 ("hw/ide/core.c: Implement ATA INITIALIZE_DEVICE_PARAMETERS command") Signed-off-by: Denis V. Lunev <den@openvz.org>

Denis V. Lunev committed Aug 4, 2026 at 18:34 UTC 33db64cf28829103e6b60905666082a01d011fc8
1 file changed +13
hw/ide/core.c
+13
@@ -2863,6 +2863,18 @@ static int transfer_end_table_idx(EndTransferFunc *fn)
2863 return -1;
2864 }
2865
2866 +static int ide_drive_pre_load(void *opaque)
2867 +{
2868 + IDEState *s = opaque;
2869 +
2870 + /* The subsections below are sent only where the guest replaced these */
2871 + s->heads = s->drive_heads;
2872 + s->sectors = s->drive_sectors;
2873 + s->reset_reverts = false;
2874 +
2875 + return 0;
2876 +}
2877 +
2878 static int ide_drive_post_load(void *opaque, int version_id)
2879 {
2880 IDEState *s = opaque;
@@ -2986,6 +2998,7 @@ const VMStateDescription vmstate_ide_drive = {
2998 .name = "ide_drive",
2999 .version_id = 3,
3000 .minimum_version_id = 0,
3001 + .pre_load = ide_drive_pre_load,
3002 .post_load = ide_drive_post_load,
3003 .fields = (const VMStateField[]) {
3004 VMSTATE_INT32(mult_sectors, IDEState),