From patchwork Mon Jan 27 14:34:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11352771 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 6DB23924 for ; Mon, 27 Jan 2020 14:41:53 +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 4A9E820720 for ; Mon, 27 Jan 2020 14:41:53 +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="QNaJsMNi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A9E820720 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 1iw5ZW-0003FH-KY; Mon, 27 Jan 2020 14:41:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iw5ZV-0003EQ-21 for xen-devel@lists.xenproject.org; Mon, 27 Jan 2020 14:41:01 +0000 X-Inumbo-ID: 08733c9e-4113-11ea-aecd-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 08733c9e-4113-11ea-aecd-bc764e2007e4; Mon, 27 Jan 2020 14:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1580136059; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Lxptjlj048jFo1TZ9LyVIlXTZTWDMEbkHr8vGwFVWNg=; b=QNaJsMNitgmcH7Ot+yOOrBXZXgz9Jc0in8oZxsVpqHocT4jzHaszVlLE jEEcp9nNFwrzlxCGDH0TiORcp26aU0++6IG9c1s7beLtYm6QTZjVCefE6 +SuELYQ/c4YRmjY1fG+4rRWY+Xm53IO3bnYkFN36hHxETc4c/lpaQUEAi s=; Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: oXzaRxdCI02X1cK9/EbsP11aVANGkgCdNa7QuodbgXb5G2sOj4YYKeLtKt/3NYGEoerEfMfzGg rqWqpOc68f35SPndDt2gKLaul0kFNWxbK+K6yjt40ncg6PPerONjD0qkABil9SHkZOWz7HfVF7 VXqIp+58GvUOcNta9gbywVYAPaC+I0k2HVj699etbbcVj7IwtibDFVihUZs9YReuiI6w50n/D/ 4QKzUOw+DcKmG9qt4eVXPQJ9HlP//RsJnOXBBpdFF740tDoNG59isTry0m8Q5RR3L9VB8j7WGs lBM= X-SBRS: 2.7 X-MesageID: 11860148 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,370,1574139600"; d="scan'208";a="11860148" From: Andrew Cooper To: Xen-devel Date: Mon, 27 Jan 2020 14:34:43 +0000 Message-ID: <20200127143444.25538-17-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200127143444.25538-1-andrew.cooper3@citrix.com> References: <20200127143444.25538-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 16/17] tools/libxc: Restore CPUID/MSR data found in the migration stream 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: Andrew Cooper , Ian Jackson , Wei Liu , =?utf-8?q?Roger?= =?utf-8?q?_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" With all other pieces in place, it is now safe to restore the CPUID and MSR data in the migration stream, rather than discarding them and using the higher level toolstacks compatibility logic. While this is a small patch, it has large implications for migrated/resumed domains. Most obviously, the CPU family/model/stepping data, cache/tlb/etc. will no longer change behind the guests back. Another change is the interpretation of the Xend cpuid strings. The 'k' option is not a sensible thing to have ever supported, and 's' is how how the stream will end up behaving. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Ian Jackson CC: Wei Liu --- tools/libxc/xc_cpuid_x86.c | 8 ++++---- tools/libxc/xc_sr_common_x86.c | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index ac38c1406e..c78d00bbc3 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -291,10 +291,9 @@ int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid, * '0' -> force to 0 * 'x' -> we don't care (use default) * 'k' -> pass through host value - * 's' -> pass through the first time and then keep the same value - * across save/restore and migration. + * 's' -> legacy alias for 'k' * - * For 's' and 'x' the configuration is overwritten with the value applied. + * In all cases, the returned string consists of just '0' and '1'. */ int xc_cpuid_set( xc_interface *xch, uint32_t domid, const unsigned int *input, @@ -420,7 +419,8 @@ int xc_cpuid_set( clear_feature(31 - j, regs[i]); config_transformed[i][j] = config[i][j]; - if ( config[i][j] == 's' ) + /* All non 0/1 values get overwritten. */ + if ( (config[i][j] & ~1) != '0' ) config_transformed[i][j] = '0' + val; } } diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c index a849891634..77ea044a74 100644 --- a/tools/libxc/xc_sr_common_x86.c +++ b/tools/libxc/xc_sr_common_x86.c @@ -134,8 +134,30 @@ int handle_x86_msr_policy(struct xc_sr_context *ctx, struct xc_sr_record *rec) 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; + xc_interface *xch = ctx->xch; + uint32_t nr_leaves = 0, nr_msrs = 0; + uint32_t err_l = ~0, err_s = ~0, err_m = ~0; + + if ( ctx->x86.restore.cpuid.ptr ) + nr_leaves = ctx->x86.restore.cpuid.size / sizeof(xen_cpuid_leaf_t); + else + *missing |= XGR_SDD_MISSING_CPUID; + + if ( ctx->x86.restore.msr.ptr ) + nr_msrs = ctx->x86.restore.msr.size / sizeof(xen_msr_entry_t); + else + *missing |= XGR_SDD_MISSING_MSR; + + if ( (nr_leaves || nr_msrs) && + xc_set_domain_cpu_policy(xch, ctx->domid, + nr_leaves, ctx->x86.restore.cpuid.ptr, + nr_msrs, ctx->x86.restore.msr.ptr, + &err_l, &err_s, &err_m) ) + { + PERROR("Failed to set CPUID policy: leaf %08x, subleaf %08x, msr %08x", + err_l, err_s, err_m); + return -1; + } return 0; }