From patchwork Mon Feb 24 16:50:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11401029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 404AD13A4 for ; Mon, 24 Feb 2020 16:52:03 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0E27120836 for ; Mon, 24 Feb 2020 16:52:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="TUjKH+7G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E27120836 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6Gwa-0006rG-VM; Mon, 24 Feb 2020 16:50:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6GwZ-0006rB-Og for xen-devel@lists.xenproject.org; Mon, 24 Feb 2020 16:50:55 +0000 X-Inumbo-ID: d25118ce-5725-11ea-a490-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d25118ce-5725-11ea-a490-bc764e2007e4; Mon, 24 Feb 2020 16:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582563055; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=1S2IXtbQ034/bxIbXGWBO4jQIaUjXNQKe10O8TUN1iE=; b=TUjKH+7G5OYZEKO21O8wWk8piv7JtCctr8wF1F4cjXIdmJvGUzaOaONf RoBSY4gLA/1FQUar10LN9cGsz+eFQAGtGvCYGr2mLthdRlEP8P2UVag+k o5Pf+FqxJCsnFgX3vFeGaYwqhRgsZuMSRRI48dfbkxDqIfC3XJ6HyXSyU w=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: pCb/IROBQHAUTe7KfXffVgg6tqxRk5VGG58i89NIrSfV0O2blFQ0ePf/EDxTbdW2PzM7ZkCEd/ MsZGVlLiVNkWgTqUPJgdwADPUqqndi9x3DgIy8b6HeOYPg/iQ/KtDSjOWs5Xv/PmE4OjbycHck 12JGUNp88EL0ouMLJ4S3Y586e6A2MUlUpnIgGBf0veBzDBWUZ7leaTleYXe3bAa/HVtmqiNlbU 0rxue1SO/gf9HM956IEtuFnGQDzVWUvD/KsfSBDgedh6girZCuTPkE2mfe9C8UJlJhKopumlPx XzM= X-SBRS: 2.7 X-MesageID: 12924457 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,480,1574139600"; d="scan'208";a="12924457" From: Andrew Cooper To: Xen-devel Date: Mon, 24 Feb 2020 16:50:50 +0000 Message-ID: <20200224165050.32287-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200127143444.25538-16-andrew.cooper3@citrix.com> References: <20200127143444.25538-16-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2.1 15/17] tools/libx[cl]: Plumb 'missing' through static_data_done() up into libxl X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Andrew Cooper , Wei Liu , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Pre Xen-4.14 streams will not contain any CPUID/MSR information. There is nothing libxc can do about this, and will have to rely on the higher level toolstack to provide backwards compatibility. To facilitate this, extend the static_data_done() callback, highlighting the missing information, and modify libxl to use it. At the libxc level, this requires an arch-specific hook which, for now, always reports CPUID and MSR as missing. This will be adjusted in a later change. No overall functional change - this is just plumbing. Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu CC: Anthony PERARD v2: * Split/rearrange from v1 * Don't re-evalute 'k' on migrate v2.1: * Rebase over libxl__cpuid_legacy() changes --- tools/libxc/include/xenguest.h | 12 ++++++++++-- tools/libxc/xc_sr_common.h | 9 +++++++++ tools/libxc/xc_sr_common_x86.c | 8 ++++++++ tools/libxc/xc_sr_common_x86.h | 5 +++++ tools/libxc/xc_sr_restore.c | 7 ++++++- tools/libxc/xc_sr_restore_x86_hvm.c | 1 + tools/libxc/xc_sr_restore_x86_pv.c | 1 + tools/libxl/libxl_create.c | 13 +++++++++++-- tools/libxl/libxl_save_msgs_gen.pl | 2 +- 9 files changed, 52 insertions(+), 6 deletions(-) diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h index b4df8d0ffe..7a12d21ff2 100644 --- a/tools/libxc/include/xenguest.h +++ b/tools/libxc/include/xenguest.h @@ -139,8 +139,16 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, /* callbacks provided by xc_domain_restore */ struct restore_callbacks { - /* Called once the STATIC_DATA_END record has been received/inferred. */ - int (*static_data_done)(void *data); + /* + * Called once the STATIC_DATA_END record has been received/inferred. + * + * For compatibility with older streams, provides a list of static data + * expected to be found in the stream, which was missing. A higher level + * toolstack is responsible for providing any necessary compatibiltiy. + */ +#define XGR_SDD_MISSING_CPUID (1 << 0) +#define XGR_SDD_MISSING_MSR (1 << 1) + int (*static_data_done)(unsigned int missing, void *data); /* Called after a new checkpoint to suspend the guest. */ int (*suspend)(void *data); diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h index 7742260690..f3bdea8006 100644 --- a/tools/libxc/xc_sr_common.h +++ b/tools/libxc/xc_sr_common.h @@ -159,6 +159,15 @@ struct xc_sr_restore_ops int (*process_record)(struct xc_sr_context *ctx, struct xc_sr_record *rec); /** + * Perform any actions required after the static data has arrived. Called + * when the STATIC_DATA_COMPLETE record has been recieved/inferred. + * 'missing' should be filled in for any data item the higher level + * toolstack needs to provide compatiblity for. + */ + int (*static_data_complete)(struct xc_sr_context *ctx, + unsigned int *missing); + + /** * Perform any actions required after the stream has been finished. Called * after the END record has been received. */ diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c index 6267655dab..a849891634 100644 --- a/tools/libxc/xc_sr_common_x86.c +++ b/tools/libxc/xc_sr_common_x86.c @@ -132,6 +132,14 @@ int handle_x86_msr_policy(struct xc_sr_context *ctx, struct xc_sr_record *rec) return rc; } +int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing) +{ + /* TODO: Become conditional on there being no data in the stream. */ + *missing = XGR_SDD_MISSING_MSR | XGR_SDD_MISSING_CPUID; + + return 0; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xc_sr_common_x86.h b/tools/libxc/xc_sr_common_x86.h index d1050981dd..e08d81e0e7 100644 --- a/tools/libxc/xc_sr_common_x86.h +++ b/tools/libxc/xc_sr_common_x86.h @@ -34,6 +34,11 @@ int handle_x86_cpuid_policy(struct xc_sr_context *ctx, int handle_x86_msr_policy(struct xc_sr_context *ctx, struct xc_sr_record *rec); +/* + * Perform common x86 actions required after the static data has arrived. + */ +int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing); + #endif /* * Local variables: diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c index bb94cd879d..bc811e6e3a 100644 --- a/tools/libxc/xc_sr_restore.c +++ b/tools/libxc/xc_sr_restore.c @@ -659,6 +659,7 @@ static int buffer_record(struct xc_sr_context *ctx, struct xc_sr_record *rec) int handle_static_data_end(struct xc_sr_context *ctx) { xc_interface *xch = ctx->xch; + unsigned int missing = 0; int rc = 0; if ( ctx->restore.seen_static_data_end ) @@ -669,9 +670,13 @@ int handle_static_data_end(struct xc_sr_context *ctx) ctx->restore.seen_static_data_end = true; + rc = ctx->restore.ops.static_data_complete(ctx, &missing); + if ( rc ) + return rc; + if ( ctx->restore.callbacks->static_data_done && (rc = ctx->restore.callbacks->static_data_done( - ctx->restore.callbacks->data) != 0) ) + missing, ctx->restore.callbacks->data) != 0) ) ERROR("static_data_done() callback failed: %d\n", rc); return rc; diff --git a/tools/libxc/xc_sr_restore_x86_hvm.c b/tools/libxc/xc_sr_restore_x86_hvm.c index 1704d524b4..a77624cc9d 100644 --- a/tools/libxc/xc_sr_restore_x86_hvm.c +++ b/tools/libxc/xc_sr_restore_x86_hvm.c @@ -258,6 +258,7 @@ struct xc_sr_restore_ops restore_ops_x86_hvm = .localise_page = x86_hvm_localise_page, .setup = x86_hvm_setup, .process_record = x86_hvm_process_record, + .static_data_complete = x86_static_data_complete, .stream_complete = x86_hvm_stream_complete, .cleanup = x86_hvm_cleanup, }; diff --git a/tools/libxc/xc_sr_restore_x86_pv.c b/tools/libxc/xc_sr_restore_x86_pv.c index a3d85d517d..d086271efb 100644 --- a/tools/libxc/xc_sr_restore_x86_pv.c +++ b/tools/libxc/xc_sr_restore_x86_pv.c @@ -1194,6 +1194,7 @@ struct xc_sr_restore_ops restore_ops_x86_pv = .localise_page = x86_pv_localise_page, .setup = x86_pv_setup, .process_record = x86_pv_process_record, + .static_data_complete = x86_static_data_complete, .stream_complete = x86_pv_stream_complete, .cleanup = x86_pv_cleanup, }; diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 2c1cbdfb2a..ad28c527ee 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1308,7 +1308,8 @@ static void libxl__colo_restore_setup_done(libxl__egc *egc, libxl__stream_read_start(egc, &dcs->srs); } -int libxl__srm_callout_callback_static_data_done(void *user) +int libxl__srm_callout_callback_static_data_done(unsigned int missing, + void *user) { libxl__save_helper_state *shs = user; libxl__domain_create_state *dcs = shs->caller_state; @@ -1318,7 +1319,15 @@ int libxl__srm_callout_callback_static_data_done(void *user) libxl_domain_config *d_config = dcs->guest_config; libxl_domain_build_info *info = &d_config->b_info; - libxl__cpuid_legacy(ctx, dcs->guest_domid, info); + /* + * CPUID/MSR information is not present in pre Xen-4.14 streams. + * + * Libxl used to always regenerate the CPUID policy from first principles + * on migrate. Continue to do so for backwards compatibility when the + * stream doesn't contain any CPUID data. + */ + if (missing & XGR_SDD_MISSING_CPUID) + libxl__cpuid_legacy(ctx, dcs->guest_domid, info); return 0; } diff --git a/tools/libxl/libxl_save_msgs_gen.pl b/tools/libxl/libxl_save_msgs_gen.pl index 93dc252370..5bfbd4fd10 100755 --- a/tools/libxl/libxl_save_msgs_gen.pl +++ b/tools/libxl/libxl_save_msgs_gen.pl @@ -29,7 +29,7 @@ our @msgs = ( [ 'srcxA', "wait_checkpoint", [] ], [ 'scxA', "switch_qemu_logdirty", [qw(uint32_t domid unsigned enable)] ], - [ 'rcxW', "static_data_done", [] ], + [ 'rcxW', "static_data_done", [qw(unsigned missing)] ], [ 'rcx', "restore_results", ['xen_pfn_t', 'store_gfn', 'xen_pfn_t', 'console_gfn'] ], [ 'srW', "complete", [qw(int retval