* [Qemu-devel] [PATCH] fix sector overflow for scsi disks >1TB large
@ 2009-01-26 22:42 Rik van Riel
2009-01-26 23:55 ` Jamie Lokier
0 siblings, 1 reply; 4+ messages in thread
From: Rik van Riel @ 2009-01-26 22:42 UTC (permalink / raw)
To: qemu-devel
Sector numbers can overflow on a virtual scsi disk of over 1TB
in size. Qemu's bdrv_read expects an int64_t, so fix the overflow
by going to that data type.
Also clip capacity to 2TB instead of returning "capacity modulo 2TB".
Signed-off-by: Rik van Riel <riel@redhat.com>
Index: trunk/hw/scsi-disk.c
===================================================================
--- trunk/hw/scsi-disk.c (revision 6451)
+++ trunk/hw/scsi-disk.c (working copy)
@@ -50,7 +50,7 @@
/* ??? We should probably keep track of whether the data trasfer is
a read or a write. Currently we rely on the host getting it right. */
/* Both sector and sector_count are in terms of qemu 512 byte blocks. */
- int sector;
+ uint64_t sector;
int sector_count;
/* The amounnt of data in the buffer. */
int buf_len;
@@ -731,6 +731,9 @@
/* Returned value is the address of the last sector. */
if (nb_sectors) {
nb_sectors--;
+ /* Clip to 2TB, instead of returning capacity modulo 2TB. */
+ if (nb_sectors > UINT_MAX)
+ nb_sectors = UINT_MAX;
outbuf[0] = (nb_sectors >> 24) & 0xff;
outbuf[1] = (nb_sectors >> 16) & 0xff;
outbuf[2] = (nb_sectors >> 8) & 0xff;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] fix sector overflow for scsi disks >1TB large
2009-01-26 22:42 Rik van Riel
@ 2009-01-26 23:55 ` Jamie Lokier
2009-01-27 15:49 ` Rik van Riel
0 siblings, 1 reply; 4+ messages in thread
From: Jamie Lokier @ 2009-01-26 23:55 UTC (permalink / raw)
To: qemu-devel
Rik van Riel wrote:
> @@ -50,7 +50,7 @@
> /* ??? We should probably keep track of whether the data trasfer is
Not your fault, but I just noticed a typo: "trasfer" :-)
> if (nb_sectors) {
> nb_sectors--;
> + /* Clip to 2TB, instead of returning capacity modulo 2TB. */
> + if (nb_sectors > UINT_MAX)
> + nb_sectors = UINT_MAX;
> outbuf[0] = (nb_sectors >> 24) & 0xff;
> outbuf[1] = (nb_sectors >> 16) & 0xff;
> outbuf[2] = (nb_sectors >> 8) & 0xff;
Wouldn't it be clearer andd safer to say 0xffffffff here, or UINT32_MAX?
I know QEMU only runs on hosts with 32-bit unsigned int, and perhaps
that will always be truea, but it's a bit unnecessary to assume it here.
-- JAmie
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] fix sector overflow for scsi disks >1TB large
2009-01-26 23:55 ` Jamie Lokier
@ 2009-01-27 15:49 ` Rik van Riel
0 siblings, 0 replies; 4+ messages in thread
From: Rik van Riel @ 2009-01-27 15:49 UTC (permalink / raw)
To: qemu-devel
Jamie Lokier wrote:
> Rik van Riel wrote:
>> @@ -50,7 +50,7 @@
>> /* ??? We should probably keep track of whether the data trasfer is
>
> Not your fault, but I just noticed a typo: "trasfer" :-)
>
>> if (nb_sectors) {
>> nb_sectors--;
>> + /* Clip to 2TB, instead of returning capacity modulo 2TB. */
>> + if (nb_sectors > UINT_MAX)
>> + nb_sectors = UINT_MAX;
>> outbuf[0] = (nb_sectors >> 24) & 0xff;
>> outbuf[1] = (nb_sectors >> 16) & 0xff;
>> outbuf[2] = (nb_sectors >> 8) & 0xff;
>
> Wouldn't it be clearer andd safer to say 0xffffffff here, or UINT32_MAX?
>
> I know QEMU only runs on hosts with 32-bit unsigned int, and perhaps
> that will always be truea, but it's a bit unnecessary to assume it here.
Neither of your suggested changes hurts one bit, so
I'll send in a new patch :)
--
All rights reversed.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH] fix sector overflow for scsi disks >1TB large
@ 2009-01-27 15:51 Rik van Riel
0 siblings, 0 replies; 4+ messages in thread
From: Rik van Riel @ 2009-01-27 15:51 UTC (permalink / raw)
To: qemu-devel
Sector numbers can overflow on a virtual scsi disk of over 1TB
in size. Qemu's bdrv_read expects an int64_t, so fix the overflow
by going to that data type.
Also clip capacity to 2TB instead of returning capacity modulo 2TB.
Signed-off-by: Rik van Riel <riel@redhat.com>
Index: trunk/hw/scsi-disk.c
===================================================================
--- trunk/hw/scsi-disk.c (revision 6451)
+++ trunk/hw/scsi-disk.c (working copy)
@@ -47,10 +47,10 @@
typedef struct SCSIRequest {
SCSIDeviceState *dev;
uint32_t tag;
- /* ??? We should probably keep track of whether the data trasfer is
+ /* ??? We should probably keep track of whether the data transfer is
a read or a write. Currently we rely on the host getting it right. */
/* Both sector and sector_count are in terms of qemu 512 byte blocks. */
- int sector;
+ uint64_t sector;
int sector_count;
/* The amounnt of data in the buffer. */
int buf_len;
@@ -731,6 +731,9 @@
/* Returned value is the address of the last sector. */
if (nb_sectors) {
nb_sectors--;
+ /* Clip to 2TB, instead of returning capacity modulo 2TB. */
+ if (nb_sectors > UINT32_MAX)
+ nb_sectors = UINT32_MAX;
outbuf[0] = (nb_sectors >> 24) & 0xff;
outbuf[1] = (nb_sectors >> 16) & 0xff;
outbuf[2] = (nb_sectors >> 8) & 0xff;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-01-27 15:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-27 15:51 [Qemu-devel] [PATCH] fix sector overflow for scsi disks >1TB large Rik van Riel
-- strict thread matches above, loose matches on Subject: below --
2009-01-26 22:42 Rik van Riel
2009-01-26 23:55 ` Jamie Lokier
2009-01-27 15:49 ` Rik van Riel
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).