From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jaeyong Yoo Subject: [PATCH RFC 2/4] Implement arch_hvm_save and arch_hvm_load functions Date: Wed, 05 Jun 2013 14:46:17 +0900 Message-ID: <1370411179-13570-3-git-send-email-jaeyong.yoo@samsung.com> References: <1370411179-13570-1-git-send-email-jaeyong.yoo@samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-reply-to: <1370411179-13570-1-git-send-email-jaeyong.yoo@samsung.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Jaeyong Yoo List-Id: xen-devel@lists.xenproject.org Signed-off-by: Jaeyong Yoo --- xen/arch/arm/hvm/Makefile | 1 + xen/arch/arm/hvm/save.c | 69 ++++++++++++++++++++++++++++++++ xen/include/public/arch-arm/hvm/save.h | 16 ++++++++ 3 files changed, 86 insertions(+) create mode 100644 xen/arch/arm/hvm/save.c diff --git a/xen/arch/arm/hvm/Makefile b/xen/arch/arm/hvm/Makefile index 6ee4054..ad38e09 100644 --- a/xen/arch/arm/hvm/Makefile +++ b/xen/arch/arm/hvm/Makefile @@ -1 +1,2 @@ obj-y += hvm.o +obj-y += save.o diff --git a/xen/arch/arm/hvm/save.c b/xen/arch/arm/hvm/save.c new file mode 100644 index 0000000..b92f593 --- /dev/null +++ b/xen/arch/arm/hvm/save.c @@ -0,0 +1,69 @@ +/* + * hvm/save.c: Save and restore HVM guest's emulated hardware state for ARM. + * + * Copyright (c) 2013, Samsung Electronics. + * + * 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 for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include +#include +#include + +void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr) +{ + hdr->cpuid = READ_SYSREG32(MIDR_EL1); +} + +int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr) +{ + uint32_t cpuid; + + if ( hdr->magic != HVM_FILE_MAGIC ) + { + printk(XENLOG_G_ERR "HVM%d restore: bad magic number %#"PRIx32"\n", + d->domain_id, hdr->magic); + return -1; + } + + if ( hdr->version != HVM_FILE_VERSION ) + { + printk(XENLOG_G_ERR "HVM%d restore: unsupported version %u\n", + d->domain_id, hdr->version); + return -1; + } + + cpuid = READ_SYSREG32(MIDR_EL1); + if ( hdr->cpuid != cpuid ) + { + printk(XENLOG_G_INFO "HVM%d restore: VM saved on one CPU " + "(%#"PRIx32") and restored on another (%#"PRIx32").\n", + d->domain_id, hdr->cpuid, cpuid); + return -1; + } + + return 0; +} + +/* + * 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/arch-arm/hvm/save.h index 75b8e65..570809e 100644 --- a/xen/include/public/arch-arm/hvm/save.h +++ b/xen/include/public/arch-arm/hvm/save.h @@ -26,6 +26,22 @@ #ifndef __XEN_PUBLIC_HVM_SAVE_ARM_H__ #define __XEN_PUBLIC_HVM_SAVE_ARM_H__ +/* + * Save/restore header: general info about the save file. + */ + +#define HVM_FILE_MAGIC 0x92385520 +#define HVM_FILE_VERSION 0x00000001 + +struct hvm_save_header { + uint32_t magic; /* Must be HVM_FILE_MAGIC */ + uint32_t version; /* File format version */ + uint64_t changeset; /* Version of Xen that saved this file */ + uint32_t cpuid; /* CPUID[0x01][%eax] on the saving machine */ +}; + +DECLARE_HVM_SAVE_TYPE(HEADER, 1, struct hvm_save_header); + #endif /* -- 1.7.9.5