From: Peter Xu <peterx@redhat.com>
To: Chuang Xu <xuchuangxclwt@bytedance.com>
Cc: qemu-devel@nongnu.org, dgilbert@redhat.com, quintela@redhat.com,
pbonzini@redhat.com, david@redhat.com, f4bug@amsat.org,
mst@redhat.com, zhouyibo@bytedance.com
Subject: Re: [RFC v3 2/3] virtio: support delay of checks in virtio_load()
Date: Tue, 13 Dec 2022 11:31:32 -0500 [thread overview]
Message-ID: <Y5io5AfRWCluAk3P@x1n> (raw)
In-Reply-To: <20221213133510.1279488-3-xuchuangxclwt@bytedance.com>
On Tue, Dec 13, 2022 at 09:35:09PM +0800, Chuang Xu wrote:
> Delay checks in virtio_load() to avoid possible address_space_to_flatview() call
> during memory region's begin/commit.
I didn't notice virtio has the vm change handler already, looks good to
reuse it. :) A few more comments though (before some real virtio developers
chim im).
>
> Signed-off-by: Chuang Xu <xuchuangxclwt@bytedance.com>
> ---
> hw/virtio/virtio.c | 37 +++++++++++++++++++++++++++----------
> include/hw/virtio/virtio.h | 2 ++
> 2 files changed, 29 insertions(+), 10 deletions(-)
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index eb6347ab5d..f556e565c6 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3642,8 +3642,26 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
> vdev->start_on_kick = true;
> }
>
> + vdev->delay_check = true;
> +
> + if (vdc->post_load) {
> + ret = vdc->post_load(vdev);
> + if (ret) {
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static void virtio_load_check_delay(VirtIODevice *vdev)
> +{
> RCU_READ_LOCK_GUARD();
> - for (i = 0; i < num; i++) {
> + for (int i = 0; i < VIRTIO_QUEUE_MAX; i++) {
> + if (vdev->vq[i].vring.num == 0) {
> + break;
> + }
> +
> if (vdev->vq[i].vring.desc) {
> uint16_t nheads;
>
> @@ -3696,19 +3714,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
> i, vdev->vq[i].vring.num,
> vdev->vq[i].last_avail_idx,
> vdev->vq[i].used_idx);
> - return -1;
> + abort();
This is when the switchover finished. I'm not sure how severe this is and
whether there can be something to remedy - abort() is probably the least we
want to do here, since the admin may not want to crash the whole VM due to
one vring failure on one device.
> }
> }
> }
>
> - if (vdc->post_load) {
> - ret = vdc->post_load(vdev);
> - if (ret) {
> - return ret;
> - }
> - }
> -
> - return 0;
> + return;
> }
>
> void virtio_cleanup(VirtIODevice *vdev)
> @@ -3722,6 +3733,11 @@ static void virtio_vmstate_change(void *opaque, bool running, RunState state)
> BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
> VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
> bool backend_run = running && virtio_device_started(vdev, vdev->status);
> +
> + if (vdev->delay_check) {
> + virtio_load_check_delay(vdev);
> + vdev->delay_check = false;
> + }
> vdev->vm_running = running;
>
> if (backend_run) {
> @@ -3789,6 +3805,7 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size)
> virtio_vmstate_change, vdev);
> vdev->device_endian = virtio_default_endian();
> vdev->use_guest_notifier_mask = true;
> + vdev->delay_check = false;
> }
>
> /*
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index acfd4df125..269e80d04a 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -135,6 +135,8 @@ struct VirtIODevice
> AddressSpace *dma_as;
> QLIST_HEAD(, VirtQueue) *vector_queues;
> QTAILQ_ENTRY(VirtIODevice) next;
> + /* @delay_check: delay checks in virtio_load */
> + bool delay_check;
I think it covers more than the check? It also initializes variables like
used_idx and shadow_avail_idx. I'm not sure how vital they are, but I'd
just avoid using the word "check" if not sure (e.g. "load_delay", or
"load_finalize"?).
> };
>
> struct VirtioDeviceClass {
> --
> 2.20.1
>
--
Peter Xu
next prev parent reply other threads:[~2022-12-13 16:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-13 13:35 [RFC v3 0/3] migration: reduce time of loading non-iterable vmstate Chuang Xu
2022-12-13 13:35 ` [RFC v3 1/3] memory: add depth assert in address_space_to_flatview Chuang Xu
2022-12-14 16:03 ` Chuang Xu
2022-12-14 21:38 ` Peter Xu
2022-12-15 16:04 ` Peter Xu
2022-12-20 14:27 ` Chuang Xu
2022-12-15 16:51 ` Peter Maydell
2022-12-20 14:28 ` Chuang Xu
2022-12-20 15:02 ` Peter Xu
2022-12-13 13:35 ` [RFC v3 2/3] virtio: support delay of checks in virtio_load() Chuang Xu
2022-12-13 16:31 ` Peter Xu [this message]
2022-12-14 16:02 ` Chuang Xu
2022-12-13 13:35 ` [RFC v3 3/3] migration: reduce time of loading non-iterable vmstate Chuang Xu
2022-12-16 17:11 ` [RFC v3 0/3] " Peter Xu
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=Y5io5AfRWCluAk3P@x1n \
--to=peterx@redhat.com \
--cc=david@redhat.com \
--cc=dgilbert@redhat.com \
--cc=f4bug@amsat.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=xuchuangxclwt@bytedance.com \
--cc=zhouyibo@bytedance.com \
/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 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.