1 Star 0 Fork 114

Jiabo Feng/qemu

forked from src-openEuler/qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vdpa-support-vdpa-device-suspend-resume.patch 4.14 KB
一键复制 编辑 原始数据 按行查看 历史
Jiabo Feng 提交于 2024-04-07 10:21 . QEMU update to version 8.2.0-5
From e58b48ab2bb679f4c661301019d6f94bd39f93e5 Mon Sep 17 00:00:00 2001
From: libai <libai12@huawei.com>
Date: Tue, 19 Dec 2023 20:18:03 +0800
Subject: [PATCH] vdpa: support vdpa device suspend/resume
only implement suspend and resume interface used for migration. The
current implementation still has bugs when suspend/resume a virtual
machine. Fix it.
Fixes: 4c5a9a0703 (""vhost: implement vhost_vdpa_device_suspend/resume)
Signed-off-by: libai <libai12@huawei.com>
---
hw/virtio/vdpa-dev-mig.c | 16 +++++++++++-----
hw/virtio/vdpa-dev.c | 8 +-------
include/hw/virtio/vdpa-dev.h | 1 +
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/hw/virtio/vdpa-dev-mig.c b/hw/virtio/vdpa-dev-mig.c
index 9b47e3ed45..8b13f89c85 100644
--- a/hw/virtio/vdpa-dev-mig.c
+++ b/hw/virtio/vdpa-dev-mig.c
@@ -143,6 +143,7 @@ static int vhost_vdpa_device_suspend(VhostVdpaDevice *vdpa)
}
vdpa->started = false;
+ vdpa->suspended = true;
ret = vhost_dev_suspend(&vdpa->dev, vdev, false);
if (ret) {
@@ -165,6 +166,7 @@ set_guest_notifiers_fail:
}
suspend_fail:
+ vdpa->suspended = false;
vdpa->started = true;
return ret;
}
@@ -201,6 +203,7 @@ static int vhost_vdpa_device_resume(VhostVdpaDevice *vdpa)
goto err_guest_notifiers;
}
vdpa->started = true;
+ vdpa->suspended = false;
/*
* guest_notifier_mask/pending not used yet, so just unmask
@@ -241,7 +244,7 @@ static void vdpa_dev_vmstate_change(void *opaque, bool running, RunState state)
MigrationIncomingState *mis = migration_incoming_get_current();
if (!running) {
- if (ms->state == RUN_STATE_PAUSED) {
+ if (ms->state == MIGRATION_STATUS_ACTIVE || state == RUN_STATE_PAUSED) {
ret = vhost_vdpa_device_suspend(vdpa);
if (ret) {
error_report("suspend vdpa device failed: %d\n", ret);
@@ -251,16 +254,19 @@ static void vdpa_dev_vmstate_change(void *opaque, bool running, RunState state)
}
}
} else {
- if (ms->state == RUN_STATE_RESTORE_VM) {
+ if (vdpa->suspended) {
ret = vhost_vdpa_device_resume(vdpa);
if (ret) {
- error_report("migration dest resume device failed, abort!\n");
- exit(EXIT_FAILURE);
+ error_report("vhost vdpa device resume failed: %d\n", ret);
}
}
if (mis->state == RUN_STATE_RESTORE_VM) {
- vhost_vdpa_call(hdev, VHOST_VDPA_RESUME, NULL);
+ ret = vhost_vdpa_call(hdev, VHOST_VDPA_RESUME, NULL);
+ if (ret) {
+ error_report("migration dest resume device failed: %d\n", ret);
+ exit(EXIT_FAILURE);
+ }
/* post resume */
mis->bh = qemu_bh_new(vdpa_dev_migration_handle_incoming_bh,
hdev);
diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
index 877bf7464f..91e71847b0 100644
--- a/hw/virtio/vdpa-dev.c
+++ b/hw/virtio/vdpa-dev.c
@@ -317,7 +317,6 @@ static void vhost_vdpa_device_stop(VirtIODevice *vdev)
static void vhost_vdpa_device_set_status(VirtIODevice *vdev, uint8_t status)
{
VhostVdpaDevice *s = VHOST_VDPA_DEVICE(vdev);
- MigrationState *ms = migrate_get_current();
bool should_start = virtio_device_started(vdev, status);
Error *local_err = NULL;
int ret;
@@ -326,12 +325,7 @@ static void vhost_vdpa_device_set_status(VirtIODevice *vdev, uint8_t status)
should_start = false;
}
- if (s->started == should_start) {
- return;
- }
-
- if (ms->state == RUN_STATE_PAUSED ||
- ms->state == RUN_STATE_RESTORE_VM) {
+ if (s->started == should_start || s->suspended) {
return;
}
diff --git a/include/hw/virtio/vdpa-dev.h b/include/hw/virtio/vdpa-dev.h
index 20f50c76c6..60e9c3f3fe 100644
--- a/include/hw/virtio/vdpa-dev.h
+++ b/include/hw/virtio/vdpa-dev.h
@@ -37,6 +37,7 @@ struct VhostVdpaDevice {
int config_size;
uint16_t queue_size;
bool started;
+ bool suspended;
int (*post_init)(VhostVdpaDevice *v, Error **errp);
VMChangeStateEntry *vmstate;
Notifier migration_state;
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/JiaboFeng/qemu.git
git@gitee.com:JiaboFeng/qemu.git
JiaboFeng
qemu
qemu
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385