Merge tag 'qga-pull-2024-03-11-2' of https://github.com/kostyanf14/qemu into staging
qga-pull-2024-03-11-2
# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEEwsLBCepDxjwUI+uE711egWG6hOcFAmXvMF4ACgkQ711egWG6
# hOd7GQ/9H11bXH5U2HZHAyEv68rCuGxHt57yjy9GfrSGAE7kqkLJ0bHwxdgoj09A
# mmaTOakOEhM5tyrkFYsROde3ta0fAwdFQXyhqpWDHG0ZwDDCAlsNsEuDd541KXbg
# qFTue26BM4EJEwTYy94nEEhOHD+2GgEAuPIsUCF6QDhrq+sBqUts1pH3uUM+E3Sg
# 7HSXaF9O/RbgYR6J8FVA53tvNOP4WgOYZ/SZoFwKYzIOAblcaRgJvVbm600OqQDb
# DUZ96s6HUBVBazKx4t24WwPOkgcvYgp7b8QYj2VVfjRU2IHnFumv9A47KuEdJEUl
# meZlo8TsgfL+uSiYWiRvps1Eo1uoS2M4s4FYGbuOeABYviLr3XhJM7VarNyPp7nf
# lupuyeqydXCic5LFbjSg5gkpaIhFYQ9gANYr6JZjPPjX5G8hmgCeB6YsZT98Ygmi
# yG1np2luapvFGsDCPd8kgNpfTkKhOpKghUnTC3UESReV8mjBGhJHRQTd+lMV7YWJ
# reMRxlqrqNq69lDUnlNuSXOqPJX1qHHGkWuV9pdz641tFvw7vigE07qhvsCr8Y7b
# tAg6oDcw+1uuq2t3nHmfkzic6WTxb4lFmSpShsDu2sRA7MqWE3lCefNoS75R+xaI
# FebdrkjkFxdbazyl6oKXwxkOkAR7rFoTvVKKbG79DVMIBDiu4BE=
# =Xt/n
# -----END PGP SIGNATURE-----
# gpg: Signature made Mon 11 Mar 2024 16:25:02 GMT
# gpg: using RSA key C2C2C109EA43C63C1423EB84EF5D5E8161BA84E7
# gpg: Good signature from "Kostiantyn Kostiuk (Upstream PR sign) <kkostiuk@redhat.com>" [unknown]
# 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: C2C2 C109 EA43 C63C 1423 EB84 EF5D 5E81 61BA 84E7
* tag 'qga-pull-2024-03-11-2' of https://github.com/kostyanf14/qemu:
qga-win: Add support of Windows Server 2025 in get-osinfo command
qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size
qga/commands-win32: Declare const qualifier before type
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 059bfdc..ff88c3f 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -128,7 +128,7 @@
error_setg(&multiple_devices_migration_blocker,
"Multiple VFIO devices migration is supported only if all of "
"them support P2P migration");
- ret = migrate_add_blocker(&multiple_devices_migration_blocker, errp);
+ ret = migrate_add_blocker_normal(&multiple_devices_migration_blocker, errp);
return ret;
}
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index bd25b9f..096d77e 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -621,10 +621,15 @@
goto free_container_exit;
}
+ ret = vfio_cpr_register_container(bcontainer, errp);
+ if (ret) {
+ goto free_container_exit;
+ }
+
ret = vfio_ram_block_discard_disable(container, true);
if (ret) {
error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken");
- goto free_container_exit;
+ goto unregister_container_exit;
}
assert(bcontainer->ops->setup);
@@ -667,6 +672,9 @@
enable_discards_exit:
vfio_ram_block_discard_disable(container, false);
+unregister_container_exit:
+ vfio_cpr_unregister_container(bcontainer);
+
free_container_exit:
g_free(container);
@@ -710,6 +718,7 @@
vfio_container_destroy(bcontainer);
trace_vfio_disconnect_container(container->fd);
+ vfio_cpr_unregister_container(bcontainer);
close(container->fd);
g_free(container);
diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
new file mode 100644
index 0000000..392c2dd
--- /dev/null
+++ b/hw/vfio/cpr.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2021-2024 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/vfio/vfio-common.h"
+#include "migration/misc.h"
+#include "qapi/error.h"
+#include "sysemu/runstate.h"
+
+static int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier,
+ MigrationEvent *e, Error **errp)
+{
+ if (e->type == MIG_EVENT_PRECOPY_SETUP &&
+ !runstate_check(RUN_STATE_SUSPENDED) && !vm_get_suspended()) {
+
+ error_setg(errp,
+ "VFIO device only supports cpr-reboot for runstate suspended");
+
+ return -1;
+ }
+ return 0;
+}
+
+int vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp)
+{
+ migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier,
+ vfio_cpr_reboot_notifier,
+ MIG_MODE_CPR_REBOOT);
+ return 0;
+}
+
+void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer)
+{
+ migration_remove_notifier(&bcontainer->cpr_reboot_notifier);
+}
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 9bfddc1..e1be224 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -411,6 +411,11 @@
goto err_listener_register;
}
+ ret = vfio_cpr_register_container(bcontainer, errp);
+ if (ret) {
+ goto err_listener_register;
+ }
+
/*
* TODO: examine RAM_BLOCK_DISCARD stuff, should we do group level
* for discarding incompatibility check as well?
@@ -461,6 +466,7 @@
iommufd_cdev_ram_block_discard_disable(false);
}
+ vfio_cpr_unregister_container(bcontainer);
iommufd_cdev_detach_container(vbasedev, container);
iommufd_cdev_container_destroy(container);
vfio_put_address_space(space);
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index bb98493..bba776f 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -5,6 +5,7 @@
'container-base.c',
'container.c',
'migration.c',
+ 'cpr.c',
))
vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 50140ed..2050ac8 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -889,7 +889,7 @@
vbasedev->migration_blocker = error_copy(err);
error_free(err);
- return migrate_add_blocker(&vbasedev->migration_blocker, errp);
+ return migrate_add_blocker_normal(&vbasedev->migration_blocker, errp);
}
/* ---------------------------------------------------------------------- */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 4a6c262..b9da6c0 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -205,6 +205,9 @@
int vfio_kvm_device_add_fd(int fd, Error **errp);
int vfio_kvm_device_del_fd(int fd, Error **errp);
+int vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp);
+void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer);
+
extern const MemoryRegionOps vfio_region_ops;
typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;
typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
index b2813b0..3582d5f 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -49,6 +49,7 @@
QLIST_ENTRY(VFIOContainerBase) next;
QLIST_HEAD(, VFIODevice) device_list;
GList *iova_ranges;
+ NotifierWithReturn cpr_reboot_notifier;
} VFIOContainerBase;
typedef struct VFIOGuestIOMMU {