[XenPPC] [linux-ppc-2.6] Fix potential xencomm memory leaks in the kernel's hypercall translation paths.

2007-03-01 Thread Xen patchbot-linux-ppc-2.6
# HG changeset patch
# User Hollis Blanchard <[EMAIL PROTECTED]>
# Date 1172766459 21600
# Node ID 3e512eaf2a6f0f740331bc891fbc0a29392a2794
# Parent  1abaceb1e6e8858b3929d5d6fd20fc3192f47e33
Fix potential xencomm memory leaks in the kernel's hypercall translation paths.
Signed-off-by: Jerone Young <[EMAIL PROTECTED]>
Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>
---
 arch/powerpc/platforms/xen/hcall.c |   28 +++-
 1 files changed, 15 insertions(+), 13 deletions(-)

diff -r 1abaceb1e6e8 -r 3e512eaf2a6f arch/powerpc/platforms/xen/hcall.c
--- a/arch/powerpc/platforms/xen/hcall.cThu Mar 01 10:11:53 2007 -0600
+++ b/arch/powerpc/platforms/xen/hcall.cThu Mar 01 10:27:39 2007 -0600
@@ -160,7 +160,7 @@ int HYPERVISOR_sched_op(int cmd, void *a
 int HYPERVISOR_sched_op(int cmd, void *arg)
 {
int argsize = 0;
-   int rc;
+   int rc = -EINVAL;
void *desc;
evtchn_port_t *ports = NULL;
 
@@ -202,12 +202,11 @@ int HYPERVISOR_sched_op(int cmd, void *a
}
 
desc = xencomm_map_no_alloc(arg, argsize); 
-
-   if (desc == NULL)
-   return -EINVAL;
-
-   rc = plpar_hcall_norets(XEN_MARK(__HYPERVISOR_sched_op),
-   cmd, desc);
+   if (desc) {
+   rc = plpar_hcall_norets(XEN_MARK(__HYPERVISOR_sched_op),
+   cmd, desc);
+   xencomm_free(desc);
+   }
 
xencomm_free(ports);
 
@@ -389,8 +388,8 @@ static int xenppc_privcmd_domctl(privcmd
if (copy_to_user(user_op, &kern_op, sizeof(xen_domctl_t)))
ret = -EFAULT;
 
-   xencomm_free(desc);
 out:
+   xencomm_free(desc);
xencomm_free(op_desc);
return ret;
 }
@@ -463,8 +462,8 @@ static int xenppc_privcmd_sysctl(privcmd
if (copy_to_user(user_op, &kern_op, sizeof(xen_sysctl_t)))
ret = -EFAULT;
 
-   xencomm_free(desc);
 out:
+   xencomm_free(desc);
xencomm_free(op_desc);
return ret;
 }
@@ -514,8 +513,8 @@ static int xenppc_privcmd_platform_op(pr
if (copy_to_user(user_op, &kern_op, sizeof(xen_platform_op_t)))
ret = -EFAULT;
 
-   xencomm_free(desc);
 out:
+   xencomm_free(desc);
xencomm_free(op_desc);
return ret;
 }
@@ -546,8 +545,10 @@ int HYPERVISOR_memory_op(unsigned int cm
mop->nr_extents *
sizeof(*xen_guest_handle(mop->extent_start)));
 
-   if (desc == NULL)
-   return -ENOMEM;
+   if (desc == NULL) {
+   ret = -ENOMEM;
+   goto out;
+   }
 
set_xen_guest_handle(mop->extent_start,
 desc);
@@ -569,9 +570,10 @@ int HYPERVISOR_memory_op(unsigned int cm
printk(KERN_ERR "%s: unknown memory op %d\n", __func__, cmd);
ret = -ENOSYS;
}
+
+out:
xencomm_free(op_desc);
return ret;
-
 }
 EXPORT_SYMBOL(HYPERVISOR_memory_op);
 

___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel


[XenPPC] [PATCH 1 of 5] [PATCH] xen: add arch hook for max_mem hcall

2007-03-01 Thread Ryan Harper
4 files changed, 14 insertions(+), 1 deletion(-)
xen/common/domctl.c  |4 
xen/include/asm-ia64/shadow.h|2 ++
xen/include/asm-powerpc/shadow.h |7 ++-
xen/include/asm-x86/shadow.h |2 ++


# HG changeset patch
# User Ryan Harper <[EMAIL PROTECTED]>
# Date 1172776731 21600
# Node ID af8e290682dd2c045fa181d5837ae2d3c97e856c
# Parent  0902dfafca1c9b247556760e451fabd7eb464345
[PATCH] xen: add arch hook for max_mem hcall

This patch introduces an arch hook in the MAX_MEM hcall.  In particular, powerpc
will use this hook to create/update a p2m mapping array.  This patch introduces
the hook only and should compile away on all arches.

Signed-off-by: Ryan Harper <[EMAIL PROTECTED]>

diff -r 0902dfafca1c -r af8e290682dd xen/common/domctl.c
--- a/xen/common/domctl.c   Mon Feb 26 15:29:42 2007 -0600
+++ b/xen/common/domctl.c   Thu Mar 01 13:18:51 2007 -0600
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -614,6 +615,9 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc
 spin_lock(&d->page_alloc_lock);
 if ( new_max >= d->tot_pages )
 {
+ret = guest_physmap_max_mem_pages(d, new_max);
+if ( ret != 0 )
+break;
 d->max_pages = new_max;
 ret = 0;
 }
diff -r 0902dfafca1c -r af8e290682dd xen/include/asm-ia64/shadow.h
--- a/xen/include/asm-ia64/shadow.h Mon Feb 26 15:29:42 2007 -0600
+++ b/xen/include/asm-ia64/shadow.h Thu Mar 01 13:18:51 2007 -0600
@@ -61,6 +61,8 @@ shadow_mark_page_dirty(struct domain *d,
 return 0;
 }
 
+#define guest_physmap_max_mem_pages(d, n) (0)
+
 #endif // _XEN_SHADOW_H
 
 /*
diff -r 0902dfafca1c -r af8e290682dd xen/include/asm-powerpc/shadow.h
--- a/xen/include/asm-powerpc/shadow.h  Mon Feb 26 15:29:42 2007 -0600
+++ b/xen/include/asm-powerpc/shadow.h  Thu Mar 01 13:18:51 2007 -0600
@@ -13,9 +13,10 @@
  * 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, 2006
+ * Copyright IBM Corp. 2005, 2006, 2007
  *
  * Authors: Hollis Blanchard <[EMAIL PROTECTED]>
+ *  Ryan Harper <[EMAIL PROTECTED]>
  */
 
 #ifndef _ASM_SHADOW_H_
@@ -58,4 +59,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)
+
 #endif
+
diff -r 0902dfafca1c -r af8e290682dd xen/include/asm-x86/shadow.h
--- a/xen/include/asm-x86/shadow.h  Mon Feb 26 15:29:42 2007 -0600
+++ b/xen/include/asm-x86/shadow.h  Thu Mar 01 13:18:51 2007 -0600
@@ -460,6 +460,8 @@ gl1e_to_ml1e(struct domain *d, l1_pgentr
 return l1e;
 }
 
+#define guest_physmap_max_mem_pages(d, n) (0)
+
 #endif /* _XEN_SHADOW_H */
 
 /*

___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel


[XenPPC] [PATCH 5 of 5] [PATCH] tools/libxc: change ppc xc_linux_build to use populate_physmap()

2007-03-01 Thread Ryan Harper
1 files changed, 32 insertions(+), 5 deletions(-)
tools/libxc/powerpc64/xc_linux_build.c |   37 +++-


# HG changeset patch
# User Ryan Harper <[EMAIL PROTECTED]>
# Date 1172776732 21600
# Node ID 178a3e6615fbf8dd556a4f8afa87e58bf7bbe575
# Parent  76a5923eaed2cc0f3ea2f9b1ac26c82fd8e7bc2b
[PATCH] tools/libxc: change ppc xc_linux_build to use populate_physmap()

Now that ppc has implemented its guest_physmap_{add/remove}_page() domU builder
needs to use populate_physmap() which will call out to the arch hooks.

To use populate_physmap, we still allocate in the same 16MB chunks, but we have
to pass down an array of pfns to tell the hypervisor how to map the newly
allocated mfns.  The extent_array is just such an array.  It is initialized to
the end of the RMA, and we adjust the pfn values in the array based on how many
extents we've allocated.

Signed-off-by: Ryan Harper <[EMAIL PROTECTED]>

diff -r 76a5923eaed2 -r 178a3e6615fb tools/libxc/powerpc64/xc_linux_build.c
--- a/tools/libxc/powerpc64/xc_linux_build.cThu Mar 01 13:18:52 2007 -0600
+++ b/tools/libxc/powerpc64/xc_linux_build.cThu Mar 01 13:18:52 2007 -0600
@@ -166,6 +166,7 @@ int xc_linux_build(int xc_handle,
 {
 struct domain_setup_info dsi;
 xen_pfn_t *page_array = NULL;
+xen_pfn_t *ext_array = NULL;
 unsigned long nr_pages;
 unsigned long devtree_addr = 0;
 unsigned long kern_addr;
@@ -182,6 +183,8 @@ int xc_linux_build(int xc_handle,
 int rma_log = 26;  /* 64MB RMA */
 int rc = 0;
 int op;
+int i;
+int j;
 struct ft_cxt devtree;
 
 DPRINTF("%s\n", __func__);
@@ -219,11 +222,34 @@ int xc_linux_build(int xc_handle,
 (((1 << extent_order) >> 10) * PAGE_SIZE) >> 10);
 
 /* now allocate the remaining memory as large-order allocations */
-DPRINTF("increase_reservation(%u, %llu, %u)\n", domid, nr_extents, 
extent_order);
-if (xc_domain_memory_increase_reservation(xc_handle, domid, nr_extents, 
-  extent_order, 0, NULL)) {
-rc = -1;
-goto out;
+for ( i = 0; i < nr_extents; i++ ) {
+/* all extents are of the same size, alloc array once can re-use */
+if ( ext_array == NULL ) {
+if ((ext_array = malloc((1

[XenPPC] [PATCH 3 of 5] [PATCH] xen: implement guest_physmap_max_mem_pages() for ppc

2007-03-01 Thread Ryan Harper
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 <[EMAIL PROTECTED]>
# 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 <[EMAIL PROTECTED]>

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 <[EMAIL PROTECTED]>
+ *  Ryan Harper <[EMAIL PROTECTED]>
  */
 
 #include 
@@ -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 <[EMAIL PROTECTED]>
  */
@@ -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
 

__

[XenPPC] [PATCH 4 of 5] [PATCH] xen: implement guest_physmap_{add/remove}_page for ppc

2007-03-01 Thread Ryan Harper
14 files changed, 237 insertions(+), 145 deletions(-)
xen/arch/powerpc/Makefile   |1 
xen/arch/powerpc/domain.c   |3 
xen/arch/powerpc/domain_build.c |   26 
xen/arch/powerpc/domctl.c   |   18 ++-
xen/arch/powerpc/iommu.c|3 
xen/arch/powerpc/memory.c   |1 
xen/arch/powerpc/mm.c   |  192 ++-
xen/arch/powerpc/ofd_fixup_memory.c |   33 --
xen/arch/powerpc/platform.c |   35 ++
xen/arch/powerpc/powerpc64/ppc970.c |8 -
xen/common/memory.c |3 
xen/include/asm-powerpc/domain.h|3 
xen/include/asm-powerpc/mm.h|   29 +
xen/include/asm-powerpc/platform.h  |   27 


# HG changeset patch
# User Ryan Harper <[EMAIL PROTECTED]>
# Date 1172776732 21600
# Node ID 76a5923eaed2cc0f3ea2f9b1ac26c82fd8e7bc2b
# Parent  539e61f7482e832ffc372f0fa8d745202f86baa4
[PATCH] xen: implement guest_physmap_{add/remove}_page for ppc

Introduce an machine to guest physical array (m2p) table.  This array is the
same size(# of elements) as the frame table, and maps mfns to a guest pfn.  This
m2p array us used in the mfn_to_gmfn() function.  With the existence of both an
m2p and p2m table, we implement the ppc version of
guest_physmap_{add/remove}_page().

Modify construct_dom0 to initialize the p2m array.  In doing so, we need to
account for the platform iohole in dom0 by introducing
platform_iohole_{base/size}() functions.

If dom0_mem is larger than the start of the platform iohole, then we allocate
platform_iohole_size() space in the p2m array and shift any memory above the
platform_iohole_base() past the end of the iohole.  This is reflected in the
p2m_size and when we allocate dom0's memory, account for this shifting (this is
done in allocate_extents()).

To ensure proper dom0 memory alignment w.r.t extents, introduce a macro,
EXTENT_UP(), which will round dom0's requested memory size up to the next cpu
extent order and inform users we've done so.

With the above in place, we eliminate the domain extent list, update dom0's
device tree memory node construction accordingly, simplify pfn2mfn() and
mfn_to_gmfn() by removing the extent list walking, killed extent list struct and
extent functions.  As a nice side-effect, we've increased mapping performance.

Signed-off-by: Ryan Harper <[EMAIL PROTECTED]>

diff -r 539e61f7482e -r 76a5923eaed2 xen/arch/powerpc/Makefile
--- a/xen/arch/powerpc/Makefile Thu Mar 01 13:18:52 2007 -0600
+++ b/xen/arch/powerpc/Makefile Thu Mar 01 13:18:52 2007 -0600
@@ -33,6 +33,7 @@ obj-y += ofd_fixup.o
 obj-y += ofd_fixup.o
 obj-y += ofd_fixup_memory.o
 obj-y += physdev.o
+obj-y += platform.o
 obj-y += rtas.o
 obj-y += setup.o
 obj-y += shadow.o
diff -r 539e61f7482e -r 76a5923eaed2 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
@@ -87,8 +87,6 @@ int arch_domain_create(struct domain *d)
 d->arch.large_page_sizes = cpu_large_page_orders(
 d->arch.large_page_order, ARRAY_SIZE(d->arch.large_page_order));
 
-INIT_LIST_HEAD(&d->arch.extent_list);
-
 d->arch.foreign_mfn_count = 1024;
 d->arch.foreign_mfns = xmalloc_array(uint, d->arch.foreign_mfn_count);
 BUG_ON(d->arch.foreign_mfns == NULL);
@@ -310,7 +308,6 @@ void domain_relinquish_resources(struct 
 {
 relinquish_memory(d, &d->xenpage_list);
 relinquish_memory(d, &d->page_list);
-free_extents(d);
 xfree(d->arch.foreign_mfns);
 return;
 }
diff -r 539e61f7482e -r 76a5923eaed2 xen/arch/powerpc/domain_build.c
--- a/xen/arch/powerpc/domain_build.c   Thu Mar 01 13:18:52 2007 -0600
+++ b/xen/arch/powerpc/domain_build.c   Thu Mar 01 13:18:52 2007 -0600
@@ -16,6 +16,7 @@
  * Copyright IBM Corp. 2005, 2007
  *
  * Authors: Jimi Xenidis <[EMAIL PROTECTED]>
+ *  Ryan Harper <[EMAIL PROTECTED]>
  */
 
 #include 
@@ -27,7 +28,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -52,6 +55,9 @@ boolean_param("dom0_shadow", opt_dom0_sh
 
 /* adapted from common/elf.c */
 #define RM_MASK(a,l) ((a) & ((1UL << (l)) - 1))
+
+#define EXTENT_SIZE (1 << cpu_extent_order())
+#define EXTENT_UP(x) x)+(EXTENT_SIZE-1))>>cpu_extent_order())*EXTENT_SIZE)
 
 int construct_dom0(struct domain *d,
unsigned long image_start, unsigned long image_len, 
@@ -71,6 +77,7 @@ int construct_dom0(struct domain *d,
 ulong eomem;
 int preempt = 0;
 int vcpu;
+ulong p2m_size;
 
 /* Sanity! */
 BUG_ON(d->domain_id != 0);
@@ -114,6 +121,25 @@ int construct_dom0(struct domain *d,
 printk("Forcing DOM0 memory size to %u MiB\n", 
 ((rma_nrpages << PAGE_SHIFT) >> 20));
 }
+
+/* ensure dom0 is cpu_extent_order aligned, round up if 
+   not and let user know we did so */
+if ( dom0_nrpages != EXTENT_UP(dom0_nrpages)) {
+printk("Aligning DOM0 to cpu e

[XenPPC] [PATCH 2 of 5] [PATCH] xen: move dom0 memory allocation into construct_dom0()

2007-03-01 Thread Ryan Harper
2 files changed, 35 insertions(+), 28 deletions(-)
xen/arch/powerpc/domain_build.c |   56 +++
xen/arch/powerpc/setup.c|7 


# HG changeset patch
# User Ryan Harper <[EMAIL PROTECTED]>
# Date 1172776732 21600
# Node ID 0a9ecb03cb24b9035726dd316ca6af388983c05b
# Parent  af8e290682dd2c045fa181d5837ae2d3c97e856c
[PATCH] xen: move dom0 memory allocation into construct_dom0()
Signed-off-by: Ryan Harper <[EMAIL PROTECTED]>

General clean-up to prepare for initializing dom0's p2m array
o Move rma allocation into construct_dom0()
o Move vcpu0 allocation into construct_dom0()
o Allow dom0_mem to set d->max_pages
o Be verbose when aligning dom0_mem with RMA check

diff -r af8e290682dd -r 0a9ecb03cb24 xen/arch/powerpc/domain_build.c
--- a/xen/arch/powerpc/domain_build.c   Thu Mar 01 13:18:51 2007 -0600
+++ b/xen/arch/powerpc/domain_build.c   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: Jimi Xenidis <[EMAIL PROTECTED]>
  */
@@ -61,12 +61,12 @@ int construct_dom0(struct domain *d,
 struct elf_binary elf;
 struct elf_dom_parms parms;
 int rc;
-struct vcpu *v = d->vcpu[0];
+struct vcpu *v;
 ulong dst;
 u64 *ofh_tree;
-uint rma_nrpages = 1 << d->arch.rma_order;
-ulong rma_sz = rma_size(d->arch.rma_order);
-ulong rma = page_to_maddr(d->arch.rma_page);
+uint rma_nrpages = (1 << cpu_default_rma_order_pages());
+ulong rma_sz;
+ulong rma;
 start_info_t *si;
 ulong eomem;
 int preempt = 0;
@@ -74,12 +74,9 @@ int construct_dom0(struct domain *d,
 
 /* Sanity! */
 BUG_ON(d->domain_id != 0);
-BUG_ON(d->vcpu[0] == NULL);
 
 if (image_len == 0)
 panic("No Dom0 image supplied\n");
-
-cpu_init_vcpu(v);
 
 printk("*** LOADING DOMAIN 0 ***\n");
 
@@ -103,9 +100,6 @@ int construct_dom0(struct domain *d,
 parms.virt_kend = RM_MASK(parms.virt_kend, 42);
 parms.virt_entry = RM_MASK(parms.virt_entry, 42);
 
-/* By default DOM0 is allocated all available memory. */
-d->max_pages = ~0U;
-
 /* default is the max(1/16th of memory, CONFIG_MIN_DOM0_PAGES) */
 if (dom0_nrpages == 0) {
 dom0_nrpages = total_pages >> 4;
@@ -114,7 +108,21 @@ int construct_dom0(struct domain *d,
 dom0_nrpages = CONFIG_MIN_DOM0_PAGES;
 }
 
-/* make sure we are at least as big as the RMA */
+/* DOM0 has to be at least RMA size */
+if (dom0_nrpages < rma_nrpages) {
+dom0_nrpages = rma_nrpages;
+printk("Forcing DOM0 memory size to %u MiB\n", 
+((rma_nrpages << PAGE_SHIFT) >> 20));
+}
+
+d->max_pages = dom0_nrpages;
+if (0 > allocate_rma(d, cpu_default_rma_order_pages()))
+panic("Error allocating domain 0 RMA\n");
+
+rma_sz = rma_size(d->arch.rma_order);
+rma = page_to_maddr(d->arch.rma_page);
+
+/* if we are bigger than rma, allocate extents */
 if (dom0_nrpages > rma_nrpages)
 dom0_nrpages = allocate_extents(d, dom0_nrpages, rma_nrpages);
 
@@ -152,15 +160,6 @@ int construct_dom0(struct domain *d,
 si->pt_base = 0;
 si->nr_pt_frames = 0;
 si->mfn_list = 0;
-
-/* OF usually sits here:
- *   - Linux needs it to be loaded before the vmlinux or initrd
- *   - AIX demands it to be @ 32M.
- */
-dst = (32 << 20);
-
-/* put stack below everything */
-v->arch.ctxt.gprs[1] = dst - STACK_FRAME_OVERHEAD;
 
 /* startup secondary processors */
 if ( opt_dom0_max_vcpus == 0 )
@@ -175,13 +174,26 @@ int construct_dom0(struct domain *d,
 #endif
 printk("Dom0 has maximum %u VCPUs\n", opt_dom0_max_vcpus);
 
-for (vcpu = 1; vcpu < opt_dom0_max_vcpus; vcpu++) {
+for (vcpu = 0; vcpu < opt_dom0_max_vcpus; vcpu++) {
 if (NULL == alloc_vcpu(dom0, vcpu, vcpu))
 panic("Error creating domain 0 vcpu %d\n", vcpu);
 /* for now we pin Dom0 VCPUs to their coresponding CPUs */
 if (cpu_isset(vcpu, cpu_online_map))
 dom0->vcpu[vcpu]->cpu_affinity = cpumask_of_cpu(vcpu);
 }
+
+/* init VCPU0 */
+v = d->vcpu[0];
+cpu_init_vcpu(v);
+
+/* OF usually sits here:
+ *   - Linux needs it to be loaded before the vmlinux or initrd
+ *   - AIX demands it to be @ 32M.
+ */
+dst = (32 << 20);
+
+/* put stack below everything */
+v->arch.ctxt.gprs[1] = dst - STACK_FRAME_OVERHEAD;
 
 /* copy relative to Xen */
 dst += rma;
diff -r af8e290682dd -r 0a9ecb03cb24 xen/arch/powerpc/setup.c
--- a/xen/arch/powerpc/setup.c  Thu Mar 01 13:18:51 2007 -0600
+++ b/xen/arch/powerpc/setup.c  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,

[XenPPC] [PATCH 0 of 5] [PATCH] replace extent list with p2m/m2p mapping

2007-03-01 Thread Ryan Harper
Revised set of patches to addressing memory management [1] ugliness.  
Applies to xenppc-unstable.hg changeset: 14607:0902dfafca1c

dom0 booted, multiple domUs created/used/destroyed

Patches:

add_arch_hook_for_max_mem.patch:
 - dummy call for x86/ia64/ppc 

clean_up_dom0_memory_alloc.patch:
 - Move rma allocation into construct_dom0()
 - Move vcpu0 allocation into construct_dom0()
 - Allow dom0_mem to set d->max_pages
 - Be verbose when aligning dom0_mem with RMA check

add_powerpc_guest_physmap_max_mem.patch:
 - implement max_mem arch hook for ppc.
 - have dom0 create p2m table

ppc_guest_physmap_add_remove_page.patch:
 - implement add/remove page hooks for ppc.
 - change allocate_extents not call add_extent()
 - for each page allocated, call physmap_add_page() to get p2m mapping
 - change pfn2mfn to use p2m table
 - change mfn_to_gmfn() to use p2m table
 - use d->tot_pages rather than extent list to create memory nodes in
   dom0 OF tree and avoid putting memory in I/O hole.
 - create machine_to_phys_table() for m2p mapping
 - wire up m2p accessors {get/set}_gpfn_from_mfn()
 - change guest_physmap_{add/remove}_page() to do m2p mapping
 - change mfn_to_gmfn() to use m2p mapping instead of extent calculation
 - add check for page ownership in mfn_to_gmfn()
 - add platform.c/platform.h to account for iohole
 - remove old struct page_extents and related functions
 - change cpu_io_mfn() to use platform code
 - removed PFN_TYPE_RMA, not needed
 - change pfnlist/getmemlist to use p2m map

xc_linux_build_use_populate_physmap.patch:
 - change libxc/powerc64/xc_linux_build() to use populate_physmap hcall

Note that a 1 line patch to linux is needed to allow populate_physmap
to work.  I'll send that seperately from this patchset.

Signed-off-by: Ryan Harper <[EMAIL PROTECTED]>

1. http://lists.xensource.com/archives/html/xen-ppc-devel/2007-02/msg00047.html
20 files changed, 387 insertions(+), 181 deletions(-)
tools/libxc/powerpc64/xc_linux_build.c |   37 +-
xen/arch/powerpc/Makefile  |1 
xen/arch/powerpc/domain.c  |   65 ++
xen/arch/powerpc/domain_build.c|   82 ++---
xen/arch/powerpc/domctl.c  |   18 +--
xen/arch/powerpc/iommu.c   |3 
xen/arch/powerpc/memory.c  |1 
xen/arch/powerpc/mm.c  |  192 
xen/arch/powerpc/ofd_fixup_memory.c|   33 +++--
xen/arch/powerpc/platform.c|   35 +
xen/arch/powerpc/powerpc64/ppc970.c|8 -
xen/arch/powerpc/setup.c   |7 -
xen/common/domctl.c|4 
xen/common/memory.c|3 
xen/include/asm-ia64/shadow.h  |2 
xen/include/asm-powerpc/domain.h   |9 -
xen/include/asm-powerpc/mm.h   |   29 +---
xen/include/asm-powerpc/platform.h |   27 
xen/include/asm-powerpc/shadow.h   |   10 +
xen/include/asm-x86/shadow.h   |2 
___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel

Re: [XenPPC] [PATCH 0 of 5] [PATCH] replace extent list with p2m/m2p mapping

2007-03-01 Thread Ryan Harper
* Ryan Harper <[EMAIL PROTECTED]> [2007-03-01 13:45]:
> Note that a 1 line patch to linux is needed to allow populate_physmap
> to work.  I'll send that seperately from this patchset.

Same as before.

-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-9253   T/L: 678-9253
[EMAIL PROTECTED]


diffstat output:
 hcall.c |1 +
 1 files changed, 1 insertion(+)

---
[PATCH] linux: add populate_phsymap to memory hcalls for ppc.

Signed-off-by: Ryan Harper <[EMAIL PROTECTED]>

diff -r 37ea4cf1281a arch/powerpc/platforms/xen/hcall.c
--- a/arch/powerpc/platforms/xen/hcall.cTue Feb 06 17:10:20 2007 -0500
+++ b/arch/powerpc/platforms/xen/hcall.cFri Feb 16 17:27:17 2007 -0600
@@ -537,6 +537,7 @@ int HYPERVISOR_memory_op(unsigned int cm
switch (cmd) {
case XENMEM_increase_reservation:
case XENMEM_decrease_reservation:
+   case XENMEM_populate_physmap:
{
void *desc = NULL;
 

___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel


[XenPPC] [PATCH] add machine info to /proc/cpuinfo & change platform to "Xen"

2007-03-01 Thread Jerone Young
This patch adds machine information to /proc/cpuinfo as well as changes
the platform for "Xen-Maple" to Xen.

Signed-off-by: Jerone Young <[EMAIL PROTECTED]>
diff -r 3e512eaf2a6f arch/powerpc/platforms/xen/setup.c
--- a/arch/powerpc/platforms/xen/setup.c	Thu Mar 01 10:27:39 2007 -0600
+++ b/arch/powerpc/platforms/xen/setup.c	Thu Mar 01 14:27:23 2007 -0600
@@ -39,6 +39,18 @@ extern struct machdep_calls mach_maple_m
 extern struct machdep_calls mach_maple_md;
 extern void maple_pci_init(void);
 
+static void xen_show_cpuinfo(struct seq_file *m)
+{
+	struct device_node *root;
+	const char *model = "";
+
+	root = of_find_node_by_path("/");
+	if (root)
+		model = get_property(root, "model", NULL);
+	seq_printf(m, "machine\t\t: CHRP %s\n", model);
+	of_node_put(root);
+}
+
 int direct_remap_pfn_range(struct vm_area_struct *vma,
 		unsigned long address, 
 		unsigned long mfn,
@@ -272,9 +284,10 @@ void xen_machine_crash_shutdown(struct p
 #endif
 
 define_machine(xen) {
-	.name			= "Xen-Maple",
+	.name			= "Xen",
 	.probe			= xen_probe,
 	.setup_arch		= xen_setup_arch,
+	.show_cpuinfo		= xen_show_cpuinfo,
 	.init_early		= xen_init_early,
 #ifdef CONFIG_SHARE_MPIC
 	.init_IRQ		= xen_maple_init_IRQ,
___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel

Re: [XenPPC] [PATCH] add machine info to /proc/cpuinfo & change platform to "Xen"

2007-03-01 Thread Hollis Blanchard
On Thu, 2007-03-01 at 15:27 -0600, Jerone Young wrote:
> This patch adds machine information to /proc/cpuinfo as well as
> changes the platform for "Xen-Maple" to Xen.

Jimi, this is the patch I was talking about.

Jerone, can you please paste cpuinfo from a system with this patch
applied? Also, see below.

> diff -r 3e512eaf2a6f arch/powerpc/platforms/xen/setup.c
> --- a/arch/powerpc/platforms/xen/setup.cThu Mar 01 10:27:39
> 2007 -0600
> +++ b/arch/powerpc/platforms/xen/setup.cThu Mar 01 14:27:23
> 2007 -0600
> @@ -39,6 +39,18 @@ extern struct machdep_calls mach_maple_m
>  extern struct machdep_calls mach_maple_md;
>  extern void maple_pci_init(void);
> 
> +static void xen_show_cpuinfo(struct seq_file *m)
> +{
> +   struct device_node *root;
> +   const char *model = "";
> +
> +   root = of_find_node_by_path("/");
> +   if (root)
> +   model = get_property(root, "model", NULL);
> +   seq_printf(m, "machine\t\t: CHRP %s\n", model);
> +   of_node_put(root);
> +}

Why CHRP? I don't think that should be there (think about PA Semi),
except *maybe* if the system actually is CHRP.

>  int direct_remap_pfn_range(struct vm_area_struct *vma,
> unsigned long address, 
> unsigned long mfn,
> @@ -272,9 +284,10 @@ void xen_machine_crash_shutdown(struct p
>  #endif
> 
>  define_machine(xen) {
> -   .name   = "Xen-Maple",
> +   .name   = "Xen",
> .probe  = xen_probe,
> .setup_arch = xen_setup_arch,
> +   .show_cpuinfo   = xen_show_cpuinfo,
> .init_early = xen_init_early,
>  #ifdef CONFIG_SHARE_MPIC
> .init_IRQ   = xen_maple_init_IRQ, 

-- 
Hollis Blanchard
IBM Linux Technology Center


___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel