qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3 00/16] Live update: cpr-transfer
@ 2024-11-01 13:47 Steve Sistare
  2024-11-01 13:47 ` [PATCH V3 01/16] machine: anon-alloc option Steve Sistare
                   ` (15 more replies)
  0 siblings, 16 replies; 86+ messages in thread
From: Steve Sistare @ 2024-11-01 13:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Xu, Fabiano Rosas, David Hildenbrand, Marcel Apfelbaum,
	Eduardo Habkost, Philippe Mathieu-Daude, Paolo Bonzini,
	Daniel P. Berrange, Markus Armbruster, Steve Sistare

What?

This patch series adds the live migration cpr-transfer 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.

The new user-visible interfaces are:
  * cpr-transfer (MigMode migration parameter)
  * cpr-uri (migration parameter)
  * cpr-uri (command-line argument)

The user sets the mode parameter before invoking the migrate command.
In this mode, the user starts new QEMU on the same host as old QEMU, with
the same arguments as old QEMU, plus the -incoming and the -cpr-uri options.
The user issues the migrate command to old QEMU, which stops the VM, saves
state to the migration channels, and enters the postmigrate state.  Execution
resumes in new QEMU.

Memory-backend objects must have the share=on attribute, but memory-backend-epc
and memory-backend-ram are not supported.  The VM must be started with the
'-machine anon-alloc=memfd' option, which allows anonymous memory to be
transferred in place to the new process.

This mode requires a second migration channel, specified by the cpr-uri
migration property on the outgoing side, and by the cpr-uri QEMU command-line
option on the incoming side.  The channel must be a type, such as unix socket,
that supports SCM_RIGHTS.

Why?

This mode has less impact on the guest than any other method of updating
in place.  The pause time is much lower, because devices need not be torn
down and recreated, DMA does not need to be drained and quiesced, and minimal
state is copied to new QEMU.  Further, there are no constraints on the guest.
By contrast, cpr-reboot mode requires the guest to support S3 suspend-to-ram,
and suspending plus resuming vfio devices adds multiple seconds to the
guest pause time.

These benefits all derive from the core design principle of this mode,
which is preserving open descriptors.  This approach is very general and
can be used to support a wide variety of devices that do not have hardware
support for live migration, including but not limited to: vfio, chardev,
vhost, vdpa, and iommufd.  Some devices need new kernel software interfaces
to allow a descriptor to be used in a process that did not originally open it.

How?

All memory that is mapped by the guest is preserved in place.  Indeed,
it must be, because it may be the target of DMA requests, which are not
quiesced during cpr-transfer.  All such memory must be mmap'able in new QEMU.
This is easy for named memory-backend objects, as long as they are mapped
shared, because they are visible in the file system in both old and new QEMU.
Anonymous memory must be allocated using memfd_create rather than MAP_ANON,
so the memfd's can be sent to new QEMU.  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 descriptors by sending them to new QEMU via the
cpr-uri, which must support SCM_RIGHTS, and by sending the unique name
and value of each descriptor to new QEMU via CPR state.

For device descriptors, new QEMU reuses the descriptor when creating the
device, rather than opening it again.  For memfd descriptors, new QEMU
mmap's the preserved memfd when a ramblock is created.

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 migration channel, specified by cpr-uri.  New QEMU
reads the second channel prior to creating devices or backends.

Example:

In this example, we simply restart the same version of QEMU, but in
a real scenario one would use a new QEMU binary path in terminal 2.

  Terminal 1: start old QEMU
  # qemu-kvm -monitor stdio -object
  memory-backend-file,id=ram0,size=4G,mem-path=/dev/shm/ram0,share=on
  -m 4G -machine anon-alloc=memfd ...

  Terminal 2: start new QEMU
  # qemu-kvm ... -incoming unix:vm.sock -cpr-uri unix:cpr.sock

  Terminal 1:
  QEMU 9.1.50 monitor - type 'help' for more information
  (qemu) info status
  VM status: running
  (qemu) migrate_set_parameter mode cpr-transfer
  (qemu) migrate_set_parameter cpr-uri unix:cpr.sock
  (qemu) migrate -d unix:vm.sock
  (qemu) info status
  VM status: paused (postmigrate)

  Terminal 2:
  QEMU 9.1.50 monitor - type 'help' for more information
  (qemu) info status
  VM status: running

This patch series implements a minimal version of cpr-transfer.  Additional
series are ready to be posted to deliver the complete vision described
above, including
  * vfio
  * chardev
  * vhost and tap
  * blockers
  * cpr-exec mode
  * iommufd

Changes in V2:
  * cpr-transfer is the first new mode proposed, and cpr-exec is deferred
  * anon-alloc does not apply to memory-backend-object
  * replaced hack with proper synchronization between source and target
  * defined QEMU_CPR_FILE_MAGIC
  * addressed misc review comments

Changes in V3:
  * added cpr-transfer to migration-test
  * documented cpr-transfer in CPR.rst
  * fixed size_t trace format for 32-bit build
  * dropped explicit fd value in VMSTATE_FD
  * deferred cpr_walk_fd() and cpr_resave_fd() to later series
  * dropped "migration: save cpr mode".
    deleted mode from cpr state, and used cpr_uri to infer transfer mode.
  * dropped "migration: stop vm earlier for cpr"
  * fixed an unreported bug for cpr-transfer and migrate cancel
  * documented cpr-transfer restrictions in qapi
  * added trace for cpr_state_save and cpr_state_load
  * added ftruncate to "preserve ram blocks"

The first 4 patches below are foundational and are needed for both cpr-transfer
mode and the proposed cpr-exec mode.  The next 7 patches are specific to
cpr-transfer and implement the mechanisms for sharing state across a socket
using SCM_RIGHTS.  The last 5 patches supply tests and documentation.

Steve Sistare (16):
  machine: anon-alloc option
  migration: cpr-state
  physmem: preserve ram blocks for cpr
  hostmem-memfd: preserve for cpr
  migration: SCM_RIGHTS for QEMUFile
  migration: VMSTATE_FD
  migration: cpr-transfer save and load
  migration: cpr-uri parameter
  migration: cpr-uri option
  migration: split qmp_migrate
  migration: cpr-transfer mode
  tests/migration-test: memory_backend
  tests/qtest: defer connection
  tests/migration-test: defer connection
  migration-test: cpr-transfer
  migration: cpr-transfer documentation

 backends/hostmem-memfd.c       |  12 ++-
 docs/devel/migration/CPR.rst   | 144 +++++++++++++++++++++++++-
 hw/core/machine.c              |  19 ++++
 include/hw/boards.h            |   1 +
 include/migration/cpr.h        |  29 ++++++
 include/migration/vmstate.h    |   9 ++
 migration/cpr-transfer.c       |  81 +++++++++++++++
 migration/cpr.c                | 223 +++++++++++++++++++++++++++++++++++++++++
 migration/meson.build          |   2 +
 migration/migration-hmp-cmds.c |  10 ++
 migration/migration.c          | 107 +++++++++++++++++++-
 migration/migration.h          |   2 +
 migration/options.c            |  40 +++++++-
 migration/options.h            |   1 +
 migration/qemu-file.c          |  83 ++++++++++++++-
 migration/qemu-file.h          |   2 +
 migration/ram.c                |   2 +
 migration/trace-events         |   9 ++
 migration/vmstate-types.c      |  24 +++++
 qapi/machine.json              |  14 +++
 qapi/migration.json            |  53 +++++++++-
 qemu-options.hx                |  19 ++++
 stubs/vmstate.c                |   7 ++
 system/physmem.c               |  63 ++++++++++++
 system/trace-events            |   3 +
 system/vl.c                    |  10 ++
 tests/qtest/libqtest.c         |  69 ++++++++-----
 tests/qtest/libqtest.h         |  19 +++-
 tests/qtest/migration-test.c   | 107 ++++++++++++++++++--
 29 files changed, 1115 insertions(+), 49 deletions(-)
 create mode 100644 include/migration/cpr.h
 create mode 100644 migration/cpr-transfer.c
 create mode 100644 migration/cpr.c

-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 86+ messages in thread

end of thread, other threads:[~2024-11-20 16:27 UTC | newest]

Thread overview: 86+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-01 13:47 [PATCH V3 00/16] Live update: cpr-transfer Steve Sistare
2024-11-01 13:47 ` [PATCH V3 01/16] machine: anon-alloc option Steve Sistare
2024-11-01 14:06   ` Peter Xu
2024-11-04 10:39   ` David Hildenbrand
2024-11-04 10:45     ` David Hildenbrand
2024-11-04 17:38     ` Steven Sistare
2024-11-04 19:51       ` David Hildenbrand
2024-11-04 20:14         ` Peter Xu
2024-11-04 20:17           ` David Hildenbrand
2024-11-04 20:41             ` Peter Xu
2024-11-04 20:15         ` David Hildenbrand
2024-11-04 20:56           ` Steven Sistare
2024-11-04 21:36             ` David Hildenbrand
2024-11-06 20:12               ` Steven Sistare
2024-11-06 20:41                 ` Peter Xu
2024-11-06 20:59                   ` Steven Sistare
2024-11-06 21:21                     ` Peter Xu
2024-11-07 14:03                       ` Steven Sistare
2024-11-07 13:05                     ` David Hildenbrand
2024-11-07 14:04                       ` Steven Sistare
2024-11-07 16:19                         ` David Hildenbrand
2024-11-07 18:13                           ` Steven Sistare
2024-11-07 16:32                         ` Peter Xu
2024-11-07 16:38                           ` David Hildenbrand
2024-11-07 17:48                             ` Peter Xu
2024-11-07 13:23                 ` David Hildenbrand
2024-11-07 16:02                   ` Steven Sistare
2024-11-07 16:26                     ` David Hildenbrand
2024-11-07 16:40                       ` Steven Sistare
2024-11-08 11:31                         ` David Hildenbrand
2024-11-08 13:43                           ` Peter Xu
2024-11-08 14:14                             ` Steven Sistare
2024-11-08 14:32                               ` Peter Xu
2024-11-08 14:18                             ` David Hildenbrand
2024-11-08 15:01                               ` Peter Xu
2024-11-08 13:56                           ` Steven Sistare
2024-11-08 14:20                             ` David Hildenbrand
2024-11-08 14:37                               ` Steven Sistare
2024-11-08 14:54                                 ` David Hildenbrand
2024-11-08 15:07                                   ` Peter Xu
2024-11-08 15:09                                     ` David Hildenbrand
2024-11-08 15:15                                   ` David Hildenbrand
2024-11-01 13:47 ` [PATCH V3 02/16] migration: cpr-state Steve Sistare
2024-11-13 20:36   ` Peter Xu
2024-11-01 13:47 ` [PATCH V3 03/16] physmem: preserve ram blocks for cpr Steve Sistare
2024-11-01 13:47 ` [PATCH V3 04/16] hostmem-memfd: preserve " Steve Sistare
2024-11-01 13:47 ` [PATCH V3 05/16] migration: SCM_RIGHTS for QEMUFile Steve Sistare
2024-11-13 20:54   ` Peter Xu
2024-11-14 18:34     ` Steven Sistare
2024-11-01 13:47 ` [PATCH V3 06/16] migration: VMSTATE_FD Steve Sistare
2024-11-13 20:55   ` Peter Xu
2024-11-01 13:47 ` [PATCH V3 07/16] migration: cpr-transfer save and load Steve Sistare
2024-11-01 13:47 ` [PATCH V3 08/16] migration: cpr-uri parameter Steve Sistare
2024-11-01 13:47 ` [PATCH V3 09/16] migration: cpr-uri option Steve Sistare
2024-11-01 13:47 ` [PATCH V3 10/16] migration: split qmp_migrate Steve Sistare
2024-11-13 21:11   ` Peter Xu
2024-11-14 18:33     ` Steven Sistare
2024-11-01 13:47 ` [PATCH V3 11/16] migration: cpr-transfer mode Steve Sistare
2024-11-13 21:58   ` Peter Xu
2024-11-14 18:36     ` Steven Sistare
2024-11-14 19:04       ` Peter Xu
2024-11-19 19:50         ` Steven Sistare
2024-11-19 20:16           ` Peter Xu
2024-11-19 20:32             ` Steven Sistare
2024-11-19 20:51               ` Peter Xu
2024-11-19 21:03                 ` Steven Sistare
2024-11-19 21:29                   ` Peter Xu
2024-11-19 21:41                     ` Steven Sistare
2024-11-19 21:48                       ` Peter Xu
2024-11-19 21:51                         ` Steven Sistare
2024-11-20  9:38               ` Daniel P. Berrangé
2024-11-20 16:12                 ` Steven Sistare
2024-11-20 16:26                   ` Daniel P. Berrangé
2024-11-01 13:47 ` [PATCH V3 12/16] tests/migration-test: memory_backend Steve Sistare
2024-11-13 22:19   ` Fabiano Rosas
2024-11-01 13:47 ` [PATCH V3 13/16] tests/qtest: defer connection Steve Sistare
2024-11-13 22:36   ` Fabiano Rosas
2024-11-14 18:45     ` Steven Sistare
2024-11-13 22:53   ` Peter Xu
2024-11-14 18:31     ` Steven Sistare
2024-11-01 13:47 ` [PATCH V3 14/16] tests/migration-test: " Steve Sistare
2024-11-14 12:46   ` Fabiano Rosas
2024-11-01 13:47 ` [PATCH V3 15/16] migration-test: cpr-transfer Steve Sistare
2024-11-01 13:47 ` [PATCH V3 16/16] migration: cpr-transfer documentation Steve Sistare
2024-11-13 22:02   ` Peter Xu
2024-11-14 18:31     ` Steven Sistare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).