Skip to contentSkip to conversation

virtio: Honour 'may_reduce_num' in vring_create_virtqueue

PATCH In review Cornelia Huck 4 participants 6 messages Apr 8, 2019 – Apr 9, 2019

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

PATCH 1/1 virtio: Honour 'may_reduce_num' in vring_create_virtqueue

vring_create_virtqueue() allows the caller to specify via the may_reduce_num parameter whether the vring code is allowed to allocate a smaller ring than specified.

However, the split ring allocation code tries to allocate a smaller ring on allocation failure regardless of what the caller specified. This may cause trouble for e.g. virtio-pci in legacy mode, which does not support ring resizing. (The packed ring code does not resize in any case.)

Let's fix this by bailing out immediately in the split ring code if the requested size cannot be allocated and may_reduce_num has not been specified.

While at it, fix a typo in the usage instructions.

Fixes 2a2d1382fe9d ("virtio: Add improved queue allocation API")
---
 drivers/virtio/virtio_ring.c | 2 ++
 include/linux/virtio_ring.h  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +2 -0
index 18846afb39da..5df92c308286 100644
@@ -882,6 +882,8 @@ static struct virtqueue *vring_create_virtqueue_split(
 					  GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO);
 		if (queue)
 			break;
+		if (!may_reduce_num)
+			return NULL;
 	}
 
 	if (!num)
include/linux/virtio_ring.h +1 -1
index fab02133a919..3dc70adfe5f5 100644
@@ -63,7 +63,7 @@ struct virtqueue;
 /*
  * Creates a virtqueue and allocates the descriptor ring.  If
  * may_reduce_num is set, then this may allocate a smaller ring than
- * expected.  The caller should query virtqueue_get_ring_size to learn
+ * expected.  The caller should query virtqueue_get_vring_size to learn
  * the actual size of the ring.
  */
 struct virtqueue *vring_create_virtqueue(unsigned int index,
Signature · 1 line
2.17.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Cornelia Huck

vring_create_virtqueue() allows the caller to specify via the may_reduce_num parameter whether the vring code is allowed to allocate a smaller ring than specified.

However, the split ring allocation code tries to allocate a smaller ring on allocation failure regardless of what the caller specified. This may cause trouble for e.g. virtio-pci in legacy mode, which does not support ring resizing. (The packed ring code does not resize in any case.)

Let's fix this by bailing out immediately in the split ring code if the requested size cannot be allocated and may_reduce_num has not been specified.

While at it, fix a typo in the usage instructions.

Quoted 8 lines
Fixes 2a2d1382fe9d ("virtio: Add improved queue allocation API")

---
drivers/virtio/virtio_ring.c | 2 ++
include/linux/virtio_ring.h | 2 +-

2 files changed, 3 insertions(+), 1 deletion(-)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Cornelia Huck
Quoted 16 lines · Cornelia Huck

vring_create_virtqueue() allows the caller to specify via the may_reduce_num parameter whether the vring code is allowed to allocate a smaller ring than specified.

However, the split ring allocation code tries to allocate a smaller ring on allocation failure regardless of what the caller specified. This may cause trouble for e.g. virtio-pci in legacy mode, which does not support ring resizing. (The packed ring code does not resize in any case.)

Let's fix this by bailing out immediately in the split ring code if the requested size cannot be allocated and may_reduce_num has not been specified.

While at it, fix a typo in the usage instructions.

Quoted 8 lines
Fixes 2a2d1382fe9d ("virtio: Add improved queue allocation API")

---
drivers/virtio/virtio_ring.c | 2 ++
include/linux/virtio_ring.h | 2 +-

2 files changed, 3 insertions(+), 1 deletion(-)
Reviewed-by on v1 1/1
#3 lore raw
In reply to Cornelia Huck
Quoted 14 lines · On Mon, 8 Apr 2019 14:33:22 +0200 Cornelia Huck <[email protected]> wrote:

vring_create_virtqueue() allows the caller to specify via the may_reduce_num parameter whether the vring code is allowed to allocate a smaller ring than specified.

However, the split ring allocation code tries to allocate a smaller ring on allocation failure regardless of what the caller specified. This may cause trouble for e.g. virtio-pci in legacy mode, which does not support ring resizing. (The packed ring code does not resize in any case.)

Let's fix this by bailing out immediately in the split ring code if the requested size cannot be allocated and may_reduce_num has not been specified.

Quoted 5 lines

While at it, fix a typo in the usage instructions.

Fixes 2a2d1382fe9d ("virtio: Add improved queue allocation API")
Acked-by on v1 1/1
#4 lore raw
In reply to Cornelia Huck
Quoted 42 lines · Cornelia Huck

vring_create_virtqueue() allows the caller to specify via the may_reduce_num parameter whether the vring code is allowed to allocate a smaller ring than specified.

However, the split ring allocation code tries to allocate a smaller ring on allocation failure regardless of what the caller specified. This may cause trouble for e.g. virtio-pci in legacy mode, which does not support ring resizing. (The packed ring code does not resize in any case.)

Let's fix this by bailing out immediately in the split ring code if the requested size cannot be allocated and may_reduce_num has not been specified.

While at it, fix a typo in the usage instructions.

Fixes 2a2d1382fe9d ("virtio: Add improved queue allocation API")
---
  drivers/virtio/virtio_ring.c | 2 ++
  include/linux/virtio_ring.h  | 2 +-
  2 files changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +2 -0
index 18846afb39da..5df92c308286 100644
@@ -882,6 +882,8 @@ static struct virtqueue *vring_create_virtqueue_split(
  					  GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO);
  		if (queue)
  			break;
+		if (!may_reduce_num)
+			return NULL;
  	}
 
  	if (!num)
include/linux/virtio_ring.h +0 -0
index fab02133a919..3dc70adfe5f5 100644

include/linux/virtio_ring.h struct virtqueue; · line 69

Quoted 8 lines
include/linux/virtio_ring.h +1 -1
@@ -63,7 +63,7 @@ struct virtqueue;
  /*
   * Creates a virtqueue and allocates the descriptor ring.  If
   * may_reduce_num is set, then this may allocate a smaller ring than
- * expected.  The caller should query virtqueue_get_ring_size to learn
+ * expected.  The caller should query virtqueue_get_vring_size to learn
   * the actual size of the ring.
   */
  struct virtqueue *vring_create_virtqueue(unsigned int index,

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by on v1 1/1
#5 lore raw
In reply to Cornelia Huck
Quoted 42 lines · Cornelia Huck

vring_create_virtqueue() allows the caller to specify via the may_reduce_num parameter whether the vring code is allowed to allocate a smaller ring than specified.

However, the split ring allocation code tries to allocate a smaller ring on allocation failure regardless of what the caller specified. This may cause trouble for e.g. virtio-pci in legacy mode, which does not support ring resizing. (The packed ring code does not resize in any case.)

Let's fix this by bailing out immediately in the split ring code if the requested size cannot be allocated and may_reduce_num has not been specified.

While at it, fix a typo in the usage instructions.

Fixes 2a2d1382fe9d ("virtio: Add improved queue allocation API")
---
  drivers/virtio/virtio_ring.c | 2 ++
  include/linux/virtio_ring.h  | 2 +-
  2 files changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +2 -0
index 18846afb39da..5df92c308286 100644
@@ -882,6 +882,8 @@ static struct virtqueue *vring_create_virtqueue_split(
  					  GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO);
  		if (queue)
  			break;
+		if (!may_reduce_num)
+			return NULL;
  	}
 
  	if (!num)
include/linux/virtio_ring.h +0 -0
index fab02133a919..3dc70adfe5f5 100644

include/linux/virtio_ring.h struct virtqueue; · line 69

Quoted 8 lines
include/linux/virtio_ring.h +1 -1
@@ -63,7 +63,7 @@ struct virtqueue;
  /*
   * Creates a virtqueue and allocates the descriptor ring.  If
   * may_reduce_num is set, then this may allocate a smaller ring than
- * expected.  The caller should query virtqueue_get_ring_size to learn
+ * expected.  The caller should query virtqueue_get_vring_size to learn
   * the actual size of the ring.
   */
  struct virtqueue *vring_create_virtqueue(unsigned int index,