aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Kardashevskiy <aik@ozlabs.ru>2015-03-13 20:40:50 +1100
committerAlexey Kardashevskiy <aik@ozlabs.ru>2015-03-13 22:31:11 +1100
commit750aec6ff6638bbf0d3f3f4c752ac8fd77071c04 (patch)
tree1f443b1a5f1262d7ca23281c2661fa7ef88e3dce
parent8d96fe983fac761677453b06b0d7054db8e681f6 (diff)
downloadSLOF-750aec6ff6638bbf0d3f3f4c752ac8fd77071c04.zip
SLOF-750aec6ff6638bbf0d3f3f4c752ac8fd77071c04.tar.gz
SLOF-750aec6ff6638bbf0d3f3f4c752ac8fd77071c04.tar.bz2
virtio: Fix vring allocation
The value returned by virtio_vring_size() is used to allocate memory for vring. The used descriptor list (array of vring_used_elem) is counted by the header - vring_used struct - is not. This fixes virtio_vring_size() to return the correct size. At the moment rings are quite small (256) and allocated with 4096 alignment, this is why we have not been having issues with this so far. Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com> Reviewed-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> --- Changes: v2: * remove magic numbers
-rw-r--r--lib/libvirtio/virtio.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
index b010796..f9c00a6 100644
--- a/lib/libvirtio/virtio.c
+++ b/lib/libvirtio/virtio.c
@@ -32,8 +32,10 @@
*/
unsigned long virtio_vring_size(unsigned int qsize)
{
- return VQ_ALIGN(sizeof(struct vring_desc) * qsize + 2 * (2 + qsize))
- + VQ_ALIGN(sizeof(struct vring_used_elem) * qsize);
+ return VQ_ALIGN(sizeof(struct vring_desc) * qsize +
+ sizeof(struct vring_avail) + sizeof(uint16_t) * qsize) +
+ VQ_ALIGN(sizeof(struct vring_used) +
+ sizeof(struct vring_used_elem) * qsize);
}