qemu/system
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
..
arch_init.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
async-teardown.c qemu/osdep: Add excluded fd parameter to qemu_close_all_open_fd() 2024-08-05 08:21:59 +10:00
balloon.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
bootdevice.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
cpu-timers.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
cpus.c cpu: Remove nr_cores from struct CPUState 2025-01-10 23:34:45 +01:00
datadir.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
device_tree-stub.c kconfig: allow compiling out QEMU device tree code per target 2024-05-10 15:45:15 +02:00
device_tree.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
dirtylimit.c system/dirtylimit: Don't use migration_is_active() 2024-12-26 07:23:38 +01:00
dma-helpers.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
globals.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
ioport.c qdev: Use machine_get_container() 2025-01-09 18:16:24 +01:00
main.c ui & main loop: Redesign of system-specific main thread event handling 2024-12-31 21:21:34 +01:00
memory.c physmem: qemu_ram_alloc_from_fd extensions 2025-01-29 11:43:03 -03:00
memory_ldst.c.inc system: Move memory_ldst.c.inc to system 2024-02-13 10:59:25 +03:00
memory_mapping.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
meson.build migration: Move cpu-throttle.c from system to migration 2024-10-31 15:48:18 -04:00
physmem.c physmem: preserve ram blocks for cpr 2025-01-29 11:43:04 -03:00
qdev-monitor.c hw/qdev: Check machine_hotplug_handler in hotplug_unplug_allowed_common 2025-01-13 17:16:03 +01:00
qemu-seccomp.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
qtest.c system/qtest: properly feedback results of clock_[step|set] 2025-01-10 11:18:32 +00:00
rtc.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
runstate-action.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
runstate-hmp-cmds.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
runstate.c system/runstate: Fix regression, clarify BQL status of exit notifiers 2025-01-15 18:05:19 +00:00
tpm-hmp-cmds.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
tpm.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
trace-events physmem: fd-based shared memory 2025-01-29 11:43:04 -03:00
trace.h system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
vl.c migration: cpr-transfer mode 2025-01-29 11:56:24 -03:00
watchpoint.c system/watchpoint: Move TCG specific code to accel/tcg/ 2024-01-19 12:28:59 +01:00