Message ID | 1426236020-10278-1-git-send-email-aik@ozlabs.ru (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Alexey Kardashevskiy <aik@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@ozlabs.ru> > --- > lib/libvirtio/virtio.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c > index b010796..22615c4 100644 > --- a/lib/libvirtio/virtio.c > +++ b/lib/libvirtio/virtio.c > @@ -33,7 +33,8 @@ > unsigned long virtio_vring_size(unsigned int qsize) > { > return VQ_ALIGN(sizeof(struct vring_desc) * qsize + 2 * (2 + qsize)) While at it, lets not have the above magic numbers as well ^^^^^^^^^^ sizeof(struct vring_avail) + sizeof(uint16_t) * qsize > - + VQ_ALIGN(sizeof(struct vring_used_elem) * qsize); > + + VQ_ALIGN(sizeof(struct vring_used) + > + sizeof(struct vring_used_elem) * qsize); > } > > > -- > 2.0.0 Regards Nikunj
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c index b010796..22615c4 100644 --- a/lib/libvirtio/virtio.c +++ b/lib/libvirtio/virtio.c @@ -33,7 +33,8 @@ 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); + + VQ_ALIGN(sizeof(struct vring_used) + + sizeof(struct vring_used_elem) * qsize); }
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@ozlabs.ru> --- lib/libvirtio/virtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)