All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Denis V. Lunev" <den@openvz.org>,
	"John Snow" <jsnow@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
	qemu-stable@nongnu.org
Subject: [PATCH v2 05/17] hw/ide: report the default CHS translation in IDENTIFY DEVICE
Date: Thu, 20 Aug 2026 12:08:32 +0200	[thread overview]
Message-ID: <20260820100844.411717-6-den@openvz.org> (raw)
In-Reply-To: <20260820100844.411717-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

IDENTIFY DEVICE words 1, 3 and 6 describe the default CHS translation,
and ATA-5 8.16.8 requires INITIALIZE DEVICE PARAMETERS to leave them
alone; the translation in effect is described by words 54 to 56 instead.
Words 3 and 6 were filled from s->heads and s->sectors, which the command
replaces, so a guest that selected a translation of its own was told that
its choice was what the drive came with, and could no longer find out the
default. Word 1 is already right, as no command changes s->cylinders.

Report s->drive_heads and s->drive_sectors, which ide_init_drive() keeps
for exactly this, along with the retired word 4 derived from them. The
CompactFlash data labels those words as the default geometry too, and
INITIALIZE DEVICE PARAMETERS is accepted for CFA drives, so fix both.

Cc: John Snow <jsnow@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Cc: qemu-stable@nongnu.org
Fixes: 176e4961bb33 ("hw/ide/core.c: Implement ATA INITIALIZE_DEVICE_PARAMETERS command")
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 hw/ide/core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 747fa71677..befbab9486 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -138,11 +138,12 @@ static void ide_identify(IDEState *s)
     memset(p, 0, sizeof(s->identify_data));
 
     put_le16(p + 0, 0x0040);
+    /* Words 1, 3 and 6 describe the default translation (ATA-5 8.16.8) */
     put_le16(p + 1, s->cylinders);
-    put_le16(p + 3, s->heads);
-    put_le16(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */
+    put_le16(p + 3, s->drive_heads);
+    put_le16(p + 4, 512 * s->drive_sectors); /* XXX: retired, remove ? */
     put_le16(p + 5, 512); /* XXX: retired, remove ? */
-    put_le16(p + 6, s->sectors);
+    put_le16(p + 6, s->drive_sectors);
     padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
     put_le16(p + 20, 3); /* XXX: retired, remove ? */
     put_le16(p + 21, 512); /* cache size in sectors */
@@ -332,8 +333,8 @@ static void ide_cfata_identify(IDEState *s)
 
     put_le16(p + 0, 0x848a);                    /* CF Storage Card signature */
     put_le16(p + 1, s->cylinders);              /* Default cylinders */
-    put_le16(p + 3, s->heads);                  /* Default heads */
-    put_le16(p + 6, s->sectors);                /* Default sectors per track */
+    put_le16(p + 3, s->drive_heads);            /* Default heads */
+    put_le16(p + 6, s->drive_sectors);          /* Default sectors per track */
     /* *(p + 7) := nb_sectors >> 16 -- see ide_cfata_identify_size */
     /* *(p + 8) := nb_sectors       -- see ide_cfata_identify_size */
     padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
-- 
2.53.0



  parent reply	other threads:[~2026-08-20 10:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20 10:08 [PATCH v2 00/17] hw/ide: fix the logical CHS translation a guest selects Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 01/17] hw/ide: reject an unsupported CHS translation Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 02/17] tests/qtest/ide-test: cover a CHS translation with zero sectors Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 03/17] tests/qtest/libqos/ahci: allow a count and an expected error Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 04/17] tests/qtest/ahci: cover the sector count of INITIALIZE DEVICE PARAMETERS Denis V. Lunev
2026-08-20 10:08 ` Denis V. Lunev [this message]
2026-08-20 10:08 ` [PATCH v2 06/17] hw/ide: name the retired IDENTIFY DEVICE words the device fills in Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 07/17] hw/ide: factor out the IDENTIFY DEVICE current geometry words Denis V. Lunev
2026-08-20 11:07   ` Philippe Mathieu-Daudé
2026-08-20 10:08 ` [PATCH v2 08/17] hw/ide: keep the IDENTIFY DEVICE current geometry in sync Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 09/17] hw/ide: restore the power-on device state before loading Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 10/17] hw/ide: migrate the logical CHS translation Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 11/17] hw/ide: migrate the power-on defaults revert flag Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 12/17] tests/qtest/ide-test: cover the CHS translation across migration Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 13/17] tests/qtest/ide-test: cover a rejected CHS translation in the stream Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 14/17] tests/qtest/ide-test: cover the IDENTIFY DEVICE geometry words Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 15/17] hw/ide: revert the CHS translation on a hardware reset Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 16/17] tests/qtest/ide-test: cover the CHS translation across resets Denis V. Lunev
2026-08-20 10:08 ` [PATCH v2 17/17] hw/ide: drop a redundant interrupt from INITIALIZE DEVICE PARAMETERS Denis V. Lunev
2026-08-20 11:08   ` Philippe Mathieu-Daudé
2026-08-20 13:09 ` [PATCH v2 00/17] hw/ide: fix the logical CHS translation a guest selects Denis V. Lunev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260820100844.411717-6-den@openvz.org \
    --to=den@openvz.org \
    --cc=jsnow@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@oss.qualcomm.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.