xref: /openbmc/qemu/docs/devel/migration/CPR.rst (revision ee48fef0)
1CheckPoint and Restart (CPR)
2============================
3
4CPR is the umbrella name for a set of migration modes in which the
5VM is migrated to a new QEMU instance on the same host.  It is
6intended for use when the goal is to update host software components
7that run the VM, such as QEMU or even the host kernel.  At this time,
8cpr-reboot is the only available mode.
9
10Because QEMU is restarted on the same host, with access to the same
11local devices, CPR is allowed in certain cases where normal migration
12would be blocked.  However, the user must not modify the contents of
13guest block devices between quitting old QEMU and starting new QEMU.
14
15CPR unconditionally stops VM execution before memory is saved, and
16thus does not depend on any form of dirty page tracking.
17
18cpr-reboot mode
19---------------
20
21In this mode, QEMU stops the VM, and writes VM state to the migration
22URI, which will typically be a file.  After quitting QEMU, the user
23resumes by running QEMU with the ``-incoming`` option.  Because the
24old and new QEMU instances are not active concurrently, the URI cannot
25be a type that streams data from one instance to the other.
26
27Guest RAM can be saved in place if backed by shared memory, or can be
28copied to a file.  The former is more efficient and is therefore
29preferred.
30
31After state and memory are saved, the user may update userland host
32software before restarting QEMU and resuming the VM.  Further, if
33the RAM is backed by persistent shared memory, such as a DAX device,
34then the user may reboot to a new host kernel before restarting QEMU.
35
36This mode supports VFIO devices provided the user first puts the
37guest in the suspended runstate, such as by issuing the
38``guest-suspend-ram`` command to the QEMU guest agent.  The agent
39must be pre-installed in the guest, and the guest must support
40suspend to RAM.  Beware that suspension can take a few seconds, so
41the user should poll to see the suspended state before proceeding
42with the CPR operation.
43
44Usage
45^^^^^
46
47It is recommended that guest RAM be backed with some type of shared
48memory, such as ``memory-backend-file,share=on``, and that the
49``x-ignore-shared`` capability be set.  This combination allows memory
50to be saved in place.  Otherwise, after QEMU stops the VM, all guest
51RAM is copied to the migration URI.
52
53Outgoing:
54  * Set the migration mode parameter to ``cpr-reboot``.
55  * Set the ``x-ignore-shared`` capability if desired.
56  * Issue the ``migrate`` command.  It is recommended the the URI be a
57    ``file`` type, but one can use other types such as ``exec``,
58    provided the command captures all the data from the outgoing side,
59    and provides all the data to the incoming side.
60  * Quit when QEMU reaches the postmigrate state.
61
62Incoming:
63  * Start QEMU with the ``-incoming defer`` option.
64  * Set the migration mode parameter to ``cpr-reboot``.
65  * Set the ``x-ignore-shared`` capability if desired.
66  * Issue the ``migrate-incoming`` command.
67  * If the VM was running when the outgoing ``migrate`` command was
68    issued, then QEMU automatically resumes VM execution.
69
70Example 1
71^^^^^^^^^
72::
73
74  # qemu-kvm -monitor stdio
75  -object memory-backend-file,id=ram0,size=4G,mem-path=/dev/dax0.0,align=2M,share=on -m 4G
76  ...
77
78  (qemu) info status
79  VM status: running
80  (qemu) migrate_set_parameter mode cpr-reboot
81  (qemu) migrate_set_capability x-ignore-shared on
82  (qemu) migrate -d file:vm.state
83  (qemu) info status
84  VM status: paused (postmigrate)
85  (qemu) quit
86
87  ### optionally update kernel and reboot
88  # systemctl kexec
89  kexec_core: Starting new kernel
90  ...
91
92  # qemu-kvm ... -incoming defer
93  (qemu) info status
94  VM status: paused (inmigrate)
95  (qemu) migrate_set_parameter mode cpr-reboot
96  (qemu) migrate_set_capability x-ignore-shared on
97  (qemu) migrate_incoming file:vm.state
98  (qemu) info status
99  VM status: running
100
101Example 2: VFIO
102^^^^^^^^^^^^^^^
103::
104
105  # qemu-kvm -monitor stdio
106  -object memory-backend-file,id=ram0,size=4G,mem-path=/dev/dax0.0,align=2M,share=on -m 4G
107  -device vfio-pci, ...
108  -chardev socket,id=qga0,path=qga.sock,server=on,wait=off
109  -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
110  ...
111
112  (qemu) info status
113  VM status: running
114
115  # echo '{"execute":"guest-suspend-ram"}' | ncat --send-only -U qga.sock
116
117  (qemu) info status
118  VM status: paused (suspended)
119  (qemu) migrate_set_parameter mode cpr-reboot
120  (qemu) migrate_set_capability x-ignore-shared on
121  (qemu) migrate -d file:vm.state
122  (qemu) info status
123  VM status: paused (postmigrate)
124  (qemu) quit
125
126  ### optionally update kernel and reboot
127  # systemctl kexec
128  kexec_core: Starting new kernel
129  ...
130
131  # qemu-kvm ... -incoming defer
132  (qemu) info status
133  VM status: paused (inmigrate)
134  (qemu) migrate_set_parameter mode cpr-reboot
135  (qemu) migrate_set_capability x-ignore-shared on
136  (qemu) migrate_incoming file:vm.state
137  (qemu) info status
138  VM status: paused (suspended)
139  (qemu) system_wakeup
140  (qemu) info status
141  VM status: running
142
143Caveats
144^^^^^^^
145
146cpr-reboot mode may not be used with postcopy, background-snapshot,
147or COLO.
148