Debian Codegraph @

docs/specs/libxc-migration-stream.pandoc

raw
1 % libxenctrl (libxc) Domain Image Format
2 % David Vrabel <<[email protected]>>
3 Andrew Cooper <<[email protected]>>
4 Wen Congyang <<[email protected]>>
5 Yang Hongyang <<[email protected]>>
6 % Revision 3
7
8 Introduction
9 ============
10
11 Purpose
12 -------
13
14 The _domain save image_ is the context of a running domain used for
15 snapshots of a domain or for transferring domains between hosts during
16 migration.
17
18 There are a number of problems with the format of the domain save
19 image used in Xen 4.4 and earlier (the _legacy format_).
20
21 * Dependant on toolstack word size. A number of fields within the
22 image are native types such as `unsigned long` which have different
23 sizes between 32-bit and 64-bit toolstacks. This prevents domains
24 from being migrated between hosts running 32-bit and 64-bit
25 toolstacks.
26
27 * There is no header identifying the image.
28
29 * The image has no version information.
30
31 A new format that addresses the above is required.
32
33 ARM does not yet have have a domain save image format specified and
34 the format described in this specification should be suitable.
35
36 Not Yet Included
37 ----------------
38
39 The following features are not yet fully specified and will be
40 included in a future draft.
41
42 * Page data compression.
43
44 * ARM
45
46
47 Overview
48 ========
49
50 The image format consists of two main sections:
51
52 * _Headers_
53 * _Records_
54
55 Headers
56 -------
57
58 There are two headers: the _image header_, and the _domain header_.
59 The image header describes the format of the image (version etc.).
60 The _domain header_ contains general information about the domain
61 (architecture, type etc.).
62
63 Records
64 -------
65
66 The main part of the format is a sequence of different _records_.
67 Each record type contains information about the domain context. At a
68 minimum there is a END record marking the end of the records section.
69
70
71 Fields
72 ------
73
74 All the fields within the headers and records have a fixed width.
75
76 Fields are always aligned to their size.
77
78 Padding and reserved fields are set to zero on save and must be
79 ignored during restore.
80
81 Integer (numeric) fields in the image header are always in big-endian
82 byte order.
83
84 Integer fields in the domain header and in the records are in the
85 endianness described in the image header (which will typically be the
86 native ordering).
87
88 \clearpage
89
90 Headers
91 =======
92
93 Image Header
94 ------------
95
96 The image header identifies an image as a Xen domain save image. It
97 includes the version of this specification that the image complies
98 with.
99
100 Tools supporting version _V_ of the specification shall always save
101 images using version _V_. Tools shall support restoring from version
102 _V_. If the previous Xen release produced version _V_ - 1 images,
103 tools shall supported restoring from these. Tools may additionally
104 support restoring from earlier versions.
105
106 The marker field can be used to distinguish between legacy images and
107 those corresponding to this specification. Legacy images will have at
108 one or more zero bits within the first 8 octets of the image.
109
110 Fields within the image header are always in _big-endian_ byte order,
111 regardless of the setting of the endianness bit.
112
113 0 1 2 3 4 5 6 7 octet
114 +-------------------------------------------------+
115 | marker |
116 +-----------------------+-------------------------+
117 | id | version |
118 +-----------+-----------+-------------------------+
119 | options | (reserved) |
120 +-----------+-------------------------------------+
121
122
123 --------------------------------------------------------------------
124 Field Description
125 ----------- --------------------------------------------------------
126 marker 0xFFFFFFFFFFFFFFFF.
127
128 id 0x58454E46 ("XENF" in ASCII).
129
130 version 0x00000003. The version of this specification.
131
132 options bit 0: Endianness. 0 = little-endian, 1 = big-endian.
133
134 bit 1-15: Reserved.
135 --------------------------------------------------------------------
136
137 The endianness shall be 0 (little-endian) for images generated on an
138 i386, x86_64, or arm host.
139
140 \clearpage
141
142 Domain Header
143 -------------
144
145 The domain header includes general properties of the domain.
146
147 0 1 2 3 4 5 6 7 octet
148 +-----------------------+-----------+-------------+
149 | type | page_shift| (reserved) |
150 +-----------------------+-----------+-------------+
151 | xen_major | xen_minor |
152 +-----------------------+-------------------------+
153
154 --------------------------------------------------------------------
155 Field Description
156 ----------- --------------------------------------------------------
157 type 0x0000: Reserved.
158
159 0x0001: x86 PV.
160
161 0x0002: x86 HVM.
162
163 0x0003 - 0xFFFFFFFF: Reserved.
164
165 page_shift Size of a guest page as a power of two.
166
167 i.e., page size = 2 ^page_shift^.
168
169 xen_major The Xen major version when this image was saved.
170
171 xen_minor The Xen minor version when this image was saved.
172 --------------------------------------------------------------------
173
174 The legacy stream conversion tool writes a `xen_major` version of 0, and sets
175 `xen_minor` to the version of itself.
176
177 \clearpage
178
179 Records
180 =======
181
182 A record has a record header, type specific data and a trailing
183 footer. If `body_length` is not a multiple of 8, the body is padded
184 with zeroes to align the end of the record on an 8 octet boundary.
185
186 0 1 2 3 4 5 6 7 octet
187 +-----------------------+-------------------------+
188 | type | body_length |
189 +-----------+-----------+-------------------------+
190 | body... |
191 ...
192 | | padding (0 to 7 octets) |
193 +-----------+-------------------------------------+
194
195 --------------------------------------------------------------------
196 Field Description
197 ----------- -------------------------------------------------------
198 type 0x00000000: END
199
200 0x00000001: PAGE_DATA
201
202 0x00000002: X86_PV_INFO
203
204 0x00000003: X86_PV_P2M_FRAMES
205
206 0x00000004: X86_PV_VCPU_BASIC
207
208 0x00000005: X86_PV_VCPU_EXTENDED
209
210 0x00000006: X86_PV_VCPU_XSAVE
211
212 0x00000007: SHARED_INFO
213
214 0x00000008: X86_TSC_INFO
215
216 0x00000009: HVM_CONTEXT
217
218 0x0000000A: HVM_PARAMS
219
220 0x0000000B: TOOLSTACK (deprecated)
221
222 0x0000000C: X86_PV_VCPU_MSRS
223
224 0x0000000D: VERIFY
225
226 0x0000000E: CHECKPOINT
227
228 0x0000000F: CHECKPOINT_DIRTY_PFN_LIST (Secondary -> Primary)
229
230 0x00000010: STATIC_DATA_END
231
232 0x00000011: X86_CPUID_POLICY
233
234 0x00000012: X86_MSR_POLICY
235
236 0x00000013 - 0x7FFFFFFF: Reserved for future _mandatory_
237 records.
238
239 0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
240 records.
241
242 body_length Length in octets of the record body.
243
244 body Content of the record.
245
246 padding 0 to 7 octets of zeros to pad the whole record to a multiple
247 of 8 octets.
248 --------------------------------------------------------------------
249
250 Records may be _mandatory_ or _optional_. Optional records have bit
251 31 set in their type. Restoring an image that has unrecognised or
252 unsupported mandatory record must fail. The contents of optional
253 records may be ignored during a restore.
254
255 The following sub-sections specify the record body format for each of
256 the record types.
257
258 \clearpage
259
260 END
261 ----
262
263 An end record marks the end of the image, and shall be the final record
264 in the stream.
265
266 0 1 2 3 4 5 6 7 octet
267 +-------------------------------------------------+
268
269 The end record contains no fields; its body_length is 0.
270
271 \clearpage
272
273 PAGE_DATA
274 ---------
275
276 The bulk of an image consists of many PAGE_DATA records containing the
277 memory contents.
278
279 0 1 2 3 4 5 6 7 octet
280 +-----------------------+-------------------------+
281 | count (C) | (reserved) |
282 +-----------------------+-------------------------+
283 | pfn[0] |
284 +-------------------------------------------------+
285 ...
286 +-------------------------------------------------+
287 | pfn[C-1] |
288 +-------------------------------------------------+
289 | page_data[0]... |
290 ...
291 +-------------------------------------------------+
292 | page_data[N-1]... |
293 ...
294 +-------------------------------------------------+
295
296 --------------------------------------------------------------------
297 Field Description
298 ----------- --------------------------------------------------------
299 count Number of pages described in this record.
300
301 pfn An array of count PFNs and their types.
302
303 Bit 63-60: XEN_DOMCTL_PFINFO_* type (from
304 `public/domctl.h` but shifted by 32 bits)
305
306 Bit 59-52: Reserved.
307
308 Bit 51-0: PFN.
309
310 page_data page_size octets of uncompressed page contents for each
311 page set as present in the pfn array.
312 --------------------------------------------------------------------
313
314 Note: Count is strictly > 0. N is strictly <= C and it is possible for there
315 to be no page_data in the record if all pfns are of invalid types.
316
317 --------------------------------------------------------------------
318 PFINFO type Value Description
319 ------------- --------- ------------------------------------------
320 NOTAB 0x0 Normal page.
321
322 L1TAB 0x1 L1 page table page.
323
324 L2TAB 0x2 L2 page table page.
325
326 L3TAB 0x3 L3 page table page.
327
328 L4TAB 0x4 L4 page table page.
329
330 0x5-0x8 Reserved.
331
332 L1TAB_PIN 0x9 L1 page table page (pinned).
333
334 L2TAB_PIN 0xA L2 page table page (pinned).
335
336 L3TAB_PIN 0xB L3 page table page (pinned).
337
338 L4TAB_PIN 0xC L4 page table page (pinned).
339
340 BROKEN 0xD Broken page.
341
342 XALLOC 0xE Allocate only.
343
344 XTAB 0xF Invalid page.
345 --------------------------------------------------------------------
346
347 Table: XEN_DOMCTL_PFINFO_* Page Types.
348
349 PFNs with type `BROKEN`, `XALLOC`, or `XTAB` do not have any
350 corresponding `page_data`.
351
352 The saver uses the `XTAB` type for PFNs that become invalid in the
353 guest's P2M table during a live migration[^2].
354
355 Restoring an image with unrecognised page types shall fail.
356
357 [^2]: In the legacy format, this is the list of unmapped PFNs in the
358 tail.
359
360 \clearpage
361
362 X86_PV_INFO
363 -----------
364
365 0 1 2 3 4 5 6 7 octet
366 +-----+-----+-----------+-------------------------+
367 | w | ptl | (reserved) |
368 +-----+-----+-----------+-------------------------+
369
370 --------------------------------------------------------------------
371 Field Description
372 ----------- ---------------------------------------------------
373 guest_width (w) Guest width in octets (either 4 or 8).
374
375 pt_levels (ptl) Number of page table levels (either 3 or 4).
376 --------------------------------------------------------------------
377
378 \clearpage
379
380 X86_PV_P2M_FRAMES
381 -----------------
382
383 0 1 2 3 4 5 6 7 octet
384 +-----+-----+-----+-----+-------------------------+
385 | p2m_start_pfn (S) | p2m_end_pfn (E) |
386 +-----+-----+-----+-----+-------------------------+
387 | p2m_pfn[p2m frame containing pfn S] |
388 +-------------------------------------------------+
389 ...
390 +-------------------------------------------------+
391 | p2m_pfn[p2m frame containing pfn E] |
392 +-------------------------------------------------+
393
394 --------------------------------------------------------------------
395 Field Description
396 ------------- ---------------------------------------------------
397 p2m_start_pfn First pfn index in the p2m_pfn array.
398
399 p2m_end_pfn Last pfn index in the p2m_pfn array.
400
401 p2m_pfn Array of PFNs containing the guest's P2M table, for
402 the PFN frames containing the PFN range S to E
403 (inclusive).
404
405 --------------------------------------------------------------------
406
407 \clearpage
408
409 X86_PV_VCPU_BASIC, EXTENDED, XSAVE, MSRS
410 ----------------------------------------
411
412 The format of these records are identical. They are all binary blobs
413 of data which are accessed using specific pairs of domctl hypercalls.
414
415 0 1 2 3 4 5 6 7 octet
416 +-----------------------+-------------------------+
417 | vcpu_id | (reserved) |
418 +-----------------------+-------------------------+
419 | context... |
420 ...
421 +-------------------------------------------------+
422
423 ---------------------------------------------------------------------
424 Field Description
425 ----------- ----------------------------------------------------
426 vcpu_id The VCPU ID.
427
428 context Binary data for this VCPU.
429 ---------------------------------------------------------------------
430
431 ---------------------------------------------------------------------
432 Record type Accessor hypercalls
433 ----------------------- ----------------------------------------
434 X86_PV_VCPU_BASIC XEN_DOMCTL_{get,set}vcpucontext
435
436 X86_PV_VCPU_EXTENDED XEN_DOMCTL_{get,set}\_ext_vcpucontext
437
438 X86_PV_VCPU_XSAVE XEN_DOMCTL_{get,set}vcpuextstate
439
440 X86_PV_VCPU_MSRS XEN_DOMCTL_{get,set}\_vcpu_msrs
441 ---------------------------------------------------------------------
442
443 \clearpage
444
445 SHARED_INFO
446 -----------
447
448 The content of the Shared Info page.
449
450 0 1 2 3 4 5 6 7 octet
451 +-------------------------------------------------+
452 | shared_info |
453 ...
454 +-------------------------------------------------+
455
456 --------------------------------------------------------------------
457 Field Description
458 ----------- ---------------------------------------------------
459 shared_info Contents of the shared info page. This record
460 should be exactly 1 page long.
461 --------------------------------------------------------------------
462
463 \clearpage
464
465 X86_TSC_INFO
466 ------------
467
468 Domain TSC information, as accessed by the
469 XEN_DOMCTL_{get,set}tscinfo hypercall sub-ops.
470
471 0 1 2 3 4 5 6 7 octet
472 +------------------------+------------------------+
473 | mode | khz |
474 +------------------------+------------------------+
475 | nsec |
476 +------------------------+------------------------+
477 | incarnation | (reserved) |
478 +------------------------+------------------------+
479
480 --------------------------------------------------------------------
481 Field Description
482 ----------- ---------------------------------------------------
483 mode TSC mode, TSC_MODE_* constant.
484
485 khz TSC frequency, in kHz.
486
487 nsec Elapsed time, in nanoseconds.
488
489 incarnation Incarnation.
490 --------------------------------------------------------------------
491
492 \clearpage
493
494 HVM_CONTEXT
495 -----------
496
497 HVM Domain context, as accessed by the
498 XEN_DOMCTL_{get,set}hvmcontext hypercall sub-ops.
499
500 0 1 2 3 4 5 6 7 octet
501 +-------------------------------------------------+
502 | hvm_ctx |
503 ...
504 +-------------------------------------------------+
505
506 --------------------------------------------------------------------
507 Field Description
508 ----------- ---------------------------------------------------
509 hvm_ctx The HVM Context blob from Xen.
510 --------------------------------------------------------------------
511
512 \clearpage
513
514 HVM_PARAMS
515 ----------
516
517 HVM Domain parameters, as accessed by the
518 HVMOP_{get,set}\_param hypercall sub-ops.
519
520 0 1 2 3 4 5 6 7 octet
521 +------------------------+------------------------+
522 | count (C) | (reserved) |
523 +------------------------+------------------------+
524 | param[0].index |
525 +-------------------------------------------------+
526 | param[0].value |
527 +-------------------------------------------------+
528 ...
529 +-------------------------------------------------+
530 | param[C-1].index |
531 +-------------------------------------------------+
532 | param[C-1].value |
533 +-------------------------------------------------+
534
535 --------------------------------------------------------------------
536 Field Description
537 ----------- ---------------------------------------------------
538 count The number of parameters contained in this record.
539 Each parameter in the record contains an index and
540 value.
541
542 param index Parameter index.
543
544 param value Parameter value.
545 --------------------------------------------------------------------
546
547 \clearpage
548
549 TOOLSTACK (deprecated)
550 ----------------------
551
552 > *This record was only present for transitionary purposes during
553 > development. It is should not be used.*
554
555 An opaque blob provided by and supplied to the higher layers of the
556 toolstack (e.g., libxl) during save and restore.
557
558 0 1 2 3 4 5 6 7 octet
559 +------------------------+------------------------+
560 | data |
561 ...
562 +-------------------------------------------------+
563
564 --------------------------------------------------------------------
565 Field Description
566 ----------- ---------------------------------------------------
567 data Blob of toolstack-specific data.
568 --------------------------------------------------------------------
569
570 \clearpage
571
572 VERIFY
573 ------
574
575 A verify record indicates that, while all memory has now been sent, the sender
576 shall send further memory records for debugging purposes.
577
578 0 1 2 3 4 5 6 7 octet
579 +-------------------------------------------------+
580
581 The verify record contains no fields; its body_length is 0.
582
583 \clearpage
584
585 CHECKPOINT
586 ----------
587
588 A checkpoint record indicates that all the preceding records in the stream
589 represent a consistent view of VM state.
590
591 0 1 2 3 4 5 6 7 octet
592 +-------------------------------------------------+
593
594 The checkpoint record contains no fields; its body_length is 0
595
596 If the stream is embedded in a higher level toolstack stream, the
597 CHECKPOINT record marks the end of the libxc portion of the stream
598 and the stream is handed back to the higher level for further
599 processing.
600
601 The higher level stream may then hand the stream back to libxc to
602 process another set of records for the next consistent VM state
603 snapshot. This next set of records may be terminated by another
604 CHECKPOINT record or an END record.
605
606 \clearpage
607
608 CHECKPOINT_DIRTY_PFN_LIST
609 -------------------------
610
611 A checkpoint dirty pfn list record is used to convey information about
612 dirty memory in the VM. It is an unordered list of PFNs. Currently only
613 applicable in the backchannel of a checkpointed stream. It is only used
614 by COLO, more detail please reference README.colo.
615
616 0 1 2 3 4 5 6 7 octet
617 +-------------------------------------------------+
618 | pfn[0] |
619 +-------------------------------------------------+
620 ...
621 +-------------------------------------------------+
622 | pfn[C-1] |
623 +-------------------------------------------------+
624
625 The count of pfns is: record->length/sizeof(uint64_t).
626
627 \clearpage
628
629 STATIC_DATA_END
630 ---------------
631
632 A static data end record marks the end of the static state. I.e. state which
633 is invariant of guest execution.
634
635
636 0 1 2 3 4 5 6 7 octet
637 +-------------------------------------------------+
638
639 The end record contains no fields; its body_length is 0.
640
641 \clearpage
642
643 X86_CPUID_POLICY
644 ----------------
645
646 CPUID policy content, as accessed by the XEN_DOMCTL_{get,set}_cpu_policy
647 hypercall sub-ops.
648
649 0 1 2 3 4 5 6 7 octet
650 +-------------------------------------------------+
651 | CPUID_policy |
652 ...
653 +-------------------------------------------------+
654
655 --------------------------------------------------------------------
656 Field Description
657 ------------ ---------------------------------------------------
658 CPUID_policy Array of xen_cpuid_leaf_t[]'s
659 --------------------------------------------------------------------
660
661 \clearpage
662
663 X86_MSR_POLICY
664 --------------
665
666 MSR policy content, as accessed by the XEN_DOMCTL_{get,set}_cpu_policy
667 hypercall sub-ops.
668
669 0 1 2 3 4 5 6 7 octet
670 +-------------------------------------------------+
671 | MSR_policy |
672 ...
673 +-------------------------------------------------+
674
675 --------------------------------------------------------------------
676 Field Description
677 ---------- ---------------------------------------------------
678 MSR_policy Array of xen_msr_entry_t[]'s
679 --------------------------------------------------------------------
680
681 \clearpage
682
683
684 Layout
685 ======
686
687 The set of valid records depends on the guest architecture and type. No
688 assumptions should be made about the ordering or interleaving of
689 independent records. Record dependencies are noted below.
690
691 Some records are used for signalling, and explicitly have zero length. All
692 other records contain data relevant to the migration. Data records with no
693 content should be elided on the source side, as their presence serves no
694 purpose, but results in extra work for the restore side.
695
696 x86 PV Guest
697 ------------
698
699 A typical save record for an x86 PV guest image would look like:
700
701 * Image header
702 * Domain header
703 * Static data records:
704 * X86_PV_INFO record
705 * X86_{CPUID,MSR}_POLICY
706 * STATIC_DATA_END
707 * X86_PV_P2M_FRAMES record
708 * Many PAGE_DATA records
709 * X86_TSC_INFO
710 * SHARED_INFO record
711 * VCPU context records for each online VCPU
712 * X86_PV_VCPU_BASIC record
713 * X86_PV_VCPU_EXTENDED record
714 * X86_PV_VCPU_XSAVE record
715 * X86_PV_VCPU_MSRS record
716 * END record
717
718 There are some strict ordering requirements. The following records must
719 be present in the following order as each of them depends on information
720 present in the preceding ones.
721
722 * X86_PV_INFO record
723 * X86_PV_P2M_FRAMES record
724 * PAGE_DATA records
725 * VCPU records
726
727 x86 HVM Guest
728 -------------
729
730 A typical save record for an x86 HVM guest image would look like:
731
732 * Image header
733 * Domain header
734 * Static data records:
735 * X86_{CPUID,MSR}_POLICY
736 * STATIC_DATA_END
737 * Many PAGE_DATA records
738 * X86_TSC_INFO
739 * HVM_PARAMS
740 * HVM_CONTEXT
741 * END record
742
743 HVM_PARAMS must precede HVM_CONTEXT, as certain parameters can affect
744 the validity of architectural state in the context.
745
746 Compatibility with older versions
747 =================================
748
749 v3 compat with v2
750 -----------------
751
752 A v3 stream is compatible with a v2 stream, but mandates the presense of a
753 STATIC_DATA_END record ahead of any memory/register content. This is to ease
754 the introduction of new static configuration records over time.
755
756 A v3-compatible reciever interpreting a v2 stream should infer the position of
757 STATIC_DATA_END based on finding the first X86_PV_P2M_FRAMES record (for PV
758 guests), or PAGE_DATA record (for HVM guests) and behave as if STATIC_DATA_END
759 had been sent.
760
761 Legacy Images (x86 only)
762 ------------------------
763
764 Restoring legacy images from older tools shall be handled by
765 translating the legacy format image into this new format.
766
767 It shall not be possible to save in the legacy format.
768
769 There are two different legacy images depending on whether they were
770 generated by a 32-bit or a 64-bit toolstack. These shall be
771 distinguished by inspecting octets 4-7 in the image. If these are
772 zero then it is a 64-bit image.
773
774 Toolstack Field Value
775 --------- ----- -----
776 64-bit Bit 31-63 of the p2m_size field 0 (since p2m_size < 2^32^)
777 32-bit extended-info chunk ID (PV) 0xFFFFFFFF
778 32-bit Chunk type (HVM) < 0
779 32-bit Page count (HVM) > 0
780
781 Table: Possible values for octet 4-7 in legacy images
782
783 This assumes the presence of the extended-info chunk which was
784 introduced in Xen 3.0.
785
786
787 Future Extensions
788 =================
789
790 All changes to this specification should bump the revision number in
791 the title block.
792
793 All changes to the image or domain headers require the image version
794 to be increased.
795
796 The format may be extended by adding additional record types.
797
798 Extending an existing record type must be done by adding a new record
799 type. This allows old images with the old record to still be
800 restored.
801
802 The image header may only be extended by _appending_ additional
803 fields. In particular, the `marker`, `id` and `version` fields must
804 never change size or location.
805
806
807 Errata
808 ======
809
810 1. For compatibility with older code, the receving side of a stream should
811 tolerate and ignore variable sized records with zero content. Xen releases
812 between 4.6 and 4.8 could end up generating valid HVM_PARAMS or
813 X86_PV_VCPU_{EXTENDED,XSAVE,MSRS} records with zero-length content.