Skip to contentSkip to conversation

xen/arm: Xen save/restore/live migration support

PATCH Superseded Wei Huang 3 participants 21 messages Apr 10, 2014 – Apr 11, 2014

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

cover xen/arm: Xen save/restore/live migration support

The following are the save/restore/live-migration patches I forward-ported to the latest Xen tree. Note that I kept the order of original patches, and Signed-off-by as well. For the patches I modified (see summary below), I added my name as Signed-off-by.

These patches aren't intended as the final version. Since Junghyun Yoo is working on his patches, I think it is better to send out my version now for discussion and proper merge. Let us make Xen 4.5 support these features.

=== Modification Summary ===

Patch 1:
* Adapt to latest Xen source code
* Setting IRQ status as enabled by checking ieanble bits after loading VM info
* Minor fixes to support 64-bit

Patch 5:
* Add new p2m ARM type (p2m_ram_logdirty) to support dirty page tracking

Patch 6:
* Enable save/restore/live migration support based on latest Xen code
* Adapt to latest Xen source code

-Wei

Alexey Sokolov (1):
xen/arm: Implement toolstack for xl restore/save and migrate

Jaeyong Yoo (4):
xen/arm: implement get_maximum_gpfn hypercall xen/arm: Implement do_suspend function
xen/arm: Implement VLPT for guest p2m mapping in live migration xen/arm: Implement hypercall for dirty page tracing

Jaeyong Yoon (1):
xen/arm: Save and restore support for hvm context hypercall

 config/arm32.mk                        |   1 +
 config/arm64.mk                        |   1 +
 tools/libxc/Makefile                   |   6 +-
 tools/libxc/xc_arm_migrate.c           | 712 +++++++++++++++++++++++++++++++++
 tools/libxc/xc_dom_arm.c               |   4 +-
 tools/libxc/xc_resume.c                |  25 ++
 tools/libxl/libxl.h                    |   3 -
 tools/misc/Makefile                    |   4 +-
 xen/arch/arm/Makefile                  |   1 +
 xen/arch/arm/domain.c                  |  19 +
 xen/arch/arm/domctl.c                  | 101 ++++-
 xen/arch/arm/hvm.c                     | 505 ++++++++++++++++++++++-
 xen/arch/arm/mm.c                      | 240 ++++++++++-
 xen/arch/arm/p2m.c                     | 208 ++++++++++
 xen/arch/arm/save.c                    |  66 +++
 xen/arch/arm/traps.c                   |   9 +
 xen/common/Makefile                    |   2 +
 xen/include/asm-arm/arm32/page.h       |  23 +-
 xen/include/asm-arm/config.h           |   9 +
 xen/include/asm-arm/domain.h           |  14 +
 xen/include/asm-arm/hvm/support.h      |  29 ++
 xen/include/asm-arm/mm.h               |  26 ++
 xen/include/asm-arm/p2m.h              |   8 +-
 xen/include/asm-arm/processor.h        |   2 +
 xen/include/public/arch-arm/hvm/save.h | 136 +++++++
 25 files changed, 2129 insertions(+), 25 deletions(-)
 create mode 100644 tools/libxc/xc_arm_migrate.c
 create mode 100644 xen/arch/arm/save.c
 create mode 100644 xen/include/asm-arm/hvm/support.h
Signature · 1 line
1.8.3.2
author
#1 lore raw

PATCH 1/6 xen/arm: Save and restore support for hvm context hypercall

From: Jaeyong Yoon <[email protected]>

Implement save/restore of hvm context hypercall. In hvm context save/restore, this patch saves gic, timer and vfp registers.

---
 xen/arch/arm/Makefile                  |   1 +
 xen/arch/arm/domctl.c                  |  92 +++++-
 xen/arch/arm/hvm.c                     | 505 ++++++++++++++++++++++++++++++++-
 xen/arch/arm/save.c                    |  66 +++++
 xen/common/Makefile                    |   2 +
 xen/include/asm-arm/hvm/support.h      |  29 ++
 xen/include/public/arch-arm/hvm/save.h | 136 +++++++++
 7 files changed, 826 insertions(+), 5 deletions(-)
 create mode 100644 xen/arch/arm/save.c
 create mode 100644 xen/include/asm-arm/hvm/support.h
xen/arch/arm/Makefile +1 -0
index 63e0460..d9a328c 100644
@@ -33,6 +33,7 @@ obj-y += hvm.o
 obj-y += device.o
 obj-y += decode.o
 obj-y += processor.o
+obj-y += save.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/domctl.c +88 -4

119 lines not on this page · raw message

xen/arch/arm/hvm.c +504 -1

521 lines not on this page · raw message

xen/arch/arm/save.c new file +66 -0

66 lines not on this page · raw message

xen/common/Makefile +2 -0
index 3683ae3..714a3c4 100644
@@ -64,6 +64,8 @@ subdir-$(CONFIG_COMPAT) += compat
 
 subdir-$(x86_64) += hvm
 
+subdir-$(CONFIG_ARM) += hvm
+
 subdir-$(coverage) += gcov
 
 subdir-y += libelf
xen/include/asm-arm/hvm/support.h new file +29 -0
new file mode 100644
index 0000000..8311f2f
@@ -0,0 +1,29 @@
+/*
+ * support.h: HVM support routines used by ARMv7 VE.
+ *
+ * Copyright (c) 2012, Citrix Systems
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARM_HVM_SUPPORT_H__
+#define __ASM_ARM_HVM_SUPPORT_H__
+
+#include <xen/types.h>
+#include <public/hvm/ioreq.h>
+#include <xen/sched.h>
+#include <xen/hvm/save.h>
+#include <asm/processor.h>
+
+#endif /* __ASM_ARM_HVM_SUPPORT_H__ */
xen/include/public/arch-arm/hvm/save.h +136 -0

142 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#2 lore raw

Re: [PATCH 1/6] xen/arm: Save and restore support for hvm context hypercall

Quoted 54 lines · Wei Huang

From: Jaeyong Yoon <[email protected]>

Implement save/restore of hvm context hypercall. In hvm context save/restore, this patch saves gic, timer and vfp registers.

---
 xen/arch/arm/Makefile                  |   1 +
 xen/arch/arm/domctl.c                  |  92 +++++-
 xen/arch/arm/hvm.c                     | 505 ++++++++++++++++++++++++++++++++-
 xen/arch/arm/save.c                    |  66 +++++
 xen/common/Makefile                    |   2 +
 xen/include/asm-arm/hvm/support.h      |  29 ++
 xen/include/public/arch-arm/hvm/save.h | 136 +++++++++
 7 files changed, 826 insertions(+), 5 deletions(-)
 create mode 100644 xen/arch/arm/save.c
 create mode 100644 xen/include/asm-arm/hvm/support.h
xen/arch/arm/Makefile +1 -0
index 63e0460..d9a328c 100644
@@ -33,6 +33,7 @@ obj-y += hvm.o
 obj-y += device.o
 obj-y += decode.o
 obj-y += processor.o
+obj-y += save.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/domctl.c +7 -0
index 45974e7..914de29 100644
@@ -9,31 +9,115 @@
 #include <xen/lib.h>
 #include <xen/errno.h>
 #include <xen/sched.h>
+#include <xen/hvm/save.h>
+#include <xen/guest_access.h>
 #include <xen/hypercall.h>
 #include <public/domctl.h>
 
 long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
+    long ret = 0;
+    bool_t copyback = 0;
+
     switch ( domctl->cmd )
     {
+    case XEN_DOMCTL_sethvmcontext:
+    {

xen/arch/arm/domctl.c line 36

Quoted 10 lines
xen/arch/arm/domctl.c +10 -0
+        struct hvm_domain_context c = { .size = domctl->u.hvmcontext.size };
+
+        ret = -ENOMEM;
+        if ( (c.data = xmalloc_bytes(c.size)) == NULL )
+            goto sethvmcontext_out;
+
+        ret = -EFAULT;
+        if ( copy_from_guest(c.data, domctl->u.hvmcontext.buffer, c.size) != 0)
+            goto sethvmcontext_out;
+

You need to ensure that d != current->domain, or domain_pause() will ASSERT().

Quoted 33 lines
xen/arch/arm/domctl.c +33 -0
+        domain_pause(d);
+        ret = hvm_load(d, &c);
+        domain_unpause(d);
+
+    sethvmcontext_out:
+        if ( c.data != NULL )
+            xfree(c.data);
+    }
+    break;
+
+    case XEN_DOMCTL_gethvmcontext:
+    {
+        struct hvm_domain_context c = { 0 };
+
+        ret = -EINVAL;
+
+        c.size = hvm_save_size(d);
+
+        if ( guest_handle_is_null(domctl->u.hvmcontext.buffer) )
+        {
+            /* Client is querying for the correct buffer size */
+            domctl->u.hvmcontext.size = c.size;
+            ret = 0;
+            goto gethvmcontext_out;
+        }
+
+        /* Check that the client has a big enough buffer */
+        ret = -ENOSPC;
+        if ( domctl->u.hvmcontext.size < c.size )
+        {
+            printk("(gethvmcontext) size error: %d and %d\n",
+                   domctl->u.hvmcontext.size, c.size );
+            goto gethvmcontext_out;

xen/arch/arm/domctl.c line 79

Quoted 10 lines
xen/arch/arm/domctl.c +10 -0
+        }
+
+        /* Allocate our own marshalling buffer */
+        ret = -ENOMEM;
+        if ( (c.data = xmalloc_bytes(c.size)) == NULL )
+        {
+            printk("(gethvmcontext) xmalloc_bytes failed: %d\n", c.size );
+            goto gethvmcontext_out;
+        }
+

Same here.

Quoted 36 lines
xen/arch/arm/domctl.c +22 -3
+        domain_pause(d);
+        ret = hvm_save(d, &c);
+        domain_unpause(d);
+
+        domctl->u.hvmcontext.size = c.cur;
+        if ( copy_to_guest(domctl->u.hvmcontext.buffer, c.data, c.size) != 0 )
+        {
+            printk("(gethvmcontext) copy to guest failed\n");
+            ret = -EFAULT;
+        }
+
+    gethvmcontext_out:
+        copyback = 1;
+
+        if ( c.data != NULL )
+            xfree(c.data);
+    }
+    break;
+
     case XEN_DOMCTL_cacheflush:
     {
         unsigned long s = domctl->u.cacheflush.start_pfn;
         unsigned long e = s + domctl->u.cacheflush.nr_pfns;
 
         if ( domctl->u.cacheflush.nr_pfns > (1U<<MAX_ORDER) )
-            return -EINVAL;
+            ret = -EINVAL;
 
         if ( e < s )
-            return -EINVAL;
+            ret = -EINVAL;
 
-        return p2m_cache_flush(d, s, e);
+        ret = p2m_cache_flush(d, s, e);
     }
 

xen/arch/arm/domctl.c line 121

Quoted 10 lines
xen/arch/arm/domctl.c +6 -1
     default:
-        return subarch_do_domctl(domctl, d, u_domctl);
+        ret = subarch_do_domctl(domctl, d, u_domctl);
     }
+
+    if ( copyback && __copy_to_guest(u_domctl, domctl, 1) )
+        ret = -EFAULT;
+
+    return ret;
 }

Both these hypercalls look suspiciously similar to the x86 variants, and look to be good candidates to live in common code.

~Andrew

author
#3 lore raw

Re: [PATCH 1/6] xen/arm: Save and restore support for hvm context hypercall

Quoted 151 lines · Andrew Cooper
Quoted 54 lines · Wei Huang

From: Jaeyong Yoon <[email protected]>

Implement save/restore of hvm context hypercall. In hvm context save/restore, this patch saves gic, timer and vfp registers.

---
  xen/arch/arm/Makefile                  |   1 +
  xen/arch/arm/domctl.c                  |  92 +++++-
  xen/arch/arm/hvm.c                     | 505 ++++++++++++++++++++++++++++++++-
  xen/arch/arm/save.c                    |  66 +++++
  xen/common/Makefile                    |   2 +
  xen/include/asm-arm/hvm/support.h      |  29 ++
  xen/include/public/arch-arm/hvm/save.h | 136 +++++++++
  7 files changed, 826 insertions(+), 5 deletions(-)

create mode 100644 xen/arch/arm/save.c create mode 100644 xen/include/asm-arm/hvm/support.h

xen/arch/arm/Makefile +1 -0
index 63e0460..d9a328c 100644
@@ -33,6 +33,7 @@ obj-y += hvm.o
  obj-y += device.o
  obj-y += decode.o
  obj-y += processor.o
+obj-y += save.o
 
  #obj-bin-y += ....o
 
xen/arch/arm/domctl.c +7 -0
index 45974e7..914de29 100644
@@ -9,31 +9,115 @@
  #include <xen/lib.h>
  #include <xen/errno.h>
  #include <xen/sched.h>
+#include <xen/hvm/save.h>
+#include <xen/guest_access.h>
  #include <xen/hypercall.h>
  #include <public/domctl.h>
 
  long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                      XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
  {
+    long ret = 0;
+    bool_t copyback = 0;
+
      switch ( domctl->cmd )
      {
+    case XEN_DOMCTL_sethvmcontext:
+    {

xen/arch/arm/domctl.c line 36

Quoted 10 lines
xen/arch/arm/domctl.c +10 -0
+        struct hvm_domain_context c = { .size = domctl->u.hvmcontext.size };
+
+        ret = -ENOMEM;
+        if ( (c.data = xmalloc_bytes(c.size)) == NULL )
+            goto sethvmcontext_out;
+
+        ret = -EFAULT;
+        if ( copy_from_guest(c.data, domctl->u.hvmcontext.buffer, c.size) != 0)
+            goto sethvmcontext_out;
+

You need to ensure that d != current->domain, or domain_pause() will ASSERT().

Quoted 33 lines
xen/arch/arm/domctl.c +33 -0
+        domain_pause(d);
+        ret = hvm_load(d, &c);
+        domain_unpause(d);
+
+    sethvmcontext_out:
+        if ( c.data != NULL )
+            xfree(c.data);
+    }
+    break;
+
+    case XEN_DOMCTL_gethvmcontext:
+    {
+        struct hvm_domain_context c = { 0 };
+
+        ret = -EINVAL;
+
+        c.size = hvm_save_size(d);
+
+        if ( guest_handle_is_null(domctl->u.hvmcontext.buffer) )
+        {
+            /* Client is querying for the correct buffer size */
+            domctl->u.hvmcontext.size = c.size;
+            ret = 0;
+            goto gethvmcontext_out;
+        }
+
+        /* Check that the client has a big enough buffer */
+        ret = -ENOSPC;
+        if ( domctl->u.hvmcontext.size < c.size )
+        {
+            printk("(gethvmcontext) size error: %d and %d\n",
+                   domctl->u.hvmcontext.size, c.size );
+            goto gethvmcontext_out;

xen/arch/arm/domctl.c line 79

Quoted 10 lines
xen/arch/arm/domctl.c +10 -0
+        }
+
+        /* Allocate our own marshalling buffer */
+        ret = -ENOMEM;
+        if ( (c.data = xmalloc_bytes(c.size)) == NULL )
+        {
+            printk("(gethvmcontext) xmalloc_bytes failed: %d\n", c.size );
+            goto gethvmcontext_out;
+        }
+

Same here.

Quoted 36 lines
xen/arch/arm/domctl.c +22 -3
+        domain_pause(d);
+        ret = hvm_save(d, &c);
+        domain_unpause(d);
+
+        domctl->u.hvmcontext.size = c.cur;
+        if ( copy_to_guest(domctl->u.hvmcontext.buffer, c.data, c.size) != 0 )
+        {
+            printk("(gethvmcontext) copy to guest failed\n");
+            ret = -EFAULT;
+        }
+
+    gethvmcontext_out:
+        copyback = 1;
+
+        if ( c.data != NULL )
+            xfree(c.data);
+    }
+    break;
+
      case XEN_DOMCTL_cacheflush:
      {
          unsigned long s = domctl->u.cacheflush.start_pfn;
          unsigned long e = s + domctl->u.cacheflush.nr_pfns;
 
          if ( domctl->u.cacheflush.nr_pfns > (1U<<MAX_ORDER) )
-            return -EINVAL;
+            ret = -EINVAL;
 
          if ( e < s )
-            return -EINVAL;
+            ret = -EINVAL;
 
-        return p2m_cache_flush(d, s, e);
+        ret = p2m_cache_flush(d, s, e);
      }
 
Quoted 13 lines

xen/arch/arm/domctl.c line 121

Quoted 10 lines
xen/arch/arm/domctl.c +6 -1
      default:
-        return subarch_do_domctl(domctl, d, u_domctl);
+        ret = subarch_do_domctl(domctl, d, u_domctl);
      }
+
+    if ( copyback && __copy_to_guest(u_domctl, domctl, 1) )
+        ret = -EFAULT;
+
+    return ret;
  }

Both these hypercalls look suspiciously similar to the x86 variants, and look to be good candidates to live in common code.

Got it. I will try to merge them with x86, if possible.

Quoted 3 lines

~Andrew

#4 lore raw

Re: [PATCH 1/6] xen/arm: Save and restore support for hvm context hypercall

In reply to Wei Huang

Hi Wei,

Thank you for the patch.

On 04/10/2014 05:48 PM, Wei Huang wrote:

[..]

Quoted 6 lines
     case XEN_DOMCTL_cacheflush:
     {
         unsigned long s = domctl->u.cacheflush.start_pfn;
         unsigned long e = s + domctl->u.cacheflush.nr_pfns;
 
         if ( domctl->u.cacheflush.nr_pfns > (1U<<MAX_ORDER) )

xen/arch/arm/domctl.c line 111

Quoted 10 lines
xen/arch/arm/domctl.c +3 -3
-            return -EINVAL;
+            ret = -EINVAL;
 
         if ( e < s )
-            return -EINVAL;
+            ret = -EINVAL;
 
-        return p2m_cache_flush(d, s, e);
+        ret = p2m_cache_flush(d, s, e);
     }

Your change in XEN_DOMCTL_cacheflush is wrong. The code should not continue if the sanity check has failed.

Quoted 23 lines

void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)

xen/arch/arm/hvm.c +2 -1
index 471c4cd..bfe38f4 100644
@@ -7,14 +7,15 @@
 
 #include <xsm/xsm.h>
 
+#include <xen/hvm/save.h>
 #include <public/xen.h>
 #include <public/hvm/params.h>
 #include <public/hvm/hvm_op.h>
 
 #include <asm/hypercall.h>
+#include <asm/gic.h>
 
 long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
-
 {
     long rc = 0;
 

xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 72

Quoted 7 lines
xen/arch/arm/hvm.c +4 -0
@@ -65,3 +66,505 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     return rc;
 }
+
+static int vgic_irq_rank_save(struct vcpu *v,
+                              struct vgic_rank *ext,
+                              struct vgic_irq_rank *rank)

I would prefer if you move all theses functions of this file in each specific file (timer in time.c, vgic in vgic.c,...).

It would be easier when GICv3 and new stuff will be supported.

Quoted 10 lines
xen/arch/arm/hvm.c +10 -0
+{
+    spin_lock(&rank->lock);
+
+    /* Some of VGIC registers are not used yet, it is for a future usage */
+    /* IENABLE, IACTIVE, IPEND,  PENDSGI registers */
+    ext->ienable = rank->ienable;
+    ext->iactive = rank->iactive;
+    ext->ipend = rank->ipend;
+    ext->pendsgi = rank->pendsgi;
+

xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 92

Quoted 10 lines
xen/arch/arm/hvm.c +10 -0
+    /* ICFG */
+    ext->icfg[0] = rank->icfg[0];
+    ext->icfg[1] = rank->icfg[1];
+
+    /* IPRIORITY */
+    if ( sizeof(rank->ipriority) != sizeof (ext->ipriority) )
+    {
+        dprintk(XENLOG_G_ERR, "hvm_hw_gic: check ipriority dumping space\n");
+        return -EINVAL;
+    }

You don't need to check it at runtime. BUILG_BUG_ON is enough here.

xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 100

Quoted 8 lines
xen/arch/arm/hvm.c +8 -0
+    memcpy(ext->ipriority, rank->ipriority, sizeof(rank->ipriority));
+
+    /* ITARGETS */
+    if ( sizeof(rank->itargets) != sizeof (ext->itargets) )
+    {
+        dprintk(XENLOG_G_ERR, "hvm_hw_gic: check itargets dumping space\n");
+        return -EINVAL;
+    }

Same here. And actually everywhere you have the pattern "if (sizeof(a) op sizeof (b))" in this file.

[..]

xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 302

Quoted 1 line
xen/arch/arm/hvm.c +1 -0
+HVM_REGISTER_SAVE_RESTORE(A15_TIMER, timer_save, timer_load, 2, HVMSR_PER_VCPU);

The timer structure is not A15 specific. Can you rename it in timer?

[..]

xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 104

Quoted 3 lines
xen/arch/arm/hvm.c +3 -0
+void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr)
+{
+    hdr->cpuid = READ_SYSREG32(MIDR_EL1);

You can directly use current_cpu_data.midr.bits;

Quoted 11 lines
xen/arch/arm/hvm.c +11 -0
+}
+
+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;

xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 125

Quoted 10 lines
xen/arch/arm/hvm.c +10 -0
+    }
+
+    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);

Same here.

Quoted 25 lines
xen/arch/arm/hvm.c +20 -0
+    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:
+ */
xen/common/Makefile +0 -0
index 3683ae3..714a3c4 100644

xen/common/Makefile subdir-$(CONFIG_COMPAT) += compat · line 68

Quoted 5 lines
xen/common/Makefile +2 -0
@@ -64,6 +64,8 @@ subdir-$(CONFIG_COMPAT) += compat
 
 subdir-$(x86_64) += hvm
 
+subdir-$(CONFIG_ARM) += hvm
+

I think you can directly merge with the line above and use:

subdir-y += hvm

Regards,

Signature · 1 line
Julien Grall
author
#5 lore raw

PATCH 2/6 xen/arm: implement get_maximum_gpfn hypercall

In reply to Wei Huang

From: Jaeyong Yoo <[email protected]>

This patchi implements get_maximum_gpfn by using the memory map info in arch_domain (from set_memory_map hypercall).

---
 xen/arch/arm/mm.c        | 19 ++++++++++++++++++-
 xen/include/asm-arm/mm.h |  2 ++
 2 files changed, 20 insertions(+), 1 deletion(-)
xen/arch/arm/mm.c +18 -1
index 362bc8d..14b4686 100644
@@ -947,7 +947,11 @@ int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
 
 unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
-    return -ENOSYS;
+    paddr_t end;
+
+    get_gma_start_end(d, NULL, &end);
+
+    return (unsigned long) (end >> PAGE_SHIFT);
 }
 
 void share_xen_page_with_guest(struct page_info *page,
@@ -1235,6 +1239,19 @@ int is_iomem_page(unsigned long mfn)
         return 1;
     return 0;
 }
+
+/*
+ * Return start and end addresses of guest
+ */
+void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end)
+{
+    if ( start )
+        *start = GUEST_RAM_BASE;
+
+    if ( end )
+        *end = GUEST_RAM_BASE + ((paddr_t) d->max_pages << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/mm.h +2 -0
index b8d4e7d..341493a 100644
@@ -341,6 +341,8 @@ static inline void put_page_and_type(struct page_info *page)
     put_page(page);
 }
 
+void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end);
+
 #endif /*  __ARCH_ARM_MM__ */
 /*
  * Local variables:
Signature · 1 line
1.8.3.2
#6 lore raw

Re: [PATCH 2/6] xen/arm: implement get_maximum_gpfn hypercall

Quoted 6 lines · Wei Huang

From: Jaeyong Yoo <[email protected]>

This patchi implements get_maximum_gpfn by using the memory map info in arch_domain (from set_memory_map hypercall).

Common implementation and a specific arch_get_maximum_gpfn() ?

~Andrew

Quoted 55 lines
---
 xen/arch/arm/mm.c        | 19 ++++++++++++++++++-
 xen/include/asm-arm/mm.h |  2 ++
 2 files changed, 20 insertions(+), 1 deletion(-)
xen/arch/arm/mm.c +18 -1
index 362bc8d..14b4686 100644
@@ -947,7 +947,11 @@ int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
 
 unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
-    return -ENOSYS;
+    paddr_t end;
+
+    get_gma_start_end(d, NULL, &end);
+
+    return (unsigned long) (end >> PAGE_SHIFT);
 }
 
 void share_xen_page_with_guest(struct page_info *page,
@@ -1235,6 +1239,19 @@ int is_iomem_page(unsigned long mfn)
         return 1;
     return 0;
 }
+
+/*
+ * Return start and end addresses of guest
+ */
+void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end)
+{
+    if ( start )
+        *start = GUEST_RAM_BASE;
+
+    if ( end )
+        *end = GUEST_RAM_BASE + ((paddr_t) d->max_pages << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/mm.h +2 -0
index b8d4e7d..341493a 100644
@@ -341,6 +341,8 @@ static inline void put_page_and_type(struct page_info *page)
     put_page(page);
 }
 
+void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end);
+
 #endif /*  __ARCH_ARM_MM__ */
 /*
  * Local variables:
author
#7 lore raw

Re: [PATCH 2/6] xen/arm: implement get_maximum_gpfn hypercall

Quoted 11 lines · Andrew Cooper
Quoted 6 lines · Wei Huang

From: Jaeyong Yoo <[email protected]>

This patchi implements get_maximum_gpfn by using the memory map info in arch_domain (from set_memory_map hypercall).

Common implementation and a specific arch_get_maximum_gpfn() ?

~Andrew

Yes, will do.

Quoted 58 lines
Quoted 56 lines
---
  xen/arch/arm/mm.c        | 19 ++++++++++++++++++-
  xen/include/asm-arm/mm.h |  2 ++
  2 files changed, 20 insertions(+), 1 deletion(-)
xen/arch/arm/mm.c +18 -1
index 362bc8d..14b4686 100644
@@ -947,7 +947,11 @@ int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
 
  unsigned long domain_get_maximum_gpfn(struct domain *d)
  {
-    return -ENOSYS;
+    paddr_t end;
+
+    get_gma_start_end(d, NULL, &end);
+
+    return (unsigned long) (end >> PAGE_SHIFT);
  }
 
  void share_xen_page_with_guest(struct page_info *page,
@@ -1235,6 +1239,19 @@ int is_iomem_page(unsigned long mfn)
          return 1;
      return 0;
  }
+
+/*
+ * Return start and end addresses of guest
+ */
+void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end)
+{
+    if ( start )
+        *start = GUEST_RAM_BASE;
+
+    if ( end )
+        *end = GUEST_RAM_BASE + ((paddr_t) d->max_pages << PAGE_SHIFT);
+}
+
  /*
   * Local variables:
   * mode: C
xen/include/asm-arm/mm.h +2 -0
index b8d4e7d..341493a 100644
@@ -341,6 +341,8 @@ static inline void put_page_and_type(struct page_info *page)
      put_page(page);
  }
 
+void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end);
+
  #endif /*  __ARCH_ARM_MM__ */
  /*
   * Local variables:
#8 lore raw

Re: [PATCH 2/6] xen/arm: implement get_maximum_gpfn hypercall

In reply to Andrew Cooper

Hi Andrew,

Quoted 9 lines · Andrew Cooper
Quoted 6 lines · Wei Huang

From: Jaeyong Yoo <[email protected]>

This patchi implements get_maximum_gpfn by using the memory map info in arch_domain (from set_memory_map hypercall).

Common implementation and a specific arch_get_maximum_gpfn() ?

domain_get_maximum_gfn is already a common implementation.

Except prefixing this function by arch_. I don't think it's possible to be more common...

Regards,

Signature · 1 line
Julien Grall
#9 lore raw

Re: [PATCH 2/6] xen/arm: implement get_maximum_gpfn hypercall

In reply to Wei Huang

Hello Wei,

Quoted 34 lines · Wei Huang

From: Jaeyong Yoo <[email protected]>

This patchi implements get_maximum_gpfn by using the memory map info in arch_domain (from set_memory_map hypercall).

---
 xen/arch/arm/mm.c        | 19 ++++++++++++++++++-
 xen/include/asm-arm/mm.h |  2 ++
 2 files changed, 20 insertions(+), 1 deletion(-)
xen/arch/arm/mm.c +8 -1
index 362bc8d..14b4686 100644
@@ -947,7 +947,11 @@ int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
 
 unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
-    return -ENOSYS;
+    paddr_t end;
+
+    get_gma_start_end(d, NULL, &end);
+
+    return (unsigned long) (end >> PAGE_SHIFT);
 }
 void share_xen_page_with_guest(struct page_info *page,
@@ -1235,6 +1239,19 @@ int is_iomem_page(unsigned long mfn)
         return 1;
     return 0;
 }
+
+/*
+ * Return start and end addresses of guest

xen/arch/arm/mm.c int is_iomem_page(unsigned long mfn) · line 1254

Quoted 10 lines
xen/arch/arm/mm.c +10 -0
+ */
+void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end)
+{
+    if ( start )
+        *start = GUEST_RAM_BASE;
+
+    if ( end )
+        *end = GUEST_RAM_BASE + ((paddr_t) d->max_pages << PAGE_SHIFT);
+}
+

Ian plans to add multiple banks support for the guest very soon. This solution will stop to work.

Late december, we've introduce max_mapped_pfn for ARM which give the maximum pfn mapped in the guest.

Would it suit for your purpose? FYI x86 uses a similar solution.

Regards,

Signature · 1 line
Julien Grall
author
#10 lore raw

PATCH 3/6 xen/arm: Implement do_suspend function

In reply to Wei Huang

From: Jaeyong Yoo <[email protected]>

Making sched_op in do_suspend (driver/xen/manage.c) returns 0 on the success of suspend.

---
 tools/libxc/xc_resume.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/libxc/xc_resume.c +25 -0
index 18b4818..9315eb8 100644
@@ -73,6 +73,31 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)
     return 0;
 }
 
+#elif defined(__arm__)
+
+static int modify_returncode(xc_interface *xch, uint32_t domid)
+{
+    vcpu_guest_context_any_t ctxt;
+    xc_dominfo_t info;
+    int rc;
+
+    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
+    {
+        PERROR("Could not get domain info");
+        return -1;
+    }
+
+    if ( (rc = xc_vcpu_getcontext(xch, domid, 0, &ctxt)) != 0 )
+        return rc;
+
+    ctxt.c.user_regs.r0_usr = 1;
+
+    if ( (rc = xc_vcpu_setcontext(xch, domid, 0, &ctxt)) != 0 )
+        return rc;
+
+    return 0;
+}
+
 #else
 
 static int modify_returncode(xc_interface *xch, uint32_t domid)
Signature · 1 line
1.8.3.2
#11 lore raw

Re: [PATCH 3/6] xen/arm: Implement do_suspend function

Hello,

Thank you for the patch.

Quoted 15 lines · Wei Huang

From: Jaeyong Yoo <[email protected]>

Making sched_op in do_suspend (driver/xen/manage.c) returns 0 on the success of suspend.

---
 tools/libxc/xc_resume.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tools/libxc/xc_resume.c +0 -0
index 18b4818..9315eb8 100644

tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 77

Quoted 5 lines
tools/libxc/xc_resume.c +2 -0
@@ -73,6 +73,31 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)
     return 0;
 }
 
+#elif defined(__arm__)
+

Did you forget to implement arm64?

Regards,

Signature · 1 line
Julien Grall
author
#12 lore raw

PATCH 4/6 xen/arm: Implement VLPT for guest p2m mapping in live migration

In reply to Wei Huang

From: Jaeyong Yoo <[email protected]>

Thsi patch implements VLPT (virtual-linear page table) for fast accessing of 3rd PTE of guest P2M. For more info about VLPT, please see
http://www.technovelty.org/linux/virtual-linear-page-table.html.

When creating a mapping for VLPT, just copy the 1st level PTE of guest p2m to xen's 2nd level PTE. Then the mapping becomes the following:

      xen's 1st PTE -->
      xen's 2nd PTE (which is the same as 1st PTE of guest p2m) -->
      guest p2m's 2nd PTE -->
      guest p2m's 3rd PTE (the memory contents where the vlpt points)

This function is used in dirty-page tracing. When domU write-fault is trapped by xen, xen can immediately locate the 3rd PTE of guest p2m.

The following link shows the performance comparison for handling a dirty-page between vlpt and typical page table walking.
http://lists.xen.org/archives/html/xen-devel/2013-08/msg01503.html

---
 xen/arch/arm/domain.c            |   5 ++
 xen/arch/arm/mm.c                | 116 +++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/arm32/page.h |  23 ++++----
 xen/include/asm-arm/config.h     |   9 +++
 xen/include/asm-arm/domain.h     |   7 +++
 xen/include/asm-arm/mm.h         |  16 ++++++
 6 files changed, 166 insertions(+), 10 deletions(-)
xen/arch/arm/domain.c +5 -0
index b125857..3f04a77 100644
@@ -502,6 +502,11 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
 
+    d->arch.dirty.second_lvl_start = 0;
+    d->arch.dirty.second_lvl_end = 0;
+    d->arch.dirty.second_lvl[0] = NULL;
+    d->arch.dirty.second_lvl[1] = NULL;
+
     clear_page(d->shared_info);
     share_xen_page_with_guest(
         virt_to_page(d->shared_info), d, XENSHARE_writable);
xen/arch/arm/mm.c +116 -0

122 lines not on this page · raw message

xen/include/asm-arm/arm32/page.h +13 -10
index 4abb281..feca06c 100644
@@ -3,22 +3,25 @@
 
 #ifndef __ASSEMBLY__
 
-/* Write a pagetable entry.
- *
- * If the table entry is changing a text mapping, it is responsibility
- * of the caller to issue an ISB after write_pte.
- */
-static inline void write_pte(lpae_t *p, lpae_t pte)
+/* Write a pagetable entry. All necessary barriers are responsibility of
+ * the caller */
+static inline void __write_pte(lpae_t *p, lpae_t pte)
 {
     asm volatile (
-        /* Ensure any writes have completed with the old mappings. */
-        "dsb;"
-        /* Safely write the entry (STRD is atomic on CPUs that support LPAE) */
+        /* safely write the entry (STRD is atomic on CPUs that support LPAE) */
         "strd %0, %H0, [%1];"
-        "dsb;"
         : : "r" (pte.bits), "r" (p) : "memory");
 }
 
+/* Write a pagetable entry with dsb barriers. All necessary barriers are
+ * responsibility of the caller. */
+static inline void write_pte(lpae_t *p, lpae_t pte)
+{
+    dsb();
+    __write_pte(p, pte);
+    dsb();
+}
+
 /* Inline ASM to flush dcache on register R (may be an inline asm operand) */
 #define __clean_xen_dcache_one(R) STORE_CP32(R, DCCMVAC)
 
xen/include/asm-arm/config.h +9 -0
index 5b7b1a8..95e84bd 100644
@@ -87,6 +87,7 @@
  *   0  -   8M   <COMMON>
  *
  *  32M - 128M   Frametable: 24 bytes per page for 16GB of RAM
+ * 128M - 256M   Virtual-linear mapping to P2M table
  * 256M -   1G   VMAP: ioremap and early_ioremap use this virtual address
  *                    space
  *
@@ -124,7 +125,9 @@
 #define CONFIG_SEPARATE_XENHEAP 1
 
 #define FRAMETABLE_VIRT_START  _AT(vaddr_t,0x02000000)
+#define VIRT_LIN_P2M_START     _AT(vaddr_t,0x08000000)
 #define VMAP_VIRT_START  _AT(vaddr_t,0x10000000)
+#define VIRT_LIN_P2M_END       VMAP_VIRT_START
 #define XENHEAP_VIRT_START     _AT(vaddr_t,0x40000000)
 #define XENHEAP_VIRT_END       _AT(vaddr_t,0x7fffffff)
 #define DOMHEAP_VIRT_START     _AT(vaddr_t,0x80000000)
@@ -157,6 +160,12 @@
 
 #define HYPERVISOR_VIRT_END    DIRECTMAP_VIRT_END
 
+/* Temporary definition for VIRT_LIN_P2M_START and VIRT_LIN_P2M_END
+ * TODO: Needs evaluation!!!!
+ */
+#define VIRT_LIN_P2M_START     _AT(vaddr_t, 0x08000000)
+#define VIRT_LIN_P2M_END       VMAP_VIRT_START
+
 #endif
 
 /* Fixmap slots */
xen/include/asm-arm/domain.h +7 -0
index 28c359a..5321bd6 100644
@@ -161,6 +161,13 @@ struct arch_domain
         spinlock_t                  lock;
     } vuart;
 
+    /* dirty-page tracing */
+    struct {
+        volatile int second_lvl_start;   /* for context switch */
+        volatile int second_lvl_end;
+        lpae_t *second_lvl[2];           /* copy of guest p2m's first */
+    } dirty;
+
     unsigned int evtchn_irq;
 }  __cacheline_aligned;
 
xen/include/asm-arm/mm.h +16 -0
index 341493a..75c27fb 100644
@@ -4,6 +4,7 @@
 #include <xen/config.h>
 #include <xen/kernel.h>
 #include <asm/page.h>
+#include <asm/config.h>
 #include <public/xen.h>
 
 /* Align Xen to a 2 MiB boundary. */
@@ -342,6 +343,21 @@ static inline void put_page_and_type(struct page_info *page)
 }
 
 void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end);
+int prepare_vlpt(struct domain *d);
+void cleanup_vlpt(struct domain *d);
+void restore_vlpt(struct domain *d);
+
+/* calculate the xen''s virtual address for accessing the leaf PTE of
+ * a given address (GPA) */
+static inline lpae_t * get_vlpt_3lvl_pte(paddr_t addr)
+{
+    lpae_t *table = (lpae_t *)VIRT_LIN_P2M_START;
+
+    /* Since we slotted the guest''s first p2m page table to xen''s
+     * second page table, one shift is enough for calculating the
+     * index of guest p2m table entry */
+    return &table[addr >> PAGE_SHIFT];
+}
 
 #endif /*  __ARCH_ARM_MM__ */
 /*
Signature · 1 line
1.8.3.2
author
#13 lore raw

PATCH 5/6 xen/arm: Implement hypercall for dirty page tracing

In reply to Wei Huang

From: Jaeyong Yoo <[email protected]>

This patch adds hypercall for shadow operations, including enable/disable and clean/peek dirty page bitmap.

The design consists of two parts: dirty page detecting and saving. For detecting, we setup the guest p2m's leaf PTE read-only and whenever the guest tries to write something, permission fault happens and traps into xen. The permission-faulted GPA should be saved for the toolstack, which checks which pages are dirty. For this purpose, it temporarily saves the GPAs into bitmap.

---
 xen/arch/arm/domain.c           |  14 +++
 xen/arch/arm/domctl.c           |   9 ++
 xen/arch/arm/mm.c               | 105 +++++++++++++++++++-
 xen/arch/arm/p2m.c              | 208 ++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/traps.c            |   9 ++
 xen/include/asm-arm/domain.h    |   7 ++
 xen/include/asm-arm/mm.h        |   8 ++
 xen/include/asm-arm/p2m.h       |   8 +-
 xen/include/asm-arm/processor.h |   2 +
 9 files changed, 368 insertions(+), 2 deletions(-)
xen/arch/arm/domain.c +14 -0
index 3f04a77..d2531ed 100644
@@ -207,6 +207,12 @@ static void ctxt_switch_to(struct vcpu *n)
 
     isb();
 
+    /* Dirty-page tracing
+     * NB: How do we consider SMP case?
+     */
+    if ( n->domain->arch.dirty.mode )
+        restore_vlpt(n->domain);
+
     /* This is could trigger an hardware interrupt from the virtual
      * timer. The interrupt needs to be injected into the guest. */
     virt_timer_restore(n);
@@ -502,11 +508,19 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)
     /* Default the virtual ID to match the physical */
     d->arch.vpidr = boot_cpu_data.midr.bits;
 
+    /* init for dirty-page tracing */
+    d->arch.dirty.count = 0;
+    d->arch.dirty.mode = 0;
+    spin_lock_init(&d->arch.dirty.lock);
+
     d->arch.dirty.second_lvl_start = 0;
     d->arch.dirty.second_lvl_end = 0;
     d->arch.dirty.second_lvl[0] = NULL;
     d->arch.dirty.second_lvl[1] = NULL;
 
+    memset(d->arch.dirty.bitmap, 0, sizeof(d->arch.dirty.bitmap));
+    d->arch.dirty.bitmap_pages = 0;
+
     clear_page(d->shared_info);
     share_xen_page_with_guest(
         virt_to_page(d->shared_info), d, XENSHARE_writable);
xen/arch/arm/domctl.c +9 -0
index 914de29..e67381b 100644
@@ -95,6 +95,15 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
             xfree(c.data);
     }
     break;
+    case XEN_DOMCTL_shadow_op:
+    {
+        domain_pause(d);
+        ret = dirty_mode_op(d, &domctl->u.shadow_op);
+        domain_unpause(d);
+
+        copyback = 1;
+    }
+    break;
 
     case XEN_DOMCTL_cacheflush:
     {
xen/arch/arm/mm.c +104 -1

126 lines not on this page · raw message

xen/arch/arm/p2m.c +208 -0

232 lines not on this page · raw message

xen/arch/arm/traps.c +9 -0
index a7edc4e..42c8b75 100644
@@ -1491,6 +1491,8 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
     struct hsr_dabt dabt = hsr.dabt;
     int rc;
     mmio_info_t info;
+    int page_fault = ( (dabt.dfsc & FSC_MASK) ==
+                          (FSC_FLT_PERM | FSC_3D_LEVEL) && dabt.write );
 
     if ( !check_conditional_instr(regs, hsr) )
     {
@@ -1512,6 +1514,13 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
     if ( rc == -EFAULT )
         goto bad_data_abort;
 
+    /* domU page fault handling for guest live migration */
+    /* dabt.valid can be 0 here */
+    if ( page_fault && handle_page_fault(current->domain, info.gpa) )
+    {
+        /* Do not modify pc after page fault to repeat memory operation */
+        return;
+    }
     /* XXX: Decode the instruction if ISS is not valid */
     if ( !dabt.valid )
         goto bad_data_abort;
xen/include/asm-arm/domain.h +7 -0
index 5321bd6..99f9f51 100644
@@ -163,9 +163,16 @@ struct arch_domain
 
     /* dirty-page tracing */
     struct {
+#define MAX_DIRTY_BITMAP_PAGES 64        /* support upto 8GB guest memory */
+        spinlock_t lock;                 /* protect list: head, mvn_head */
+        volatile int mode;               /* 1 if dirty pages tracing enabled */
+        volatile unsigned int count;     /* dirty pages counter */
         volatile int second_lvl_start;   /* for context switch */
         volatile int second_lvl_end;
         lpae_t *second_lvl[2];           /* copy of guest p2m's first */
+        /* dirty bitmap */
+        uint8_t *bitmap[MAX_DIRTY_BITMAP_PAGES];
+        int bitmap_pages;                /* number of dirty bitmap pages */
     } dirty;
 
     unsigned int evtchn_irq;
xen/include/asm-arm/mm.h +8 -0
index 75c27fb..6733021 100644
@@ -342,11 +342,19 @@ static inline void put_page_and_type(struct page_info *page)
     put_page(page);
 }
 
+enum mg { mg_clear, mg_ro, mg_rw, mg_rx };
+
+/* routine for dirty-page tracing */
+int handle_page_fault(struct domain *d, paddr_t addr);
+
 void get_gma_start_end(struct domain *d, paddr_t *start, paddr_t *end);
 int prepare_vlpt(struct domain *d);
 void cleanup_vlpt(struct domain *d);
 void restore_vlpt(struct domain *d);
 
+int prepare_bitmap(struct domain *d);
+void cleanup_bitmap(struct domain *d);
+
 /* calculate the xen''s virtual address for accessing the leaf PTE of
  * a given address (GPA) */
 static inline lpae_t * get_vlpt_3lvl_pte(paddr_t addr)
xen/include/asm-arm/p2m.h +7 -1
index bd71abe..0cecbe7 100644
@@ -2,6 +2,7 @@
 #define _XEN_P2M_H
 
 #include <xen/mm.h>
+#include <public/domctl.h>
 
 struct domain;
 
@@ -41,6 +42,7 @@ typedef enum {
     p2m_invalid = 0,    /* Nothing mapped here */
     p2m_ram_rw,         /* Normal read/write guest RAM */
     p2m_ram_ro,         /* Read-only; writes are silently dropped */
+    p2m_ram_logdirty,   /* Read-only: special mode for log dirty */
     p2m_mmio_direct,    /* Read/write mapping of genuine MMIO area */
     p2m_map_foreign,    /* Ram pages from foreign domain */
     p2m_grant_map_rw,   /* Read/write grant mapping */
@@ -49,7 +51,8 @@ typedef enum {
 } p2m_type_t;
 
 #define p2m_is_foreign(_t)  ((_t) == p2m_map_foreign)
-#define p2m_is_ram(_t)      ((_t) == p2m_ram_rw || (_t) == p2m_ram_ro)
+#define p2m_is_ram(_t)      ((_t) == p2m_ram_rw || (_t) == p2m_ram_ro ||  \
+                             (_t) == p2m_ram_logdirty)
 
 /* Initialise vmid allocator */
 void p2m_vmid_allocator_init(void);
@@ -178,6 +181,9 @@ static inline int get_page_and_type(struct page_info *page,
     return rc;
 }
 
+void p2m_change_entry_type_global(struct domain *d, enum mg nt);
+long dirty_mode_op(struct domain *d, xen_domctl_shadow_op_t *sc);
+
 #endif /* _XEN_P2M_H */
 
 /*
xen/include/asm-arm/processor.h +2 -0
index 06e638f..9dc49c3 100644
@@ -399,6 +399,8 @@ union hsr {
 #define FSC_CPR        (0x3a) /* Coprocossor Abort */
 
 #define FSC_LL_MASK    (_AC(0x03,U)<<0)
+#define FSC_MASK       (0x3f) /* Fault status mask */
+#define FSC_3D_LEVEL   (0x03) /* Third level fault*/
 
 /* Time counter hypervisor control register */
 #define CNTHCTL_PA      (1u<<0)  /* Kernel/user access to physical counter */
Signature · 1 line
1.8.3.2
author
#14 lore raw

PATCH 6/6 xen/arm: Implement toolstack for xl restore/save and migrate

In reply to Wei Huang

From: Alexey Sokolov <[email protected]>

This patch implements xl save/restore operation in xc_arm_migrate.c and make it compilable with existing design. The operation is also used by migration.

The overall process of save is the following:
1) save guest parameters (i.e., memory map, console and store pfn, etc)
2) save memory (if it is live migration, perform dirty-page tracing)
3) save hvm states (i.e., gic, timer, vcpu etc)

---
 config/arm32.mk              |   1 +
 config/arm64.mk              |   1 +
 tools/libxc/Makefile         |   6 +-
 tools/libxc/xc_arm_migrate.c | 712 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_dom_arm.c     |   4 +-
 tools/libxl/libxl.h          |   3 -
 tools/misc/Makefile          |   4 +-
 7 files changed, 724 insertions(+), 7 deletions(-)
 create mode 100644 tools/libxc/xc_arm_migrate.c
config/arm32.mk +1 -0
index aa79d22..01374c9 100644
@@ -1,6 +1,7 @@
 CONFIG_ARM := y
 CONFIG_ARM_32 := y
 CONFIG_ARM_$(XEN_OS) := y
+CONFIG_MIGRATE := y
 
 CONFIG_XEN_INSTALL_SUFFIX :=
 
config/arm64.mk +1 -0
index 15b57a4..7ac3b65 100644
@@ -1,6 +1,7 @@
 CONFIG_ARM := y
 CONFIG_ARM_64 := y
 CONFIG_ARM_$(XEN_OS) := y
+CONFIG_MIGRATE := y
 
 CONFIG_XEN_INSTALL_SUFFIX :=
 
tools/libxc/Makefile +5 -1
index 2cca2b2..6b90b1c 100644
@@ -43,8 +43,13 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
 ifeq ($(CONFIG_MIGRATE),y)
+ifeq ($(CONFIG_X86),y)
 GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c
 GUEST_SRCS-y += xc_offline_page.c xc_compression.c
+endif
+ifeq ($(CONFIG_ARM),y)
+GUEST_SRCS-y += xc_arm_migrate.c
+endif
 else
 GUEST_SRCS-y += xc_nomigrate.c
 endif
@@ -64,7 +69,6 @@ $(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
 GUEST_SRCS-y                 += xc_dom_core.c xc_dom_boot.c
 GUEST_SRCS-y                 += xc_dom_elfloader.c
 GUEST_SRCS-$(CONFIG_X86)     += xc_dom_bzimageloader.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_decompress_lz4.c
 GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_armzimageloader.c
 GUEST_SRCS-y                 += xc_dom_binloader.c
 GUEST_SRCS-y                 += xc_dom_compat_linux.c
tools/libxc/xc_arm_migrate.c new file +712 -0

712 lines not on this page · raw message

tools/libxc/xc_dom_arm.c +3 -1
index a40e04d..f4d3af4 100644
@@ -297,7 +297,9 @@ int arch_setup_meminit(struct xc_dom_image *dom)
                   dom->devicetree_seg.vstart, dom->devicetree_seg.vend);
     }
 
-    return 0;
+    return xc_domain_setmaxmem(dom->xch, dom->guest_domid,
+                               (dom->total_pages + NR_MAGIC_PAGES)
+                                << (PAGE_SHIFT - 10));
 }
 
 int arch_setup_bootearly(struct xc_dom_image *dom)
tools/libxl/libxl.h +0 -3
index b2c3015..e10f4fb 100644
@@ -441,9 +441,6 @@
  *  - libxl_domain_resume
  *  - libxl_domain_remus_start
  */
-#if defined(__arm__) || defined(__aarch64__)
-#define LIBXL_HAVE_NO_SUSPEND_RESUME 1
-#endif
 
 /*
  * LIBXL_HAVE_DEVICE_PCI_SEIZE
tools/misc/Makefile +2 -2
index 17aeda5..0824100 100644
@@ -11,7 +11,7 @@ HDRS     = $(wildcard *.h)
 
 TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xenwatchdogd xencov
 TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvmcrash xen-lowmemd xen-mfndump
-TARGETS-$(CONFIG_MIGRATE) += xen-hptool
+TARGETS-$(CONFIG_X86) += xen-hptool
 TARGETS := $(TARGETS-y)
 
 SUBDIRS := $(SUBDIRS-y)
@@ -23,7 +23,7 @@ INSTALL_BIN := $(INSTALL_BIN-y)
 INSTALL_SBIN-y := xen-bugtool xen-python-path xenperf xenpm xen-tmem-list-parse gtraceview \
 	gtracestat xenlockprof xenwatchdogd xen-ringwatch xencov
 INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx xen-hvmcrash xen-lowmemd xen-mfndump
-INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool
+INSTALL_SBIN-$(CONFIG_X86) += xen-hptool
 INSTALL_SBIN := $(INSTALL_SBIN-y)
 
 INSTALL_PRIVBIN-y := xenpvnetboot
Signature · 1 line
1.8.3.2
#15 lore raw
In reply to Wei Huang

Hi Wei,

Thank you for the series, I plan to give a try on midway. On which board did you try the migration?

Quoted 16 lines · Wei Huang

The following are the save/restore/live-migration patches I forward-ported to the latest Xen tree. Note that I kept the order of original patches, and Signed-off-by as well. For the patches I modified (see summary below), I added my name as Signed-off-by.

These patches aren't intended as the final version. Since Junghyun Yoo is working on his patches, I think it is better to send out my version now for discussion and proper merge. Let us make Xen 4.5 support these features.

=== Modification Summary ===

Patch 1:
* Adapt to latest Xen source code
* Setting IRQ status as enabled by checking ieanble bits after loading VM info
* Minor fixes to support 64-bit

Quoted 6 lines

Patch 5:
* Add new p2m ARM type (p2m_ram_logdirty) to support dirty page tracking

Patch 6:
* Enable save/restore/live migration support based on latest Xen code
* Adapt to latest Xen source code

Might be a stupid, did you go through the different comments on the v5 sent by Jaeyong? Sorry if it was the case.

Regards,

Signature · 1 line
Julien Grall
author
#16 lore raw
Quoted 4 lines · Julien Grall

Hi Wei,

Thank you for the series, I plan to give a try on midway. On which board did you try the migration?

I tested the patches on a system with A15 CPUs. I don't see any problem to run them on midway. You need patches for DomU to support migration. Most of them were from Jaeyong's patch posted before (I made some modification). IMO they are hack-ish, so I didn't post them here. I can set them to you in private email. Let me know.

Quoted 21 lines · Wei Huang
Quoted 19 lines

The following are the save/restore/live-migration patches I forward-ported to the latest Xen tree. Note that I kept the order of original patches, and Signed-off-by as well. For the patches I modified (see summary below), I added my name as Signed-off-by.

These patches aren't intended as the final version. Since Junghyun Yoo is working on his patches, I think it is better to send out my version now for discussion and proper merge. Let us make Xen 4.5 support these features.

=== Modification Summary ===

Patch 1:
* Adapt to latest Xen source code
* Setting IRQ status as enabled by checking ieanble bits after loading VM info
* Minor fixes to support 64-bit

Patch 5:
* Add new p2m ARM type (p2m_ram_logdirty) to support dirty page tracking

Quoted 6 lines
Quoted 3 lines

Patch 6:
* Enable save/restore/live migration support based on latest Xen code
* Adapt to latest Xen source code

Might be a stupid, did you go through the different comments on the v5 sent by Jaeyong? Sorry if it was the case.

Not completely. I will work on them in next revision. If Junghyun has fixes, please post them too.

Quoted 3 lines

Regards,

#17 lore raw
Quoted 10 lines · Wei Huang
Quoted 4 lines · Julien Grall

Hi Wei,

Thank you for the series, I plan to give a try on midway. On which board did you try the migration?

I tested the patches on a system with A15 CPUs. I don't see any problem to run them on midway. You need patches for DomU to support migration. Most of them were from Jaeyong's patch posted before (I made some modification). IMO they are hack-ish, so I didn't post them here. I can set them to you in private email. Let me know.

Is it the one posted in July 2013? If you have an updated version, can you send me the series?

Quoted 25 lines
Quoted 25 lines · Wei Huang
Quoted 23 lines

The following are the save/restore/live-migration patches I forward-ported to
the latest Xen tree. Note that I kept the order of original patches, and Signed-off-by as well. For the patches I modified (see summary below), I added my name as Signed-off-by.

These patches aren't intended as the final version. Since Junghyun Yoo is
working on his patches, I think it is better to send out my version now for discussion and proper merge. Let us make Xen 4.5 support these features.

=== Modification Summary ===

Patch 1:
* Adapt to latest Xen source code
* Setting IRQ status as enabled by checking ieanble bits after loading VM info
* Minor fixes to support 64-bit

Patch 5:
* Add new p2m ARM type (p2m_ram_logdirty) to support dirty page tracking

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Patch 6:
* Enable save/restore/live migration support based on latest Xen code
* Adapt to latest Xen source code

Might be a stupid, did you go through the different comments on the v5 sent by Jaeyong? Sorry if it was the case.

Not completely. I will work on them in next revision. If Junghyun has fixes, please post them too.

Thanks, I will wait the next version before reviewing. I don't want to bother you with the same comments :).

Regards,

Signature · 1 line
Julien Grall
author
#18 lore raw
Quoted 6 lines · Julien Grall
Quoted 5 lines · Wei Huang
Quoted 4 lines · Julien Grall

Hi Wei,

Thank you for the series, I plan to give a try on midway. On which board did you try the migration?

Quoted 8 lines
Quoted 5 lines

I tested the patches on a system with A15 CPUs. I don't see any problem to run them on midway. You need patches for DomU to support migration. Most of them were from Jaeyong's patch posted before (I made some modification). IMO they are hack-ish, so I didn't post them here. I can set them to you in private email. Let me know.

Is it the one posted in July 2013? If you have an updated version, can you send me the series?

Yes, it was from July 2013.

Quoted 40 lines
Quoted 26 lines
Quoted 26 lines · Wei Huang
Quoted 23 lines

The following are the save/restore/live-migration patches I forward-ported to
the latest Xen tree. Note that I kept the order of original patches, and Signed-off-by as well. For the patches I modified (see summary below), I added my name as Signed-off-by.

These patches aren't intended as the final version. Since Junghyun Yoo is
working on his patches, I think it is better to send out my version now for discussion and proper merge. Let us make Xen 4.5 support these features.

=== Modification Summary ===

Patch 1:
* Adapt to latest Xen source code
* Setting IRQ status as enabled by checking ieanble bits after loading VM info
* Minor fixes to support 64-bit

Patch 5:
* Add new p2m ARM type (p2m_ram_logdirty) to support dirty page tracking

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Patch 6:
* Enable save/restore/live migration support based on latest Xen code
* Adapt to latest Xen source code

Might be a stupid, did you go through the different comments on the v5 sent by Jaeyong? Sorry if it was the case.

Not completely. I will work on them in next revision. If Junghyun has fixes, please post them too.

Thanks, I will wait the next version before reviewing. I don't want to bother you with the same comments :).

Regards,

#19 lore raw
Quoted 14 lines · Wei Huang
Quoted 13 lines · Julien Grall
Quoted 11 lines · Wei Huang
Quoted 5 lines · Julien Grall

Hi Wei,

Thank you for the series, I plan to give a try on midway. On which board
did you try the migration?

I tested the patches on a system with A15 CPUs. I don't see any problem to run them on midway. You need patches for DomU to support migration. Most of them were from Jaeyong's patch posted before (I made some modification). IMO they are hack-ish, so I didn't post them here. I can set them to you in private email. Let me know.

Quoted 3 lines
Quoted 2 lines

Is it the one posted in July 2013? If you have an updated version, can you send me the series?

Yes, it was from July 2013.

What happen if the guest doesn't have this patch? Does the toolstack notify the user?

Regards,

Signature · 1 line
Julien Grall
author
#20 lore raw
Quoted 15 lines · Julien Grall
Quoted 14 lines · Wei Huang
Quoted 13 lines · Julien Grall
Quoted 11 lines · Wei Huang
Quoted 5 lines · Julien Grall

Hi Wei,

Thank you for the series, I plan to give a try on midway. On which board
did you try the migration?

I tested the patches on a system with A15 CPUs. I don't see any problem to run them on midway. You need patches for DomU to support migration. Most of them were from Jaeyong's patch posted before (I made some modification). IMO they are hack-ish, so I didn't post them here. I can set them to you in private email. Let me know.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Is it the one posted in July 2013? If you have an updated version, can you send me the series?

Yes, it was from July 2013.

What happen if the guest doesn't have this patch? Does the toolstack notify the user?

During migration, the toolstack will probe and check guest status. If guest doesn't support suspend, the migration (save/restore as well) will abort.

Quoted 3 lines

Regards,