aboutsummaryrefslogtreecommitdiff
path: root/hw/vfio/migration.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2024-01-08 10:28:42 +0000
committerPeter Maydell <peter.maydell@linaro.org>2024-01-08 10:28:42 +0000
commitffd454c67e38cc6df792733ebc5d967eee28ac0d (patch)
treeaff8d2ad7466ff6934fe3f7067fda272166c9f52 /hw/vfio/migration.c
parent33252ebde15a238a1dbf07104aa0e5d5d487143c (diff)
parent19368b1905b4b917e915526fcbd5bfa3f7439451 (diff)
downloadqemu-ffd454c67e38cc6df792733ebc5d967eee28ac0d.zip
qemu-ffd454c67e38cc6df792733ebc5d967eee28ac0d.tar.gz
qemu-ffd454c67e38cc6df792733ebc5d967eee28ac0d.tar.bz2
Merge tag 'pull-vfio-20240107' of https://github.com/legoater/qemu into staging
vfio queue: * Minor cleanups * Fix for a regression in device reset introduced in 8.2 * Coverity fixes, including the removal of the iommufd backend mutex * Introduced VFIOIOMMUClass, to avoid compiling spapr when !CONFIG_PSERIES # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEEoPZlSPBIlev+awtgUaNDx8/77KEFAmWbIrcACgkQUaNDx8/7 # 7KFtPRAAxWcH9uh4tjJe4CgL+wXC+JOgviiNaI3AS6KmxdTHXcAvXMNAiGJfTBo4 # y/lJg+PYNgcDWrOqZqp1jj6ulWpO8ekLD9Nxv03e6o3kaArX/o2MtsrndOtWYnG/ # CUrr+/kTNeEw9008OaOca9vuh03xh3AnSwb3DzjHTvpMkj5LTXzuE1mU50DTUkn9 # GZjuN3rqHcdjJ/fXpiS6IgJbxcxLdo2aSykmyuq+TZmGf02lTES94PRef3Btr7Q6 # sKQZpv+A+gcZ8DHDJqfOEzEgu1OSa257q4ic47O1X3CeSyiGTGQ7rVKHtX6bK7xP # mB9WOVqzzdH/g+kHNG+kVXMCQXZ0qo7VlIkHabYD220RryZBCqMecQ4aKPLFULQE # e7C5ZaEvb7TLe/EaEQUSFrLCns7Nq6ciurcoAmP0cn2Ef1Sr1luNQVAR9LWRH1pc # 1TeNmHy4nQygT0dQtFBXwNUZfnTuGcKdr43twReiCjX1ViPBU4lrcajVQH4rAuoe # K/bBak2Kyi1LsFn8AzIwKXZZl83L57EyL+XEW8i5GN1jFSAHFx4ocUq8NQBa//kS # xei9LV3HEJbAMOQsPO8HEK40mg5WR17s22AUClMqtD2DAQbPUrmcLbZ6Ttq6hTuV # BqL56JFjbfML5RGjxwF9G8v5mdLmLlNRCGF2KI3NsT7dkMbVh24= # =zvPi # -----END PGP SIGNATURE----- # gpg: Signature made Sun 07 Jan 2024 22:16:23 GMT # gpg: using RSA key A0F66548F04895EBFE6B0B6051A343C7CFFBECA1 # gpg: Good signature from "Cédric Le Goater <clg@kaod.org>" [undefined] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: A0F6 6548 F048 95EB FE6B 0B60 51A3 43C7 CFFB ECA1 * tag 'pull-vfio-20240107' of https://github.com/legoater/qemu: backends/iommufd: Remove mutex backends/iommufd: Remove check on number of backend users vfio/migration: Add helper function to set state or reset device vfio/container: Rename vfio_init_container to vfio_set_iommu vfio/iommufd: Remove the use of stat() to check file existence hw/vfio: fix iteration over global VFIODevice list vfio/container: Replace basename with g_path_get_basename vfio/iommufd: Remove CONFIG_IOMMUFD usage vfio/spapr: Only compile sPAPR IOMMU support when needed vfio/iommufd: Introduce a VFIOIOMMU iommufd QOM interface vfio/spapr: Introduce a sPAPR VFIOIOMMU QOM interface vfio/container: Intoduce a new VFIOIOMMUClass::setup handler vfio/container: Introduce a VFIOIOMMU legacy QOM interface vfio/container: Introduce a VFIOIOMMU QOM interface vfio/container: Initialize VFIOIOMMUOps under vfio_init_container() vfio/container: Introduce vfio_legacy_setup() for further cleanups vfio/spapr: Extend VFIOIOMMUOps with a release handler Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/vfio/migration.c')
-rw-r--r--hw/vfio/migration.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 28d422b..70e6b1a 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -163,6 +163,19 @@ reset_device:
return ret;
}
+/*
+ * Some device state transitions require resetting the device if they fail.
+ * This function sets the device in new_state and resets the device if that
+ * fails. Reset is done by using ERROR as the recover state.
+ */
+static int
+vfio_migration_set_state_or_reset(VFIODevice *vbasedev,
+ enum vfio_device_mig_state new_state)
+{
+ return vfio_migration_set_state(vbasedev, new_state,
+ VFIO_DEVICE_STATE_ERROR);
+}
+
static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,
uint64_t data_size)
{
@@ -422,12 +435,7 @@ static void vfio_save_cleanup(void *opaque)
* after migration has completed, so it won't increase downtime.
*/
if (migration->device_state == VFIO_DEVICE_STATE_STOP_COPY) {
- /*
- * If setting the device in STOP state fails, the device should be
- * reset. To do so, use ERROR state as a recover state.
- */
- vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP,
- VFIO_DEVICE_STATE_ERROR);
+ vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_STOP);
}
g_free(migration->data_buffer);
@@ -699,12 +707,7 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,
VFIO_DEVICE_STATE_PRE_COPY_P2P :
VFIO_DEVICE_STATE_RUNNING_P2P;
- /*
- * If setting the device in new_state fails, the device should be reset.
- * To do so, use ERROR state as a recover state.
- */
- ret = vfio_migration_set_state(vbasedev, new_state,
- VFIO_DEVICE_STATE_ERROR);
+ ret = vfio_migration_set_state_or_reset(vbasedev, new_state);
if (ret) {
/*
* Migration should be aborted in this case, but vm_state_notify()
@@ -736,12 +739,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)
VFIO_DEVICE_STATE_STOP;
}
- /*
- * If setting the device in new_state fails, the device should be reset.
- * To do so, use ERROR state as a recover state.
- */
- ret = vfio_migration_set_state(vbasedev, new_state,
- VFIO_DEVICE_STATE_ERROR);
+ ret = vfio_migration_set_state_or_reset(vbasedev, new_state);
if (ret) {
/*
* Migration should be aborted in this case, but vm_state_notify()
@@ -770,12 +768,7 @@ static void vfio_migration_state_notifier(Notifier *notifier, void *data)
case MIGRATION_STATUS_CANCELLING:
case MIGRATION_STATUS_CANCELLED:
case MIGRATION_STATUS_FAILED:
- /*
- * If setting the device in RUNNING state fails, the device should
- * be reset. To do so, use ERROR state as a recover state.
- */
- vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RUNNING,
- VFIO_DEVICE_STATE_ERROR);
+ vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_RUNNING);
}
}