From: Jaeyong Yoo <jaeyong.yoo@samsung.com>
To: xen-devel@lists.xen.org
Cc: Elena Pyatunina <e.pyatunina@samsung.com>
Subject: [PATCH RFC v2 6/9] xen/arm: Add handling write fault for dirty-page tracing
Date: Wed, 03 Jul 2013 18:15:40 +0900 [thread overview]
Message-ID: <1372842943-27482-7-git-send-email-jaeyong.yoo@samsung.com> (raw)
In-Reply-To: <1372842943-27482-1-git-send-email-jaeyong.yoo@samsung.com>
From: Elena Pyatunina <e.pyatunina@samsung.com>
Add handling write fault in do_trap_data_abort_guest for dirty-page
tracing. Mark dirty function makes the bitmap of dirty pages.
Signed-off-by: Elena Pyatunina <e.pyatunina@samsung.com>
Singed-off-by: Jaeyong Yoo <jaeyong.yoo@samsung.com>
---
xen/arch/arm/mm.c | 59 ++++++++++++++++++++++++++++++-
xen/arch/arm/p2m.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
xen/arch/arm/traps.c | 7 ++++
xen/include/asm-arm/domain.h | 8 +++++
xen/include/asm-arm/mm.h | 2 ++
xen/include/asm-arm/p2m.h | 3 ++
6 files changed, 162 insertions(+), 1 deletion(-)
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 650b1fc..f509008 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -680,7 +680,6 @@ void destroy_xen_mappings(unsigned long v, unsigned long e)
create_xen_entries(REMOVE, v, 0, (e - v) >> PAGE_SHIFT, 0);
}
-enum mg { mg_clear, mg_ro, mg_rw, mg_rx };
static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg)
{
lpae_t pte;
@@ -1142,6 +1141,64 @@ int is_iomem_page(unsigned long mfn)
return 1;
return 0;
}
+
+/*
+ * Set l3e entries of P2M table to be read-only.
+ *
+ * On first write, it page faults, its entry is changed to read-write,
+ * and on retry the write succeeds.
+ *
+ * Populate dirty_bitmap by looking for entries that have been
+ * switched to read-write.
+ */
+int handle_page_fault(struct domain *d, paddr_t addr)
+{
+ lpae_t pte, *first = NULL, *second = NULL, *third = NULL;
+ struct p2m_domain *p2m = &d->arch.p2m;
+
+ if ( d->arch.dirty.mode == 0 || first_table_offset(addr) >= LPAE_ENTRIES )
+ return 1;
+
+ spin_lock(&p2m->lock);
+
+ first = __map_domain_page(p2m->first_level);
+
+ if ( !first ||
+ !first[first_table_offset(addr)].walk.valid ||
+ !first[first_table_offset(addr)].walk.table )
+ goto done;
+
+ second = map_domain_page(first[first_table_offset(addr)].walk.base);
+
+ if ( !second ||
+ !second[second_table_offset(addr)].walk.valid ||
+ !second[second_table_offset(addr)].walk.table )
+ goto done;
+
+ third = map_domain_page(second[second_table_offset(addr)].walk.base);
+
+ if ( !third )
+ goto done;
+
+ pte = third[third_table_offset(addr)];
+
+ if (pte.p2m.valid && pte.p2m.write == 0)
+ {
+ mark_dirty(d, addr);
+ pte.p2m.write = 1;
+ write_pte(&third[third_table_offset(addr)], pte);
+ flush_tlb_local();
+ }
+
+done:
+ if (third) unmap_domain_page(third);
+ if (second) unmap_domain_page(second);
+ if (first) unmap_domain_page(first);
+
+ spin_unlock(&p2m->lock);
+ return 0;
+}
+
/*
* Local variables:
* mode: C
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 8bf7eb7..bae7af7 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -412,6 +412,90 @@ unsigned long gmfn_to_mfn(struct domain *d, unsigned long gpfn)
return p >> PAGE_SHIFT;
}
+static struct page_info * new_dirty_page(void)
+{
+ struct page_info *page = NULL;
+ void *p;
+
+ page = alloc_domheap_page(NULL, 0);
+ if ( page == NULL )
+ return NULL;
+
+ p = __map_domain_page(page);
+
+ clear_page(p);
+ unmap_domain_page(p);
+
+ return page;
+}
+
+void mark_dirty(struct domain *d, paddr_t addr)
+{
+ struct page_info *page;
+ xen_pfn_t *first = NULL, *second = NULL, *third = NULL;
+ void *p;
+ int changed;
+
+ spin_lock(&d->arch.dirty.lock);
+
+ if (d->arch.dirty.top == NULL)
+ {
+ page = alloc_domheap_pages(NULL, 1, 0);
+ if (page == NULL)
+ {
+ printk("Error: couldn't allocate page for dirty bitmap!\n");
+ spin_unlock(&d->arch.dirty.lock);
+ return;
+ }
+
+ INIT_PAGE_LIST_HEAD(&d->arch.dirty.pages);
+ page_list_add(page, &d->arch.dirty.pages);
+
+ /* Clear both first level pages */
+ p = __map_domain_page(page);
+ clear_page(p);
+ unmap_domain_page(p);
+
+ p = __map_domain_page(page + 1);
+ clear_page(p);
+ unmap_domain_page(p);
+
+ d->arch.dirty.top = page;
+ }
+
+ first = __map_domain_page(d->arch.dirty.top);
+ BUG_ON(!first && "Can't map first level p2m.");
+ if ( !first[first_table_offset(addr)])
+ {
+ page = new_dirty_page();
+ page_list_add(page, &d->arch.dirty.pages);
+ first[first_table_offset(addr)] = page_to_mfn(page);
+ }
+
+ second = map_domain_page(first[first_table_offset(addr)]);
+ BUG_ON(!second && "Can't map second level p2m.");
+ if (!second[second_table_offset(addr)])
+ {
+ page = new_dirty_page();
+ page_list_add(page, &d->arch.dirty.pages);
+ second[second_table_offset(addr)] = page_to_mfn(page);
+ }
+
+ third = map_domain_page(second[second_table_offset(addr)]);
+ BUG_ON(!third && "Can't map third level p2m.");
+ changed = !__test_and_set_bit(third_table_offset(addr), third);
+ if (changed)
+ {
+ d->arch.dirty.count++;
+ }
+
+ if (third) unmap_domain_page(third);
+ if (second) unmap_domain_page(second);
+ if (first) unmap_domain_page(first);
+
+ spin_unlock(&d->arch.dirty.lock);
+}
+
/*
* Local variables:
* mode: C
diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 398d209..9927712 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -1011,6 +1011,13 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs,
if ( rc == -EFAULT )
goto bad_data_abort;
+ /* handle permission fault on write */
+ if ((dabt.dfsc & 0x3f) == (FSC_FLT_PERM + 3) && dabt.write)
+ {
+ if (handle_page_fault(current->domain, info.gpa) == 0)
+ return;
+ }
+
if (handle_mmio(&info))
{
regs->pc += dabt.len ? 4 : 2;
diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h
index cb251cc..3536757 100644
--- a/xen/include/asm-arm/domain.h
+++ b/xen/include/asm-arm/domain.h
@@ -107,6 +107,14 @@ struct arch_domain
spinlock_t lock;
} uart0;
+ struct {
+ spinlock_t lock;
+ int mode;
+ unsigned int count;
+ struct page_info *top;
+ struct page_list_head pages;
+ } dirty;
+
} __cacheline_aligned;
struct arch_vcpu
diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index 5e7c5a3..2b961de 100644
--- a/xen/include/asm-arm/mm.h
+++ b/xen/include/asm-arm/mm.h
@@ -327,6 +327,8 @@ static inline void put_page_and_type(struct page_info *page)
put_page(page);
}
+int handle_page_fault(struct domain *d, paddr_t addr);
+
#endif /* __ARCH_ARM_MM__ */
/*
* Local variables:
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 379c453..fd5890f 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -110,6 +110,9 @@ static inline int get_page_and_type(struct page_info *page,
return rc;
}
+enum mg { mg_clear, mg_ro, mg_rw, mg_rx };
+void mark_dirty(struct domain *d, paddr_t addr);
+
#endif /* _XEN_P2M_H */
/*
--
1.8.1.2
next prev parent reply other threads:[~2013-07-03 9:15 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-03 9:15 [PATCH RFC v2 0/9] Preliminary working version of live migration Jaeyong Yoo
2013-07-03 9:15 ` [PATCH RFC v2 1/9] xen-arm: Implement basic save/load for hvm context Jaeyong Yoo
2013-07-03 11:29 ` Stefano Stabellini
2013-07-03 23:51 ` Jaeyong Yoo
2013-07-03 9:15 ` [PATCH RFC v2 2/9] xen/arm: Implement save and restore for gic, vtimer, and ptimer Jaeyong Yoo
2013-07-03 11:29 ` Stefano Stabellini
2013-07-03 23:53 ` Jaeyong Yoo
2013-07-03 9:15 ` [PATCH RFC v2 3/9] xen/arm: Add more registers for saving and restoring vcpu registers Jaeyong Yoo
2013-07-03 11:29 ` Stefano Stabellini
2013-07-03 9:15 ` [PATCH RFC v2 4/9] xen/arm: Implement get_maximum_gpfn hypercall for arm Jaeyong Yoo
2013-07-03 11:29 ` Stefano Stabellini
2013-07-03 11:35 ` Ian Campbell
2013-07-04 0:09 ` Jaeyong Yoo
2013-07-04 8:47 ` Ian Campbell
2013-07-03 9:15 ` [PATCH RFC v2 5/9] xen/arm: Implement modify_returncode Jaeyong Yoo
2013-07-03 9:15 ` Jaeyong Yoo [this message]
2013-07-03 12:10 ` [PATCH RFC v2 6/9] xen/arm: Add handling write fault for dirty-page tracing Stefano Stabellini
2013-07-04 0:44 ` Jaeyong Yoo
2013-07-03 12:26 ` Ian Campbell
2013-07-04 1:02 ` Jaeyong Yoo
2013-07-04 7:21 ` Jaeyong Yoo
2013-07-04 8:46 ` Ian Campbell
2013-07-04 11:47 ` Jaeyong Yoo
2013-07-05 4:42 ` Jaeyong Yoo
2013-07-07 16:53 ` Ian Campbell
2013-07-12 0:54 ` Jaeyong Yoo
2013-07-03 9:15 ` [PATCH RFC v2 7/9] xen/arm: Missing impl of clear_guest_offset macro Jaeyong Yoo
2013-07-03 11:37 ` Stefano Stabellini
2013-07-03 11:57 ` Ian Campbell
2013-07-04 0:09 ` Jaeyong Yoo
2013-07-03 9:15 ` [PATCH RFC v2 8/9] xen/arm: Implement hypercall for dirty page tracing (shadow op) Jaeyong Yoo
2013-07-03 12:38 ` Stefano Stabellini
2013-07-04 1:25 ` Jaeyong Yoo
2013-07-04 8:42 ` Ian Campbell
2013-07-04 10:18 ` Jaeyong Yoo
2013-07-04 10:29 ` Stefano Stabellini
2013-07-04 10:36 ` Ian Campbell
2013-07-10 15:34 ` Eugene Fedotov
2013-07-10 15:39 ` Ian Campbell
2013-07-11 10:18 ` Eugene Fedotov
2013-07-11 11:24 ` Ian Campbell
2013-07-03 9:15 ` [PATCH RFC v2 9/9] xen/arm: Implement toolstack for xl restore/save and migrate Jaeyong Yoo
2013-07-03 9:21 ` [PATCH RFC v2 0/9] Preliminary working version of live migration Ian Campbell
2013-07-03 12:54 ` Stefano Stabellini
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=1372842943-27482-7-git-send-email-jaeyong.yoo@samsung.com \
--to=jaeyong.yoo@samsung.com \
--cc=e.pyatunina@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).