Skip to contentSkip to conversation

mini-os: support of auto-ballooning

PATCH Superseded Juergen Gross 2 participants 44 messages Aug 5, 2016 – Aug 11, 2016

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover mini-os: support of auto-ballooning

Support ballooning Mini-OS automatically up in case of memory shortage.

Do some cleanups, a small correction and add some basic features to lay groundwork for support of ballooning in Mini-OS (patches 1-14).

The main visible change is the virtual memory layout: to be able to add memory to the running Mini-OS we need to have some spare areas especially after the 1:1 mapping of physical memory.

Then add the ballooning functionality: the p2m map must be expanded, the page allocator's bitmap must be expanded and we must get new memory from the hypervisor.

In case of a detected memory shortage the domain will balloon up until either enough memory is available or the upper limit has been reached.

Ballooning has been tested with a xenstore stubdom. Regression tests have been done with:
- pure mini-os
- ioemu stubdom
- pvgrub 64 bit

pvgrub 32 bit didn't work before applying the series, it just entered the grub shell. With the series applied the behavior was exactly the same. The grub shell however was working (I tried "help" and "reboot").

I tried to modify arm specific files in order not to break the non-ballooning case, but I haven't tested it to either work or to compile.

V1 of this series consisted of patches 1-9 only.

Changes in V2:
- added patches 10-18
- some coding style corrections
- patch 7: introduced balloon specific source files
- moved ballooning specific functions/definitions to ballon specific files
- patch 9: avoid conflict with hypervisor mapped area on 32 bits

Juergen Gross (18):
mini-os: correct first free pfn
mini-os: remove unused alloc_contig_pages() function
mini-os: remove MM_DEBUG code
mini-os: add description of x86 memory usage
mini-os: add nr_free_pages counter
mini-os: let memory allocation fail if no free page available
mini-os: add ballooning config item
mini-os: get maximum memory size from hypervisor
mini-os: modify virtual memory layout for support of ballooning
mini-os: remove unused mem_test() function
mini-os: add checks for out of memory
mini-os: don't allocate new pages for level 1 p2m tree
mini-os: add function to map one frame
mini-os: move p2m related macros to header file
mini-os: remap p2m list in case of ballooning
mini-os: map page allocator's bitmap to virtual kernel area for
ballooning
mini-os: add support for ballooning up
mini-os: balloon up in case of oom

 Makefile              |   3 +
 arch/arm/balloon.c    |  39 +++++++
 arch/arm/mm.c         |  10 +-
 arch/x86/balloon.c    | 146 +++++++++++++++++++++++
 arch/x86/mm.c         | 314 +++++++-------------------------------------------
 balloon.c             | 159 +++++++++++++++++++++++++
 include/arm/arch_mm.h |   2 +
 include/balloon.h     |  59 ++++++++++
 include/mm.h          |  13 ++-
 include/x86/arch_mm.h |  70 +++++++++++
 mm.c                  | 108 ++++++-----------
 11 files changed, 575 insertions(+), 348 deletions(-)
 create mode 100644 arch/arm/balloon.c
 create mode 100644 arch/x86/balloon.c
 create mode 100644 balloon.c
 create mode 100644 include/balloon.h
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v2 1/18 mini-os: correct first free pfn

The first free pfn available for allocation is calculated by adding the number of page table frames to the pfn of the first page table and then the magic number 3 to account for start info page et al.

As the start info page, xenstore page and console page are allocated _before_ the page tables leaving room for these pages behind the page tables makes no sense.

---
 arch/x86/mm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/mm.c +2 -3
index 51aa966..ae1036e 100644
@@ -867,9 +867,8 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
     printk("stack start: %p(VA)\n", stack);
     printk("       _end: %p(VA)\n", &_end);
 
-    /* First page follows page table pages and 3 more pages (store page etc) */
-    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + 
-        start_info.nr_pt_frames + 3;
+    /* First page follows page table pages. */
+    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + start_info.nr_pt_frames;
     max_pfn = start_info.nr_pages;
 
     /* We need room for demand mapping and heap, clip available memory */
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

PATCH v2 2/18 mini-os: remove unused alloc_contig_pages() function

In reply to Juergen Gross

alloc_contig_pages() is never used anywhere in mini-os. Remove it.

---
 arch/x86/mm.c | 142 ----------------------------------------------------------
 include/mm.h  |   1 -
 2 files changed, 143 deletions(-)
arch/x86/mm.c +0 -142
index ae1036e..c59a5d3 100644
@@ -652,148 +652,6 @@ int unmap_frames(unsigned long va, unsigned long num_frames)
 }
 
 /*
- * Allocate pages which are contiguous in machine memory.
- * Returns a VA to where they are mapped or 0 on failure.
- * 
- * addr_bits indicates if the region has restrictions on where it is
- * located. Typical values are 32 (if for example PCI devices can't access
- * 64bit memory) or 0 for no restrictions.
- *
- * Allocated pages can be freed using the page allocators free_pages() 
- * function.
- *
- * based on Linux function xen_create_contiguous_region()
- */
-#define MAX_CONTIG_ORDER 9 /* 2MB */
-unsigned long alloc_contig_pages(int order, unsigned int addr_bits)
-{
-    unsigned long in_va, va;
-    unsigned long in_frames[1UL << order], out_frames, mfn;
-    multicall_entry_t call[1UL << order];
-    unsigned int i, num_pages = 1UL << order;
-    int ret, exch_success;
-
-    /* pass in num_pages 'extends' of size 1 and
-     * request 1 extend of size 'order */
-    struct xen_memory_exchange exchange = {
-        .in = {
-            .nr_extents   = num_pages,
-            .extent_order = 0,
-            .domid        = DOMID_SELF
-        },
-        .out = {
-            .nr_extents   = 1,
-            .extent_order = order,
-            .address_bits = addr_bits,
-            .domid        = DOMID_SELF
-        },
-        .nr_exchanged = 0
-    };
-
-    if ( order > MAX_CONTIG_ORDER )
-    {
-        printk("alloc_contig_pages: order too large 0x%x > 0x%x\n",
-               order, MAX_CONTIG_ORDER);
-        return 0;
-    }
-
-    /* Allocate some potentially discontiguous pages */
-    in_va = alloc_pages(order);
-    if ( !in_va )
-    {
-        printk("alloc_contig_pages: could not get enough pages (order=0x%x\n",
-               order);
-        return 0;
-    }
-
-    /* set up arguments for exchange hyper call */
-    set_xen_guest_handle(exchange.in.extent_start, in_frames);
-    set_xen_guest_handle(exchange.out.extent_start, &out_frames);
-
-    /* unmap current frames, keep a list of MFNs */
-    for ( i = 0; i < num_pages; i++ )
-    {
-        int arg = 0;
-
-        va = in_va + (PAGE_SIZE * i);
-        in_frames[i] = virt_to_mfn(va);
-
-        /* update P2M mapping */
-        phys_to_machine_mapping[virt_to_pfn(va)] = INVALID_P2M_ENTRY;
-
-        /* build multi call */
-        call[i].op = __HYPERVISOR_update_va_mapping;
-        call[i].args[arg++] = va;
-        call[i].args[arg++] = 0;
-#ifdef __i386__
-        call[i].args[arg++] = 0;
-#endif  
-        call[i].args[arg++] = UVMF_INVLPG;
-    }
-
-    ret = HYPERVISOR_multicall(call, i);
-    if ( ret )
-    {
-        printk("Odd, update_va_mapping hypercall failed with rc=%d.\n", ret);
-        return 0;
-    }
-
-    /* try getting a contig range of MFNs */
-    out_frames = virt_to_pfn(in_va); /* PFNs to populate */
-    ret = HYPERVISOR_memory_op(XENMEM_exchange, &exchange);
-    if ( ret ) {
-        printk("mem exchanged order=0x%x failed with rc=%d, nr_exchanged=%lu\n",
-               order, ret, exchange.nr_exchanged);
-        /* we still need to return the allocated pages above to the pool
-         * ie. map them back into the 1:1 mapping etc. so we continue but 
-         * in the end return the pages to the page allocator and return 0. */
-        exch_success = 0;
-    }
-    else
-        exch_success = 1;
-
-    /* map frames into 1:1 and update p2m */
-    for ( i = 0; i < num_pages; i++ )
-    {
-        int arg = 0;
-        pte_t pte;
-
-        va = in_va + (PAGE_SIZE * i);
-        mfn = i < exchange.nr_exchanged ? (out_frames + i) : in_frames[i];
-        pte = __pte(mfn << PAGE_SHIFT | L1_PROT);
-
-        /* update P2M mapping */
-        phys_to_machine_mapping[virt_to_pfn(va)] = mfn;
-
-        /* build multi call */
-        call[i].op = __HYPERVISOR_update_va_mapping;
-        call[i].args[arg++] = va;
-#ifdef __x86_64__
-        call[i].args[arg++] = (pgentry_t)pte.pte;
-#else
-        call[i].args[arg++] = pte.pte_low;
-        call[i].args[arg++] = pte.pte_high;
-#endif  
-        call[i].args[arg++] = UVMF_INVLPG;
-    }
-    ret = HYPERVISOR_multicall(call, i);
-    if ( ret )
-    {
-        printk("update_va_mapping hypercall no. 2 failed with rc=%d.\n", ret);
-        return 0;
-    }
-
-    if ( !exch_success )
-    {
-        /* since the exchanged failed we just free the pages as well */
-        free_pages((void *) in_va, order);
-        return 0;
-    }
-    
-    return in_va;
-}
-
-/*
  * Clear some of the bootstrap memory
  */
 static void clear_bootstrap(void)
include/mm.h +0 -1
index f57d8ab..a48f485 100644
@@ -71,7 +71,6 @@ void do_map_frames(unsigned long addr,
         const unsigned long *f, unsigned long n, unsigned long stride,
 	unsigned long increment, domid_t id, int *err, unsigned long prot);
 int unmap_frames(unsigned long va, unsigned long num_frames);
-unsigned long alloc_contig_pages(int order, unsigned int addr_bits);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

PATCH v2 3/18 mini-os: remove MM_DEBUG code

In reply to Juergen Gross

mm.c contains unused code inside #ifdef MM_DEBUG areas. Its usability is rather questionable and some parts are even wrong (e.g. print_chunks() called with nr_pages > 1000 will clobber an arbitrary stack content with a 0 byte).

Remove this code.

---
 mm.c | 60 ------------------------------------------------------------
 1 file changed, 60 deletions(-)
mm.c +0 -60
index 31aaf83..0dd4862 100644
@@ -42,13 +42,6 @@
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
 
-#ifdef MM_DEBUG
-#define DEBUG(_f, _a...) \
-    printk("MINI_OS(file=mm.c, line=%d) " _f "\n", __LINE__, ## _a)
-#else
-#define DEBUG(_f, _a...)    ((void)0)
-#endif
-
 /*********************
  * ALLOCATION BITMAP
  *  One bit per page of memory. Bit set => page is allocated.
@@ -140,59 +133,6 @@ static chunk_head_t  free_tail[FREELIST_SIZE];
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 
-#ifdef MM_DEBUG
-/*
- * Prints allocation[0/1] for @nr_pages, starting at @start
- * address (virtual).
- */
-USED static void print_allocation(void *start, int nr_pages)
-{
-    unsigned long pfn_start = virt_to_pfn(start);
-    int count;
-    for(count = 0; count < nr_pages; count++)
-        if(allocated_in_map(pfn_start + count)) printk("1");
-        else printk("0");
-        
-    printk("\n");        
-}
-
-/*
- * Prints chunks (making them with letters) for @nr_pages starting
- * at @start (virtual).
- */
-USED static void print_chunks(void *start, int nr_pages)
-{
-    char chunks[1001], current='A';
-    int order, count;
-    chunk_head_t *head;
-    unsigned long pfn_start = virt_to_pfn(start);
-   
-    memset(chunks, (int)'_', 1000);
-    if(nr_pages > 1000) 
-    {
-        DEBUG("Can only pring 1000 pages. Increase buffer size.");
-    }
-    
-    for(order=0; order < FREELIST_SIZE; order++)
-    {
-        head = free_head[order];
-        while(!FREELIST_EMPTY(head))
-        {
-            for(count = 0; count < 1UL<< head->level; count++)
-            {
-                if(count + virt_to_pfn(head) - pfn_start < 1000)
-                    chunks[count + virt_to_pfn(head) - pfn_start] = current;
-            }
-            head = head->next;
-            current++;
-        }
-    }
-    chunks[nr_pages] = '\0';
-    printk("%s\n", chunks);
-}
-#endif
-
-
 /*
  * Initialise allocator, placing addresses [@min,@max] in free pool.
  * @min and @max are PHYSICAL addresses.
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#7 lore raw

PATCH v2 4/18 mini-os: add description of x86 memory usage

In reply to Juergen Gross

Add a brief description how the physical and virtual address usage looks like on x86 to include/x86/arch_mm.h

---
 include/x86/arch_mm.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
include/x86/arch_mm.h +20 -0
index 58f29fc..f756dab 100644
@@ -36,6 +36,26 @@
 #endif
 #endif
 
+/*
+ * Physical address space usage:
+ *
+ * 0..._edata: kernel text/data
+ * *stack    : kernel stack (thread 0)
+ * hypervisor allocated data: p2m_list, start_info page, xenstore page,
+ *                            console page, initial page tables
+ * bitmap of allocated pages
+ * pages controlled by the page allocator
+ *
+ *
+ * Virtual address space usage:
+ *
+ * 1:1 mapping of physical memory starting at VA(0)
+ * 1 unallocated page
+ * demand map area (32 bits: 2 GB, 64 bits: 128 GB) for virtual allocations
+ * 1 unallocated page
+ * with libc: heap area (32 bits: 1 GB, 64 bits: 128 GB)
+ */
+
 #define L1_FRAME                1
 #define L2_FRAME                2
 #define L3_FRAME                3
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#9 lore raw

PATCH v2 5/18 mini-os: add nr_free_pages counter

In reply to Juergen Gross

Add a variable holding the number of available memory pages. This will aid auto-ballooning later.

---
 include/mm.h | 1 +
 mm.c         | 6 ++++++
 2 files changed, 7 insertions(+)
include/mm.h +1 -0
index a48f485..b97b43e 100644
@@ -42,6 +42,7 @@
 #define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER
 #define STACK_SIZE __STACK_SIZE
 
+extern unsigned long nr_free_pages;
 
 void init_mm(void);
 unsigned long alloc_pages(int order);
mm.c +6 -0
index 0dd4862..263a356 100644
@@ -53,6 +53,8 @@ static unsigned long *alloc_bitmap;
 #define allocated_in_map(_pn) \
 (alloc_bitmap[(_pn)/PAGES_PER_MAPWORD] & (1UL<<((_pn)&(PAGES_PER_MAPWORD-1))))
 
+unsigned long nr_free_pages;
+
 /*
  * Hint regarding bitwise arithmetic in map_{alloc,free}:
  *  -(1<<n)  sets all bits >= n. 
@@ -81,6 +83,8 @@ static void map_alloc(unsigned long first_page, unsigned long nr_pages)
         while ( ++curr_idx < end_idx ) alloc_bitmap[curr_idx] = ~0UL;
         alloc_bitmap[curr_idx] |= (1UL<<end_off)-1;
     }
+
+    nr_free_pages -= nr_pages;
 }
 
 
@@ -93,6 +97,8 @@ static void map_free(unsigned long first_page, unsigned long nr_pages)
     end_idx   = (first_page + nr_pages) / PAGES_PER_MAPWORD;
     end_off   = (first_page + nr_pages) & (PAGES_PER_MAPWORD-1);
 
+    nr_free_pages += nr_pages;
+
     if ( curr_idx == end_idx )
     {
         alloc_bitmap[curr_idx] &= -(1UL<<end_off) | ((1UL<<start_off)-1);
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

PATCH v2 6/18 mini-os: let memory allocation fail if no free page available

In reply to Juergen Gross

Instead of panicing when no page can be allocated try to fail the memory allocation by returning NULL instead.

---
V2: fixed minor style issue

---
 mm.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm.c +7 -0
index 263a356..8cf3210 100644
@@ -335,6 +335,13 @@ void *sbrk(ptrdiff_t increment)
     
     if (new_brk > heap_mapped) {
         unsigned long n = (new_brk - heap_mapped + PAGE_SIZE - 1) / PAGE_SIZE;
+
+        if ( n > nr_free_pages )
+        {
+            printk("Memory exhausted: want %ld pages, but only %ld are left\n",
+                   n, nr_free_pages);
+            return NULL;
+        }
         do_map_zero(heap_mapped, n);
         heap_mapped += n * PAGE_SIZE;
     }
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#13 lore raw

PATCH v2 7/18 mini-os: add ballooning config item

In reply to Juergen Gross

Add CONFIG_BALLOON defaulting to 'n' as a config item to Mini-OS.

Add balloon.c, balloon.h and arch/*/balloon.c for future use.

---
V2: Added dummy sources and header

---
 Makefile           |  3 +++
 arch/arm/balloon.c | 28 ++++++++++++++++++++++++++++
 arch/x86/balloon.c | 28 ++++++++++++++++++++++++++++
 balloon.c          | 24 ++++++++++++++++++++++++
 include/balloon.h  | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 115 insertions(+)
 create mode 100644 arch/arm/balloon.c
 create mode 100644 arch/x86/balloon.c
 create mode 100644 balloon.c
 create mode 100644 include/balloon.h
Makefile +3 -0
index 2e4bdba..f5b7011 100644
@@ -33,6 +33,7 @@ CONFIG_CONSFRONT ?= y
 CONFIG_XENBUS ?= y
 CONFIG_XC ?=y
 CONFIG_LWIP ?= $(lwip)
+CONFIG_BALLOON ?= n
 
 # Export config items as compiler directives
 flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
@@ -48,6 +49,7 @@ flags-$(CONFIG_KBDFRONT) += -DCONFIG_KBDFRONT
 flags-$(CONFIG_FBFRONT) += -DCONFIG_FBFRONT
 flags-$(CONFIG_CONSFRONT) += -DCONFIG_CONSFRONT
 flags-$(CONFIG_XENBUS) += -DCONFIG_XENBUS
+flags-$(CONFIG_BALLOON) += -DCONFIG_BALLOON
 
 DEF_CFLAGS += $(flags-y)
 
@@ -96,6 +98,7 @@ src-$(CONFIG_NETFRONT) += netfront.c
 src-$(CONFIG_PCIFRONT) += pcifront.c
 src-y += sched.c
 src-$(CONFIG_TEST) += test.c
+src-$(CONFIG_BALLOON) += balloon.c
 
 src-y += lib/ctype.c
 src-y += lib/math.c
arch/arm/balloon.c new file +28 -0
new file mode 100644
index 0000000..dc6270d
@@ -0,0 +1,28 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <mini-os/balloon.h>
+
+#ifdef CONFIG_BALLOON
+
+#endif
arch/x86/balloon.c new file +28 -0
new file mode 100644
index 0000000..dc6270d
@@ -0,0 +1,28 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <mini-os/balloon.h>
+
+#ifdef CONFIG_BALLOON
+
+#endif
balloon.c new file +24 -0
new file mode 100644
index 0000000..9cabde0
@@ -0,0 +1,24 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <mini-os/balloon.h>
include/balloon.h new file +32 -0
new file mode 100644
index 0000000..399fff4
@@ -0,0 +1,32 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _BALLOON_H_
+#define _BALLOON_H_
+
+#ifdef CONFIG_BALLOON
+
+#else /* CONFIG_BALLOON */
+
+#endif /* CONFIG_BALLOON */
+#endif /* _BALLOON_H_ */
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#15 lore raw

PATCH v2 8/18 mini-os: get maximum memory size from hypervisor

In reply to Juergen Gross

Add support for obtaining the maximum memory size from the hypervisor. This will make it possible to support ballooning.

---
V2: Moved new stuff to balloon.c

---
 balloon.c         | 22 ++++++++++++++++++++++
 include/balloon.h |  6 ++++++
 mm.c              |  3 ++-
 3 files changed, 30 insertions(+), 1 deletion(-)
balloon.c +22 -0
index 9cabde0..4c18c5c 100644
@@ -21,4 +21,26 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <mini-os/os.h>
 #include <mini-os/balloon.h>
+#include <mini-os/lib.h>
+#include <xen/xen.h>
+#include <xen/memory.h>
+
+unsigned long nr_max_pages;
+
+void get_max_pages(void)
+{
+    long ret;
+    domid_t domid = DOMID_SELF;
+
+    ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid);
+    if ( ret < 0 )
+    {
+        printk("Could not get maximum pfn\n");
+        return;
+    }
+
+    nr_max_pages = ret;
+    printk("Maximum memory size: %ld pages\n", nr_max_pages);
+}
include/balloon.h +6 -0
index 399fff4..e7219f8 100644
@@ -26,7 +26,13 @@
 
 #ifdef CONFIG_BALLOON
 
+extern unsigned long nr_max_pages;
+
+void get_max_pages(void);
+
 #else /* CONFIG_BALLOON */
 
+static inline void get_max_pages(void) { }
+
 #endif /* CONFIG_BALLOON */
 #endif /* _BALLOON_H_ */
mm.c +2 -1
index 8cf3210..25ee3da 100644
@@ -38,6 +38,7 @@
 #include <mini-os/hypervisor.h>
 #include <xen/memory.h>
 #include <mini-os/mm.h>
+#include <mini-os/balloon.h>
 #include <mini-os/types.h>
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
@@ -353,7 +354,6 @@ void *sbrk(ptrdiff_t increment)
 #endif
 
 
-
 void init_mm(void)
 {
 
@@ -361,6 +361,7 @@ void init_mm(void)
 
     printk("MM: Init\n");
 
+    get_max_pages();
     arch_init_mm(&start_pfn, &max_pfn);
     /*
      * now we can initialise the page allocator
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#17 lore raw

PATCH v2 9/18 mini-os: modify virtual memory layout for support of ballooning

In reply to Juergen Gross

In order to be able to support ballooning the virtual memory layout of Mini-OS has to be modified: instead of a (nearly) consecutive area used for physical memory mapping, on demand mappings, and heap we need enough spare place for adding new memory.

So instead of dynamically place the different regions based on found memory size locate them statically at fixed virtual addresses:

area x86-64 x86-32
------------------------------------------------------------

mapped physical memory       00000000             00000000
kernel virtual mappings    8000000000             3f000000
demand mappings          100000000000             40000000
heap                     200000000000             b0000000

This will enable Mini-OS to support up to 512GB of domain memory with a 64 bit kernel and nearly 1GB with a 32 bit kernel.

For a 32 bit Mini-OS we have to avoid a conflict between heap and m2p table which the hypervisor maps at f5600000. So the demand mapping size is reduced by 256MB in order to keep the heap at about 1GB.

The kernel virtual mappings are a new area needed for being able to grow the p2m list without having to relocate it in physical memory.

Modify the placement of the demand mappings and heap and adjust the memory layout description.

---
V2: avoid conflict with hypervisor mapped area on 32 bits

---
 arch/arm/mm.c         |  2 +-
 arch/x86/mm.c         | 44 +++++++++++---------------------------------
 include/mm.h          |  2 +-
 include/x86/arch_mm.h | 35 ++++++++++++++++++++++++++++++-----
 mm.c                  |  2 +-
 5 files changed, 44 insertions(+), 41 deletions(-)
arch/arm/mm.c +1 -1
index efecc51..f75888d 100644
@@ -75,7 +75,7 @@ void arch_init_p2m(unsigned long max_pfn)
 {
 }
 
-void arch_init_demand_mapping_area(unsigned long cur_pfn)
+void arch_init_demand_mapping_area(void)
 {
 }
 
arch/x86/mm.c +11 -33

62 lines not on this page · raw message

include/mm.h +1 -1
index b97b43e..a22dcd1 100644
@@ -59,7 +59,7 @@ static __inline__ int get_order(unsigned long size)
     return order;
 }
 
-void arch_init_demand_mapping_area(unsigned long max_pfn);
+void arch_init_demand_mapping_area(void);
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p);
 void arch_init_p2m(unsigned long max_pfn_p);
 
include/x86/arch_mm.h +30 -5
index f756dab..d87fe55 100644
@@ -49,11 +49,13 @@
  *
  * Virtual address space usage:
  *
- * 1:1 mapping of physical memory starting at VA(0)
- * 1 unallocated page
- * demand map area (32 bits: 2 GB, 64 bits: 128 GB) for virtual allocations
- * 1 unallocated page
- * with libc: heap area (32 bits: 1 GB, 64 bits: 128 GB)
+ *  area                           x86-64               x86-32
+ *  ------------------------------------------------------------
+ *  mapped physical memory       00000000             00000000
+ *  kernel virtual mappings    8000000000             3f000000
+ *  demand mappings          100000000000             40000000
+ *  heap (with libc only)    200000000000             b0000000
+ *
  */
 
 #define L1_FRAME                1
@@ -81,6 +83,15 @@
 typedef uint64_t pgentry_t;
 #endif
 
+#define MAX_MEM_SIZE            0x3f000000UL
+#define VIRT_KERNEL_AREA        0x3f000000UL
+#define VIRT_DEMAND_AREA        0x40000000UL
+#define VIRT_HEAP_AREA          0xb0000000UL
+
+#define DEMAND_MAP_PAGES        0x6ffffUL
+#define HEAP_PAGES_MAX          ((HYPERVISOR_VIRT_START - VIRT_HEAP_AREA) / \
+                                 PAGE_SIZE - 1)
+
 #elif defined(__x86_64__)
 
 #define L2_PAGETABLE_SHIFT      21
@@ -106,6 +117,20 @@ typedef uint64_t pgentry_t;
 typedef unsigned long pgentry_t;
 #endif
 
+#define MAX_MEM_SIZE            (512ULL << 30)
+#define VIRT_KERNEL_AREA        0x0000008000000000UL
+#define VIRT_DEMAND_AREA        0x0000100000000000UL
+#define VIRT_HEAP_AREA          0x0000200000000000UL
+
+#define DEMAND_MAP_PAGES        0x8000000UL
+#define HEAP_PAGES_MAX          0x8000000UL
+
+#endif
+
+#ifndef HAVE_LIBC
+#define HEAP_PAGES 0
+#else
+#define HEAP_PAGES   HEAP_PAGES_MAX
 #endif
 
 #define L1_MASK  ((1UL << L2_PAGETABLE_SHIFT) - 1)
mm.c +1 -1
index 25ee3da..ff071ca 100644
@@ -374,7 +374,7 @@ void init_mm(void)
 
     arch_init_p2m(max_pfn);
     
-    arch_init_demand_mapping_area(max_pfn);
+    arch_init_demand_mapping_area();
 }
 
 void fini_mm(void)
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#19 lore raw

PATCH v2 10/18 mini-os: remove unused mem_test() function

In reply to Juergen Gross

mem_test() isn't used anywhere and its value is rather questionable with mini-os being in a mature state. Remove the function.

---
 arch/x86/mm.c | 55 -------------------------------------------------------
 1 file changed, 55 deletions(-)
arch/x86/mm.c +0 -55
index 6aa4468..e2f026b 100644
@@ -302,61 +302,6 @@ static void set_readonly(void *text, void *etext)
 }
 
 /*
- * A useful mem testing function. Write the address to every address in the
- * range provided and read back the value. If verbose, print page walk to
- * some VA
- * 
- * If we get MEM_TEST_MAX_ERRORS we might as well stop
- */
-#define MEM_TEST_MAX_ERRORS 10 
-int mem_test(unsigned long *start_va, unsigned long *end_va, int verbose)
-{
-    unsigned long mask = 0x10000;
-    unsigned long *pointer;
-    int error_count = 0;
- 
-    /* write values and print page walks */
-    if ( verbose && (((unsigned long)start_va) & 0xfffff) )
-    {
-        printk("MemTest Start: 0x%p\n", start_va);
-        page_walk((unsigned long)start_va);
-    }
-    for ( pointer = start_va; pointer < end_va; pointer++ )
-    {
-        if ( verbose && !(((unsigned long)pointer) & 0xfffff) )
-        {
-            printk("Writing to %p\n", pointer);
-            page_walk((unsigned long)pointer);
-        }
-        *pointer = (unsigned long)pointer & ~mask;
-    }
-    if ( verbose && (((unsigned long)end_va) & 0xfffff) )
-    {
-        printk("MemTest End: %p\n", end_va-1);
-        page_walk((unsigned long)end_va-1);
-    }
- 
-    /* verify values */
-    for ( pointer = start_va; pointer < end_va; pointer++ )
-    {
-        if ( ((unsigned long)pointer & ~mask) != *pointer )
-        {
-            printk("Read error at 0x%lx. Read: 0x%lx, should read 0x%lx\n",
-                   (unsigned long)pointer, *pointer, 
-                   ((unsigned long)pointer & ~mask));
-            error_count++;
-            if ( error_count >= MEM_TEST_MAX_ERRORS )
-            {
-                printk("mem_test: too many errors\n");
-                return -1;
-            }
-        }
-    }
-    return 0;
-}
-
-
-/*
  * get the PTE for virtual address va if it exists. Otherwise NULL.
  */
 static pgentry_t *get_pgt(unsigned long va)
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#21 lore raw

PATCH v2 11/18 mini-os: add checks for out of memory

In reply to Juergen Gross

There are several core functions in Mini-OS not checking for failed memory allocations. Add such checks.

Add do_map_frames() dummy function to arm architecture as it will be needed in future for compilations to succeed.

---
 arch/arm/mm.c |  8 ++++++++
 arch/x86/mm.c | 26 +++++++++++++++++++-------
 include/mm.h  |  2 +-
 3 files changed, 28 insertions(+), 8 deletions(-)
arch/arm/mm.c +8 -0
index f75888d..fc8d4bc 100644
@@ -1,6 +1,7 @@
 #include <mini-os/console.h>
 #include <xen/memory.h>
 #include <arch_mm.h>
+#include <mini-os/errno.h>
 #include <mini-os/hypervisor.h>
 #include <libfdt.h>
 #include <lib.h>
@@ -79,6 +80,13 @@ void arch_init_demand_mapping_area(void)
 {
 }
 
+int do_map_frames(unsigned long addr,
+        const unsigned long *f, unsigned long n, unsigned long stride,
+        unsigned long increment, domid_t id, int *err, unsigned long prot)
+{
+    return -ENOSYS;
+}
+
 /* Get Xen's suggested physical page assignments for the grant table. */
 static paddr_t get_gnttab_base(void)
 {
arch/x86/mm.c +19 -7
index e2f026b..12f7fe4 100644
@@ -34,6 +34,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <mini-os/errno.h>
 #include <mini-os/os.h>
 #include <mini-os/hypervisor.h>
 #include <mini-os/mm.h>
@@ -354,6 +355,8 @@ pgentry_t *need_pgt(unsigned long va)
     if ( !(tab[offset] & _PAGE_PRESENT) )
     {
         pt_pfn = virt_to_pfn(alloc_page());
+        if ( !pt_pfn )
+            return NULL;
         new_pt_frame(&pt_pfn, pt_mfn, offset, L3_FRAME);
     }
     ASSERT(tab[offset] & _PAGE_PRESENT);
@@ -364,6 +367,8 @@ pgentry_t *need_pgt(unsigned long va)
     if ( !(tab[offset] & _PAGE_PRESENT) ) 
     {
         pt_pfn = virt_to_pfn(alloc_page());
+        if ( !pt_pfn )
+            return NULL;
         new_pt_frame(&pt_pfn, pt_mfn, offset, L2_FRAME);
     }
     ASSERT(tab[offset] & _PAGE_PRESENT);
@@ -373,6 +378,8 @@ pgentry_t *need_pgt(unsigned long va)
     if ( !(tab[offset] & _PAGE_PRESENT) )
     {
         pt_pfn = virt_to_pfn(alloc_page());
+        if ( !pt_pfn )
+            return NULL;
         new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME);
     }
     ASSERT(tab[offset] & _PAGE_PRESENT);
@@ -445,10 +452,10 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
  * va. map f[i*stride]+i*increment for i in 0..n-1.
  */
 #define MAP_BATCH ((STACK_SIZE / 2) / sizeof(mmu_update_t))
-void do_map_frames(unsigned long va,
-                   const unsigned long *mfns, unsigned long n, 
-                   unsigned long stride, unsigned long incr, 
-                   domid_t id, int *err, unsigned long prot)
+int do_map_frames(unsigned long va,
+                  const unsigned long *mfns, unsigned long n,
+                  unsigned long stride, unsigned long incr,
+                  domid_t id, int *err, unsigned long prot)
 {
     pgentry_t *pgt = NULL;
     unsigned long done = 0;
@@ -458,7 +465,7 @@ void do_map_frames(unsigned long va,
     if ( !mfns ) 
     {
         printk("do_map_frames: no mfns supplied\n");
-        return;
+        return -EINVAL;
     }
     DEBUG("va=%p n=0x%lx, mfns[0]=0x%lx stride=0x%lx incr=0x%lx prot=0x%lx\n",
           va, n, mfns[0], stride, incr, prot);
@@ -484,7 +491,9 @@ void do_map_frames(unsigned long va,
             {
                 if ( !pgt || !(va & L1_MASK) )
                     pgt = need_pgt(va);
-                
+                if ( !pgt )
+                    return -ENOMEM;
+
                 mmu_updates[i].ptr = virt_to_mach(pgt) | MMU_NORMAL_PT_UPDATE;
                 mmu_updates[i].val = ((pgentry_t)(mfns[(done + i) * stride] +
                                                   (done + i) * incr)
@@ -505,6 +514,8 @@ void do_map_frames(unsigned long va,
         }
         done += todo;
     }
+
+    return 0;
 }
 
 /*
@@ -521,7 +532,8 @@ void *map_frames_ex(const unsigned long *mfns, unsigned long n,
     if ( !va )
         return NULL;
 
-    do_map_frames(va, mfns, n, stride, incr, id, err, prot);
+    if ( do_map_frames(va, mfns, n, stride, incr, id, err, prot) )
+        return NULL;
 
     return (void *)va;
 }
include/mm.h +1 -1
index a22dcd1..9244e26 100644
@@ -68,7 +68,7 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
 void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride,
 	unsigned long increment, unsigned long alignment, domid_t id,
 	int *err, unsigned long prot);
-void do_map_frames(unsigned long addr,
+int do_map_frames(unsigned long addr,
         const unsigned long *f, unsigned long n, unsigned long stride,
 	unsigned long increment, domid_t id, int *err, unsigned long prot);
 int unmap_frames(unsigned long va, unsigned long num_frames);
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#23 lore raw

PATCH v2 12/18 mini-os: don't allocate new pages for level 1 p2m tree

In reply to Juergen Gross

When constructing the 3 level p2m tree there is no need to allocate new pages for the level 1 containing the p2m info for all pages. The pages from the linear p2m list constructed by the hypervisor can be used for that purpose.

---
 arch/x86/mm.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
arch/x86/mm.c +4 -10
index 12f7fe4..e10c2c5 100644
@@ -625,11 +625,11 @@ void arch_init_p2m(unsigned long max_pfn)
 #define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
 #define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
     
-    unsigned long *l1_list = NULL, *l2_list = NULL, *l3_list;
+    unsigned long *l2_list = NULL, *l3_list;
     unsigned long pfn;
     
     l3_list = (unsigned long *)alloc_page(); 
-    for ( pfn=0; pfn<max_pfn; pfn++ )
+    for ( pfn = 0; pfn < max_pfn; pfn += L1_P2M_ENTRIES )
     {
         if ( !(pfn % (L1_P2M_ENTRIES * L2_P2M_ENTRIES)) )
         {
@@ -641,14 +641,8 @@ void arch_init_p2m(unsigned long max_pfn)
             }
             l3_list[(pfn >> L2_P2M_SHIFT)] = virt_to_mfn(l2_list);  
         }
-        if ( !(pfn % (L1_P2M_ENTRIES)) )
-        {
-            l1_list = (unsigned long*)alloc_page();
-            l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] = 
-                virt_to_mfn(l1_list); 
-        }
-
-        l1_list[pfn & L1_P2M_MASK] = pfn_to_mfn(pfn); 
+        l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] =
+            virt_to_mfn(phys_to_machine_mapping + pfn);
     }
     HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 
         virt_to_mfn(l3_list);
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#25 lore raw

PATCH v2 13/18 mini-os: add function to map one frame

In reply to Juergen Gross

Add a function to map one physical frame to a specified virtual address as read/write. This will be used later multiple times.

---
 include/arm/arch_mm.h | 2 ++
 include/mm.h          | 1 +
 mm.c                  | 5 +++++
 3 files changed, 8 insertions(+)
include/arm/arch_mm.h +2 -0
index 085d4e5..f4685d8 100644
@@ -14,6 +14,8 @@ extern uint32_t physical_address_offset;	/* Add this to a virtual address to get
 
 #define L1_PAGETABLE_SHIFT      12
 
+#define L1_PROT          0
+
 #define to_phys(x)                 (((paddr_t)(x)+physical_address_offset) & 0xffffffff)
 #define to_virt(x)                 ((void *)(((x)-physical_address_offset) & 0xffffffff))
 
include/mm.h +1 -0
index 9244e26..6add683 100644
@@ -72,6 +72,7 @@ int do_map_frames(unsigned long addr,
         const unsigned long *f, unsigned long n, unsigned long stride,
 	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);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
mm.c +5 -0
index ff071ca..fd66115 100644
@@ -319,6 +319,11 @@ int free_physical_pages(xen_pfn_t *mfns, int n)
     return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
 }
 
+int map_frame_rw(unsigned long addr, unsigned long mfn)
+{
+    return do_map_frames(addr, &mfn, 1, 1, 1, DOMID_SELF, NULL, L1_PROT);
+}
+
 #ifdef HAVE_LIBC
 void *sbrk(ptrdiff_t increment)
 {
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#27 lore raw

PATCH v2 14/18 mini-os: move p2m related macros to header file

In reply to Juergen Gross

In order to be able to use p2m related macros for ballooning move their definitions to arch/x86/mm.h.

There is no need to define different macros regarding index masks and number of entries for the different levels, as all levels share the same entry format (a plain mfn). So reduce the number of macros accordingly.

Add some macros to get the indices into p2m pages from a pfn and make use of them in current p2m code.

---
 arch/x86/mm.c         | 31 +++++--------------------------
 include/x86/arch_mm.h | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 26 deletions(-)
arch/x86/mm.c +5 -26
index e10c2c5..a5c8959 100644
@@ -609,40 +609,19 @@ static void clear_bootstrap(void)
 
 void arch_init_p2m(unsigned long max_pfn)
 {
-#ifdef __x86_64__
-#define L1_P2M_SHIFT    9
-#define L2_P2M_SHIFT    18    
-#define L3_P2M_SHIFT    27    
-#else
-#define L1_P2M_SHIFT    10
-#define L2_P2M_SHIFT    20    
-#define L3_P2M_SHIFT    30    
-#endif
-#define L1_P2M_ENTRIES  (1 << L1_P2M_SHIFT)    
-#define L2_P2M_ENTRIES  (1 << (L2_P2M_SHIFT - L1_P2M_SHIFT))    
-#define L3_P2M_ENTRIES  (1 << (L3_P2M_SHIFT - L2_P2M_SHIFT))    
-#define L1_P2M_MASK     (L1_P2M_ENTRIES - 1)    
-#define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
-#define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
-    
     unsigned long *l2_list = NULL, *l3_list;
     unsigned long pfn;
     
+    p2m_chk_pfn(max_pfn - 1);
     l3_list = (unsigned long *)alloc_page(); 
-    for ( pfn = 0; pfn < max_pfn; pfn += L1_P2M_ENTRIES )
+    for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
     {
-        if ( !(pfn % (L1_P2M_ENTRIES * L2_P2M_ENTRIES)) )
+        if ( !(pfn % (P2M_ENTRIES * P2M_ENTRIES)) )
         {
             l2_list = (unsigned long*)alloc_page();
-            if ( (pfn >> L3_P2M_SHIFT) > 0 )
-            {
-                printk("Error: Too many pfns.\n");
-                do_exit();
-            }
-            l3_list[(pfn >> L2_P2M_SHIFT)] = virt_to_mfn(l2_list);  
+            l3_list[L3_P2M_IDX(pfn)] = virt_to_mfn(l2_list);
         }
-        l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] =
-            virt_to_mfn(phys_to_machine_mapping + pfn);
+        l2_list[L2_P2M_IDX(pfn)] = virt_to_mfn(phys_to_machine_mapping + pfn);
     }
     HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 
         virt_to_mfn(l3_list);
include/x86/arch_mm.h +21 -0
index d87fe55..7283f64 100644
@@ -176,7 +176,28 @@ typedef unsigned long pgentry_t;
 #define IO_PROT_NOCACHE (L1_PROT | _PAGE_PCD)
 
 /* for P2M */
+#ifdef __x86_64__
+#define P2M_SHIFT       9
+#else
+#define P2M_SHIFT       10
+#endif
+#define P2M_ENTRIES     (1UL << P2M_SHIFT)
+#define P2M_MASK        (P2M_ENTRIES - 1)
+#define L1_P2M_SHIFT    P2M_SHIFT
+#define L2_P2M_SHIFT    (2 * P2M_SHIFT)
+#define L3_P2M_SHIFT    (3 * P2M_SHIFT)
+#define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK)
+#define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK)
+#define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
 #define INVALID_P2M_ENTRY (~0UL)
+static inline void p2m_chk_pfn(unsigned long pfn)
+{
+    if ( (pfn >> L3_P2M_SHIFT) > 0 )
+    {
+        printk("Error: Too many pfns.\n");
+        do_exit();
+    }
+}
 
 #include "arch_limits.h"
 #define PAGE_SIZE       __PAGE_SIZE
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#29 lore raw

PATCH v2 15/18 mini-os: remap p2m list in case of ballooning

In reply to Juergen Gross

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.

---
 arch/arm/balloon.c    |  2 ++
 arch/x86/balloon.c    | 24 ++++++++++++++++++++++++
 arch/x86/mm.c         |  3 +++
 include/balloon.h     |  3 +++
 include/x86/arch_mm.h |  4 ++++
 5 files changed, 36 insertions(+)
arch/arm/balloon.c +2 -0
index dc6270d..a76db3b 100644
@@ -25,4 +25,6 @@
 
 #ifdef CONFIG_BALLOON
 
+unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
+
 #endif
arch/x86/balloon.c +24 -0
index dc6270d..db37e8f 100644
@@ -21,8 +21,32 @@
  * 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);
+}
+
 #endif
arch/x86/mm.c +3 -0
index a5c8959..8fa3b4c 100644
@@ -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)
include/balloon.h +3 -0
index e7219f8..b8d9335 100644
@@ -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_ */
include/x86/arch_mm.h +4 -0
index 7283f64..e5d9c57 100644
@@ -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
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#33 lore raw

PATCH v2 16/18 mini-os: map page allocator's bitmap to virtual kernel area for ballooning

In reply to Juergen Gross

In case of CONFIG_BALLOON the page allocator's bitmap needs some space to be able to grow. Remap it to kernel virtual area if the preallocated area isn't large enough.

---
 balloon.c         | 17 +++++++++++++++++
 include/balloon.h |  2 ++
 include/mm.h      |  6 ++++++
 mm.c              | 19 ++++++++++---------
 4 files changed, 35 insertions(+), 9 deletions(-)
balloon.c +17 -0
index 4c18c5c..75b87c8 100644
@@ -44,3 +44,20 @@ void get_max_pages(void)
     nr_max_pages = ret;
     printk("Maximum memory size: %ld pages\n", nr_max_pages);
 }
+
+void alloc_bitmap_remap(void)
+{
+    unsigned long i;
+
+    if ( alloc_bitmap_size >= ((nr_max_pages + 1) >> (PAGE_SHIFT + 3)) )
+        return;
+
+    for ( i = 0; i < alloc_bitmap_size; i += PAGE_SIZE )
+    {
+        map_frame_rw(virt_kernel_area_end + i,
+                     virt_to_mfn((unsigned long)(alloc_bitmap) + i));
+    }
+
+    alloc_bitmap = (unsigned long *)virt_kernel_area_end;
+    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> (PAGE_SHIFT + 3));
+}
include/balloon.h +2 -0
index b8d9335..0e2340b 100644
@@ -31,11 +31,13 @@ extern unsigned long virt_kernel_area_end;
 
 void get_max_pages(void);
 void arch_remap_p2m(unsigned long max_pfn);
+void alloc_bitmap_remap(void);
 
 #else /* CONFIG_BALLOON */
 
 static inline void get_max_pages(void) { }
 static inline void arch_remap_p2m(unsigned long max_pfn) { }
+static inline void alloc_bitmap_remap(void) { }
 
 #endif /* CONFIG_BALLOON */
 #endif /* _BALLOON_H_ */
include/mm.h +6 -0
index 6add683..73c59c4 100644
@@ -42,8 +42,14 @@
 #define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER
 #define STACK_SIZE __STACK_SIZE
 
+#define round_pgdown(_p)  ((_p) & PAGE_MASK)
+#define round_pgup(_p)    (((_p) + (PAGE_SIZE - 1)) & PAGE_MASK)
+
 extern unsigned long nr_free_pages;
 
+extern unsigned long *alloc_bitmap;
+extern unsigned long alloc_bitmap_size;
+
 void init_mm(void);
 unsigned long alloc_pages(int order);
 #define alloc_page()    alloc_pages(0)
mm.c +10 -9
index fd66115..13bb3e5 100644
@@ -48,7 +48,9 @@
  *  One bit per page of memory. Bit set => page is allocated.
  */
 
-static unsigned long *alloc_bitmap;
+unsigned long *alloc_bitmap;
+unsigned long alloc_bitmap_size;
+
 #define PAGES_PER_MAPWORD (sizeof(unsigned long) * 8)
 
 #define allocated_in_map(_pn) \
@@ -137,9 +139,6 @@ static chunk_head_t *free_head[FREELIST_SIZE];
 static chunk_head_t  free_tail[FREELIST_SIZE];
 #define FREELIST_EMPTY(_l) ((_l)->next == NULL)
 
-#define round_pgdown(_p)  ((_p)&PAGE_MASK)
-#define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
-
 /*
  * Initialise allocator, placing addresses [@min,@max] in free pool.
  * @min and @max are PHYSICAL addresses.
@@ -147,7 +146,7 @@ static chunk_head_t  free_tail[FREELIST_SIZE];
 static void init_page_allocator(unsigned long min, unsigned long max)
 {
     int i;
-    unsigned long range, bitmap_size;
+    unsigned long range;
     chunk_head_t *ch;
     chunk_tail_t *ct;
     for ( i = 0; i < FREELIST_SIZE; i++ )
@@ -161,14 +160,14 @@ static void init_page_allocator(unsigned long min, unsigned long max)
     max = round_pgdown(max);
 
     /* Allocate space for the allocation bitmap. */
-    bitmap_size  = (max+1) >> (PAGE_SHIFT+3);
-    bitmap_size  = round_pgup(bitmap_size);
+    alloc_bitmap_size  = (max + 1) >> (PAGE_SHIFT + 3);
+    alloc_bitmap_size  = round_pgup(alloc_bitmap_size);
     alloc_bitmap = (unsigned long *)to_virt(min);
-    min         += bitmap_size;
+    min         += alloc_bitmap_size;
     range        = max - min;
 
     /* All allocated by default. */
-    memset(alloc_bitmap, ~0, bitmap_size);
+    memset(alloc_bitmap, ~0, alloc_bitmap_size);
     /* Free up the memory we've been given to play with. */
     map_free(PHYS_PFN(min), range>>PAGE_SHIFT);
 
@@ -198,6 +197,8 @@ static void init_page_allocator(unsigned long min, unsigned long max)
         free_head[i]    = ch;
         ct->level       = i;
     }
+
+    alloc_bitmap_remap();
 }
 
 
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#36 lore raw

PATCH v2 17/18 mini-os: add support for ballooning up

In reply to Juergen Gross

Add support for ballooning the domain up by a specified amount of pages. Following steps are performed:

- extending the p2m map
- extending the page allocator's bitmap
- getting new memory pages from the hypervisor
- adding the memory at the current end of guest memory

---
 arch/arm/balloon.c |  9 ++++++
 arch/x86/balloon.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 balloon.c          | 64 +++++++++++++++++++++++++++++++++++++
 include/balloon.h  |  5 +++
 mm.c               |  4 +++
 5 files changed, 176 insertions(+)
arch/arm/balloon.c +9 -0
index a76db3b..fbb8007 100644
@@ -27,4 +27,13 @@
 
 unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
 
+int arch_expand_p2m(unsigned long max_pfn)
+{
+    return 0;
+}
+
+void arch_pfn_add(unsigned long pfn, unsigned long mfn)
+{
+}
+
 #endif
arch/x86/balloon.c +94 -0

113 lines not on this page · raw message

balloon.c +64 -0

78 lines not on this page · raw message

include/balloon.h +5 -0
index 0e2340b..8bf77e5 100644
@@ -28,10 +28,15 @@
 
 extern unsigned long nr_max_pages;
 extern unsigned long virt_kernel_area_end;
+extern unsigned long nr_mem_pages;
 
 void get_max_pages(void);
+int balloon_up(unsigned long n_pages);
+
 void arch_remap_p2m(unsigned long max_pfn);
 void alloc_bitmap_remap(void);
+int arch_expand_p2m(unsigned long max_pfn);
+void arch_pfn_add(unsigned long pfn, unsigned long mfn);
 
 #else /* CONFIG_BALLOON */
 
mm.c +4 -0
index 13bb3e5..092c5f9 100644
@@ -381,6 +381,10 @@ void init_mm(void)
     arch_init_p2m(max_pfn);
     
     arch_init_demand_mapping_area();
+
+#ifdef CONFIG_BALLOON
+    nr_mem_pages = max_pfn;
+#endif
 }
 
 void fini_mm(void)
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#39 lore raw

PATCH v2 18/18 mini-os: balloon up in case of oom

In reply to Juergen Gross

If a memory shortage is detected balloon up.

Be careful to always leave some pages free as ballooning up might need some memory, too:

- new p2m frames
- page tables for addressing new p2m frame
- new frame for page allocation bitmap
- page table for addressing new page allocation bitmap frame
- page tables for addressing new 1:1 mapped frames

For the moment we only balloon up synchronously when memory shortage is detected in allocation routines with irqs on.

---
 balloon.c         | 32 ++++++++++++++++++++++++++++++++
 include/balloon.h | 11 +++++++++++
 mm.c              |  4 +++-
 3 files changed, 46 insertions(+), 1 deletion(-)
balloon.c +32 -0
index 30e571c..30b338c 100644
@@ -125,3 +125,35 @@ int balloon_up(unsigned long n_pages)
 
     return rc;
 }
+
+static int in_balloon;
+
+int chk_free_pages(unsigned long needed)
+{
+    unsigned long n_pages;
+
+    /* No need for ballooning if plenty of space available. */
+    if ( needed + BALLOON_EMERGENCY_PAGES <= nr_free_pages )
+        return 0;
+
+    /* If we are already ballooning up just hope for the best. */
+    if ( in_balloon )
+        return 0;
+
+    /* Interrupts disabled can't be handled right now. */
+    if ( irqs_disabled() )
+        return 0;
+
+    in_balloon = 1;
+
+    while ( needed + BALLOON_EMERGENCY_PAGES > nr_free_pages )
+    {
+        n_pages = needed + BALLOON_EMERGENCY_PAGES - nr_free_pages;
+        if ( !balloon_up(n_pages) )
+            break;
+    }
+
+    in_balloon = 0;
+
+    return needed > nr_free_pages;
+}
include/balloon.h +11 -0
index 8bf77e5..c08b3f8 100644
@@ -26,6 +26,12 @@
 
 #ifdef CONFIG_BALLOON
 
+/*
+ * Always keep some pages free for allocations while ballooning or
+ * interrupts disabled.
+ */
+#define BALLOON_EMERGENCY_PAGES   64
+
 extern unsigned long nr_max_pages;
 extern unsigned long virt_kernel_area_end;
 extern unsigned long nr_mem_pages;
@@ -37,12 +43,17 @@ void arch_remap_p2m(unsigned long max_pfn);
 void alloc_bitmap_remap(void);
 int arch_expand_p2m(unsigned long max_pfn);
 void arch_pfn_add(unsigned long pfn, unsigned long mfn);
+int chk_free_pages(unsigned long needed);
 
 #else /* CONFIG_BALLOON */
 
 static inline void get_max_pages(void) { }
 static inline void arch_remap_p2m(unsigned long max_pfn) { }
 static inline void alloc_bitmap_remap(void) { }
+static inline int chk_free_pages(unsigned long needed)
+{
+    return needed > nr_free_pages;
+}
 
 #endif /* CONFIG_BALLOON */
 #endif /* _BALLOON_H_ */
mm.c +3 -1
index 092c5f9..2b57f46 100644
@@ -209,6 +209,8 @@ unsigned long alloc_pages(int order)
     chunk_head_t *alloc_ch, *spare_ch;
     chunk_tail_t            *spare_ct;
 
+    if ( chk_free_pages(1UL << order) )
+        goto no_memory;
 
     /* Find smallest order which can satisfy the request. */
     for ( i = order; i < FREELIST_SIZE; i++ ) {
@@ -343,7 +345,7 @@ void *sbrk(ptrdiff_t increment)
     if (new_brk > heap_mapped) {
         unsigned long n = (new_brk - heap_mapped + PAGE_SIZE - 1) / PAGE_SIZE;
 
-        if ( n > nr_free_pages )
+        if ( chk_free_pages(n) )
         {
             printk("Memory exhausted: want %ld pages, but only %ld are left\n",
                    n, nr_free_pages);
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 1/18
#2 lore raw

Re: [PATCH v2 01/18] mini-os: correct first free pfn

In reply to Juergen Gross
Quoted 7 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:45 +0200, wrote:

The first free pfn available for allocation is calculated by adding the number of page table frames to the pfn of the first page table and then the magic number 3 to account for start info page et al.

As the start info page, xenstore page and console page are allocated _before_ the page tables leaving room for these pages behind the page tables makes no sense.

Ah, it seems this dates back a very long time ago indeed.

Quoted 2 lines
Quoted 23 lines
---
 arch/x86/mm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/mm.c +2 -3
index 51aa966..ae1036e 100644
@@ -867,9 +867,8 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
     printk("stack start: %p(VA)\n", stack);
     printk("       _end: %p(VA)\n", &_end);
 
-    /* First page follows page table pages and 3 more pages (store page etc) */
-    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + 
-        start_info.nr_pt_frames + 3;
+    /* First page follows page table pages. */
+    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + start_info.nr_pt_frames;
     max_pfn = start_info.nr_pages;
 
     /* We need room for demand mapping and heap, clip available memory */
Signature · 1 line
2.6.6
Signature · 9 lines
Samuel
<c> hiri, le cri ici, c des marrants
<c> j'ai un rep ".uglyhackdirectorywithoutacls" ds mon home
 -+- #ens-mim en stage -+-

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 2/18
#4 lore raw

Re: [PATCH v2 02/18] mini-os: remove unused alloc_contig_pages() function

In reply to Juergen Gross
Quoted 4 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:46 +0200, wrote:

alloc_contig_pages() is never used anywhere in mini-os. Remove it.

Quoted 173 lines
---
 arch/x86/mm.c | 142 ----------------------------------------------------------
 include/mm.h  |   1 -
 2 files changed, 143 deletions(-)
arch/x86/mm.c +0 -142
index ae1036e..c59a5d3 100644
@@ -652,148 +652,6 @@ int unmap_frames(unsigned long va, unsigned long num_frames)
 }
 
 /*
- * Allocate pages which are contiguous in machine memory.
- * Returns a VA to where they are mapped or 0 on failure.
- * 
- * addr_bits indicates if the region has restrictions on where it is
- * located. Typical values are 32 (if for example PCI devices can't access
- * 64bit memory) or 0 for no restrictions.
- *
- * Allocated pages can be freed using the page allocators free_pages() 
- * function.
- *
- * based on Linux function xen_create_contiguous_region()
- */
-#define MAX_CONTIG_ORDER 9 /* 2MB */
-unsigned long alloc_contig_pages(int order, unsigned int addr_bits)
-{
-    unsigned long in_va, va;
-    unsigned long in_frames[1UL << order], out_frames, mfn;
-    multicall_entry_t call[1UL << order];
-    unsigned int i, num_pages = 1UL << order;
-    int ret, exch_success;
-
-    /* pass in num_pages 'extends' of size 1 and
-     * request 1 extend of size 'order */
-    struct xen_memory_exchange exchange = {
-        .in = {
-            .nr_extents   = num_pages,
-            .extent_order = 0,
-            .domid        = DOMID_SELF
-        },
-        .out = {
-            .nr_extents   = 1,
-            .extent_order = order,
-            .address_bits = addr_bits,
-            .domid        = DOMID_SELF
-        },
-        .nr_exchanged = 0
-    };
-
-    if ( order > MAX_CONTIG_ORDER )
-    {
-        printk("alloc_contig_pages: order too large 0x%x > 0x%x\n",
-               order, MAX_CONTIG_ORDER);
-        return 0;
-    }
-
-    /* Allocate some potentially discontiguous pages */
-    in_va = alloc_pages(order);
-    if ( !in_va )
-    {
-        printk("alloc_contig_pages: could not get enough pages (order=0x%x\n",
-               order);
-        return 0;
-    }
-
-    /* set up arguments for exchange hyper call */
-    set_xen_guest_handle(exchange.in.extent_start, in_frames);
-    set_xen_guest_handle(exchange.out.extent_start, &out_frames);
-
-    /* unmap current frames, keep a list of MFNs */
-    for ( i = 0; i < num_pages; i++ )
-    {
-        int arg = 0;
-
-        va = in_va + (PAGE_SIZE * i);
-        in_frames[i] = virt_to_mfn(va);
-
-        /* update P2M mapping */
-        phys_to_machine_mapping[virt_to_pfn(va)] = INVALID_P2M_ENTRY;
-
-        /* build multi call */
-        call[i].op = __HYPERVISOR_update_va_mapping;
-        call[i].args[arg++] = va;
-        call[i].args[arg++] = 0;
-#ifdef __i386__
-        call[i].args[arg++] = 0;
-#endif  
-        call[i].args[arg++] = UVMF_INVLPG;
-    }
-
-    ret = HYPERVISOR_multicall(call, i);
-    if ( ret )
-    {
-        printk("Odd, update_va_mapping hypercall failed with rc=%d.\n", ret);
-        return 0;
-    }
-
-    /* try getting a contig range of MFNs */
-    out_frames = virt_to_pfn(in_va); /* PFNs to populate */
-    ret = HYPERVISOR_memory_op(XENMEM_exchange, &exchange);
-    if ( ret ) {
-        printk("mem exchanged order=0x%x failed with rc=%d, nr_exchanged=%lu\n",
-               order, ret, exchange.nr_exchanged);
-        /* we still need to return the allocated pages above to the pool
-         * ie. map them back into the 1:1 mapping etc. so we continue but 
-         * in the end return the pages to the page allocator and return 0. */
-        exch_success = 0;
-    }
-    else
-        exch_success = 1;
-
-    /* map frames into 1:1 and update p2m */
-    for ( i = 0; i < num_pages; i++ )
-    {
-        int arg = 0;
-        pte_t pte;
-
-        va = in_va + (PAGE_SIZE * i);
-        mfn = i < exchange.nr_exchanged ? (out_frames + i) : in_frames[i];
-        pte = __pte(mfn << PAGE_SHIFT | L1_PROT);
-
-        /* update P2M mapping */
-        phys_to_machine_mapping[virt_to_pfn(va)] = mfn;
-
-        /* build multi call */
-        call[i].op = __HYPERVISOR_update_va_mapping;
-        call[i].args[arg++] = va;
-#ifdef __x86_64__
-        call[i].args[arg++] = (pgentry_t)pte.pte;
-#else
-        call[i].args[arg++] = pte.pte_low;
-        call[i].args[arg++] = pte.pte_high;
-#endif  
-        call[i].args[arg++] = UVMF_INVLPG;
-    }
-    ret = HYPERVISOR_multicall(call, i);
-    if ( ret )
-    {
-        printk("update_va_mapping hypercall no. 2 failed with rc=%d.\n", ret);
-        return 0;
-    }
-
-    if ( !exch_success )
-    {
-        /* since the exchanged failed we just free the pages as well */
-        free_pages((void *) in_va, order);
-        return 0;
-    }
-    
-    return in_va;
-}
-
-/*
  * Clear some of the bootstrap memory
  */
 static void clear_bootstrap(void)
include/mm.h +0 -1
index f57d8ab..a48f485 100644
@@ -71,7 +71,6 @@ void do_map_frames(unsigned long addr,
         const unsigned long *f, unsigned long n, unsigned long stride,
 	unsigned long increment, domid_t id, int *err, unsigned long prot);
 int unmap_frames(unsigned long va, unsigned long num_frames);
-unsigned long alloc_contig_pages(int order, unsigned int addr_bits);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
Signature · 1 line
2.6.6
Signature · 8 lines
Samuel
<c> ya(ka|ma|to)* ca existe une fois sur 2 au japon, c'est facile ;-)
 -+- #ens-mim au japon -+-

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 3/18
#6 lore raw

Re: [PATCH v2 03/18] mini-os: remove MM_DEBUG code

In reply to Juergen Gross
Quoted 9 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:47 +0200, wrote:

mm.c contains unused code inside #ifdef MM_DEBUG areas. Its usability is rather questionable and some parts are even wrong (e.g. print_chunks() called with nr_pages > 1000 will clobber an arbitrary stack content with a 0 byte).

Remove this code.

Quoted 85 lines
---
 mm.c | 60 ------------------------------------------------------------
 1 file changed, 60 deletions(-)
mm.c +0 -60
index 31aaf83..0dd4862 100644
@@ -42,13 +42,6 @@
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
 
-#ifdef MM_DEBUG
-#define DEBUG(_f, _a...) \
-    printk("MINI_OS(file=mm.c, line=%d) " _f "\n", __LINE__, ## _a)
-#else
-#define DEBUG(_f, _a...)    ((void)0)
-#endif
-
 /*********************
  * ALLOCATION BITMAP
  *  One bit per page of memory. Bit set => page is allocated.
@@ -140,59 +133,6 @@ static chunk_head_t  free_tail[FREELIST_SIZE];
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 
-#ifdef MM_DEBUG
-/*
- * Prints allocation[0/1] for @nr_pages, starting at @start
- * address (virtual).
- */
-USED static void print_allocation(void *start, int nr_pages)
-{
-    unsigned long pfn_start = virt_to_pfn(start);
-    int count;
-    for(count = 0; count < nr_pages; count++)
-        if(allocated_in_map(pfn_start + count)) printk("1");
-        else printk("0");
-        
-    printk("\n");        
-}
-
-/*
- * Prints chunks (making them with letters) for @nr_pages starting
- * at @start (virtual).
- */
-USED static void print_chunks(void *start, int nr_pages)
-{
-    char chunks[1001], current='A';
-    int order, count;
-    chunk_head_t *head;
-    unsigned long pfn_start = virt_to_pfn(start);
-   
-    memset(chunks, (int)'_', 1000);
-    if(nr_pages > 1000) 
-    {
-        DEBUG("Can only pring 1000 pages. Increase buffer size.");
-    }
-    
-    for(order=0; order < FREELIST_SIZE; order++)
-    {
-        head = free_head[order];
-        while(!FREELIST_EMPTY(head))
-        {
-            for(count = 0; count < 1UL<< head->level; count++)
-            {
-                if(count + virt_to_pfn(head) - pfn_start < 1000)
-                    chunks[count + virt_to_pfn(head) - pfn_start] = current;
-            }
-            head = head->next;
-            current++;
-        }
-    }
-    chunks[nr_pages] = '\0';
-    printk("%s\n", chunks);
-}
-#endif
-
-
 /*
  * Initialise allocator, placing addresses [@min,@max] in free pool.
  * @min and @max are PHYSICAL addresses.
Signature · 1 line
2.6.6
Signature · 9 lines
Samuel
Be warned that typing \fBkillall \fIname\fP may not have the desired
effect on non-Linux systems, especially when done by a privileged user.
(From the killall manual page)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 4/18
#8 lore raw

Re: [PATCH v2 04/18] mini-os: add description of x86 memory usage

In reply to Juergen Gross
Quoted 5 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:48 +0200, wrote:

Add a brief description how the physical and virtual address usage looks like on x86 to include/x86/arch_mm.h

Quoted 38 lines
---
 include/x86/arch_mm.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
include/x86/arch_mm.h +20 -0
index 58f29fc..f756dab 100644
@@ -36,6 +36,26 @@
 #endif
 #endif
 
+/*
+ * Physical address space usage:
+ *
+ * 0..._edata: kernel text/data
+ * *stack    : kernel stack (thread 0)
+ * hypervisor allocated data: p2m_list, start_info page, xenstore page,
+ *                            console page, initial page tables
+ * bitmap of allocated pages
+ * pages controlled by the page allocator
+ *
+ *
+ * Virtual address space usage:
+ *
+ * 1:1 mapping of physical memory starting at VA(0)
+ * 1 unallocated page
+ * demand map area (32 bits: 2 GB, 64 bits: 128 GB) for virtual allocations
+ * 1 unallocated page
+ * with libc: heap area (32 bits: 1 GB, 64 bits: 128 GB)
+ */
+
 #define L1_FRAME                1
 #define L2_FRAME                2
 #define L3_FRAME                3
Signature · 1 line
2.6.6
Signature · 9 lines
Samuel
<B> l'alim je sais où elle est, elle est juste à côté de la dame qui dort
<g> B: clairement faut revoir les priorités dans la vie
<g> B: une dame ça se retrouve, un uptime...

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 5/18
#10 lore raw

Re: [PATCH v2 05/18] mini-os: add nr_free_pages counter

In reply to Juergen Gross
Quoted 5 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:49 +0200, wrote:

Add a variable holding the number of available memory pages. This will aid auto-ballooning later.

Quoted 51 lines
---
 include/mm.h | 1 +
 mm.c         | 6 ++++++
 2 files changed, 7 insertions(+)
include/mm.h +1 -0
index a48f485..b97b43e 100644
@@ -42,6 +42,7 @@
 #define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER
 #define STACK_SIZE __STACK_SIZE
 
+extern unsigned long nr_free_pages;
 
 void init_mm(void);
 unsigned long alloc_pages(int order);
mm.c +6 -0
index 0dd4862..263a356 100644
@@ -53,6 +53,8 @@ static unsigned long *alloc_bitmap;
 #define allocated_in_map(_pn) \
 (alloc_bitmap[(_pn)/PAGES_PER_MAPWORD] & (1UL<<((_pn)&(PAGES_PER_MAPWORD-1))))
 
+unsigned long nr_free_pages;
+
 /*
  * Hint regarding bitwise arithmetic in map_{alloc,free}:
  *  -(1<<n)  sets all bits >= n. 
@@ -81,6 +83,8 @@ static void map_alloc(unsigned long first_page, unsigned long nr_pages)
         while ( ++curr_idx < end_idx ) alloc_bitmap[curr_idx] = ~0UL;
         alloc_bitmap[curr_idx] |= (1UL<<end_off)-1;
     }
+
+    nr_free_pages -= nr_pages;
 }
 
 
@@ -93,6 +97,8 @@ static void map_free(unsigned long first_page, unsigned long nr_pages)
     end_idx   = (first_page + nr_pages) / PAGES_PER_MAPWORD;
     end_off   = (first_page + nr_pages) & (PAGES_PER_MAPWORD-1);
 
+    nr_free_pages += nr_pages;
+
     if ( curr_idx == end_idx )
     {
         alloc_bitmap[curr_idx] &= -(1UL<<end_off) | ((1UL<<start_off)-1);
Signature · 1 line
2.6.6
Signature · 8 lines
Samuel
In mutt, type cthis
Dans mutt, taper cceci

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 6/18
#12 lore raw

Re: [PATCH v2 06/18] mini-os: let memory allocation fail if no free page available

In reply to Juergen Gross
Quoted 5 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:50 +0200, wrote:

Instead of panicing when no page can be allocated try to fail the memory allocation by returning NULL instead.

Quoted 27 lines

---
V2: fixed minor style issue

---
 mm.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm.c +7 -0
index 263a356..8cf3210 100644
@@ -335,6 +335,13 @@ void *sbrk(ptrdiff_t increment)
 
     if (new_brk > heap_mapped) {
         unsigned long n = (new_brk - heap_mapped + PAGE_SIZE - 1) / PAGE_SIZE;
+
+        if ( n > nr_free_pages )
+        {
+            printk("Memory exhausted: want %ld pages, but only %ld are left\n",
+                   n, nr_free_pages);
+            return NULL;
+        }
         do_map_zero(heap_mapped, n);
         heap_mapped += n * PAGE_SIZE;
     }
Signature · 1 line
2.6.6
Signature · 7 lines
Samuel
War doesn't prove who's right, just who's left.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 7/18
#14 lore raw

Re: [PATCH v2 07/18] mini-os: add ballooning config item

In reply to Juergen Gross
Quoted 5 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:51 +0200, wrote:

Add CONFIG_BALLOON defaulting to 'n' as a config item to Mini-OS.

Add balloon.c, balloon.h and arch/*/balloon.c for future use.

Not much to be against here :)

Quoted 181 lines

---
V2: Added dummy sources and header

---
 Makefile           |  3 +++
 arch/arm/balloon.c | 28 ++++++++++++++++++++++++++++
 arch/x86/balloon.c | 28 ++++++++++++++++++++++++++++
 balloon.c          | 24 ++++++++++++++++++++++++
 include/balloon.h  | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 115 insertions(+)
 create mode 100644 arch/arm/balloon.c
 create mode 100644 arch/x86/balloon.c
 create mode 100644 balloon.c
 create mode 100644 include/balloon.h
Makefile +3 -0
index 2e4bdba..f5b7011 100644
@@ -33,6 +33,7 @@ CONFIG_CONSFRONT ?= y
 CONFIG_XENBUS ?= y
 CONFIG_XC ?=y
 CONFIG_LWIP ?= $(lwip)
+CONFIG_BALLOON ?= n
 
 # Export config items as compiler directives
 flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
@@ -48,6 +49,7 @@ flags-$(CONFIG_KBDFRONT) += -DCONFIG_KBDFRONT
 flags-$(CONFIG_FBFRONT) += -DCONFIG_FBFRONT
 flags-$(CONFIG_CONSFRONT) += -DCONFIG_CONSFRONT
 flags-$(CONFIG_XENBUS) += -DCONFIG_XENBUS
+flags-$(CONFIG_BALLOON) += -DCONFIG_BALLOON
 
 DEF_CFLAGS += $(flags-y)
 
@@ -96,6 +98,7 @@ src-$(CONFIG_NETFRONT) += netfront.c
 src-$(CONFIG_PCIFRONT) += pcifront.c
 src-y += sched.c
 src-$(CONFIG_TEST) += test.c
+src-$(CONFIG_BALLOON) += balloon.c
 
 src-y += lib/ctype.c
 src-y += lib/math.c
arch/arm/balloon.c new file +28 -0
new file mode 100644
index 0000000..dc6270d
@@ -0,0 +1,28 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <mini-os/balloon.h>
+
+#ifdef CONFIG_BALLOON
+
+#endif
arch/x86/balloon.c new file +28 -0
new file mode 100644
index 0000000..dc6270d
@@ -0,0 +1,28 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <mini-os/balloon.h>
+
+#ifdef CONFIG_BALLOON
+
+#endif
balloon.c new file +24 -0
new file mode 100644
index 0000000..9cabde0
@@ -0,0 +1,24 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <mini-os/balloon.h>
include/balloon.h new file +32 -0
new file mode 100644
index 0000000..399fff4
@@ -0,0 +1,32 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _BALLOON_H_
+#define _BALLOON_H_
+
+#ifdef CONFIG_BALLOON
+
+#else /* CONFIG_BALLOON */
+
+#endif /* CONFIG_BALLOON */
+#endif /* _BALLOON_H_ */
Signature · 1 line
2.6.6
Signature · 10 lines
Samuel
 FYLG> Tiens, vlà une URL qui va bien :
 FYLG> ftp://127.0.0.1/WaReZ/NiouZeS/WinDoZe/NeWSMoNGeR/SuPeR
 c'est gentil sauf que l'adresse ne fonctionne pas sa me fais une erreur
 -+- Furtif in Guide du Neuneu Usenet : <MODE CERVEAU OFF> -+-

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 8/18
#16 lore raw

Re: [PATCH v2 08/18] mini-os: get maximum memory size from hypervisor

In reply to Juergen Gross
Quoted 4 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:52 +0200, wrote:

Add support for obtaining the maximum memory size from the hypervisor. This will make it possible to support ballooning.

mm.c void *sbrk(ptrdiff_t increment) · line 359

Quoted 12 lines
mm.c +0 -1
index 8cf3210..25ee3da 100644
@@ -353,7 +354,6 @@ void *sbrk(ptrdiff_t increment)
 #endif
 
 
-
 void init_mm(void)
 {
 

That one could be dropped from the patch :)

Samuel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v2 9/18
#18 lore raw

Re: [PATCH v2 09/18] mini-os: modify virtual memory layout for support of ballooning

In reply to Juergen Gross
Quoted 22 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:53 +0200, wrote:

In order to be able to support ballooning the virtual memory layout of Mini-OS has to be modified: instead of a (nearly) consecutive area used for physical memory mapping, on demand mappings, and heap we need enough spare place for adding new memory.

So instead of dynamically place the different regions based on found memory size locate them statically at fixed virtual addresses:

area x86-64 x86-32
------------------------------------------------------------

mapped physical memory       00000000             00000000
kernel virtual mappings    8000000000             3f000000
demand mappings          100000000000             40000000
heap                     200000000000             b0000000

This will enable Mini-OS to support up to 512GB of domain memory with a 64 bit kernel and nearly 1GB with a 32 bit kernel.

For a 32 bit Mini-OS we have to avoid a conflict between heap and m2p table which the hypervisor maps at f5600000. So the demand mapping size is reduced by 256MB in order to keep the heap at about 1GB.

Quoted 7 lines

The kernel virtual mappings are a new area needed for being able to grow the p2m list without having to relocate it in physical memory.

Modify the placement of the demand mappings and heap and adjust the memory layout description.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v2 10/18
#20 lore raw

Re: [PATCH v2 10/18] mini-os: remove unused mem_test() function

In reply to Juergen Gross
Quoted 4 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:54 +0200, wrote:

mem_test() isn't used anywhere and its value is rather questionable with mini-os being in a mature state. Remove the function.

Quoted 73 lines
---
 arch/x86/mm.c | 55 -------------------------------------------------------
 1 file changed, 55 deletions(-)
arch/x86/mm.c +0 -55
index 6aa4468..e2f026b 100644
@@ -302,61 +302,6 @@ static void set_readonly(void *text, void *etext)
 }
 
 /*
- * A useful mem testing function. Write the address to every address in the
- * range provided and read back the value. If verbose, print page walk to
- * some VA
- * 
- * If we get MEM_TEST_MAX_ERRORS we might as well stop
- */
-#define MEM_TEST_MAX_ERRORS 10 
-int mem_test(unsigned long *start_va, unsigned long *end_va, int verbose)
-{
-    unsigned long mask = 0x10000;
-    unsigned long *pointer;
-    int error_count = 0;
- 
-    /* write values and print page walks */
-    if ( verbose && (((unsigned long)start_va) & 0xfffff) )
-    {
-        printk("MemTest Start: 0x%p\n", start_va);
-        page_walk((unsigned long)start_va);
-    }
-    for ( pointer = start_va; pointer < end_va; pointer++ )
-    {
-        if ( verbose && !(((unsigned long)pointer) & 0xfffff) )
-        {
-            printk("Writing to %p\n", pointer);
-            page_walk((unsigned long)pointer);
-        }
-        *pointer = (unsigned long)pointer & ~mask;
-    }
-    if ( verbose && (((unsigned long)end_va) & 0xfffff) )
-    {
-        printk("MemTest End: %p\n", end_va-1);
-        page_walk((unsigned long)end_va-1);
-    }
- 
-    /* verify values */
-    for ( pointer = start_va; pointer < end_va; pointer++ )
-    {
-        if ( ((unsigned long)pointer & ~mask) != *pointer )
-        {
-            printk("Read error at 0x%lx. Read: 0x%lx, should read 0x%lx\n",
-                   (unsigned long)pointer, *pointer, 
-                   ((unsigned long)pointer & ~mask));
-            error_count++;
-            if ( error_count >= MEM_TEST_MAX_ERRORS )
-            {
-                printk("mem_test: too many errors\n");
-                return -1;
-            }
-        }
-    }
-    return 0;
-}
-
-
-/*
  * get the PTE for virtual address va if it exists. Otherwise NULL.
  */
 static pgentry_t *get_pgt(unsigned long va)
Signature · 1 line
2.6.6
Signature · 8 lines
Samuel
In mutt, type cthis
Dans mutt, taper cceci

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 11/18
#22 lore raw

Re: [PATCH v2 11/18] mini-os: add checks for out of memory

In reply to Juergen Gross
Quoted 7 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:55 +0200, wrote:

There are several core functions in Mini-OS not checking for failed memory allocations. Add such checks.

Add do_map_frames() dummy function to arm architecture as it will be needed in future for compilations to succeed.

Quoted 141 lines
---
 arch/arm/mm.c |  8 ++++++++
 arch/x86/mm.c | 26 +++++++++++++++++++-------
 include/mm.h  |  2 +-
 3 files changed, 28 insertions(+), 8 deletions(-)
arch/arm/mm.c +8 -0
index f75888d..fc8d4bc 100644
@@ -1,6 +1,7 @@
 #include <mini-os/console.h>
 #include <xen/memory.h>
 #include <arch_mm.h>
+#include <mini-os/errno.h>
 #include <mini-os/hypervisor.h>
 #include <libfdt.h>
 #include <lib.h>
@@ -79,6 +80,13 @@ void arch_init_demand_mapping_area(void)
 {
 }
 
+int do_map_frames(unsigned long addr,
+        const unsigned long *f, unsigned long n, unsigned long stride,
+        unsigned long increment, domid_t id, int *err, unsigned long prot)
+{
+    return -ENOSYS;
+}
+
 /* Get Xen's suggested physical page assignments for the grant table. */
 static paddr_t get_gnttab_base(void)
 {
arch/x86/mm.c +19 -7
index e2f026b..12f7fe4 100644
@@ -34,6 +34,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <mini-os/errno.h>
 #include <mini-os/os.h>
 #include <mini-os/hypervisor.h>
 #include <mini-os/mm.h>
@@ -354,6 +355,8 @@ pgentry_t *need_pgt(unsigned long va)
     if ( !(tab[offset] & _PAGE_PRESENT) )
     {
         pt_pfn = virt_to_pfn(alloc_page());
+        if ( !pt_pfn )
+            return NULL;
         new_pt_frame(&pt_pfn, pt_mfn, offset, L3_FRAME);
     }
     ASSERT(tab[offset] & _PAGE_PRESENT);
@@ -364,6 +367,8 @@ pgentry_t *need_pgt(unsigned long va)
     if ( !(tab[offset] & _PAGE_PRESENT) ) 
     {
         pt_pfn = virt_to_pfn(alloc_page());
+        if ( !pt_pfn )
+            return NULL;
         new_pt_frame(&pt_pfn, pt_mfn, offset, L2_FRAME);
     }
     ASSERT(tab[offset] & _PAGE_PRESENT);
@@ -373,6 +378,8 @@ pgentry_t *need_pgt(unsigned long va)
     if ( !(tab[offset] & _PAGE_PRESENT) )
     {
         pt_pfn = virt_to_pfn(alloc_page());
+        if ( !pt_pfn )
+            return NULL;
         new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME);
     }
     ASSERT(tab[offset] & _PAGE_PRESENT);
@@ -445,10 +452,10 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
  * va. map f[i*stride]+i*increment for i in 0..n-1.
  */
 #define MAP_BATCH ((STACK_SIZE / 2) / sizeof(mmu_update_t))
-void do_map_frames(unsigned long va,
-                   const unsigned long *mfns, unsigned long n, 
-                   unsigned long stride, unsigned long incr, 
-                   domid_t id, int *err, unsigned long prot)
+int do_map_frames(unsigned long va,
+                  const unsigned long *mfns, unsigned long n,
+                  unsigned long stride, unsigned long incr,
+                  domid_t id, int *err, unsigned long prot)
 {
     pgentry_t *pgt = NULL;
     unsigned long done = 0;
@@ -458,7 +465,7 @@ void do_map_frames(unsigned long va,
     if ( !mfns ) 
     {
         printk("do_map_frames: no mfns supplied\n");
-        return;
+        return -EINVAL;
     }
     DEBUG("va=%p n=0x%lx, mfns[0]=0x%lx stride=0x%lx incr=0x%lx prot=0x%lx\n",
           va, n, mfns[0], stride, incr, prot);
@@ -484,7 +491,9 @@ void do_map_frames(unsigned long va,
             {
                 if ( !pgt || !(va & L1_MASK) )
                     pgt = need_pgt(va);
-                
+                if ( !pgt )
+                    return -ENOMEM;
+
                 mmu_updates[i].ptr = virt_to_mach(pgt) | MMU_NORMAL_PT_UPDATE;
                 mmu_updates[i].val = ((pgentry_t)(mfns[(done + i) * stride] +
                                                   (done + i) * incr)
@@ -505,6 +514,8 @@ void do_map_frames(unsigned long va,
         }
         done += todo;
     }
+
+    return 0;
 }
 
 /*
@@ -521,7 +532,8 @@ void *map_frames_ex(const unsigned long *mfns, unsigned long n,
     if ( !va )
         return NULL;
 
-    do_map_frames(va, mfns, n, stride, incr, id, err, prot);
+    if ( do_map_frames(va, mfns, n, stride, incr, id, err, prot) )
+        return NULL;
 
     return (void *)va;
 }
include/mm.h +1 -1
index a22dcd1..9244e26 100644
@@ -68,7 +68,7 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
 void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride,
 	unsigned long increment, unsigned long alignment, domid_t id,
 	int *err, unsigned long prot);
-void do_map_frames(unsigned long addr,
+int do_map_frames(unsigned long addr,
         const unsigned long *f, unsigned long n, unsigned long stride,
 	unsigned long increment, domid_t id, int *err, unsigned long prot);
 int unmap_frames(unsigned long va, unsigned long num_frames);
Signature · 1 line
2.6.6
Signature · 9 lines
Samuel
"How should I know if it works?  That's what beta testers are for.  I only
coded it."
(Attributed to Linus Torvalds, somewhere in a posting)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 12/18
#24 lore raw

Re: [PATCH v2 12/18] mini-os: don't allocate new pages for level 1 p2m tree

In reply to Juergen Gross
Quoted 6 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:56 +0200, wrote:

When constructing the 3 level p2m tree there is no need to allocate new pages for the level 1 containing the p2m info for all pages. The pages from the linear p2m list constructed by the hypervisor can be used for that purpose.

Quoted 42 lines
---
 arch/x86/mm.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
arch/x86/mm.c +4 -10
index 12f7fe4..e10c2c5 100644
@@ -625,11 +625,11 @@ void arch_init_p2m(unsigned long max_pfn)
 #define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
 #define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
 
-    unsigned long *l1_list = NULL, *l2_list = NULL, *l3_list;
+    unsigned long *l2_list = NULL, *l3_list;
     unsigned long pfn;
 
     l3_list = (unsigned long *)alloc_page(); 
-    for ( pfn=0; pfn<max_pfn; pfn++ )
+    for ( pfn = 0; pfn < max_pfn; pfn += L1_P2M_ENTRIES )
     {
         if ( !(pfn % (L1_P2M_ENTRIES * L2_P2M_ENTRIES)) )
         {
@@ -641,14 +641,8 @@ void arch_init_p2m(unsigned long max_pfn)
             }
             l3_list[(pfn >> L2_P2M_SHIFT)] = virt_to_mfn(l2_list);  
         }
-        if ( !(pfn % (L1_P2M_ENTRIES)) )
-        {
-            l1_list = (unsigned long*)alloc_page();
-            l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] = 
-                virt_to_mfn(l1_list); 
-        }
-
-        l1_list[pfn & L1_P2M_MASK] = pfn_to_mfn(pfn); 
+        l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] =
+            virt_to_mfn(phys_to_machine_mapping + pfn);
     }
     HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 
         virt_to_mfn(l3_list);
Signature · 1 line
2.6.6
Signature · 1 line
Samuel
Quoted 1 line

Ever heard of .cshrc?

That's a city in Bosnia. Right?
(Discussion in comp.os.linux.misc on the intuitiveness of commands.)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v2 13/18
#26 lore raw

Re: [PATCH v2 13/18] mini-os: add function to map one frame

In reply to Juergen Gross
Quoted 4 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:57 +0200, wrote:

Add a function to map one physical frame to a specified virtual address as read/write. This will be used later multiple times.

Quoted 50 lines
---
 include/arm/arch_mm.h | 2 ++
 include/mm.h          | 1 +
 mm.c                  | 5 +++++
 3 files changed, 8 insertions(+)
include/arm/arch_mm.h +2 -0
index 085d4e5..f4685d8 100644
@@ -14,6 +14,8 @@ extern uint32_t physical_address_offset;	/* Add this to a virtual address to get
 
 #define L1_PAGETABLE_SHIFT      12
 
+#define L1_PROT          0
+
 #define to_phys(x)                 (((paddr_t)(x)+physical_address_offset) & 0xffffffff)
 #define to_virt(x)                 ((void *)(((x)-physical_address_offset) & 0xffffffff))
 
include/mm.h +1 -0
index 9244e26..6add683 100644
@@ -72,6 +72,7 @@ int do_map_frames(unsigned long addr,
         const unsigned long *f, unsigned long n, unsigned long stride,
 	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);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
mm.c +5 -0
index ff071ca..fd66115 100644
@@ -319,6 +319,11 @@ int free_physical_pages(xen_pfn_t *mfns, int n)
     return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
 }
 
+int map_frame_rw(unsigned long addr, unsigned long mfn)
+{
+    return do_map_frames(addr, &mfn, 1, 1, 1, DOMID_SELF, NULL, L1_PROT);
+}
+
 #ifdef HAVE_LIBC
 void *sbrk(ptrdiff_t increment)
 {
Signature · 1 line
2.6.6
Signature · 8 lines
Samuel
<c> xlnt comme sujet de stage je peux essayer de donner une description formelle de automake
 -+- #ens-mim -+-

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 14/18
#28 lore raw

Re: [PATCH v2 14/18] mini-os: move p2m related macros to header file

In reply to Juergen Gross
Quoted 8 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:58 +0200, wrote:

In order to be able to use p2m related macros for ballooning move their definitions to arch/x86/mm.h.

There is no need to define different macros regarding index masks and number of entries for the different levels, as all levels share the same entry format (a plain mfn). So reduce the number of macros accordingly.

Quoted 4 lines

Add some macros to get the indices into p2m pages from a pfn and make use of them in current p2m code.

Quoted 91 lines
---
 arch/x86/mm.c         | 31 +++++--------------------------
 include/x86/arch_mm.h | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 26 deletions(-)
arch/x86/mm.c +5 -26
index e10c2c5..a5c8959 100644
@@ -609,40 +609,19 @@ static void clear_bootstrap(void)
 
 void arch_init_p2m(unsigned long max_pfn)
 {
-#ifdef __x86_64__
-#define L1_P2M_SHIFT    9
-#define L2_P2M_SHIFT    18    
-#define L3_P2M_SHIFT    27    
-#else
-#define L1_P2M_SHIFT    10
-#define L2_P2M_SHIFT    20    
-#define L3_P2M_SHIFT    30    
-#endif
-#define L1_P2M_ENTRIES  (1 << L1_P2M_SHIFT)    
-#define L2_P2M_ENTRIES  (1 << (L2_P2M_SHIFT - L1_P2M_SHIFT))    
-#define L3_P2M_ENTRIES  (1 << (L3_P2M_SHIFT - L2_P2M_SHIFT))    
-#define L1_P2M_MASK     (L1_P2M_ENTRIES - 1)    
-#define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
-#define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
-    
     unsigned long *l2_list = NULL, *l3_list;
     unsigned long pfn;
 
+    p2m_chk_pfn(max_pfn - 1);
     l3_list = (unsigned long *)alloc_page(); 
-    for ( pfn = 0; pfn < max_pfn; pfn += L1_P2M_ENTRIES )
+    for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
     {
-        if ( !(pfn % (L1_P2M_ENTRIES * L2_P2M_ENTRIES)) )
+        if ( !(pfn % (P2M_ENTRIES * P2M_ENTRIES)) )
         {
             l2_list = (unsigned long*)alloc_page();
-            if ( (pfn >> L3_P2M_SHIFT) > 0 )
-            {
-                printk("Error: Too many pfns.\n");
-                do_exit();
-            }
-            l3_list[(pfn >> L2_P2M_SHIFT)] = virt_to_mfn(l2_list);  
+            l3_list[L3_P2M_IDX(pfn)] = virt_to_mfn(l2_list);
         }
-        l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] =
-            virt_to_mfn(phys_to_machine_mapping + pfn);
+        l2_list[L2_P2M_IDX(pfn)] = virt_to_mfn(phys_to_machine_mapping + pfn);
     }
     HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 
         virt_to_mfn(l3_list);
include/x86/arch_mm.h +21 -0
index d87fe55..7283f64 100644
@@ -176,7 +176,28 @@ typedef unsigned long pgentry_t;
 #define IO_PROT_NOCACHE (L1_PROT | _PAGE_PCD)
 
 /* for P2M */
+#ifdef __x86_64__
+#define P2M_SHIFT       9
+#else
+#define P2M_SHIFT       10
+#endif
+#define P2M_ENTRIES     (1UL << P2M_SHIFT)
+#define P2M_MASK        (P2M_ENTRIES - 1)
+#define L1_P2M_SHIFT    P2M_SHIFT
+#define L2_P2M_SHIFT    (2 * P2M_SHIFT)
+#define L3_P2M_SHIFT    (3 * P2M_SHIFT)
+#define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK)
+#define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK)
+#define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
 #define INVALID_P2M_ENTRY (~0UL)
+static inline void p2m_chk_pfn(unsigned long pfn)
+{
+    if ( (pfn >> L3_P2M_SHIFT) > 0 )
+    {
+        printk("Error: Too many pfns.\n");
+        do_exit();
+    }
+}
 
 #include "arch_limits.h"
 #define PAGE_SIZE       __PAGE_SIZE
Signature · 1 line
2.6.6
Signature · 7 lines
Samuel
"2 + 2 = 5 pour d'assez grandes valeurs de 2"

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 15/18
#30 lore raw

Re: [PATCH v2 15/18] mini-os: remap p2m list in case of ballooning

In reply to Juergen Gross
Quoted 6 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:59 +0200, wrote:

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.

Quoted 115 lines
---
 arch/arm/balloon.c    |  2 ++
 arch/x86/balloon.c    | 24 ++++++++++++++++++++++++
 arch/x86/mm.c         |  3 +++
 include/balloon.h     |  3 +++
 include/x86/arch_mm.h |  4 ++++
 5 files changed, 36 insertions(+)
arch/arm/balloon.c +2 -0
index dc6270d..a76db3b 100644
@@ -25,4 +25,6 @@
 
 #ifdef CONFIG_BALLOON
 
+unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
+
 #endif
arch/x86/balloon.c +24 -0
index dc6270d..db37e8f 100644
@@ -21,8 +21,32 @@
  * 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);
+}
+
 #endif
arch/x86/mm.c +3 -0
index a5c8959..8fa3b4c 100644
@@ -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)
include/balloon.h +3 -0
index e7219f8..b8d9335 100644
@@ -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_ */
include/x86/arch_mm.h +4 -0
index 7283f64..e5d9c57 100644
@@ -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
Signature · 1 line
2.6.6
Signature · 9 lines
Samuel
<r> make
<r> oops
<m> make clean

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#31 lore raw

Re: [PATCH v2 15/18] mini-os: remap p2m list in case of ballooning

In reply to Juergen Gross
Quoted 2 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:59 +0200, wrote:
(quoted diff) +2 -0
+void arch_remap_p2m(unsigned long max_pfn)
+{

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+    virt_kernel_area_end += PAGE_SIZE * p2m_pages(nr_max_pages);

I'd however rather see an assertion against hitting VIRT_DEMAND_AREA here, even if the figures happen to make it impossible, better catch it in case somebody else changes figures.

Quoted 1 line

+}

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#34 lore raw

Re: [PATCH v2 16/18] mini-os: map page allocator's bitmap to virtual kernel area for ballooning

In reply to Juergen Gross

It looks a bit odd to be remapping something that was just allocated, but I guess it makes portability easier.

Quoted 14 lines · Juergen Gross, on Fri 05 Aug 2016 19:36:00 +0200, wrote:
balloon.c +6 -0
index 4c18c5c..75b87c8 100644
@@ -44,3 +44,20 @@ void get_max_pages(void)
     nr_max_pages = ret;
     printk("Maximum memory size: %ld pages\n", nr_max_pages);
 }
+
+void alloc_bitmap_remap(void)
+{
+    unsigned long i;
+
+    if ( alloc_bitmap_size >= ((nr_max_pages + 1) >> (PAGE_SHIFT + 3)) )

balloon.c void get_max_pages(void) · line 62

Quoted 10 lines
balloon.c +10 -0
+        return;
+
+    for ( i = 0; i < alloc_bitmap_size; i += PAGE_SIZE )
+    {
+        map_frame_rw(virt_kernel_area_end + i,
+                     virt_to_mfn((unsigned long)(alloc_bitmap) + i));
+    }
+
+    alloc_bitmap = (unsigned long *)virt_kernel_area_end;
+    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> (PAGE_SHIFT + 3));

Ditto here, better check against hitting VIRT_DEMAND_AREA.

Quoted 5 lines
include/balloon.h +0 -0
index b8d9335..0e2340b 100644

include/balloon.h extern unsigned long virt_kernel_area_end; · line 40

Quoted 10 lines
include/balloon.h +2 -0
@@ -31,11 +31,13 @@ extern unsigned long virt_kernel_area_end;
 
 void get_max_pages(void);
 void arch_remap_p2m(unsigned long max_pfn);
+void alloc_bitmap_remap(void);
 
 #else /* CONFIG_BALLOON */
 
 static inline void get_max_pages(void) { }
 static inline void arch_remap_p2m(unsigned long max_pfn) { }
+static inline void alloc_bitmap_remap(void) { }

I'd say call it rather mm_alloc_bitmap_remap(). We have C namespace issues with the stubdom applications, and the alloc_bitmap_ prefix seems quite generic (even if less that bitmap_), mm_ adds some kernelish notion.

include/balloon.h extern unsigned long virt_kernel_area_end;

Quoted 4 lines
include/balloon.h +2 -0
 extern unsigned long nr_free_pages;
 
+extern unsigned long *alloc_bitmap;
+extern unsigned long alloc_bitmap_size;

Ditto, mm_bitmap and mm_bitmap_size.

Otherwise it looks good.

Samuel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v2 17/18
#37 lore raw

Re: [PATCH v2 17/18] mini-os: add support for ballooning up

In reply to Juergen Gross
Quoted 10 lines · Juergen Gross, on Fri 05 Aug 2016 19:36:01 +0200, wrote:
balloon.c +10 -0
+#define N_BALLOON_FRAMES 64
+static unsigned long balloon_frames[N_BALLOON_FRAMES];
+
+int balloon_up(unsigned long n_pages)
+{
+    unsigned long page, pfn;
+    int rc;
+    struct xen_memory_reservation reservation = {
+        .address_bits = 0,
+        .extent_order = 0,

balloon.c void alloc_bitmap_remap(void) · line 86

Quoted 10 lines
balloon.c +10 -0
+        .domid        = DOMID_SELF
+    };
+
+    if ( n_pages > nr_max_pages - nr_mem_pages )
+        n_pages = nr_max_pages - nr_mem_pages;
+    if ( n_pages > N_BALLOON_FRAMES )
+        n_pages = N_BALLOON_FRAMES;
+
+    /* Resize alloc_bitmap if necessary. */
+    if ( alloc_bitmap_size * 8 < nr_mem_pages + n_pages )

To be on the safe side, I'd say use a while here, even if the value of N_BALLOON_FRAMES is so that there'll always be one iteration ATM.

Otherwise it looks good,

Samuel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v2 18/18
#40 lore raw

Re: [PATCH v2 18/18] mini-os: balloon up in case of oom

In reply to Juergen Gross

include/balloon.h void arch_remap_p2m(unsigned long max_pfn); · line 56

Quoted 4 lines · Juergen Gross, on Fri 05 Aug 2016 19:36:02 +0200, wrote:
include/balloon.h +4 -0
+static inline int chk_free_pages(unsigned long needed)
+{
+    return needed > nr_free_pages;
+}

The logic looks reversed to me:

mm.c unsigned long alloc_pages(int order) · line 213

Quoted 2 lines
mm.c +2 -0
+    if ( chk_free_pages(1UL << order) )
+        goto no_memory;

I would have written it

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( !chk_free_pages(1UL << order) )
+        goto no_memory;

"If there are not enough free pages for this amount, go out".

Otherwise it looks good,

Samuel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#32 lore raw

Re: [PATCH v2 15/18] mini-os: remap p2m list in case of ballooning

In reply to Samuel Thibault
Quoted 10 lines · Samuel Thibault
Quoted 2 lines · Juergen Gross, on Fri 05 Aug 2016 19:35:59 +0200, wrote:
(quoted diff) +2 -0
+void arch_remap_p2m(unsigned long max_pfn)
+{

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+    virt_kernel_area_end += PAGE_SIZE * p2m_pages(nr_max_pages);

I'd however rather see an assertion against hitting VIRT_DEMAND_AREA here, even if the figures happen to make it impossible, better catch it in case somebody else changes figures.

Okay.

Thanks,

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#35 lore raw

Re: [PATCH v2 16/18] mini-os: map page allocator's bitmap to virtual kernel area for ballooning

In reply to Samuel Thibault
Quoted 2 lines · Samuel Thibault

It looks a bit odd to be remapping something that was just allocated, but I guess it makes portability easier.

Remapping needs the page allocator to be active as page tables need to be allocated. :-)

Quoted 20 lines
Quoted 18 lines · Juergen Gross, on Fri 05 Aug 2016 19:36:00 +0200, wrote:
balloon.c +10 -0
index 4c18c5c..75b87c8 100644
@@ -44,3 +44,20 @@ void get_max_pages(void)
     nr_max_pages = ret;
     printk("Maximum memory size: %ld pages\n", nr_max_pages);
 }
+
+void alloc_bitmap_remap(void)
+{
+    unsigned long i;
+
+    if ( alloc_bitmap_size >= ((nr_max_pages + 1) >> (PAGE_SHIFT + 3)) )
+        return;
+
+    for ( i = 0; i < alloc_bitmap_size; i += PAGE_SIZE )
+    {
Quoted 8 lines

balloon.c void get_max_pages(void) · line 62

Quoted 6 lines
balloon.c +6 -0
+        map_frame_rw(virt_kernel_area_end + i,
+                     virt_to_mfn((unsigned long)(alloc_bitmap) + i));
+    }
+
+    alloc_bitmap = (unsigned long *)virt_kernel_area_end;
+    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> (PAGE_SHIFT + 3));

Ditto here, better check against hitting VIRT_DEMAND_AREA.

Okay.

Quoted 13 lines
Quoted 13 lines
include/balloon.h +1 -0
index b8d9335..0e2340b 100644
@@ -31,11 +31,13 @@ extern unsigned long virt_kernel_area_end;
 
 void get_max_pages(void);
 void arch_remap_p2m(unsigned long max_pfn);
+void alloc_bitmap_remap(void);
 
 #else /* CONFIG_BALLOON */
 
Quoted 8 lines

include/balloon.h extern unsigned long virt_kernel_area_end; · line 40

Quoted 3 lines
include/balloon.h +1 -0
 static inline void get_max_pages(void) { }
 static inline void arch_remap_p2m(unsigned long max_pfn) { }
+static inline void alloc_bitmap_remap(void) { }

I'd say call it rather mm_alloc_bitmap_remap(). We have C namespace issues with the stubdom applications, and the alloc_bitmap_ prefix seems quite generic (even if less that bitmap_), mm_ adds some kernelish notion.

Okay.

Quoted 7 lines

include/balloon.h extern unsigned long virt_kernel_area_end;

Quoted 5 lines
include/balloon.h +2 -0
 extern unsigned long nr_free_pages;
 
+extern unsigned long *alloc_bitmap;
+extern unsigned long alloc_bitmap_size;

Ditto, mm_bitmap and mm_bitmap_size.

Okay.

Quoted 2 lines

Otherwise it looks good.

Thanks,

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#38 lore raw

Re: [PATCH v2 17/18] mini-os: add support for ballooning up

In reply to Samuel Thibault
Quoted 16 lines · Samuel Thibault
Quoted 15 lines · Juergen Gross, on Fri 05 Aug 2016 19:36:01 +0200, wrote:
balloon.c +15 -0
+#define N_BALLOON_FRAMES 64
+static unsigned long balloon_frames[N_BALLOON_FRAMES];
+
+int balloon_up(unsigned long n_pages)
+{
+    unsigned long page, pfn;
+    int rc;
+    struct xen_memory_reservation reservation = {
+        .address_bits = 0,
+        .extent_order = 0,
+        .domid        = DOMID_SELF
+    };
+
+    if ( n_pages > nr_max_pages - nr_mem_pages )
+        n_pages = nr_max_pages - nr_mem_pages;
Quoted 8 lines

balloon.c void alloc_bitmap_remap(void) · line 86

Quoted 5 lines
balloon.c +5 -0
+    if ( n_pages > N_BALLOON_FRAMES )
+        n_pages = N_BALLOON_FRAMES;
+
+    /* Resize alloc_bitmap if necessary. */
+    if ( alloc_bitmap_size * 8 < nr_mem_pages + n_pages )

To be on the safe side, I'd say use a while here, even if the value of N_BALLOON_FRAMES is so that there'll always be one iteration ATM.

I don't mind changing it, while it seems rather unlikely that the maximum number of frames added in one chunk would ever exceed 32768.

Quoted 4 lines

Otherwise it looks good,

Thanks,

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#41 lore raw

Re: [PATCH v2 18/18] mini-os: balloon up in case of oom

In reply to Samuel Thibault
Quoted 11 lines · Samuel Thibault

include/balloon.h void arch_remap_p2m(unsigned long max_pfn); · line 56

Quoted 4 lines · Juergen Gross, on Fri 05 Aug 2016 19:36:02 +0200, wrote:
include/balloon.h +4 -0
+static inline int chk_free_pages(unsigned long needed)
+{
+    return needed > nr_free_pages;
+}

The logic looks reversed to me:

mm.c unsigned long alloc_pages(int order) · line 213

Quoted 2 lines
mm.c +2 -0
+    if ( chk_free_pages(1UL << order) )
+        goto no_memory;
Quoted 6 lines

I would have written it

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( !chk_free_pages(1UL << order) )
+        goto no_memory;

"If there are not enough free pages for this amount, go out".

Hmm, yes, I can see your point.

I'll change it.

Quoted 4 lines

Otherwise it looks good,

Thanks,

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel