From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hildenbrand Subject: Re: [PATCH kvm-unit-tests v2 06/12] phys_alloc: ensure we account all allocations Date: Wed, 17 Jan 2018 13:15:47 +0100 Message-ID: <69272fc0-b8ca-cada-df36-d74cd3cf5990@redhat.com> References: <20180117104005.29211-1-drjones@redhat.com> <20180117104005.29211-7-drjones@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: pbonzini@redhat.com, rkrcmar@redhat.com, cdall@linaro.org, lvivier@redhat.com, thuth@redhat.com To: Andrew Jones , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:45784 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752285AbeAQMPv (ORCPT ); Wed, 17 Jan 2018 07:15:51 -0500 In-Reply-To: <20180117104005.29211-7-drjones@redhat.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 17.01.2018 11:39, Andrew Jones wrote: > Also throw another assert into phys_alloc_aligned_safe. > > Signed-off-by: Andrew Jones > --- > lib/alloc_phys.c | 10 ++++++++++ > lib/alloc_phys.h | 6 ++++-- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/lib/alloc_phys.c b/lib/alloc_phys.c > index d09395d1010c..736c3129fc02 100644 > --- a/lib/alloc_phys.c > +++ b/lib/alloc_phys.c > @@ -81,6 +81,8 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size, > if (safe && sizeof(long) == 4) > top_safe = MIN(top_safe, 1ULL << 32); > > + assert(base < top_safe); > + > addr = ALIGN(base, align); > size += addr - base; > > @@ -116,6 +118,14 @@ void phys_alloc_get_unused(phys_addr_t *p_base, phys_addr_t *p_top) > { > *p_base = base; > *p_top = top; > + if (base == top) > + return; > + spin_lock(&lock); > + regions[nr_regions].base = base; > + regions[nr_regions].size = top - base; > + ++nr_regions; > + base = top; > + spin_unlock(&lock); > } > > static void *early_memalign(size_t alignment, size_t size) > diff --git a/lib/alloc_phys.h b/lib/alloc_phys.h > index 848d3db23a1e..7cf59a661180 100644 > --- a/lib/alloc_phys.h > +++ b/lib/alloc_phys.h > @@ -37,8 +37,10 @@ extern void phys_alloc_set_minimum_alignment(phys_addr_t align); > extern void phys_alloc_show(void); > > /* > - * phys_alloc_get_unused returns the addresses for the still-unused part > - * of the initial free memory region passed to phys_alloc_init. > + * phys_alloc_get_unused allocates all remaining memory from the region > + * passed to phys_alloc_init, returning the newly allocated memory's base > + * and top addresses. phys_allo_get_unused will still return base and top s/phys_allo_get_unused/phys_alloc_get_unused/ Looks good to me -- Thanks, David / dhildenb