xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Jaeyong Yoo <jaeyong.yoo@samsung.com>
To: xen-devel@lists.xen.org
Cc: Jaeyong Yoo <jaeyong.yoo@samsung.com>
Subject: [PATCH v4 7/9] xen/arm: Implement virtual-linear page table for guest p2m mapping in live migration
Date: Fri, 04 Oct 2013 13:44:03 +0900	[thread overview]
Message-ID: <1380861845-23268-8-git-send-email-jaeyong.yoo@samsung.com> (raw)
In-Reply-To: <1380861845-23268-1-git-send-email-jaeyong.yoo@samsung.com>

Implement vlpt (virtual-linear page table) for fast accessing of 3rd
PTE of guest p2m. When creating a mapping for vlpt, just copy the
1st level PTE of guest p2m to the 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)
For more info about vlpt, see:
http://www.technovelty.org/linux/virtual-linear-page-table.html

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.

Signed-off-by: Jaeyong Yoo <jaeyong.yoo@samsung.com>
---
 xen/arch/arm/mm.c            | 78 ++++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/config.h |  6 ++++
 xen/include/asm-arm/domain.h |  7 ++++
 xen/include/asm-arm/mm.h     | 22 +++++++++++++
 4 files changed, 113 insertions(+)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 120eae8..98edbc9 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1382,6 +1382,84 @@ int is_iomem_page(unsigned long mfn)
         return 1;
     return 0;
 }
+
+/* flush the vlpt area */
+static void flush_vlpt(struct domain *d)
+{
+    int flush_size;
+    flush_size = (d->arch.dirty.second_lvl_end -
+                  d->arch.dirty.second_lvl_start) << SECOND_SHIFT;
+    /* flushing the 3rd level mapping */
+    flush_xen_data_tlb_range_va(VIRT_LIN_P2M_START,
+                                flush_size);
+}
+
+/* restore the xen page table for vlpt mapping for domain d */
+void restore_vlpt(struct domain *d)
+{
+    int i, j = 0;
+    int need_flush = 0;
+
+    for ( i = d->arch.dirty.second_lvl_start;
+          i < d->arch.dirty.second_lvl_end;
+          ++i, ++j )
+    {
+        if ( xen_second[i].bits != d->arch.dirty.second_lvl[j].bits )
+        {
+            write_pte(&xen_second[i], d->arch.dirty.second_lvl[j]);
+            need_flush = 1;
+        }
+    }
+
+    if ( need_flush ) flush_vlpt(d);
+}
+
+/* setting up the xen page table for vlpt mapping for domain d */
+void prepare_vlpt(struct domain *d)
+{
+    int xen_second_linear_base;
+    int gp2m_start_index, gp2m_end_index;
+    struct p2m_domain *p2m = &d->arch.p2m;
+    struct page_info *second_lvl_page;
+    vaddr_t gma_start = 0;
+    vaddr_t gma_end = 0;
+    lpae_t *first;
+    int i, j;
+
+    xen_second_linear_base = second_linear_offset(VIRT_LIN_P2M_START);
+    get_gma_start_end(d, &gma_start, &gma_end);
+
+    gp2m_start_index = gma_start >> FIRST_SHIFT;
+    gp2m_end_index = (gma_end >> FIRST_SHIFT) + 1;
+
+    second_lvl_page = alloc_domheap_page(NULL, 0);
+    d->arch.dirty.second_lvl = map_domain_page_global(
+                                 page_to_mfn(second_lvl_page) );
+
+    first = __map_domain_page(p2m->first_level);
+    for ( i = gp2m_start_index, j = 0; i < gp2m_end_index; ++i, ++j )
+    {
+        write_pte(&xen_second[xen_second_linear_base+i],
+                  first[i]);
+
+        /* we copy the mapping into domain's structure as a reference in case
+         * of the context switch (used in restore_vlpt) */
+        d->arch.dirty.second_lvl[j] = first[i];
+    }
+    unmap_domain_page(first);
+
+    /* storing the start and end index */
+    d->arch.dirty.second_lvl_start = xen_second_linear_base + gp2m_start_index;
+    d->arch.dirty.second_lvl_end = xen_second_linear_base + gp2m_end_index;
+
+    flush_vlpt(d);
+}
+
+void cleanup_vlpt(struct domain *d)
+{
+    unmap_domain_page_global(d->arch.dirty.second_lvl);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h
index 9e395c2..47fc26e 100644
--- a/xen/include/asm-arm/config.h
+++ b/xen/include/asm-arm/config.h
@@ -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
  *
@@ -132,6 +133,9 @@
 
 #define VMAP_VIRT_END    XENHEAP_VIRT_START
 
+#define VIRT_LIN_P2M_START     _AT(vaddr_t,0x08000000)
+#define VIRT_LIN_P2M_END       VMAP_VIRT_START
+
 #define DOMHEAP_ENTRIES        1024  /* 1024 2MB mapping slots */
 
 /* Number of domheap pagetable pages required at the second level (2MB mappings) */
@@ -158,6 +162,8 @@
 
 #define HYPERVISOR_VIRT_END    DIRECTMAP_VIRT_END
 
+/*TODO (ARM_64): define VIRT_LIN_P2M_START VIRT_LIN_P2M_END */
+
 #endif
 
 /* Fixmap slots */
diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h
index 755c7af..7e7743a 100644
--- a/xen/include/asm-arm/domain.h
+++ b/xen/include/asm-arm/domain.h
@@ -112,6 +112,13 @@ struct arch_domain
         spinlock_t                  lock;
     } vuart;
 
+    /* dirty-page tracing */
+    struct {
+        int second_lvl_start;            /* for context switch */
+        int second_lvl_end;
+        lpae_t *second_lvl;
+    } dirty;
+
     struct dt_mem_info map_domain;
     spinlock_t         map_lock;
 }  __cacheline_aligned;
diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index 021e8d6..b9cbcf2 100644
--- a/xen/include/asm-arm/mm.h
+++ b/xen/include/asm-arm/mm.h
@@ -344,6 +344,28 @@ static inline void put_page_and_type(struct page_info *page)
 
 void get_gma_start_end(struct domain *d, vaddr_t *start, vaddr_t *end);
 
+/* vlpt (virtual linear page table) related functions */
+void 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(vaddr_t addr)
+{
+    unsigned long ipa_third = third_table_offset(addr);
+    unsigned long ipa_second = second_table_offset(addr);
+    unsigned long ipa_first = first_table_offset(addr);
+
+    /* guest p2m's first level index is the index of xen's second level,
+       and guest p2m's second level index is the index of xen's third level */
+    return (lpae_t *)(
+        ( (second_linear_offset(VIRT_LIN_P2M_START) + ipa_first)
+           << SECOND_SHIFT) +
+        (ipa_second << THIRD_SHIFT) +
+        (ipa_third << 3) );
+}
+
 #endif /*  __ARCH_ARM_MM__ */
 /*
  * Local variables:
-- 
1.8.1.2

  parent reply	other threads:[~2013-10-04  4:44 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-04  4:43 [PATCH v4 0/9] xen/arm: live migration support in arndale board Jaeyong Yoo
2013-10-04  4:43 ` [PATCH v4 1/9] xen/arm: Implement hvm save and restore Jaeyong Yoo
2013-10-07 12:49   ` Julien Grall
2013-10-04  4:43 ` [PATCH v4 2/9] xen/arm: Add more registers for saving and restoring vcpu registers Jaeyong Yoo
2013-10-10 10:40   ` Ian Campbell
2013-10-11  8:30     ` Jaeyong Yoo
2013-10-11  8:43       ` Ian Campbell
2013-10-11 10:22         ` Tim Deegan
2013-10-11 10:25           ` Ian Campbell
2013-10-14  4:39             ` Jaeyong Yoo
2013-10-17  2:14               ` Jaeyong Yoo
2013-10-17 10:01                 ` Ian Campbell
2013-10-04  4:43 ` [PATCH v4 3/9] xen/arm: Implement set_memory_map hypercall for arm Jaeyong Yoo
2013-10-10 10:56   ` Ian Campbell
2013-10-11 10:06     ` Eugene Fedotov
2013-10-11 10:09       ` Ian Campbell
2013-10-11 10:18         ` Tim Deegan
2013-10-31  8:56         ` Eugene Fedotov
2013-11-01  9:04           ` Ian Campbell
2013-11-01  9:14           ` Ian Campbell
2013-11-01  9:51             ` Eugene Fedotov
2013-11-01  9:48               ` Ian Campbell
2013-11-01 10:08                 ` Eugene Fedotov
2013-11-01 10:30                   ` Ian Campbell
2013-10-04  4:44 ` [PATCH v4 4/9] xen/arm: Implement get_maximum_gpfn " Jaeyong Yoo
2013-10-04  4:44 ` [PATCH v4 5/9] xen/arm: Implement modify_returncode Jaeyong Yoo
2013-10-04  4:44 ` [PATCH v4 6/9] xen/arm: Fixing clear_guest_offset macro Jaeyong Yoo
2013-10-07 12:53   ` Julien Grall
2013-10-10 12:00     ` Ian Campbell
2013-10-04  4:44 ` Jaeyong Yoo [this message]
2013-10-16 12:50   ` [PATCH v4 7/9] xen/arm: Implement virtual-linear page table for guest p2m mapping in live migration Ian Campbell
2013-10-17  8:58     ` Jaeyong Yoo
2013-10-17 10:06       ` Ian Campbell
2013-10-17 10:25         ` Jaeyong Yoo
2013-10-04  4:44 ` [PATCH v4 8/9] xen/arm: Implement hypercall for dirty page tracing Jaeyong Yoo
2013-10-07 13:02   ` Julien Grall
2013-10-07 15:51     ` Eugene Fedotov
2013-10-10 14:10       ` Julien Grall
2013-10-16 13:44   ` Ian Campbell
2013-10-17 10:12     ` Jaeyong Yoo
2013-10-17 10:30       ` Ian Campbell
2013-10-17 11:05         ` Jaeyong Yoo
2013-10-17 11:47           ` Ian Campbell
2013-10-18  4:17             ` Jaeyong Yoo
2013-10-18  9:11               ` Ian Campbell
2013-10-04  4:44 ` [PATCH v4 9/9] xen/arm: Implement toolstack for xl restore/save and migrate Jaeyong Yoo
2013-10-16 13:55   ` Ian Campbell
2013-10-17 10:14     ` Jaeyong Yoo

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=1380861845-23268-8-git-send-email-jaeyong.yoo@samsung.com \
    --to=jaeyong.yoo@samsung.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).