3 files changed, 69 insertions(+), 2 deletions(-)
xen/arch/powerpc/domain.c | 62 ++++++++++++++++++++++++++++++++++++++
xen/include/asm-powerpc/domain.h | 6 +++
xen/include/asm-powerpc/shadow.h | 3 +
# HG changeset patch
# User Ryan Harper <ryanh@xxxxxxxxxx>
# Date 1172776732 21600
# Node ID 539e61f7482e832ffc372f0fa8d745202f86baa4
# Parent 0a9ecb03cb24b9035726dd316ca6af388983c05b
[PATCH] xen: implement guest_physmap_max_mem_pages() for ppc
Implement arch hook for setting domain max_mem_pages. This triggers the
creation/extension of the domain's physical to machine (p2m) mapping array.
This array is used to translate a guest physical address to the corresponding
machine frame. Currently we only support growing the size of the p2m array.
When the size of the array is increased, we copy over the existing mappings and
initialize any new slots to INVALID_MFN. The size of the current p2m array is
kept in d->arch.p2m_size. The p2m table can be larger than d->max_pages for
dom0 as it needs to account for platform iohole. p2m table will always be at
least d->max_pages.
Signed-off-by: Ryan Harper <ryanh@xxxxxxxxxx>
diff -r 0a9ecb03cb24 -r 539e61f7482e xen/arch/powerpc/domain.c
--- a/xen/arch/powerpc/domain.c Thu Mar 01 13:18:52 2007 -0600
+++ b/xen/arch/powerpc/domain.c Thu Mar 01 13:18:52 2007 -0600
@@ -16,6 +16,7 @@
* Copyright IBM Corp. 2005, 2006, 2007
*
* Authors: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
+ * Ryan Harper <ryanh@xxxxxxxxxx>
*/
#include <stdarg.h>
@@ -347,3 +348,64 @@ void idle_loop(void)
do_softirq();
}
}
+
+/* NB: caller holds d->page_alloc lock, sets d->max_pages = new_max */
+int do_guest_physmap_max_mem_pages(struct domain *d, unsigned long new_max)
+{
+ ulong *p2m_array = NULL;
+ ulong *p2m_old = NULL;
+ ulong p2m_old_sz;
+ ulong p2m_pages;
+ ulong copy_end = 0;
+ ulong i;
+
+ /* we don't handle shrinking p2m array
+ * NB: d->max_pages >= d->arch.p2m_size */
+ if (new_max < d->max_pages) {
+ printk("Can't shrink DOM%d max memory pages\n", d->domain_id);
+ return -EINVAL;
+ }
+
+ /* our work is done here */
+ if (new_max <= d->arch.p2m_size)
+ return 0;
+
+ /* the only case we handle is growing p2m table */
+ ASSERT(new_max > d->arch.p2m_size);
+
+ /* make a p2m array of new_max mfns */
+ p2m_pages = (new_max * sizeof(ulong)) >> PAGE_SHIFT;
+ /* NB: must use xenheap as caller holds page_alloc lock */
+ p2m_array = alloc_xenheap_pages(get_order_from_pages(p2m_pages));
+ if (p2m_array == NULL)
+ return -ENOMEM;
+
+ /* copy old mappings into new array if any */
+ if (d->arch.p2m != NULL) {
+ /* mark where the copy will stop (which page) */
+ copy_end = d->arch.p2m_size;
+
+ /* TODO: this could take a long time, we should do a hcall continuation
+ * that uses copy_page() */
+ /* memcpy takes size in bytes */
+ memcpy(p2m_array, d->arch.p2m, (d->arch.p2m_size * sizeof(ulong)));
+
+ /* keep a pointer to the old array and size */
+ p2m_old = d->arch.p2m;
+ p2m_old_sz = d->arch.p2m_size;
+ }
+
+ /* mark remaining (or all) mfn as INVALID_MFN, memset takes size in bytes
*/
+ for (i = copy_end; i < (new_max - d->arch.p2m_size); i++)
+ p2m_array[i] = INVALID_MFN;
+
+ /* set p2m pointer and size */
+ d->arch.p2m = p2m_array;
+ d->arch.p2m_size = new_max;
+
+ /* free old p2m array if present */
+ if (p2m_old)
+ free_xenheap_pages(p2m_old, get_order_from_pages(d->arch.p2m_size));
+
+ return 0;
+}
diff -r 0a9ecb03cb24 -r 539e61f7482e xen/include/asm-powerpc/domain.h
--- a/xen/include/asm-powerpc/domain.h Thu Mar 01 13:18:52 2007 -0600
+++ b/xen/include/asm-powerpc/domain.h Thu Mar 01 13:18:52 2007 -0600
@@ -13,7 +13,7 @@
* along with this program; if not, write to the Free Software
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * Copyright (C) IBM Corp. 2005
+ * Copyright IBM Corp. 2005, 2007
*
* Authors: Hollis Blanchard <hollisb@xxxxxxxxxx>
*/
@@ -46,6 +46,10 @@ struct arch_domain {
/* I/O-port access bitmap mask. */
u8 *iobmp_mask; /* Address of IO bitmap mask, or NULL. */
+
+ /* P2M mapping array and size */
+ ulong *p2m;
+ ulong p2m_size;
uint large_page_sizes;
uint large_page_order[4];
diff -r 0a9ecb03cb24 -r 539e61f7482e xen/include/asm-powerpc/shadow.h
--- a/xen/include/asm-powerpc/shadow.h Thu Mar 01 13:18:52 2007 -0600
+++ b/xen/include/asm-powerpc/shadow.h Thu Mar 01 13:18:52 2007 -0600
@@ -60,7 +60,8 @@ static inline unsigned int shadow_get_al
return (1ULL << (d->arch.htab.order + PAGE_SHIFT)) >> 20;
}
-#define guest_physmap_max_mem_pages(d, n) (0)
+int do_guest_physmap_max_mem_pages(struct domain *d, unsigned long new_max);
+#define guest_physmap_max_mem_pages(d, n) do_guest_physmap_max_mem_pages(d, n)
#endif
_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel
|