[Xen-devel] [PATCH 6/6] Add interface for memory add

Jiang, Yunhong
Sun, 28 Jun 2009 09:27:54 -0000

This patch add a interface to memory add. When memory add, Xen HV will set up
the boot allocator (if needed), m2p table, frame table, IOMMU table, and put the
memory to domheap.

The proximity_domain parameter will be used for NUMA support, and that deserve
more discussion.

Signed-off-by: Jiang, Yunhong <yunhong.jiang@intel.com>
Signed-off-by: Wang, shane <shane.wang@intel.com>

Increase page range function

diff -r 181b6a1ee260 xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c	Thu Jun 25 20:04:56 2009 +0800
+++ b/xen/arch/x86/mm.c	Thu Jun 25 20:06:47 2009 +0800
@@ -461,6 +461,71 @@ void __init arch_init_memory(void)
     subarch_init_memory();
 }

+#define PAGES_PER_MAPWORD (sizeof(unsigned long) * 8)
+int increase_pages(unsigned long spfn, unsigned long epfn, int pxm)
+{
+    unsigned long i, rc;
+
+#if defined(CONFIG_X86_32) && !defined(CONFIG_MEMORY_HOTPLUG)
+    return -ENOSYS;
+#endif
+
+    /* the memory range should at least be 2M aligned */
+    if ((spfn | epfn) & !((1UL << PAGETABLE_ORDER) - 1) )
+        return -EINVAL;
+
+    if (epfn < max_page)
+        return -EINVAL;
+
+    /* Setup the allocate bitmap firstly,  */
+    rc = extend_boot_allocator(spfn, epfn);
+    if (rc)
+    {
+        dprintk(XENLOG_WARNING, "failed to extend boot allocator\n");
+        return rc;
+    }
+
+    rc = construct_frame_table(spfn, epfn);
+    if (rc)
+    {
+        dprintk(XENLOG_WARNING, "failed to construct frame table\n");
+        return rc;
+    }
+
+    rc = setup_m2p_table(spfn, epfn, 1);
+    if (rc)
+    {
+        dprintk(XENLOG_WARNING, "failed to setup m2p table\n");
+        return rc;
+    }
+
+    for ( i = max_page; i < epfn; i++ )
+    {
+        iommu_map_page(dom0, i, i);
+    }
+
+    /* Set max_page */
+    max_page = epfn;
+
+    total_pages += epfn - spfn;
+
+    /* Set the range between old max_page and spfn as I/O. */
+    for ( i = max_page; i < spfn; i++ )
+        share_xen_page_with_guest(
+          mfn_to_page(i), dom_io, XENSHARE_writable);
+
+    /* Map all pages to xen in x86_64 */
+#if defined(__x86_64__)
+    map_pages_to_xen(
+            (unsigned long)maddr_to_bootstrap_virt(spfn << PAGE_SHIFT),
+            spfn, (epfn - spfn + 1), PAGE_HYPERVISOR);
+#endif
+
+    end_boot_allocator_range(spfn, epfn);
+
+    return 0;
+}
+
 int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
 {
     uint64_t maddr = pfn_to_paddr(mfn);
diff -r 181b6a1ee260 xen/arch/x86/setup.c
--- a/xen/arch/x86/setup.c	Thu Jun 25 20:04:56 2009 +0800
+++ b/xen/arch/x86/setup.c	Thu Jun 25 20:05:33 2009 +0800
@@ -40,14 +40,6 @@
 #include <asm/tboot.h>

 int __init bzimage_headroom(char *image_start, unsigned long image_length);
-
-#if defined(CONFIG_X86_64)
-#define BOOTSTRAP_DIRECTMAP_END (1UL << 32) /* 4GB */
-#define maddr_to_bootstrap_virt(m) maddr_to_virt(m)
-#else
-#define BOOTSTRAP_DIRECTMAP_END (1UL << 30) /* 1GB */
-#define maddr_to_bootstrap_virt(m) ((void *)(long)(m))
-#endif

 extern void generic_apic_probe(void);
 extern void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
diff -r 181b6a1ee260 xen/common/sysctl.c
--- a/xen/common/sysctl.c	Thu Jun 25 20:04:56 2009 +0800
+++ b/xen/common/sysctl.c	Thu Jun 25 20:05:33 2009 +0800
@@ -297,6 +297,22 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
     }
     break;

+    case XEN_SYSCTL_memory_add_op:
+    {
+        unsigned long spfn, epfn;
+
+        spfn = op->u.memory_add.spfn;
+        epfn = op->u.memory_add.epfn;
+
+        if ( spfn > epfn || spfn < max_page || epfn < max_page )
+            return -EINVAL;
+        if ( !IS_PRIV(current->domain) )
+            return -EPERM;
+
+        ret = increase_pages(spfn, epfn, 0);
+    }
+    break;
+
     default:
         ret = arch_do_sysctl(op, u_sysctl);
         break;
diff -r 181b6a1ee260 xen/include/asm-ia64/mm.h
--- a/xen/include/asm-ia64/mm.h	Thu Jun 25 20:04:56 2009 +0800
+++ b/xen/include/asm-ia64/mm.h	Thu Jun 25 20:05:33 2009 +0800
@@ -535,6 +535,11 @@ p2m_pod_decrease_reservation(struct doma
                              xen_pfn_t gpfn, unsigned int order);
 int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn,
                                           unsigned int order);
+static inline
+int increase_pages(unsigned long spfn, unsigned long epfn, int node)
+{
+    return -ENOSYS;
+}

 extern volatile unsigned long *mpt_table;
 extern unsigned long gmfn_to_mfn_foreign(struct domain *d, unsigned long gpfn);
diff -r 181b6a1ee260 xen/include/asm-x86/mm.h
--- a/xen/include/asm-x86/mm.h	Thu Jun 25 20:04:56 2009 +0800
+++ b/xen/include/asm-x86/mm.h	Thu Jun 25 20:05:33 2009 +0800
@@ -496,7 +496,16 @@ int donate_page(
 int donate_page(
     struct domain *d, struct page_info *page, unsigned int memflags);

+int increase_pages(unsigned long spfn, unsigned long epfn, int node);
 int map_ldt_shadow_page(unsigned int);
+
+#if defined(CONFIG_X86_64)
+#define BOOTSTRAP_DIRECTMAP_END (1UL << 32) /* 4GB */
+#define maddr_to_bootstrap_virt(m) maddr_to_virt(m)
+#else
+#define BOOTSTRAP_DIRECTMAP_END (1UL << 30) /* 1GB */
+#define maddr_to_bootstrap_virt(m) ((void *)(long)(m))
+#endif

 #ifdef CONFIG_COMPAT
 void domain_set_alloc_bitsize(struct domain *d);
diff -r 181b6a1ee260 xen/include/public/sysctl.h
--- a/xen/include/public/sysctl.h	Thu Jun 25 20:04:56 2009 +0800
+++ b/xen/include/public/sysctl.h	Thu Jun 25 20:05:33 2009 +0800
@@ -423,6 +423,18 @@ struct xen_sysctl_page_offline_op {
     XEN_GUEST_HANDLE(uint32) status;
 };

+#define XEN_SYSCTL_memory_add_op        15
+struct xen_sysctl_memory_online_op {
+    /* IN: spfn */
+    uint64_t spfn;
+    uint64_t epfn;
+    uint32_t proximity_domain;
+    uint32_t pad;
+
+    /* OUT: result */
+    XEN_GUEST_HANDLE(uint32) status;
+};
+
 #define PG_OFFLINE_STATUS_MASK    (0xFFUL)

 /* The result is invalid, i.e. HV does not handle it */
@@ -471,6 +483,7 @@ struct xen_sysctl {
         struct xen_sysctl_cpu_hotplug       cpu_hotplug;
         struct xen_sysctl_pm_op             pm_op;
         struct xen_sysctl_page_offline_op   page_offline;
+        struct xen_sysctl_memory_online_op  memory_add;
         uint8_t                             pad[128];
     } u;
 };


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com