[PATCH slof v2] virtio: Fix vring allocation
Nikunj A Dadhania
nikunj at linux.vnet.ibm.com
Fri Mar 13 21:14:38 AEDT 2015
Alexey Kardashevskiy <aik at ozlabs.ru> writes:
> 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.
>
> Signed-off-by: Alexey Kardashevskiy <aik at ozlabs.ru>
Reviewed-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
> ---
> Changes:
> v2:
> * remove magic numbers
> ---
> lib/libvirtio/virtio.c | 6 ++++--
> 1 file 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);
> }
>
>
> --
> 2.0.0
More information about the Linuxppc-dev
mailing list