Patchwork [PULL,14/14] virtio: virtqueue_get_avail_bytes: fix desc_pa when loop over the indirect descriptor table

login
register
mail settings
Submitter Michael S. Tsirkin
Date Aug. 26, 2013, 4:43 p.m.
Message ID <1377535318-30491-15-git-send-email-mst@redhat.com>
Download mbox | patch
Permalink /patch/269943/
State New
Headers show

Comments

Michael S. Tsirkin - Aug. 26, 2013, 4:43 p.m.
From: yinyin <yin.yin@cs2c.com.cn>

virtqueue_get_avail_bytes: when found a indirect desc, we need loop over it.
           /* loop over the indirect descriptor table */
           indirect = 1;
           max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
           num_bufs = i = 0;
           desc_pa = vring_desc_addr(desc_pa, i);
But, It init i to 0, then use i to update desc_pa. so we will always get:
desc_pa = vring_desc_addr(desc_pa, 0);
the last two line should swap.

Cc: qemu-stable@nongnu.org
Signed-off-by: Yin Yin <yin.yin@cs2c.com.cn>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/virtio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Amos Kong - Aug. 28, 2013, 9:24 a.m.
On Mon, Aug 26, 2013 at 07:43:41PM +0300, Michael S. Tsirkin wrote:
> From: yinyin <yin.yin@cs2c.com.cn>
> 
> virtqueue_get_avail_bytes: when found a indirect desc, we need loop over it.
>            /* loop over the indirect descriptor table */
>            indirect = 1;
>            max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
>            num_bufs = i = 0;
>            desc_pa = vring_desc_addr(desc_pa, i);
> But, It init i to 0, then use i to update desc_pa. so we will always get:
> desc_pa = vring_desc_addr(desc_pa, 0);
> the last two line should swap.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Yin Yin <yin.yin@cs2c.com.cn>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Acked-by: Amos Kong <akong@redhat.com>

> ---
>  hw/virtio/virtio.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index f03c45d..2f1e73b 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -377,8 +377,8 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
>              /* loop over the indirect descriptor table */
>              indirect = 1;
>              max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
> -            num_bufs = i = 0;
>              desc_pa = vring_desc_addr(desc_pa, i);
> +            num_bufs = i = 0;
>          }
>  
>          do {
> -- 
> MST
>

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index f03c45d..2f1e73b 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -377,8 +377,8 @@  void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
             /* loop over the indirect descriptor table */
             indirect = 1;
             max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
-            num_bufs = i = 0;
             desc_pa = vring_desc_addr(desc_pa, i);
+            num_bufs = i = 0;
         }
 
         do {