[PATCH] hw/vfio/migration: Fix vfio migration isn't aborted in a corner case

From: Kunkun Jiang <jiangkunkun@huawei.com> In the final stage of vfio migration, the destination VM will execute vm_start vfio_vmstate_change vfio_migration_set_state At this time, vfio_migration_set_state may return failure. For example, the device is in the reset process due to some hardware problems. In this case, the vfio migration should be aborted, but the current logic does not abort. Instead, it continues to execute, which will cause Unpredictable impact. This patch fixes this case. Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> --- hw/vfio/migration.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index b81cb7e23b..8c27298477 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -720,7 +720,7 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running, static void vfio_vmstate_change(void *opaque, bool running, RunState state) { VFIODevice *vbasedev = opaque; - enum vfio_device_mig_state new_state; + enum vfio_device_mig_state new_state, pre_state; int ret; if (running) { @@ -733,6 +733,8 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) VFIO_DEVICE_STATE_STOP; } + pre_state = vbasedev->migration->device_state; + /* * If setting the device in new_state fails, the device should be reset. * To do so, use ERROR state as a recover state. @@ -747,6 +749,10 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) if (migrate_get_current()->to_dst_file) { qemu_file_set_error(migrate_get_current()->to_dst_file, ret); } + + if (pre_state == VFIO_DEVICE_STATE_RESUMING) { + exit(EXIT_FAILURE); + } } trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state), -- 2.33.0
participants (1)
-
Jinqian Yang