All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: kvm@vger.kernel.org, pbonzini@redhat.com
Cc: frankja@linux.ibm.com, thuth@redhat.com, david@redhat.com
Subject: [kvm-unit-tests PATCH v1 8/8] lib/vmalloc: add locking and a check for initialization
Date: Mon, 22 Jun 2020 18:21:41 +0200	[thread overview]
Message-ID: <20200622162141.279716-9-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20200622162141.279716-1-imbrenda@linux.ibm.com>

Make sure init_alloc_vpage is never called when vmalloc is in use.

Get both init_alloc_vpage and setup_vm to use the lock.

For setup_vm we only check at the end because at least on some
architectures setup_mmu can call init_alloc_vpage, which would cause
a deadlock.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 lib/vmalloc.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/vmalloc.c b/lib/vmalloc.c
index 83e34aa..10f15af 100644
--- a/lib/vmalloc.c
+++ b/lib/vmalloc.c
@@ -37,11 +37,6 @@ void *alloc_vpage(void)
 	return alloc_vpages(1);
 }
 
-void init_alloc_vpage(void *top)
-{
-	vfree_top = top;
-}
-
 void *vmap(phys_addr_t phys, size_t size)
 {
 	void *mem, *p;
@@ -96,6 +91,14 @@ void __attribute__((__weak__)) find_highmem(void)
 {
 }
 
+void init_alloc_vpage(void *top)
+{
+	spin_lock(&lock);
+	assert(alloc_ops != &vmalloc_ops);
+	vfree_top = top;
+	spin_unlock(&lock);
+}
+
 void setup_vm()
 {
 	phys_addr_t base, top;
@@ -124,5 +127,8 @@ void setup_vm()
 		free_pages(phys_to_virt(base), top - base);
 	}
 
+	spin_lock(&lock);
+	assert(alloc_ops != &vmalloc_ops);
 	alloc_ops = &vmalloc_ops;
+	spin_unlock(&lock);
 }
-- 
2.26.2


  parent reply	other threads:[~2020-06-22 16:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 16:21 [kvm-unit-tests PATCH v1 0/8] Minor fixes, improvements, and cleanup Claudio Imbrenda
2020-06-22 16:21 ` [kvm-unit-tests PATCH v1 1/8] x86/cstart.S: initialize stack before using it Claudio Imbrenda
2020-06-22 16:21 ` [kvm-unit-tests PATCH v1 2/8] x86: add missing PAGE_ALIGN macro from page.h Claudio Imbrenda
2020-06-22 16:21 ` [kvm-unit-tests PATCH v1 3/8] lib: use PAGE_ALIGN Claudio Imbrenda
2020-06-22 16:21 ` [kvm-unit-tests PATCH v1 4/8] lib/alloc.c: add overflow check for calloc Claudio Imbrenda
2020-06-23  5:57   ` Thomas Huth
2020-06-23  7:27     ` Paolo Bonzini
2020-06-22 16:21 ` [kvm-unit-tests PATCH v1 5/8] lib: Fix a typo and add documentation comments Claudio Imbrenda
2020-06-22 16:21 ` [kvm-unit-tests PATCH v1 6/8] lib/vmalloc: fix potential race and non-standard pointer arithmetic Claudio Imbrenda
2020-06-22 16:21 ` [kvm-unit-tests PATCH v1 7/8] lib/alloc_page: make get_order return unsigned int Claudio Imbrenda
2020-06-22 16:21 ` Claudio Imbrenda [this message]
2020-06-22 17:50 ` [kvm-unit-tests PATCH v1 0/8] Minor fixes, improvements, and cleanup Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200622162141.279716-9-imbrenda@linux.ibm.com \
    --to=imbrenda@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.