From: "Jan Beulich" Subject: Re: [PATCH v5 1/4] xen: introduce a helper to allocate non-contiguous memory Date: Mon, 11 May 2015 08:42:25 +0100 Message-ID: <555079810200007800078B9D@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.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YriM9-0003lT-EV for xen-devel@lists.xenproject.org; Mon, 11 May 2015 07:42:29 +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: > +void vfree(void *va) > +{ > + unsigned int i, pages = vm_size(va); > + > + if ( pages == 0 ) > + return; > + > + for ( i = 0; i < pages; i++ ) > + free_domheap_pages(vmap_to_page(va + i * PAGE_SIZE), 1); > + > + vunmap(va); > +} There actually is another problem here: You must not free the pages before having torn down the mapping. An option (to avoid the need for a memory allocation) might be to zap the present bits (or whatever their equivalent on ARM) in a first pass (making sure to flush TLBs), free, and then vunmap(). And you would of course better use the single page shortcut macros of the domheap allocation/free functions. Jan