@samitouri / QOSamiQemu / commits / b5542796b3

hw/ide: keep the IDENTIFY DEVICE current geometry in sync

Bit 0 of IDENTIFY DEVICE word 53 says that words 54 to 58 describe the CHS translation in effect, and ATA-5 8.16.8 has INITIALIZE DEVICE PARAMETERS set words 55 and 56 to the heads and sectors per track it was given. The data is built once and then cached, so those words kept describing whatever was in effect when a guest first asked for IDENTIFY DEVICE: the device reported one geometry while addressing the medium with another, and nothing reported an error. The revert SET FEATURES 0xCC asks for on the next reset left the same disagreement. Do not drop the cached data on a change, as parts of it are guest state rather than a description of the drive: SET FEATURES records the write cache setting in word 85, which ide_drive_post_load() reads back after migration. Refresh the affected words in place instead, the way ide_identify_size() does for the capacity words. An ATAPI device has no translation but does take SET FEATURES 0xCC, so leave its IDENTIFY PACKET DEVICE data alone, where those words differ. 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 14, 2026 at 17:43 UTC b5542796b3cbe052daa3660d00ec1d4a1033e7ff
1 file changed +7
hw/ide/core.c
+7
@@ -1360,6 +1360,10 @@ static void ide_reset(IDEState *s)
1360 s->reset_reverts = false;
1361 s->heads = s->drive_heads;
1362 s->sectors = s->drive_sectors;
1363 + /* An ATAPI device takes SET FEATURES 0xCC but has no translation */
1364 + if (s->identify_set && s->drive_kind != IDE_CD) {
1365 + ide_identify_chs(s);
1366 + }
1367 }
1368 if (s->drive_kind == IDE_CFATA)
1369 s->mult_sectors = 0;
@@ -1668,6 +1672,9 @@ static bool cmd_specify(IDEState *s, uint8_t cmd)
1672
1673 s->heads = (s->select & (ATA_DEV_HS)) + 1;
1674 s->sectors = s->nsector;
1675 + if (s->identify_set) {
1676 + ide_identify_chs(s);
1677 + }
1678 ide_bus_set_irq(s->bus);
1679
1680 return true;