Migration Stream v2
v6 cover Migration Stream v2
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
v6 follows the integration of this code into XenServer, and having the full suite of XenRT tests being run. Included in these tests are live migrations from 32bit toolstacks to 64bit toolstacks, using the python conversion script. Several corruption issues have been located and fixed, as well as many minor improvements.
In addition, performance tests have been performed. After finding an initial regression, the code uas been tweaked to use writev() in preference to write() which vastly reduces the number of system calls performed. The performance is now better than the legacy code for all sizes of VM.
This series depends on several prerequisites which are still floating around on the xen-devel mailing list. These patches can be found in the "saverestore2-v6" branch of:
git://xenbits.xen.org/people/andrewcoop/xen.git
http://xenbits.xen.org/git-http/people/andrewcoop/xen.git
The next area of work is the libxl integration, which will seek to undo the current layering violations. It will involve introducing a new libxl framing format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion scripts so migrations from older libxl/libxc toolstacks will continue to work.
The code is presented here for comment/query/critism.
~Andrew
PATCH v6 1/13 docs: libxc migration stream specification
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
---
v6:
* Add pandoc -> txt/html conversion
* Spelling fixes
* Introduce SAVING_CPU record
--- docs/Makefile | 11 +- docs/specs/libxc-migration-stream.pandoc | 677 ++++++++++++++++++++++++++++++ 2 files changed, 687 insertions(+), 1 deletion(-) create mode 100644 docs/specs/libxc-migration-stream.pandoc
docs/Makefile +10 -1
@@ -14,21 +14,26 @@ MAN5SRC-y := $(wildcard man/xl*.pod.5) MARKDOWNSRC-y := $(wildcard misc/*.markdown) +PANDOCSRC-y += $(wildcard specs/*.pandoc) + TXTSRC-y := $(wildcard misc/*.txt) DOC_MAN1 := $(patsubst man/%.pod.1,man1/%.1,$(MAN1SRC-y)) DOC_MAN5 := $(patsubst man/%.pod.5,man5/%.5,$(MAN5SRC-y)) DOC_HTML := $(patsubst %.markdown,html/%.html,$(MARKDOWNSRC-y)) \ + $(patsubst %.pandoc,html/%.html,$(PANDOCSRC-y)) \ $(patsubst man/%.pod.1,html/man/%.1.html,$(MAN1SRC-y)) \ $(patsubst man/%.pod.5,html/man/%.5.html,$(MAN5SRC-y)) \ $(patsubst %.txt,html/%.txt,$(TXTSRC-y)) \ $(patsubst %,html/hypercall/%/index.html,$(DOC_ARCHES)) DOC_TXT := $(patsubst %.txt,txt/%.txt,$(TXTSRC-y)) \ $(patsubst %.markdown,txt/%.txt,$(MARKDOWNSRC-y)) \ + $(patsubst %.pandoc,txt/%.txt,$(PANDOCSRC-y)) \ $(patsubst man/%.pod.1,txt/man/%.1.txt,$(MAN1SRC-y)) \ $(patsubst man/%.pod.5,txt/man/%.5.txt,$(MAN5SRC-y)) -DOC_PDF := $(patsubst %.markdown,pdf/%.pdf,$(MARKDOWNSRC-y)) +DOC_PDF := $(patsubst %.markdown,pdf/%.pdf,$(MARKDOWNSRC-y)) \ + $(patsubst %.pandoc,pdf/%.pdf,$(PANDOCSRC-y)) .PHONY: all all: build
@@ -191,6 +196,10 @@ pdf/%.pdf: %.markdown $(INSTALL_DIR) $(@D) pandoc -N --toc --standalone $< --output $@ +pdf/%.pdf txt/%.txt html/%.html: %.pandoc + $(INSTALL_DIR) $(@D) + pandoc --number-sections --toc --standalone $< --output $@ + ifeq (,$(findstring clean,$(MAKECMDGOALS))) $(XEN_ROOT)/config/Docs.mk: $(error You have to run ./configure before building docs)
docs/specs/libxc-migration-stream.pandoc new file +677 -0
677 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [Patch v6 01/13] docs: libxc migration stream specification
Quoted 32 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>---
v6:
* Add pandoc -> txt/html conversion
* Spelling fixes
* IntroduceSAVING_CPUrecord--- docs/Makefile | 11 +- docs/specs/libxc-migration-stream.pandoc | 677 ++++++++++++++++++++++++++++++ 2 files changed, 687 insertions(+), 1 deletion(-)
...snip...
Quoted 58 lines
docs/specs/libxc-migration-stream.pandoc new file +58
-0+ +VERIFY +------ + +A verify record indicates that, while all memory has now been sent, the sender +shall send further memory records for debugging purposes. + + 0 1 2 3 4 5 6 7 octet + +-------------------------------------------------+ + +The verify record contains no fields; its body_length is 0. + +\clearpage + +SAVING\_CPU +---------- + +A saving cpu record provides a human readable representation of the CPU on +which the guest was saved. + + 0 1 2 3 4 5 6 7 octet + +------------------------+------------------------+ + | 7bit ASCII String | + ... + +-------------------------------------------------+ + +The information is purely informative as it doesn't directly affect how to +save or restore the guest, but in the case of an error on restoration may help +to narrow down the issue. + +x86 architecutres use the _CPUID_ 48 character processor brand string. + +\clearpage + +Layout +====== + +The set of valid records depends on the guest architecture and type. + +x86 PV Guest +------------ + +An x86 PV guest image will have this order of records: + +1. Image header +2. Domain header +3. X86\_PV\_INFO record +4. X86\_PV\_P2M\_FRAMES record +5. Many PAGE\_DATA records +6. TSC\_INFO +7. SHARED\_INFO record +8. VCPU context records for each online VCPU + a. X86\_PV\_VCPU\_BASIC record + b. X86\_PV\_VCPU\_EXTENDED record + c. X86\_PV\_VCPU\_XSAVE record + d. X86\_PV\_VCPU\_MSRS record +9. END record +
docs/specs/libxc-migration-stream.pandoc line 635
Quoted 10 lines
docs/specs/libxc-migration-stream.pandoc new file +10
-0+x86 HVM Guest +------------- + +1. Image header +2. Domain header +3. Many PAGE\_DATA records +4. TSC\_INFO +5. HVM\_CONTEXT +6. HVM\_PARAMS +
do VERIFY/SAVING_CPU records should be document here? Although they are optional, we may need to know in which order when they are included...
Quoted 43 lines
docs/specs/libxc-migration-stream.pandoc new file +42
-0+ +Legacy Images (x86 only) +======================== + +Restoring legacy images from older tools shall be handled by +translating the legacy format image into this new format. + +It shall not be possible to save in the legacy format. + +There are two different legacy images depending on whether they were +generated by a 32-bit or a 64-bit toolstack. These shall be +distinguished by inspecting octets 4-7 in the image. If these are +zero then it is a 64-bit image. + +Toolstack Field Value +--------- ----- ----- +64-bit Bit 31-63 of the p2m_size field 0 (since p2m_size < 2^32^) +32-bit extended-info chunk ID (PV) 0xFFFFFFFF +32-bit Chunk type (HVM) < 0 +32-bit Page count (HVM) > 0 + +Table: Possible values for octet 4-7 in legacy images + +This assumes the presence of the extended-info chunk which was +introduced in Xen 3.0. + + +Future Extensions +================= + +All changes to the image or domain headers require the image version +to be increased. + +The format may be extended by adding additional record types. + +Extending an existing record type must be done by adding a new record +type. This allows old images with the old record to still be +restored. + +The image header may only be extended by _appending_ additional +fields. In particular, the `marker`, `id` and `version` fields must +never change size or location.
Signature · 2 lines
Thanks, Yang.
Re: [Patch v6 01/13] docs: libxc migration stream specification
Quoted 108 lines · Hongyang Yang
Quoted 34 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>---
v6:
* Add pandoc -> txt/html conversion
* Spelling fixes
* IntroduceSAVING_CPUrecord--- docs/Makefile | 11 +- docs/specs/libxc-migration-stream.pandoc | 677 ++++++++++++++++++++++++++++++ 2 files changed, 687 insertions(+), 1 deletion(-)...snip...
Quoted 68 lines
docs/specs/libxc-migration-stream.pandoc new file +5
-0+ +VERIFY +------ + +A verify record indicates that, while all memory has now been sent,the sender
docs/specs/libxc-migration-stream.pandoc new file +13
-0+shall send further memory records for debugging purposes. + + 0 1 2 3 4 5 6 7 octet + +-------------------------------------------------+ + +The verify record contains no fields; its body_length is 0. + +\clearpage + +SAVING\_CPU +---------- + +A saving cpu record provides a human readable representation of theCPU on
docs/specs/libxc-migration-stream.pandoc new file +9
-0+which the guest was saved. + + 0 1 2 3 4 5 6 7 octet + +------------------------+------------------------+ + | 7bit ASCII String | + ... + +-------------------------------------------------+ + +The information is purely informative as it doesn't directly affecthow to
+save or restore the guest, but in the case of an error on restoration may helpdocs/specs/libxc-migration-stream.pandoc new file +36
-0+to narrow down the issue. + +x86 architecutres use the _CPUID_ 48 character processor brand string. + +\clearpage + +Layout +====== + +The set of valid records depends on the guest architecture and type. + +x86 PV Guest +------------ + +An x86 PV guest image will have this order of records: + +1. Image header +2. Domain header +3. X86\_PV\_INFO record +4. X86\_PV\_P2M\_FRAMES record +5. Many PAGE\_DATA records +6. TSC\_INFO +7. SHARED\_INFO record +8. VCPU context records for each online VCPU + a. X86\_PV\_VCPU\_BASIC record + b. X86\_PV\_VCPU\_EXTENDED record + c. X86\_PV\_VCPU\_XSAVE record + d. X86\_PV\_VCPU\_MSRS record +9. END record + +x86 HVM Guest +------------- + +1. Image header +2. Domain header +3. Many PAGE\_DATA records
Quoted 8 lines
Quoted 4 lines
+4. TSC\_INFO
+5. HVM\_CONTEXT
+6. HVM\_PARAMS
+do VERIFY/SAVING_CPU records should be document here? Although they are optional, we may need to know in which order when they are included...
I will have to rewrite this section for clarity. The wording is not fantastic.
There is no prescribed order of records, which is why the receiving side is deliberately coded with "do { get_one_record(); process_one_record(); } while (!END_RECORD);" loops
The above are expected ordering in standard cases, but even performing a legacy conversion results in a different ordering of records.
For the specific two you identified, the VERIFY record is for debugging only and I don't expect to see it in production use. The SAVING_CPU record is currently written immediately after the Domain Header, but could reside anywhere in the stream.
~Andrew
Re: [Patch v6 01/13] docs: libxc migration stream specification
Quoted 118 lines · Andrew Cooper
Quoted 108 lines · Hongyang Yang
Quoted 34 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>---
v6:
* Add pandoc -> txt/html conversion
* Spelling fixes
* IntroduceSAVING_CPUrecord--- docs/Makefile | 11 +- docs/specs/libxc-migration-stream.pandoc | 677 ++++++++++++++++++++++++++++++ 2 files changed, 687 insertions(+), 1 deletion(-)...snip...
Quoted 68 lines
docs/specs/libxc-migration-stream.pandoc new file +5
-0+ +VERIFY +------ + +A verify record indicates that, while all memory has now been sent,the sender
docs/specs/libxc-migration-stream.pandoc new file +13
-0+shall send further memory records for debugging purposes. + + 0 1 2 3 4 5 6 7 octet + +-------------------------------------------------+ + +The verify record contains no fields; its body_length is 0. + +\clearpage + +SAVING\_CPU +---------- + +A saving cpu record provides a human readable representation of theCPU on
docs/specs/libxc-migration-stream.pandoc new file +9
-0+which the guest was saved. + + 0 1 2 3 4 5 6 7 octet + +------------------------+------------------------+ + | 7bit ASCII String | + ... + +-------------------------------------------------+ + +The information is purely informative as it doesn't directly affecthow to
+save or restore the guest, but in the case of an error on restoration may helpdocs/specs/libxc-migration-stream.pandoc new file +36
-0+to narrow down the issue. + +x86 architecutres use the _CPUID_ 48 character processor brand string. + +\clearpage + +Layout +====== + +The set of valid records depends on the guest architecture and type. + +x86 PV Guest +------------ + +An x86 PV guest image will have this order of records: + +1. Image header +2. Domain header +3. X86\_PV\_INFO record +4. X86\_PV\_P2M\_FRAMES record +5. Many PAGE\_DATA records +6. TSC\_INFO +7. SHARED\_INFO record +8. VCPU context records for each online VCPU + a. X86\_PV\_VCPU\_BASIC record + b. X86\_PV\_VCPU\_EXTENDED record + c. X86\_PV\_VCPU\_XSAVE record + d. X86\_PV\_VCPU\_MSRS record +9. END record + +x86 HVM Guest +------------- + +1. Image header +2. Domain header +3. Many PAGE\_DATA recordsQuoted 8 lines
Quoted 4 lines
+4. TSC\_INFO
+5. HVM\_CONTEXT
+6. HVM\_PARAMS
+do VERIFY/SAVING_CPU records should be document here? Although they are optional, we may need to know in which order when they are included...
Quoted 6 lines
I will have to rewrite this section for clarity. The wording is not fantastic.
There is no prescribed order of records, which is why the receiving side is deliberately coded with "do {
get_one_record();process_one_record(); } while (!END_RECORD);" loops
Indeed, I've noticed that in the restore code.
So the order should be:
Image header
Domain header
records...
END record
Quoted 12 lines
The above are expected ordering in standard cases, but even performing a legacy conversion results in a different ordering of records.
For the specific two you identified, the VERIFY record is for debugging only and I don't expect to see it in production use. The
SAVING_CPUrecord is currently written immediately after the Domain Header, but could reside anywhere in the stream.~Andrew
.
Signature · 2 lines
Thanks, Yang.
Re: [Patch v6 01/13] docs: libxc migration stream specification
In reply to Andrew CooperQuoted 8 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +7
-0+SAVING\_CPU +---------- + +A saving cpu record provides a human readable representation of the CPU on +which the guest was saved. + + 0 1 2 3 4 5 6 7 octet
docs/specs/libxc-migration-stream.pandoc line 598
Quoted 10 lines
docs/specs/libxc-migration-stream.pandoc new file +10
-0+ +------------------------+------------------------+ + | 7bit ASCII String | + ... + +-------------------------------------------------+ + +The information is purely informative as it doesn't directly affect how to +save or restore the guest, but in the case of an error on restoration may help +to narrow down the issue. + +x86 architecutres use the _CPUID_ 48 character processor brand string.
This is new functionality that I think should be separate from this series.
This feels like something that should be machine readable and verifiable rather than a human readable string.
That's not to say a freeform record for human readable information wouldn't be useful, but I don't think it should be restricted to just the CPU name.
7 bit ASCII is rather quaint. Would utf-8 be better?
David
Re: [Patch v6 01/13] docs: libxc migration stream specification
Quoted 11 lines · David Vrabel
Quoted 10 lines · Andrew Cooper
docs/specs/libxc-migration-stream.pandoc new file +10
-0+SAVING\_CPU +---------- + +A saving cpu record provides a human readable representation of the CPU on +which the guest was saved. + + 0 1 2 3 4 5 6 7 octet + +------------------------+------------------------+ + | 7bit ASCII String | + ...
Quoted 8 lines
docs/specs/libxc-migration-stream.pandoc line 598
Quoted 7 lines
docs/specs/libxc-migration-stream.pandoc new file +7
-0+ +-------------------------------------------------+ + +The information is purely informative as it doesn't directly affect how to +save or restore the guest, but in the case of an error on restoration may help +to narrow down the issue. + +x86 architecutres use the _CPUID_ 48 character processor brand string.This is new functionality that I think should be separate from this series.
Perhaps. Had I considered that before preparing this latest series, my answer might be different.
At this point, it is already merged in and isn't a trivial patch; being the first optional record, there are a number of improvements in the common infrastructure. I don't have the time to maintain a separate patch which modifies core code on top of a series which introduces that code code, which is still under development and change. If the underlying series were static, the situation would be very different.
Quoted 7 lines
This feels like something that should be machine readable and verifiable rather than a human readable string.
That's not to say a freeform record for human readable information wouldn't be useful, but I don't think it should be restricted to just the CPU name.
What else would you include? There are plenty of other optional records available.
I put this in specifically to help identify the case where someone suspended a VM in an AMD server and attempted to resume it at some point later on an Intel server. Presently, the results of attempting this are particularly cryptic, with hvm_set_context failing with EPERM.
Quoted 5 lines
7 bit ASCII is rather quaint. Would utf-8 be better?
David
7bit ASCII is far easier to deal with in a C program without linking a UTF library into libxc. As it stands, this is a valid utf-8 string.
~Andrew
PATCH v6 2/13 tools/python: Scripts relating to migrationv2 streams
In reply to Andrew Cooper* format.py contains structure and constants as per the stream specificion.
* convert-legacy-stream.py will take a legacy migration stream as an input, and produce a v2 stream as an output.
* verify-stream-v2.py will verify a stream against the v2 specification.
format.py lives as part of the regular xen library, while convert-legacy-stream and verify-stream-v2 are installed as standalone scripts into PRIVATE_BINDIR.
---
v6:
* Move to be part of tools/python and installed in proper locations
--- tools/python/Makefile | 5 + tools/python/scripts/convert-legacy-stream.py | 622 +++++++++++++++++++++++++ tools/python/scripts/verify-stream-v2.py | 456 ++++++++++++++++++ tools/python/setup.py | 1 + tools/python/xen/streamv2/format.py | 148 ++++++ 5 files changed, 1232 insertions(+) create mode 100755 tools/python/scripts/convert-legacy-stream.py create mode 100755 tools/python/scripts/verify-stream-v2.py create mode 100644 tools/python/xen/streamv2/__init__.py create mode 100644 tools/python/xen/streamv2/format.py
tools/python/Makefile +5 -0
@@ -20,9 +20,14 @@ build: genpath genwrap.py $(XEN_ROOT)/tools/libxl/libxl_types.idl \ .PHONY: install install: + $(INSTALL_DIR) $(DESTDIR)$(PRIVATE_BINDIR) + CC="$(CC)" CFLAGS="$(CFLAGS) $(APPEND_LDFLAGS)" $(PYTHON) setup.py install \ $(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" --force + $(INSTALL_PROG) scripts/convert-legacy-stream.py $(DESTDIR)$(PRIVATE_BINDIR)/convert-legacy-stream + $(INSTALL_PROG) scripts/verify-stream-v2.py $(DESTDIR)$(PRIVATE_BINDIR)/verify-stream-v2 + .PHONY: test test: export LD_LIBRARY_PATH=$$(readlink -f ../libxc):$$(readlink -f ../xenstore); $(PYTHON) test.py -b -u
tools/python/scripts/convert-legacy-stream.py new file +622 -0
622 lines not on this page · raw message
tools/python/scripts/verify-stream-v2.py new file +456 -0
456 lines not on this page · raw message
tools/python/setup.py +1 -0
@@ -43,6 +43,7 @@ setup(name = 'xen', version = '3.0', description = 'Xen', packages = ['xen', + 'xen.streamv2', 'xen.lowlevel', ], ext_package = "xen.lowlevel",
tools/python/xen/streamv2/__init__.py new file +0 -0
tools/python/xen/streamv2/format.py new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [Patch v6 02/13] tools/python: Scripts relating to migrationv2 streams
Quoted 18 lines · Andrew Cooper
*
format.pycontains structure and constants as per the stream specificion.*
convert-legacy-stream.pywill take a legacy migration stream as an input, and produce a v2 stream as an output.*
verify-stream-v2.pywill verify a stream against the v2 specification.
format.pylives as part of the regular xen library, while convert-legacy-stream and verify-stream-v2 are installed as standalone scripts intoPRIVATE_BINDIR.Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>---
v6:
* Move to be part oftools/pythonand installed in proper locations
Quoted 6 lines
--- tools/python/Makefile | 5 + tools/python/scripts/convert-legacy-stream.py | 622 +++++++++++++++++++++++++ tools/python/scripts/verify-stream-v2.py | 456 ++++++++++++++++++ tools/python/setup.py | 1 + tools/python/xen/streamv2/format.py | 148 ++++++
I think you could reasonably take the xen.migration namespace for the library bit of this, streamv2 isn't very meaningful in the long run.
Have you developed any particular unit tests for the conversion stuff as you've been developing this? I think we could check them in if yes, so long as the input dataset isn't an entire domain of course...
Quoted 1 line
+ elif marker == -1: #
XC_SAVE_ID_ENABLE_VERIFY_MODE
You could define names for all these.
I'm not really enough of a Pythonista to make any particularly insightful review comments, but it all looks fine to me.
Quoted 1 line
+squahsed_page_data_records = 0
"squashed" (repeatedly)
Ian.
Re: [Patch v6 02/13] tools/python: Scripts relating to migrationv2 streams
Quoted 25 lines · Ian Campbell
Quoted 18 lines · Andrew Cooper
*
format.pycontains structure and constants as per the stream specificion.*
convert-legacy-stream.pywill take a legacy migration stream as an input, and produce a v2 stream as an output.*
verify-stream-v2.pywill verify a stream against the v2 specification.
format.pylives as part of the regular xen library, while convert-legacy-stream and verify-stream-v2 are installed as standalone scripts intoPRIVATE_BINDIR.Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>---
v6:
* Move to be part oftools/pythonand installed in proper locationsQuoted 6 lines
--- tools/python/Makefile | 5 + tools/python/scripts/convert-legacy-stream.py | 622 +++++++++++++++++++++++++ tools/python/scripts/verify-stream-v2.py | 456 ++++++++++++++++++ tools/python/setup.py | 1 + tools/python/xen/streamv2/format.py | 148 ++++++
Quoted 2 lines
I think you could reasonably take the xen.migration namespace for the library bit of this, streamv2 isn't very meaningful in the long run.
Ok
Quoted 4 lines
Have you developed any particular unit tests for the conversion stuff as you've been developing this? I think we could check them in if yes, so long as the input dataset isn't an entire domain of course...
andrewcoop@andrewcoop:/local/xen.git$ ls -hlA tools/python/v2tests/ total 285M -rw-rw-r-- 1 andrewcoop xendev 65M Jul 11 11:35 conv-v1-t64-hvm -rw-rw-r-- 1 andrewcoop xendev 40M Jul 11 11:35 conv-v1-t64-pv32 -rw-rw-r-- 1 andrewcoop xendev 40M Jul 11 11:35 conv-v1-t64-pv64 -rw-rw-r-- 1 andrewcoop xendev 1.1K Jul 6 20:06 Makefile -rw-r--r-- 1 andrewcoop xendev 65M May 6 14:09 v1-t64-hvm -rw-r--r-- 1 andrewcoop xendev 40M May 6 14:05 v1-t64-pv32 -rw-r--r-- 1 andrewcoop xendev 40M May 6 14:04 v1-t64-pv64
They are the smallest domains I could create and suspend, but are still too large to reasonably be committed
I will see if I can come up with something smaller which can be committed, but nothing comes immediately to mind.
Quoted 3 lines
Quoted 2 lines
+ elif marker == -1: #
XC_SAVE_ID_ENABLE_VERIFY_MODEYou could define names for all these.
I considered that, but they are used exactly once, and commented in place. I decided that, on balance, it was better without.
Quoted 9 lines
I'm not really enough of a Pythonista to make any particularly insightful review comments, but it all looks fine to me.
Quoted 1 line
+squahsed_page_data_records = 0
"squashed" (repeatedly)
Ian.
Oops.
~Andrew
Re: [Patch v6 02/13] tools/python: Scripts relating to migrationv2 streams
Quoted 14 lines · Andrew Cooper
Quoted 3 lines
Have you developed any particular unit tests for the conversion stuff as you've been developing this? I think we could check them in if yes, so long as the input dataset isn't an entire domain of course...
andrewcoop@andrewcoop:/local/xen.git$ ls -hlA tools/python/v2tests/ total 285M(quoted diff) +0
-7-rw-rw-r-- 1 andrewcoop xendev 65M Jul 11 11:35 conv-v1-t64-hvm -rw-rw-r-- 1 andrewcoop xendev 40M Jul 11 11:35 conv-v1-t64-pv32 -rw-rw-r-- 1 andrewcoop xendev 40M Jul 11 11:35 conv-v1-t64-pv64 -rw-rw-r-- 1 andrewcoop xendev 1.1K Jul 6 20:06 Makefile -rw-r--r-- 1 andrewcoop xendev 65M May 6 14:09 v1-t64-hvm -rw-r--r-- 1 andrewcoop xendev 40M May 6 14:05 v1-t64-pv32 -rw-r--r-- 1 andrewcoop xendev 40M May 6 14:04 v1-t64-pv64
Quoted 2 lines
They are the smallest domains I could create and suspend, but are still too large to reasonably be committed
Agreed.
Quoted 2 lines
I will see if I can come up with something smaller which can be committed, but nothing comes immediately to mind.
Perhaps a minios domain for the pv cases at least?
For HVM perhaps a tiny domain sat at its bootloader prompt?
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
+ elif marker == -1: #
XC_SAVE_ID_ENABLE_VERIFY_MODEYou could define names for all these.
I considered that, but they are used exactly once, and commented in place. I decided that, on balance, it was better without.
OK.
Ian.
Re: [Patch v6 02/13] tools/python: Scripts relating to migrationv2 streams
Quoted 14 lines · Ian Campbell
Quoted 13 lines · Andrew Cooper
Quoted 3 lines
Have you developed any particular unit tests for the conversion stuff as you've been developing this? I think we could check them in if yes, so long as the input dataset isn't an entire domain of course...
andrewcoop@andrewcoop:/local/xen.git$ ls -hlA tools/python/v2tests/ total 285M(quoted diff) +0
-7-rw-rw-r-- 1 andrewcoop xendev 65M Jul 11 11:35 conv-v1-t64-hvm -rw-rw-r-- 1 andrewcoop xendev 40M Jul 11 11:35 conv-v1-t64-pv32 -rw-rw-r-- 1 andrewcoop xendev 40M Jul 11 11:35 conv-v1-t64-pv64 -rw-rw-r-- 1 andrewcoop xendev 1.1K Jul 6 20:06 Makefile -rw-r--r-- 1 andrewcoop xendev 65M May 6 14:09 v1-t64-hvm -rw-r--r-- 1 andrewcoop xendev 40M May 6 14:05 v1-t64-pv32 -rw-r--r-- 1 andrewcoop xendev 40M May 6 14:04 v1-t64-pv64
Quoted 9 lines
Quoted 2 lines
They are the smallest domains I could create and suspend, but are still too large to reasonably be committed
Agreed.
Quoted 2 lines
I will see if I can come up with something smaller which can be committed, but nothing comes immediately to mind.
Perhaps a minios domain for the pv cases at least?
I've got a mirage guest that suspends and resumes - built from here:
https://github.com/mirage/mirage-skeleton/pull/42
It's ~400k gzipped, which still might be on the large side, but I'll attach it here in case it's of use.
I believe there are currently some efforts to get the suspend/resume changes required upstreamed back to mini-os, so hopefully this will all be a bit easier in the future.
Jon
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 3/13 tools/libxc: save/restore v2 framework
In reply to Andrew CooperFor testing purposes, the environmental variable "XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.
It is indended that once this series is less RFC, the v2 framework will completely replace v1.
--- tools/libxc/Makefile | 1 + tools/libxc/saverestore/common.h | 15 +++++++++++++++ tools/libxc/saverestore/restore.c | 23 +++++++++++++++++++++++ tools/libxc/saverestore/save.c | 19 +++++++++++++++++++ tools/libxc/xc_domain_restore.c | 8 ++++++++ tools/libxc/xc_domain_save.c | 6 ++++++ tools/libxc/xenguest.h | 13 +++++++++++++ 7 files changed, 85 insertions(+) create mode 100644 tools/libxc/saverestore/common.h create mode 100644 tools/libxc/saverestore/restore.c create mode 100644 tools/libxc/saverestore/save.c
tools/libxc/Makefile +1 -0
@@ -45,6 +45,7 @@ GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c +GUEST_SRCS-y += $(wildcard saverestore/*.c) GUEST_SRCS-y += xc_offline_page.c xc_compression.c else GUEST_SRCS-y += xc_nomigrate.c
tools/libxc/saverestore/common.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __COMMON__H +#define __COMMON__H + +#include "../xg_private.h" + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/restore.c new file +23 -0
@@ -0,0 +1,23 @@ +#include "common.h" + +int xc_domain_restore2 (xc_interface *xch,int io_fd,uint32_t dom, +unsigned int store_evtchn,unsigned long *store_mfn, +domid_t store_domid,unsigned int console_evtchn, +unsigned long *console_mfn,domid_t console_domid, +unsigned int hvm,unsigned int pae,int superpages, +int checkpointed_stream, +struct restore_callbacks *callbacks) +{ +IPRINTF ("In experimental %s" , __func__); +return -1 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/save.c new file +19 -0
@@ -0,0 +1,19 @@ +#include "common.h" + +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters, +uint32_t max_factor,uint32_t flags, +struct save_callbacks * callbacks,int hvm) +{ +IPRINTF ("In experimental %s" , __func__); +return -1 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/xc_domain_restore.c +8 -0
@@ -1490,6 +1490,14 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,struct restore_ctx *ctx = &_ctx;struct domain_info_context *dinfo = &ctx->dinfo; +if (getenv ("XG_MIGRATION_V2" ) ) + { +return xc_domain_restore2 ( + xch, io_fd, dom, store_evtchn, store_mfn, + store_domid, console_evtchn, console_mfn, console_domid, + hvm, pae, superpages, checkpointed_stream, callbacks); + } +DPRINTF ("%s: starting restore of new domid %u" , __func__, dom);pagebuf_init (&pagebuf);
tools/libxc/xc_domain_save.c +6 -0
@@ -894,6 +894,12 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterint completed =0 ; +if (getenv ("XG_MIGRATION_V2" ) ) + { +return xc_domain_save2 (xch, io_fd, dom, max_iters, + max_factor, flags, callbacks, hvm); + } +DPRINTF ("%s: starting save of domid %u" , __func__, dom);if ( hvm && !callbacks->switch_qemu_logdirty )
tools/libxc/xenguest.h +13 -0
@@ -88,6 +88,10 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */, struct save_callbacks* callbacks, int hvm); +/* Domain Save v2 */ +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters, +uint32_t max_factor,uint32_t flags, +struct save_callbacks * callbacks,int hvm);/* callbacks provided by xc_domain_restore */ struct restore_callbacks {
@@ -124,6 +128,15 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, unsigned int hvm, unsigned int pae, int superpages, int checkpointed_stream, struct restore_callbacks *callbacks); + +/* Domain Restore v2 */ +int xc_domain_restore2 (xc_interface *xch,int io_fd,uint32_t dom, +unsigned int store_evtchn,unsigned long *store_mfn, +domid_t store_domid,unsigned int console_evtchn, +unsigned long *console_mfn,domid_t console_domid, +unsigned int hvm,unsigned int pae,int superpages, +int checkpointed_stream, +struct restore_callbacks *callbacks);/** * xc_domain_restore writes a file to disk that contains the device * model saved state.
Signature · 1 line
1.7.10.4
PATCH v6 4/13 tools/libxc: C implementation of stream format
In reply to Andrew CooperProvide the C structures matching the binary (wire) format of the new stream format. All header/record fields are naturally aligned and explicit padding fields are used to ensure the correct layout (i.e., there is no need for any non-standard structure packing pragma or attribute).
Provide some helper functions for converting types to string for diagnostic purposes.
--- tools/libxc/saverestore/common.c | 87 ++++++++++++++++++ tools/libxc/saverestore/common.h | 8 ++ tools/libxc/saverestore/stream_format.h | 151 +++++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 tools/libxc/saverestore/common.c create mode 100644 tools/libxc/saverestore/stream_format.h
tools/libxc/saverestore/common.c new file +87 -0
@@ -0,0 +1,87 @@ +#include "common.h" + +static const char *dhdr_types[] = +{ + [DHDR_TYPE_X86_PV ] ="x86 PV" , + [DHDR_TYPE_X86_HVM ] ="x86 HVM" , + [DHDR_TYPE_X86_PVH ] ="x86 PVH" , + [DHDR_TYPE_ARM ] ="ARM" , +}; + +const char *dhdr_type_to_str (uint32_t type) +{ +if ( type <ARRAY_SIZE (dhdr_types) && dhdr_types[type] ) +return dhdr_types[type]; + +return "Reserved" ; +} + +static const char *mandatory_rec_types[] = +{ + [REC_TYPE_END ] ="End" , + [REC_TYPE_PAGE_DATA ] ="Page data" , + [REC_TYPE_X86_PV_INFO ] ="x86 PV info" , + [REC_TYPE_X86_PV_P2M_FRAMES ] ="x86 PV P2M frames" , + [REC_TYPE_X86_PV_VCPU_BASIC ] ="x86 PV vcpu basic" , + [REC_TYPE_X86_PV_VCPU_EXTENDED ] ="x86 PV vcpu extended" , + [REC_TYPE_X86_PV_VCPU_XSAVE ] ="x86 PV vcpu xsave" , + [REC_TYPE_SHARED_INFO ] ="Shared info" , + [REC_TYPE_TSC_INFO ] ="TSC info" , + [REC_TYPE_HVM_CONTEXT ] ="HVM context" , + [REC_TYPE_HVM_PARAMS ] ="HVM params" , + [REC_TYPE_TOOLSTACK ] ="Toolstack" , + [REC_TYPE_X86_PV_VCPU_MSRS ] ="x86 PV vcpu msrs" , + [REC_TYPE_VERIFY ] ="Verify" , +}; + + +static const char *optional_rec_types[] = +{ + [_REC_TYPE_SAVING_CPU] ="Saving CPU" , +}; + + +const char *rec_type_to_str (uint32_t type) +{ +if ( type &REC_TYPE_OPTIONAL ) + { +uint32_t idx = type & ~REC_TYPE_OPTIONAL ; + +if ( (idx <ARRAY_SIZE (optional_rec_types)) && + optional_rec_types[idx] ) +return optional_rec_types[idx]; + } +else + { +if ( (type <ARRAY_SIZE (mandatory_rec_types)) && + (mandatory_rec_types[type]) ) +return mandatory_rec_types[type]; + } + +return "Reserved" ; +} + +static void __attribute__((unused))build_assertions (void ) +{ +XC_BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_dhdr ) !=16 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rhdr ) !=8 ); + +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_page_data_header ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_info ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_p2m_frames ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_vcpu_hdr ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_tsc_info ) !=24 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params_entry ) !=16 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params ) !=8 ); +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/common.h +8 -0
@@ -3,6 +3,14 @@#include "../xg_private.h" +#include "stream_format.h" + +/* String representation of Domain Header types. */ +const char *dhdr_type_to_str (uint32_t type); + +/* String representation of Record types. */ +const char *rec_type_to_str (uint32_t type); +#endif /* * Local variables:
tools/libxc/saverestore/stream_format.h new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v6 5/13 tools/libxc: noarch common code
In reply to Andrew CooperAdd the context structure used to keep state during the save/restore process.
Define the set of architecture or domain type specific operations with a set of callbacks (save_ops, and restore_ops).
Add common functions for writing records.
---
v6:
* Use writev() instead of write()
--- tools/libxc/saverestore/common.c | 42 ++++++ tools/libxc/saverestore/common.h | 273 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 315 insertions(+)
tools/libxc/saverestore/common.c +42 -0
@@ -1,3 +1,5 @@ +#include <assert.h> +#include "common.h" static const char *dhdr_types[] =
@@ -61,6 +63,46 @@ const char *rec_type_to_str(uint32_t type)return "Reserved" ; } +int write_split_record (struct xc_sr_context *ctx,struct xc_sr_record *rec, +void *buf,size_t sz) +{ +static const char zeroes[(1u <<REC_ALIGN_ORDER ) -1 ] = {0 }; + +xc_interface *xch = ctx->xch; + typeof(rec->length) combined_length = rec->length + sz; +size_t record_length =ROUNDUP (combined_length,REC_ALIGN_ORDER ); +struct iovec parts[] = + { + { &rec->type,sizeof (rec->type) }, + { &combined_length,sizeof (combined_length) }, + { rec->data, rec->length }, + { buf, sz }, + { (void *)zeroes, record_length - combined_length }, + }; + +if ( record_length >REC_LENGTH_MAX ) + { +ERROR ("Record (0x%08" PRIx32", %s) length 0x%" PRIx32 +" exceeds max (0x%" PRIx32")" , rec->type, +rec_type_to_str (rec->type), rec->length,REC_LENGTH_MAX ); +return -1 ; + } + +if ( rec->length ) +assert (rec->data); +if ( sz ) +assert (buf); + +if (writev_exact (ctx->fd, parts,ARRAY_SIZE (parts)) ) + goto err; + +return 0 ; + + err: +PERROR ("Unable to write record to stream" ); +return -1 ; +} +static void __attribute__((unused))build_assertions (void ) {XC_BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 );
tools/libxc/saverestore/common.h +273 -0
286 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v6 6/13 tools/libxc: x86 common code
In reply to Andrew CooperSave/restore records common to all x86 domain types (HVM, PV).
This is only the TSC_INFO record.
--- tools/libxc/saverestore/common_x86.c | 133 ++++++++++++++++++++++++++++++++++ tools/libxc/saverestore/common_x86.h | 26 +++++++ 2 files changed, 159 insertions(+) create mode 100644 tools/libxc/saverestore/common_x86.c create mode 100644 tools/libxc/saverestore/common_x86.h
tools/libxc/saverestore/common_x86.c new file +133 -0
@@ -0,0 +1,133 @@ +#include "common_x86.h" + +static void cpuid_count (uint32_t leaf,uint32_t subleaf, +uint32_t *eax,uint32_t *ebx, +uint32_t *ecx,uint32_t *edx) +{ + asmvolatile ("cpuid" + :"=a" (*eax),"=b" (*ebx),"=c" (*ecx),"=d" (*edx) + :"a" (leaf),"c" (subleaf)); +} + +static void cpuid (uint32_t leaf, +uint32_t *eax,uint32_t *ebx, +uint32_t *ecx,uint32_t *edx) +{ +cpuid_count (leaf,0 , eax, ebx, ecx, edx); +} + +static int get_processor_brand_string (char *str) +{ +uint32_t *parts = (uint32_t *)str; +uint32_t max_extd_leaf, dummy; + +cpuid (0x80000000 , &max_extd_leaf, &dummy, &dummy, &dummy); + +if ( max_extd_leaf <0x80000004 ) +return -1 ; + +cpuid (0x80000002 , &parts[0 ], &parts[1 ], &parts[2 ], &parts[3 ]); +cpuid (0x80000003 , &parts[4 ], &parts[5 ], &parts[6 ], &parts[7 ]); +cpuid (0x80000004 , &parts[8 ], &parts[9 ], &parts[10 ], &parts[11 ]); + +return 0 ; +} + +int write_tsc_info (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_tsc_info tsc = {0 }; +struct xc_sr_record rec = + { + .type =REC_TYPE_TSC_INFO , + .length =sizeof (tsc), + .data = &tsc + }; + +if (xc_domain_get_tsc_info (xch, ctx->domid, &tsc.mode, + &tsc.nsec, &tsc.khz, &tsc.incarnation) <0 ) + { +PERROR ("Unable to obtain TSC information" ); +return -1 ; + } + +return write_record (ctx, &rec); +} + +int handle_tsc_info (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_tsc_info *tsc = rec->data; + +if ( rec->length !=sizeof (*tsc) ) + { +ERROR ("TSC_INFO record wrong size: length %" PRIu32", expected %zu" , + rec->length,sizeof (*tsc)); +return -1 ; + } + +if (xc_domain_set_tsc_info (xch, ctx->domid, tsc->mode, + tsc->nsec, tsc->khz, tsc->incarnation) ) + { +PERROR ("Unable to set TSC information" ); +return -1 ; + } + +return 0 ; +} + +int arch_write_saving_cpu (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +char *brand_string =alloca (49 );/* 48 from cpuid, and NUL. */ +struct xc_sr_record rec; + +if (get_processor_brand_string (brand_string) ) + { +ERROR ("Failed to obtain cpuid long processor brand string" ); +return -1 ; + } + + brand_string[48 ] ='\0' ; +while ( *brand_string ==' ' )/* Strip leading spaces. */ + brand_string++; + + rec.type =REC_TYPE_SAVING_CPU ; + rec.length =strlen (brand_string); + rec.data = brand_string; + +return write_record (ctx, &rec); +} + +int arch_handle_saving_cpu (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +char *brand_string =alloca (49 );/* 48 from cpuid, and NUL. */ + +if ( rec->length ==0 ) +return 0 ; + +DPRINTF ("Saving cpu was '%*s'" , + (int )rec->length, (char *)rec->data); + +if ( !get_processor_brand_string (brand_string) ) + { + brand_string[48 ] ='\0' ; +while ( *brand_string ==' ' )/* Strip leading spaces. */ + brand_string++; + +DPRINTF ("Current cpu is '%s'" , brand_string); + } + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/common_x86.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __COMMON_X86__H +#define __COMMON_X86__H + +#include "common.h" + +/* +* Obtains a domains TSC information from Xen and writes a TSC_INFO record +* into the stream. +*/ +int write_tsc_info (struct xc_sr_context *ctx); + +/* +* Parses a TSC_INFO record and applies the result to the domain. +*/ +int handle_tsc_info (struct xc_sr_context *ctx,struct xc_sr_record *rec); + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
PATCH v6 7/13 tools/libxc: x86 PV common code
In reply to Andrew CooperAdd functions common to save and restore of x86 PV guests. This includes functions for dealing with the P2M and M2P and the VCPU context.
--- tools/libxc/saverestore/common_x86_pv.c | 198 +++++++++++++++++++++++++++++++ tools/libxc/saverestore/common_x86_pv.h | 102 ++++++++++++++++ 2 files changed, 300 insertions(+) create mode 100644 tools/libxc/saverestore/common_x86_pv.c create mode 100644 tools/libxc/saverestore/common_x86_pv.h
tools/libxc/saverestore/common_x86_pv.c new file +198 -0
@@ -0,0 +1,198 @@ +#include <assert.h> + +#include "common_x86_pv.h" + +xen_pfn_t mfn_to_pfn (struct xc_sr_context *ctx,xen_pfn_t mfn) +{ +assert (mfn <= ctx->x86_pv.max_mfn); +return ctx->x86_pv.m2p[mfn]; +} + +bool mfn_in_pseudophysmap (struct xc_sr_context *ctx,xen_pfn_t mfn) +{ +return ( (mfn <= ctx->x86_pv.max_mfn) && + (mfn_to_pfn (ctx, mfn) <= ctx->x86_pv.max_pfn) && + (xc_pfn_to_mfn (mfn_to_pfn (ctx, mfn), ctx->x86_pv.p2m, + ctx->x86_pv.width) == mfn) ); +} + +void dump_bad_pseudophysmap_entry (struct xc_sr_context *ctx,xen_pfn_t mfn) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t pfn = ~0UL ; + +ERROR ("mfn %#lx, max %#lx" , mfn, ctx->x86_pv.max_mfn); + +if ( (mfn != ~0UL ) && (mfn <= ctx->x86_pv.max_mfn) ) + { + pfn = ctx->x86_pv.m2p[mfn]; +ERROR (" m2p[%#lx] = %#lx, max_pfn %#lx" , + mfn, pfn, ctx->x86_pv.max_pfn); + } + +if ( (pfn != ~0UL ) && (pfn <= ctx->x86_pv.max_pfn) ) +ERROR (" p2m[%#lx] = %#lx" , + pfn,xc_pfn_to_mfn (pfn, ctx->x86_pv.p2m, ctx->x86_pv.width)); +} + +xen_pfn_t cr3_to_mfn (struct xc_sr_context *ctx,uint64_t cr3) +{ +if ( ctx->x86_pv.width ==8 ) +return cr3 >>12 ; +else +return (((uint32_t )cr3 >>12 ) | ((uint32_t )cr3 <<20 )); +} + +uint64_t mfn_to_cr3 (struct xc_sr_context *ctx,xen_pfn_t mfn) +{ +if ( ctx->x86_pv.width ==8 ) +return ((uint64_t )mfn) <<12 ; +else +return (((uint32_t )mfn <<12 ) | ((uint32_t )mfn >>20 )); +} + +int x86_pv_domain_info (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +unsigned int guest_width, guest_levels, fpp; +int max_pfn; + +/* Get the domain width */ +if (xc_domain_get_guest_width (xch, ctx->domid, &guest_width) ) + { +PERROR ("Unable to determine dom%d's width" , ctx->domid); +return -1 ; + } + +if ( guest_width ==4 ) + guest_levels =3 ; +else if ( guest_width ==8 ) + guest_levels =4 ; +else + { +ERROR ("Invalid guest width %d. Expected 32 or 64" , guest_width *8 ); +return -1 ; + } + ctx->x86_pv.width = guest_width; + ctx->x86_pv.levels = guest_levels; + fpp =PAGE_SIZE / ctx->x86_pv.width; + +DPRINTF ("%d bits, %d levels" , guest_width *8 , guest_levels); + +/* Get the domain's size */ + max_pfn =xc_domain_maximum_gpfn (xch, ctx->domid); +if ( max_pfn <0 ) + { +PERROR ("Unable to obtain guests max pfn" ); +return -1 ; + } + +if ( max_pfn >0 ) + { + ctx->x86_pv.max_pfn = max_pfn; + ctx->x86_pv.p2m_frames = (ctx->x86_pv.max_pfn + fpp) / fpp; + +DPRINTF ("max_pfn %#x, p2m_frames %d" , max_pfn, ctx->x86_pv.p2m_frames); + } + +return 0 ; +} + +int x86_pv_map_m2p (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +long max_page =xc_maximum_ram_page (xch); +unsigned long m2p_chunks, m2p_size; +privcmd_mmap_entry_t *entries =NULL ; +xen_pfn_t *extents_start =NULL ; +int rc =-1 , i; + +if ( max_page <0 ) + { +PERROR ("Failed to get maximum ram page" ); + goto err; + } + + ctx->x86_pv.max_mfn = max_page; + m2p_size =M2P_SIZE (ctx->x86_pv.max_mfn); + m2p_chunks =M2P_CHUNKS (ctx->x86_pv.max_mfn); + + extents_start =malloc (m2p_chunks *sizeof (xen_pfn_t)); +if ( !extents_start ) + { +ERROR ("Unable to allocate %lu bytes for m2p mfns" , + m2p_chunks *sizeof (xen_pfn_t)); + goto err; + } + +if (xc_machphys_mfn_list (xch, m2p_chunks, extents_start) ) + { +PERROR ("Failed to get m2p mfn list" ); + goto err; + } + + entries =malloc (m2p_chunks *sizeof (privcmd_mmap_entry_t)); +if ( !entries ) + { +ERROR ("Unable to allocate %lu bytes for m2p mapping mfns" , + m2p_chunks *sizeof (privcmd_mmap_entry_t)); + goto err; + } + +for ( i =0 ; i < m2p_chunks; ++i ) + entries[i].mfn = extents_start[i]; + + ctx->x86_pv.m2p =xc_map_foreign_ranges ( + xch,DOMID_XEN , m2p_size,PROT_READ , +M2P_CHUNK_SIZE , entries, m2p_chunks); + +if ( !ctx->x86_pv.m2p ) + { +PERROR ("Failed to mmap m2p ranges" ); + goto err; + } + + ctx->x86_pv.nr_m2p_frames = (M2P_CHUNK_SIZE >>PAGE_SHIFT ) * m2p_chunks; + +#ifdef __i386__ +/* 32 bit toolstacks automatically get the compat m2p */ + ctx->x86_pv.compat_m2p_mfn0 = entries[0 ].mfn; +#else +/* 64 bit toolstacks need to ask Xen specially for it */ + { +struct xen_machphys_mfn_list xmml = { + .max_extents =1 , + .extent_start = { &ctx->x86_pv.compat_m2p_mfn0 } + }; + + rc =do_memory_op (xch, XENMEM_machphys_compat_mfn_list, + &xmml,sizeof (xmml)); +if ( rc || xmml.nr_extents !=1 ) + { +PERROR ("Failed to get compat mfn list from Xen" ); + rc =-1 ; + goto err; + } + } +#endif + +/* All Done */ + rc =0 ; +DPRINTF ("max_mfn %#lx" , ctx->x86_pv.max_mfn); + +err: +free (entries); +free (extents_start); + +return rc; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/common_x86_pv.h new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v6 8/13 tools/libxc: x86 PV save code
In reply to Andrew CooperSave the x86 PV specific parts of a domain. This is the X86_PV_INFO record, the P2M_FRAMES, the X86_PV_SHARED_INFO, the three different VCPU context records, and the MSR records.
The normalise_page callback used by the common code when writing the PAGE_DATA records, converts MFNs in page tables to PFNs.
---
v6:
* L1's don't have PSE. Bit 7 of an L1 is a PAT bit.
* Type-change failures are not fatal if live.
--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/save_x86_pv.c | 873 +++++++++++++++++++++++++++++++++ 2 files changed, 874 insertions(+) create mode 100644 tools/libxc/saverestore/save_x86_pv.c
tools/libxc/saverestore/common.h +1 -0
@@ -237,6 +237,7 @@ struct xc_sr_context }; }; +extern struct xc_sr_save_ops save_ops_x86_pv;struct xc_sr_record {
tools/libxc/saverestore/save_x86_pv.c new file +873 -0
873 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v6 9/13 tools/libxc: x86 PV restore code
In reply to Andrew CooperRestore the x86 PV specific parts. The X86_PV_INFO, the P2M_FRAMES, SHARED_INFO, and VCPU context records.
The localise_page callback is called from the common PAGE_DATA code to convert PFNs in page tables to MFNs.
Page tables are pinned and the guest's P2M is updated when the stream is complete.
---
v6:
* Batch pagetable pinning.
* Fix fencepost error validating basic vcpu state.
--- tools/libxc/saverestore/common.h | 2 + tools/libxc/saverestore/restore_x86_pv.c | 1016 ++++++++++++++++++++++++++++++ 2 files changed, 1018 insertions(+) create mode 100644 tools/libxc/saverestore/restore_x86_pv.c
tools/libxc/saverestore/common.h +2 -0
@@ -239,6 +239,8 @@ struct xc_sr_contextextern struct xc_sr_save_ops save_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_pv; +struct xc_sr_record {uint32_t type;
tools/libxc/saverestore/restore_x86_pv.c new file +1016 -0
1,016 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v6 10/13 tools/libxc: x86 HVM save code
In reply to Andrew CooperSave the x86 HVM specific parts of the domain. This is considerably simpler than an x86 PV domain. Only the HVM_CONTEXT and HVM_PARAMS records are needed.
There is no need for any page normalisation.
--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/save_x86_hvm.c | 255 ++++++++++++++++++++++++++++++++ 2 files changed, 256 insertions(+) create mode 100644 tools/libxc/saverestore/save_x86_hvm.c
tools/libxc/saverestore/common.h +1 -0
@@ -238,6 +238,7 @@ struct xc_sr_context };extern struct xc_sr_save_ops save_ops_x86_pv; +extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv;
tools/libxc/saverestore/save_x86_hvm.c new file +255 -0
255 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v6 11/13 tools/libxc: x86 HVM restore code
In reply to Andrew CooperRestore the x86 HVM specific parts of a domain. This is the HVM_CONTEXT and HVM_PARAMS records.
There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because this is what libxc currently does. This is intended to be moved into libxl proper in the future.
--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/restore_x86_hvm.c | 336 +++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+) create mode 100644 tools/libxc/saverestore/restore_x86_hvm.c
tools/libxc/saverestore/common.h +1 -0
@@ -241,6 +241,7 @@ extern struct xc_sr_save_ops save_ops_x86_pv;extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_hvm;struct xc_sr_record {
tools/libxc/saverestore/restore_x86_hvm.c new file +336 -0
336 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [Patch v6 11/13] tools/libxc: x86 HVM restore code
At 2014/7/8 1:38, Andrew Cooper Wrote:
Quoted 92 lines
Restore the x86 HVM specific parts of a domain. This is the
HVM_CONTEXTandHVM_PARAMSrecords.There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because this is what libxc currently does. This is intended to be moved into libxl proper in the future.
Signed-off-by Andrew Cooper <[email protected]>--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/restore_x86_hvm.c | 336 +++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+)create mode 100644
tools/libxc/saverestore/restore_x86_hvm.ctools/libxc/saverestore/common.h +1
-0@@ -241,6 +241,7 @@ extern struct xc_sr_save_ops save_ops_x86_pv;extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_hvm;struct xc_sr_record {tools/libxc/saverestore/restore_x86_hvm.c new file +58
-0@@ -0,0 +1,336 @@ +#include <assert.h> +#include <arpa/inet.h> + +#include "common_x86.h" + +/* TODO: remove */ +static int handle_toolstack (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +int rc; + +if ( !ctx->restore.callbacks || !ctx->restore.callbacks->toolstack_restore ) +return 0 ; + + rc = ctx->restore.callbacks->toolstack_restore (ctx->domid, rec->data, rec->length, + ctx->restore.callbacks->data); +if ( rc <0 ) +PERROR ("restoring toolstack" ); +return rc; +} + +/* +* Process an HVM_CONTEXT record from the stream. +*/ +static int handle_hvm_context (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +int rc; + + rc =xc_domain_hvm_setcontext (xch, ctx->domid, rec->data, rec->length); +if ( rc <0 ) +PERROR ("Unable to restore HVM context" ); +return rc; +} + +/* +* Process an HVM_PARAMS record from the stream. +*/ +static int handle_hvm_params (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_hvm_params *hdr = rec->data; +struct xc_sr_rec_hvm_params_entry *entry = hdr->param; +unsigned int i; +int rc; + +if ( rec->length <sizeof (*hdr) + || rec->length <sizeof (*hdr) + hdr->count *sizeof (*entry) ) + { +ERROR ("hvm_params record is too short" ); +return -1 ; + } + +for ( i =0 ; i < hdr->count; i++, entry++ ) + { +switch ( entry->index ) + { +case HVM_PARAM_CONSOLE_PFN :
tools/libxc/saverestore/restore_x86_hvm.c line 68
Quoted 10 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +10
-0+ ctx->restore.console_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_STORE_PFN : + ctx->restore.xenstore_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +xc_clear_domain_page (xch, ctx->domid, entry->value);
ioreq page may contain pending i/o request, so I think we should not clear them.
Thanks
Wen Congyang
Quoted 14 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +14
-0+break ; + } + + rc =xc_set_hvm_param (xch, ctx->domid, entry->index, entry->value); +if ( rc <0 ) + { +PERROR ("set HVM param %" PRId64" = 0x%016" PRIx64, + entry->index, entry->value); +return rc; + } + } +return 0 ; +} +
Re: [Patch v6 11/13] tools/libxc: x86 HVM restore code
Quoted 121 lines · Wen Congyang
At 2014/7/8 1:38, Andrew Cooper Wrote:
Quoted 105 lines
Restore the x86 HVM specific parts of a domain. This is the
HVM_CONTEXTandHVM_PARAMSrecords.There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because
this is what libxc currently does. This is intended to be moved into libxl
proper in the future.Signed-off-by Andrew Cooper <[email protected]>--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/restore_x86_hvm.c | 336 +++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+)create mode 100644
tools/libxc/saverestore/restore_x86_hvm.ctools/libxc/saverestore/common.h +1
-0@@ -241,6 +241,7 @@ extern struct xc_sr_save_ops save_ops_x86_pv;extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_hvm;struct xc_sr_record {tools/libxc/saverestore/restore_x86_hvm.c new file +7
-0@@ -0,0 +1,336 @@ +#include <assert.h> +#include <arpa/inet.h> + +#include "common_x86.h" + +/* TODO: remove */ +static int handle_toolstack(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +5
-0+{ +xc_interface *xch = ctx->xch; +int rc; + + if ( !ctx->restore.callbacks ||!ctx->restore.callbacks->toolstack_restore )
tools/libxc/saverestore/restore_x86_hvm.c new file +3
-0+return 0 ; + + rc = ctx->restore.callbacks->toolstack_restore(ctx->domid,
rec->data,rec->length,
+ctx->restore.callbacks->data);tools/libxc/saverestore/restore_x86_hvm.c new file +9
-0+if ( rc <0 ) +PERROR ("restoring toolstack" ); +return rc; +} + +/* +* Process an HVM_CONTEXT record from the stream. +*/ +static int handle_hvm_context(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +5
-0+{ +xc_interface *xch = ctx->xch; +int rc; + + rc = xc_domain_hvm_setcontext(xch, ctx->domid, rec->data,
rec->length);tools/libxc/saverestore/restore_x86_hvm.c new file +9
-0+if ( rc <0 ) +PERROR ("Unable to restore HVM context" ); +return rc; +} + +/* +* Process an HVM_PARAMS record from the stream. +*/ +static int handle_hvm_params(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +19
-0+{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_hvm_params *hdr = rec->data; +struct xc_sr_rec_hvm_params_entry *entry = hdr->param; +unsigned int i; +int rc; + +if ( rec->length <sizeof (*hdr) + || rec->length <sizeof (*hdr) + hdr->count *sizeof (*entry) ) + { +ERROR ("hvm_params record is too short" ); +return -1 ; + } + +for ( i =0 ; i < hdr->count; i++, entry++ ) + { +switch ( entry->index ) + { +case HVM_PARAM_CONSOLE_PFN :tools/libxc/saverestore/restore_x86_hvm.c line 68
Quoted 10 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +10
-0+ ctx->restore.console_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_STORE_PFN : + ctx->restore.xenstore_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +xc_clear_domain_page (xch, ctx->domid, entry->value);ioreq page may contain pending i/o request, so I think we should not clear
them.
Quoted 2 lines
Thanks
Wen Congyang
I noticed that in your other series.
While I can see why it is causing problems for you, avoiding clearing the page only hides the problem; it doesn't solve it.
Amongst other things, avoiding clearing the page could result in qemu binding to the wrong event channels. Without sending the other IO emulation state, leaving stale ioreqs in the rings is dangerous.
All of this comes as a result of attempting to performs actions (i.e. migrating an essentially unpaused VM) outside of the original designed usecase, and you are going to have to do more than just avoiding cleaning these pages.
~Andrew
Quoted 16 lines
Quoted 16 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +4
-0+break ; + } + + rc = xc_set_hvm_param(xch, ctx->domid, entry->index,
entry->value);tools/libxc/saverestore/restore_x86_hvm.c new file +10
-0+if ( rc <0 ) + { +PERROR ("set HVM param %" PRId64" = 0x%016" PRIx64, + entry->index, entry->value); +return rc; + } + } +return 0 ; +} +
Re: [Patch v6 11/13] tools/libxc: x86 HVM restore code
Quoted 132 lines
-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Andrew Cooper
Sent: 18 July 2014 16:09
To: Wen Congyang; Xen-devel
Subject: Re: [Xen-devel] [Patch v6 11/13]tools/libxc: x86 HVM restore codeQuoted 121 lines · Wen Congyang
At 2014/7/8 1:38, Andrew Cooper Wrote:
Quoted 105 lines
Restore the x86 HVM specific parts of a domain. This is the
HVM_CONTEXTandHVM_PARAMSrecords.There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because
this is what libxc currently does. This is intended to be moved into libxl
proper in the future.Signed-off-by Andrew Cooper <[email protected]>--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/restore_x86_hvm.c | 336 +++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+)create mode 100644
tools/libxc/saverestore/restore_x86_hvm.ctools/libxc/saverestore/common.h +1
-0@@ -241,6 +241,7 @@ extern struct xc_sr_save_ops save_ops_x86_pv;extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_hvm;struct xc_sr_record {tools/libxc/saverestore/restore_x86_hvm.c new file +7
-0@@ -0,0 +1,336 @@ +#include <assert.h> +#include <arpa/inet.h> + +#include "common_x86.h" + +/* TODO: remove */ +static int handle_toolstack(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +5
-0+{ +xc_interface *xch = ctx->xch; +int rc; + + if ( !ctx->restore.callbacks ||!ctx->restore.callbacks->toolstack_restore )
tools/libxc/saverestore/restore_x86_hvm.c new file +3
-0+return 0 ; + + rc = ctx->restore.callbacks->toolstack_restore(ctx->domid,
rec->data,rec->length,
+ctx->restore.callbacks->data);tools/libxc/saverestore/restore_x86_hvm.c new file +9
-0+if ( rc <0 ) +PERROR ("restoring toolstack" ); +return rc; +} + +/* +* Process an HVM_CONTEXT record from the stream. +*/ +static int handle_hvm_context(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +5
-0+{ +xc_interface *xch = ctx->xch; +int rc; + + rc = xc_domain_hvm_setcontext(xch, ctx->domid, rec->data,
rec->length);tools/libxc/saverestore/restore_x86_hvm.c new file +9
-0+if ( rc <0 ) +PERROR ("Unable to restore HVM context" ); +return rc; +} + +/* +* Process an HVM_PARAMS record from the stream. +*/ +static int handle_hvm_params(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +19
-0+{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_hvm_params *hdr = rec->data; +struct xc_sr_rec_hvm_params_entry *entry = hdr->param; +unsigned int i; +int rc; + +if ( rec->length <sizeof (*hdr) + || rec->length <sizeof (*hdr) + hdr->count *sizeof (*entry) ) + { +ERROR ("hvm_params record is too short" ); +return -1 ; + } + +for ( i =0 ; i < hdr->count; i++, entry++ ) + { +switch ( entry->index ) + { +case HVM_PARAM_CONSOLE_PFN :tools/libxc/saverestore/restore_x86_hvm.c line 68
Quoted 10 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +10
-0+ ctx->restore.console_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_STORE_PFN : + ctx->restore.xenstore_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +xc_clear_domain_page (xch, ctx->domid, entry->value);ioreq page may contain pending i/o request, so I think we should not clear
them.Quoted 2 lines
Thanks
Wen Congyang
Quoted 9 lines
I noticed that in your other series.
While I can see why it is causing problems for you, avoiding clearing the page only hides the problem; it doesn't solve it.
Amongst other things, avoiding clearing the page could result in qemu binding to the wrong event channels. Without sending the other IO emulation state, leaving stale ioreqs in the rings is dangerous.
I don't think this is the case (providing vcpus are paused). Xen should have updated the event channels before the new QEMU instance starts at the receiving end (otherwise how would it work now?) and the ioreq state will either be complete (i.e. ready for a vcpu resume) or new (i.e. untouched by qemu), unless qemu died uncleanly at the sending end, which I assume is not a supported usecase. Gratuitously clearing these pages seems like a bad thing to do.
Paul
Quoted 29 lines
All of this comes as a result of attempting to performs actions (i.e. migrating an essentially unpaused VM) outside of the original designed usecase, and you are going to have to do more than just avoiding cleaning these pages.
~Andrew
Quoted 16 lines
Quoted 6 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +4
-0+break ; + } + + rc = xc_set_hvm_param(xch, ctx->domid, entry->index,
entry->value);tools/libxc/saverestore/restore_x86_hvm.c line 82
Quoted 10 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +10
-0+if ( rc <0 ) + { +PERROR ("set HVM param %" PRId64" = 0x%016" PRIx64, + entry->index, entry->value); +return rc; + } + } +return 0 ; +} +_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Patch v6 11/13] tools/libxc: x86 HVM restore code
At 2014/7/18 23:42, Paul Durrant Wrote:
Quoted 137 lines
Quoted 137 lines
-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Andrew Cooper
Sent: 18 July 2014 16:09
To: Wen Congyang; Xen-devel
Subject: Re: [Xen-devel] [Patch v6 11/13]tools/libxc: x86 HVM restore codeQuoted 121 lines · Wen Congyang
At 2014/7/8 1:38, Andrew Cooper Wrote:
Quoted 105 lines
Restore the x86 HVM specific parts of a domain. This is the
HVM_CONTEXTandHVM_PARAMSrecords.There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because
this is what libxc currently does. This is intended to be moved into libxl
proper in the future.Signed-off-by Andrew Cooper <[email protected]>--- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/restore_x86_hvm.c | 336 +++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+)create mode 100644
tools/libxc/saverestore/restore_x86_hvm.ctools/libxc/saverestore/common.h +1
-0@@ -241,6 +241,7 @@ extern struct xc_sr_save_ops save_ops_x86_pv;extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_hvm;struct xc_sr_record {tools/libxc/saverestore/restore_x86_hvm.c new file +7
-0@@ -0,0 +1,336 @@ +#include <assert.h> +#include <arpa/inet.h> + +#include "common_x86.h" + +/* TODO: remove */ +static int handle_toolstack(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +5
-0+{ +xc_interface *xch = ctx->xch; +int rc; + + if ( !ctx->restore.callbacks ||!ctx->restore.callbacks->toolstack_restore )
tools/libxc/saverestore/restore_x86_hvm.c new file +3
-0+return 0 ; + + rc = ctx->restore.callbacks->toolstack_restore(ctx->domid,
rec->data,rec->length,
+ctx->restore.callbacks->data);tools/libxc/saverestore/restore_x86_hvm.c new file +9
-0+if ( rc <0 ) +PERROR ("restoring toolstack" ); +return rc; +} + +/* +* Process an HVM_CONTEXT record from the stream. +*/ +static int handle_hvm_context(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +5
-0+{ +xc_interface *xch = ctx->xch; +int rc; + + rc = xc_domain_hvm_setcontext(xch, ctx->domid, rec->data,
rec->length);tools/libxc/saverestore/restore_x86_hvm.c new file +9
-0+if ( rc <0 ) +PERROR ("Unable to restore HVM context" ); +return rc; +} + +/* +* Process an HVM_PARAMS record from the stream. +*/ +static int handle_hvm_params(struct xc_sr_context *ctx, struct
xc_sr_record*rec)tools/libxc/saverestore/restore_x86_hvm.c new file +19
-0+{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_hvm_params *hdr = rec->data; +struct xc_sr_rec_hvm_params_entry *entry = hdr->param; +unsigned int i; +int rc; + +if ( rec->length <sizeof (*hdr) + || rec->length <sizeof (*hdr) + hdr->count *sizeof (*entry) ) + { +ERROR ("hvm_params record is too short" ); +return -1 ; + } + +for ( i =0 ; i < hdr->count; i++, entry++ ) + { +switch ( entry->index ) + { +case HVM_PARAM_CONSOLE_PFN :tools/libxc/saverestore/restore_x86_hvm.c line 68
Quoted 10 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +10
-0+ ctx->restore.console_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_STORE_PFN : + ctx->restore.xenstore_mfn = entry->value; +xc_clear_domain_page (xch, ctx->domid, entry->value); +break ; +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +xc_clear_domain_page (xch, ctx->domid, entry->value);ioreq page may contain pending i/o request, so I think we should not clear
them.Quoted 2 lines
Thanks
Wen CongyangI noticed that in your other series.
While I can see why it is causing problems for you, avoiding clearing the page only hides the problem; it doesn't solve it.
Quoted 6 lines
Quoted 4 lines
Amongst other things, avoiding clearing the page could result in qemu binding to the wrong event channels. Without sending the other IO emulation state, leaving stale ioreqs in the rings is dangerous.
I don't think this is the case (providing vcpus are paused). Xen should have updated the event channels before the new QEMU instance starts at the receiving end (otherwise how would it work now?) and the ioreq state will either be complete (i.e. ready for a vcpu resume) or new (i.e. untouched by qemu), unless qemu died uncleanly at the sending end, which I assume is not a supported usecase. Gratuitously clearing these pages seems like a bad thing to do.
Here is the qemu codes:
xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_IOREQ_PFN, &ioreq_pfn);
DPRINTF("shared page at pfn %lx\n", ioreq_pfn);
state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
PROT_READ|PROT_WRITE,ioreq_pfn);
if (state->shared_page == NULL) {
hw_error("map shared IO page returned error %d handle="XC_INTERFACE_FMT,
errno, xen_xc);
}
xc_get_hvm_param(xen_xc, xen_domid, HVM_PARAM_BUFIOREQ_PFN,
&ioreq_pfn);
DPRINTF("buffered io page at pfn %lx\n", ioreq_pfn);
state->buffered_io_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
PROT_READ|PROT_WRITE, ioreq_pfn);
if (state->buffered_io_page == NULL) {
hw_error("map buffered IO page returned error %d", errno);
}
state->ioreq_local_port = g_malloc0(max_cpus * sizeof (evtchn_port_t));In qemu, we need to get ioreq/buffeed req pfn before mapping the share page. We will auto create default ioreq server when getting the pfn. So the event channel is valid before we map the page.
Thanks
Wen Congyang
Quoted 34 lines
Paul
Quoted 29 lines
All of this comes as a result of attempting to performs actions (i.e. migrating an essentially unpaused VM) outside of the original designed usecase, and you are going to have to do more than just avoiding cleaning these pages.
~Andrew
Quoted 16 lines
Quoted 6 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +4
-0+break ; + } + + rc = xc_set_hvm_param(xch, ctx->domid, entry->index,
entry->value);tools/libxc/saverestore/restore_x86_hvm.c line 82
Quoted 10 lines
tools/libxc/saverestore/restore_x86_hvm.c new file +10
-0+if ( rc <0 ) + { +PERROR ("set HVM param %" PRId64" = 0x%016" PRIx64, + entry->index, entry->value); +return rc; + } + } +return 0 ; +} +_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 12/13 tools/libxc: noarch save code
In reply to Andrew CooperSave a domain, calling domain type specific function at the appropriate points. This implements the xc_domain_save2() API function which is equivalent to the existing xc_domain_save().
This writes the image and domain headers, and writes all the PAGE_DATA records using a "live" process.
---
v6:
* Use writev() instead of write() for PAGE_DATA.
* Introduce separate non-live suspend which avoids playing with logdirty.
* Fix a bug which would clobber the penultimate logdirty bitmap.
--- tools/libxc/saverestore/save.c | 687 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 686 insertions(+), 1 deletion(-)
tools/libxc/saverestore/save.c +686 -1
@@ -1,11 +1,696 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct xc_sr_context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +struct xc_sr_ihdr ihdr = + { + .marker =IHDR_MARKER , + .id =htonl (IHDR_ID ), + .version =htonl (IHDR_VERSION ), + .options =htons (IHDR_OPT_LITTLE_ENDIAN ), + }; +struct xc_sr_dhdr dhdr = + { + .type = guest_type, + .page_shift =XC_PAGE_SHIFT , + .xen_major = (xen_version >>16 ) &0xffff , + .xen_minor = (xen_version) &0xffff , + }; + +if ( xen_version <0 ) + { +PERROR ("Unable to obtain Xen Version" ); +return -1 ; + } + +if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) + { +PERROR ("Unable to write Image Header to stream" ); +return -1 ; + } + +if (write_exact (ctx->fd, &dhdr,sizeof (dhdr)) ) + { +PERROR ("Unable to write Domain Header to stream" ); +return -1 ; + } + +return 0 ; +} + +/* +* Writes an END record into the stream. +*/ +static int write_end_record (struct xc_sr_context *ctx) +{ +struct xc_sr_record end = {REC_TYPE_END ,0 ,NULL }; + +return write_record (ctx, &end); +} + +/* +* Writes a batch of memory as a PAGE_DATA record into the stream. The batch +* is constructed in ctx->save.batch_pfns. +* +* This function: +* - gets the types for each pfn in the batch. +* - for each pfn with real data: +* - maps and attempts to localise the pages. +* - construct and writes a PAGE_DATA record into the stream. +*/ +static int write_batch (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =NULL , *types =NULL ; +void *guest_mapping =NULL ; +void **guest_data =NULL ; +void **local_pages =NULL ; +int *errors =NULL , rc =-1 ; +unsigned i, p, nr_pages =0 ; +unsigned nr_pfns = ctx->save.nr_batch_pfns; +void *page, *orig_page; +uint64_t *rec_pfns =NULL ; +struct iovec *iov =NULL ;int iovcnt =0 ; +struct xc_sr_rec_page_data_header hdr = {0 }; +struct xc_sr_record rec = + { + .type =REC_TYPE_PAGE_DATA , + }; + +assert (nr_pfns !=0 ); + +/* Mfns of the batch pfns. */ + mfns =malloc (nr_pfns *sizeof (*mfns)); +/* Types of the batch pfns. */ + types =malloc (nr_pfns *sizeof (*types)); +/* Errors from attempting to map the mfns. */ + errors =malloc (nr_pfns *sizeof (*errors)); +/* Pointers to page data to send. Either mapped mfns or local allocations. */ + guest_data =calloc (nr_pfns,sizeof (*guest_data)); +/* Pointers to locally allocated pages. Need freeing. */ + local_pages =calloc (nr_pfns,sizeof (*local_pages)); +/* iovec[] for writev(). */ + iov =malloc ((nr_pfns +4 ) *sizeof (*iov)); + +if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov ) + { +ERROR ("Unable to allocate arrays for a batch of %u pages" , + nr_pfns); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { + types[i] = mfns[i] = ctx->save.ops.pfn_to_gfn (ctx, ctx->save.batch_pfns[i]); + +/* Likely a ballooned page. */ +if ( mfns[i] ==INVALID_MFN ) +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + } + + rc =xc_get_pfn_type_batch (xch, ctx->domid, nr_pfns, types); +if ( rc ) + { +PERROR ("Failed to get types for pfn batch" ); + goto err; + } + rc =-1 ; + +for ( i =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + + mfns[nr_pages++] = mfns[i]; + } + +if ( nr_pages >0 ) + { + guest_mapping =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ , mfns, errors, nr_pages); +if ( !guest_mapping ) + { +PERROR ("Failed to map guest pages" ); + goto err; + } + } + +for ( i =0 , p =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + +if ( errors[p] ) + { +ERROR ("Mapping of pfn %#lx (mfn %#lx) failed %d" , + ctx->save.batch_pfns[i], mfns[p], errors[p]); + goto err; + } + + orig_page = page = guest_mapping + (p *PAGE_SIZE ); + rc = ctx->save.ops.normalise_page (ctx, types[i], &page); +if ( rc ) + { +if ( rc ==-1 && errno ==EAGAIN ) + { +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + types[i] =XEN_DOMCTL_PFINFO_XTAB ; + --nr_pages; + } +else + goto err; + } +else + guest_data[i] = page; + +if ( page != orig_page ) + local_pages[i] = page; + rc =-1 ; + + ++p; + } + + rec_pfns =malloc (nr_pfns *sizeof (*rec_pfns)); +if ( !rec_pfns ) + { +ERROR ("Unable to allocate %zu bytes of memory for page data pfn list" , + nr_pfns *sizeof (*rec_pfns)); + goto err; + } + + hdr.count = nr_pfns; + + rec.length =sizeof (hdr); + rec.length += nr_pfns *sizeof (*rec_pfns); + rec.length += nr_pages *PAGE_SIZE ; + +for ( i =0 ; i < nr_pfns; ++i ) + rec_pfns[i] = ((uint64_t )(types[i]) <<32 ) | ctx->save.batch_pfns[i]; + + iov[0 ].iov_base = &rec.type; + iov[0 ].iov_len =sizeof (rec.type); + + iov[1 ].iov_base = &rec.length; + iov[1 ].iov_len =sizeof (rec.length); + + iov[2 ].iov_base = &hdr; + iov[2 ].iov_len =sizeof (hdr); + + iov[3 ].iov_base = rec_pfns; + iov[3 ].iov_len = nr_pfns *sizeof (*rec_pfns); + +for ( i =0 , iovcnt =4 ; i < nr_pfns; ++i ) + { +if ( guest_data[i] ) + { + iov[iovcnt].iov_base = guest_data[i]; + iov[iovcnt].iov_len =PAGE_SIZE ; + iovcnt++; + --nr_pages; + } + } + +if (writev_exact (ctx->fd, iov, iovcnt) ) + { +PERROR ("Failed to write page data to stream" ); + goto err; + } + +/* Sanity check we have sent all the pages we expected to. */ +assert (nr_pages ==0 ); + rc = ctx->save.nr_batch_pfns =0 ; + + err: +free (rec_pfns); +if ( guest_mapping ) +munmap (guest_mapping, nr_pages *PAGE_SIZE ); +for ( i =0 ; local_pages && i < nr_pfns; ++i ) +free (local_pages[i]); +free (iov); +free (local_pages); +free (guest_data); +free (errors); +free (types); +free (mfns); + +return rc; +} + +/* +* Flush a batch of pfns into the stream. +*/ +static int flush_batch (struct xc_sr_context *ctx) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==0 ) +return rc; + + rc =write_batch (ctx); + +if ( !rc ) + { +VALGRIND_MAKE_MEM_UNDEFINED (ctx->save.batch_pfns, +MAX_BATCH_SIZE *sizeof (*ctx->save.batch_pfns)); + } + +return rc; +} + +/* +* Add a single pfn to the batch, flushing the batch if full. +*/ +static int add_to_batch (struct xc_sr_context *ctx,xen_pfn_t pfn) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==MAX_BATCH_SIZE ) + rc =flush_batch (ctx); + +if ( rc ==0 ) + ctx->save.batch_pfns[ctx->save.nr_batch_pfns++] = pfn; + +return rc; +} + +/* +* Pause/suspend the domain, and refresh ctx->dominfo if required. +*/ +static int suspend_domain (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +/* TODO: Properly specify the return value from this callback. All +* implementations currently appear to return 1 for success, whereas +* the legacy code checks for != 0. */ +int cb_rc = ctx->save.callbacks->suspend (ctx->save.callbacks->data); + +if ( cb_rc ==0 ) + { +ERROR ("save callback suspend() failed: %d" , cb_rc); +return -1 ; + } + +/* Refresh domain information. */ +if ( (xc_domain_getinfo (xch, ctx->domid,1 , &ctx->dominfo) !=1 ) || + (ctx->dominfo.domid != ctx->domid) ) + { +PERROR ("Unable to refresh domain information" ); +return -1 ; + } + +/* Confirm the domain has actually been paused. */ +if ( !ctx->dominfo.shutdown || + (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain has not been suspended: shutdown %d, reason %d" , + ctx->dominfo.shutdown, ctx->dominfo.shutdown_reason); +return -1 ; + } + +IPRINTF ("Domain now paused" ); + +return 0 ; +} + +/* +* Send all pages in the guests p2m. Used as the first iteration of the live +* migration loop, and for a non-live save. +*/ +static int send_all_pages (struct xc_sr_context *ctx) +{ +xen_pfn_t p; +int rc; + +for ( p =0 ; p < ctx->save.p2m_size; ++p ) + { + rc =add_to_batch (ctx, p); +if ( rc ) +return rc; + } + +return flush_batch (ctx); +} + +/* +* Send all domain memory. This is the heart of the live migration loop. +*/ +static int send_domain_memory_live (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); +xc_shadow_op_stats_t stats = {-1 ,-1 }; +unsigned pages_written; +unsigned x =0 , max_iter =5 , dirty_threshold =50 ; +xen_pfn_t p; +int rc =-1 ; + + to_send =xc_hypercall_buffer_alloc_pages ( + xch, to_send,NRPAGES (bitmap_size (ctx->save.p2m_size))); + + ctx->save.batch_pfns =malloc (MAX_BATCH_SIZE *sizeof (*ctx->save.batch_pfns)); + ctx->save.deferred_pages =calloc (1 ,bitmap_size (ctx->save.p2m_size)); + +if ( !ctx->save.batch_pfns || !to_send || !ctx->save.deferred_pages ) + { +ERROR ("Unable to allocate memory for to_{send,fix}/batch bitmaps" ); + goto out; + } + +/* This juggling is required if logdirty is already on, e.g. VRAM tracking */ +if (xc_shadow_control (xch, ctx->domid, +XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY , +NULL ,0 ,NULL ,0 ,NULL ) <0 ) + { +int frc =xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); +if ( frc >=0 ) + frc =xc_shadow_control (xch, ctx->domid, +XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY , +NULL ,0 ,NULL ,0 ,NULL ); +if ( frc <0 ) + { +PERROR ("Failed to enable logdirty: rc %d" , frc); + goto out; + } + } + +DPRINTF ("Iteration %u" , x); + rc =send_all_pages (ctx); +if ( rc ) + goto out; + pages_written = ctx->save.p2m_size -1 ; + +for ( x =1 ; x < max_iter ; ++x ) + { +DPRINTF ("Iteration %u" , x); + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } +else +DPRINTF (" Wrote %u pages; stats: faults %" PRIu32", dirty %" PRIu32, + pages_written, stats.fault_count, stats.dirty_count); + pages_written =0 ; + +for ( p =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + +if ( stats.dirty_count < dirty_threshold ) +break ; + } + + rc =suspend_domain (ctx); +if ( rc ) + goto out; + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +for ( p =0 , pages_written =0 ; p < ctx->save.p2m_size; ++p ) + { +if (test_bit (p, to_send) ||test_bit (p, ctx->save.deferred_pages) ) + { + rc =add_to_batch (ctx, p); +if ( rc ) + goto out; + ++pages_written; + } + } + + rc =flush_batch (ctx); +if ( rc ) + goto out; + +DPRINTF (" Wrote %u pages" , pages_written); +IPRINTF ("Sent all pages" ); + +if ( ctx->save.debug ) + { +struct xc_sr_record rec = + { + .type =REC_TYPE_VERIFY , + .length =0 , + }; + +DPRINTF ("Enabling verify mode" ); + + rc =write_record (ctx, &rec); +if ( rc ) + goto out; + + rc =send_all_pages (ctx); +if ( rc ) + goto out; + +DPRINTF (" Wrote %lu verification pages" , ctx->save.p2m_size -1 ); + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_PEEK , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +DPRINTF (" Further stats: faults %" PRIu32", dirty %" PRIu32, + stats.fault_count, stats.dirty_count); + } + + out: +xc_hypercall_buffer_free_pages (xch, to_send, +NRPAGES (bitmap_size (ctx->save.p2m_size))); +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); +return rc; +} + +/* +* Send all domain memory, pausing the domain first. Generally used for +* suspend-to-file. +*/ +static int send_domain_memory_nonlive (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc =-1 ; + + ctx->save.batch_pfns =malloc (MAX_BATCH_SIZE * +sizeof (*ctx->save.batch_pfns)); + ctx->save.deferred_pages =calloc (1 ,bitmap_size (ctx->save.p2m_size)); + +if ( !ctx->save.batch_pfns || !ctx->save.deferred_pages ) + { +PERROR ("Failed to allocate memory for nonlive tracking structures" ); + errno =ENOMEM ; + goto err; + } + + rc =suspend_domain (ctx); +if ( rc ) + goto err; + + rc =send_all_pages (ctx); +if ( rc ) + goto err; + +IPRINTF ("Sent all %lu pages" , ctx->save.p2m_size -1 ); + + err: +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); + +return rc; +} + +/* +* Save a domain. +*/ +static int save (struct xc_sr_context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Saving domain %d, type %s" , + ctx->domid,dhdr_type_to_str (guest_type)); + + rc = ctx->save.ops.setup (ctx); +if ( rc ) + goto err; + + rc =write_headers (ctx, guest_type); +if ( rc ) + goto err; + + rc =arch_write_saving_cpu (ctx); +if ( rc ) + goto err; + + rc = ctx->save.ops.start_of_stream (ctx); +if ( rc ) + goto err; + +if ( ctx->save.live ) + { +DPRINTF ("Starting live migrate" ); + rc =send_domain_memory_live (ctx); + } +else + { +DPRINTF ("Starting nonlive save" ); + rc =send_domain_memory_nonlive (ctx); + } + +if ( rc ) + goto err; + +/* Refresh domain information now it has paused. */ +if ( (xc_domain_getinfo (xch, ctx->domid,1 , &ctx->dominfo) !=1 ) || + (ctx->dominfo.domid != ctx->domid) ) + { +PERROR ("Unable to refresh domain information" ); + rc =-1 ; + goto err; + } +else if ( (!ctx->dominfo.shutdown || + ctx->dominfo.shutdown_reason != SHUTDOWN_suspend ) && + !ctx->dominfo.paused ) + { +ERROR ("Domain has not been suspended" ); + rc =-1 ; + goto err; + } + + rc = ctx->save.ops.end_of_stream (ctx); +if ( rc ) + goto err; + + rc =write_end_record (ctx); +if ( rc ) + goto err; + +IPRINTF ("Save successful" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Save failed" ); + + done: +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); + + rc = ctx->save.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +}; +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters,uint32_t max_factor,uint32_t flags,struct save_callbacks * callbacks,int hvm) { +struct xc_sr_context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions :( */ + ctx.save.callbacks = callbacks; + ctx.save.live = !!(flags &XCFLAGS_LIVE ); + ctx.save.debug = !!(flags &XCFLAGS_DEBUG ); +IPRINTF ("In experimental %s" , __func__); -return -1 ; +DPRINTF ("fd %d, dom %" PRIu32", max_iters %" PRIu32", max_factor %" PRIu32 +", flags %" PRIu32", hvm %d" , io_fd, dom, max_iters, max_factor, + flags, hvm); + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %" PRIu32" does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; +IPRINTF ("Saving domain %" PRIu32, dom); + + ctx.save.p2m_size =xc_domain_maximum_gpfn (xch, dom) +1 ; +if ( ctx.save.p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) + { + errno =E2BIG ; +ERROR ("Cannot save this big a guest" ); +return -1 ; + } + +if ( ctx.dominfo.hvm ) + { + ctx.save.ops = save_ops_x86_hvm; +return save (&ctx,DHDR_TYPE_X86_HVM ); + } +else + { + ctx.save.ops = save_ops_x86_pv; +return save (&ctx,DHDR_TYPE_X86_PV ); + } }/*
Signature · 1 line
1.7.10.4
PATCH v6 13/13 tools/libxc: noarch restore code
In reply to Andrew CooperRestore a domain from the new format. This reads and validates the domain and image header and loads the guest memory from the PAGE_DATA records, populating the p2m as it does so.
This provides the xc_domain_restore2() function as an alternative to the existing xc_domain_restore().
---
v6:
* Fix error path with rc = 0.
* Fix undefined memory issue with creating the populated_pfns array.
--- tools/libxc/saverestore/common.h | 6 + tools/libxc/saverestore/restore.c | 628 ++++++++++++++++++++++++++++++++++++- 2 files changed, 633 insertions(+), 1 deletion(-)
tools/libxc/saverestore/common.h +6 -0
@@ -289,6 +289,12 @@ int arch_write_saving_cpu(struct xc_sr_context *ctx);*/ int arch_handle_saving_cpu (struct xc_sr_context *ctx,struct xc_sr_record *rec); +/* TODO - find a better way of hiding this. It should be private to +* restore.c, but is needed by x86_pv_localise_page() +*/ +int populate_pfns (struct xc_sr_context *ctx,unsigned count, +const xen_pfn_t *original_pfns,const uint32_t *types); +#endif /* * Local variables:
tools/libxc/saverestore/restore.c +627 -1
640 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 6 lines · Andrew Cooper
The next area of work is the libxl integration, which will seek to undo the current layering violations. It will involve introducing a new libxl framing format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion scripts so migrations from older libxl/libxc toolstacks will continue to work.
I think the xl/libxl work is orthogonal to this libxc work. If the libxl maintainers are keen on addressing similar problems with the libxl stream protocol then perhaps they could volunteer? It seems somewhat unfair to require people fixing a related area in libxc to also do this work.
The two problem areas between libxl and libxc are:
1. qemu save record processed by the libxc restore code -- this is an internal implementation detail that has no impact on the save record format.
2. The TOOLSTACK record. I think it would be acceptable to leave this for now and deprecate it once it becomes unnecessary. It's only a minor problem.
David
Quoted 8 lines · David Vrabel
Quoted 6 lines · Andrew Cooper
The next area of work is the libxl integration, which will seek to undo the current layering violations. It will involve introducing a new libxl framing format (which will happen to look curiously similar to the libxc framing format), as well as providing legacy compatibility using the legacy conversion scripts so migrations from older libxl/libxc toolstacks will continue to work.
Quoted 5 lines
I think the xl/libxl work is orthogonal to this libxc work. If the libxl maintainers are keen on addressing similar problems with the libxl stream protocol then perhaps they could volunteer? It seems somewhat unfair to require people fixing a related area in libxc to also do this work.
AFAIK no one has asked Andrew to do anything with the xl/libxl layer stuff (at least not beyond any protocol framing explicitly required due to the libxc changes), it's all been of his own desire.
Ian.
Quoted 10 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
v6 follows the integration of this code into XenServer, and having the full suite of XenRT tests being run. Included in these tests are live migrations from 32bit toolstacks to 64bit toolstacks, using the python conversion script. Several corruption issues have been located and fixed, as well as many minor improvements.
Quoted 4 lines
In addition, performance tests have been performed. After finding an initial regression, the code uas been tweaked to use
writev()in preference towrite()which vastly reduces the number of system calls performed. The performance is now better than the legacy code for all sizes of VM.
Fantastic!
.. snip..
Quoted 1 line
The code is presented here for comment/query/critism.
My notes say: 'tmem and remus need work'. Is that addressed by this patchset or would that be further work?
Thank you.
Quoted 7 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 15 lines · Konrad Rzeszutek Wilk
Quoted 10 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
v6 follows the integration of this code into XenServer, and having the full suite of XenRT tests being run. Included in these tests are live migrations from 32bit toolstacks to 64bit toolstacks, using the python conversion script. Several corruption issues have been located and fixed, as well as many minor improvements.
Quoted 4 lines
In addition, performance tests have been performed. After finding an initial regression, the code uas been tweaked to use
writev()in preference towrite()which vastly reduces the number of system calls performed. The performance is now better than the legacy code for all sizes of VM.
Quoted 8 lines
Fantastic!
.. snip..
Quoted 1 line
The code is presented here for comment/query/critism.
My notes say: 'tmem and remus need work'. Is that addressed by this patchset or would that be further work?
Thank you.
tmem still completely outstanding.
remus is being worked on by Yang (which is fantastic from my point of view). I believe this is a PoC apparently working?
~Andrew
Hi Andrew,
Quoted 23 lines · Andrew Cooper
Quoted 22 lines · Konrad Rzeszutek Wilk
Quoted 10 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
v6 follows the integration of this code into XenServer, and having the full suite of XenRT tests being run. Included in these tests are live migrations from 32bit toolstacks to 64bit toolstacks, using the python conversion script. Several corruption issues have been located and fixed, as well as many minor improvements.
Quoted 4 lines
In addition, performance tests have been performed. After finding an initial regression, the code uas been tweaked to use
writev()in preference towrite()which vastly reduces the number of system calls performed. The performance is now better than the legacy code for all sizes of VM.Fantastic!
.. snip..
Quoted 1 line
The code is presented here for comment/query/critism.
My notes say: 'tmem and remus need work'. Is that addressed by this patchset or would that be further work?
Quoted 6 lines
Quoted 1 line
Thank you.
tmem still completely outstanding.
remus is being worked on by Yang (which is fantastic from my point of view). I believe this is a PoC apparently working?
Do you mean a PoC of remus support on migration v2? If so, yes, I will post a RFC patch on this.
BTW, will migration v2 be in Xen 4.5(both libxc and libxl side)? If it will be in Xen 4.5, will legacy migration be completely removed from 4.5 or both versions of migration will co-exist for a period?
Quoted 8 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Signature · 2 lines
Thanks, Yang.
Quoted 39 lines · Hongyang Yang
Hi Andrew,
Quoted 29 lines · Andrew Cooper
Quoted 28 lines · Konrad Rzeszutek Wilk
Quoted 14 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
v6 follows the integration of this code into XenServer, and having the full
suite of XenRT tests being run. Included in these tests are live migrations
from 32bit toolstacks to 64bit toolstacks, using the python conversion script.
Several corruption issues have been located and fixed, as well as many minor
improvements.Quoted 6 lines
In addition, performance tests have been performed. After finding an initial
regression, the code uas been tweaked to usewritev()in preference towrite()which vastly reduces the number of system calls performed. The
performance is now better than the legacy code for all sizes of VM.Fantastic!
.. snip..
Quoted 1 line
The code is presented here for comment/query/critism.
My notes say: 'tmem and remus need work'. Is that addressed by this patchset or would that be further work?
Quoted 6 lines
Quoted 1 line
Thank you.
tmem still completely outstanding.
remus is being worked on by Yang (which is fantastic from my point of view). I believe this is a PoC apparently working?
Quoted 6 lines
Do you mean a PoC of remus support on migration v2? If so, yes, I will post a RFC patch on this.
BTW, will migration v2 be in Xen 4.5(both libxc and libxl side)? If it will be in Xen 4.5, will legacy migration be completely removed from 4.5 or both versions of migration will co-exist for a period?
The two versions coexist in my dev branches alone, for debug and development ease. The plan is not to have two versions at the point at which the code gets committed.
As for acceptance, that is a little out of my hands. I think the libxc side is mostly ready (subject to ripping out the old code and infrastructure), but committing it as-is will break libxl. (Well - I suppose technically not, given the switch on the environment variable, but it has been indicated in the past that this hack is not going to be committed)
As for the libxl side of things, that's going slowly. As Wei is finding, there is quite a few bits which are currently in xl which need to be in libxl.
~Andrew
Quoted 58 lines · Andrew Cooper
Quoted 39 lines · Hongyang Yang
Hi Andrew,
Quoted 29 lines · Andrew Cooper
Quoted 28 lines · Konrad Rzeszutek Wilk
Quoted 14 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
v6 follows the integration of this code into XenServer, and having the full
suite of XenRT tests being run. Included in these tests are live migrations
from 32bit toolstacks to 64bit toolstacks, using the python conversion script.
Several corruption issues have been located and fixed, as well as many minor
improvements.Quoted 6 lines
In addition, performance tests have been performed. After finding an initial
regression, the code uas been tweaked to usewritev()in preference towrite()which vastly reduces the number of system calls performed. The
performance is now better than the legacy code for all sizes of VM.Fantastic!
.. snip..
Quoted 1 line
The code is presented here for comment/query/critism.
My notes say: 'tmem and remus need work'. Is that addressed by this patchset or would that be further work?
Quoted 6 lines
Quoted 1 line
Thank you.
tmem still completely outstanding.
remus is being worked on by Yang (which is fantastic from my point of view). I believe this is a PoC apparently working?
Quoted 6 lines
Do you mean a PoC of remus support on migration v2? If so, yes, I will post a RFC patch on this.
BTW, will migration v2 be in Xen 4.5(both libxc and libxl side)? If it will be in Xen 4.5, will legacy migration be completely removed from 4.5 or both versions of migration will co-exist for a period?
The two versions coexist in my dev branches alone, for debug and development ease. The plan is not to have two versions at the point at which the code gets committed.
As for acceptance, that is a little out of my hands. I think the libxc side is mostly ready (subject to ripping out the old code and infrastructure), but committing it as-is will break libxl. (Well - I suppose technically not, given the switch on the environment variable, but it has been indicated in the past that this hack is not going to be committed)
Quoted 3 lines
As for the libxl side of things, that's going slowly. As Wei is finding, there is quite a few bits which are currently in xl which need to be in libxl.
There are two months left before the feature freeze window.
It sounds to me that the 'libxc' parts, remus, tmem will be all nicely baked.
The 'libxl' is the one that is on the danger side. Do you have thoughts of what those 'few bits' are that could be identified?
Thank you.
Quoted 2 lines
~Andrew
Quoted 56 lines · Konrad Rzeszutek Wilk
Quoted 55 lines · Andrew Cooper
Quoted 35 lines · Hongyang Yang
Hi Andrew,
Quoted 32 lines · Andrew Cooper
Quoted 21 lines · Konrad Rzeszutek Wilk
Quoted 14 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
v6 follows the integration of this code into XenServer, and having the full
suite of XenRT tests being run. Included in these tests are live migrations
from 32bit toolstacks to 64bit toolstacks, using the python conversion script.
Several corruption issues have been located and fixed, as well as many minor
improvements.Quoted 6 lines
In addition, performance tests have been performed. After finding an initial
regression, the code uas been tweaked to usewritev()in preference towrite()which vastly reduces the number of system calls performed. The
performance is now better than the legacy code for all sizes of VM.Quoted 8 lines
Fantastic!
.. snip..
Quoted 1 line
The code is presented here for comment/query/critism.
My notes say: 'tmem and remus need work'. Is that addressed by this patchset or would that be further work?
Thank you.
tmem still completely outstanding.
Quoted 8 lines
Quoted 2 lines
remus is being worked on by Yang (which is fantastic from my point of view). I believe this is a PoC apparently working?
Do you mean a PoC of remus support on migration v2? If so, yes, I will post a RFC patch on this.
BTW, will migration v2 be in Xen 4.5(both libxc and libxl side)? If it will be in Xen 4.5, will legacy migration be completely removed from 4.5 or both versions of migration will co-exist for a period?
The two versions coexist in my dev branches alone, for debug and development ease. The plan is not to have two versions at the point at which the code gets committed.
As for acceptance, that is a little out of my hands. I think the libxc side is mostly ready (subject to ripping out the old code and infrastructure), but committing it as-is will break libxl. (Well - I suppose technically not, given the switch on the environment variable, but it has been indicated in the past that this hack is not going to be committed)
Quoted 7 lines
Quoted 3 lines
As for the libxl side of things, that's going slowly. As Wei is finding, there is quite a few bits which are currently in xl which need to be in libxl.
There are two months left before the feature freeze window.
It sounds to me that the 'libxc' parts, remus, tmem will be all nicely baked.
Nothing has been started on tmem, and from my point of view I am focusing on getting the libxl stuff in shape. One issue with the current tmem save/restore is that the libxc functions expect to get control of the fd, which doesn't fit with the new type/length/content layout.
Quoted 3 lines
The 'libxl' is the one that is on the danger side. Do you have thoughts of what those 'few bits' are that could be identified?
Still investigating. I am trying to look for the minimal fixes required to get libxl working, without interfering with Wei's work to move the .cfg data to json which also involves moving bits between xl and libxl.
~Andrew
Quoted 3 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
I had it in my mind that I had been through this iteration but it appears that I have not, sorry.
Given that so much time has passed is there any point in my doing it now, or may I as well wait for v7?
Ian.
Quoted 13 lines · Ian Campbell
Quoted 3 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
I had it in my mind that I had been through this iteration but it appears that I have not, sorry.
Given that so much time has passed is there any point in my doing it now, or may I as well wait for v7?
Ian.
I would be interested in your views about the python stuff (patch 2), but other than that, waiting for v7 is probably best.
~Andrew
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Andrew Cooper
Hello,
Presented here for review is v6 of the Migration Stream v2 work.
I had it in my mind that I had been through this iteration but it appears that I have not, sorry.
Quoted 8 lines
Quoted 6 lines
Given that so much time has passed is there any point in my doing it now, or may I as well wait for v7?
Ian.
I would be interested in your views about the python stuff (patch 2),
Done (although I didn't have much to say)
Quoted 1 line
but other than that, waiting for v7 is probably best.
OK, will do.
Ian.