]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.14.112/virtio-honour-may_reduce_num-in-vring_create_virtqueue.patch
Linux 4.14.112
[thirdparty/kernel/stable-queue.git] / releases / 4.14.112 / virtio-honour-may_reduce_num-in-vring_create_virtqueue.patch
CommitLineData
f6935fcd
GKH
1From cf94db21905333e610e479688add629397a4b384 Mon Sep 17 00:00:00 2001
2From: Cornelia Huck <cohuck@redhat.com>
3Date: Mon, 8 Apr 2019 14:33:22 +0200
4Subject: virtio: Honour 'may_reduce_num' in vring_create_virtqueue
5
6From: Cornelia Huck <cohuck@redhat.com>
7
8commit cf94db21905333e610e479688add629397a4b384 upstream.
9
10vring_create_virtqueue() allows the caller to specify via the
11may_reduce_num parameter whether the vring code is allowed to
12allocate a smaller ring than specified.
13
14However, the split ring allocation code tries to allocate a
15smaller ring on allocation failure regardless of what the
16caller specified. This may cause trouble for e.g. virtio-pci
17in legacy mode, which does not support ring resizing. (The
18packed ring code does not resize in any case.)
19
20Let's fix this by bailing out immediately in the split ring code
21if the requested size cannot be allocated and may_reduce_num has
22not been specified.
23
24While at it, fix a typo in the usage instructions.
25
26Fixes: 2a2d1382fe9d ("virtio: Add improved queue allocation API")
27Cc: stable@vger.kernel.org # v4.6+
28Signed-off-by: Cornelia Huck <cohuck@redhat.com>
29Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
30Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
31Reviewed-by: Jens Freimann <jfreimann@redhat.com>
32Signed-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@@ -1087,6 +1087,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,