From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183511; cv=none; d=zohomail.com; s=zohoarc; b=hE5X0bgMUgpAJY0n9/5DEo9IogASKL9zux1u+CteCp23iBx5s5lnbrZzNlO0caXJkh+KoPbmqhHR4vIGxdiUtkxylHYJOJ+bd4n8U3+JB6Kb8rEPbQtPOP8fLS63mO2MyG6mCMrTie+cslrtNgozBq3KNHTrMKWgFbNJjkrvggg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183511; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UWh3z72cedco8BYeLrNyT1WM5VqVHSPK2ry97ilWHbM=; b=JHiICFayIZ0p6ID02vxO0wfboMCq4jmCSJmUjDi9NOJ4aro4Oa2wnYv8TemIAM3fvl7mSe+1R6NONHzx0+N3RtUU61DCXUakQJhu70gR31OZSGycEk9EKLr401AxUp7NX2+ETNAG4a822iRFJradFzlJwxAXIkH8NejZx6E8Lpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183511405585.9840402122294; Thu, 8 Oct 2020 11:58:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4557.11918 (Exim 4.92) (envelope-from ) id 1kQb6m-0005Ra-GA; Thu, 08 Oct 2020 18:57:44 +0000 Received: by outflank-mailman (output) from mailman id 4557.11918; Thu, 08 Oct 2020 18:57:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6m-0005RT-D3; Thu, 08 Oct 2020 18:57:44 +0000 Received: by outflank-mailman (input) for mailman id 4557; Thu, 08 Oct 2020 18:57:44 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6l-0005RO-VE for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:44 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a700aef9-855c-45d9-8cc0-d4c741c137d9; Thu, 08 Oct 2020 18:57:42 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6i-000419-5v; Thu, 08 Oct 2020 18:57:40 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6h-0002P9-TL; Thu, 08 Oct 2020 18:57:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6l-0005RO-VE for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:44 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a700aef9-855c-45d9-8cc0-d4c741c137d9; Thu, 08 Oct 2020 18:57:42 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6i-000419-5v; Thu, 08 Oct 2020 18:57:40 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6h-0002P9-TL; Thu, 08 Oct 2020 18:57:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a700aef9-855c-45d9-8cc0-d4c741c137d9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=UWh3z72cedco8BYeLrNyT1WM5VqVHSPK2ry97ilWHbM=; b=GjA3D5gCTCKzxAjMsiSTBtmec7 4sW0wpdtMyI6pbtzYn6+nMRW9K21NGSRQIhc52CajAn9qcI7fE4KGu3ApClPqcczOOgVbebO695aW M6nf9Q3/OZa2iZPZMnJ/aP3PR+vSrmZZSIKtlmia6uRcfWCE/UwfrenEnaPV7LNtKSME=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v10 01/11] docs / include: introduce a new framework for 'domain context' records Date: Thu, 8 Oct 2020 19:57:25 +0100 Message-Id: <20201008185735.29875-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) From: Paul Durrant To allow enlightened HVM guests (i.e. those that have PV drivers) to be migrated without their co-operation it will be necessary to transfer 'PV' state such as event channel state, grant entry state, etc. Currently there is a framework (entered via the hvm_save/load() functions) that allows a domain's 'HVM' (architectural) state to be transferred but 'PV' state is also common with pure PV guests and so this framework is not really suitable. This patch adds the specification of a new common 'domain context' image and the supporting public header. Subsequent patches will introduce other parts= of the framework, and code that will make use of it. This patch also marks the HVM-only framework as deprecated in favour of the new framework. Signed-off-by: Paul Durrant --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini Cc: Wei Liu Cc: Volodymyr Babchuk Cc: "Roger Pau Monn=C3=A9" v10: - New in v10 --- docs/specs/domain-context.md | 137 +++++++++++++++++++++++++ xen/include/public/arch-arm/hvm/save.h | 5 + xen/include/public/arch-x86/hvm/save.h | 5 + xen/include/public/save.h | 66 ++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 docs/specs/domain-context.md create mode 100644 xen/include/public/save.h diff --git a/docs/specs/domain-context.md b/docs/specs/domain-context.md new file mode 100644 index 0000000000..f177cf24b3 --- /dev/null +++ b/docs/specs/domain-context.md @@ -0,0 +1,137 @@ +# Domain Context (v1) + +## Background + +The design for *Non-Cooperative Migration of Guests*[1] explains that extra +information is required in the migration stream to allow a guest running PV +drivers to be migrated without its co-operation. This information includes +hypervisor state such as the set of event channels in operation and the +content of the grant table. + +There already exists in Xen a mechanism to save and restore *HVM context*[= 2]. +This specification describes a new framework that will replace that +mechanism and be suitable for transferring additional *PV state* records +conveying the information mentioned above. There is also on-going work to +implement *live update* of Xen where hypervisor state must be transferred = in +memory from one incarnation to the next. The framework described is design= ed +to also be suitable for this purpose. + +## Image format + +The format will read from or written to the hypervisor in a single virtual= ly +contiguous buffer segmented into **context records** specified in the foll= owing +sections. + +Fields within the records will always be aligned to their size. Padding and +reserved fields will always be set to zero when the context buffer is read +from the hypervisor and will be verified when written. +The endianness of numerical values will the native endianness of the +hypervisor. In the case of migration, that endianness is specified in the +*libxenctrl (libxc) Domain Image Format*[3]. + +### Record format + +All records have the following format: + +``` + 0 1 2 3 4 5 6 7 octet ++-------+-------+-------+-------+-------+-------+-------+-------+ +| type | instance | ++-------------------------------+-------------------------------+ +| length | ++---------------------------------------------------------------+ +| body +... +| | padding (0 to 7 octets) | ++-------+-------------------------------------------------------+ +``` + +\pagebreak +The fields are defined as follows: + + +| Field | Description | +|------------|--------------------------------------------------| +| `type` | A code which determines the layout and semantics | +| | of `body` | +| | | +| `instance` | The instance of the record | +| | | +| `length` | The length (in octets) of `body` | +| | | +| `body` | Zero or more octets of record data | +| | | +| `padding` | Zero to seven octets of zero-filled padding to | +| | bring the total record length up to the next | +| | 64-bit boundary | + +The `instance` field is present to distinguish multiple occurences of +a record. E.g. state that is per-vcpu may need to be described in multiple +records. + +The first record in the image is always a **START** record. The version of +the image format can be inferred from the `type` of this record. + +## Image content + +The following records are defined for the v1 image format. This set may be +extended in newer versions of the hypervisor. It is not expected that an i= mage +saved on a newer version of Xen will need to be restored on an older versi= on. +Therefore an image containing unrecognized record types should be rejected. + +### START + +``` + 0 1 2 3 4 5 6 7 octet ++-------+-------+-------+-------+-------+-------+-------+-------+ +| type =3D=3D 1 | instance =3D=3D 0 | ++-------------------------------+-------------------------------+ +| length =3D=3D 8 | ++-------------------------------+-------------------------------+ +| xen_major | xen_minor | ++-------------------------------+-------------------------------+ +``` + +A type 1 **START** record implies a v1 image. If a new image format version +is needed in future then this can be indicated by a new type value for this +(first) record in the image. + +\pagebreak +The record body contains the following fields: + +| Field | Description | +|-------------|-------------------------------------------------| +| `xen_major` | The major version of Xen that created this | +| | image | +| | | +| `xen_minor` | The minor version of Xen that created this | +| | image | + +The version of Xen that created the image can be useful to the version that +is restoring the image to determine whether certain records are expected to +be present in the image. For example, a version of Xen prior to X.Y may not +generate a FOO record but Xen X.Y+ can infer its content. But Xen X.Y+1 +**must** generate the FOO record as, from that version onward, its content +can no longer be safely inferred. + +### END + +``` + 0 1 2 3 4 5 6 7 octet ++-------+-------+-------+-------+-------+-------+-------+-------+ +| type =3D=3D 0 | instance =3D=3D 0 | ++-------------------------------+-------------------------------+ +| length =3D=3D 0 | ++---------------------------------------------------------------+ +``` + +A record of this type terminates the image. No further data from the buffer +should be consumed. + +* * * + +[1] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Ddocs/desi= gns/non-cooperative-migration.md + +[2] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Dxen/inclu= de/public/hvm/save.h + +[3] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Ddocs/spec= s/libxc-migration-stream.pandoc diff --git a/xen/include/public/arch-arm/hvm/save.h b/xen/include/public/ar= ch-arm/hvm/save.h index 75b8e65bcb..d5b0c15203 100644 --- a/xen/include/public/arch-arm/hvm/save.h +++ b/xen/include/public/arch-arm/hvm/save.h @@ -26,6 +26,11 @@ #ifndef __XEN_PUBLIC_HVM_SAVE_ARM_H__ #define __XEN_PUBLIC_HVM_SAVE_ARM_H__ =20 +/* + * Further use of HVM state is deprecated. New state records should only + * be added to the domain state header: public/save.h + */ + #endif =20 /* diff --git a/xen/include/public/arch-x86/hvm/save.h b/xen/include/public/ar= ch-x86/hvm/save.h index 773a380bc2..e61e2dbcd7 100644 --- a/xen/include/public/arch-x86/hvm/save.h +++ b/xen/include/public/arch-x86/hvm/save.h @@ -648,6 +648,11 @@ struct hvm_msr { */ #define HVM_SAVE_CODE_MAX 20 =20 +/* + * Further use of HVM state is deprecated. New state records should only + * be added to the domain state header: public/save.h + */ + #endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */ =20 /* diff --git a/xen/include/public/save.h b/xen/include/public/save.h new file mode 100644 index 0000000000..c4be9f570c --- /dev/null +++ b/xen/include/public/save.h @@ -0,0 +1,66 @@ +/* + * save.h + * + * Structure definitions for common PV/HVM domain state that is held by Xe= n. + * + * Copyright Amazon.com Inc. or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation = the + * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or + * sell copies of the Software, and to permit persons to whom the Software= is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef XEN_PUBLIC_SAVE_H +#define XEN_PUBLIC_SAVE_H + +#if defined(__XEN__) || defined(__XEN_TOOLS__) + +#include "xen.h" + +/* + * C structures for the Domain Context v1 format. + * See docs/specs/domain-context.md + */ + +struct domain_context_record { + uint32_t type; + uint32_t instance; + uint64_t length; + uint8_t body[XEN_FLEX_ARRAY_DIM]; +}; + +#define _DOMAIN_CONTEXT_RECORD_ALIGN 3 +#define DOMAIN_CONTEXT_RECORD_ALIGN (1U << _DOMAIN_CONTEXT_RECORD_ALIGN) + +enum { + DOMAIN_CONTEXT_END, + DOMAIN_CONTEXT_START, + /* New types go here */ + DOMAIN_CONTEXT_NR_TYPES +}; + +/* Initial entry */ +struct domain_context_start { + uint32_t xen_major, xen_minor; +}; + +/* Terminating entry */ +struct domain_context_end {}; + +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ + +#endif /* XEN_PUBLIC_SAVE_H */ --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183508; cv=none; d=zohomail.com; s=zohoarc; b=eymgvHJKcK456bw0pOWRn3TxMhF8aAFQHEyxXz7a+D1lRGMwvkQcogT+HZcly/HQHEfmxIs77A98yyrbB3N/bsCyVqEMEP+V6A/W7qVjbYVMtO5Tw1IqDFsKM97YMjLVgbakuuThWf6L3reGfZUcOoo3b0rWs91F32cb8dsNDnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183508; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MH3Jcb2gIq1O8Mh9sTMsNlQA5vWj9EpZg8v7PZTX4es=; b=fIZE357s2hSEVrqE+T5BXmAJ+8KrGx23MnhPosAsIUk/gLr4aape1WqcqFCAHnhckx/LFwbwWC5JnKJeY4S/vQkxGMgCIX4AZnh4RpPvtoQ8rZ8lWuYqNGGfsl2JVz9t4UUkLjBd1mj2swMoFCbNuyabtXffhmnLXWO86zQOJC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183508023833.0661761520773; Thu, 8 Oct 2020 11:58:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4558.11930 (Exim 4.92) (envelope-from ) id 1kQb6n-0005SX-QW; Thu, 08 Oct 2020 18:57:45 +0000 Received: by outflank-mailman (output) from mailman id 4558.11930; Thu, 08 Oct 2020 18:57:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6n-0005SQ-LI; Thu, 08 Oct 2020 18:57:45 +0000 Received: by outflank-mailman (input) for mailman id 4558; Thu, 08 Oct 2020 18:57:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6m-0005Rd-I8 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:44 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 22f72eed-43f4-4eb6-be00-1881072b7c92; Thu, 08 Oct 2020 18:57:43 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6j-00041D-Hq; Thu, 08 Oct 2020 18:57:41 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6j-0002P9-A5; Thu, 08 Oct 2020 18:57:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6m-0005Rd-I8 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:44 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 22f72eed-43f4-4eb6-be00-1881072b7c92; Thu, 08 Oct 2020 18:57:43 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6j-00041D-Hq; Thu, 08 Oct 2020 18:57:41 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6j-0002P9-A5; Thu, 08 Oct 2020 18:57:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 22f72eed-43f4-4eb6-be00-1881072b7c92 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=MH3Jcb2gIq1O8Mh9sTMsNlQA5vWj9EpZg8v7PZTX4es=; b=vLm+VSM1g8XlfzsW/Qq54eKPLa iubIj2PDUwi92PaDQQOb8bVRVlC60wlgtv8UUtz5UHjzygnhfWSZDYTZXK82LzAoOURDKxLVfPbF4 J/KQz7Auv1cEE+alXIVZf8LNxjY9xpPJZaLwjsJI1EHqobBRoBFEttX2HXZa43GcJiLI=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v10 02/11] xen: introduce implementation of save/restore of 'domain context' Date: Thu, 8 Oct 2020 19:57:26 +0100 Message-Id: <20201008185735.29875-3-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant A previous patch introduced the specification of the 'domain context' image and the supporting public header. This patch introduces the code necessary to generate and consume such an image. The entry points to the code are domain_save_ctxt() and domain_load_ctxt(). Code to call these functions will be introduced in a subsequent patch. Signed-off-by: Paul Durrant --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini Cc: Wei Liu v10: - New in v10 - Largely derived from patch #1 of the v9 series, but the code has been re-worked both functionally and cosmetically --- xen/common/Makefile | 1 + xen/common/save.c | 339 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/save.h | 160 +++++++++++++++++++ 3 files changed, 500 insertions(+) create mode 100644 xen/common/save.c create mode 100644 xen/include/xen/save.h diff --git a/xen/common/Makefile b/xen/common/Makefile index b3b60a1ba2..3e6f21714a 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -37,6 +37,7 @@ obj-y +=3D radix-tree.o obj-y +=3D rbtree.o obj-y +=3D rcupdate.o obj-y +=3D rwlock.o +obj-y +=3D save.o obj-y +=3D shutdown.o obj-y +=3D softirq.o obj-y +=3D sort.o diff --git a/xen/common/save.c b/xen/common/save.c new file mode 100644 index 0000000000..9287b20198 --- /dev/null +++ b/xen/common/save.c @@ -0,0 +1,339 @@ +/* + * save.c: save and load state common to all domain types. + * + * Copyright Amazon.com Inc. or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program; If not, see . + */ + +#include +#include + +struct domain_ctxt_state { + struct domain *d; + struct domain_context_record rec; + size_t len; /* for internal accounting */ + union { + const struct domain_save_ctxt_ops *save; + const struct domain_load_ctxt_ops *load; + } ops; + void *priv; + bool dry_run; +}; + +static struct { + const char *name; + domain_save_ctxt_type save; + domain_load_ctxt_type load; +} fns[DOMAIN_CONTEXT_NR_TYPES]; + +void __init domain_register_ctxt_type(unsigned int type, const char *name, + domain_save_ctxt_type save, + domain_load_ctxt_type load) +{ + BUG_ON(type >=3D ARRAY_SIZE(fns)); + + ASSERT(!fns[type].save); + ASSERT(!fns[type].load); + + fns[type].name =3D name; + fns[type].save =3D save; + fns[type].load =3D load; +} + +int domain_save_ctxt_rec_begin(struct domain_ctxt_state *c, + unsigned int type, unsigned int instance) +{ + struct domain_context_record rec =3D { .type =3D type, .instance =3D i= nstance }; + int rc; + + c->rec =3D rec; + c->len =3D 0; + + rc =3D c->ops.save->begin(c->priv, &c->rec); + if ( rc ) + return rc; + + return 0; +} + +int domain_save_ctxt_rec_data(struct domain_ctxt_state *c, const void *src, + size_t len) +{ + int rc =3D c->ops.save->append(c->priv, src, len); + + if ( !rc ) + c->len +=3D len; + + return rc; +} + +int domain_save_ctxt_rec_end(struct domain_ctxt_state *c) +{ + size_t len =3D c->len; + size_t pad =3D ROUNDUP(len, DOMAIN_CONTEXT_RECORD_ALIGN) - len; + int rc; + + if ( pad ) + { + static const uint8_t zeroes[DOMAIN_CONTEXT_RECORD_ALIGN] =3D {}; + + rc =3D c->ops.save->append(c->priv, zeroes, pad); + if ( rc ) + return rc; + } + + if ( !c->dry_run ) + gdprintk(XENLOG_DEBUG, "%pd save: %s[%u] +%zu (+%zu)\n", c->d, + fns[c->rec.type].name, c->rec.instance, + len, pad); + + rc =3D c->ops.save->end(c->priv, c->len); + + return rc; +} + +int domain_save_ctxt(struct domain *d, const struct domain_save_ctxt_ops *= ops, + void *priv, bool dry_run) +{ + struct domain_ctxt_state c =3D { + .d =3D d, + .ops.save =3D ops, + .priv =3D priv, + .dry_run =3D dry_run, + }; + domain_save_ctxt_type save; + unsigned int type; + int rc; + + ASSERT(d !=3D current->domain); + + save =3D fns[DOMAIN_CONTEXT_START].save; + BUG_ON(!save); + + rc =3D save(d, &c, dry_run); + if ( rc ) + return rc; + + domain_pause(d); + + for ( type =3D DOMAIN_CONTEXT_START + 1; type < ARRAY_SIZE(fns); type+= + ) + { + save =3D fns[type].save; + if ( !save ) + continue; + + rc =3D save(d, &c, dry_run); + if ( rc ) + break; + } + + domain_unpause(d); + + if ( rc ) + return rc; + + save =3D fns[DOMAIN_CONTEXT_END].save; + BUG_ON(!save); + + return save(d, &c, dry_run); +} + +int domain_load_ctxt_rec_begin(struct domain_ctxt_state *c, + unsigned int type, unsigned int *instance) +{ + if ( type !=3D c->rec.type ) + { + ASSERT_UNREACHABLE(); + return -EINVAL; + } + + *instance =3D c->rec.instance; + c->len =3D 0; + + return 0; +} + +int domain_load_ctxt_rec_data(struct domain_ctxt_state *c, void *dst, + size_t len) +{ + int rc =3D 0; + + c->len +=3D len; + if (c->len > c->rec.length) + return -ENODATA; + + if ( dst ) + rc =3D c->ops.load->read(c->priv, dst, len); + else /* sink data */ + { + uint8_t ignore; + + while ( !rc && len-- ) + rc =3D c->ops.load->read(c->priv, &ignore, sizeof(ignore)); + } + + return rc; +} + +int domain_load_ctxt_rec_end(struct domain_ctxt_state *c, bool ignore_data) +{ + size_t len =3D c->len; + size_t pad =3D ROUNDUP(len, DOMAIN_CONTEXT_RECORD_ALIGN) - len; + + gdprintk(XENLOG_DEBUG, "%pd load: %s[%u] +%zu (+%zu)\n", c->d, + fns[c->rec.type].name, c->rec.instance, + len, pad); + + while ( pad-- ) + { + uint8_t zero; + int rc =3D c->ops.load->read(c->priv, &zero, sizeof(zero)); + + if ( rc ) + return rc; + + if ( zero ) + return -EINVAL; + } + + return 0; +} + +int domain_load_ctxt(struct domain *d, const struct domain_load_ctxt_ops *= ops, + void *priv) +{ + struct domain_ctxt_state c =3D { .d =3D d, .ops.load =3D ops, .priv = =3D priv, }; + domain_load_ctxt_type load; + int rc; + + ASSERT(d !=3D current->domain); + + rc =3D c.ops.load->read(c.priv, &c.rec, sizeof(c.rec)); + if ( rc ) + return rc; + + load =3D fns[DOMAIN_CONTEXT_START].load; + BUG_ON(!load); + + rc =3D load(d, &c); + if ( rc ) + return rc; + + domain_pause(d); + + for (;;) + { + unsigned int type; + + rc =3D c.ops.load->read(c.priv, &c.rec, sizeof(c.rec)); + if ( rc ) + break; + + type =3D c.rec.type; + if ( type =3D=3D DOMAIN_CONTEXT_END ) + break; + + rc =3D -EINVAL; + if ( type >=3D ARRAY_SIZE(fns) ) + break; + + load =3D fns[type].load; + if ( !load ) + break; + + rc =3D load(d, &c); + if ( rc ) + break; + } + + domain_unpause(d); + + if ( rc ) + return rc; + + load =3D fns[DOMAIN_CONTEXT_END].load; + BUG_ON(!load); + + return load(d, &c); +} + +static int save_start(struct domain *d, struct domain_ctxt_state *c, + bool dry_run) +{ + static const struct domain_context_start s =3D { + .xen_major =3D XEN_VERSION, + .xen_minor =3D XEN_SUBVERSION, + }; + + return domain_save_ctxt_rec(c, DOMAIN_CONTEXT_START, 0, &s, sizeof(s)); +} + +static int load_start(struct domain *d, struct domain_ctxt_state *c) +{ + static struct domain_context_start s; + unsigned int i; + int rc =3D domain_load_ctxt_rec(c, DOMAIN_CONTEXT_START, &i, &s, sizeo= f(s)); + + if ( rc ) + return rc; + + if ( i ) + return -EINVAL; + + /* + * Make sure we are not attempting to load an image generated by a new= er + * version of Xen. + */ + if ( s.xen_major > XEN_VERSION && s.xen_minor > XEN_SUBVERSION ) + return -EOPNOTSUPP; + + return 0; +} + +DOMAIN_REGISTER_CTXT_TYPE(START, save_start, load_start); + +static int save_end(struct domain *d, struct domain_ctxt_state *c, + bool dry_run) +{ + static const struct domain_context_end e =3D {}; + + return domain_save_ctxt_rec(c, DOMAIN_CONTEXT_END, 0, &e, sizeof(e)); +} + +static int load_end(struct domain *d, struct domain_ctxt_state *c) +{ + unsigned int i; + int rc =3D domain_load_ctxt_rec(c, DOMAIN_CONTEXT_END, &i, NULL, + sizeof(struct domain_context_end)); + + if ( rc ) + return rc; + + if ( i ) + return -EINVAL; + + return 0; +} + +DOMAIN_REGISTER_CTXT_TYPE(END, save_end, load_end); + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/save.h b/xen/include/xen/save.h new file mode 100644 index 0000000000..358cf2f700 --- /dev/null +++ b/xen/include/xen/save.h @@ -0,0 +1,160 @@ +/* + * save.h: support routines for save/restore + * + * Copyright Amazon.com Inc. or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program; If not, see . + */ + +#ifndef XEN_SAVE_H +#define XEN_SAVE_H + +#include +#include +#include + +#include + +struct domain_ctxt_state; + +int domain_save_ctxt_rec_begin(struct domain_ctxt_state *c, unsigned int t= ype, + unsigned int instance); +int domain_save_ctxt_rec_data(struct domain_ctxt_state *c, const void *dat= a, + size_t len); +int domain_save_ctxt_rec_end(struct domain_ctxt_state *c); + +static inline int domain_save_ctxt_rec(struct domain_ctxt_state *c, + unsigned int type, unsigned int ins= tance, + const void *src, size_t len) +{ + int rc; + + rc =3D domain_save_ctxt_rec_begin(c, type, instance); + if ( rc ) + return rc; + + rc =3D domain_save_ctxt_rec_data(c, src, len); + if ( rc ) + return rc; + + return domain_save_ctxt_rec_end(c); +} + +int domain_load_ctxt_rec_begin(struct domain_ctxt_state *c, unsigned int t= ype, + unsigned int *instance); +int domain_load_ctxt_rec_data(struct domain_ctxt_state *c, void *data, + size_t len); +int domain_load_ctxt_rec_end(struct domain_ctxt_state *c, bool ignore_data= ); + +static inline int domain_load_ctxt_rec(struct domain_ctxt_state *c, + unsigned int type, + unsigned int *instance, void *dst, + size_t len) +{ + int rc; + + rc =3D domain_load_ctxt_rec_begin(c, type, instance); + if ( rc ) + return rc; + + rc =3D domain_load_ctxt_rec_data(c, dst, len); + if ( rc ) + return rc; + + return domain_load_ctxt_rec_end(c, false); +} + +/* + * The 'dry_run' flag indicates that the caller of domain_save_ctxt() (see= below) + * is not trying to actually acquire the data, only the size of the data. + * The save handler can therefore limit work to only that which is necessa= ry + * to call domain_save_ctxt_rec_data() the correct number of times with ac= curate + * values for 'len'. + * + * NOTE: the domain pointer argument to domain_save_ctxt_type is not const= as + * some handlers may need to acquire locks. + */ +typedef int (*domain_save_ctxt_type)(struct domain *d, + struct domain_ctxt_state *c, + bool dry_run); +typedef int (*domain_load_ctxt_type)(struct domain *d, + struct domain_ctxt_state *c); + +void domain_register_ctxt_type(unsigned int type, const char *name, + domain_save_ctxt_type save, + domain_load_ctxt_type load); + +/* + * Register save and load handlers for a record type. + * + * Save handlers will be invoked in an order which copes with any inter- + * entry dependencies. For now this means that HEADER will come first and + * END will come last, all others being invoked in order of 'typecode'. + * + * Load handlers will be invoked in the order of entries present in the + * buffer. + */ +#define DOMAIN_REGISTER_CTXT_TYPE(x, s, l) \ + static int __init __domain_register_##x##_ctxt_type(void) \ + { \ + domain_register_ctxt_type( \ + DOMAIN_CONTEXT_ ## x, \ + #x, \ + &(s), \ + &(l)); \ + \ + return 0; \ + } \ + __initcall(__domain_register_##x##_ctxt_type); + +/* Callback functions */ +struct domain_save_ctxt_ops { + /* + * Begin a new entry with the given record (only type and instance are + * valid). + */ + int (*begin)(void *priv, const struct domain_context_record *rec); + /* Append data/padding to the buffer */ + int (*append)(void *priv, const void *data, size_t len); + /* + * Complete the entry by updating the record with the total length of = the + * appended data (not including padding). + */ + int (*end)(void *priv, size_t len); +}; + +struct domain_load_ctxt_ops { + /* Read data/padding from the buffer */ + int (*read)(void *priv, void *data, size_t len); +}; + +/* + * Entry points: + * + * ops: These are callback functions provided by the caller that will + * be used to write to (in the save case) or read from (in the + * load case) the context buffer. See above for more detail. + * priv: This is a pointer that will be passed to the copy function to + * allow it to identify the context buffer and the current state + * of the save or load operation. + * dry_run: If this is set then the caller of domain_save() is only trying + * to acquire the total size of the data, not the data itself. + * In this case the caller may supply different ops to avoid doing + * unnecessary work. + */ +int domain_save_ctxt(struct domain *d, const struct domain_save_ctxt_ops *= ops, + void *priv, bool dry_run); +int domain_load_ctxt(struct domain *d, const struct domain_load_ctxt_ops *= ops, + void *priv); + +#endif /* XEN_SAVE_H */ --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183505; cv=none; d=zohomail.com; s=zohoarc; b=RnYdGN2pDm++QzrbcORL99ELbzQJGOnNvXEHzOdzez8AaE0M4nuysi+nnBpSicYi0lsLW8xfC880Ei41OY+TkURK2TplRvCr8D2Vsezym8XszwtYnMtwnpx9nVLwqu8MjIEB+J7ntxhyCk8hJG5Zdy7tTv9kRBFGcz0XkEoyvMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183505; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PIEMrLkEW9cqepMH9vM88oB66k912G0TL+PNGKBij/g=; b=X+r16RQvhX5/AAfo4AO+u5Gtq+VkYUKe6sTLXsgq7OP4dPFJz0wQ7Tr/c45IAxwaof+tdercJr6u7LJFkOqeu1rkrXLSjFnBNxXdsTzMgc3LjmbZUAihYBrqrhLFEOmNtIYEoL4LIrvAVXzSBoJF9pP155VoWWhRnFo2rgO103c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183505928229.15583716609012; Thu, 8 Oct 2020 11:58:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4561.11966 (Exim 4.92) (envelope-from ) id 1kQb6w-0005aQ-Rh; Thu, 08 Oct 2020 18:57:54 +0000 Received: by outflank-mailman (output) from mailman id 4561.11966; Thu, 08 Oct 2020 18:57:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6w-0005aF-NL; Thu, 08 Oct 2020 18:57:54 +0000 Received: by outflank-mailman (input) for mailman id 4561; Thu, 08 Oct 2020 18:57:53 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6v-0005RO-Oh for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:53 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2735b4bf-4c1d-4fe6-833a-c586c308dc65; Thu, 08 Oct 2020 18:57:46 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6l-00041O-9a; Thu, 08 Oct 2020 18:57:43 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6k-0002P9-QB; Thu, 08 Oct 2020 18:57:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6v-0005RO-Oh for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:53 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2735b4bf-4c1d-4fe6-833a-c586c308dc65; Thu, 08 Oct 2020 18:57:46 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6l-00041O-9a; Thu, 08 Oct 2020 18:57:43 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6k-0002P9-QB; Thu, 08 Oct 2020 18:57:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2735b4bf-4c1d-4fe6-833a-c586c308dc65 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=PIEMrLkEW9cqepMH9vM88oB66k912G0TL+PNGKBij/g=; b=1qd0VIdCHtQLR5HdSVJ3PjcAuE Dpa0nudmTP4twX2Csaq/21cUrdp7dpotIMAHIwChbsP6E7yBd5OhIW6O5E+cNWD4TQot8ljNYnUF3 ifa6gdZqXE6NgL56QFjkx798ZLZfbq/Ai5MEKxMPrZVbkmp9oZbwcVxKPcsOvMsysBoY=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Julien Grall , Wei Liu , Daniel De Graaf , Ian Jackson , Andrew Cooper , George Dunlap , Jan Beulich , Stefano Stabellini Subject: [PATCH v10 03/11] xen/common/domctl: introduce XEN_DOMCTL_get/set_domain_context Date: Thu, 8 Oct 2020 19:57:27 +0100 Message-Id: <20201008185735.29875-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" These domctls provide a mechanism to get and set 'domain context' from the toolstack. The implementation calls the domain_save_ctxt() and domain_load_ctxt() functions introduced in a previous patch. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Julien Grall Cc: Wei Liu Cc: Daniel De Graaf Cc: Ian Jackson Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Stefano Stabellini v10: - Re-base - Add underscores and move to 64-bit image size as requested by Andrew - Add a couple of record alignment ASSERTions - Dropped R-b and A-b since changes are not entirely cosmetic v4: - Add missing zero pad checks v3: - Addressed comments from Julien and Jan - Use vmalloc() rather than xmalloc_bytes() v2: - drop mask parameter - const-ify some more buffers --- tools/flask/policy/modules/xen.if | 4 +- tools/libs/ctrl/include/xenctrl.h | 5 + tools/libs/ctrl/xc_domain.c | 56 +++++++++ xen/common/domctl.c | 173 ++++++++++++++++++++++++++++ xen/include/public/domctl.h | 39 +++++++ xen/xsm/flask/hooks.c | 6 + xen/xsm/flask/policy/access_vectors | 4 + 7 files changed, 285 insertions(+), 2 deletions(-) diff --git a/tools/flask/policy/modules/xen.if b/tools/flask/policy/modules= /xen.if index 5e2aa472b6..2e2303d684 100644 --- a/tools/flask/policy/modules/xen.if +++ b/tools/flask/policy/modules/xen.if @@ -53,7 +53,7 @@ define(`create_domain_common', ` allow $1 $2:domain2 { set_cpu_policy settsc setscheduler setclaim set_vnumainfo get_vnumainfo cacheflush psr_cmt_op psr_alloc soft_reset - resource_map get_cpu_policy }; + resource_map get_cpu_policy set_context }; allow $1 $2:security check_context; allow $1 $2:shadow enable; allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmu= ext_op updatemp }; @@ -97,7 +97,7 @@ define(`migrate_domain_out', ` allow $1 $2:hvm { gethvmc getparam }; allow $1 $2:mmu { stat pageinfo map_read }; allow $1 $2:domain { getaddrsize getvcpucontext pause destroy }; - allow $1 $2:domain2 gettsc; + allow $1 $2:domain2 { gettsc get_context }; allow $1 $2:shadow { enable disable logdirty }; ') =20 diff --git a/tools/libs/ctrl/include/xenctrl.h b/tools/libs/ctrl/include/xe= nctrl.h index 3796425e1e..754a00c67b 100644 --- a/tools/libs/ctrl/include/xenctrl.h +++ b/tools/libs/ctrl/include/xenctrl.h @@ -867,6 +867,11 @@ int xc_domain_hvm_setcontext(xc_interface *xch, uint8_t *hvm_ctxt, uint32_t size); =20 +int xc_domain_get_context(xc_interface *xch, uint32_t domid, + void *ctxt_buf, size_t *size); +int xc_domain_set_context(xc_interface *xch, uint32_t domid, + const void *ctxt_buf, size_t size); + /** * This function will return guest IO ABI protocol * diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index e7cea4a17d..f35c1d2a28 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -536,6 +536,62 @@ int xc_domain_hvm_setcontext(xc_interface *xch, return ret; } =20 +int xc_domain_get_context(xc_interface *xch, uint32_t domid, + void *ctxt_buf, size_t *size) +{ + int ret; + DECLARE_DOMCTL =3D { + .cmd =3D XEN_DOMCTL_get_domain_context, + .domain =3D domid, + .u.get_domain_context.size =3D *size, + }; + DECLARE_HYPERCALL_BOUNCE(ctxt_buf, *size, XC_HYPERCALL_BUFFER_BOUNCE_O= UT); + + if ( xc_hypercall_bounce_pre(xch, ctxt_buf) ) + return -1; + + set_xen_guest_handle(domctl.u.set_domain_context.buffer, ctxt_buf); + + ret =3D do_domctl(xch, &domctl); + + xc_hypercall_bounce_post(xch, ctxt_buf); + + if ( ret ) + return ret; + + *size =3D domctl.u.get_domain_context.size; + if ( *size !=3D domctl.u.get_domain_context.size ) + { + errno =3D EOVERFLOW; + return -1; + } + + return 0; +} + +int xc_domain_set_context(xc_interface *xch, uint32_t domid, + const void *ctxt_buf, size_t size) +{ + int ret; + DECLARE_DOMCTL =3D { + .cmd =3D XEN_DOMCTL_set_domain_context, + .domain =3D domid, + .u.set_domain_context.size =3D size, + }; + DECLARE_HYPERCALL_BOUNCE_IN(ctxt_buf, size); + + if ( xc_hypercall_bounce_pre(xch, ctxt_buf) ) + return -1; + + set_xen_guest_handle(domctl.u.set_domain_context.buffer, ctxt_buf); + + ret =3D do_domctl(xch, &domctl); + + xc_hypercall_bounce_post(xch, ctxt_buf); + + return ret; +} + int xc_vcpu_getcontext(xc_interface *xch, uint32_t domid, uint32_t vcpu, diff --git a/xen/common/domctl.c b/xen/common/domctl.c index af044e2eda..6dbbe7f08a 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -273,6 +275,168 @@ static struct vnuma_info *vnuma_init(const struct xen= _domctl_vnuma *uinfo, return ERR_PTR(ret); } =20 +struct domctl_context +{ + void *buffer; + struct domain_context_record *rec; + size_t len; + size_t cur; +}; + +static int dry_run_append(void *priv, const void *data, size_t len) +{ + struct domctl_context *c =3D priv; + + if ( c->len + len < c->len ) + return -EOVERFLOW; + + c->len +=3D len; + + return 0; +} + +static int dry_run_begin(void *priv, const struct domain_context_record *r= ec) +{ + return dry_run_append(priv, NULL, sizeof(*rec)); +} + +static int dry_run_end(void *priv, size_t len) +{ + struct domctl_context *c =3D priv; + + ASSERT(IS_ALIGNED(c->len, DOMAIN_CONTEXT_RECORD_ALIGN)); + + return 0; +} + +static struct domain_save_ctxt_ops dry_run_ops =3D { + .begin =3D dry_run_begin, + .append =3D dry_run_append, + .end =3D dry_run_end, +}; + +static int save_begin(void *priv, const struct domain_context_record *rec) +{ + struct domctl_context *c =3D priv; + + ASSERT(IS_ALIGNED(c->cur, DOMAIN_CONTEXT_RECORD_ALIGN)); + + if ( c->len - c->cur < sizeof(*rec) ) + return -ENOSPC; + + c->rec =3D c->buffer + c->cur; /* stash pointer to record */ + *c->rec =3D *rec; + + c->cur +=3D sizeof(*rec); + + return 0; +} + +static int save_append(void *priv, const void *data, size_t len) +{ + struct domctl_context *c =3D priv; + + if ( c->len - c->cur < len ) + return -ENOSPC; + + memcpy(c->buffer + c->cur, data, len); + c->cur +=3D len; + + return 0; +} + +static int save_end(void *priv, size_t len) +{ + struct domctl_context *c =3D priv; + + c->rec->length =3D len; + + return 0; +} + +static struct domain_save_ctxt_ops save_ops =3D { + .begin =3D save_begin, + .append =3D save_append, + .end =3D save_end, +}; + +static int get_domain_context(struct domain *d, + struct xen_domctl_get_domain_context *gdc) +{ + struct domctl_context c =3D { .buffer =3D ZERO_BLOCK_PTR }; + int rc; + + if ( d =3D=3D current->domain ) + return -EPERM; + + if ( guest_handle_is_null(gdc->buffer) ) /* query for buffer size */ + { + if ( gdc->size ) + return -EINVAL; + + /* dry run to acquire buffer size */ + rc =3D domain_save_ctxt(d, &dry_run_ops, &c, true); + if ( rc ) + return rc; + + gdc->size =3D c.len; + return 0; + } + + c.len =3D gdc->size; + c.buffer =3D vmalloc(c.len); + if ( !c.buffer ) + return -ENOMEM; + + rc =3D domain_save_ctxt(d, &save_ops, &c, false); + + gdc->size =3D c.cur; + if ( !rc && copy_to_guest(gdc->buffer, c.buffer, gdc->size) ) + rc =3D -EFAULT; + + vfree(c.buffer); + + return rc; +} + +static int load_read(void *priv, void *data, size_t len) +{ + struct domctl_context *c =3D priv; + + if ( c->len - c->cur < len ) + return -ENODATA; + + memcpy(data, c->buffer + c->cur, len); + c->cur +=3D len; + + return 0; +} + +static struct domain_load_ctxt_ops load_ops =3D { + .read =3D load_read, +}; + +static int set_domain_context(struct domain *d, + const struct xen_domctl_set_domain_context *= sdc) +{ + struct domctl_context c =3D { .buffer =3D ZERO_BLOCK_PTR, .len =3D sdc= ->size }; + int rc; + + if ( d =3D=3D current->domain ) + return -EPERM; + + c.buffer =3D vmalloc(c.len); + if ( !c.buffer ) + return -ENOMEM; + + rc =3D !copy_from_guest(c.buffer, sdc->buffer, c.len) ? + domain_load_ctxt(d, &load_ops, &c) : -EFAULT; + + vfree(c.buffer); + + return rc; +} + long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) { long ret =3D 0; @@ -867,6 +1031,15 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) copyback =3D 1; break; =20 + case XEN_DOMCTL_get_domain_context: + ret =3D get_domain_context(d, &op->u.get_domain_context); + copyback =3D !ret; + break; + + case XEN_DOMCTL_set_domain_context: + ret =3D set_domain_context(d, &op->u.set_domain_context); + break; + default: ret =3D arch_do_domctl(op, d, u_domctl); break; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 666aeb71bf..a3e10c03f1 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1132,6 +1132,41 @@ struct xen_domctl_vuart_op { */ }; =20 +/* + * XEN_DOMCTL_get_domain_context + * ----------------------------- + * + * buffer (IN): The buffer into which the context data should be + * copied, or NULL to query the buffer size that should + * be allocated. + * size (IN/OUT): If 'buffer' is NULL then the value passed in must be + * zero, and the value passed out will be the size of the + * buffer to allocate. + * If 'buffer' is non-NULL then the value passed in must + * be the size of the buffer into which data may be copied. + * The value passed out will be the size of data written. + */ +struct xen_domctl_get_domain_context { + uint64_t size; + XEN_GUEST_HANDLE_64(void) buffer; +}; + +/* XEN_DOMCTL_set_domain_context + * ----------------------------- + * + * buffer (IN): The buffer from which the context data should be + * copied. + * size (IN): The size of the buffer from which data may be copied. + * This data must include DOMAIN_SAVE_CODE_HEADER at the + * start and terminate with a DOMAIN_SAVE_CODE_END record. + * Any data beyond the DOMAIN_SAVE_CODE_END record will be + * ignored. + */ +struct xen_domctl_set_domain_context { + uint64_t size; + XEN_GUEST_HANDLE_64(const_void) buffer; +}; + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1216,6 +1251,8 @@ struct xen_domctl { #define XEN_DOMCTL_vuart_op 81 #define XEN_DOMCTL_get_cpu_policy 82 #define XEN_DOMCTL_set_cpu_policy 83 +#define XEN_DOMCTL_get_domain_context 84 +#define XEN_DOMCTL_set_domain_context 85 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1276,6 +1313,8 @@ struct xen_domctl { struct xen_domctl_monitor_op monitor_op; struct xen_domctl_psr_alloc psr_alloc; struct xen_domctl_vuart_op vuart_op; + struct xen_domctl_get_domain_context get_domain_context; + struct xen_domctl_set_domain_context set_domain_context; uint8_t pad[128]; } u; }; diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index de050cc9fe..3c6217e4ac 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -754,6 +754,12 @@ static int flask_domctl(struct domain *d, int cmd) case XEN_DOMCTL_get_cpu_policy: return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__GET_CPU_POLI= CY); =20 + case XEN_DOMCTL_set_domain_context: + return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_CONTEXT); + + case XEN_DOMCTL_get_domain_context: + return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__GET_CONTEXT); + default: return avc_unknown_permission("domctl", cmd); } diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/acc= ess_vectors index 1aa0bb501c..fea0c9f143 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -245,6 +245,10 @@ class domain2 resource_map # XEN_DOMCTL_get_cpu_policy get_cpu_policy +# XEN_DOMCTL_set_domain_context + set_context +# XEN_DOMCTL_get_domain_context + get_context } =20 # Similar to class domain, but primarily contains domctls related to HVM d= omains --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183504; cv=none; d=zohomail.com; s=zohoarc; b=c83XBm1YD5agIBPhprkc3sKvcwWsclH6c9Ksc8W6x3iS4yFCWJYwQm0WAG6qJyud3pVICnmz+hhnh2twx9YubENZLVyuHIjb1oPnvd+K0xhSKT5eiup4XT7lGegBaV0SRlSqTwKjcvuyr3uQwXIEaSxHIW3Vwy0VGjFvwrT2p4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183504; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KuTv/AiA3AykRxQcQYe5kZtE2uGaDTe4ZnjePHv8ems=; b=IiytQxfMF/YOB4fbYYdXXXsCrllk1WpayjqioulyJvrHvNrfz2AqesO2cIhIdrasrWcrhYqbTeycMDv2jLx6vw/M7FugwpB9638PnGjSkrCTWaSjmc/vS+JrgFg4u+hLXi8GCSOF3DZU1t/SxswhZrFa9AOUQXbwvZijMC8r+UU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183504808268.48570111749723; Thu, 8 Oct 2020 11:58:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4560.11954 (Exim 4.92) (envelope-from ) id 1kQb6t-0005WP-GA; Thu, 08 Oct 2020 18:57:51 +0000 Received: by outflank-mailman (output) from mailman id 4560.11954; Thu, 08 Oct 2020 18:57:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6t-0005WH-C3; Thu, 08 Oct 2020 18:57:51 +0000 Received: by outflank-mailman (input) for mailman id 4560; Thu, 08 Oct 2020 18:57:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6r-0005Rd-Gs for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:49 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 08ecb7e3-5169-43f5-968b-d4e3676090eb; Thu, 08 Oct 2020 18:57:45 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6m-00041U-9S; Thu, 08 Oct 2020 18:57:44 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6m-0002P9-1o; Thu, 08 Oct 2020 18:57:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6r-0005Rd-Gs for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:49 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 08ecb7e3-5169-43f5-968b-d4e3676090eb; Thu, 08 Oct 2020 18:57:45 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6m-00041U-9S; Thu, 08 Oct 2020 18:57:44 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6m-0002P9-1o; Thu, 08 Oct 2020 18:57:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 08ecb7e3-5169-43f5-968b-d4e3676090eb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=KuTv/AiA3AykRxQcQYe5kZtE2uGaDTe4ZnjePHv8ems=; b=4BKw2EiLnQterbDLN/hAsmx+RQ yybqjdsv86n0liKGgrRVdDL5IzIPhMQ+5z5x+mfhCgck5YKQ2ldcRbynxBmSL7K5KJwzddY2gLGaH Sbhkze0q4Ugn46LP7bOymaTZKGdy4R8KpkBDizxL84lCzG8T/CBnT1uK4VapD+g/30WA=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Andrew Cooper Subject: [PATCH v10 04/11] tools/misc: add xen-domctx to present domain context Date: Thu, 8 Oct 2020 19:57:28 +0100 Message-Id: <20201008185735.29875-5-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" This tool is analogous to 'xen-hvmctx' which presents HVM context. Subsequent patches will add 'dump' functions when new records are introduced. Signed-off-by: Paul Durrant Acked-by: Ian Jackson Acked-by: Wei Liu --- Cc: Andrew Cooper v10: - Re-base - Use err[x]() - Keep existing A-b since modifications are trivial v3: - Re-worked to avoid copying onto stack - Added optional typecode and instance arguments v2: - Change name from 'xen-ctx' to 'xen-domctx' --- .gitignore | 1 + tools/misc/Makefile | 4 + tools/misc/xen-domctx.c | 172 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 tools/misc/xen-domctx.c diff --git a/.gitignore b/.gitignore index 188495783e..4d9a61124d 100644 --- a/.gitignore +++ b/.gitignore @@ -243,6 +243,7 @@ tools/misc/xen_cpuperf tools/misc/xen-cpuid tools/misc/xen-detect tools/misc/xen-diag +tools/misc/xen-domctx tools/misc/xen-tmem-list-parse tools/misc/xen-livepatch tools/misc/xenperf diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 7d37f297a9..fb673d0ff6 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -32,6 +32,7 @@ INSTALL_SBIN +=3D xenpm INSTALL_SBIN +=3D xenwatchdogd INSTALL_SBIN +=3D xen-livepatch INSTALL_SBIN +=3D xen-diag +INSTALL_SBIN +=3D xen-domctx INSTALL_SBIN +=3D $(INSTALL_SBIN-y) =20 # Everything to be installed in a private bin/ @@ -111,6 +112,9 @@ xen-livepatch: xen-livepatch.o xen-diag: xen-diag.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 +xen-domctx: xen-domctx.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + xen-lowmemd: xen-lowmemd.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(L= DLIBS_libxenstore) $(APPEND_LDFLAGS) =20 diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c new file mode 100644 index 0000000000..ca135b9a28 --- /dev/null +++ b/tools/misc/xen-domctx.c @@ -0,0 +1,172 @@ +/* + * xen-domctx.c + * + * Print out domain save records in a human-readable way. + * + * Copyright Amazon.com Inc. or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software= "), + * to deal in the Software without restriction, including without limitati= on + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static void *buf =3D NULL; +static size_t len, off; + +#define GET_PTR(_x) = \ + do { = \ + if ( len - off < sizeof(*(_x)) ) = \ + errx(1, "error: need another %lu bytes, only %lu available", = \ + sizeof(*(_x)), len - off); = \ + (_x) =3D buf + off; = \ + } while (false); + +static void dump_start(void) +{ + struct domain_context_start *s; + + GET_PTR(s); + + printf(" START: Xen %u.%u\n", s->xen_major, s->xen_minor); +} + +static void dump_end(void) +{ + struct domain_context_end *e; + + GET_PTR(e); + + printf(" END\n"); +} + +static void usage(void) +{ + errx(1, "usage: [ [ ]]"); +} + +int main(int argc, char **argv) +{ + char *s, *e; + long domid; + long type =3D -1; + long instance =3D -1; + unsigned int entry; + xc_interface *xch; + int rc; + + if ( argc < 2 || argc > 4 ) + usage(); + + s =3D e =3D argv[1]; + domid =3D strtol(s, &e, 0); + + if ( *s =3D=3D '\0' || *e !=3D '\0' || + domid < 0 || domid >=3D DOMID_FIRST_RESERVED ) + errx(1, "invalid domid '%s'", s); + + if ( argc >=3D 3 ) + { + s =3D e =3D argv[2]; + type =3D strtol(s, &e, 0); + + if ( *s =3D=3D '\0' || *e !=3D '\0' ) + errx(1, "invalid type '%s'", s); + } + + if ( argc =3D=3D 4 ) + { + s =3D e =3D argv[3]; + instance =3D strtol(s, &e, 0); + + if ( *s =3D=3D '\0' || *e !=3D '\0' ) + errx(1, "invalid instance '%s'", s); + } + + xch =3D xc_interface_open(0, 0, 0); + if ( !xch ) + err(1, "can't open libxc handle"); + + rc =3D xc_domain_get_context(xch, domid, NULL, &len); + if ( rc < 0 ) + err(1, "can't get context length for dom %lu", domid); + + buf =3D malloc(len); + if ( !buf ) + err(1, "can't allocate %lu bytes", len); + + rc =3D xc_domain_get_context(xch, domid, buf, &len); + if ( rc < 0 ) + err(1, "can't get context for dom %lu", domid); + + off =3D 0; + + entry =3D 0; + for ( ;; ) + { + struct domain_context_record *rec; + + GET_PTR(rec); + + off +=3D sizeof(*rec); + + if ( (type < 0 || type =3D=3D rec->type) && + (instance < 0 || instance =3D=3D rec->instance) ) + { + printf("[%u] type: %u instance: %u length: %"PRIu64"\n", entry= ++, + rec->type, rec->instance, rec->length); + + switch (rec->type) + { + case DOMAIN_CONTEXT_START: dump_start(); break; + case DOMAIN_CONTEXT_END: dump_end(); break; + default: + printf("Unknown type %u: skipping\n", rec->type); + break; + } + } + + if ( rec->type =3D=3D DOMAIN_CONTEXT_END ) + break; + + off +=3D ROUNDUP(rec->length, _DOMAIN_CONTEXT_RECORD_ALIGN); + } + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183508; cv=none; d=zohomail.com; s=zohoarc; b=aiabVnG9foyv0CFohjMOl3gsA95YxE9kgWgCDCG5JkOM4An2ueay56oxMn3qghoWlI35n7TJ0F/6f/HyX+QOq+gRI23YZy8BlAz0RdwmStENPY3S1RNbNWbN2gq8vTMedMXTK3X5brQN60/ufaq0TF5sO3mux8zZIjszFIrHI7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183508; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=08OQ9dhpBtbLKfokq1GJMc6/ONnHhWNL0B52lkG8Jxs=; b=JzGnFRKlS21I4ykocKGaWDgjruv51USPd9ZiLPviwFXBY9AmHJ5ZDww+NAPL5TcZUyTaqqxz+EjG9h6Dtl2/J6SAKx5wS0GHEItigEW5RiiaOoFzzxRrWUwFZNCX1mY9qzRt4E/xPWAo4lg2eJXQ0xiR+TIbKDigYSzd5LB6EE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183508911823.6873969258322; Thu, 8 Oct 2020 11:58:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4563.11990 (Exim 4.92) (envelope-from ) id 1kQb72-0005jL-Nh; Thu, 08 Oct 2020 18:58:00 +0000 Received: by outflank-mailman (output) from mailman id 4563.11990; Thu, 08 Oct 2020 18:58:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb72-0005jB-IQ; Thu, 08 Oct 2020 18:58:00 +0000 Received: by outflank-mailman (input) for mailman id 4563; Thu, 08 Oct 2020 18:57:58 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb70-0005RO-Or for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:58 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b401a948-9a26-4764-a57a-e7a26aace545; Thu, 08 Oct 2020 18:57:46 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6n-00041e-MH; Thu, 08 Oct 2020 18:57:45 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6n-0002P9-Ea; Thu, 08 Oct 2020 18:57:45 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb70-0005RO-Or for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:58 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b401a948-9a26-4764-a57a-e7a26aace545; Thu, 08 Oct 2020 18:57:46 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6n-00041e-MH; Thu, 08 Oct 2020 18:57:45 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6n-0002P9-Ea; Thu, 08 Oct 2020 18:57:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b401a948-9a26-4764-a57a-e7a26aace545 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=08OQ9dhpBtbLKfokq1GJMc6/ONnHhWNL0B52lkG8Jxs=; b=0X+9fnPxu+nVAFDzZo+0JLq+3R B9jEyuocVfr4jF570pJIh+UXlKXKAv9fMBqH8w7GhbXuVVfWhY/1Aik64e+/Dy09D6lJnRvUInhuf UZfZNSgYOvder6/BoDN6GkxHnS61NcuSKXC+kPFoltX2UfAc7FcAUjFD1VzkDQ66i5RI=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Jan Beulich , Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v10 05/11] common/domain: add a domain context record for shared_info... Date: Thu, 8 Oct 2020 19:57:29 +0100 Message-Id: <20201008185735.29875-6-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... and update xen-domctx to dump some information describing the record. NOTE: Processing of the content during restore is currently limited to PV domains, and matches processing of the PV-only SHARED_INFO record done by libxc. All content is, however, saved such that restore processing can be modified in future without requiring a new record format. Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Julien Grall Cc: Stefano Stabellini v10: - Re-base - Amend the specification now there is one - Dropped Jan's R-b as modifications are not completely trivial v9: - Use macros to make the code less verbose - Add missing check for allocation failure v8: - Incorporate zero-ing out of shared info fields that would be done in processing of SHARED_INFO from older stream versions v7: - Only restore vcpu_info and arch sub-structures for PV domains, to match processing of SHARED_INFO in xc_sr_restore_x86_pv.c - Use additional option to domain_load_end() to ignore the record for HVM domains v6: - Only save compat_shared_info buffer if has_32bit_shinfo is set - Validate flags field in load handler v5: - Addressed comments from Julien v4: - Addressed comments from Jan v3: - Actually dump some of the content of shared_info v2: - Drop the header change to define a 'Xen' page size and instead use a variable length struct now that the framework makes this is feasible - Guard use of 'has_32bit_shinfo' in common code with CONFIG_COMPAT --- docs/specs/domain-context.md | 29 +++++++++ tools/misc/xen-domctx.c | 80 +++++++++++++++++++++++++ xen/common/domain.c | 113 +++++++++++++++++++++++++++++++++++ xen/include/public/save.h | 11 ++++ 4 files changed, 233 insertions(+) diff --git a/docs/specs/domain-context.md b/docs/specs/domain-context.md index f177cf24b3..95e9f9d1ab 100644 --- a/docs/specs/domain-context.md +++ b/docs/specs/domain-context.md @@ -128,6 +128,33 @@ can no longer be safely inferred. A record of this type terminates the image. No further data from the buffer should be consumed. =20 +### SHARED_INFO + +``` + 0 1 2 3 4 5 6 7 octet ++-------+-------+-------+-------+-------+-------+-------+-------+ +| type =3D=3D 2 | instance =3D=3D 0 | ++-------------------------------+-------------------------------+ +| length | ++-------------------------------+-------------------------------+ +| flags | buffer ++-------------------------------+ +... +``` + +\pagebreak +The record body contains the following fields: + +| Field | Description | +|-------------|-------------------------------------------------| +| `flags` | A bit-wise OR of the following: | +| | | +| | 0x00000001: The domain has 32-bit (compat) | +| | shared info | +| | | +| `buffer` | The shared info (`length` being architecture | +| | dependent[4]) | + * * * =20 [1] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Ddocs/desi= gns/non-cooperative-migration.md @@ -135,3 +162,5 @@ should be consumed. [2] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Dxen/inclu= de/public/hvm/save.h =20 [3] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Ddocs/spec= s/libxc-migration-stream.pandoc + +[4] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Dtools/inc= lude/xen-foreign/reference.size diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c index ca135b9a28..5ea6de50d1 100644 --- a/tools/misc/xen-domctx.c +++ b/tools/misc/xen-domctx.c @@ -57,6 +57,85 @@ static void dump_start(void) printf(" START: Xen %u.%u\n", s->xen_major, s->xen_minor); } =20 +static void print_binary(const char *prefix, const void *val, size_t size, + const char *suffix) +{ + printf("%s", prefix); + + while ( size-- ) + { + uint8_t octet =3D *(const uint8_t *)val++; + unsigned int i; + + for ( i =3D 0; i < 8; i++ ) + { + printf("%u", octet & 1); + octet >>=3D 1; + } + } + + printf("%s", suffix); +} + +static void dump_shared_info(void) +{ + struct domain_context_shared_info *s; + bool has_32bit_shinfo; + shared_info_any_t *info; + unsigned int i, n; + + GET_PTR(s); + has_32bit_shinfo =3D s->flags & DOMAIN_CONTEXT_32BIT_SHARED_INFO; + + printf(" SHARED_INFO: has_32bit_shinfo: %s\n", + has_32bit_shinfo ? "true" : "false"); + + info =3D (shared_info_any_t *)s->buffer; + +#define GET_FIELD_PTR(_f) \ + (has_32bit_shinfo ? \ + (const void *)&(info->x32._f) : \ + (const void *)&(info->x64._f)) +#define GET_FIELD_SIZE(_f) \ + (has_32bit_shinfo ? sizeof(info->x32._f) : sizeof(info->x64._f)) +#define GET_FIELD(_f) \ + (has_32bit_shinfo ? info->x32._f : info->x64._f) + + n =3D has_32bit_shinfo ? + ARRAY_SIZE(info->x32.evtchn_pending) : + ARRAY_SIZE(info->x64.evtchn_pending); + + for ( i =3D 0; i < n; i++ ) + { + const char *prefix =3D !i ? + " evtchn_pending: " : + " "; + + print_binary(prefix, GET_FIELD_PTR(evtchn_pending[0]), + GET_FIELD_SIZE(evtchn_pending[0]), "\n"); + } + + for ( i =3D 0; i < n; i++ ) + { + const char *prefix =3D !i ? + " evtchn_mask: " : + " "; + + print_binary(prefix, GET_FIELD_PTR(evtchn_mask[0]), + GET_FIELD_SIZE(evtchn_mask[0]), "\n"); + } + + printf(" wc: version: %u sec: %u nsec: %u", + GET_FIELD(wc_version), GET_FIELD(wc_sec), GET_FIELD(wc_nsec)); + if ( !has_32bit_shinfo ) + printf(" sec_hi: %u", info->x64.xen_wc_sec_hi); + printf("\n"); + +#undef GET_FIELD +#undef GET_FIELD_SIZE +#undef GET_FIELD_PTR +} + static void dump_end(void) { struct domain_context_end *e; @@ -145,6 +224,7 @@ int main(int argc, char **argv) switch (rec->type) { case DOMAIN_CONTEXT_START: dump_start(); break; + case DOMAIN_CONTEXT_SHARED_INFO: dump_shared_info(); break; case DOMAIN_CONTEXT_END: dump_end(); break; default: printf("Unknown type %u: skipping\n", rec->type); diff --git a/xen/common/domain.c b/xen/common/domain.c index f748806a45..6c223dae38 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1671,6 +1672,118 @@ int continue_hypercall_on_cpu( return 0; } =20 +static int save_shared_info(struct domain *d, struct domain_ctxt_state *c, + bool dry_run) +{ +#ifdef CONFIG_COMPAT + struct domain_context_shared_info s =3D { + .flags =3D has_32bit_shinfo(d) ? DOMAIN_CONTEXT_32BIT_SHARED_INFO = : 0, + }; + size_t size =3D has_32bit_shinfo(d) ? + sizeof(struct compat_shared_info) : + sizeof(struct shared_info); +#else + struct domain_context_shared_info s =3D {}; + size_t size =3D sizeof(struct shared_info); +#endif + int rc; + + rc =3D domain_save_ctxt_rec_begin(c, DOMAIN_CONTEXT_SHARED_INFO, 0); + if ( rc ) + return rc; + + rc =3D domain_save_ctxt_rec_data(c, &s, offsetof(typeof(s), buffer)); + if ( rc ) + return rc; + + rc =3D domain_save_ctxt_rec_data(c, d->shared_info, size); + if ( rc ) + return rc; + + return domain_save_ctxt_rec_end(c); +} + +static int load_shared_info(struct domain *d, struct domain_ctxt_state *c) +{ + struct domain_context_shared_info s =3D {}; + size_t size; + unsigned int i; + int rc; + + rc =3D domain_load_ctxt_rec_begin(c, DOMAIN_CONTEXT_SHARED_INFO, &i); + if ( rc ) + return rc; + + if ( i ) /* expect only a single instance */ + return -ENXIO; + + rc =3D domain_load_ctxt_rec_data(c, &s, offsetof(typeof(s), buffer)); + if ( rc ) + return rc; + + if ( s.flags & ~DOMAIN_CONTEXT_32BIT_SHARED_INFO ) + return -EINVAL; + + if ( s.flags & DOMAIN_CONTEXT_32BIT_SHARED_INFO ) + { +#ifdef CONFIG_COMPAT + d->arch.has_32bit_shinfo =3D true; + size =3D sizeof(struct compat_shared_info); +#else + return -EINVAL; +#endif + } + else + size =3D sizeof(struct shared_info); + + if ( is_pv_domain(d) ) + { + shared_info_t *shinfo =3D xzalloc(shared_info_t); + + if ( !shinfo ) + return -ENOMEM; + + rc =3D domain_load_ctxt_rec_data(c, shinfo, size); + if ( rc ) + goto out; + + memcpy(&shared_info(d, vcpu_info), &__shared_info(d, shinfo, vcpu_= info), + sizeof(shared_info(d, vcpu_info))); + memcpy(&shared_info(d, arch), &__shared_info(d, shinfo, arch), + sizeof(shared_info(d, arch))); + + memset(&shared_info(d, evtchn_pending), 0, + sizeof(shared_info(d, evtchn_pending))); + memset(&shared_info(d, evtchn_mask), 0xff, + sizeof(shared_info(d, evtchn_mask))); + +#ifdef CONFIG_X86 + shared_info(d, arch.pfn_to_mfn_frame_list_list) =3D 0; +#endif + for ( i =3D 0; i < XEN_LEGACY_MAX_VCPUS; i++ ) + shared_info(d, vcpu_info[i].evtchn_pending_sel) =3D 0; + + rc =3D domain_load_ctxt_rec_end(c, false); + + out: + xfree(shinfo); + } + else + { + /* + * No modifications to shared_info are required for restoring non-= PV + * domains. + */ + rc =3D domain_load_ctxt_rec_data(c, NULL, size); + if ( !rc ) + rc =3D domain_load_ctxt_rec_end(c, true); + } + + return rc; +} + +DOMAIN_REGISTER_CTXT_TYPE(SHARED_INFO, save_shared_info, load_shared_info); + /* * Local variables: * mode: C diff --git a/xen/include/public/save.h b/xen/include/public/save.h index c4be9f570c..bccbaadd0b 100644 --- a/xen/include/public/save.h +++ b/xen/include/public/save.h @@ -49,6 +49,7 @@ struct domain_context_record { enum { DOMAIN_CONTEXT_END, DOMAIN_CONTEXT_START, + DOMAIN_CONTEXT_SHARED_INFO, /* New types go here */ DOMAIN_CONTEXT_NR_TYPES }; @@ -58,6 +59,16 @@ struct domain_context_start { uint32_t xen_major, xen_minor; }; =20 +struct domain_context_shared_info { + uint32_t flags; + +#define _DOMAIN_CONTEXT_32BIT_SHARED_INFO 0 +#define DOMAIN_CONTEXT_32BIT_SHARED_INFO \ + (1U << _DOMAIN_CONTEXT_32BIT_SHARED_INFO) + + uint8_t buffer[XEN_FLEX_ARRAY_DIM]; +}; + /* Terminating entry */ struct domain_context_end {}; =20 --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183509; cv=none; d=zohomail.com; s=zohoarc; b=N8roeMchG22HcZ9OMFwvwdOjs/p/E7dqrP8ES6d+gBR6Fvp1Qb0Q8Xc7IFPLGi5fR0cl3LS5iupJ0amXzj/olFt3wtB1NUJDhQhUIAJ9v8mNfhGy7nxM1QHVTqdamYnnUK4Z1c1f5lscBqozkA0MI4tUANZU43+73HEvu7mHPKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183509; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AC7LRRI1wOmmMw28VRmEhixnQ6YAW+ioZhx4wAS3Mgc=; b=QxZmmUzwq6jL7JKCKAnYxWc2Iflkl+HqmKlm9rfdUuqiWOJsuEJPvl+B8jbdwgIkpbQDYoRKLrDeQsjIcoP0SuNF5fnBeflprX4jhg504KK7gkUV+etLonf1mW/ZJ1bQpuTT7uyqnf8Q2AnEJqlyYNvk9qpxCSzIxgbu1Vvw75g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183509960136.9951281237412; Thu, 8 Oct 2020 11:58:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4565.12014 (Exim 4.92) (envelope-from ) id 1kQb77-0005rT-EA; Thu, 08 Oct 2020 18:58:05 +0000 Received: by outflank-mailman (output) from mailman id 4565.12014; Thu, 08 Oct 2020 18:58:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb77-0005rF-8n; Thu, 08 Oct 2020 18:58:05 +0000 Received: by outflank-mailman (input) for mailman id 4565; Thu, 08 Oct 2020 18:58:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb75-0005RO-P5 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:58:03 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f4a4771c-8495-46c6-aa76-25ee6f552b4b; Thu, 08 Oct 2020 18:57:48 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6p-00041s-5r; Thu, 08 Oct 2020 18:57:47 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6o-0002P9-Ug; Thu, 08 Oct 2020 18:57:47 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb75-0005RO-P5 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:58:03 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f4a4771c-8495-46c6-aa76-25ee6f552b4b; Thu, 08 Oct 2020 18:57:48 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6p-00041s-5r; Thu, 08 Oct 2020 18:57:47 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6o-0002P9-Ug; Thu, 08 Oct 2020 18:57:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f4a4771c-8495-46c6-aa76-25ee6f552b4b DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=AC7LRRI1wOmmMw28VRmEhixnQ6YAW+ioZhx4wAS3Mgc=; b=I/SgwdNaU4Vq24kIJOAwqscdRv Z+eGMyM/eyRDVC81hbY0ckFcIxoD/5YtKXYklLcHW+/UM6+8noE3kpf+Ypmml9H8WOHSBgBzAg+CJ GLXHQyhBAsN0XxH+fbzrHDHvHjY4YmBcLWfzIpmUae7OvJO5tvaNyWbGd8yeDq+SzE+0=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Jan Beulich , Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v10 06/11] x86/time: add a domain context record for tsc_info... Date: Thu, 8 Oct 2020 19:57:30 +0100 Message-Id: <20201008185735.29875-7-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) From: Paul Durrant ... and update xen-domctx to dump some information describing the record. NOTE: Whilst the record is x86 specific, it is visible directly in the comm= on header as context record numbers should be unique across all architectures. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Julien Grall Cc: Stefano Stabellini Cc: "Roger Pau Monn=C3=A9" v10: - Re-base - Amend the specification now there is one - Kept Jan's R-b as the changes are cosmetic v8: - Removed stray blank line v7: - New in v7 --- docs/specs/domain-context.md | 32 ++++++++++++++++++++++++++++++++ tools/misc/xen-domctx.c | 12 ++++++++++++ xen/arch/x86/time.c | 30 ++++++++++++++++++++++++++++++ xen/include/public/save.h | 8 ++++++++ 4 files changed, 82 insertions(+) diff --git a/docs/specs/domain-context.md b/docs/specs/domain-context.md index 95e9f9d1ab..8aa3466d96 100644 --- a/docs/specs/domain-context.md +++ b/docs/specs/domain-context.md @@ -155,6 +155,38 @@ The record body contains the following fields: | `buffer` | The shared info (`length` being architecture | | | dependent[4]) | =20 +### TSC_INFO + +``` + 0 1 2 3 4 5 6 7 octet ++-------+-------+-------+-------+-------+-------+-------+-------+ +| type =3D=3D 3 | instance =3D=3D 0 | ++-------------------------------+-------------------------------+ +| length =3D=3D 20 | ++-------------------------------+-------------------------------+ +| mode | khz | ++-------------------------------+-------------------------------+ +| nsec | ++-------------------------------+-------------------------------+ +| incarnation | ++-------------------------------+ +``` + +The record body contains the following fields: + +| Field | Description | +|---------------|-----------------------------------------------| +| `mode` | 0x00000000: Default (emulate if necessary) | +| | 0x00000001: Always emulate | +| | 0x00000002: Never emulate | +| | | +| `khz` | The TSC frequency in kHz | +| | | +| `nsec` | Elapsed time in nanoseconds | +| | | +| `incarnation` | Incarnation (counter indicating how many | +| | times the TSC value has been set) | + * * * =20 [1] See https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Ddocs/desi= gns/non-cooperative-migration.md diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c index 5ea6de50d1..1a5dfb9d5a 100644 --- a/tools/misc/xen-domctx.c +++ b/tools/misc/xen-domctx.c @@ -136,6 +136,17 @@ static void dump_shared_info(void) #undef GET_FIELD_PTR } =20 +static void dump_tsc_info(void) +{ + struct domain_context_tsc_info *t; + + GET_PTR(t); + + printf(" TSC_INFO: mode: %u incarnation: %u\n" + " khz %u nsec: %"PRIu64"\n", + t->mode, t->incarnation, t->khz, t->nsec); +} + static void dump_end(void) { struct domain_context_end *e; @@ -225,6 +236,7 @@ int main(int argc, char **argv) { case DOMAIN_CONTEXT_START: dump_start(); break; case DOMAIN_CONTEXT_SHARED_INFO: dump_shared_info(); break; + case DOMAIN_CONTEXT_TSC_INFO: dump_tsc_info(); break; case DOMAIN_CONTEXT_END: dump_end(); break; default: printf("Unknown type %u: skipping\n", rec->type); diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 8938c0f435..aec4bfb0f3 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -2451,6 +2452,35 @@ int tsc_set_info(struct domain *d, return 0; } =20 +static int save_tsc_info(struct domain *d, struct domain_ctxt_state *c, + bool dry_run) +{ + struct domain_context_tsc_info t =3D {}; + + if ( !dry_run ) + tsc_get_info(d, &t.mode, &t.nsec, &t.khz, &t.incarnation); + + return domain_save_ctxt_rec(c, DOMAIN_CONTEXT_TSC_INFO, 0, &t, sizeof(= t)); +} + +static int load_tsc_info(struct domain *d, struct domain_ctxt_state *c) +{ + struct domain_context_tsc_info t; + unsigned int i; + int rc; + + rc =3D domain_load_ctxt_rec(c, DOMAIN_CONTEXT_TSC_INFO, &i, &t, sizeof= (t)); + if ( rc ) + return rc; + + if ( i ) /* expect only a single instance */ + return -ENXIO; + + return tsc_set_info(d, t.mode, t.nsec, t.khz, t.incarnation); +} + +DOMAIN_REGISTER_CTXT_TYPE(TSC_INFO, save_tsc_info, load_tsc_info); + /* vtsc may incur measurable performance degradation, diagnose with this */ static void dump_softtsc(unsigned char key) { diff --git a/xen/include/public/save.h b/xen/include/public/save.h index bccbaadd0b..86881864cf 100644 --- a/xen/include/public/save.h +++ b/xen/include/public/save.h @@ -50,6 +50,7 @@ enum { DOMAIN_CONTEXT_END, DOMAIN_CONTEXT_START, DOMAIN_CONTEXT_SHARED_INFO, + DOMAIN_CONTEXT_TSC_INFO, /* New types go here */ DOMAIN_CONTEXT_NR_TYPES }; @@ -69,6 +70,13 @@ struct domain_context_shared_info { uint8_t buffer[XEN_FLEX_ARRAY_DIM]; }; =20 +struct domain_context_tsc_info { + uint32_t mode; + uint32_t khz; + uint64_t nsec; + uint32_t incarnation; +}; + /* Terminating entry */ struct domain_context_end {}; =20 --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183504; cv=none; d=zohomail.com; s=zohoarc; b=Vv5DqkLKhTMNT8VzJJO6hV19hvwV4iC/riofPWM85ED0WqHB4GdU1cLqmR8n6yLM01AUxDnwuxMuK3M6Y2hElFF1gCCvvVKguHBc9RgJAHr/NC3V6a0Yi9+jBtC66xNpVvKRchuERskE5i24eM9pgbHQwASSyh9qUCNrkyTmxDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183504; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oKO5AKNeTUrG7AZllhuh/I6ylTG0M0k1GwLjYqlJpq8=; b=GXPbf+nQHkHGVYmwKfp6Z4/630iWQgljZpfCq5/bcfI18B8wuaLSPUj8URqTua/BKZk3rl99BsTrf2oo00QDNWWksoDj2KvZfwVL7HNBwO5yacpVOMPkn8yBqCIYBhTccgoE40yQwt83ajlYO7qAFvA1CHjeEUxegSSQh6uLVyE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 160218350480451.20547081761936; Thu, 8 Oct 2020 11:58:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4562.11978 (Exim 4.92) (envelope-from ) id 1kQb6y-0005d4-B4; Thu, 08 Oct 2020 18:57:56 +0000 Received: by outflank-mailman (output) from mailman id 4562.11978; Thu, 08 Oct 2020 18:57:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6y-0005cp-67; Thu, 08 Oct 2020 18:57:56 +0000 Received: by outflank-mailman (input) for mailman id 4562; Thu, 08 Oct 2020 18:57:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6w-0005Rd-H6 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:54 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 27f7fc65-d96f-4489-8d37-a62f4a7d1169; Thu, 08 Oct 2020 18:57:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6q-000424-JJ; Thu, 08 Oct 2020 18:57:48 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6q-0002P9-BJ; Thu, 08 Oct 2020 18:57:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6w-0005Rd-H6 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:54 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 27f7fc65-d96f-4489-8d37-a62f4a7d1169; Thu, 08 Oct 2020 18:57:50 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6q-000424-JJ; Thu, 08 Oct 2020 18:57:48 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6q-0002P9-BJ; Thu, 08 Oct 2020 18:57:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 27f7fc65-d96f-4489-8d37-a62f4a7d1169 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=oKO5AKNeTUrG7AZllhuh/I6ylTG0M0k1GwLjYqlJpq8=; b=0VgqTqfgE6iFtnmo7tyTIVdPMt QuH44fAxOfGUDZ2JqYkrCJWtWWT6vj4yDx8LsTfBjGgb8bjzH29jAuYNqvMPy39i/BhA/eiF8aMkp SjnpjqBdbXSOjti8kq4F7ckpIQHWOEygmmaDs/MMwHw9JH0C1u3r2rWY+DUVEIGJlM00=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Wei Liu , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v10 07/11] docs/specs: add missing definitions to libxc-migration-stream Date: Thu, 8 Oct 2020 19:57:31 +0100 Message-Id: <20201008185735.29875-8-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant The STATIC_DATA_END, X86_CPUID_POLICY and X86_MSR_POLICY record types have sections explaining what they are but their values are not defined. Indeed their values are defined as "Reserved for future mandatory records." Also, the spec revision is adjusted to match the migration stream version and an END record is added to the description of a 'typical save record for and x86 HVM guest.' Signed-off-by: Paul Durrant Fixes: 6f71b5b1506 ("docs/migration Specify migration v3 and STATIC_DATA_EN= D") Fixes: ddd273d8863 ("docs/migration: Specify X86_{CPUID,MSR}_POLICY records= ") Acked-by: Wei Liu --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini v7: - New in v7 --- docs/specs/libxc-migration-stream.pandoc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/specs/libxc-migration-stream.pandoc b/docs/specs/libxc-mi= gration-stream.pandoc index 6b0c49e97a..8aeab3b11b 100644 --- a/docs/specs/libxc-migration-stream.pandoc +++ b/docs/specs/libxc-migration-stream.pandoc @@ -3,7 +3,7 @@ Andrew Cooper <> Wen Congyang <> Yang Hongyang <> -% Revision 2 +% Revision 3 =20 Introduction =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -227,7 +227,13 @@ type 0x00000000: END =20 0x0000000F: CHECKPOINT_DIRTY_PFN_LIST (Secondary -> Primary) =20 - 0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_ + 0x00000010: STATIC_DATA_END + + 0x00000011: X86_CPUID_POLICY + + 0x00000012: X86_MSR_POLICY + + 0x00000013 - 0x7FFFFFFF: Reserved for future _mandatory_ records. =20 0x80000000 - 0xFFFFFFFF: Reserved for future _optional_ @@ -732,6 +738,7 @@ A typical save record for an x86 HVM guest image would = look like: * X86_TSC_INFO * HVM_PARAMS * HVM_CONTEXT +* END record =20 HVM_PARAMS must precede HVM_CONTEXT, as certain parameters can affect the validity of architectural state in the context. --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183507; cv=none; d=zohomail.com; s=zohoarc; b=jrY88MglSW4JWR7voEHfxl5vTDTOAJehdouyVPySzRv3ZlIdwXC8MJtxykFnNODQjJNO5/HZAJTJC3ou7lPZ6f5oSmg4czImVz0II3HrEqwaxHsNJSOxTEh4uCPC/VMyMI1UPeQy6u8YRvrCjXql6pRz2MTAm2xgy+wMXTrknbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183507; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RXDGKqvarznbbGXJp5zFlQUMeIoJk0IJ8cYPeqwtqQs=; b=WSCw3Ov1vp0YSy/kx7qqxd7vhsWIZ8CkFCxIymKKTeOIt+aiHd1zbgKjeNjf6qDcZTPFkQowUahrjjKmUcP4h9GkaejLJYtb6vnUqraf0mOiscf7yRgazBzTe9y6N3jNxs1mZ/+W+ZEZbCF+722V1osiR+YxgbiymhZjY1PJecY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183507720233.7857998214762; Thu, 8 Oct 2020 11:58:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4564.11995 (Exim 4.92) (envelope-from ) id 1kQb73-0005kM-7I; Thu, 08 Oct 2020 18:58:01 +0000 Received: by outflank-mailman (output) from mailman id 4564.11995; Thu, 08 Oct 2020 18:58:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb72-0005k6-UT; Thu, 08 Oct 2020 18:58:00 +0000 Received: by outflank-mailman (input) for mailman id 4564; Thu, 08 Oct 2020 18:57:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb71-0005Rd-HC for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:59 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9873da21-24d2-457c-af46-bf5823508cc0; Thu, 08 Oct 2020 18:57:51 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6s-00042L-4O; Thu, 08 Oct 2020 18:57:50 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6r-0002P9-RT; Thu, 08 Oct 2020 18:57:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb71-0005Rd-HC for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:57:59 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9873da21-24d2-457c-af46-bf5823508cc0; Thu, 08 Oct 2020 18:57:51 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6s-00042L-4O; Thu, 08 Oct 2020 18:57:50 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6r-0002P9-RT; Thu, 08 Oct 2020 18:57:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9873da21-24d2-457c-af46-bf5823508cc0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=RXDGKqvarznbbGXJp5zFlQUMeIoJk0IJ8cYPeqwtqQs=; b=rAfksRyRfbM1+KyVINSizjKsW7 s5ZYQtUw+GOOJZCSzw5hYA6ljgkke3rzD0gwKzLnGthpgP2tGuCHbmeGbgATInoETkuNNvJmdhG35 hqVaY2FjQBaANGFUy6bky3cOyVEFeTGprgfM9LU6N+s93WuFwHRk7yURWou6zR2Y6yOQ=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Wei Liu , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH v10 08/11] docs / tools: specify migration v4 to include DOMAIN_CONTEXT Date: Thu, 8 Oct 2020 19:57:32 +0100 Message-Id: <20201008185735.29875-9-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) From: Paul Durrant A new 'domain context' framework was recently introduced to facilitate transfer of state for both PV and HVM guests. Hence this patch mandates the presence of a new DOMAIN_CONTEXT record in version 4 of the libxc migration stream. This record will incorprate the content of the domain's 'shared_info' page and the TSC informition so the SHARED_INFO and TSC_INFO records are depreca= ted. It is intended that, in future, this record will contain state currently present in the HVM_CONTEXT record. However, for compatibility with earlier migration streams, the version 4 stream format continues to specify an HVM_CONTEXT record and XEN_DOMCTL_sethvmcontext will continue to accept all content of that record that may be present in a version 3 stream. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini Cc: "Marek Marczykowski-G=C3=B3recki" NOTE: Wei requested ack from Andrew v10: - Removed changes to xg_sr_common.c and libxc.py to make this a just documentation and header patch - Dropped Wei's A-b in light of change v7: - New in v7 --- docs/specs/libxc-migration-stream.pandoc | 62 ++++++++++++++++++------ tools/libs/guest/xg_sr_stream_format.h | 1 + 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/docs/specs/libxc-migration-stream.pandoc b/docs/specs/libxc-mi= gration-stream.pandoc index 8aeab3b11b..aa6fe284f3 100644 --- a/docs/specs/libxc-migration-stream.pandoc +++ b/docs/specs/libxc-migration-stream.pandoc @@ -3,7 +3,7 @@ Andrew Cooper <> Wen Congyang <> Yang Hongyang <> -% Revision 3 +% Revision 4 =20 Introduction =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -127,7 +127,7 @@ marker 0xFFFFFFFFFFFFFFFF. =20 id 0x58454E46 ("XENF" in ASCII). =20 -version 0x00000003. The version of this specification. +version 0x00000004. The version of this specification. =20 options bit 0: Endianness. 0 =3D little-endian, 1 =3D big-endian. =20 @@ -209,9 +209,9 @@ type 0x00000000: END =20 0x00000006: X86_PV_VCPU_XSAVE =20 - 0x00000007: SHARED_INFO + 0x00000007: SHARED_INFO (deprecated) =20 - 0x00000008: X86_TSC_INFO + 0x00000008: X86_TSC_INFO (deprecated) =20 0x00000009: HVM_CONTEXT =20 @@ -233,7 +233,9 @@ type 0x00000000: END =20 0x00000012: X86_MSR_POLICY =20 - 0x00000013 - 0x7FFFFFFF: Reserved for future _mandatory_ + 0x00000013: DOMAIN_CONTEXT + + 0x00000014 - 0x7FFFFFFF: Reserved for future _mandatory_ records. =20 0x80000000 - 0xFFFFFFFF: Reserved for future _optional_ @@ -442,10 +444,11 @@ X86_PV_VCPU_MSRS XEN_DOMCTL_{get,set}\_vc= pu_msrs =20 \clearpage =20 -SHARED_INFO ------------ +SHARED_INFO (deprecated) +------------------------ =20 -The content of the Shared Info page. +The content of the Shared Info page. This is incorporated into the +DOMAIN_CONTEXT record as of specification version 4. =20 0 1 2 3 4 5 6 7 octet +-------------------------------------------------+ @@ -462,11 +465,12 @@ shared_info Contents of the shared info page. T= his record =20 \clearpage =20 -X86_TSC_INFO ------------- +X86_TSC_INFO (deprecated) +------------------------- =20 Domain TSC information, as accessed by the -XEN_DOMCTL_{get,set}tscinfo hypercall sub-ops. +XEN_DOMCTL_{get,set}tscinfo hypercall sub-ops. This is incorporated into t= he +DOMAIN_CONTEXT record as of specification version 4. =20 0 1 2 3 4 5 6 7 octet +------------------------+------------------------+ @@ -680,6 +684,25 @@ MSR_policy Array of xen_msr_entry_t[]'s =20 \clearpage =20 +DOMAIN_CONTEXT +-------------- + +Domain context, as accessed by the +XEN_DOMCTL_{get,set}_domain_context hypercall sub-ops. + + 0 1 2 3 4 5 6 7 octet + +-------------------------------------------------+ + | dom_ctx | + ... + +-------------------------------------------------+ + +-------------------------------------------------------------------- +Field Description +----------- --------------------------------------------------- +dom_ctx The Domain Context blob from Xen. +-------------------------------------------------------------------- + +\clearpage =20 Layout =3D=3D=3D=3D=3D=3D @@ -706,8 +729,7 @@ A typical save record for an x86 PV guest image would l= ook like: * STATIC_DATA_END * X86_PV_P2M_FRAMES record * Many PAGE_DATA records -* X86_TSC_INFO -* SHARED_INFO record +* DOMAIN_CONTEXT * VCPU context records for each online VCPU * X86_PV_VCPU_BASIC record * X86_PV_VCPU_EXTENDED record @@ -735,7 +757,7 @@ A typical save record for an x86 HVM guest image would = look like: * X86_{CPUID,MSR}_POLICY * STATIC_DATA_END * Many PAGE_DATA records -* X86_TSC_INFO +* DOMAIN_CONTEXT * HVM_PARAMS * HVM_CONTEXT * END record @@ -746,6 +768,18 @@ the validity of architectural state in the context. Compatibility with older versions =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +v4 compat with v3 +----------------- + +A v4 stream is compatible with a v3 stream, but mandates the presence of a +DOMAIN_CONTEXT record. This incorporates context such as the content of +the domain's Shared Info page and the TSC information, hence the SHARED_IN= FO +and TSC_INFO records are deprecated. +It also supercedes HVM_CONTEXT and, over time, data that is currently part= of +the HVM_CONTEXT blob will move to the DOMAIN_CONTEXT blob. Xen, however, w= ill +continue to accept all defined HVM_CONTEXT records so a v4-compatible +receiver can still accept an unmodified v3 stream. + v3 compat with v2 ----------------- =20 diff --git a/tools/libs/guest/xg_sr_stream_format.h b/tools/libs/guest/xg_s= r_stream_format.h index 8a0da26f75..bc538bc192 100644 --- a/tools/libs/guest/xg_sr_stream_format.h +++ b/tools/libs/guest/xg_sr_stream_format.h @@ -76,6 +76,7 @@ struct xc_sr_rhdr #define REC_TYPE_STATIC_DATA_END 0x00000010U #define REC_TYPE_X86_CPUID_POLICY 0x00000011U #define REC_TYPE_X86_MSR_POLICY 0x00000012U +#define REC_TYPE_DOMAIN_CONTEXT 0x00000013U =20 #define REC_TYPE_OPTIONAL 0x80000000U =20 --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602183508; cv=none; d=zohomail.com; s=zohoarc; b=bF3DRZiGTXS/29Ei/Eo4539lqhVSLYqj6ikLmDJeOUgNI8IZ/tSnRT0JjNQceZl8Qp6XhjVoOfxMBtR07IxHGPdW6oRPRWhmmcALmABQ6ogEvFsdM8Pks2CrowPgVtWp8RuGiDzFsB7OPycoj+dNSzNpVwlKDJb0pwRDt/ndaRo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602183508; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D58UTgHV8FlNHLsedxEWdVpeTR0XSu26cm7AoQLQNpU=; b=GYSGv7fXQ/t1d7OQtBV+w2r1dvqJyd9tpSbIPU93WU+V++uOr0Fa44qR1OKvoKkdBu/4ma0bfhrFC1x6sW3ptIjTcNTZzMQFpuyY+3BjRkLqkdgCCZMZfhraHXRDaC+znoS8PVnFY/bZr+uDco0972Kf+rWTmLBPJbR/8TuKHO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602183508291234.36773913826823; Thu, 8 Oct 2020 11:58:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4566.12026 (Exim 4.92) (envelope-from ) id 1kQb7C-0005ze-1g; Thu, 08 Oct 2020 18:58:10 +0000 Received: by outflank-mailman (output) from mailman id 4566.12026; Thu, 08 Oct 2020 18:58:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb7B-0005zU-UL; Thu, 08 Oct 2020 18:58:09 +0000 Received: by outflank-mailman (input) for mailman id 4566; Thu, 08 Oct 2020 18:58:08 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb7A-0005RO-PI for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:58:08 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ebdf290f-2615-4289-be82-5b3bb9be3c6f; Thu, 08 Oct 2020 18:57:52 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6t-00042S-7Y; Thu, 08 Oct 2020 18:57:51 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6t-0002P9-03; Thu, 08 Oct 2020 18:57:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb7A-0005RO-PI for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 18:58:08 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ebdf290f-2615-4289-be82-5b3bb9be3c6f; Thu, 08 Oct 2020 18:57:52 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQb6t-00042S-7Y; Thu, 08 Oct 2020 18:57:51 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6t-0002P9-03; Thu, 08 Oct 2020 18:57:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ebdf290f-2615-4289-be82-5b3bb9be3c6f DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=D58UTgHV8FlNHLsedxEWdVpeTR0XSu26cm7AoQLQNpU=; b=Hi+X0PIXwE3MkDPPVg7LgaUgIy 1IT8qkoisipVVxs5J/J4D+7PangVK3a9UXTSWQucdbxGtyCTx8gRu9OcvjDB3VPqFHmU+ti3VZyN5 FaR26E7S5UZdCNP/drdWiJ7MeGKil7Hu1PmEhpBjbxgscOZeTVqU8ufWNGe7kpH3cC0E=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Andrew Cooper , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Ian Jackson , Wei Liu Subject: [PATCH v10 09/11] tools/python: modify libxc.py to verify v4 stream Date: Thu, 8 Oct 2020 19:57:33 +0100 Message-Id: <20201008185735.29875-10-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) From: Paul Durrant This patch adds code to verify the presence of a REC_TYPE_domain_context record in a v4 stream, as well as absence of REC_TYPE_shared_info and REC_TYPE_tsc_info records. Signed-off-by: Paul Durrant --- Cc: Andrew Cooper Cc: "Marek Marczykowski-G=C3=B3recki" Cc: Ian Jackson Cc: Wei Liu v10: - New in v10 --- tools/python/xen/migration/libxc.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/python/xen/migration/libxc.py b/tools/python/xen/migrati= on/libxc.py index 9881f5ced4..24fb50cbda 100644 --- a/tools/python/xen/migration/libxc.py +++ b/tools/python/xen/migration/libxc.py @@ -59,6 +59,7 @@ REC_TYPE_checkpoint_dirty_pfn_list =3D 0x0000000f REC_TYPE_static_data_end =3D 0x00000010 REC_TYPE_x86_cpuid_policy =3D 0x00000011 REC_TYPE_x86_msr_policy =3D 0x00000012 +REC_TYPE_domain_context =3D 0x00000013 =20 rec_type_to_str =3D { REC_TYPE_end : "End", @@ -80,6 +81,7 @@ rec_type_to_str =3D { REC_TYPE_static_data_end : "Static data end", REC_TYPE_x86_cpuid_policy : "x86 CPUID policy", REC_TYPE_x86_msr_policy : "x86 MSR policy", + REC_TYPE_domain_context : "Domain context", } =20 # page_data @@ -156,9 +158,9 @@ class VerifyLibxc(VerifyBase): raise StreamError("Bad image id: Expected 0x%x, got 0x%x" % (IHDR_IDENT, ident)) =20 - if not (2 <=3D version <=3D 3): + if not (2 <=3D version <=3D 4): raise StreamError( - "Unknown image version: Expected 2 <=3D ver <=3D 3, got %d= " % + "Unknown image version: Expected 2 <=3D ver <=3D 4, got %d= " % (version, )) =20 self.version =3D version @@ -362,6 +364,9 @@ class VerifyLibxc(VerifyBase): def verify_record_shared_info(self, content): """ shared info record """ =20 + if self.version >=3D 4: + raise RecordError("Shared info record found in v4 stream") + contentsz =3D len(content) if contentsz !=3D 4096: raise RecordError("Length expected to be 4906 bytes, not %d" % @@ -371,6 +376,9 @@ class VerifyLibxc(VerifyBase): def verify_record_tsc_info(self, content): """ tsc info record """ =20 + if self.version >=3D 4: + raise RecordError("TSC info record found in v4 stream") + sz =3D calcsize(X86_TSC_INFO_FORMAT) =20 if len(content) !=3D sz: @@ -476,6 +484,14 @@ class VerifyLibxc(VerifyBase): raise RecordError("Record length %u, expected multiple of %u" % (contentsz, sz)) =20 + def verify_record_domain_context(self, content): + """ domain context record """ + + if self.version < 4: + raise RecordError("Domain context record found in v3 stream") + + if len(content) =3D=3D 0: + raise RecordError("Zero length domain context") =20 record_verifiers =3D { REC_TYPE_end: @@ -526,4 +542,6 @@ record_verifiers =3D { VerifyLibxc.verify_record_x86_cpuid_policy, REC_TYPE_x86_msr_policy: VerifyLibxc.verify_record_x86_msr_policy, + REC_TYPE_domain_context: + VerifyLibxc.verify_record_domain_context, } --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602185000; cv=none; d=zohomail.com; s=zohoarc; b=J13EokF/FGS1A8de3fpwhnMBBJC4AE4DkRALs3XbGvHzGOVQRsOVyZzqNdUF0HjZyhYImzj4BXEiDKldIs7voVsYREd7V3R/Ag/mSUeJPZmraF9sQlgE1/rPu7ldL7rxkXmfO7EKWrC0K9nDRySQZ3DgLzfmZVqnU5I+7Ltw34g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602185000; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ci9ElP7+t6nSyjJlvsrEVOvf1v3Xr2+ABAE93SLLx1k=; b=TGZQ0GzoXmcGikkiZmNysSrsX1EPbsahLLdEW3qngLLM1ZfPq1Mu3etblsyx5X5Fjn4mCpC2QYa0f0uk0X0fyhRPQPPCTnpNIwie5YdPAAccTcCLznMoQbxgQcjz5LnJEaa9GdFPcM0Q98xcjxIm17hGV39IAQxbecbEZImVsuA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602185000106915.8114666471463; Thu, 8 Oct 2020 12:23:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4612.12169 (Exim 4.92) (envelope-from ) id 1kQbVG-000230-0n; Thu, 08 Oct 2020 19:23:02 +0000 Received: by outflank-mailman (output) from mailman id 4612.12169; Thu, 08 Oct 2020 19:23:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVF-00022t-Ty; Thu, 08 Oct 2020 19:23:01 +0000 Received: by outflank-mailman (input) for mailman id 4612; Thu, 08 Oct 2020 19:22:59 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVD-00022n-0J for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 19:22:59 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5ca40446-ffd0-4a4d-8213-18c2ccb5eaf2; Thu, 08 Oct 2020 19:22:58 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVA-0004dz-OJ; Thu, 08 Oct 2020 19:22:56 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6t-0002P9-WA; Thu, 08 Oct 2020 18:57:52 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVD-00022n-0J for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 19:22:59 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5ca40446-ffd0-4a4d-8213-18c2ccb5eaf2; Thu, 08 Oct 2020 19:22:58 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVA-0004dz-OJ; Thu, 08 Oct 2020 19:22:56 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6t-0002P9-WA; Thu, 08 Oct 2020 18:57:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5ca40446-ffd0-4a4d-8213-18c2ccb5eaf2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Ci9ElP7+t6nSyjJlvsrEVOvf1v3Xr2+ABAE93SLLx1k=; b=df3O5q3+SZF71Hv5AwwF8CGSdI wpSBcvUqgbAeFlsZ3g1+teZRisgnU6KTJuwHTayscSaZuy/sNf4CoFaHS19JHzR1+9LijZ/RL61d5 b4azNpI0UfcLk7/yCx98fieKlZW8hjhZwvfylZag2Qun96m+8xX+BW85SeahnMilBHns=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Andrew Cooper , Ian Jackson , Wei Liu Subject: [PATCH v10 10/11] tools/libs/guest: add code to restore a v4 libxc stream Date: Thu, 8 Oct 2020 19:57:34 +0100 Message-Id: <20201008185735.29875-11-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant This patch adds the necessary code to accept a v4 stream, and to recognise = and restore a REC_TYPE_DOMAIN_CONTEXT record. Signed-off-by: Paul Durrant --- Cc: Andrew Cooper Cc: Ian Jackson Cc: Wei Liu v10: - New in v10 - Derived from patch #8 of the v9 series - Fix memory leak --- tools/libs/guest/xg_sr_common.c | 1 + tools/libs/guest/xg_sr_common.h | 3 +++ tools/libs/guest/xg_sr_restore.c | 24 ++++++++++++++++++++++-- tools/libs/guest/xg_sr_restore_x86_hvm.c | 9 +++++++++ tools/libs/guest/xg_sr_restore_x86_pv.c | 9 +++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 17567ab133..f813320202 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -39,6 +39,7 @@ static const char *const mandatory_rec_types[] =3D [REC_TYPE_STATIC_DATA_END] =3D "Static data end", [REC_TYPE_X86_CPUID_POLICY] =3D "x86 CPUID policy", [REC_TYPE_X86_MSR_POLICY] =3D "x86 MSR policy", + [REC_TYPE_DOMAIN_CONTEXT] =3D "Domain context", }; =20 const char *rec_type_to_str(uint32_t type) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index cc3ad1c394..ba9e5b0a84 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -297,6 +297,9 @@ struct xc_sr_context =20 /* Sender has invoked verify mode on the stream. */ bool verify; + + /* Domain context blob. */ + struct xc_sr_blob dom_ctx; } restore; }; =20 diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index b57a787519..9d2bbdfaa3 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -35,9 +35,9 @@ static int read_headers(struct xc_sr_context *ctx) return -1; } =20 - if ( ihdr.version < 2 || ihdr.version > 3 ) + if ( ihdr.version < 2 || ihdr.version > 4 ) { - ERROR("Invalid Version: Expected 2 <=3D ver <=3D 3, Got %d", + ERROR("Invalid Version: Expected 2 <=3D ver <=3D 4, Got %d", ihdr.version); return -1; } @@ -682,6 +682,21 @@ int handle_static_data_end(struct xc_sr_context *ctx) return rc; } =20 +/* + * Process a DOMAIN_CONTEXT record from the stream. + */ +static int handle_domain_context(struct xc_sr_context *ctx, + struct xc_sr_record *rec) +{ + xc_interface *xch =3D ctx->xch; + int rc =3D update_blob(&ctx->restore.dom_ctx, rec->data, rec->length); + + if ( rc ) + ERROR("Unable to allocate %u bytes for domain context", rec->lengt= h); + + return rc; +} + static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *= rec) { xc_interface *xch =3D ctx->xch; @@ -709,6 +724,10 @@ static int process_record(struct xc_sr_context *ctx, s= truct xc_sr_record *rec) rc =3D handle_static_data_end(ctx); break; =20 + case REC_TYPE_DOMAIN_CONTEXT: + rc =3D handle_domain_context(ctx, rec); + break; + default: rc =3D ctx->restore.ops.process_record(ctx, rec); break; @@ -784,6 +803,7 @@ static void cleanup(struct xc_sr_context *ctx) =20 free(ctx->restore.buffered_records); free(ctx->restore.populated_pfns); + free(ctx->restore.dom_ctx.ptr); =20 if ( ctx->restore.ops.cleanup(ctx) ) PERROR("Failed to clean up"); diff --git a/tools/libs/guest/xg_sr_restore_x86_hvm.c b/tools/libs/guest/xg= _sr_restore_x86_hvm.c index d6ea6f3012..6bb164b9f0 100644 --- a/tools/libs/guest/xg_sr_restore_x86_hvm.c +++ b/tools/libs/guest/xg_sr_restore_x86_hvm.c @@ -225,6 +225,15 @@ static int x86_hvm_stream_complete(struct xc_sr_contex= t *ctx) return rc; } =20 + rc =3D xc_domain_set_context(xch, ctx->domid, + ctx->restore.dom_ctx.ptr, + ctx->restore.dom_ctx.size); + if ( rc ) + { + PERROR("Unable to restore Domain context"); + return rc; + } + rc =3D xc_dom_gnttab_seed(xch, ctx->domid, true, ctx->restore.console_gfn, ctx->restore.xenstore_gfn, diff --git a/tools/libs/guest/xg_sr_restore_x86_pv.c b/tools/libs/guest/xg_= sr_restore_x86_pv.c index dc50b0f5a8..2dafad7b83 100644 --- a/tools/libs/guest/xg_sr_restore_x86_pv.c +++ b/tools/libs/guest/xg_sr_restore_x86_pv.c @@ -1134,6 +1134,15 @@ static int x86_pv_stream_complete(struct xc_sr_conte= xt *ctx) if ( rc ) return rc; =20 + rc =3D xc_domain_set_context(xch, ctx->domid, + ctx->restore.dom_ctx.ptr, + ctx->restore.dom_ctx.size); + if ( rc ) + { + PERROR("Unable to restore Domain context"); + return rc; + } + rc =3D xc_dom_gnttab_seed(xch, ctx->domid, false, ctx->restore.console_gfn, ctx->restore.xenstore_gfn, --=20 2.20.1 From nobody Fri Mar 29 09:57:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1602185004; cv=none; d=zohomail.com; s=zohoarc; b=g+MSqmX1zrtDz1MjA32Wce4ordI7es5vyrViN/Xs8RgxJnHeTPTAMhu1DPuj6Xp3v8THuqZslN8/y/u3W5IFYThfJG4rHoT5GkcUWIhx5iSNNRUrjwn9H58Wk99nGZ2qC/YPGYJIxFwn93RbtNm1CdwkUZ97RSum012DEgY3mD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602185004; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NK7CpHuHkdziWvYnINTC4RC1wRqkyK5TJ03pOR95Gpw=; b=GfjxWm06zOgCm7njzqMYMxkwLdpI8ack5YN2jN9j5CjBNBbMmeEpWS0DbkYrhLceDPgiNVf2h6IfSxbrkLBeN/k55SJDdHZDyNaE6Aoyt5MXGPIiZg/PsSq8PxW3j5RQKxU9E6QPvbAY2AbJArD3N2QLKAL1luOfEZi4pKnTTMI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1602185004958179.60002864188277; Thu, 8 Oct 2020 12:23:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.4613.12182 (Exim 4.92) (envelope-from ) id 1kQbVJ-00024s-As; Thu, 08 Oct 2020 19:23:05 +0000 Received: by outflank-mailman (output) from mailman id 4613.12182; Thu, 08 Oct 2020 19:23:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVJ-00024k-5y; Thu, 08 Oct 2020 19:23:05 +0000 Received: by outflank-mailman (input) for mailman id 4613; Thu, 08 Oct 2020 19:23:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVH-00022n-V7 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 19:23:03 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 15f5fd7e-b207-46b1-9f4d-2ad76c0f10ab; Thu, 08 Oct 2020 19:22:58 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVA-0004dx-MV; Thu, 08 Oct 2020 19:22:56 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6u-0002P9-W8; Thu, 08 Oct 2020 18:57:53 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVH-00022n-V7 for xen-devel@lists.xenproject.org; Thu, 08 Oct 2020 19:23:03 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 15f5fd7e-b207-46b1-9f4d-2ad76c0f10ab; Thu, 08 Oct 2020 19:22:58 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQbVA-0004dx-MV; Thu, 08 Oct 2020 19:22:56 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQb6u-0002P9-W8; Thu, 08 Oct 2020 18:57:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 15f5fd7e-b207-46b1-9f4d-2ad76c0f10ab DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=NK7CpHuHkdziWvYnINTC4RC1wRqkyK5TJ03pOR95Gpw=; b=fgPKe+f5yoRg42ttK4I/VvlcO9 UL8ifZWH2gcHck4+lsRqprbrM2r3/gvTAUXtNiIAkxciGsycfdWXQTjkpSHKRWfLz6wTUCXuciwlE 3wHOrcUtitTYdZV5X6p+fKxDMCKykIx4oSE0RhMlA3sVcp5BvXsJ+ExhhwkfkPmJg1c8=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Andrew Cooper , Ian Jackson , Wei Liu Subject: [PATCH v10 11/11] tools/libs/guest: add code to save a v4 libxc stream Date: Thu, 8 Oct 2020 19:57:35 +0100 Message-Id: <20201008185735.29875-12-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008185735.29875-1-paul@xen.org> References: <20201008185735.29875-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant This patch adds the necessary code to save a REC_TYPE_DOMAIN_CONTEXT record, and stop saving the now obsolete REC_TYPE_SHARED_INFO and REC_TYPE_TSC_INFO records for PV guests. Signed-off-by: Paul Durrant --- Cc: Andrew Cooper Cc: Ian Jackson Cc: Wei Liu v10: - New in v10 - Derived from patch #8 of the v9 series --- tools/libs/guest/xg_sr_common_x86.c | 20 ----------- tools/libs/guest/xg_sr_common_x86.h | 6 ---- tools/libs/guest/xg_sr_save.c | 52 ++++++++++++++++++++++++++- tools/libs/guest/xg_sr_save_x86_hvm.c | 5 --- tools/libs/guest/xg_sr_save_x86_pv.c | 22 ------------ 5 files changed, 51 insertions(+), 54 deletions(-) diff --git a/tools/libs/guest/xg_sr_common_x86.c b/tools/libs/guest/xg_sr_c= ommon_x86.c index 6f12483907..10a35b998e 100644 --- a/tools/libs/guest/xg_sr_common_x86.c +++ b/tools/libs/guest/xg_sr_common_x86.c @@ -1,25 +1,5 @@ #include "xg_sr_common_x86.h" =20 -int write_x86_tsc_info(struct xc_sr_context *ctx) -{ - xc_interface *xch =3D ctx->xch; - struct xc_sr_rec_x86_tsc_info tsc =3D {}; - struct xc_sr_record rec =3D { - .type =3D REC_TYPE_X86_TSC_INFO, - .length =3D sizeof(tsc), - .data =3D &tsc, - }; - - if ( xc_domain_get_tsc_info(xch, ctx->domid, &tsc.mode, - &tsc.nsec, &tsc.khz, &tsc.incarnation) < 0= ) - { - PERROR("Unable to obtain TSC information"); - return -1; - } - - return write_record(ctx, &rec); -} - int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *re= c) { xc_interface *xch =3D ctx->xch; diff --git a/tools/libs/guest/xg_sr_common_x86.h b/tools/libs/guest/xg_sr_c= ommon_x86.h index b55758c96d..e504169705 100644 --- a/tools/libs/guest/xg_sr_common_x86.h +++ b/tools/libs/guest/xg_sr_common_x86.h @@ -3,12 +3,6 @@ =20 #include "xg_sr_common.h" =20 -/* - * Obtains a domains TSC information from Xen and writes a X86_TSC_INFO re= cord - * into the stream. - */ -int write_x86_tsc_info(struct xc_sr_context *ctx); - /* * Parses a X86_TSC_INFO record and applies the result to the domain. */ diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 2ba7c3200c..3eecc3e987 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -13,7 +13,7 @@ static int write_headers(struct xc_sr_context *ctx, uint1= 6_t guest_type) struct xc_sr_ihdr ihdr =3D { .marker =3D IHDR_MARKER, .id =3D htonl(IHDR_ID), - .version =3D htonl(3), + .version =3D htonl(4), .options =3D htons(IHDR_OPT_LITTLE_ENDIAN), }; struct xc_sr_dhdr dhdr =3D { @@ -44,6 +44,52 @@ static int write_headers(struct xc_sr_context *ctx, uint= 16_t guest_type) return 0; } =20 +/* + * Writes a DOMAIN_CONTEXT record into the stream. + */ +static int write_domain_context_record(struct xc_sr_context *ctx) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_record rec =3D { + .type =3D REC_TYPE_DOMAIN_CONTEXT, + }; + size_t len =3D 0; + int rc; + + rc =3D xc_domain_get_context(xch, ctx->domid, NULL, &len); + if ( rc < 0 ) + { + PERROR("can't get record length for dom %u\n", ctx->domid); + goto out; + } + + rec.data =3D malloc(len); + + rc =3D -1; + if ( !rec.data ) + { + PERROR("can't allocate %lu bytes\n", len); + goto out; + } + + rc =3D xc_domain_get_context(xch, ctx->domid, rec.data, &len); + if ( rc < 0 ) + { + PERROR("can't get domain record for dom %u\n", ctx->domid); + goto out; + } + + rec.length =3D len; + rc =3D write_record(ctx, &rec); + if ( rc < 0 ) + PERROR("failed to write DOMAIN_CONTEXT record"); + + out: + free(rec.data); + + return rc; +} + /* * Writes an END record into the stream. */ @@ -905,6 +951,10 @@ static int save(struct xc_sr_context *ctx, uint16_t gu= est_type) goto err; } =20 + rc =3D write_domain_context_record(ctx); + if ( rc ) + goto err; + rc =3D ctx->save.ops.end_of_checkpoint(ctx); if ( rc ) goto err; diff --git a/tools/libs/guest/xg_sr_save_x86_hvm.c b/tools/libs/guest/xg_sr= _save_x86_hvm.c index 1634a7bc43..d44fb3fc4f 100644 --- a/tools/libs/guest/xg_sr_save_x86_hvm.c +++ b/tools/libs/guest/xg_sr_save_x86_hvm.c @@ -193,11 +193,6 @@ static int x86_hvm_end_of_checkpoint(struct xc_sr_cont= ext *ctx) { int rc; =20 - /* Write the TSC record. */ - rc =3D write_x86_tsc_info(ctx); - if ( rc ) - return rc; - /* Write the HVM_CONTEXT record. */ rc =3D write_hvm_context(ctx); if ( rc ) diff --git a/tools/libs/guest/xg_sr_save_x86_pv.c b/tools/libs/guest/xg_sr_= save_x86_pv.c index 4964f1f7b8..3de7b19f54 100644 --- a/tools/libs/guest/xg_sr_save_x86_pv.c +++ b/tools/libs/guest/xg_sr_save_x86_pv.c @@ -849,20 +849,6 @@ static int write_x86_pv_p2m_frames(struct xc_sr_contex= t *ctx) return rc; } =20 -/* - * Writes an SHARED_INFO record into the stream. - */ -static int write_shared_info(struct xc_sr_context *ctx) -{ - struct xc_sr_record rec =3D { - .type =3D REC_TYPE_SHARED_INFO, - .length =3D PAGE_SIZE, - .data =3D ctx->x86.pv.shinfo, - }; - - return write_record(ctx, &rec); -} - /* * Normalise a pagetable for the migration stream. Performs mfn->pfn * conversions on the ptes. @@ -1093,14 +1079,6 @@ static int x86_pv_end_of_checkpoint(struct xc_sr_con= text *ctx) { int rc; =20 - rc =3D write_x86_tsc_info(ctx); - if ( rc ) - return rc; - - rc =3D write_shared_info(ctx); - if ( rc ) - return rc; - rc =3D write_all_vcpu_information(ctx); if ( rc ) return rc; --=20 2.20.1