qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Wafer <Wafer@jaguarmicro.com>,
	mst@redhat.com, jasowang@redhat.com, groug@kaod.org
Cc: eperezma@redhat.com, qemu-devel@nongnu.org, angus.chen@jaguarmicro.com
Subject: Re: [PATCH] hw/virtio: Fix getting the correct ring number on loading
Date: Fri, 22 Nov 2024 08:01:34 +0100	[thread overview]
Message-ID: <52aebd45-da0c-41a9-ab2f-acee8da5d7e4@linaro.org> (raw)
In-Reply-To: <20241122020002.564-1-Wafer@jaguarmicro.com>

Hi Wafer,

On 22/11/24 03:00, Wafer wrote:
> From: Wafer Xie <wafer@jaguarmicro.com>
> 
> The virtio-1.2 specification writes:
> 
> 2.7.6 The Virtqueue Available Ring:
> "idx field indicates where the driver would put the next descriptor entry
> in the ring (modulo the queue size). This starts at 0, and increases"

"modulo" ...

> 
> The idx will increase from 0 to 0xFFFF and repeat,
> So idx may be less than last_avail_idx.
> 
> Fixes: 616a6552 (virtio: add endian-ambivalent support to VirtIODevice)

This commit is only about endianness... Do you mean 1abeb5a65d
("virtio: fix up VQ checks") or 258dc7c96b ("virtio: sanity-check
available index")?

> 
> Signed-off-by: Wafer Xie <wafer@jaguarmicro.com>
> ---
>   hw/virtio/virtio.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index a26f18908e..ae7d407113 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3362,7 +3362,13 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
>                   continue;
>               }
>   
> -            nheads = vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_avail_idx;
> +            if (vring_avail_idx(&vdev->vq[i]) >= vdev->vq[i].last_avail_idx) {
> +                nheads = vring_avail_idx(&vdev->vq[i]) -
> +                         vdev->vq[i].last_avail_idx;
> +            } else {
> +                nheads = UINT16_MAX - vdev->vq[i].last_avail_idx +
> +                         vring_avail_idx(&vdev->vq[i]) + 1;
> +            }

...           nheads %= UINT16_MAX; ?

>               /* Check it isn't doing strange things with descriptor numbers. */
>               if (nheads > vdev->vq[i].vring.num) {
>                   virtio_error(vdev, "VQ %d size 0x%x Guest index 0x%x "



  reply	other threads:[~2024-11-22  7:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-22  2:00 [PATCH] hw/virtio: Fix getting the correct ring number on loading Wafer
2024-11-22  7:01 ` Philippe Mathieu-Daudé [this message]
2024-11-22 11:27   ` Greg Kurz
2024-11-23  8:39   ` Wafer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52aebd45-da0c-41a9-ab2f-acee8da5d7e4@linaro.org \
    --to=philmd@linaro.org \
    --cc=Wafer@jaguarmicro.com \
    --cc=angus.chen@jaguarmicro.com \
    --cc=eperezma@redhat.com \
    --cc=groug@kaod.org \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).