[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V4 24/25] cpr: only-cpr-capable option
From: |
Steve Sistare |
Subject: |
[PATCH V4 24/25] cpr: only-cpr-capable option |
Date: |
Tue, 6 Jul 2021 09:45:55 -0700 |
Add the only-cpr-capable option, which causes qemu to exit with an error
if any devices that are not capable of cpr are added. This guarantees that
a cprexec operation will not fail with an unsupported device error.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
MAINTAINERS | 1 +
chardev/char-socket.c | 4 ++++
hw/vfio/common.c | 5 +++++
hw/vfio/pci.c | 5 +++++
include/sysemu/sysemu.h | 1 +
migration/migration.c | 5 +++++
qemu-options.hx | 8 ++++++++
softmmu/globals.c | 1 +
softmmu/physmem.c | 4 ++++
softmmu/vl.c | 14 +++++++++++++-
stubs/cpr.c | 3 +++
stubs/meson.build | 1 +
12 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 stubs/cpr.c
diff --git a/MAINTAINERS b/MAINTAINERS
index b69bbf5..25b5bc3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2853,6 +2853,7 @@ F: migration/cpr.c
F: qapi/cpr.json
F: include/qemu/env.h
F: util/env.c
+F: stubs/cpr.c
Record/replay
M: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 110f263..b8c75ff 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -40,6 +40,7 @@
#include "chardev/char-io.h"
#include "qom/object.h"
+#include "sysemu/sysemu.h"
/***********************************************************/
/* TCP Net console */
@@ -1468,6 +1469,9 @@ static void qmp_chardev_open_socket(Chardev *chr,
if (!s->tls_creds && !s->is_websock) {
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_CPR);
+ } else if (only_cpr_capable) {
+ error_setg(errp, "error: socket %s is not cpr capable due to %s
option",
+ chr->label, (s->tls_creds ? "TLS" : "websocket"));
}
/* be isn't opened until we get a connection */
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 40c882f..09d5e6e 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -37,6 +37,7 @@
#include "qemu/range.h"
#include "sysemu/kvm.h"
#include "sysemu/reset.h"
+#include "sysemu/sysemu.h"
#include "trace.h"
#include "qapi/error.h"
#include "migration/migration.h"
@@ -1601,6 +1602,10 @@ static int vfio_get_iommu_type(VFIOContainer *container,
for (i = 0; i < ARRAY_SIZE(iommu_types); i++) {
if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu_types[i])) {
+ if (only_cpr_capable && !vfio_cpr_capable(container, errp)) {
+ error_prepend(errp, "only-cpr-capable is specified: ");
+ return -EINVAL;
+ }
return iommu_types[i];
}
}
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 492ff31..706fc0b 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -266,6 +266,11 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error
**errp)
if (!pin) {
return 0;
+ } else if (only_cpr_capable) {
+ error_setg(errp,
+ "%s: vfio-pci INTX is not compatible with
-only-cpr-capable",
+ vdev->vbasedev.name);
+ return -1;
}
vfio_disable_interrupts(vdev);
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 8fae667..6241c20 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -9,6 +9,7 @@
/* vl.c */
extern int only_migratable;
+extern bool only_cpr_capable;
extern const char *qemu_name;
extern QemuUUID qemu_uuid;
extern bool qemu_uuid_set;
diff --git a/migration/migration.c b/migration/migration.c
index 8ca0341..181c8d5 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1262,6 +1262,11 @@ static bool migrate_caps_check(bool *cap_list,
}
}
+ if (cap_list[MIGRATION_CAPABILITY_X_COLO] && only_cpr_capable) {
+ error_setg(errp, "x-colo is not compatible with -only-cpr-capable");
+ return false;
+ }
+
return true;
}
diff --git a/qemu-options.hx b/qemu-options.hx
index ef2d24a..f1b372b 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4257,6 +4257,14 @@ SRST
an unmigratable state.
ERST
+DEF("only-cpr-capable", 0, QEMU_OPTION_only_cpr_capable, \
+ "-only-cpr-capable allow only cpr capable devices\n", QEMU_ARCH_ALL)
+SRST
+``-only-cpr-capable``
+ Only allow cpr capable devices, which guarantees that cprsave will not
+ fail with an unsupported device error.
+ERST
+
DEF("nodefaults", 0, QEMU_OPTION_nodefaults, \
"-nodefaults don't create default devices\n", QEMU_ARCH_ALL)
SRST
diff --git a/softmmu/globals.c b/softmmu/globals.c
index 7d0fc81..a18fd8d 100644
--- a/softmmu/globals.c
+++ b/softmmu/globals.c
@@ -59,6 +59,7 @@ int boot_menu;
bool boot_strict;
uint8_t *boot_splash_filedata;
int only_migratable; /* turn it off unless user states otherwise */
+bool only_cpr_capable;
int icount_align_option;
/* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index b79f408..04e3603 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -1973,6 +1973,10 @@ static void ram_block_add(RAMBlock *new_block, Error
**errp, bool shared)
addr = file_ram_alloc(new_block, maxlen, mfd,
false, false, 0, errp);
trace_anon_memfd_alloc(name, maxlen, addr, mfd);
+ } else if (only_cpr_capable) {
+ error_setg(errp,
+ "only-cpr-capable requires -machine memfd-alloc=on");
+ return;
} else {
addr = qemu_anon_ram_alloc(maxlen, &mr->align, shared);
}
diff --git a/softmmu/vl.c b/softmmu/vl.c
index aadb526..78f8829 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2589,6 +2589,10 @@ void qmp_x_exit_preconfig(Error **errp)
qemu_create_cli_devices();
qemu_machine_creation_done();
+ if (only_cpr_capable && !qemu_chr_cpr_capable(errp)) {
+ ; /* not reached due to error_fatal */
+ }
+
if (loadvm) {
Error *local_err = NULL;
if (!load_snapshot(loadvm, NULL, false, NULL, &local_err)) {
@@ -2598,7 +2602,12 @@ void qmp_x_exit_preconfig(Error **errp)
}
}
if (replay_mode != REPLAY_MODE_NONE) {
- replay_vmstate_init();
+ if (only_cpr_capable) {
+ error_setg(errp, "replay is not compatible with
-only-cpr-capable");
+ /* not reached due to error_fatal */
+ } else {
+ replay_vmstate_init();
+ }
}
if (incoming) {
@@ -3339,6 +3348,9 @@ void qemu_init(int argc, char **argv, char **envp)
case QEMU_OPTION_only_migratable:
only_migratable = 1;
break;
+ case QEMU_OPTION_only_cpr_capable:
+ only_cpr_capable = true;
+ break;
case QEMU_OPTION_nodefaults:
has_defaults = 0;
break;
diff --git a/stubs/cpr.c b/stubs/cpr.c
new file mode 100644
index 0000000..aaa189e
--- /dev/null
+++ b/stubs/cpr.c
@@ -0,0 +1,3 @@
+#include "qemu/osdep.h"
+
+bool only_cpr_capable;
diff --git a/stubs/meson.build b/stubs/meson.build
index be6f6d6..2003c77 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -5,6 +5,7 @@ stub_ss.add(files('blk-exp-close-all.c'))
stub_ss.add(files('blockdev-close-all-bdrv-states.c'))
stub_ss.add(files('change-state-handler.c'))
stub_ss.add(files('cmos.c'))
+stub_ss.add(files('cpr.c'))
stub_ss.add(files('cpu-get-clock.c'))
stub_ss.add(files('cpus-get-virtual-clock.c'))
stub_ss.add(files('qemu-timer-notify-cb.c'))
--
1.8.3.1
- [PATCH V4 15/25] vfio-pci: refactor for cpr, (continued)
- [PATCH V4 15/25] vfio-pci: refactor for cpr, Steve Sistare, 2021/07/06
- [PATCH V4 17/25] vfio-pci: cpr part 2, Steve Sistare, 2021/07/06
- [PATCH V4 19/25] hostmem-memfd: cpr support, Steve Sistare, 2021/07/06
- [PATCH V4 18/25] vhost: reset vhost devices upon cprsave, Steve Sistare, 2021/07/06
- [PATCH V4 21/25] chardev: cpr for simple devices, Steve Sistare, 2021/07/06
- [PATCH V4 20/25] chardev: cpr framework, Steve Sistare, 2021/07/06
- [PATCH V4 22/25] chardev: cpr for pty, Steve Sistare, 2021/07/06
- [PATCH V4 23/25] chardev: cpr for sockets, Steve Sistare, 2021/07/06
- [PATCH V4 25/25] simplify savevm, Steve Sistare, 2021/07/06
- [PATCH V4 24/25] cpr: only-cpr-capable option,
Steve Sistare <=
- [PATCH V4 04/25] cpr: HMP interfaces for reboot, Steve Sistare, 2021/07/06
- [PATCH V4 16/25] vfio-pci: cpr part 1, Steve Sistare, 2021/07/06
- Re: [PATCH V4 00/25] Live Update, Marc-André Lureau, 2021/07/07