From: Ian Campbell <ian.campbell@citrix.com>
To: ian.jackson@eu.citrix.com, wei.liu2@citrix.com,
xen-devel@lists.xen.org, stefano.stabellini@eu.citrix.com,
julien.grall@citrix.com
Cc: andrew.cooper3@citrix.com, Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH RFC XEN v1 07/14] xen: arm: Save and restore basic per-VCPU state.
Date: Wed, 9 Dec 2015 14:32:21 +0000 [thread overview]
Message-ID: <1449671548-4050-7-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1449671507.16124.264.camel@citrix.com>
XXX TBD No support for arm64 (or even 32-bit guest on arm64).
XXX In particular the handling of save/restore of VFP state doesn't
XXX even compile for arm32. I need to investigate the best way to
XXX reflect the differing possible VFB states in the save record.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
xen/arch/arm/hvm.c | 167 +++++++++++++++++++++++++++++++++
xen/include/public/arch-arm/hvm/save.h | 38 +++++++-
2 files changed, 204 insertions(+), 1 deletion(-)
diff --git a/xen/arch/arm/hvm.c b/xen/arch/arm/hvm.c
index 5fd0753..3c59e63 100644
--- a/xen/arch/arm/hvm.c
+++ b/xen/arch/arm/hvm.c
@@ -7,6 +7,7 @@
#include <xsm/xsm.h>
+#include <xen/hvm/save.h>
#include <public/xen.h>
#include <public/hvm/params.h>
#include <public/hvm/hvm_op.h>
@@ -65,3 +66,169 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
return rc;
}
+
+static int cpu_save(struct domain *d, hvm_domain_context_t *h)
+{
+ struct hvm_hw_cpu ctxt;
+ struct vcpu *v;
+
+ /* Save the state of CPU */
+ for_each_vcpu( d, v )
+ {
+ /*
+ * We don't need to save state for a vcpu that is down; the restore
+ * code will leave it down if there is nothing saved.
+ */
+ if ( test_bit(_VPF_down, &v->pause_flags) )
+ continue;
+
+ memset(&ctxt, 0, sizeof(ctxt));
+ ctxt.sctlr = v->arch.sctlr;
+ ctxt.ttbr0 = v->arch.ttbr0;
+ ctxt.ttbr1 = v->arch.ttbr1;
+ ctxt.ttbcr = v->arch.ttbcr;
+
+ ctxt.dacr = v->arch.dacr;
+#ifdef CONFIG_ARM_32 /* XXX 32on64 */
+ ctxt.ifar = v->arch.ifar;
+ ctxt.ifsr = v->arch.ifsr;
+ ctxt.dfar = v->arch.dfar;
+ ctxt.dfsr = v->arch.dfsr;
+#else
+ /* XXX 64-bit */
+#endif
+
+#ifdef CONFIG_ARM_32
+ ctxt.mair0 = v->arch.mair0;
+ ctxt.mair1 = v->arch.mair1;
+#else
+ ctxt.mair0 = v->arch.mair;
+#endif
+ /* Control Registers */
+ ctxt.actlr = v->arch.actlr;
+ ctxt.sctlr = v->arch.sctlr;
+ ctxt.cpacr = v->arch.cpacr;
+
+ ctxt.contextidr = v->arch.contextidr;
+ ctxt.tpidr_el0 = v->arch.tpidr_el0;
+ ctxt.tpidr_el1 = v->arch.tpidr_el1;
+ ctxt.tpidrro_el0 = v->arch.tpidrro_el0;
+
+ /* CP 15 */
+ ctxt.csselr = v->arch.csselr;
+ ctxt.mpidr = v->arch.vmpidr;
+
+ ctxt.afsr0 = v->arch.afsr0;
+ ctxt.afsr1 = v->arch.afsr1;
+ ctxt.vbar = v->arch.vbar;
+ ctxt.par = v->arch.par;
+ ctxt.teecr = v->arch.teecr;
+ ctxt.teehbr = v->arch.teehbr;
+#ifdef CONFIG_ARM_32 /* XXX 32on64 */
+ ctxt.joscr = v->arch.joscr;
+ ctxt.jmcr = v->arch.jmcr;
+#endif
+
+ memset(&ctxt.core_regs, 0, sizeof(ctxt.core_regs));
+
+ /* get guest core registers */
+ vcpu_regs_hyp_to_user(v, &ctxt.core_regs);
+
+ /* check VFP state size before dumping */
+ BUILD_BUG_ON(sizeof(v->arch.vfp) > sizeof (ctxt.vfp));
+ memcpy((void*) &ctxt.vfp, (void*) &v->arch.vfp, sizeof(v->arch.vfp));
+
+ if ( hvm_save_entry(VCPU, v->vcpu_id, h, &ctxt) != 0 )
+ return 1;
+ }
+ return 0;
+}
+
+static int cpu_load(struct domain *d, hvm_domain_context_t *h)
+{
+ int vcpuid;
+ struct hvm_hw_cpu ctxt;
+ struct vcpu *v;
+
+ /* Which vcpu is this? */
+ vcpuid = hvm_load_instance(h);
+ if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
+ {
+ dprintk(XENLOG_G_ERR, "HVM restore: dom%u has no vcpu%u\n",
+ d->domain_id, vcpuid);
+ return -EINVAL;
+ }
+
+ if ( hvm_load_entry(VCPU, h, &ctxt) != 0 )
+ return -EINVAL;
+
+ v->arch.sctlr = ctxt.sctlr;
+ v->arch.ttbr0 = ctxt.ttbr0;
+ v->arch.ttbr1 = ctxt.ttbr1;
+ v->arch.ttbcr = ctxt.ttbcr;
+
+ v->arch.dacr = ctxt.dacr;
+#ifdef CONFIG_ARM_32 /* XXX 32on64 */
+ v->arch.ifar = ctxt.ifar;
+ v->arch.ifsr = ctxt.ifsr;
+ v->arch.dfar = ctxt.dfar;
+ v->arch.dfsr = ctxt.dfsr;
+#else
+ /* XXX 64-bit */
+#endif
+
+#ifdef CONFIG_ARM_32
+ v->arch.mair0 = ctxt.mair0;
+ v->arch.mair1 = ctxt.mair1;
+#else
+ v->arch.mair = ctxt.mair0;
+#endif
+
+ /* Control Registers */
+ v->arch.actlr = ctxt.actlr;
+ v->arch.cpacr = ctxt.cpacr;
+ v->arch.contextidr = ctxt.contextidr;
+ v->arch.tpidr_el0 = ctxt.tpidr_el0;
+ v->arch.tpidr_el1 = ctxt.tpidr_el1;
+ v->arch.tpidrro_el0 = ctxt.tpidrro_el0;
+
+ /* CP 15 */
+ v->arch.csselr = ctxt.csselr;
+ v->arch.vmpidr = ctxt.mpidr;
+
+ v->arch.afsr0 = ctxt.afsr0;
+ v->arch.afsr1 = ctxt.afsr1;
+ v->arch.vbar = ctxt.vbar;
+ v->arch.par = ctxt.par;
+ v->arch.teecr = ctxt.teecr;
+ v->arch.teehbr = ctxt.teehbr;
+#ifdef CONFIG_ARM_32 /* XXX 32on64 */
+ v->arch.joscr = ctxt.joscr;
+ v->arch.jmcr = ctxt.jmcr;
+#endif
+
+ /* set guest core registers */
+ vcpu_regs_user_to_hyp(v, &ctxt.core_regs);
+
+ /* restore VFP */
+ BUILD_BUG_ON(sizeof(v->arch.vfp) > sizeof (ctxt.vfp));
+ memcpy(&v->arch.vfp, &ctxt.vfp, sizeof(v->arch.vfp));
+
+ v->is_initialised = 1;
+ clear_bit(_VPF_down, &v->pause_flags);
+
+ /* we don't need vcpu_wake(v) here */
+ return 0;
+}
+
+HVM_REGISTER_SAVE_RESTORE(VCPU, cpu_save, cpu_load, 1, HVMSR_PER_VCPU);
+
+/*
+ * 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 6f1be37..72474e5 100644
--- a/xen/include/public/arch-arm/hvm/save.h
+++ b/xen/include/public/arch-arm/hvm/save.h
@@ -44,10 +44,46 @@ struct hvm_save_header
DECLARE_HVM_SAVE_TYPE(HEADER, 1, struct hvm_save_header);
+struct hvm_hw_cpu
+{
+ uint64_t vfp[34]; /* Vector floating pointer */
+ /* VFP v3 state is 34x64 bit, VFP v4 is not yet supported */
+
+ /* Guest core registers */
+ struct vcpu_guest_core_regs core_regs;
+
+ uint32_t sctlr, ttbcr;
+ uint64_t ttbr0, ttbr1;
+
+ uint32_t ifar, dfar;
+ uint32_t ifsr, dfsr;
+ uint32_t dacr;
+ uint64_t par;
+
+ uint64_t mair0, mair1;
+ uint64_t tpidr_el0;
+ uint64_t tpidr_el1;
+ uint64_t tpidrro_el0;
+ uint64_t vbar;
+
+ /* Control Registers */
+ uint32_t actlr;
+ uint32_t cpacr;
+ uint32_t afsr0, afsr1;
+ uint32_t contextidr;
+ uint32_t teecr, teehbr; /* ThumbEE, 32-bit guests only */
+ uint32_t joscr, jmcr;
+ /* CP 15 */
+ uint32_t csselr;
+ uint64_t mpidr;
+};
+
+DECLARE_HVM_SAVE_TYPE(VCPU, 2, struct hvm_hw_cpu);
+
/*
* Largest type-code in use
*/
-#define HVM_SAVE_CODE_MAX 1
+#define HVM_SAVE_CODE_MAX 2
#endif
--
2.6.1
next prev parent reply other threads:[~2015-12-09 14:32 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-09 14:31 [PATCH RFC v1 00/14] xen: arm: support for save restore and dead migration Ian Campbell
2015-12-09 14:32 ` [PATCH RFC XEN v1 01/14] xen: arm: Add gic_hw_desc Ian Campbell
2015-12-15 16:15 ` Stefano Stabellini
2015-12-15 16:21 ` Ian Campbell
2015-12-15 16:35 ` Andrew Cooper
2015-12-15 16:56 ` Ian Campbell
2015-12-09 14:32 ` [PATCH RFC XEN v1 02/14] xen: arm: Provide a mechanism to read (and decode) an LR from a saved VCPU Ian Campbell
2015-12-15 16:22 ` Stefano Stabellini
2015-12-09 14:32 ` [PATCH RFC XEN v1 03/14] xen: arm: switch arch_do_domctl to a common exit path Ian Campbell
2015-12-15 16:34 ` Stefano Stabellini
2015-12-15 16:57 ` Ian Campbell
2015-12-15 17:07 ` Andrew Cooper
2015-12-15 17:11 ` Jan Beulich
2015-12-09 14:32 ` [PATCH RFC XEN v1 04/14] xen: arm: Implement XEN_DOMCTL_getpageframeinfo3 Ian Campbell
2015-12-15 16:44 ` Stefano Stabellini
2015-12-09 14:32 ` [PATCH RFC XEN v1 05/14] xen: arm: Implement basic XEN_DOMCTL_{set, get}hvmcontext support Ian Campbell
2015-12-15 18:00 ` Stefano Stabellini
2015-12-16 10:18 ` Ian Campbell
2015-12-09 14:32 ` [PATCH RFC XEN v1 06/14] xen: arm: Add some basic platform info to save header Ian Campbell
2015-12-15 18:37 ` Stefano Stabellini
2015-12-16 10:20 ` Ian Campbell
2015-12-09 14:32 ` Ian Campbell [this message]
2015-12-16 14:55 ` [PATCH RFC XEN v1 07/14] xen: arm: Save and restore basic per-VCPU state Stefano Stabellini
2015-12-16 15:04 ` Ian Campbell
2015-12-09 14:32 ` [PATCH RFC XEN v1 08/14] xen: arm: Save and restore arch timer state Ian Campbell
2015-12-16 15:53 ` Stefano Stabellini
2015-12-16 16:02 ` Ian Campbell
2015-12-16 16:17 ` Julien Grall
2015-12-16 16:37 ` Ian Campbell
2015-12-16 18:05 ` Stefano Stabellini
2015-12-17 9:33 ` Ian Campbell
2015-12-09 14:32 ` [PATCH RFC XEN v1 09/14] xen: arm: Save and restore GIC state Ian Campbell
2015-12-16 18:30 ` Stefano Stabellini
2015-12-17 9:54 ` Ian Campbell
2015-12-22 16:44 ` Stefano Stabellini
2015-12-09 14:32 ` [PATCH RFC XEN v1 10/14] tools: Switch a few CONFIG_MIGRATE features to CONFIG_X86 Ian Campbell
2015-12-09 15:16 ` Andrew Cooper
2015-12-09 14:32 ` [PATCH RFC XEN v1 11/14] tools: migrate: refactor selection of save/restore ops to be arch specific Ian Campbell
2015-12-09 15:26 ` Andrew Cooper
2015-12-09 15:33 ` Ian Campbell
2015-12-09 14:32 ` [PATCH RFC XEN v1 12/14] tools: libxc: implement modify_returncode for ARM Ian Campbell
2015-12-16 16:22 ` Stefano Stabellini
2015-12-16 16:36 ` Ian Campbell
2015-12-09 14:32 ` [PATCH RFC XEN v1 13/14] tools: libxc: wire up migration " Ian Campbell
2015-12-09 15:48 ` Andrew Cooper
2015-12-09 14:32 ` [PATCH RFC XEN v1 14/14] tools/libxl: BODGE ARM save/restore and (dead) migration Ian Campbell
2015-12-09 14:33 ` [PATCH RFC LINUX v1] xen: arm: enable migration on ARM Ian Campbell
2016-01-06 17:47 ` Stefano Stabellini
2016-01-06 17:57 ` Stefano Stabellini
2016-01-07 9:47 ` Ian Campbell
2016-01-07 9:43 ` Ian Campbell
2016-01-06 17:55 ` Stefano Stabellini
2016-01-07 9:47 ` Ian Campbell
2016-01-07 11:32 ` Stefano Stabellini
2015-12-09 15:51 ` [PATCH RFC v1 00/14] xen: arm: support for save restore and dead migration Andrew Cooper
2015-12-09 16:09 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1449671548-4050-7-git-send-email-ian.campbell@citrix.com \
--to=ian.campbell@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=julien.grall@citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).