]> xenbits.xensource.com Git - mini-os.git/commitdiff
mini-os: remap p2m list in case of ballooning
authorJuergen Gross <jgross@suse.com>
Mon, 1 Aug 2016 07:26:08 +0000 (09:26 +0200)
committerJuergen Gross <jgross@suse.com>
Thu, 11 Aug 2016 11:04:12 +0000 (13:04 +0200)
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@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
arch/arm/balloon.c
arch/x86/balloon.c
arch/x86/mm.c
include/balloon.h
include/x86/arch_mm.h

index 28021d654609ebcd82ac04d4ee5b42f21353ce6e..549e51b574aad828ce2fbf1503bdf37a33345988 100644 (file)
@@ -25,4 +25,6 @@
 
 #ifdef CONFIG_BALLOON
 
+unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
+
 #endif
index 28021d654609ebcd82ac04d4ee5b42f21353ce6e..a7f20e48714d29b7e04adb98e6582a4cde1fe4b4 100644 (file)
  * 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
index a5c8959e9cb259f2bef335de4008656dbf2a11e1..8fa3b4c794c58825d0387eeaeeb2323dc129559a 100644 (file)
@@ -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)
index cd790179faa3f5dd915cd533cd7bee68c67e886c..b0d0ebffa065327cb15f006a1f95b987814f72b7 100644 (file)
 #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_ */
index 7283f6489fba08756ae88cba9791c8596abc9cda..e5d9c57788f5febd2cba00ab608e38b2727e46f0 100644 (file)
@@ -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