* [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
@ 2011-05-24 22:46 Alexander Graf
2011-05-24 22:46 ` [Qemu-devel] [PATCH] vmdk: fix endianness bugs Alexander Graf
2011-05-24 22:58 ` [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits Alexander Graf
0 siblings, 2 replies; 4+ 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] 4+ messages in thread
* [Qemu-devel] [PATCH] vmdk: fix endianness bugs
2011-05-24 22:46 [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits Alexander Graf
@ 2011-05-24 22:46 ` Alexander Graf
2011-05-25 7:57 ` Kevin Wolf
2011-05-24 22:58 ` [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits Alexander Graf
1 sibling, 1 reply; 4+ messages in thread
From: Alexander Graf @ 2011-05-24 22:46 UTC (permalink / raw)
To: qemu-devel@nongnu.org Developers; +Cc: Kevin Wolf
The vmdk code is sloppy when handling the header descriptor during
creation of an image. Fix all header accesses in the create path to
either store native endianness or convert it when appropriate.
Reported-by: Yury Tsarev <ytsarev@novell.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
block/vmdk.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 8fc9d67..922b23d 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -716,11 +716,11 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
return -errno;
magic = cpu_to_be32(VMDK4_MAGIC);
memset(&header, 0, sizeof(header));
- header.version = cpu_to_le32(1);
- header.flags = cpu_to_le32(3); /* ?? */
- header.capacity = cpu_to_le64(total_size);
- header.granularity = cpu_to_le64(128);
- header.num_gtes_per_gte = cpu_to_le32(512);
+ header.version = 1;
+ header.flags = 3; /* ?? */
+ header.capacity = total_size;
+ header.granularity = 128;
+ header.num_gtes_per_gte = 512;
grains = (total_size + header.granularity - 1) / header.granularity;
gt_size = ((header.num_gtes_per_gte * sizeof(uint32_t)) + 511) >> 9;
@@ -736,6 +736,12 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
header.granularity - 1) / header.granularity) *
header.granularity;
+ /* swap endianness for all header fields */
+ header.version = cpu_to_le32(header.version);
+ header.flags = cpu_to_le32(header.flags);
+ header.capacity = cpu_to_le64(header.capacity);
+ header.granularity = cpu_to_le64(header.granularity);
+ header.num_gtes_per_gte = cpu_to_le32(header.num_gtes_per_gte);
header.desc_offset = cpu_to_le64(header.desc_offset);
header.desc_size = cpu_to_le64(header.desc_size);
header.rgd_offset = cpu_to_le64(header.rgd_offset);
@@ -759,7 +765,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
goto exit;
}
- ret = ftruncate(fd, header.grain_offset << 9);
+ ret = ftruncate(fd, le64_to_cpu(header.grain_offset) << 9);
if (ret < 0) {
ret = -errno;
goto exit;
@@ -767,7 +773,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
/* write grain directory */
lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET);
- for (i = 0, tmp = header.rgd_offset + gd_size;
+ for (i = 0, tmp = le64_to_cpu(header.rgd_offset) + gd_size;
i < gt_count; i++, tmp += gt_size) {
ret = qemu_write_full(fd, &tmp, sizeof(tmp));
if (ret != sizeof(tmp)) {
@@ -778,7 +784,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
/* write backup grain directory */
lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET);
- for (i = 0, tmp = header.gd_offset + gd_size;
+ for (i = 0, tmp = le64_to_cpu(header.gd_offset) + gd_size;
i < gt_count; i++, tmp += gt_size) {
ret = qemu_write_full(fd, &tmp, sizeof(tmp));
if (ret != sizeof(tmp)) {
--
1.6.0.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits
2011-05-24 22:46 [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits Alexander Graf
2011-05-24 22:46 ` [Qemu-devel] [PATCH] vmdk: fix endianness bugs Alexander Graf
@ 2011-05-24 22:58 ` Alexander Graf
1 sibling, 0 replies; 4+ 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] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] vmdk: fix endianness bugs
2011-05-24 22:46 ` [Qemu-devel] [PATCH] vmdk: fix endianness bugs Alexander Graf
@ 2011-05-25 7:57 ` Kevin Wolf
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2011-05-25 7:57 UTC (permalink / raw)
To: Alexander Graf; +Cc: qemu-devel@nongnu.org Developers
Am 25.05.2011 00:46, schrieb Alexander Graf:
> The vmdk code is sloppy when handling the header descriptor during
> creation of an image. Fix all header accesses in the create path to
> either store native endianness or convert it when appropriate.
>
> Reported-by: Yury Tsarev <ytsarev@novell.com>
> Signed-off-by: Alexander Graf <agraf@suse.de>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-05-25 14:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-24 22:46 [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits Alexander Graf
2011-05-24 22:46 ` [Qemu-devel] [PATCH] vmdk: fix endianness bugs Alexander Graf
2011-05-25 7:57 ` Kevin Wolf
2011-05-24 22:58 ` [Qemu-devel] [PATCH] ahci: Fix non-NCQ accesses for LBA > 16bits 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).