* [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
@ 2011-05-18 12:48 Alexander Graf
2011-05-18 19:16 ` Jan Kiszka
0 siblings, 1 reply; 7+ messages in thread
From: Alexander Graf @ 2011-05-18 12:48 UTC (permalink / raw)
To: qemu-devel@nongnu.org Developers
Cc: Kevin Wolf, René Rebe, Jan Kiszka, Alexey Zaytsev
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>
---
hw/ide/ahci.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index c6e0c77..bc5c553 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -884,8 +884,13 @@ 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]);
+ ide_set_sector(ide_state, ((uint64_t)cmd_fis[10] << 40)
+ | ((uint64_t)cmd_fis[9] << 32)
+ | ((uint64_t)cmd_fis[8] << 24)
+ | ((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.6.0.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
2011-05-18 12:48 Alexander Graf
@ 2011-05-18 19:16 ` Jan Kiszka
2011-05-18 19:38 ` Alexander Graf
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kiszka @ 2011-05-18 19:16 UTC (permalink / raw)
To: Alexander Graf
Cc: Kevin Wolf, René Rebe, qemu-devel@nongnu.org Developers,
Alexey Zaytsev
[-- Attachment #1: Type: text/plain, Size: 1878 bytes --]
On 2011-05-18 14:48, Alexander Graf wrote:
> 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.
Cool! I actually had such a guest as well, but I didn't manage to look
closer so far. Now this patch cures it.
Jan
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
> hw/ide/ahci.c | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> index c6e0c77..bc5c553 100644
> --- a/hw/ide/ahci.c
> +++ b/hw/ide/ahci.c
> @@ -884,8 +884,13 @@ 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]);
> + ide_set_sector(ide_state, ((uint64_t)cmd_fis[10] << 40)
> + | ((uint64_t)cmd_fis[9] << 32)
> + | ((uint64_t)cmd_fis[8] << 24)
> + | ((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
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
2011-05-18 19:16 ` Jan Kiszka
@ 2011-05-18 19:38 ` Alexander Graf
0 siblings, 0 replies; 7+ messages in thread
From: Alexander Graf @ 2011-05-18 19:38 UTC (permalink / raw)
To: Jan Kiszka
Cc: Kevin Wolf, René Rebe, qemu-devel@nongnu.org Developers,
Alexey Zaytsev
On 18.05.2011, at 21:16, Jan Kiszka wrote:
> On 2011-05-18 14:48, Alexander Graf wrote:
>> 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.
>
> Cool! I actually had such a guest as well, but I didn't manage to look
> closer so far. Now this patch cures it.
Heh, yeah. Only costed me 2 days of my life - sigh :)
Alex
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
@ 2011-05-19 9:57 Alexander Graf
2011-05-19 10:09 ` Kevin Wolf
0 siblings, 1 reply; 7+ messages in thread
From: Alexander Graf @ 2011-05-19 9:57 UTC (permalink / raw)
To: qemu-devel@nongnu.org Developers
Cc: Kevin Wolf, René Rebe, Jan Kiszka, Alexey Zaytsev
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>
---
v1 -> v2:
- document fis bytes
---
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 c6e0c77..db20aae 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.6.0.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
2011-05-19 9:57 [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits Alexander Graf
@ 2011-05-19 10:09 ` Kevin Wolf
0 siblings, 0 replies; 7+ messages in thread
From: Kevin Wolf @ 2011-05-19 10:09 UTC (permalink / raw)
To: Alexander Graf
Cc: René Rebe, Jan Kiszka, qemu-devel@nongnu.org Developers,
Alexey Zaytsev
Am 19.05.2011 11:57, schrieb Alexander Graf:
> 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>
>
> ---
>
> v1 -> v2:
>
> - document fis bytes
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
@ 2011-05-24 22:46 Alexander Graf
2011-05-24 22:58 ` Alexander Graf
0 siblings, 1 reply; 7+ messages in thread
From: Alexander Graf @ 2011-05-24 22:46 UTC (permalink / raw)
To: qemu-devel@nongnu.org Developers; +Cc: Kevin Wolf
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>
---
hw/ide/ahci.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index c6e0c77..bc5c553 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -884,8 +884,13 @@ 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]);
+ ide_set_sector(ide_state, ((uint64_t)cmd_fis[10] << 40)
+ | ((uint64_t)cmd_fis[9] << 32)
+ | ((uint64_t)cmd_fis[8] << 24)
+ | ((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.6.0.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
2011-05-24 22:46 Alexander Graf
@ 2011-05-24 22:58 ` Alexander Graf
0 siblings, 0 replies; 7+ messages in thread
From: Alexander Graf @ 2011-05-24 22:58 UTC (permalink / raw)
To: Alexander Graf; +Cc: Kevin Wolf, qemu-devel@nongnu.org Developers
On 25.05.2011, at 00:46, Alexander Graf wrote:
> 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>
Eh - ignore that one please. I was reusing an old git-send-email command line that accidently had this patch in it :).
Alex
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-05-24 22:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-19 9:57 [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits Alexander Graf
2011-05-19 10:09 ` Kevin Wolf
-- strict thread matches above, loose matches on Subject: below --
2011-05-24 22:46 Alexander Graf
2011-05-24 22:58 ` Alexander Graf
2011-05-18 12:48 Alexander Graf
2011-05-18 19:16 ` Jan Kiszka
2011-05-18 19:38 ` Alexander Graf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).