Patchwork [kvm-unit-tests,v2,07/12] page_alloc: allow initialization before setup_vm call

login
register
mail settings
Submitter Andrew Jones
Date Jan. 17, 2018, 10:40 a.m.
Message ID <20180117104005.29211-8-drjones@redhat.com>
Download mbox | patch
Permalink /patch/429645/
State New
Headers show

Comments

Andrew Jones - Jan. 17, 2018, 10:40 a.m.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/alloc_page.c | 5 +++++
 lib/alloc_page.h | 1 +
 lib/vmalloc.c    | 9 ++++++---
 3 files changed, 12 insertions(+), 3 deletions(-)

Patch

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;
 }