aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc
diff options
context:
space:
mode:
authorPaul Durrant <paul.durrant@citrix.com>2011-12-16 14:54:14 +0000
committerPaul Durrant <paul.durrant@citrix.com>2011-12-16 14:54:14 +0000
commit8f76fc6c983e3bf7c8c32fae2c7264f718e2b467 (patch)
treea279f798e76580f86bffe3f632a0eb276859665d /tools/libxc
parentbe9b274df12d03fe2366fdbb58a37f537c3d2ff1 (diff)
downloadxen-8f76fc6c983e3bf7c8c32fae2c7264f718e2b467.tar.gz
xen-8f76fc6c983e3bf7c8c32fae2c7264f718e2b467.tar.bz2
xen-8f76fc6c983e3bf7c8c32fae2c7264f718e2b467.zip
tools: VM generation ID save/restore and migrate.
Add code to track the address of the VM generation ID buffer across a save/restore or migrate, and increment it as necessary. The address of the buffer is written into xenstore by hvmloader at boot time. It must be read from xenstore by the caller of xc_domain_save() and then written back again by the caller of xc_domain_restore(). Note that the changes to xc_save.c and xc_restore.c are merely sufficient for them to build. Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/libxc')
-rw-r--r--tools/libxc/ia64/xc_ia64_linux_restore.c4
-rw-r--r--tools/libxc/ia64/xc_ia64_linux_save.c3
-rw-r--r--tools/libxc/xc_domain_restore.c49
-rw-r--r--tools/libxc/xc_domain_save.c13
-rw-r--r--tools/libxc/xenguest.h9
-rw-r--r--tools/libxc/xg_save_restore.h1
6 files changed, 73 insertions, 6 deletions
diff --git a/tools/libxc/ia64/xc_ia64_linux_restore.c b/tools/libxc/ia64/xc_ia64_linux_restore.c
index 5a915aa993..d199cbfac4 100644
--- a/tools/libxc/ia64/xc_ia64_linux_restore.c
+++ b/tools/libxc/ia64/xc_ia64_linux_restore.c
@@ -548,7 +548,9 @@ int
xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
unsigned int store_evtchn, unsigned long *store_mfn,
unsigned int console_evtchn, unsigned long *console_mfn,
- unsigned int hvm, unsigned int pae, int superpages)
+ unsigned int hvm, unsigned int pae, int superpages,
+ int no_incr_generationid,
+ unsigned long *vm_generationid_addr)
{
DECLARE_DOMCTL;
int rc = 1;
diff --git a/tools/libxc/ia64/xc_ia64_linux_save.c b/tools/libxc/ia64/xc_ia64_linux_save.c
index 52b37f1017..5bb988cbd7 100644
--- a/tools/libxc/ia64/xc_ia64_linux_save.c
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c
@@ -382,7 +382,8 @@ out:
int
xc_domain_save(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 save_callbacks* callbacks, int hvm,
+ unsigned long vm_generationid_addr)
{
DECLARE_DOMCTL;
xc_dominfo_t info;
diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_restore.c
index 14451d1a59..3fda6f8c68 100644
--- a/tools/libxc/xc_domain_restore.c
+++ b/tools/libxc/xc_domain_restore.c
@@ -681,6 +681,7 @@ typedef struct {
uint64_t console_pfn;
uint64_t acpi_ioport_location;
uint64_t viridian;
+ uint64_t vm_generationid_addr;
} pagebuf_t;
static int pagebuf_init(pagebuf_t* buf)
@@ -860,6 +861,17 @@ static int pagebuf_get_one(xc_interface *xch, struct restore_ctx *ctx,
}
return compbuf_size;
+ case XC_SAVE_ID_HVM_GENERATION_ID_ADDR:
+ /* Skip padding 4 bytes then read the generation id buffer location. */
+ if ( RDEXACT(fd, &buf->vm_generationid_addr, sizeof(uint32_t)) ||
+ RDEXACT(fd, &buf->vm_generationid_addr, sizeof(uint64_t)) )
+ {
+ PERROR("error read the generation id buffer location");
+ return -1;
+ }
+ DPRINTF("read generation id buffer address");
+ return pagebuf_get_one(xch, ctx, buf, fd, dom);
+
default:
if ( (count > MAX_BATCH_SIZE) || (count < 0) ) {
ERROR("Max batch size exceeded (%d). Giving up.", count);
@@ -1248,7 +1260,9 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
unsigned int store_evtchn, unsigned long *store_mfn,
unsigned int console_evtchn, unsigned long *console_mfn,
- unsigned int hvm, unsigned int pae, int superpages)
+ unsigned int hvm, unsigned int pae, int superpages,
+ int no_incr_generationid,
+ unsigned long *vm_generationid_addr)
{
DECLARE_DOMCTL;
int rc = 1, frc, i, j, n, m, pae_extended_cr3 = 0, ext_vcpucontext = 0;
@@ -1449,6 +1463,39 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
xc_set_hvm_param(xch, dom, HVM_PARAM_VM86_TSS, pagebuf.vm86_tss);
if ( pagebuf.console_pfn )
console_pfn = pagebuf.console_pfn;
+ if ( pagebuf.vm_generationid_addr ) {
+ if ( !no_incr_generationid ) {
+ unsigned int offset;
+ unsigned char *buf;
+ unsigned long long generationid;
+
+ /*
+ * Map the VM generation id buffer and inject the new value.
+ */
+
+ pfn = pagebuf.vm_generationid_addr >> PAGE_SHIFT;
+ offset = pagebuf.vm_generationid_addr & (PAGE_SIZE - 1);
+
+ if ( (pfn >= dinfo->p2m_size) ||
+ (pfn_type[pfn] != XEN_DOMCTL_PFINFO_NOTAB) )
+ {
+ ERROR("generation id buffer frame is bad");
+ goto out;
+ }
+
+ mfn = ctx->p2m[pfn];
+ buf = xc_map_foreign_range(xch, dom, PAGE_SIZE,
+ PROT_READ | PROT_WRITE, mfn);
+
+ generationid = *(unsigned long long *)(buf + offset);
+ *(unsigned long long *)(buf + offset) = generationid + 1;
+
+ munmap(buf, PAGE_SIZE);
+ }
+
+ *vm_generationid_addr = pagebuf.vm_generationid_addr;
+ }
+
break; /* our work here is done */
}
diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c
index a6bb89475f..f473dd7c5c 100644
--- a/tools/libxc/xc_domain_save.c
+++ b/tools/libxc/xc_domain_save.c
@@ -804,7 +804,8 @@ static int save_tsc_info(xc_interface *xch, uint32_t dom, int io_fd)
int xc_domain_save(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 save_callbacks* callbacks, int hvm,
+ unsigned long vm_generationid_addr)
{
xc_dominfo_t info;
DECLARE_DOMCTL;
@@ -1616,6 +1617,16 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
uint64_t data;
} chunk = { 0, };
+ chunk.id = XC_SAVE_ID_HVM_GENERATION_ID_ADDR;
+ chunk.data = vm_generationid_addr;
+
+ if ( (chunk.data != 0) &&
+ wrexact(io_fd, &chunk, sizeof(chunk)) )
+ {
+ PERROR("Error when writing the generation id buffer location for guest");
+ goto out;
+ }
+
chunk.id = XC_SAVE_ID_HVM_IDENT_PT;
chunk.data = 0;
xc_get_hvm_param(xch, dom, HVM_PARAM_IDENT_PT,
diff --git a/tools/libxc/xenguest.h b/tools/libxc/xenguest.h
index 4475ee92ee..60263709ce 100644
--- a/tools/libxc/xenguest.h
+++ b/tools/libxc/xenguest.h
@@ -58,7 +58,8 @@ struct save_callbacks {
*/
int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
- struct save_callbacks* callbacks, int hvm);
+ struct save_callbacks* callbacks, int hvm,
+ unsigned long vm_generationid_addr);
/**
@@ -72,12 +73,16 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
* @parm hvm non-zero if this is a HVM restore
* @parm pae non-zero if this HVM domain has PAE support enabled
* @parm superpages non-zero to allocate guest memory with superpages
+ * @parm no_incr_generationid non-zero if generation id is NOT to be incremented
+ * @parm vm_generationid_addr returned with the address of the generation id buffer
* @return 0 on success, -1 on failure
*/
int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
unsigned int store_evtchn, unsigned long *store_mfn,
unsigned int console_evtchn, unsigned long *console_mfn,
- unsigned int hvm, unsigned int pae, int superpages);
+ unsigned int hvm, unsigned int pae, int superpages,
+ int no_incr_generationid,
+ unsigned long *vm_generationid_addr);
/**
* xc_domain_restore writes a file to disk that contains the device
* model saved state.
diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h
index c5e0743dcf..6286b6814a 100644
--- a/tools/libxc/xg_save_restore.h
+++ b/tools/libxc/xg_save_restore.h
@@ -253,6 +253,7 @@
#define XC_SAVE_ID_HVM_VIRIDIAN -11
#define XC_SAVE_ID_COMPRESSED_DATA -12 /* Marker to indicate arrival of compressed data */
#define XC_SAVE_ID_ENABLE_COMPRESSION -13 /* Marker to enable compression logic at receiver side */
+#define XC_SAVE_ID_HVM_GENERATION_ID_ADDR -14
/*
** We process save/restore/migrate in batches of pages; the below