qemu/stubs
Steve Sistare 624e6e654e migration: cpr-transfer mode
Add the cpr-transfer migration mode, which allows the user to transfer
a guest to a new QEMU instance on the same host with minimal guest pause
time, by preserving guest RAM in place, albeit with new virtual addresses
in new QEMU, and by preserving device file descriptors.  Pages that were
locked in memory for DMA in old QEMU remain locked in new QEMU, because the
descriptor of the device that locked them remains open.

cpr-transfer preserves memory and devices descriptors by sending them to
new QEMU over a unix domain socket using SCM_RIGHTS.  Such CPR state cannot
be sent over the normal migration channel, because devices and backends
are created prior to reading the channel, so this mode sends CPR state
over a second "cpr" migration channel.  New QEMU reads the cpr channel
prior to creating devices or backends.  The user specifies the cpr channel
in the channel arguments on the outgoing side, and in a second -incoming
command-line parameter on the incoming side.

The user must start old QEMU with the the '-machine aux-ram-share=on' option,
which allows anonymous memory to be transferred in place to the new process
by transferring a memory descriptor for each ram block.  Memory-backend
objects must have the share=on attribute, but memory-backend-epc is not
supported.

The user starts new QEMU on the same host as old QEMU, with command-line
arguments to create the same machine, plus the -incoming option for the
main migration channel, like normal live migration.  In addition, the user
adds a second -incoming option with channel type "cpr".  This CPR channel
must support file descriptor transfer with SCM_RIGHTS, i.e. it must be a
UNIX domain socket.

To initiate CPR, the user issues a migrate command to old QEMU, adding
a second migration channel of type "cpr" in the channels argument.
Old QEMU stops the VM, saves state to the migration channels, and enters
the postmigrate state.  New QEMU mmap's memory descriptors, and execution
resumes.

The implementation splits qmp_migrate into start and finish functions.
Start sends CPR state to new QEMU, which responds by closing the CPR
channel.  Old QEMU detects the HUP then calls finish, which connects the
main migration channel.

In summary, the usage is:

  qemu-system-$arch -machine aux-ram-share=on ...

  start new QEMU with "-incoming <main-uri> -incoming <cpr-channel>"

  Issue commands to old QEMU:
    migrate_set_parameter mode cpr-transfer

    {"execute": "migrate", ...
        {"channel-type": "main"...}, {"channel-type": "cpr"...} ... }

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Link: https://lore.kernel.org/r/1736967650-129648-17-git-send-email-steven.sistare@oracle.com
Signed-off-by: Fabiano Rosas <farosas@suse.de>
2025-01-29 11:56:24 -03:00
..
bdrv-next-monitor-owned.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
blk-commit-all.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
blk-exp-close-all.c meson: Drop the .fa library suffix 2024-07-03 18:41:26 +02:00
blockdev-close-all-bdrv-states.c all: Clean up includes 2016-02-16 14:29:28 +00:00
change-state-handler.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
cmos.c stubs/cmos: Use correct include 2020-09-01 09:10:58 +02:00
cpu-get-clock.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
cpu-synchronize-state.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
cpus-virtual-clock.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
dump.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
error-printf.c Move error_printf_unless_qmp() with monitor unit 2022-04-21 17:09:09 +04:00
fdset.c monitor: Report errors from monitor_fdset_dup_fd_add 2024-06-21 09:47:21 -03:00
fw_cfg.c hw/nvram/fw_cfg: Add fw_cfg_arch_key_name() 2019-05-23 14:10:31 +02:00
gdbstub.c gdbstub: Introduce GDBFeature structure 2023-10-11 08:46:33 +01:00
get-vm-name.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
graph-lock.c async: Register/unregister aiocontext in graph lock list 2022-12-15 16:07:43 +01:00
hotplug-stubs.c hw/core: Move system emulation files to system_ss 2024-04-18 11:17:27 +02:00
icount.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
io_uring.c stubs: add stubs for io_uring interface 2020-01-30 20:59:41 +00:00
iothread-lock-block.c main-loop.h: introduce qemu_in_main_thread() 2022-03-04 18:18:15 +01:00
iothread-lock.c bql: add a "mock" BQL for Rust unit tests 2024-12-19 19:36:37 +01:00
is-daemonized.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
linux-aio.c linux-aio: properly bubble up errors from initialization 2018-06-27 13:06:34 +01:00
meson.build stubs: avoid duplicate symbols in libqemuutil.a 2024-10-30 16:30:56 +01:00
migr-blocker.c migration: per-mode blockers 2023-11-01 16:13:59 +01:00
monitor-core.c stubs: remove obsolete stubs 2024-04-18 11:17:27 +02:00
monitor-internal.c stubs: move monitor_fdsets_cleanup with other fdset stubs 2024-04-18 11:17:27 +02:00
physmem.c stubs: add qemu_ram_block_from_host() and qemu_ram_get_fd() 2022-10-26 14:56:42 -04:00
qdev.c stubs: remove obsolete stubs 2024-04-18 11:17:27 +02:00
qemu-timer-notify-cb.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
qmp-command-available.c remove preconfig state 2020-12-15 12:51:48 -05:00
qmp-quit.c chardev: don't exit() straight away on C-a x 2021-11-04 10:32:01 +00:00
qtest.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
ram-block.c util/vfio-helpers.c: Use ram_block_discard_disable() in qemu_vfio_open_pci() 2020-11-16 13:22:17 -05:00
replay-mode.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
replay-tools.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
replay.c stubs: split record/replay stubs further 2024-04-18 11:17:27 +02:00
runstate-check.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
sysbus.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
target-get-monitor-def.c Clean up includes some more 2016-03-22 22:20:16 +01:00
target-monitor-defs.c monitor: remove MonitorDef from typedefs.h 2024-05-03 15:47:48 +02:00
trace-control.c trace: remove code that depends on setting vcpu 2023-06-01 11:05:05 -04:00
uuid.c qapi: Restrict query-uuid command to machine code 2020-09-29 15:41:35 +02:00
vm-stop.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
vmstate.c migration: cpr-transfer mode 2025-01-29 11:56:24 -03:00
win32-kbd-hook.c ui/win32-kbd-hook: handle AltGr in a hook procedure 2020-05-19 09:06:44 +02:00
xen-hw-stub.c hw/xen: Remove unnecessary xen_hvm_inject_msi() stub 2024-03-09 18:51:45 +01:00