From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [PATCH kvm-unit-tests v2 07/12] page_alloc: allow initialization before setup_vm call Date: Wed, 17 Jan 2018 11:40:00 +0100 Message-ID: <20180117104005.29211-8-drjones@redhat.com> References: <20180117104005.29211-1-drjones@redhat.com> Cc: pbonzini@redhat.com, rkrcmar@redhat.com, cdall@linaro.org, david@redhat.com, lvivier@redhat.com, thuth@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:47440 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752693AbeAQKke (ORCPT ); Wed, 17 Jan 2018 05:40:34 -0500 In-Reply-To: <20180117104005.29211-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Andrew Jones --- 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