Fix vmalloc iterating on address hint page-alloc-and-vga
authorJack Miller <jack@codezen.org>
Sat, 19 Mar 2016 03:54:41 +0000 (22:54 -0500)
committerJack Miller <jack@codezen.org>
Sat, 19 Mar 2016 19:02:48 +0000 (14:02 -0500)
mm/vmalloc.c

index b2d89e7..3dc3ff2 100644 (file)
@@ -8,7 +8,7 @@
 #include <types.h>
 #include <errno.h>
 
-#undef TEST_VMALLOC
+#define TEST_VMALLOC
 
 /* NOTE: The names are included here, but as we have no string functions, or
  * even display capability, these are unused for the moment */
@@ -173,6 +173,34 @@ int __free_vspace(struct virtual_block **head, u64 virtual, u64 size)
        return 0;
 }
 
+void *vmalloc(char *name, u64 address_hint, u64 size)
+{
+       struct virtual_block *cur;
+       u64 prev_end, end;
+
+       prev_end = 0;
+       for(cur = kernel_virtual_space; cur; cur = cur->next) {
+               end = cur->address + cur->size;
+               if ((cur->address >= address_hint)) {
+                       if ((cur->address != address_hint) && size <= (cur->address - prev_end)) {
+                               __alloc_vspace(&kernel_virtual_space, name, address_hint, size);
+                               return (void *) address_hint;
+                       } else
+                               address_hint = end;
+               }
+
+               prev_end = end;
+       }
+
+       if ((MAX_VIRT_ADDRESS - prev_end) >= size) {
+               __alloc_vspace(&kernel_virtual_space, name, address_hint, size);
+               return (void *) prev_end;
+       }
+
+       return NULL;
+}
+
+
 #ifdef TEST_VMALLOC
 
 struct virtual_block *test_virtual_space = NULL;
@@ -271,35 +299,23 @@ void test_alloc_vspace(void)
 
        /* Reset */
        used_vblocks = 0;
+       test_virtual_space = NULL;
 }
-#endif
 
-void *vmalloc(char *name, u64 address_hint, u64 size)
+void test_vmalloc(void)
 {
-       struct virtual_block *cur;
-       u64 prev_end, end;
+       u64 *test = vmalloc("test", VMALLOC_HEAP_VIRTUAL, 0);
+       u64 *test2 = vmalloc("test", VMALLOC_HEAP_VIRTUAL, 0);
 
-       prev_end = 0;
-       for(cur = kernel_virtual_space; cur; prev_end = end, cur = cur->next) {
-               end = cur->address + cur->size;
-               if (cur->address > address_hint) {
-                       if (size <= (cur->address - prev_end)) {
-                               __alloc_vspace(&kernel_virtual_space, name, address_hint, size);
-                               return (void *) address_hint;
-                       }
-                       else
-                               address_hint = end;
-               }
-       }
-
-       if ((MAX_VIRT_ADDRESS - prev_end) >= size) {
-               __alloc_vspace(&kernel_virtual_space, name, prev_end, size);
-               return (void *) prev_end;
-       }
+       if (test == test2)
+               while(1) {}
 
-       return NULL;
+       used_vblocks = 0;
+       kernel_virtual_space = NULL;
 }
 
+#endif
+
 void vmalloc_vspace(char *name, u64 address, u64 size)
 {
        __alloc_vspace(&kernel_virtual_space, name, address, size);
@@ -321,6 +337,7 @@ void vmalloc_init(void)
 
 #ifdef TEST_VMALLOC
        test_alloc_vspace();
+       test_vmalloc();
 #endif
 
        __alloc_vspace(&kernel_virtual_space, "vmalloc", VMALLOC_HEAP_VIRTUAL, (1 << (alloc_order + PAGE_SHIFT)));