[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [Patch v6 10/13] tools/libxc: x86 HVM save code
Save 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. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- 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 diff --git a/tools/libxc/saverestore/common.h b/tools/libxc/saverestore/common.h index 7536b08..8d125f9 100644 --- a/tools/libxc/saverestore/common.h +++ b/tools/libxc/saverestore/common.h @@ -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; diff --git a/tools/libxc/saverestore/save_x86_hvm.c b/tools/libxc/saverestore/save_x86_hvm.c new file mode 100644 index 0000000..5c8052f --- /dev/null +++ b/tools/libxc/saverestore/save_x86_hvm.c @@ -0,0 +1,255 @@ +#include <assert.h> + +#include "common_x86.h" + +#include <xen/hvm/params.h> + +/* + * Query for the HVM context and write an HVM_CONTEXT record into the stream. + */ +static int write_hvm_context(struct xc_sr_context *ctx) +{ + xc_interface *xch = ctx->xch; + unsigned long hvm_buf_size; + int rc; + struct xc_sr_record hvm_rec = + { + .type = REC_TYPE_HVM_CONTEXT, + }; + + hvm_buf_size = xc_domain_hvm_getcontext(xch, ctx->domid, 0, 0); + if ( hvm_buf_size == -1 ) + { + PERROR("Couldn't get HVM context size from Xen"); + rc = -1; + goto out; + } + + hvm_rec.data = malloc(hvm_buf_size); + if ( !hvm_rec.data ) + { + PERROR("Couldn't allocate memory"); + rc = -1; + goto out; + } + + hvm_rec.length = xc_domain_hvm_getcontext(xch, ctx->domid, + hvm_rec.data, hvm_buf_size); + if ( hvm_rec.length < 0 ) + { + PERROR("HVM:Could not get hvm buffer"); + rc = -1; + goto out; + } + + rc = write_record(ctx, &hvm_rec); + if ( rc < 0 ) + { + PERROR("error write HVM_CONTEXT record"); + goto out; + } + + out: + free(hvm_rec.data); + return rc; +} + +/* + * Query for a range of HVM parameters and write an HVM_PARAMS record into the + * stream. + */ +static int write_hvm_params(struct xc_sr_context *ctx) +{ + static const unsigned int params[] = { + HVM_PARAM_STORE_PFN, + HVM_PARAM_IOREQ_PFN, + HVM_PARAM_BUFIOREQ_PFN, + HVM_PARAM_PAGING_RING_PFN, + HVM_PARAM_ACCESS_RING_PFN, + HVM_PARAM_SHARING_RING_PFN, + HVM_PARAM_VM86_TSS, + HVM_PARAM_CONSOLE_PFN, + HVM_PARAM_ACPI_IOPORTS_LOCATION, + HVM_PARAM_VIRIDIAN, + HVM_PARAM_IDENT_PT, + HVM_PARAM_PAE_ENABLED, + HVM_PARAM_VM_GENERATION_ID_ADDR, + HVM_PARAM_IOREQ_SERVER_PFN, + HVM_PARAM_NR_IOREQ_SERVER_PAGES, + }; + + xc_interface *xch = ctx->xch; + struct xc_sr_rec_hvm_params_entry entries[ARRAY_SIZE(params)]; + struct xc_sr_rec_hvm_params hdr = { + .count = 0, + }; + struct xc_sr_record rec = { + .type = REC_TYPE_HVM_PARAMS, + .length = sizeof(hdr), + .data = &hdr, + }; + unsigned int i; + int rc; + + for ( i = 0; i < ARRAY_SIZE(params); i++ ) + { + uint32_t index = params[i]; + uint64_t value; + + rc = xc_get_hvm_param(xch, ctx->domid, index, (unsigned long *)&value); + if ( rc ) + { + /* Gross XenServer hack. Consider HVM_PARAM_CONSOLE_PFN failure + * nonfatal. This is related to the fact it is impossible to + * distinguish "no console" from a console at pfn/evtchn 0. + * + * TODO - find a compatible way to fix this. + */ + if ( index == HVM_PARAM_CONSOLE_PFN ) + continue; + + PERROR("Failed to get HVMPARAM at index %u", index); + return rc; + } + + if ( value != 0 ) + { + entries[hdr.count].index = index; + entries[hdr.count].value = value; + hdr.count++; + } + } + + rc = write_split_record(ctx, &rec, entries, hdr.count * sizeof(*entries)); + if ( rc ) + PERROR("Failed to write HVM_PARAMS record"); + + return rc; +} + +/* TODO - remove. */ +static int write_toolstack(struct xc_sr_context *ctx) +{ + xc_interface *xch = ctx->xch; + struct xc_sr_record rec = { + .type = REC_TYPE_TOOLSTACK, + .length = 0, + }; + uint8_t *buf; + uint32_t len; + int rc; + + if ( !ctx->save.callbacks || !ctx->save.callbacks->toolstack_save ) + return 0; + + if ( ctx->save.callbacks->toolstack_save(ctx->domid, &buf, &len, ctx->save.callbacks->data) < 0 ) + { + PERROR("Error calling toolstack_save"); + return -1; + } + + rc = write_split_record(ctx, &rec, buf, len); + if ( rc < 0 ) + PERROR("Error writing TOOLSTACK record"); + free(buf); + return rc; +} + +static xen_pfn_t x86_hvm_pfn_to_gfn(const struct xc_sr_context *ctx, xen_pfn_t pfn) +{ + /* identify map */ + return pfn; +} + +static int x86_hvm_normalise_page(struct xc_sr_context *ctx, xen_pfn_t type, void **page) +{ + /* no-op */ + return 0; +} + +static int x86_hvm_setup(struct xc_sr_context *ctx) +{ + xc_interface *xch = ctx->xch; + + if ( !ctx->save.callbacks->switch_qemu_logdirty ) + { + ERROR("No switch_qemu_logdirty callback provided"); + errno = EINVAL; + return -1; + } + + if ( ctx->save.callbacks->switch_qemu_logdirty( + ctx->domid, 1, ctx->save.callbacks->data) ) + { + PERROR("Couldn't enable qemu log-dirty mode"); + return -1; + } + + return 0; +} + +static int x86_hvm_start_of_stream(struct xc_sr_context *ctx) +{ + /* no-op */ + return 0; +} + +static int x86_hvm_end_of_stream(struct xc_sr_context *ctx) +{ + int rc; + + rc = write_tsc_info(ctx); + if ( rc ) + return rc; + + /* TODO - remove. */ + rc = write_toolstack(ctx); + if ( rc ) + return rc; + + /* Write the HVM_CONTEXT record. */ + rc = write_hvm_context(ctx); + if ( rc ) + return rc; + + /* Write HVM_PARAMS record contains applicable HVM params. */ + rc = write_hvm_params(ctx); + if ( rc ) + return rc; + + return rc; +} + +static int x86_hvm_cleanup(struct xc_sr_context *ctx) +{ + xc_interface *xch = ctx->xch; + + if ( ctx->save.callbacks->switch_qemu_logdirty( + ctx->domid, 0, ctx->save.callbacks->data) ) + { + PERROR("Couldn't disable qemu log-dirty mode"); + return -1; + } + + return 0; +} + +struct xc_sr_save_ops save_ops_x86_hvm = +{ + .pfn_to_gfn = x86_hvm_pfn_to_gfn, + .normalise_page = x86_hvm_normalise_page, + .setup = x86_hvm_setup, + .start_of_stream = x86_hvm_start_of_stream, + .end_of_stream = x86_hvm_end_of_stream, + .cleanup = x86_hvm_cleanup, +}; + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |