Skip to contentSkip to conversation

virtio-blk: fix minimum number of S/G elements

PATCH In review Christoph Hellwig 2 participants 2 messages May 25, 2010 – May 26, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-blk: fix minimum number of S/G elements

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.

drivers/block/virtio_blk.c +4 -2
Index: linux-2.6/drivers/block/virtio_blk.c
===================================================================
@@ -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. */
#1 lore raw
Quoted 6 lines · Christoph Hellwig

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.

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 <[email protected]>

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.

drivers/block/virtio_blk.c +3 -1
@@ -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. */