]>
Commit | Line | Data |
---|---|---|
a215792c GKH |
1 | From b92b1b89a33c172c075edccf6afb0edc41d851fd Mon Sep 17 00:00:00 2001 |
2 | From: Will Deacon <will.deacon@arm.com> | |
3 | Date: Fri, 19 Oct 2012 14:03:33 +0100 | |
4 | Subject: virtio: force vring descriptors to be allocated from lowmem | |
5 | ||
6 | From: Will Deacon <will.deacon@arm.com> | |
7 | ||
8 | commit b92b1b89a33c172c075edccf6afb0edc41d851fd upstream. | |
9 | ||
10 | Virtio devices may attempt to add descriptors to a virtqueue from atomic | |
11 | context using GFP_ATOMIC allocation. This is problematic because such | |
12 | allocations can fall outside of the lowmem mapping, causing virt_to_phys | |
13 | to report bogus physical addresses which are subsequently passed to | |
14 | userspace via the buffers for the virtual device. | |
15 | ||
16 | This patch masks out __GFP_HIGH and __GFP_HIGHMEM from the requested | |
17 | flags when allocating descriptors for a virtqueue. If an atomic | |
18 | allocation is requested and later fails, we will return -ENOSPC which | |
19 | will be handled by the driver. | |
20 | ||
21 | Signed-off-by: Will Deacon <will.deacon@arm.com> | |
22 | Cc: Sasha Levin <levinsasha928@gmail.com> | |
23 | Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> | |
24 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
25 | ||
26 | --- | |
27 | drivers/virtio/virtio_ring.c | 7 +++++++ | |
28 | 1 file changed, 7 insertions(+) | |
29 | ||
30 | --- a/drivers/virtio/virtio_ring.c | |
31 | +++ b/drivers/virtio/virtio_ring.c | |
32 | @@ -132,6 +132,13 @@ static int vring_add_indirect(struct vri | |
33 | unsigned head; | |
34 | int i; | |
35 | ||
36 | + /* | |
37 | + * We require lowmem mappings for the descriptors because | |
38 | + * otherwise virt_to_phys will give us bogus addresses in the | |
39 | + * virtqueue. | |
40 | + */ | |
41 | + gfp &= ~(__GFP_HIGHMEM | __GFP_HIGH); | |
42 | + | |
43 | desc = kmalloc((out + in) * sizeof(struct vring_desc), gfp); | |
44 | if (!desc) | |
45 | return -ENOMEM; |