From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: Re: [kvm-unit-tests PATCH v2 4/6] x86: lib/alloc: move heap management to lib Date: Thu, 3 Nov 2016 14:28:15 +0100 Message-ID: References: <1478119966-13252-1-git-send-email-drjones@redhat.com> <1478119966-13252-5-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]:38626 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750762AbcKCN2S (ORCPT ); Thu, 3 Nov 2016 09:28:18 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 C5DC1C04B93E for ; Thu, 3 Nov 2016 13:28:17 +0000 (UTC) In-Reply-To: <1478119966-13252-5-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 02/11/2016 21:52, Andrew Jones wrote: > This will allow other arches to use {alloc,free}_page. > > Signed-off-by: Andrew Jones > --- > lib/alloc.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > lib/alloc.h | 10 ++++++++++ > lib/x86/vm.c | 48 ++---------------------------------------------- > x86/Makefile.common | 1 + > 4 files changed, 62 insertions(+), 46 deletions(-) > > diff --git a/lib/alloc.c b/lib/alloc.c > index 1d990a803825..ce1198e2977f 100644 > --- a/lib/alloc.c > +++ b/lib/alloc.c > @@ -5,6 +5,7 @@ > */ > #include "alloc.h" > #include "asm/spinlock.h" > +#include "asm/page.h" > #include "asm/io.h" > > #define MIN(a, b) ((a) < (b) ? (a) : (b)) > @@ -150,6 +151,54 @@ phys_addr_t phys_zalloc(phys_addr_t size) > return phys_zalloc_aligned(size, phys_alloc_align_min); > } > > +static struct spinlock heap_lock; > +static void *heap_free_head; > + > +void heap_init(void *start, size_t size) > +{ > + void *p = start; why do you introduce "p"? It's not obvious for me... > + > + assert(!((unsigned long)start & ~PAGE_MASK)); > + > + spin_lock(&heap_lock); > + > + heap_free_head = NULL; > + > + while (size >= PAGE_SIZE) { > + *(void **)p = heap_free_head; > + heap_free_head = p; > + p += PAGE_SIZE; > + size -= PAGE_SIZE; > + } > + > + spin_unlock(&heap_lock); > +} > + > +void *alloc_page(void) > +{ > + void *p; > + > + spin_lock(&heap_lock); > + > + if (!heap_free_head) > + return NULL; missing unlock propagated from PATCH 1 Laurent