]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.35/virtio-honour-may_reduce_num-in-vring_create_virtqueue.patch
Linux 4.19.35
[thirdparty/kernel/stable-queue.git] / releases / 4.19.35 / virtio-honour-may_reduce_num-in-vring_create_virtqueue.patch
1 From cf94db21905333e610e479688add629397a4b384 Mon Sep 17 00:00:00 2001
2 From: Cornelia Huck <cohuck@redhat.com>
3 Date: Mon, 8 Apr 2019 14:33:22 +0200
4 Subject: virtio: Honour 'may_reduce_num' in vring_create_virtqueue
5
6 From: Cornelia Huck <cohuck@redhat.com>
7
8 commit cf94db21905333e610e479688add629397a4b384 upstream.
9
10 vring_create_virtqueue() allows the caller to specify via the
11 may_reduce_num parameter whether the vring code is allowed to
12 allocate a smaller ring than specified.
13
14 However, the split ring allocation code tries to allocate a
15 smaller ring on allocation failure regardless of what the
16 caller specified. This may cause trouble for e.g. virtio-pci
17 in legacy mode, which does not support ring resizing. (The
18 packed ring code does not resize in any case.)
19
20 Let's fix this by bailing out immediately in the split ring code
21 if the requested size cannot be allocated and may_reduce_num has
22 not been specified.
23
24 While at it, fix a typo in the usage instructions.
25
26 Fixes: 2a2d1382fe9d ("virtio: Add improved queue allocation API")
27 Cc: stable@vger.kernel.org # v4.6+
28 Signed-off-by: Cornelia Huck <cohuck@redhat.com>
29 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
30 Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
31 Reviewed-by: Jens Freimann <jfreimann@redhat.com>
32 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33
34 ---
35 drivers/virtio/virtio_ring.c | 2 ++
36 include/linux/virtio_ring.h | 2 +-
37 2 files changed, 3 insertions(+), 1 deletion(-)
38
39 --- a/drivers/virtio/virtio_ring.c
40 +++ b/drivers/virtio/virtio_ring.c
41 @@ -1086,6 +1086,8 @@ struct virtqueue *vring_create_virtqueue
42 GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO);
43 if (queue)
44 break;
45 + if (!may_reduce_num)
46 + return NULL;
47 }
48
49 if (!num)
50 --- a/include/linux/virtio_ring.h
51 +++ b/include/linux/virtio_ring.h
52 @@ -63,7 +63,7 @@ struct virtqueue;
53 /*
54 * Creates a virtqueue and allocates the descriptor ring. If
55 * may_reduce_num is set, then this may allocate a smaller ring than
56 - * expected. The caller should query virtqueue_get_ring_size to learn
57 + * expected. The caller should query virtqueue_get_vring_size to learn
58 * the actual size of the ring.
59 */
60 struct virtqueue *vring_create_virtqueue(unsigned int index,