All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH slof] virtio: Fix vring allocation
@ 2015-03-13  8:40 Alexey Kardashevskiy
  2015-03-13  9:19 ` Nikunj A Dadhania
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Kardashevskiy @ 2015-03-13  8:40 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Alexey Kardashevskiy, Thomas Huth, Nikunj A Dadhania

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))
-		+ VQ_ALIGN(sizeof(struct vring_used_elem) * qsize);
+               + VQ_ALIGN(sizeof(struct vring_used) +
+                          sizeof(struct vring_used_elem) * qsize);
 }
 
 
-- 
2.0.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH slof] virtio: Fix vring allocation
  2015-03-13  8:40 [PATCH slof] virtio: Fix vring allocation Alexey Kardashevskiy
@ 2015-03-13  9:19 ` Nikunj A Dadhania
  2015-03-13  9:42   ` [PATCH slof v2] " Alexey Kardashevskiy
  0 siblings, 1 reply; 5+ messages in thread
From: Nikunj A Dadhania @ 2015-03-13  9:19 UTC (permalink / raw)
  To: Alexey Kardashevskiy, linuxppc-dev; +Cc: Alexey Kardashevskiy, Thomas Huth

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH slof v2] virtio: Fix vring allocation
  2015-03-13  9:19 ` Nikunj A Dadhania
@ 2015-03-13  9:42   ` Alexey Kardashevskiy
  2015-03-13 10:14     ` Nikunj A Dadhania
  2015-03-13 10:25     ` Thomas Huth
  0 siblings, 2 replies; 5+ messages in thread
From: Alexey Kardashevskiy @ 2015-03-13  9:42 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Alexey Kardashevskiy, Thomas Huth, Nikunj A Dadhania

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>
---
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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH slof v2] virtio: Fix vring allocation
  2015-03-13  9:42   ` [PATCH slof v2] " Alexey Kardashevskiy
@ 2015-03-13 10:14     ` Nikunj A Dadhania
  2015-03-13 10:25     ` Thomas Huth
  1 sibling, 0 replies; 5+ messages in thread
From: Nikunj A Dadhania @ 2015-03-13 10:14 UTC (permalink / raw)
  To: Alexey Kardashevskiy, linuxppc-dev; +Cc: Alexey Kardashevskiy, Thomas Huth

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>

Reviewed-by: Nikunj A Dadhania <nikunj@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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH slof v2] virtio: Fix vring allocation
  2015-03-13  9:42   ` [PATCH slof v2] " Alexey Kardashevskiy
  2015-03-13 10:14     ` Nikunj A Dadhania
@ 2015-03-13 10:25     ` Thomas Huth
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Huth @ 2015-03-13 10:25 UTC (permalink / raw)
  To: Alexey Kardashevskiy; +Cc: linuxppc-dev, Nikunj A Dadhania

On Fri, 13 Mar 2015 20:42:03 +1100
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:

> 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>
> ---
> 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);
>  }

Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>

That should be at least ok for the current status that we support in
SLOF. I think I might have written the original version of that
function with a very old version of the virtio spec (v0.8.10), when
ther was no "used_event" event field in the struct vring_avail defined
yet.
But if SLOF ever supports VIRTIO_F_EVENT_IDX, we've got to keep in mind
to add some additional bytes here, too.

 Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-13 10:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-13  8:40 [PATCH slof] virtio: Fix vring allocation Alexey Kardashevskiy
2015-03-13  9:19 ` Nikunj A Dadhania
2015-03-13  9:42   ` [PATCH slof v2] " Alexey Kardashevskiy
2015-03-13 10:14     ` Nikunj A Dadhania
2015-03-13 10:25     ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.