From nobody Thu Mar 28 14:34:03 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=1600186712; cv=none; d=zohomail.com; s=zohoarc; b=P9mwKYp4gAFV920g6BZMkrJglye/nUGwr7I9LvF3vbpw1SYADEo/QSTYRZQaqQlSoiOi1cea/oF9EokxJq0pZ98wwu8oq+wAZOHkPZ4JmtOwRtIMAWekXnxPvReseCYeA6eBabXLPRUN7vhjR1+/RSScJe4Z9o3M1ABEbJ5Dg/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186712; 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=IHd8BSL7KylTdsh9YvRkNfQ0Z+VqRjSnuuLNjY9L5oc=; b=UZtFam/MFi/i+VTvg45i5Ex/JbUNlaVJiO+VbTYtE6+lcDWQ41kZ7jEfn8hHQHcpx0ksHJx2jxScKOZc7xiLkcHDvE8JrxBuK+j1H3fyD1W2RdBK0TPva+S2NMlmonOQ6L9fTBC2FsULb0D59UhO7mWuNol5XN65FOPVsU/JiTs= 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 1600186712279957.7199076914651; Tue, 15 Sep 2020 09:18:32 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDem-0001UK-7z; Tue, 15 Sep 2020 16:18:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDel-0001Sm-Ip for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:11 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 99347dbe-d410-45ab-bc99-5df7770a1dcd; Tue, 15 Sep 2020 16:18:05 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDef-00074k-BF; Tue, 15 Sep 2020 16:18:05 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDef-0000cN-17; Tue, 15 Sep 2020 16:18:05 +0000 X-Inumbo-ID: 99347dbe-d410-45ab-bc99-5df7770a1dcd 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=IHd8BSL7KylTdsh9YvRkNfQ0Z+VqRjSnuuLNjY9L5oc=; b=UWBP5OkILCGFVhv3N2t4WEkiFg tBjyhjEX+me+2txWT/aOGmwYBh8TDHB8x5LGvyi8CDNQRXxEyg6T8TQzzOg4yNReErHCfgKHe+nyJ EMAkiOyMEQkbEXDgcAqWsWUFaJ+1HK6oUduexAAtjufH9OSpE3qFsWCJ7sGtVP4wjymw=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Julien Grall , Jan Beulich , Andrew Cooper , George Dunlap , Ian Jackson , Stefano Stabellini , Wei Liu , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v8 1/8] xen/common: introduce a new framework for save/restore of 'domain' context Date: Tue, 15 Sep 2020 17:17:53 +0100 Message-Id: <20200915161800.1384-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @xen.org) 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 new public header and low level implementation of a new common framework, entered via the domain_save/load() functions. Subsequent patches will introduce other parts of the framework, and code that will make use of it within the current version of the libxc migration stream. This patch also marks the HVM-only framework as deprecated in favour of the new framework. Signed-off-by: Paul Durrant Acked-by: Julien Grall Reviewed-by: Jan Beulich --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Stefano Stabellini Cc: Wei Liu Cc: Volodymyr Babchuk Cc: "Roger Pau Monn=C3=A9" v7: - Add an option to domain_load_end() to ignore unconsumed data, which will be needed by a subsequent patch - Kept acks since the modification is very small v4: - Addressed further comments from Jan v3: - Addressed comments from Julien and Jan - Save handlers no longer need to state entry length up-front - Save handlers expected to deal with multiple instances internally - Entries are now auto-padded to 8 byte boundary v2: - Allow multi-stage save/load to avoid the need to double-buffer - Get rid of the masks and add an 'ignore' flag instead - Create copy function union to preserve const save buffer - Deprecate HVM-only framework --- xen/common/Makefile | 1 + xen/common/save.c | 315 +++++++++++++++++++++++++ xen/include/public/arch-arm/hvm/save.h | 5 + xen/include/public/arch-x86/hvm/save.h | 5 + xen/include/public/save.h | 89 +++++++ xen/include/xen/save.h | 170 +++++++++++++ 6 files changed, 585 insertions(+) create mode 100644 xen/common/save.c create mode 100644 xen/include/public/save.h 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..841c4d0e4e --- /dev/null +++ b/xen/common/save.c @@ -0,0 +1,315 @@ +/* + * save.c: Save and restore PV guest 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_context { + struct domain *domain; + const char *name; /* for logging purposes */ + struct domain_save_descriptor desc; + size_t len; /* for internal accounting */ + union { + const struct domain_save_ops *save; + const struct domain_load_ops *load; + } ops; + void *priv; +}; + +static struct { + const char *name; + domain_save_handler save; + domain_load_handler load; +} handlers[DOMAIN_SAVE_CODE_MAX + 1]; + +void __init domain_register_save_type(unsigned int typecode, + const char *name, + domain_save_handler save, + domain_load_handler load) +{ + BUG_ON(typecode >=3D ARRAY_SIZE(handlers)); + + ASSERT(!handlers[typecode].save); + ASSERT(!handlers[typecode].load); + + handlers[typecode].name =3D name; + handlers[typecode].save =3D save; + handlers[typecode].load =3D load; +} + +int domain_save_begin(struct domain_context *c, unsigned int typecode, + unsigned int instance) +{ + int rc; + + if ( typecode !=3D c->desc.typecode ) + { + ASSERT_UNREACHABLE(); + return -EINVAL; + } + ASSERT(!c->desc.length); /* Should always be zero during domain_save()= */ + ASSERT(!c->len); /* Verify domain_save_end() was called */ + + rc =3D c->ops.save->begin(c->priv, &c->desc); + if ( rc ) + return rc; + + return 0; +} + +int domain_save_data(struct domain_context *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; +} + +#define DOMAIN_SAVE_ALIGN 8 + +int domain_save_end(struct domain_context *c) +{ + struct domain *d =3D c->domain; + size_t len =3D ROUNDUP(c->len, DOMAIN_SAVE_ALIGN) - c->len; /* padding= */ + int rc; + + if ( len ) + { + static const uint8_t pad[DOMAIN_SAVE_ALIGN] =3D {}; + + rc =3D domain_save_data(c, pad, len); + + if ( rc ) + return rc; + } + ASSERT(IS_ALIGNED(c->len, DOMAIN_SAVE_ALIGN)); + + if ( c->name ) + gdprintk(XENLOG_INFO, "%pd save: %s[%u] +%zu (-%zu)\n", d, c->name, + c->desc.instance, c->len, len); + + rc =3D c->ops.save->end(c->priv, c->len); + c->len =3D 0; + + return rc; +} + +int domain_save(struct domain *d, const struct domain_save_ops *ops, + void *priv, bool dry_run) +{ + struct domain_context c =3D { + .domain =3D d, + .ops.save =3D ops, + .priv =3D priv, + }; + static const struct domain_save_header h =3D { + .magic =3D DOMAIN_SAVE_MAGIC, + .xen_major =3D XEN_VERSION, + .xen_minor =3D XEN_SUBVERSION, + .version =3D DOMAIN_SAVE_VERSION, + }; + const struct domain_save_end e =3D {}; + unsigned int i; + int rc; + + ASSERT(d !=3D current->domain); + domain_pause(d); + + c.name =3D !dry_run ? "HEADER" : NULL; + c.desc.typecode =3D DOMAIN_SAVE_CODE(HEADER); + + rc =3D DOMAIN_SAVE_ENTRY(HEADER, &c, 0, &h, sizeof(h)); + if ( rc ) + goto out; + + for ( i =3D 0; i < ARRAY_SIZE(handlers); i++ ) + { + domain_save_handler save =3D handlers[i].save; + + if ( !save ) + continue; + + c.name =3D !dry_run ? handlers[i].name : NULL; + memset(&c.desc, 0, sizeof(c.desc)); + c.desc.typecode =3D i; + + rc =3D save(d, &c, dry_run); + if ( rc ) + goto out; + } + + c.name =3D !dry_run ? "END" : NULL; + memset(&c.desc, 0, sizeof(c.desc)); + c.desc.typecode =3D DOMAIN_SAVE_CODE(END); + + rc =3D DOMAIN_SAVE_ENTRY(END, &c, 0, &e, sizeof(e)); + + out: + domain_unpause(d); + + return rc; +} + +int domain_load_begin(struct domain_context *c, unsigned int typecode, + unsigned int *instance) +{ + if ( typecode !=3D c->desc.typecode ) + { + ASSERT_UNREACHABLE(); + return -EINVAL; + } + + ASSERT(!c->len); /* Verify domain_load_end() was called */ + + *instance =3D c->desc.instance; + + return 0; +} + +int domain_load_data(struct domain_context *c, void *dst, size_t len) +{ + size_t copy_len =3D min_t(size_t, len, c->desc.length - c->len); + int rc; + + c->len +=3D copy_len; + ASSERT(c->len <=3D c->desc.length); + + rc =3D copy_len ? c->ops.load->read(c->priv, dst, copy_len) : 0; + if ( rc ) + return rc; + + /* Zero extend if the entry is exhausted */ + len -=3D copy_len; + if ( len ) + { + dst +=3D copy_len; + memset(dst, 0, len); + } + + return 0; +} + +int domain_load_end(struct domain_context *c, bool ignore_data) +{ + struct domain *d =3D c->domain; + size_t len =3D c->desc.length - c->len; + + while ( c->len !=3D c->desc.length ) /* unconsumed data or pad */ + { + uint8_t pad; + int rc =3D domain_load_data(c, &pad, sizeof(pad)); + + if ( rc ) + return rc; + + if ( !ignore_data && pad ) + return -EINVAL; + } + + ASSERT(c->name); + gdprintk(XENLOG_INFO, "%pd load: %s[%u] +%zu (-%zu)\n", d, c->name, + c->desc.instance, c->len, len); + + c->len =3D 0; + + return 0; +} + +int domain_load(struct domain *d, const struct domain_load_ops *ops, + void *priv) +{ + struct domain_context c =3D { + .domain =3D d, + .ops.load =3D ops, + .priv =3D priv, + }; + unsigned int instance; + struct domain_save_header h; + int rc; + + ASSERT(d !=3D current->domain); + + rc =3D c.ops.load->read(c.priv, &c.desc, sizeof(c.desc)); + if ( rc ) + return rc; + + c.name =3D "HEADER"; + + rc =3D DOMAIN_LOAD_ENTRY(HEADER, &c, &instance, &h, sizeof(h)); + if ( rc ) + return rc; + + if ( instance || h.magic !=3D DOMAIN_SAVE_MAGIC || + h.version !=3D DOMAIN_SAVE_VERSION ) + return -EINVAL; + + domain_pause(d); + + for (;;) + { + unsigned int i; + domain_load_handler load; + + rc =3D c.ops.load->read(c.priv, &c.desc, sizeof(c.desc)); + if ( rc ) + return rc; + + rc =3D -EINVAL; + + if ( c.desc.typecode =3D=3D DOMAIN_SAVE_CODE(END) ) + { + struct domain_save_end e; + + c.name =3D "END"; + + rc =3D DOMAIN_LOAD_ENTRY(END, &c, &instance, &e, sizeof(e)); + + if ( instance ) + return -EINVAL; + + break; + } + + i =3D c.desc.typecode; + if ( i >=3D ARRAY_SIZE(handlers) ) + break; + + c.name =3D handlers[i].name; + load =3D handlers[i].load; + + rc =3D load ? load(d, &c) : -EOPNOTSUPP; + if ( rc ) + break; + } + + domain_unpause(d); + + return rc; +} + +/* + * 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/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..551dbbddb8 --- /dev/null +++ b/xen/include/public/save.h @@ -0,0 +1,89 @@ +/* + * save.h + * + * Structure definitions for common PV/HVM domain state that is held by + * Xen and must be saved along with the domain's memory. + * + * 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" + +/* Entry data is preceded by a descriptor */ +struct domain_save_descriptor { + uint16_t typecode; + + /* + * Instance number of the entry (since there may be multiple of some + * types of entries). + */ + uint16_t instance; + + /* Entry length not including this descriptor */ + uint32_t length; +}; + +/* + * Each entry has a type associated with it. DECLARE_DOMAIN_SAVE_TYPE + * binds these things together, although it is not intended that the + * resulting type is ever instantiated. + */ +#define DECLARE_DOMAIN_SAVE_TYPE(_x, _code, _type) \ + struct DOMAIN_SAVE_TYPE_##_x { char c[_code]; _type t; }; + +#define DOMAIN_SAVE_CODE(_x) \ + (sizeof(((struct DOMAIN_SAVE_TYPE_##_x *)0)->c)) +#define DOMAIN_SAVE_TYPE(_x) \ + typeof(((struct DOMAIN_SAVE_TYPE_##_x *)0)->t) + +/* + * All entries will be zero-padded to the next 64-bit boundary when saved, + * so there is no need to include trailing pad fields in structure + * definitions. + * When loading, entries will be zero-extended if the load handler reads + * beyond the length specified in the descriptor. + */ + +/* Terminating entry */ +struct domain_save_end {}; +DECLARE_DOMAIN_SAVE_TYPE(END, 0, struct domain_save_end); + +#define DOMAIN_SAVE_MAGIC 0x53415645 +#define DOMAIN_SAVE_VERSION 0x00000001 + +/* Initial entry */ +struct domain_save_header { + uint32_t magic; /* Must be DOMAIN_SAVE_MAGIC */ + uint16_t xen_major, xen_minor; /* Xen version */ + uint32_t version; /* Save format version */ +}; +DECLARE_DOMAIN_SAVE_TYPE(HEADER, 1, struct domain_save_header); + +#define DOMAIN_SAVE_CODE_MAX 1 + +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ + +#endif /* XEN_PUBLIC_SAVE_H */ diff --git a/xen/include/xen/save.h b/xen/include/xen/save.h new file mode 100644 index 0000000000..e631a2e85e --- /dev/null +++ b/xen/include/xen/save.h @@ -0,0 +1,170 @@ +/* + * 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_context; + +int domain_save_begin(struct domain_context *c, unsigned int typecode, + unsigned int instance); + +#define DOMAIN_SAVE_BEGIN(x, c, i) \ + domain_save_begin((c), DOMAIN_SAVE_CODE(x), (i)) + +int domain_save_data(struct domain_context *c, const void *data, size_t le= n); +int domain_save_end(struct domain_context *c); + +static inline int domain_save_entry(struct domain_context *c, + unsigned int typecode, + unsigned int instance, const void *src, + size_t len) +{ + int rc; + + rc =3D domain_save_begin(c, typecode, instance); + if ( rc ) + return rc; + + rc =3D domain_save_data(c, src, len); + if ( rc ) + return rc; + + return domain_save_end(c); +} + +#define DOMAIN_SAVE_ENTRY(x, c, i, s, l) \ + domain_save_entry((c), DOMAIN_SAVE_CODE(x), (i), (s), (l)) + +int domain_load_begin(struct domain_context *c, unsigned int typecode, + unsigned int *instance); + +#define DOMAIN_LOAD_BEGIN(x, c, i) \ + domain_load_begin((c), DOMAIN_SAVE_CODE(x), (i)) + +int domain_load_data(struct domain_context *c, void *data, size_t len); +int domain_load_end(struct domain_context *c, bool ignore_data); + +static inline int domain_load_entry(struct domain_context *c, + unsigned int typecode, + unsigned int *instance, void *dst, + size_t len) +{ + int rc; + + rc =3D domain_load_begin(c, typecode, instance); + if ( rc ) + return rc; + + rc =3D domain_load_data(c, dst, len); + if ( rc ) + return rc; + + return domain_load_end(c, false); +} + +#define DOMAIN_LOAD_ENTRY(x, c, i, d, l) \ + domain_load_entry((c), DOMAIN_SAVE_CODE(x), (i), (d), (l)) + +/* + * The 'dry_run' flag indicates that the caller of domain_save() (see belo= w) + * 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_data() the correct number of times with accurate va= lues + * for 'len'. + */ +typedef int (*domain_save_handler)(const struct domain *d, + struct domain_context *c, + bool dry_run); +typedef int (*domain_load_handler)(struct domain *d, + struct domain_context *c); + +void domain_register_save_type(unsigned int typecode, const char *name, + domain_save_handler save, + domain_load_handler load); + +/* + * Register save and load handlers. + * + * 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_SAVE_LOAD(x, s, l) \ + static int __init __domain_register_##x##_save_load(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(x), \ + #x, \ + &(s), \ + &(l)); \ + \ + return 0; \ + } \ + __initcall(__domain_register_##x##_save_load); + +/* Callback functions */ +struct domain_save_ops { + /* + * Begin a new entry with the given descriptor (only type and instance + * are valid). + */ + int (*begin)(void *priv, const struct domain_save_descriptor *desc); + /* Append data/padding to the buffer */ + int (*append)(void *priv, const void *data, size_t len); + /* + * Complete the entry by updating the descriptor with the total + * length of the appended data (not including padding). + */ + int (*end)(void *priv, size_t len); +}; + +struct domain_load_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(struct domain *d, const struct domain_save_ops *ops, + void *priv, bool dry_run); +int domain_load(struct domain *d, const struct domain_load_ops *ops, + void *priv); + +#endif /* XEN_SAVE_H */ --=20 2.20.1 From nobody Thu Mar 28 14:34:03 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=1600186718; cv=none; d=zohomail.com; s=zohoarc; b=RmwoEr91ppkf8MkKvvBKpQS18mmVMJWsd23B6rNpbqXdquxX8Jmjco8i2axPnUOH9fW/Eyzb7tk7OrNndMDfGx+Ld9cG8QpiORWttHn0R9KkHsN9ZZxuBE5VGEYnlD1ZQ6OJB2QOXZ+MwnCgN+Irr68AVqUx7b+0rQ4+AfsjArg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186718; 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=fOmu4uwdmmRDxWfAjQS0ff+qckmBVmI3n81Zlz993QU=; b=PADNZEJRvN6+D4MGZFQpbeAktitKxt9QNq+tN+lZDb1cmrY9EX87/mTMZOaMJJTtYiKip/0aKyKHxjPFCOIPeCybdMt7vavyanTMSKCdK3BjSHabdyhgdq1LDvBdY2lptWZg4B04vOKMHxD4WoaNNlOudTCs+1SLDu340TXgg58= 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 1600186718174907.4169928300649; Tue, 15 Sep 2020 09:18:38 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDeq-0001W3-ID; Tue, 15 Sep 2020 16:18:16 +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 1kIDeo-0001TA-UK for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:14 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8bf022e4-74f4-4678-bfdd-242188628425; Tue, 15 Sep 2020 16:18:08 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDeg-00074s-Pu; Tue, 15 Sep 2020 16:18:06 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDeg-0000cN-Hx; Tue, 15 Sep 2020 16:18:06 +0000 X-Inumbo-ID: 8bf022e4-74f4-4678-bfdd-242188628425 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=fOmu4uwdmmRDxWfAjQS0ff+qckmBVmI3n81Zlz993QU=; b=NDy0hKWBCapK91CNElrGHpqnLw ozhjTm5jtMYx05G2gGUPNJYtdfXkPae3zclsFZ7q7XApmxhByFkTYbzryZrFLW31Uv/X0w27gcO1x ENM1UMe7ud1AAxKdWFNjP9WC8KCQjbimsu1hrU7Du0v8Y2o6eswpF28ImaO4o7TsFEtg=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Julien Grall , Daniel De Graaf , Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Jan Beulich , Stefano Stabellini Subject: [PATCH v8 2/8] xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontext Date: Tue, 15 Sep 2020 17:17:54 +0100 Message-Id: <20200915161800.1384-3-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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. Signed-off-by: Paul Durrant Reviewed-by: Julien Grall --- Cc: Daniel De Graaf Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Stefano Stabellini 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/libxc/include/xenctrl.h | 5 + tools/libxc/xc_domain.c | 56 +++++++++ xen/common/domctl.c | 173 ++++++++++++++++++++++++++++ xen/include/public/domctl.h | 41 +++++++ xen/xsm/flask/hooks.c | 6 + xen/xsm/flask/policy/access_vectors | 4 + 7 files changed, 287 insertions(+), 2 deletions(-) diff --git a/tools/flask/policy/modules/xen.if b/tools/flask/policy/modules= /xen.if index 8eb2293a52..2bc9db4f64 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 setcontext }; 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 getcontext }; allow $1 $2:shadow { enable disable logdirty }; ') =20 diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 4c89b7294c..5eb04dcb38 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/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_getcontext(xc_interface *xch, uint32_t domid, + void *ctxt_buf, size_t *size); +int xc_domain_setcontext(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/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 71829c2bce..e462a6f728 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -537,6 +537,62 @@ int xc_domain_hvm_setcontext(xc_interface *xch, return ret; } =20 +int xc_domain_getcontext(xc_interface *xch, uint32_t domid, + void *ctxt_buf, size_t *size) +{ + int ret; + DECLARE_DOMCTL =3D { + .cmd =3D XEN_DOMCTL_getdomaincontext, + .domain =3D domid, + .u.getdomaincontext.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.setdomaincontext.buffer, ctxt_buf); + + ret =3D do_domctl(xch, &domctl); + + xc_hypercall_bounce_post(xch, ctxt_buf); + + if ( ret ) + return ret; + + *size =3D domctl.u.getdomaincontext.size; + if ( *size !=3D domctl.u.getdomaincontext.size ) + { + errno =3D EOVERFLOW; + return -1; + } + + return 0; +} + +int xc_domain_setcontext(xc_interface *xch, uint32_t domid, + const void *ctxt_buf, size_t size) +{ + int ret; + DECLARE_DOMCTL =3D { + .cmd =3D XEN_DOMCTL_setdomaincontext, + .domain =3D domid, + .u.setdomaincontext.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.setdomaincontext.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 5ac6e9c5ca..8ce5e7a2fa 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_save_descriptor *desc; + 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_save_descriptor *= desc) +{ + return dry_run_append(priv, NULL, sizeof(*desc)); +} + +static int dry_run_end(void *priv, size_t len) +{ + return 0; +} + +static struct domain_save_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_save_descriptor *des= c) +{ + struct domctl_context *c =3D priv; + + if ( c->len - c->cur < sizeof(*desc) ) + return -ENOSPC; + + c->desc =3D c->buffer + c->cur; /* stash pointer to descriptor */ + *c->desc =3D *desc; + + c->cur +=3D sizeof(*desc); + + 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->desc->length =3D len; + + return 0; +} + +static struct domain_save_ops save_ops =3D { + .begin =3D save_begin, + .append =3D save_append, + .end =3D save_end, +}; + +static int getdomaincontext(struct domain *d, + struct xen_domctl_getdomaincontext *gdc) +{ + struct domctl_context c =3D { .buffer =3D ZERO_BLOCK_PTR }; + int rc; + + if ( d =3D=3D current->domain ) + return -EPERM; + + if ( gdc->pad ) + return -EINVAL; + + 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(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(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_ops load_ops =3D { + .read =3D load_read, +}; + +static int setdomaincontext(struct domain *d, + const struct xen_domctl_setdomaincontext *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; + + if ( sdc->pad ) + return -EINVAL; + + c.buffer =3D vmalloc(c.len); + if ( !c.buffer ) + return -ENOMEM; + + rc =3D !copy_from_guest(c.buffer, sdc->buffer, c.len) ? + domain_load(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; @@ -857,6 +1021,15 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) copyback =3D 1; break; =20 + case XEN_DOMCTL_getdomaincontext: + ret =3D getdomaincontext(d, &op->u.getdomaincontext); + copyback =3D !ret; + break; + + case XEN_DOMCTL_setdomaincontext: + ret =3D setdomaincontext(d, &op->u.setdomaincontext); + 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 9464a9058a..a889719323 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1135,6 +1135,43 @@ struct xen_domctl_vuart_op { */ }; =20 +/* + * XEN_DOMCTL_getdomaincontext + * --------------------------- + * + * 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_getdomaincontext { + uint32_t size; + uint32_t pad; + XEN_GUEST_HANDLE_64(void) buffer; +}; + +/* XEN_DOMCTL_setdomaincontext + * --------------------------- + * + * 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_setdomaincontext { + uint32_t size; + uint32_t pad; + XEN_GUEST_HANDLE_64(const_void) buffer; +}; + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1216,6 +1253,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_getdomaincontext 84 +#define XEN_DOMCTL_setdomaincontext 85 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1277,6 +1316,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_getdomaincontext getdomaincontext; + struct xen_domctl_setdomaincontext setdomaincontext; uint8_t pad[128]; } u; }; diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index a314bf85ce..4cbf787b1f 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -745,6 +745,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_setdomaincontext: + return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SETCONTEXT); + + case XEN_DOMCTL_getdomaincontext: + return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__GETCONTEXT); + 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 b87c99ea98..54a2759886 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_setdomaincontext + setcontext +# XEN_DOMCTL_getdomaincontext + getcontext } =20 # Similar to class domain, but primarily contains domctls related to HVM d= omains --=20 2.20.1 From nobody Thu Mar 28 14:34:03 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=1600186711; cv=none; d=zohomail.com; s=zohoarc; b=MmJ6INJf0MkEbGj3czw9tC7GySgSO4Ev+3XoLyao07mx9bSdXB3Py3kydEzPedHuLKb/y4/3QrZpb1bYaA3hVhzG5nTeKvGlmagCRiSXLIJW4npgL15DhK8m7hMDT3Tjpua+bvXbcHlrWwQaBdswLZtqyCnbIuwJ0lBiwx8du3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186711; 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=Y0HCKsMN0PcOgvgo5WZ1uaZi3nKY5js10zrLVkDxRtY=; b=nzXQjd9SAjnPXL5yRHHbqPuLJMBRLzEYCISvCVdFKNlm5n5OBNw/fOZ699kA2gz2RbGLZJAZXc7rtMp7xTXIiY6wOyfuUT7+R6mEIresDTMUpUJ9HsOrscsDE3IyBPqsHhvq1M6zbytRJ3IISK9HdgpSt8VNtJBeUE3N/q97jS0= 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 160018671155857.19278409871299; Tue, 15 Sep 2020 09:18:31 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDek-0001TK-S5; Tue, 15 Sep 2020 16:18:10 +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 1kIDek-0001TA-0m for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:10 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 927c3778-8e2e-48c7-b3e7-ebbd617d5562; Tue, 15 Sep 2020 16:18:08 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDeh-00074x-Pi; Tue, 15 Sep 2020 16:18:07 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDeh-0000cN-Hy; Tue, 15 Sep 2020 16:18:07 +0000 X-Inumbo-ID: 927c3778-8e2e-48c7-b3e7-ebbd617d5562 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=Y0HCKsMN0PcOgvgo5WZ1uaZi3nKY5js10zrLVkDxRtY=; b=B0wSMW7ZwT9l/lSO1Ii/HEY0WO Yy4qD69oExOu+CyMKZfv2qh5wlkY8lOHHGo0Godfhxi4gMz7sICXTN04mmmBKQnlTKpddufBKCaLc uzg1vvmMuPv1lslKDTd6ZkuK658T66IAKcafqE953DmMJRMAfLr+U2qnPfUFVG770Jj4=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Andrew Cooper , Wei Liu Subject: [PATCH v8 3/8] tools/misc: add xen-domctx to present domain context Date: Tue, 15 Sep 2020 17:17:55 +0100 Message-Id: <20200915161800.1384-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 --- Cc: Andrew Cooper Cc: Wei Liu NOTE: Ian requested ack from Andrew 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 | 200 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 tools/misc/xen-domctx.c diff --git a/.gitignore b/.gitignore index 823f4743dc..cadb29ea23 100644 --- a/.gitignore +++ b/.gitignore @@ -212,6 +212,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 9fdb13597f..13e37402e2 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -31,6 +31,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/ @@ -114,6 +115,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..243325dfce --- /dev/null +++ b/tools/misc/xen-domctx.c @@ -0,0 +1,200 @@ +/* + * 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 + +static void *buf =3D NULL; +static size_t len, off; + +#define GET_PTR(_x) = \ + do { = \ + if ( len - off < sizeof(*(_x)) ) = \ + { = \ + fprintf(stderr, = \ + "error: need another %lu bytes, only %lu available\n",= \ + sizeof(*(_x)), len - off); = \ + exit(1); = \ + } = \ + (_x) =3D buf + off; = \ + } while (false); + +static void dump_header(void) +{ + DOMAIN_SAVE_TYPE(HEADER) *h; + + GET_PTR(h); + + printf(" HEADER: magic %#x, version %u\n", + h->magic, h->version); + +} + +static void dump_end(void) +{ + DOMAIN_SAVE_TYPE(END) *e; + + GET_PTR(e); + + printf(" END\n"); +} + +static void usage(const char *prog) +{ + fprintf(stderr, "usage: %s [ [ ]]\n", + prog); + exit(1); +} + +int main(int argc, char **argv) +{ + char *s, *e; + long domid; + long typecode =3D -1; + long instance =3D -1; + unsigned int entry; + xc_interface *xch; + int rc; + + if ( argc < 2 || argc > 4 ) + usage(argv[0]); + + 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 ) + { + fprintf(stderr, "invalid domid '%s'\n", s); + exit(1); + } + + if ( argc >=3D 3 ) + { + s =3D e =3D argv[2]; + typecode =3D strtol(s, &e, 0); + + if ( *s =3D=3D '\0' || *e !=3D '\0' ) + { + fprintf(stderr, "invalid typecode '%s'\n", s); + exit(1); + } + } + + 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' ) + { + fprintf(stderr, "invalid instance '%s'\n", s); + exit(1); + } + } + + xch =3D xc_interface_open(0, 0, 0); + if ( !xch ) + { + fprintf(stderr, "error: can't open libxc handle\n"); + exit(1); + } + + rc =3D xc_domain_getcontext(xch, domid, NULL, &len); + if ( rc < 0 ) + { + fprintf(stderr, "error: can't get record length for dom %lu: %s\n", + domid, strerror(errno)); + exit(1); + } + + buf =3D malloc(len); + if ( !buf ) + { + fprintf(stderr, "error: can't allocate %lu bytes\n", len); + exit(1); + } + + rc =3D xc_domain_getcontext(xch, domid, buf, &len); + if ( rc < 0 ) + { + fprintf(stderr, "error: can't get domain record for dom %lu: %s\n", + domid, strerror(errno)); + exit(1); + } + off =3D 0; + + entry =3D 0; + for ( ; ; ) + { + struct domain_save_descriptor *desc; + + GET_PTR(desc); + + off +=3D sizeof(*desc); + + if ( (typecode < 0 || typecode =3D=3D desc->typecode) && + (instance < 0 || instance =3D=3D desc->instance) ) + { + printf("[%u] type: %u instance: %u length: %u\n", entry++, + desc->typecode, desc->instance, desc->length); + + switch (desc->typecode) + { + case DOMAIN_SAVE_CODE(HEADER): dump_header(); break; + case DOMAIN_SAVE_CODE(END): dump_end(); break; + default: + printf("Unknown type %u: skipping\n", desc->typecode); + break; + } + } + + if ( desc->typecode =3D=3D DOMAIN_SAVE_CODE(END) ) + break; + + off +=3D desc->length; + } + + 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 Thu Mar 28 14:34:03 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=1600186712; cv=none; d=zohomail.com; s=zohoarc; b=G+FnAnU7MQiBFUmgk5sZ4DauIiFWkcdRYmq1vrdKKi3VucJhosrqLdQ6O4qc7l0A9cpSXA42vWkDukfXruZgsIkQWrHSTTas4KcUJQvmuP427ljkaNBJv8yFYJv2AzqL/19Lm8b3lgGhxhK6Q8MopstzhqPvGJeYUczUYLlXBNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186712; 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=Q48nB/F4uU8xPjTIE8qhVPPBlboQ5C2A8+ikvUg0FYs=; b=gRQX7IJsYrfc5ARhrsbMEYHPtjGCyt8Jg+qQkM0w6EXC68ey5muQ0bGF863O4YfrfQYq/j/wTw8YVPdyUNs8/Tvmmn7A5a++KXefdpMK7gaaCTrvSaCNWqEz8RbMj9rTjKGch4laMu8pNUC2ToWT32LzkKqJ09pJtnZ6nVa/bzE= 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 1600186712300737.7740780732887; Tue, 15 Sep 2020 09:18:32 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDer-0001Wu-1k; Tue, 15 Sep 2020 16:18:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDeq-0001Sm-JA for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:16 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id fefc4ebd-cad3-4a11-afd7-ad881786b514; Tue, 15 Sep 2020 16:18:09 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDej-000757-6F; Tue, 15 Sep 2020 16:18:09 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDei-0000cN-Uw; Tue, 15 Sep 2020 16:18:09 +0000 X-Inumbo-ID: fefc4ebd-cad3-4a11-afd7-ad881786b514 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=Q48nB/F4uU8xPjTIE8qhVPPBlboQ5C2A8+ikvUg0FYs=; b=2iDx526W5Fjk+pNOQ4I2hC649A gLHy2sE3DscrPYQq0omFLsn0KjM+JXNGRwRSOub79O8XbxyA8pZsV7MkN5aryvXSOKv1zS6LPGSil BBXABxGAxKSVH/FkIYfY6j2jX4FGtaOedqYpGW3KBQwlEgeeKvQLMgJTul5Ua+q7fkyk=; 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 v8 4/8] docs/specs: add missing definitions to libxc-migration-stream Date: Tue, 15 Sep 2020 17:17:56 +0100 Message-Id: <20200915161800.1384-5-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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= ") --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini Cc: Wei Liu 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 Thu Mar 28 14:34:03 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=1600186718; cv=none; d=zohomail.com; s=zohoarc; b=Jq90z+uXbxL8PVWX5pubwI1LhZ6jc+/1HyJ0KX0hRz4XOcj8BA6V1NFIrEySFcb3p35Ogigil7A4P2js7PscKhsTaJaR8vJ6rZmlPh9HSy6pg6URLrSvRCCvIOsuhvrbtWHSF/BsW7MnyO1WX1T1AkJ5tm9fD4zqPy6Z8D7u03c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186718; 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=9B06LaTam4r9aPcamK/16qRY4ae2xUL3Egxlq2b/Qp0=; b=ZYKv+oFfGGp9Gf/BloUEW4BXQuhxVGkVBs0w0e8VoQHWbOaweziiulfQbLn0YvveQLOs7rwDEeXtuJ5vitQM/hHUQB49FauB9tTa9GMu12tSuV383J4u+8z62/fXLOfMkSyuMg7s7DX/hGea0ZsHdOaozq07LAGyWSvsxlqBEP4= 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 1600186718618484.176069761246; Tue, 15 Sep 2020 09:18:38 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDew-0001aS-Ku; Tue, 15 Sep 2020 16:18:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDev-0001Sm-Jh for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:21 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 65a96756-f278-4bd7-b9c6-3087a866382f; Tue, 15 Sep 2020 16:18:11 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDek-00075K-MN; Tue, 15 Sep 2020 16:18:10 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDek-0000cN-Em; Tue, 15 Sep 2020 16:18:10 +0000 X-Inumbo-ID: 65a96756-f278-4bd7-b9c6-3087a866382f 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=9B06LaTam4r9aPcamK/16qRY4ae2xUL3Egxlq2b/Qp0=; b=J0PWWpGQueahgBaeq/TjXlE/p4 rtO2tuNl2IjzIhQ8wTKXTmkEADumXrH5UKJ1hvvIA1d9Gc0G6o5+hunfZjjsQFaHAjeLlBqPC3kTf UdyKuI6ZxdS5P8ZfoZaNgm5sMv/RFI/dtnDViLUy12Qt9HH2Uplg9hbBBfp3AnJXoqH4=; 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 , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH v8 5/8] docs / tools: specific migration v4 to include DOMAIN_CONTEXT Date: Tue, 15 Sep 2020 17:17:57 +0100 Message-Id: <20200915161800.1384-6-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 informaiton 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: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini Cc: Wei Liu Cc: "Marek Marczykowski-G=C3=B3recki" v7: - New in v7 --- docs/specs/libxc-migration-stream.pandoc | 62 ++++++++++++++++++------ tools/libxc/xc_sr_common.c | 1 + tools/libxc/xc_sr_stream_format.h | 1 + tools/python/xen/migration/libxc.py | 2 + 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/docs/specs/libxc-migration-stream.pandoc b/docs/specs/libxc-mi= gration-stream.pandoc index 8aeab3b11b..989f2a0cb6 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}domaincontext 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/libxc/xc_sr_common.c b/tools/libxc/xc_sr_common.c index 7c54b03414..2fdb6e6634 100644 --- a/tools/libxc/xc_sr_common.c +++ b/tools/libxc/xc_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/libxc/xc_sr_stream_format.h b/tools/libxc/xc_sr_stream_f= ormat.h index 8a0da26f75..bc538bc192 100644 --- a/tools/libxc/xc_sr_stream_format.h +++ b/tools/libxc/xc_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 diff --git a/tools/python/xen/migration/libxc.py b/tools/python/xen/migrati= on/libxc.py index 9881f5ced4..08ac81344f 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 --=20 2.20.1 From nobody Thu Mar 28 14:34:03 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=1600186719; cv=none; d=zohomail.com; s=zohoarc; b=XIjbShDef/N4HZtDtS/36R5+ic5pa81ivt198S+0qtimBZEKiVkLrtcW+Mx0R5y+k/V+Pjq/Sxp/CCOHnDX/RsZbx7gKRDtaoelgekOCiulljpBVuKvfadFUxJeiF3Id2az2L7QjL0QPchJVgzifstFS0fAftDUY6urjBohS5Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186719; 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=M8+UCfBnDkPwUvAq7NIm9OKh0hY4HyBdcyPNDLGAcvA=; b=kbX3JA7ZDBj/xLHftC7GE5abHnvvu7U6mJ42Mmw0fbz+7tjWDJSNgwgXtcTXSEKkyPRQ5tpDzPT4jMkX/cvypc3BeaaMTAd09SSjY+ColkJd22/jkbfUaro+kHeLOTm2nFTs5wD0/B3G7ieswQy6RxFa+82tLdjOqjEyy6GofEc= 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 1600186719133740.2214477223513; Tue, 15 Sep 2020 09:18:39 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDev-0001ZP-BY; Tue, 15 Sep 2020 16:18:21 +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 1kIDet-0001TA-UZ for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:19 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6dbd685a-31c9-450a-8b1a-e265ceef0fb9; Tue, 15 Sep 2020 16:18:12 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDem-00075T-38; Tue, 15 Sep 2020 16:18:12 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDel-0000cN-Rh; Tue, 15 Sep 2020 16:18:12 +0000 X-Inumbo-ID: 6dbd685a-31c9-450a-8b1a-e265ceef0fb9 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=M8+UCfBnDkPwUvAq7NIm9OKh0hY4HyBdcyPNDLGAcvA=; b=Ao1l67nWK+2kjibWyOd9Evv9YI /1uznTRFChZYqQuq5Qd0C4p6K2PkdkwChNHApGj6AqWwJm1f6WZhtXLBCPOFupJgy2Iqt9d0EiN8j Nif8C5/xIl5bCSl2BMDN6S4xy3S4vSbcUXL+7PtyzBBqmdmRNmdsLqsz4Hylamhathe0=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v8 6/8] common/domain: add a domain context record for shared_info... Date: Tue, 15 Sep 2020 17:17:58 +0100 Message-Id: <20200915161800.1384-7-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini 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 --- tools/misc/xen-domctx.c | 78 +++++++++++++++++++++ xen/common/domain.c | 144 ++++++++++++++++++++++++++++++++++++++ xen/include/public/save.h | 13 +++- 3 files changed, 234 insertions(+), 1 deletion(-) diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c index 243325dfce..6ead7ea89d 100644 --- a/tools/misc/xen-domctx.c +++ b/tools/misc/xen-domctx.c @@ -31,6 +31,7 @@ #include =20 #include +#include #include #include #include @@ -61,6 +62,82 @@ static void dump_header(void) =20 } =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) +{ + DOMAIN_SAVE_TYPE(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_SAVE_32BIT_SHINFO; + + printf(" SHARED_INFO: has_32bit_shinfo: %s buffer_size: %u\n", + has_32bit_shinfo ? "true" : "false", s->buffer_size); + + 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\n", + GET_FIELD(wc_version), GET_FIELD(wc_sec), GET_FIELD(wc_nsec)); + +#undef GET_FIELD +#undef GET_FIELD_SIZE +#undef GET_FIELD_PTR +} + static void dump_end(void) { DOMAIN_SAVE_TYPE(END) *e; @@ -173,6 +250,7 @@ int main(int argc, char **argv) switch (desc->typecode) { case DOMAIN_SAVE_CODE(HEADER): dump_header(); break; + case DOMAIN_SAVE_CODE(SHARED_INFO): dump_shared_info(); break; case DOMAIN_SAVE_CODE(END): dump_end(); break; default: printf("Unknown type %u: skipping\n", desc->typecode); diff --git a/xen/common/domain.c b/xen/common/domain.c index f0f9c62feb..2375e250af 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1659,6 +1660,149 @@ int continue_hypercall_on_cpu( return 0; } =20 +static int save_shared_info(const struct domain *d, struct domain_context = *c, + bool dry_run) +{ + struct domain_shared_info_context ctxt =3D { +#ifdef CONFIG_COMPAT + .flags =3D has_32bit_shinfo(d) ? DOMAIN_SAVE_32BIT_SHINFO : 0, + .buffer_size =3D has_32bit_shinfo(d) ? + sizeof(struct compat_shared_info) : + sizeof(struct shared_info), +#else + .buffer_size =3D sizeof(struct shared_info), +#endif + }; + size_t hdr_size =3D offsetof(typeof(ctxt), buffer); + int rc; + + rc =3D DOMAIN_SAVE_BEGIN(SHARED_INFO, c, 0); + if ( rc ) + return rc; + + rc =3D domain_save_data(c, &ctxt, hdr_size); + if ( rc ) + return rc; + + rc =3D domain_save_data(c, d->shared_info, ctxt.buffer_size); + if ( rc ) + return rc; + + return domain_save_end(c); +} + +static int load_shared_info(struct domain *d, struct domain_context *c) +{ + struct domain_shared_info_context ctxt; + size_t hdr_size =3D offsetof(typeof(ctxt), buffer); + unsigned int i; + int rc; + + rc =3D DOMAIN_LOAD_BEGIN(SHARED_INFO, c, &i); + if ( rc ) + return rc; + + if ( i ) /* expect only a single instance */ + return -ENXIO; + + rc =3D domain_load_data(c, &ctxt, hdr_size); + if ( rc ) + return rc; + + if ( ctxt.buffer_size > sizeof(shared_info_t) || + (ctxt.flags & ~DOMAIN_SAVE_32BIT_SHINFO) ) + return -EINVAL; + + if ( ctxt.flags & DOMAIN_SAVE_32BIT_SHINFO ) + { +#ifdef CONFIG_COMPAT + has_32bit_shinfo(d) =3D true; +#else + return -EINVAL; +#endif + } + + if ( is_pv_domain(d) ) + { + shared_info_t *shinfo =3D xmalloc(shared_info_t); + + rc =3D domain_load_data(c, shinfo, sizeof(*shinfo)); + if ( rc ) + { + xfree(shinfo); + return rc; + } + +#ifdef CONFIG_COMPAT + if ( has_32bit_shinfo(d) ) + { + memcpy(&d->shared_info->compat.vcpu_info, + &shinfo->compat.vcpu_info, + sizeof(d->shared_info->compat.vcpu_info)); + memcpy(&d->shared_info->compat.arch, + &shinfo->compat.arch, + sizeof(d->shared_info->compat.vcpu_info)); + memset(&d->shared_info->compat.evtchn_pending, + 0, + sizeof(d->shared_info->compat.evtchn_pending)); + memset(&d->shared_info->compat.evtchn_mask, + 0xff, + sizeof(d->shared_info->compat.evtchn_mask)); + + d->shared_info->compat.arch.pfn_to_mfn_frame_list_list =3D 0; + for ( i =3D 0; i < XEN_LEGACY_MAX_VCPUS; i++ ) + d->shared_info->compat.vcpu_info[i].evtchn_pending_sel =3D= 0; + } + else + { + memcpy(&d->shared_info->native.vcpu_info, + &shinfo->native.vcpu_info, + sizeof(d->shared_info->native.vcpu_info)); + memcpy(&d->shared_info->native.arch, + &shinfo->native.arch, + sizeof(d->shared_info->native.arch)); + memset(&d->shared_info->native.evtchn_pending, + 0, + sizeof(d->shared_info->compat.evtchn_pending)); + memset(&d->shared_info->native.evtchn_mask, + 0xff, + sizeof(d->shared_info->native.evtchn_mask)); + + d->shared_info->native.arch.pfn_to_mfn_frame_list_list =3D 0; + for ( i =3D 0; i < XEN_LEGACY_MAX_VCPUS; i++ ) + d->shared_info->native.vcpu_info[i].evtchn_pending_sel =3D= 0; + } +#else + memcpy(&d->shared_info->vcpu_info, + &shinfo->vcpu_info, + sizeof(d->shared_info->vcpu_info)); + memcpy(&d->shared_info->arch, + &shinfo->arch, + sizeof(d->shared_info->shared)); + memset(&d->shared_info->evtchn_pending, + 0, + sizeof(d->shared_info->evtchn_pending)); + memset(&d->shared_info->evtchn_mask, + 0xff, + sizeof(d->shared_info->evtchn_mask)); + + d->shared_info.arch.pfn_to_mfn_frame_list_list =3D 0; + for ( i =3D 0; i < XEN_LEGACY_MAX_VCPUS; i++ ) + d->shared_info.vcpu_info[i].evtchn_pending_sel =3D 0; +#endif + + xfree(shinfo); + + rc =3D domain_load_end(c, false); + } + else + rc =3D domain_load_end(c, true); + + return rc; +} + +DOMAIN_REGISTER_SAVE_LOAD(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 551dbbddb8..0e855a4b97 100644 --- a/xen/include/public/save.h +++ b/xen/include/public/save.h @@ -82,7 +82,18 @@ struct domain_save_header { }; DECLARE_DOMAIN_SAVE_TYPE(HEADER, 1, struct domain_save_header); =20 -#define DOMAIN_SAVE_CODE_MAX 1 +struct domain_shared_info_context { + uint32_t flags; + +#define DOMAIN_SAVE_32BIT_SHINFO 0x00000001 + + uint32_t buffer_size; + uint8_t buffer[XEN_FLEX_ARRAY_DIM]; /* Implementation specific size */ +}; + +DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context= ); + +#define DOMAIN_SAVE_CODE_MAX 2 =20 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ =20 --=20 2.20.1 From nobody Thu Mar 28 14:34:03 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=1600186724; cv=none; d=zohomail.com; s=zohoarc; b=VH2ZNTgIQlgejCMBtB4Kd1MuhOkkbTDgd0K2AIs27oWHAnH1LpooR2t+jH0ATXzR5W0PX4va8PLNRzQOEHKbdcCzPWl7dBvtHEusQ358jAv8ZbKwMmskCMrkFFVnO/cbGlrPhzTu4PIsJ1DE7gFhlSac8FE5uzeRxgU/QSO/LH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186724; 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=FGlB2UQIQASWliNynhnstajXESwqTlalG0wjsNUQoic=; b=aH/88mvxnlDcz7cbIJis8Ehv/uyDSrO7uJWBOOYs0cn42H1fvX0GwUP8mLtdib/OhKOgFRLb6NrBv1PH9qvZKsSjKlfDRsaD6NTkoj6xJSKmCBXYjl8OeRNTf3Ew2cDNcyjwjd5nDbIUBBF24Fc/yq7py1/pGA8RgGuPbPUJ/js= 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 1600186724761440.7001894801699; Tue, 15 Sep 2020 09:18:44 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDf2-0001dG-09; Tue, 15 Sep 2020 16:18:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDf0-0001Sm-Jf for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:26 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7c1fe9a4-f218-4ec5-9492-9cfc6f2c8564; Tue, 15 Sep 2020 16:18:13 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDen-00075j-J4; Tue, 15 Sep 2020 16:18:13 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDen-0000cN-BZ; Tue, 15 Sep 2020 16:18:13 +0000 X-Inumbo-ID: 7c1fe9a4-f218-4ec5-9492-9cfc6f2c8564 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=FGlB2UQIQASWliNynhnstajXESwqTlalG0wjsNUQoic=; b=fK5eqAVEqSTyV+7YEUn8U/dY7W oB9exPRCswz/Sim0jHMLt0Bh5ea6K0GYYgw3gRyv9s1ClebcznEYHswYKYdP8EZCxlTu1M2vw2X4o KXPvMMkucUOq89tNfMAkrYQmQ7je/keozcGtt5wka4yJ8ordoUw3IzmqXq8JDRL3tDXM=; 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 v8 7/8] x86/time: add a domain context record for tsc_info... Date: Tue, 15 Sep 2020 17:17:59 +0100 Message-Id: <20200915161800.1384-8-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 definition is x86 specific, it is visible directly in the common 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" v8: - Removed stray blank line v7: - New in v7 --- tools/misc/xen-domctx.c | 11 +++++++++++ xen/arch/x86/time.c | 34 +++++++++++++++++++++++++++++++++- xen/include/asm-x86/time.h | 5 +++-- xen/include/public/save.h | 13 ++++++++++++- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c index 6ead7ea89d..e582a79678 100644 --- a/tools/misc/xen-domctx.c +++ b/tools/misc/xen-domctx.c @@ -59,7 +59,17 @@ static void dump_header(void) =20 printf(" HEADER: magic %#x, version %u\n", h->magic, h->version); +} + +static void dump_tsc_info(void) +{ + DOMAIN_SAVE_TYPE(TSC_INFO) *t; + + GET_PTR(t); =20 + printf(" TSC_INFO: mode: %u incarnation: %u\n" + " khz %u elapsed_nsec: %"PRIu64"\n", + t->mode, t->incarnation, t->khz, t->elapsed_nsec); } =20 static void print_binary(const char *prefix, const void *val, size_t size, @@ -251,6 +261,7 @@ int main(int argc, char **argv) { case DOMAIN_SAVE_CODE(HEADER): dump_header(); break; case DOMAIN_SAVE_CODE(SHARED_INFO): dump_shared_info(); break; + case DOMAIN_SAVE_CODE(TSC_INFO): dump_tsc_info(); break; case DOMAIN_SAVE_CODE(END): dump_end(); break; default: printf("Unknown type %u: skipping\n", desc->typecode); diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 505e54ebd7..05f65fbf12 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -2334,7 +2335,7 @@ int host_tsc_is_safe(void) * called to collect tsc-related data only for save file or live * migrate; called after last rdtsc is done on this incarnation */ -void tsc_get_info(struct domain *d, uint32_t *tsc_mode, +void tsc_get_info(const struct domain *d, uint32_t *tsc_mode, uint64_t *elapsed_nsec, uint32_t *gtsc_khz, uint32_t *incarnation) { @@ -2453,6 +2454,37 @@ int tsc_set_info(struct domain *d, return 0; } =20 +static int save_tsc_info(const struct domain *d, struct domain_context *c, + bool dry_run) +{ + struct domain_tsc_info_context ctxt; + + if ( !dry_run ) + tsc_get_info(d, &ctxt.mode, &ctxt.elapsed_nsec, &ctxt.khz, + &ctxt.incarnation); + + return DOMAIN_SAVE_ENTRY(TSC_INFO, c, 0, &ctxt, sizeof(ctxt)); +} + +static int load_tsc_info(struct domain *d, struct domain_context *c) +{ + struct domain_tsc_info_context ctxt; + unsigned int i; + int rc; + + rc =3D DOMAIN_LOAD_ENTRY(TSC_INFO, c, &i, &ctxt, sizeof(ctxt)); + if ( rc ) + return rc; + + if ( i ) /* expect only a single instance */ + return -ENXIO; + + return tsc_set_info(d, ctxt.mode, ctxt.elapsed_nsec, ctxt.khz, + ctxt.incarnation); +} + +DOMAIN_REGISTER_SAVE_LOAD(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/asm-x86/time.h b/xen/include/asm-x86/time.h index f347311cc4..7f2ce6226a 100644 --- a/xen/include/asm-x86/time.h +++ b/xen/include/asm-x86/time.h @@ -59,8 +59,9 @@ u64 gtsc_to_gtime(struct domain *d, u64 tsc); int tsc_set_info(struct domain *d, uint32_t tsc_mode, uint64_t elapsed_nse= c, uint32_t gtsc_khz, uint32_t incarnation); =20 -void tsc_get_info(struct domain *d, uint32_t *tsc_mode, uint64_t *elapsed_= nsec, - uint32_t *gtsc_khz, uint32_t *incarnation); +void tsc_get_info(const struct domain *d, uint32_t *tsc_mode, + uint64_t *elapsed_nsec, uint32_t *gtsc_khz, + uint32_t *incarnation); =20 =20 void force_update_vcpu_system_time(struct vcpu *v); diff --git a/xen/include/public/save.h b/xen/include/public/save.h index 0e855a4b97..aeb17298eb 100644 --- a/xen/include/public/save.h +++ b/xen/include/public/save.h @@ -93,7 +93,18 @@ struct domain_shared_info_context { =20 DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context= ); =20 -#define DOMAIN_SAVE_CODE_MAX 2 +#if defined(__i386__) || defined(__x86_64__) +struct domain_tsc_info_context { + uint32_t mode; + uint32_t incarnation; + uint64_t elapsed_nsec; + uint32_t khz; +}; + +DECLARE_DOMAIN_SAVE_TYPE(TSC_INFO, 3, struct domain_tsc_info_context); +#endif + +#define DOMAIN_SAVE_CODE_MAX 3 =20 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ =20 --=20 2.20.1 From nobody Thu Mar 28 14:34:03 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=1600186728; cv=none; d=zohomail.com; s=zohoarc; b=V94Zcmzigc77Sv6RDBwka0KAHdwINz3oJKn4gTUPxqRlb50KACPFfeARA4A9VsHVtMDqDmsKrZCtyQYTd1Mdi/d/Nc2SMQKNFpNEyB/ZIQqo8Gjw4Px2uDeEyMj6assZBR5JiMU2vMYXzejUyTms/TkX6+P6296dnZt8RDGuz1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600186728; 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=uCNYjocIfT1Bb/G3WJgONNuto9xcJ5WXtW2Z0YXVZkM=; b=QH2gG2K1p6ZA+Bnc9p0PT3AD6+jTxCHceKNDfo+M9TuGAj0uGjxxZ2iyUSuqsz57c2fVF5KK6EnmHZqrdGErNUUaKre0vKJQLHOOTj1ovQew4UXPQEV81lvYDbPz5SS1e4p7vyamAcpDwItaGvRL8Gg+Epb8AeNXmXoDLlHS6NQ= 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 160018672864610.810229220937003; Tue, 15 Sep 2020 09:18:48 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDf6-0001gb-GP; Tue, 15 Sep 2020 16:18:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDf5-0001Sm-Jg for xen-devel@lists.xenproject.org; Tue, 15 Sep 2020 16:18:31 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 06494b7b-41ac-4cfc-b503-13d56cc76720; Tue, 15 Sep 2020 16:18:14 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIDeo-00075v-Fp; Tue, 15 Sep 2020 16:18:14 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIDeo-0000cN-8N; Tue, 15 Sep 2020 16:18:14 +0000 X-Inumbo-ID: 06494b7b-41ac-4cfc-b503-13d56cc76720 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=uCNYjocIfT1Bb/G3WJgONNuto9xcJ5WXtW2Z0YXVZkM=; b=WrPC64TpJapG8LeTMf2RFCEzdw k1h7aGb0AEeD13G4b1eNyhs1Mq7nIDDVdnaBSny2N7laJ/+yUg8QCGT+h8hYnBXN136SON253oYtW y5/+L96lLjPZMBOfQkfDyb3KR19mP6HE2Rc2hlA0iAjNvAsjrsDWARINqIZnatedrcW8=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH v8 8/8] tools/libxc: add DOMAIN_CONTEXT records to the migration stream... Date: Tue, 15 Sep 2020 17:18:00 +0100 Message-Id: <20200915161800.1384-9-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200915161800.1384-1-paul@xen.org> References: <20200915161800.1384-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... and bump the version. This patch implements version 4 of the migration stream by adding the code necessary to save and restore DOMAIN_CONTEXT records, and removing the code to save the SHARED_INFO and TSC_INFO records (as these are deprecated in version 4). Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu v7: - New in v7 --- tools/libxc/xc_sr_common.h | 3 ++ tools/libxc/xc_sr_common_x86.c | 20 ------------ tools/libxc/xc_sr_common_x86.h | 6 ---- tools/libxc/xc_sr_restore.c | 45 +++++++++++++++++++++++++-- tools/libxc/xc_sr_save.c | 52 +++++++++++++++++++++++++++++++- tools/libxc/xc_sr_save_x86_hvm.c | 5 --- tools/libxc/xc_sr_save_x86_pv.c | 22 -------------- 7 files changed, 97 insertions(+), 56 deletions(-) diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h index f3bdea8006..91ba918b32 100644 --- a/tools/libxc/xc_sr_common.h +++ b/tools/libxc/xc_sr_common.h @@ -298,6 +298,9 @@ struct xc_sr_context =20 /* Sender has invoked verify mode on the stream. */ bool verify; + + /* Domain context blob. */ + struct xc_sr_blob context; } restore; }; =20 diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c index 77ea044a74..dda8e1053c 100644 --- a/tools/libxc/xc_sr_common_x86.c +++ b/tools/libxc/xc_sr_common_x86.c @@ -1,25 +1,5 @@ #include "xc_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/libxc/xc_sr_common_x86.h b/tools/libxc/xc_sr_common_x86.h index e08d81e0e7..39645d0196 100644 --- a/tools/libxc/xc_sr_common_x86.h +++ b/tools/libxc/xc_sr_common_x86.h @@ -3,12 +3,6 @@ =20 #include "xc_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/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c index bc811e6e3a..858d0c184e 100644 --- a/tools/libxc/xc_sr_restore.c +++ b/tools/libxc/xc_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; } @@ -529,6 +529,20 @@ static int send_checkpoint_dirty_pfn_list(struct xc_sr= _context *ctx) return rc; } =20 +static int stream_complete(struct xc_sr_context *ctx) +{ + xc_interface *xch =3D ctx->xch; + int rc; + + rc =3D xc_domain_setcontext(xch, ctx->domid, + ctx->restore.context.ptr, + ctx->restore.context.size); + if ( rc < 0 ) + PERROR("Unable to restore domain context"); + + return rc; +} + static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *= rec); static int handle_checkpoint(struct xc_sr_context *ctx) { @@ -597,6 +611,10 @@ static int handle_checkpoint(struct xc_sr_context *ctx) /* COLO */ =20 /* We need to resume guest */ + rc =3D stream_complete(ctx); + if ( rc ) + goto err; + rc =3D ctx->restore.ops.stream_complete(ctx); if ( rc ) goto err; @@ -682,6 +700,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.context, 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 +742,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; @@ -860,6 +897,10 @@ static int restore(struct xc_sr_context *ctx) * With Remus, if we reach here, there must be some error on primary, * failover from the last checkpoint state. */ + rc =3D stream_complete(ctx); + if ( rc ) + goto err; + rc =3D ctx->restore.ops.stream_complete(ctx); if ( rc ) goto err; diff --git a/tools/libxc/xc_sr_save.c b/tools/libxc/xc_sr_save.c index 80b1d5de1f..60f88d9c24 100644 --- a/tools/libxc/xc_sr_save.c +++ b/tools/libxc/xc_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_getcontext(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_getcontext(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/libxc/xc_sr_save_x86_hvm.c b/tools/libxc/xc_sr_save_x86_= hvm.c index 0b2abb26bd..4c4de914c9 100644 --- a/tools/libxc/xc_sr_save_x86_hvm.c +++ b/tools/libxc/xc_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/libxc/xc_sr_save_x86_pv.c b/tools/libxc/xc_sr_save_x86_p= v.c index c7e246ef4f..fdd2562994 100644 --- a/tools/libxc/xc_sr_save_x86_pv.c +++ b/tools/libxc/xc_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