[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v3 2/3] virtio: support delay of checks in virtio_load()
From: |
Chuang Xu |
Subject: |
[RFC v3 2/3] virtio: support delay of checks in virtio_load() |
Date: |
Tue, 13 Dec 2022 21:35:09 +0800 |
Delay checks in virtio_load() to avoid possible address_space_to_flatview() call
during memory region's begin/commit.
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();
}
}
}
- 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;
};
struct VirtioDeviceClass {
--
2.20.1
[RFC v3 2/3] virtio: support delay of checks in virtio_load(),
Chuang Xu <=
[RFC v3 3/3] migration: reduce time of loading non-iterable vmstate, Chuang Xu, 2022/12/13
Re: [RFC v3 0/3] migration: reduce time of loading non-iterable vmstate, Peter Xu, 2022/12/16