public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio-blk: fix minimum number of S/G elements
@ 2010-05-25 12:17 Christoph Hellwig
  2010-05-26  8:03 ` Rusty Russell
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2010-05-25 12:17 UTC (permalink / raw)
  To: rusty; +Cc: linux-kernel


We need at least one S/G element to operate properly, as does the block
layer which increments it to one anyway.  We hit this due to a qemu
bug which advertises a sg_elements of 0 under some circumstances.

Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: linux-2.6/drivers/block/virtio_blk.c
===================================================================
--- linux-2.6.orig/drivers/block/virtio_blk.c	2010-05-25 13:21:44.136254435 +0200
+++ linux-2.6/drivers/block/virtio_blk.c	2010-05-25 13:59:04.334005727 +0200
@@ -287,7 +287,7 @@ static int __devinit virtblk_probe(struc
 	struct request_queue *q;
 	int err;
 	u64 cap;
-	u32 v, blk_size, sg_elems, opt_io_size;
+	u32 v, blk_size, sg_elems = 0, opt_io_size;
 	u16 min_io_size;
 	u8 physical_block_exp, alignment_offset;
 
@@ -298,7 +298,9 @@ static int __devinit virtblk_probe(struc
 	err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX,
 				offsetof(struct virtio_blk_config, seg_max),
 				&sg_elems);
-	if (err)
+
+	/* We need at least one SG element */
+	if (!sg_elems)
 		sg_elems = 1;
 
 	/* We need an extra sg elements at head and tail. */

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

* Re: [PATCH] virtio-blk: fix minimum number of S/G elements
  2010-05-25 12:17 [PATCH] virtio-blk: fix minimum number of S/G elements Christoph Hellwig
@ 2010-05-26  8:03 ` Rusty Russell
  0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2010-05-26  8:03 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel

On Tue, 25 May 2010 09:47:54 pm Christoph Hellwig wrote:
> 
> We need at least one S/G element to operate properly, as does the block
> layer which increments it to one anyway.  We hit this due to a qemu
> bug which advertises a sg_elements of 0 under some circumstances.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Seems reasonable: we might as well ignore it if device is obviously talking
crap.

However, the result is awkward (we assign err then don't use it), and assumes
that sg_elems isn't touched on error (true at the moment).

Prefer this:

Subject: virtio-blk: fix minimum number of S/G elements
Date: Tue, 25 May 2010 14:17:54 +0200
From: Christoph Hellwig <hch@lst.de>

We need at least one S/G element to operate properly, as does the block
layer which increments it to one anyway.  We hit this due to a qemu
bug which advertises a sg_elements of 0 under some circumstances.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (tweaked logic)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -298,7 +298,9 @@ static int __devinit virtblk_probe(struc
 	err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX,
 				offsetof(struct virtio_blk_config, seg_max),
 				&sg_elems);
-	if (err)
+
+	/* We need at least one SG element, whatever they say. */
+	if (err || !sg_elems)
 		sg_elems = 1;
 
 	/* We need an extra sg elements at head and tail. */

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

end of thread, other threads:[~2010-05-26  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-25 12:17 [PATCH] virtio-blk: fix minimum number of S/G elements Christoph Hellwig
2010-05-26  8:03 ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox