From: Denis V. Lunev <[email protected]> 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 <[email protected]> Cc: Peter Maydell <[email protected]> Cc: Philippe Mathieu-Daudé <[email protected]> Fixes: 176e4961bb33 ("hw/ide/core.c: Implement ATA INITIALIZE_DEVICE_PARAMETERS command") Signed-off-by: Denis V. Lunev <[email protected]> --- hw/ide/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/ide/core.c b/hw/ide/core.c index e5fd570575..048655b2d0 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1360,6 +1360,10 @@ static void ide_reset(IDEState *s) s->reset_reverts = false; s->heads = s->drive_heads; s->sectors = s->drive_sectors; + /* An ATAPI device takes SET FEATURES 0xCC but has no translation */ + if (s->identify_set && s->drive_kind != IDE_CD) { + ide_identify_chs(s); + } } if (s->drive_kind == IDE_CFATA) s->mult_sectors = 0; @@ -1668,6 +1672,9 @@ static bool cmd_specify(IDEState *s, uint8_t cmd) s->heads = (s->select & (ATA_DEV_HS)) + 1; s->sectors = s->nsector; + if (s->identify_set) { + ide_identify_chs(s); + } ide_bus_set_irq(s->bus); return true; -- 2.53.0
