]> xenbits.xensource.com Git - mini-os.git/commitdiff
mini-os: add map_frame_virt() function
authorJuergen Gross <jgross@suse.com>
Thu, 18 Aug 2016 11:36:36 +0000 (13:36 +0200)
committerWei Liu <wei.liu2@citrix.com>
Wed, 24 Aug 2016 10:37:05 +0000 (11:37 +0100)
Add a function map_frame_virt() to map a given frame and return its
virtual address.

On arm we just use the frame physical address, while on x86 we take a
page from the virtual kernel area. For this purpose make this area
available even in case of undefined CONFIG_BALLOON.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
arch/arm/balloon.c
arch/arm/mm.c
arch/x86/balloon.c
arch/x86/mm.c
balloon.c
include/balloon.h
include/mm.h
include/x86/arch_mm.h

index 958ecba3196ef44d43a654a1be2d23d5860ee148..1df7d1cae9b5e48e636f02d000adb284f5379b7b 100644 (file)
@@ -25,8 +25,6 @@
 
 #ifdef CONFIG_BALLOON
 
-unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
-
 void arch_pfn_add(unsigned long pfn, unsigned long mfn)
 {
 }
index 4f58fc77922267aefcedb9f69afb9be153c85933..dbde162857c98bfe1088b0323e66a2b0a56bc209 100644 (file)
@@ -141,3 +141,8 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
 
     return to_virt(gnttab_table);
 }
+
+unsigned long map_frame_virt(unsigned long mfn)
+{
+    return mfn_to_virt(mfn);
+}
index 16aaae426c115814aaf8f595e3132b64af8a64c7..10b440ce5eead6bcc30516622c266ceda4396865 100644 (file)
@@ -29,9 +29,6 @@
 #include <mini-os/paravirt.h>
 
 #ifdef CONFIG_BALLOON
-
-unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
-
 #ifdef CONFIG_PARAVIRT
 static void p2m_invalidate(unsigned long *list, unsigned long start_idx)
 {
@@ -53,7 +50,7 @@ static inline unsigned long *p2m_to_virt(unsigned long p2m)
 
 void arch_remap_p2m(unsigned long max_pfn)
 {
-    unsigned long pfn;
+    unsigned long pfn, new_p2m;
     unsigned long *l3_list, *l2_list, *l1_list;
 
     l3_list = p2m_l3list();
@@ -67,17 +64,15 @@ void arch_remap_p2m(unsigned long max_pfn)
     if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) )
         return;
 
+    new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages));
     for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
     {
-        map_frame_rw(virt_kernel_area_end + PAGE_SIZE * (pfn / P2M_ENTRIES),
+        map_frame_rw(new_p2m + PAGE_SIZE * (pfn / P2M_ENTRIES),
                      virt_to_mfn(phys_to_machine_mapping + pfn));
     }
 
-    phys_to_machine_mapping = (unsigned long *)virt_kernel_area_end;
+    phys_to_machine_mapping = (unsigned long *)new_p2m;
     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);
 }
 
 int arch_expand_p2m(unsigned long max_pfn)
index f5248a4e1b6c0b3a0cc9f84584dc9524d2464e95..762599d49e4fb7532020c86d60043e959073ae76 100644 (file)
@@ -57,6 +57,7 @@ unsigned long mfn_zero;
 pgentry_t *pt_base;
 static unsigned long first_free_pfn;
 static unsigned long last_free_pfn;
+static unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
 
 extern char stack[];
 extern void page_walk(unsigned long va);
@@ -829,3 +830,25 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
     HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
     return map_frames(frames, nr_grant_frames);
 }
+
+unsigned long alloc_virt_kernel(unsigned n_pages)
+{
+    unsigned long addr;
+
+    addr = virt_kernel_area_end;
+    virt_kernel_area_end += PAGE_SIZE * n_pages;
+    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
+
+    return addr;
+}
+
+unsigned long map_frame_virt(unsigned long mfn)
+{
+    unsigned long addr;
+
+    addr = alloc_virt_kernel(1);
+    if ( map_frame_rw(addr, mfn) )
+        return 0;
+
+    return addr;
+}
index 8669edb6ad78c8e69aa31aeda402fa62a0526d64..b0d0230e0a6af4be83e82c91a4648f979ab9d915 100644 (file)
--- a/balloon.c
+++ b/balloon.c
@@ -50,20 +50,19 @@ void get_max_pages(void)
 
 void mm_alloc_bitmap_remap(void)
 {
-    unsigned long i;
+    unsigned long i, new_bitmap;
 
     if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) )
         return;
 
+    new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3));
     for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE )
     {
-        map_frame_rw(virt_kernel_area_end + i,
+        map_frame_rw(new_bitmap + i,
                      virt_to_mfn((unsigned long)(mm_alloc_bitmap) + i));
     }
 
-    mm_alloc_bitmap = (unsigned long *)virt_kernel_area_end;
-    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> 3);
-    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
+    mm_alloc_bitmap = (unsigned long *)new_bitmap;
 }
 
 #define N_BALLOON_FRAMES 64
index 8cd41af7e7ddc73aca6d757d17c674d828bcc686..6cfec4ffb60701fd7ede85f9352f22d4d24bce1e 100644 (file)
@@ -33,7 +33,6 @@
 #define BALLOON_EMERGENCY_PAGES   64
 
 extern unsigned long nr_max_pages;
-extern unsigned long virt_kernel_area_end;
 extern unsigned long nr_mem_pages;
 
 void get_max_pages(void);
index 953570cb6b8a2cd7344434dabccd409a16819599..4fc364ff1b5d28aa018ab67fa1f85ae2faa77be8 100644 (file)
@@ -79,6 +79,7 @@ int do_map_frames(unsigned long addr,
        unsigned long increment, domid_t id, int *err, unsigned long prot);
 int unmap_frames(unsigned long va, unsigned long num_frames);
 int map_frame_rw(unsigned long addr, unsigned long mfn);
+unsigned long map_frame_virt(unsigned long mfn);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
index e0ae5527dea26382ba49cd5d18be1f180ebc0bdf..9372f1eafca7b3327b78b8022cd81d690ce0030f 100644 (file)
@@ -277,6 +277,7 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
 
 pgentry_t *need_pgt(unsigned long addr);
 void arch_mm_preinit(void *p);
+unsigned long alloc_virt_kernel(unsigned n_pages);
 
 #endif