From patchwork Tue Dec 24 15:19:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11309531 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 4E56313A4 for ; Tue, 24 Dec 2019 15:41:58 +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 1EEC820643 for ; Tue, 24 Dec 2019 15:41:58 +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="W2qzTils" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EEC820643 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 1ijmIn-0003dW-Ct; Tue, 24 Dec 2019 15:40:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ijmIm-0003dQ-3S for xen-devel@lists.xenproject.org; Tue, 24 Dec 2019 15:40:52 +0000 X-Inumbo-ID: be703bca-2663-11ea-88e7-bc764e2007e4 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id be703bca-2663-11ea-88e7-bc764e2007e4; Tue, 24 Dec 2019 15:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1577202044; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=4fBapI9z/Ms+ixWeUrkyCN8fJrLRsHqVO9a2fRn+69o=; b=W2qzTilsVB3tY4QCsI4OANP2Env+btfBLp7ZVKONQMEiYdS7U7cnBf7R XwVV+qafhEsjof6EXeH0K2Q8z5QNwOEIm96oNeVuZbHyLYP0aycB9x3Ap IFtWqckuvyS+dRg+w1TLPgVi03ha7hWytq+fdXSW8GIt+Nrkm9fPXxpbG 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: lhpDStWcvWfCljV8jH97FFhZwk42l0YOizboElBhUSSaoulaJ60VPQrSnVxal9gm6CQfc1W4t3 HhRieveMpjpiXGxGY7WuBg6FawKspkW9ZMyCFqn4YnOCEczEr23cLjCmHvrNyAggFGqhSROJsG HymPF4LHIiL8GVS2qA6xnO4XfSijGmGCELrv3EmUHmWxx1hc+cedzSJkSJxb2XcRl8lBiPWsWZ DHlwgoSWlysEwpubJwzEjVyROICMsF7805byyADjRYLB65f2OH0O0lO2is85IBVOHttBxYO17B OiY= X-SBRS: 2.7 X-MesageID: 10129278 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.69,351,1571716800"; d="scan'208";a="10129278" From: Andrew Cooper To: Xen-devel Date: Tue, 24 Dec 2019 15:19:31 +0000 Message-ID: <20191224151932.6304-12-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191224151932.6304-1-andrew.cooper3@citrix.com> References: <20191224151932.6304-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 11/12] libxc/restore: Handle X86_{CPUID, MSR}_DATA records 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 , Wei Liu , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" For now, the data are just stashed, and discarded at the end. This will be addressed when the TODO in x86_static_data_complete() is addressed. No practical change to behaviour - this is all plumbing work. Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu --- tools/libxc/xc_sr_common.h | 10 ++++++++++ tools/libxc/xc_sr_common_x86.c | 40 +++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_common_x86.h | 14 +++++++++++++ tools/libxc/xc_sr_restore_x86_hvm.c | 9 +++++++++ tools/libxc/xc_sr_restore_x86_pv.c | 9 +++++++++ 5 files changed, 82 insertions(+) diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h index 3f52ef7d53..337c746e17 100644 --- a/tools/libxc/xc_sr_common.h +++ b/tools/libxc/xc_sr_common.h @@ -308,6 +308,16 @@ struct xc_sr_context { struct /* x86 */ { + /* Common save/restore data. */ + union + { + struct + { + /* X86_{CPUID,MSR}_DATA blobs for CPU Policy. */ + struct xc_sr_blob cpuid, msr; + } restore; + }; + struct /* x86 PV guest. */ { /* 4 or 8; 32 or 64 bit domain */ diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c index 083454d256..d4d86bb12f 100644 --- a/tools/libxc/xc_sr_common_x86.c +++ b/tools/libxc/xc_sr_common_x86.c @@ -49,6 +49,46 @@ int x86_static_data_complete(struct xc_sr_context *ctx) return 0; } +int handle_x86_cpuid_policy(struct xc_sr_context *ctx, struct xc_sr_record *rec) +{ + xc_interface *xch = ctx->xch; + int rc; + + if ( rec->length == 0 || + rec->length % sizeof(xen_cpuid_leaf_t) != 0 ) + { + ERROR("X86_CPUID_POLICY size %u should be multiple of %zu", + rec->length, sizeof(xen_cpuid_leaf_t)); + return -1; + } + + rc = update_blob(&ctx->x86.restore.cpuid, rec->data, rec->length); + if ( rc ) + ERROR("Unable to allocate %u bytes for X86_CPUID_POLICY", rec->length); + + return rc; +} + +int handle_x86_msr_policy(struct xc_sr_context *ctx, struct xc_sr_record *rec) +{ + xc_interface *xch = ctx->xch; + int rc; + + if ( rec->length == 0 || + rec->length % sizeof(xen_msr_entry_t) != 0 ) + { + ERROR("X86_MSR_POLICY size %u should be multiple of %zu", + rec->length, sizeof(xen_cpuid_leaf_t)); + return -1; + } + + rc = update_blob(&ctx->x86.restore.msr, rec->data, rec->length); + if ( rc ) + ERROR("Unable to allocate %u bytes for X86_MSR_POLICY", rec->length); + + return rc; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xc_sr_common_x86.h b/tools/libxc/xc_sr_common_x86.h index 7c2d42efe8..f7fa4fe62b 100644 --- a/tools/libxc/xc_sr_common_x86.h +++ b/tools/libxc/xc_sr_common_x86.h @@ -19,6 +19,20 @@ int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec); */ int x86_static_data_complete(struct xc_sr_context *ctx); +/* + * Parses an X86_CPUID_POLICY record and stashes the content for application + * when a STATIC_DATA_END record is encountered. + */ +int handle_x86_cpuid_policy(struct xc_sr_context *ctx, + struct xc_sr_record *rec); + +/* + * Parses an X86_MSR_POLICY record and stashes the content for application + * when a STATIC_DATA_END record is encountered. + */ +int handle_x86_msr_policy(struct xc_sr_context *ctx, + struct xc_sr_record *rec); + #endif /* * Local variables: diff --git a/tools/libxc/xc_sr_restore_x86_hvm.c b/tools/libxc/xc_sr_restore_x86_hvm.c index 94f47f2589..9190edaee7 100644 --- a/tools/libxc/xc_sr_restore_x86_hvm.c +++ b/tools/libxc/xc_sr_restore_x86_hvm.c @@ -171,6 +171,12 @@ static int x86_hvm_process_record(struct xc_sr_context *ctx, case REC_TYPE_HVM_PARAMS: return handle_hvm_params(ctx, rec); + case REC_TYPE_X86_CPUID_POLICY: + return handle_x86_cpuid_policy(ctx, rec); + + case REC_TYPE_X86_MSR_POLICY: + return handle_x86_msr_policy(ctx, rec); + default: return RECORD_NOT_PROCESSED; } @@ -227,6 +233,9 @@ static int x86_hvm_cleanup(struct xc_sr_context *ctx) { free(ctx->x86.hvm.restore.context.ptr); + free(ctx->x86.restore.cpuid.ptr); + free(ctx->x86.restore.msr.ptr); + return 0; } diff --git a/tools/libxc/xc_sr_restore_x86_pv.c b/tools/libxc/xc_sr_restore_x86_pv.c index 90b1e5427b..3d593753ab 100644 --- a/tools/libxc/xc_sr_restore_x86_pv.c +++ b/tools/libxc/xc_sr_restore_x86_pv.c @@ -1102,6 +1102,12 @@ static int x86_pv_process_record(struct xc_sr_context *ctx, case REC_TYPE_X86_TSC_INFO: return handle_x86_tsc_info(ctx, rec); + case REC_TYPE_X86_CPUID_POLICY: + return handle_x86_cpuid_policy(ctx, rec); + + case REC_TYPE_X86_MSR_POLICY: + return handle_x86_msr_policy(ctx, rec); + default: return RECORD_NOT_PROCESSED; } @@ -1173,6 +1179,9 @@ static int x86_pv_cleanup(struct xc_sr_context *ctx) if ( ctx->x86.pv.m2p ) munmap(ctx->x86.pv.m2p, ctx->x86.pv.nr_m2p_frames * PAGE_SIZE); + free(ctx->x86.restore.cpuid.ptr); + free(ctx->x86.restore.msr.ptr); + return 0; }