From: "Jan Beulich" Subject: Re: [PATCH v5 1/4] xen: introduce a helper to allocate non-contiguous memory Date: Fri, 08 May 2015 16:25:06 +0100 Message-ID: <554CF1720200007800078695@mail.emea.novell.com> References: <1431095651-25935-1-git-send-email-roger.pau@citrix.com> <1431095651-25935-2-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yqk9E-0001do-3a for xen-devel@lists.xenproject.org; Fri, 08 May 2015 15:25:08 +0000 In-Reply-To: <1431095651-25935-2-git-send-email-roger.pau@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Roger Pau Monne Cc: Andrew Cooper , Tim Deegan , Stefano Stabellini , Ian Campbell , xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> On 08.05.15 at 16:34, wrote: > --- a/xen/common/vmap.c > +++ b/xen/common/vmap.c > @@ -146,7 +146,7 @@ static unsigned int vm_index(const void *va) > test_bit(idx, vm_bitmap) ? idx : 0; > } > > -static unsigned int vm_size(const void *va) > +unsigned int vm_size(const void *va) I was hoping you would avoid this. I really think vmalloc() and vfree() should go into vmap.c. They certainly don't belong into ... > --- a/xen/common/xmalloc_tlsf.c > +++ b/xen/common/xmalloc_tlsf.c ... here. > +void *vmalloc(unsigned long size) > +{ > + unsigned long *mfn; > + unsigned long pages, i; > + struct page_info *pg; > + void *va = NULL; > + > + ASSERT(!in_irq()); I don't think you explicitly need this here - the xzalloc_array() below will catch that case, and the function here doesn't itself depend on that. > + if ( size == 0 ) > + return ZERO_BLOCK_PTR; If you really wanted this, vfree() would need to cope. But I think it's better to simply ASSERT(size) here. > + pages = DIV_ROUND_UP(size, PAGE_SIZE); I think this would better use PFN_UP(). > + mfn = xzalloc_array(unsigned long, pages); > + if ( mfn == NULL ) > + return NULL; > + > + for ( i = 0; i < pages; i++ ) > + { > + pg = alloc_domheap_pages(NULL, 1, 0); > + if ( pg == NULL ) > + goto error; > + mfn[i] = page_to_mfn(pg); > + } > + > + va = vmap(mfn, pages); > + if ( va == NULL ) > + goto error; > + > + xfree(mfn); > + return va; > + > + error: > + vunmap(va); I don't think vunmap() copes with NULL passed into it. But I also don't see why you call it in the first place - no path leads here with va != NULL. > +void vfree(void *va) > +{ > + unsigned int i, pages = vm_size(va); > + > + if ( pages == 0 ) > + return; This then shouldn't be needed either (or become an ASSERT()). > --- a/xen/include/xen/xmalloc.h > +++ b/xen/include/xen/xmalloc.h > @@ -30,6 +30,10 @@ extern void xfree(void *); > extern void *_xmalloc(unsigned long size, unsigned long align); > extern void *_xzalloc(unsigned long size, unsigned long align); > > +void *vmalloc(unsigned long size); > +void *vzalloc(unsigned long size); > +void vfree(void *va); And consequently this is the wrong place then too. Jan