All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 18/18] ahci: Fix non-NCQ accesses for LBA > 16bits
Date: Thu, 19 May 2011 14:33:32 +0200	[thread overview]
Message-ID: <1305808412-16994-19-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1305808412-16994-1-git-send-email-kwolf@redhat.com>

From: Alexander Graf <agraf@suse.de>

AHCI provides two ways of reading/writing data:

 1) NCQ
 2) ATA commands with the LBA in the command FIS

In the second code path, we didn't handle any LBAs that were bigger than
16 bits, so whenever a guest that used high LBA numbers wanted to access
data, the LBA got truncated down to 16 bits, giving the guest garbage.

This patch adds support for LBAs higher than 16 bits. I've tested that it
works just fine with SeaBIOS and Linux guests. This patch also unbreaks
the often reported grub errors people have seen with AHCI.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 hw/ide/ahci.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 744d19d..1f008a3 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -884,8 +884,31 @@ static int handle_cmd(AHCIState *s, int port, int slot)
         }
 
         if (ide_state->drive_kind != IDE_CD) {
-            ide_set_sector(ide_state, (cmd_fis[6] << 16) | (cmd_fis[5] << 8) |
-                           cmd_fis[4]);
+            /*
+             * We set the sector depending on the sector defined in the FIS.
+             * Unfortunately, the spec isn't exactly obvious on this one.
+             *
+             * Apparently LBA48 commands set fis bytes 10,9,8,6,5,4 to the
+             * 48 bit sector number. ATA_CMD_READ_DMA_EXT is an example for
+             * such a command.
+             *
+             * Non-LBA48 commands however use 7[lower 4 bits],6,5,4 to define a
+             * 28-bit sector number. ATA_CMD_READ_DMA is an example for such
+             * a command.
+             *
+             * Since the spec doesn't explicitly state what each field should
+             * do, I simply assume non-used fields as reserved and OR everything
+             * together, independent of the command.
+             */
+            ide_set_sector(ide_state, ((uint64_t)cmd_fis[10] << 40)
+                                    | ((uint64_t)cmd_fis[9] << 32)
+                                    /* This is used for LBA48 commands */
+                                    | ((uint64_t)cmd_fis[8] << 24)
+                                    /* This is used for non-LBA48 commands */
+                                    | ((uint64_t)(cmd_fis[7] & 0xf) << 24)
+                                    | ((uint64_t)cmd_fis[6] << 16)
+                                    | ((uint64_t)cmd_fis[5] << 8)
+                                    | cmd_fis[4]);
         }
 
         /* Copy the ACMD field (ATAPI packet, if any) from the AHCI command
-- 
1.7.2.3

  parent reply	other threads:[~2011-05-19 12:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-19 12:33 [Qemu-devel] [PULL 00/18] Block patches Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 01/18] ide: cleanup warnings Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 02/18] posix-aio-compat: Fix idle_threads counter Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 03/18] qemu-img.c: Remove superfluous parenthesis Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 04/18] hw/xen_disk: Remove unused local variable Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 05/18] ide: Turn debug messages into assertions Kevin Wolf
2011-05-26 21:12   ` Luiz Capitulino
2011-05-27  6:39     ` Kevin Wolf
2011-05-27 13:12       ` Luiz Capitulino
2011-06-01 13:44     ` Luiz Capitulino
2011-06-01 14:02       ` Kevin Wolf
2011-06-01 14:07         ` Luiz Capitulino
2011-06-01 15:32         ` Markus Armbruster
2011-06-06  9:08           ` Kevin Wolf
2011-06-06 11:57             ` Markus Armbruster
2011-06-06 12:56               ` Kevin Wolf
2011-06-06 13:52                 ` Markus Armbruster
2011-06-06 15:54       ` Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 06/18] Add documentation for qemu_progress_{init, print}() Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 07/18] ahci: Fix crashes on duplicate BH registration Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 08/18] qemu-tool: Stub out qemu-timer functions Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 09/18] qed: Periodically flush and clear need check bit Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 10/18] qemu_img: is_not_zero() optimization Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 11/18] qed: support for growing images Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 12/18] ide: Split qdev "ide-drive" into "ide-hd" and "ide-cd" Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 13/18] scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd" Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 14/18] defaults: ide-cd, ide-hd and scsi-cd devices suppress default CD-ROM Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 15/18] block QMP: Deprecate query-block's "type", drop info block's "type=" Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 16/18] blockdev: Store -drive option media in DriveInfo Kevin Wolf
2011-05-19 12:33 ` [Qemu-devel] [PATCH 17/18] block: Remove type hint, it's guest matter, doesn't belong here Kevin Wolf
2011-05-19 12:33 ` Kevin Wolf [this message]
2011-05-19 15:09 ` [Qemu-devel] [PULL 00/18] Block patches Anthony Liguori

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=1305808412-16994-19-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@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.