[PATCH kvm-unit-tests 07/11] page_alloc: allow initialization before setup_vm call

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

 



Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/alloc_page.c | 5 +++++
 lib/alloc_page.h | 1 +
 lib/vmalloc.c    | 9 ++++++---
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index f0d46d7ac201..ca11496829a0 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -13,6 +13,11 @@
 static struct spinlock lock;
 static void *freelist = 0;
 
+bool page_alloc_initialized(void)
+{
+	return freelist != 0;
+}
+
 void free_pages(void *mem, unsigned long size)
 {
 	void *old_freelist;
diff --git a/lib/alloc_page.h b/lib/alloc_page.h
index 1884c7a34ffc..1c2b3ec9add6 100644
--- a/lib/alloc_page.h
+++ b/lib/alloc_page.h
@@ -8,6 +8,7 @@
 #ifndef ALLOC_PAGE_H
 #define ALLOC_PAGE_H 1
 
+bool page_alloc_initialized(void);
 void *alloc_page();
 void *alloc_pages(unsigned long order);
 void free_page(void *page);
diff --git a/lib/vmalloc.c b/lib/vmalloc.c
index ca36bf87579a..b583786e2647 100644
--- a/lib/vmalloc.c
+++ b/lib/vmalloc.c
@@ -94,9 +94,12 @@ void setup_vm()
 		return;
 
 	phys_alloc_get_unused(&base, &top);
-	base = (base + PAGE_SIZE - 1) & -PAGE_SIZE;
-	top = top & -PAGE_SIZE;
-	free_pages(phys_to_virt(base), top - base);
+	assert(base != top || page_alloc_initialized());
+	if (!page_alloc_initialized()) {
+		base = (base + PAGE_SIZE - 1) & -PAGE_SIZE;
+		top = top & -PAGE_SIZE;
+		free_pages(phys_to_virt(base), top - base);
+	}
 	page_root = setup_mmu(top);
 	alloc_ops = &vmalloc_ops;
 }
-- 
2.13.6




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux