qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
@ 2012-11-22  9:07 Stefan Priebe
  2012-11-22 16:40 ` Andreas Färber
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Stefan Priebe @ 2012-11-22  9:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, Stefan Priebe, stefanha, sw, josh.durgin,
	ceph-devel

When acb->cmd is WRITE or DISCARD block/rbd stores rcb->size into acb->ret

Look here:
   if (acb->cmd == RBD_AIO_WRITE ||
        acb->cmd == RBD_AIO_DISCARD) {
        if (r < 0) {
            acb->ret = r;
            acb->error = 1;
        } else if (!acb->error) {
            acb->ret = rcb->size;
        }

right now acb->ret is just an int and we might get an overflow if size is too big.
For discards rcb->size holds the size of the discard - this might be some TB if you
discard a whole device.

The steps to reproduce are:
mkfs.xfs -f a whole device bigger than int in bytes. mkfs.xfs sends a discard. Important is that you use scsi-hd and set discard_granularity=512. Otherwise rbd disabled discard support.
---
 block/rbd.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index 5a0f79f..0384c6c 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -69,7 +69,7 @@ typedef enum {
 typedef struct RBDAIOCB {
     BlockDriverAIOCB common;
     QEMUBH *bh;
-    int ret;
+    ssize_t ret;
     QEMUIOVector *qiov;
     char *bounce;
     RBDAIOCmd cmd;
@@ -86,7 +86,7 @@ typedef struct RADOSCB {
     int done;
     int64_t size;
     char *buf;
-    int ret;
+    ssize_t ret;
 } RADOSCB;
 
 #define RBD_FD_READ 0
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-22  9:07 [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret Stefan Priebe
@ 2012-11-22 16:40 ` Andreas Färber
  2012-11-22 19:09   ` Stefan Priebe - Profihost AG
  2012-11-22 20:49 ` Stefan Priebe - Profihost AG
  2012-11-23 14:11 ` Stefan Hajnoczi
  2 siblings, 1 reply; 9+ messages in thread
From: Andreas Färber @ 2012-11-22 16:40 UTC (permalink / raw)
  To: Stefan Priebe
  Cc: peter.maydell, sw, qemu-devel, stefanha, josh.durgin, ceph-devel

Am 22.11.2012 10:07, schrieb Stefan Priebe:
> When acb->cmd is WRITE or DISCARD block/rbd stores rcb->size into acb->ret
> 
> Look here:
>    if (acb->cmd == RBD_AIO_WRITE ||
>         acb->cmd == RBD_AIO_DISCARD) {
>         if (r < 0) {
>             acb->ret = r;
>             acb->error = 1;
>         } else if (!acb->error) {
>             acb->ret = rcb->size;
>         }
> 
> right now acb->ret is just an int and we might get an overflow if size is too big.
> For discards rcb->size holds the size of the discard - this might be some TB if you
> discard a whole device.
> 
> The steps to reproduce are:
> mkfs.xfs -f a whole device bigger than int in bytes. mkfs.xfs sends a discard. Important is that you use scsi-hd and set discard_granularity=512. Otherwise rbd disabled discard support.

Whatever type you decide to use, please add an identifying topic such as
"block/rbd:" in the subject (int ret is very generic!), and this patch
is missing a Signed-off-by.

Regards,
Andreas


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-22 16:40 ` Andreas Färber
@ 2012-11-22 19:09   ` Stefan Priebe - Profihost AG
  2012-11-22 19:37     ` Stefan Weil
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Priebe - Profihost AG @ 2012-11-22 19:09 UTC (permalink / raw)
  To: Andreas Färber
  Cc: peter.maydell, sw, qemu-devel, stefanha, josh.durgin, ceph-devel

Hi Andreas,

thanks for your comment. Do i have to resend this patch?

--
Greets,
Stefan

Am 22.11.2012 17:40, schrieb Andreas Färber:
> Am 22.11.2012 10:07, schrieb Stefan Priebe:
>> When acb->cmd is WRITE or DISCARD block/rbd stores rcb->size into acb->ret
>>
>> Look here:
>>     if (acb->cmd == RBD_AIO_WRITE ||
>>          acb->cmd == RBD_AIO_DISCARD) {
>>          if (r<  0) {
>>              acb->ret = r;
>>              acb->error = 1;
>>          } else if (!acb->error) {
>>              acb->ret = rcb->size;
>>          }
>>
>> right now acb->ret is just an int and we might get an overflow if size is too big.
>> For discards rcb->size holds the size of the discard - this might be some TB if you
>> discard a whole device.
>>
>> The steps to reproduce are:
>> mkfs.xfs -f a whole device bigger than int in bytes. mkfs.xfs sends a discard. Important is that you use scsi-hd and set discard_granularity=512. Otherwise rbd disabled discard support.
>
> Whatever type you decide to use, please add an identifying topic such as
> "block/rbd:" in the subject (int ret is very generic!), and this patch
> is missing a Signed-off-by.
>
> Regards,
> Andreas
>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-22 19:09   ` Stefan Priebe - Profihost AG
@ 2012-11-22 19:37     ` Stefan Weil
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Weil @ 2012-11-22 19:37 UTC (permalink / raw)
  To: Stefan Priebe - Profihost AG
  Cc: peter.maydell, stefanha, qemu-devel, josh.durgin, ceph-devel,
	Andreas Färber

Am 22.11.2012 20:09, schrieb Stefan Priebe - Profihost AG:
> Hi Andreas,
>
> thanks for your comment. Do i have to resend this patch?
>
> -- 
> Greets,
> Stefan
>


Hi Stefan,

I'm afraid yes, you'll have to resend the patch.

Signed-off-by is a must, see http://wiki.qemu.org/Contribute/SubmitAPatch

When you resend the patch, you can fix the minor issues (subject)as well.

Regards

StefanW.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-22  9:07 [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret Stefan Priebe
  2012-11-22 16:40 ` Andreas Färber
@ 2012-11-22 20:49 ` Stefan Priebe - Profihost AG
  2012-11-23 14:11 ` Stefan Hajnoczi
  2 siblings, 0 replies; 9+ messages in thread
From: Stefan Priebe - Profihost AG @ 2012-11-22 20:49 UTC (permalink / raw)
  To: Stefan Priebe
  Cc: peter.maydell, stefanha, qemu-devel, sw, josh.durgin, ceph-devel


Signed-off-by: Stefan Priebe <s.priebe@profihost.ag>

Am 22.11.2012 10:07, schrieb Stefan Priebe:
> When acb->cmd is WRITE or DISCARD block/rbd stores rcb->size into acb->ret
>
> Look here:
>     if (acb->cmd == RBD_AIO_WRITE ||
>          acb->cmd == RBD_AIO_DISCARD) {
>          if (r<  0) {
>              acb->ret = r;
>              acb->error = 1;
>          } else if (!acb->error) {
>              acb->ret = rcb->size;
>          }
>
> right now acb->ret is just an int and we might get an overflow if size is too big.
> For discards rcb->size holds the size of the discard - this might be some TB if you
> discard a whole device.
>
> The steps to reproduce are:
> mkfs.xfs -f a whole device bigger than int in bytes. mkfs.xfs sends a discard. Important is that you use scsi-hd and set discard_granularity=512. Otherwise rbd disabled discard support.
> ---
>   block/rbd.c |    4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/rbd.c b/block/rbd.c
> index 5a0f79f..0384c6c 100644
> --- a/block/rbd.c
> +++ b/block/rbd.c
> @@ -69,7 +69,7 @@ typedef enum {
>   typedef struct RBDAIOCB {
>       BlockDriverAIOCB common;
>       QEMUBH *bh;
> -    int ret;
> +    ssize_t ret;
>       QEMUIOVector *qiov;
>       char *bounce;
>       RBDAIOCmd cmd;
> @@ -86,7 +86,7 @@ typedef struct RADOSCB {
>       int done;
>       int64_t size;
>       char *buf;
> -    int ret;
> +    ssize_t ret;
>   } RADOSCB;
>
>   #define RBD_FD_READ 0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-22  9:07 [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret Stefan Priebe
  2012-11-22 16:40 ` Andreas Färber
  2012-11-22 20:49 ` Stefan Priebe - Profihost AG
@ 2012-11-23 14:11 ` Stefan Hajnoczi
  2012-11-23 14:15   ` Peter Maydell
  2 siblings, 1 reply; 9+ messages in thread
From: Stefan Hajnoczi @ 2012-11-23 14:11 UTC (permalink / raw)
  To: Stefan Priebe
  Cc: Peter Maydell, Josh Durgin, ceph-devel, qemu-devel, Stefan Weil

On Thu, Nov 22, 2012 at 10:07 AM, Stefan Priebe <s.priebe@profihost.ag> wrote:
> diff --git a/block/rbd.c b/block/rbd.c
> index 5a0f79f..0384c6c 100644
> --- a/block/rbd.c
> +++ b/block/rbd.c
> @@ -69,7 +69,7 @@ typedef enum {
>  typedef struct RBDAIOCB {
>      BlockDriverAIOCB common;
>      QEMUBH *bh;
> -    int ret;
> +    ssize_t ret;
>      QEMUIOVector *qiov;
>      char *bounce;
>      RBDAIOCmd cmd;
> @@ -86,7 +86,7 @@ typedef struct RADOSCB {
>      int done;
>      int64_t size;
>      char *buf;
> -    int ret;
> +    ssize_t ret;
>  } RADOSCB;
>
>  #define RBD_FD_READ 0

I preferred your previous patch:

ssize_t on 32-bit hosts has sizeof(ssize_t) == 4.  In
qemu_rbd_complete_aio() we may assign acb->ret = rcb->size.  Here the
size field is int64_t, so ssize_t ret would truncate the value.

But BlockDriverCompetionFunc only takes an int argument so we're back
to square one.

The types are busted and changing the type of ret won't fix that :(.

Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-23 14:11 ` Stefan Hajnoczi
@ 2012-11-23 14:15   ` Peter Maydell
  2012-11-23 14:38     ` Stefan Priebe - Profihost AG
  2012-11-23 15:56     ` Stefan Hajnoczi
  0 siblings, 2 replies; 9+ messages in thread
From: Peter Maydell @ 2012-11-23 14:15 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Josh Durgin, ceph-devel, Stefan Weil, qemu-devel, Stefan Priebe

On 23 November 2012 14:11, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Thu, Nov 22, 2012 at 10:07 AM, Stefan Priebe <s.priebe@profihost.ag> wrote:
>> diff --git a/block/rbd.c b/block/rbd.c
>> index 5a0f79f..0384c6c 100644
>> --- a/block/rbd.c
>> +++ b/block/rbd.c
>> @@ -69,7 +69,7 @@ typedef enum {
>>  typedef struct RBDAIOCB {
>>      BlockDriverAIOCB common;
>>      QEMUBH *bh;
>> -    int ret;
>> +    ssize_t ret;
>>      QEMUIOVector *qiov;
>>      char *bounce;
>>      RBDAIOCmd cmd;
>> @@ -86,7 +86,7 @@ typedef struct RADOSCB {
>>      int done;
>>      int64_t size;
>>      char *buf;
>> -    int ret;
>> +    ssize_t ret;
>>  } RADOSCB;
>>
>>  #define RBD_FD_READ 0
>
> I preferred your previous patch:
>
> ssize_t on 32-bit hosts has sizeof(ssize_t) == 4.  In
> qemu_rbd_complete_aio() we may assign acb->ret = rcb->size.  Here the
> size field is int64_t, so ssize_t ret would truncate the value.

The rcb size field should be a size_t: it is used for calling
rbd_aio_write and rbd_aio_read so if we've overflowed 32 bits
then we've already got a problem there.

-- PMM

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-23 14:15   ` Peter Maydell
@ 2012-11-23 14:38     ` Stefan Priebe - Profihost AG
  2012-11-23 15:56     ` Stefan Hajnoczi
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Priebe - Profihost AG @ 2012-11-23 14:38 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Stefan Hajnoczi, ceph-devel, Stefan Weil, qemu-devel, Josh Durgin

Hi,

i'm not a ceph or inktank guy. I can't made any decision on what to 
change. At least right now you'll see failing I/O's in your guest, when 
you discard whole disks.

I could fix this for me with int64 and with ssize_t. So if i should 
resend another patch i need a concrete advise how to patch.

Thanks!

Greets,
Stefan

Am 23.11.2012 15:15, schrieb Peter Maydell:
> On 23 November 2012 14:11, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>> On Thu, Nov 22, 2012 at 10:07 AM, Stefan Priebe <s.priebe@profihost.ag> wrote:
>>> diff --git a/block/rbd.c b/block/rbd.c
>>> index 5a0f79f..0384c6c 100644
>>> --- a/block/rbd.c
>>> +++ b/block/rbd.c
>>> @@ -69,7 +69,7 @@ typedef enum {
>>>   typedef struct RBDAIOCB {
>>>       BlockDriverAIOCB common;
>>>       QEMUBH *bh;
>>> -    int ret;
>>> +    ssize_t ret;
>>>       QEMUIOVector *qiov;
>>>       char *bounce;
>>>       RBDAIOCmd cmd;
>>> @@ -86,7 +86,7 @@ typedef struct RADOSCB {
>>>       int done;
>>>       int64_t size;
>>>       char *buf;
>>> -    int ret;
>>> +    ssize_t ret;
>>>   } RADOSCB;
>>>
>>>   #define RBD_FD_READ 0
>>
>> I preferred your previous patch:
>>
>> ssize_t on 32-bit hosts has sizeof(ssize_t) == 4.  In
>> qemu_rbd_complete_aio() we may assign acb->ret = rcb->size.  Here the
>> size field is int64_t, so ssize_t ret would truncate the value.
>
> The rcb size field should be a size_t: it is used for calling
> rbd_aio_write and rbd_aio_read so if we've overflowed 32 bits
> then we've already got a problem there.
>
> -- PMM
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret
  2012-11-23 14:15   ` Peter Maydell
  2012-11-23 14:38     ` Stefan Priebe - Profihost AG
@ 2012-11-23 15:56     ` Stefan Hajnoczi
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2012-11-23 15:56 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Josh Durgin, ceph-devel, Stefan Weil, qemu-devel, Stefan Priebe

On Fri, Nov 23, 2012 at 3:15 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 23 November 2012 14:11, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>> On Thu, Nov 22, 2012 at 10:07 AM, Stefan Priebe <s.priebe@profihost.ag> wrote:
>>> diff --git a/block/rbd.c b/block/rbd.c
>>> index 5a0f79f..0384c6c 100644
>>> --- a/block/rbd.c
>>> +++ b/block/rbd.c
>>> @@ -69,7 +69,7 @@ typedef enum {
>>>  typedef struct RBDAIOCB {
>>>      BlockDriverAIOCB common;
>>>      QEMUBH *bh;
>>> -    int ret;
>>> +    ssize_t ret;
>>>      QEMUIOVector *qiov;
>>>      char *bounce;
>>>      RBDAIOCmd cmd;
>>> @@ -86,7 +86,7 @@ typedef struct RADOSCB {
>>>      int done;
>>>      int64_t size;
>>>      char *buf;
>>> -    int ret;
>>> +    ssize_t ret;
>>>  } RADOSCB;
>>>
>>>  #define RBD_FD_READ 0
>>
>> I preferred your previous patch:
>>
>> ssize_t on 32-bit hosts has sizeof(ssize_t) == 4.  In
>> qemu_rbd_complete_aio() we may assign acb->ret = rcb->size.  Here the
>> size field is int64_t, so ssize_t ret would truncate the value.
>
> The rcb size field should be a size_t: it is used for calling
> rbd_aio_write and rbd_aio_read so if we've overflowed 32 bits
> then we've already got a problem there.

You are right that size_t is fine for read/write.

But size_t is not fine for discard:
1. librbd takes uint64_t for discard.
2. Completing a discard request uses size.
3. BlockDriverCompletionFunc only passes int ret value <--- broken for
large discard

Stefan Priebe has been discarding large regions (e.g. >4 GB must be
possible on a 32-bit host).

The previous int64_t patch didn't clean up types completely but it
made things better.  AFAICT we need to be able to discard >4 GB so
ssize_t/size_t doesn't cut it on 32-bit hosts.

Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-11-23 15:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-22  9:07 [Qemu-devel] [PATCH] overflow of int ret: use ssize_t for ret Stefan Priebe
2012-11-22 16:40 ` Andreas Färber
2012-11-22 19:09   ` Stefan Priebe - Profihost AG
2012-11-22 19:37     ` Stefan Weil
2012-11-22 20:49 ` Stefan Priebe - Profihost AG
2012-11-23 14:11 ` Stefan Hajnoczi
2012-11-23 14:15   ` Peter Maydell
2012-11-23 14:38     ` Stefan Priebe - Profihost AG
2012-11-23 15:56     ` Stefan Hajnoczi

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).