[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v5 RFC 11/14] tools/libxc: x86 HVM save code
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Signed-off-by: Frediano Ziglio <frediano.ziglio@xxxxxxxxxx> Signed-off-by: David Vrabel <david.vrabel@xxxxxxxxxx> --- tools/libxc/saverestore/common.h | 1 + tools/libxc/saverestore/save_x86_hvm.c | 223 ++++++++++++++++++++++++++++++++ 2 files changed, 224 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 7ba9c4f..9e70ed6 100644 --- a/tools/libxc/saverestore/common.h +++ b/tools/libxc/saverestore/common.h @@ -248,6 +248,7 @@ extern struct common_ops common_ops_x86_pv; extern struct common_ops common_ops_x86_hvm; extern struct save_ops save_ops_x86_pv; +extern struct save_ops save_ops_x86_hvm; extern struct 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..6548eae --- /dev/null +++ b/tools/libxc/saverestore/save_x86_hvm.c @@ -0,0 +1,223 @@ +#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 context *ctx) +{ + xc_interface *xch = ctx->xch; + unsigned long hvm_buf_size; + int rc; + struct 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 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, + }; + + xc_interface *xch = ctx->xch; + struct rec_hvm_params_entry entries[ARRAY_SIZE(params)]; + struct rec_hvm_params hdr = { + .count = 0, + }; + struct 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 context *ctx) +{ + xc_interface *xch = ctx->xch; + struct 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 int x86_hvm_normalise_page(struct context *ctx, xen_pfn_t type, void **page) +{ + /* no-op */ + return 0; +} + +static int x86_hvm_setup(struct context *ctx) +{ + /* no-op */ + return 0; +} + +static int x86_hvm_start_of_stream(struct context *ctx) +{ + /* no-op */ + return 0; +} + +static int x86_hvm_end_of_stream(struct 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 context *ctx) +{ + /* no-op */ + return 0; +} + +struct save_ops save_ops_x86_hvm = +{ + .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 |