Skip to content

hw/ide: fix the logical CHS translation a guest selects

Denis V. Lunev qemu-devel 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest17 patches 3 repliesIn review
  2. v115 patches 4 repliesSuperseded

Changes in v2 from the cover letter

-------------

- patch 1, patch 5: Cc qemu-stable. (Philippe)
- patch 6: new, the "XXX: retired, remove ?" on IDENTIFY DEVICE words 4, 5 and 20 is answered rather than carried. ATA-5 3.2.3.6 keeps the ATA-1 meaning of a retired word that a device still fills in, so the comments name that meaning; word 21 is a buffer size, not a cache size. (Philippe)
- patch 7: new, splits the extraction of ide_identify_chs() out of what is now patch 8, leaving that one with the two call sites that keep the words in sync. (Philippe)

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/17hw/ide: reject an unsupported CHS translationhw/ide/core.c+12 -50 replies
2/17tests/qtest/ide-test: cover a CHS translation with zero sectorstests/qtest/ide-test.c+62 -00 replies
3/17tests/qtest/libqos/ahci: allow a count and an expected errortests/qtest/libqos/ahci.c tests/qtest/libqos/ahci.h+20 -00 replies
4/17tests/qtest/ahci: cover the sector count of INITIALIZE DEVICE PARAMETERStests/qtest/ahci-test.c+40 -00 replies
5/17hw/ide: report the default CHS translation in IDENTIFY DEVICEhw/ide/core.c+6 -50 replies
6/17hw/ide: name the retired IDENTIFY DEVICE words the device fills inhw/ide/core.c+4 -40 replies
7/17hw/ide: factor out the IDENTIFY DEVICE current geometry wordshw/ide/core.c+14 -151 reply
8/17hw/ide: keep the IDENTIFY DEVICE current geometry in synchw/ide/core.c+7 -00 replies
9/17hw/ide: restore the power-on device state before loadinghw/ide/core.c+13 -00 replies
10/17hw/ide: migrate the logical CHS translationhw/ide/core.c+27 -00 replies
11/17hw/ide: migrate the power-on defaults revert flaghw/ide/core.c+20 -00 replies
12/17tests/qtest/ide-test: cover the CHS translation across migrationtests/qtest/ide-test.c+231 -00 replies
13/17tests/qtest/ide-test: cover a rejected CHS translation in the streamtests/qtest/ide-test.c+81 -00 replies
14/17tests/qtest/ide-test: cover the IDENTIFY DEVICE geometry wordstests/qtest/ide-test.c+84 -50 replies
15/17hw/ide: revert the CHS translation on a hardware resethw/ide/ahci.c hw/ide/cmd646.c hw/ide/core.c +7 more+30 -250 replies
16/17tests/qtest/ide-test: cover the CHS translation across resetstests/qtest/ide-test.c+46 -00 replies
17/17hw/ide: drop a redundant interrupt from INITIALIZE DEVICE PARAMETERShw/ide/core.c+0 -11 reply

Reviews trailers per patch

5 of 17 patches have a Reviewed-by or Acked-by.

PatchPhilippe Mathieu-Daudé
1/17R-b
2/17
3/17
4/17
5/17R-b
6/17
7/17R-b
8/17
9/17
10/17
11/17
12/17
13/17
14/17
15/17R-b
16/17
17/17R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/17] hw/ide: fix the logical CHS translation a guest selects

INITIALIZE DEVICE PARAMETERS lets a guest replace the logical CHS translation that turns the CHS registers into an LBA. cmd_specify() has implemented it since 176e4961bb33, released in v7.2, and the geometry it stores is mishandled four ways.

It is not validated: zero sectors per logical track kills QEMU with SIGFPE in ide_set_sector(), which is issue 2399, and since handle_cmd() takes the count from a 16 bit field of the register FIS, an AHCI guest can drive ide_get_sector() into an int overflow as well. It is not reported:
IDENTIFY DEVICE is built once and cached, so both the words describing the default geometry and the words describing the current one go wrong. It does not travel, leaving a migrated guest addressing the disk in a translation the destination does not have. And it does not revert on a hardware reset, which ATA-5 9.1 requires, so it outlives the reset of the machine it was selected on.

The two subsections patches 10 and 11 add are the only change to the migration stream, and both are sent only when the guest replaced the default geometry. An unaffected guest migrates to an older QEMU as before; an affected one now fails the load on the unknown subsection instead of silently addressing the wrong sectors.

Tested with ide-test (25 cases), ahci-test (74), a full make check, a clang build, and real guests on both controllers: FreeDOS reading a FAT16 disk through INT 13h CHS, Red Hat Linux 9 whose 2.4 IDE driver prints the geometry it read, and Ubuntu 26.04 over libata, each with a CD and a disk, plus a machine reset in the middle.

v1:
https://lore.kernel.org/qemu-devel/[email protected]/

Changes in v2
-------------

- patch 1, patch 5: Cc qemu-stable. (Philippe)
- patch 6: new, the "XXX: retired, remove ?" on IDENTIFY DEVICE words 4, 5 and 20 is answered rather than carried. ATA-5 3.2.3.6 keeps the ATA-1 meaning of a retired word that a device still fills in, so the comments name that meaning; word 21 is a buffer size, not a cache size. (Philippe)
- patch 7: new, splits the extraction of ide_identify_chs() out of what is now patch 8, leaving that one with the two call sites that keep the words in sync. (Philippe)

Cc John Snow <[email protected]>
Cc Peter Maydell <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>

Denis V. Lunev (17):
hw/ide: reject an unsupported CHS translation tests/qtest/ide-test: cover a CHS translation with zero sectors tests/qtest/libqos/ahci: allow a count and an expected error tests/qtest/ahci: cover the sector count of INITIALIZE DEVICE
PARAMETERS
hw/ide: report the default CHS translation in IDENTIFY DEVICE hw/ide: name the retired IDENTIFY DEVICE words the device fills in hw/ide: factor out the IDENTIFY DEVICE current geometry words hw/ide: keep the IDENTIFY DEVICE current geometry in sync hw/ide: restore the power-on device state before loading hw/ide: migrate the logical CHS translation
hw/ide: migrate the power-on defaults revert flag tests/qtest/ide-test: cover the CHS translation across migration tests/qtest/ide-test: cover a rejected CHS translation in the stream tests/qtest/ide-test: cover the IDENTIFY DEVICE geometry words hw/ide: revert the CHS translation on a hardware reset tests/qtest/ide-test: cover the CHS translation across resets hw/ide: drop a redundant interrupt from INITIALIZE DEVICE PARAMETERS

 hw/ide/ahci.c             |  12 +-
 hw/ide/cmd646.c           |   2 +-
 hw/ide/core.c             | 147 ++++++++---
 hw/ide/ide-internal.h     |   7 +-
 hw/ide/isa.c              |   2 +-
 hw/ide/macio.c            |   2 +-
 hw/ide/mmio.c             |   2 +-
 hw/ide/piix.c             |   2 +-
 hw/ide/sii3112.c          |   6 +-
 hw/ide/via.c              |   2 +-
 tests/qtest/ahci-test.c   |  40 +++
 tests/qtest/ide-test.c    | 499 ++++++++++++++++++++++++++++++++++++++
 tests/qtest/libqos/ahci.c |  14 ++
 tests/qtest/libqos/ahci.h |   6 +
 14 files changed, 690 insertions(+), 53 deletions(-)

base-commit: ae4f3443209ab154b48b706a146e5f557ab147cb

Signature · 1 line
2.53.0