[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [PATCH v3 15/19] mini-os: remap p2m list in case of ballooning



In case of enabled ballooning we must be prepared for a growing p2m
list. If the maximum memory size of the domain can't be covered by the
actual p2m list remap it to the kernel virtual mapping area and leave
enough space at the end.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
Reviewed-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
---
V3: add assertion as requested by Samuel Thibault
---
 arch/arm/balloon.c    |  2 ++
 arch/x86/balloon.c    | 25 +++++++++++++++++++++++++
 arch/x86/mm.c         |  3 +++
 include/balloon.h     |  3 +++
 include/x86/arch_mm.h |  4 ++++
 5 files changed, 37 insertions(+)

diff --git a/arch/arm/balloon.c b/arch/arm/balloon.c
index 28021d6..549e51b 100644
--- a/arch/arm/balloon.c
+++ b/arch/arm/balloon.c
@@ -25,4 +25,6 @@
 
 #ifdef CONFIG_BALLOON
 
+unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
+
 #endif
diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c
index 28021d6..a7f20e4 100644
--- a/arch/x86/balloon.c
+++ b/arch/x86/balloon.c
@@ -21,8 +21,33 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <mini-os/os.h>
 #include <mini-os/balloon.h>
+#include <mini-os/lib.h>
+#include <mini-os/mm.h>
 
 #ifdef CONFIG_BALLOON
 
+unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
+
+void arch_remap_p2m(unsigned long max_pfn)
+{
+    unsigned long pfn;
+
+    if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) )
+        return;
+
+    for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
+    {
+        map_frame_rw(virt_kernel_area_end + PAGE_SIZE * (pfn / P2M_ENTRIES),
+                     virt_to_mfn(phys_to_machine_mapping + pfn));
+    }
+
+    phys_to_machine_mapping = (unsigned long *)virt_kernel_area_end;
+    printk("remapped p2m list to %p\n", phys_to_machine_mapping);
+
+    virt_kernel_area_end += PAGE_SIZE * p2m_pages(nr_max_pages);
+    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
+}
+
 #endif
diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index a5c8959..8fa3b4c 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -37,6 +37,7 @@
 #include <mini-os/errno.h>
 #include <mini-os/os.h>
 #include <mini-os/hypervisor.h>
+#include <mini-os/balloon.h>
 #include <mini-os/mm.h>
 #include <mini-os/types.h>
 #include <mini-os/lib.h>
@@ -626,6 +627,8 @@ void arch_init_p2m(unsigned long max_pfn)
     HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 
         virt_to_mfn(l3_list);
     HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
+
+    arch_remap_p2m(max_pfn);
 }
 
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
diff --git a/include/balloon.h b/include/balloon.h
index cd79017..b0d0ebf 100644
--- a/include/balloon.h
+++ b/include/balloon.h
@@ -27,12 +27,15 @@
 #ifdef CONFIG_BALLOON
 
 extern unsigned long nr_max_pages;
+extern unsigned long virt_kernel_area_end;
 
 void get_max_pages(void);
+void arch_remap_p2m(unsigned long max_pfn);
 
 #else /* CONFIG_BALLOON */
 
 static inline void get_max_pages(void) { }
+static inline void arch_remap_p2m(unsigned long max_pfn) { }
 
 #endif /* CONFIG_BALLOON */
 #endif /* _BALLOON_H_ */
diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index 7283f64..e5d9c57 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -198,6 +198,10 @@ static inline void p2m_chk_pfn(unsigned long pfn)
         do_exit();
     }
 }
+static inline unsigned long p2m_pages(unsigned long pages)
+{
+    return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT;
+}
 
 #include "arch_limits.h"
 #define PAGE_SIZE       __PAGE_SIZE
-- 
2.6.6


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.