diff mbox

libqos: fix bugs in qvirtqueue_kick()

Message ID 1472181502-6588-1-git-send-email-zhangshuai13@huawei.com
State New
Headers show

Commit Message

zhangshuai Aug. 26, 2016, 3:18 a.m. UTC
From: Zhang Shuai <zhangshuai13@huawei.com>

The idx and ring[] of vring_avail is 16-bit, but the writel
is 32-bit, the second writel will cover the ring[free_head]
with 0. So use writew to replace writel to fix the bug.

Signed-off-by: zhangshuai <zhangshuai13@huawei.com>
---
 tests/libqos/virtio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stefan Hajnoczi Sept. 5, 2016, 5:44 p.m. UTC | #1
On Fri, Aug 26, 2016 at 11:18:22AM +0800, zhangshuai wrote:
> From: Zhang Shuai <zhangshuai13@huawei.com>
> 
> The idx and ring[] of vring_avail is 16-bit, but the writel
> is 32-bit, the second writel will cover the ring[free_head]
> with 0. So use writew to replace writel to fix the bug.
> 
> Signed-off-by: zhangshuai <zhangshuai13@huawei.com>
> ---
>  tests/libqos/virtio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next

Stefan
Stefan Hajnoczi Sept. 5, 2016, 6:08 p.m. UTC | #2
On Fri, Aug 26, 2016 at 11:18:22AM +0800, zhangshuai wrote:
> From: Zhang Shuai <zhangshuai13@huawei.com>
> 
> The idx and ring[] of vring_avail is 16-bit, but the writel
> is 32-bit, the second writel will cover the ring[free_head]
> with 0. So use writew to replace writel to fix the bug.
> 
> Signed-off-by: zhangshuai <zhangshuai13@huawei.com>
> ---
>  tests/libqos/virtio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
> index d8c2970..801690f 100644
> --- a/tests/libqos/virtio.c
> +++ b/tests/libqos/virtio.c
> @@ -264,9 +264,9 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
>      uint16_t avail_event;
>  
>      /* vq->avail->ring[idx % vq->size] */
> -    writel(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
> +    writew(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
>      /* vq->avail->idx */
> -    writel(vq->avail + 2, idx + 1);
> +    writew(vq->avail + 2, idx + 1);

Laurent Vivier sent an equivalent patch that also covers the incorrect
readl() call.  I have applied his patch instead and mentioned your work
to give you credit.

Stefan
diff mbox

Patch

diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index d8c2970..801690f 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -264,9 +264,9 @@  void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
     uint16_t avail_event;
 
     /* vq->avail->ring[idx % vq->size] */
-    writel(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
+    writew(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
     /* vq->avail->idx */
-    writel(vq->avail + 2, idx + 1);
+    writew(vq->avail + 2, idx + 1);
 
     /* Must read after idx is updated */
     flags = readw(vq->avail);