From: Laurent Vivier Subject: Re: [kvm-unit-tests PATCH v2 1/6] lib/x86/vm: collection of improvements Date: Thu, 3 Nov 2016 10:40:14 +0100 Message-ID: <7a0f1a1a-59a4-9fba-cdfe-985d18cf0be4@redhat.com> References: <1478119966-13252-1-git-send-email-drjones@redhat.com> <1478119966-13252-2-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: pbonzini@redhat.com, thuth@redhat.com To: Andrew Jones , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:52272 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753209AbcKCJkR (ORCPT ); Thu, 3 Nov 2016 05:40:17 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6B9F96C3 for ; Thu, 3 Nov 2016 09:40:16 +0000 (UTC) In-Reply-To: <1478119966-13252-2-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 02/11/2016 21:52, Andrew Jones wrote: > Ensure we're page aligned, add locking, just return if NULL is > passed to vfree(). > > Signed-off-by: Andrew Jones > --- > lib/x86/asm/page.h | 2 ++ > lib/x86/vm.c | 44 +++++++++++++++++++++++++++++++++++++------- > 2 files changed, 39 insertions(+), 7 deletions(-) > > diff --git a/lib/x86/asm/page.h b/lib/x86/asm/page.h > index 5044a49ab0cc..dd999304f1f0 100644 > --- a/lib/x86/asm/page.h > +++ b/lib/x86/asm/page.h > @@ -16,6 +16,8 @@ > > #ifndef __ASSEMBLY__ > > +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) > + > #ifdef __x86_64__ > #define LARGE_PAGE_SIZE (512 * PAGE_SIZE) > #else > diff --git a/lib/x86/vm.c b/lib/x86/vm.c > index f7e778b3779c..baea17e7f475 100644 > --- a/lib/x86/vm.c > +++ b/lib/x86/vm.c > @@ -1,37 +1,54 @@ > #include "fwcfg.h" > #include "vm.h" > #include "libcflat.h" > +#include "asm/spinlock.h" > > +static struct spinlock heap_lock; > +static struct spinlock vm_lock; > static void *free = 0; > static void *vfree_top = 0; > > static void free_memory(void *mem, unsigned long size) > { > + assert(!((unsigned long)mem & ~PAGE_MASK)); > + > + spin_lock(&heap_lock); > + > + free = NULL; > + > while (size >= PAGE_SIZE) { > *(void **)mem = free; > free = mem; > mem += PAGE_SIZE; > size -= PAGE_SIZE; > } > + > + spin_unlock(&heap_lock); > } > > void *alloc_page() > { > void *p; > > + spin_lock(&heap_lock); > + > if (!free) > - return 0; > + return NULL; You must unlock heap_lock before return Laurent