Skip to content

Commit cf94db2

Browse files
cohuckmstsirkin
authored andcommitted
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: 2a2d138 ("virtio: Add improved queue allocation API") Cc: [email protected] # v4.6+ Signed-off-by: Cornelia Huck <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Halil Pasic <[email protected]> Reviewed-by: Jens Freimann <[email protected]>
1 parent 5e9642a commit cf94db2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

drivers/virtio/virtio_ring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,8 @@ static struct virtqueue *vring_create_virtqueue_split(
882882
GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO);
883883
if (queue)
884884
break;
885+
if (!may_reduce_num)
886+
return NULL;
885887
}
886888

887889
if (!num)

include/linux/virtio_ring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct virtqueue;
6363
/*
6464
* Creates a virtqueue and allocates the descriptor ring. If
6565
* may_reduce_num is set, then this may allocate a smaller ring than
66-
* expected. The caller should query virtqueue_get_ring_size to learn
66+
* expected. The caller should query virtqueue_get_vring_size to learn
6767
* the actual size of the ring.
6868
*/
6969
struct virtqueue *vring_create_virtqueue(unsigned int index,

0 commit comments

Comments
 (0)