From: Keir Fraser Subject: Re: xenheap pages mapped by dom0 Date: Fri, 18 Dec 2009 15:24:58 +0000 Message-ID: References: <4B2B9FC50200007800026A53@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4B2B9FC50200007800026A53@vpn.id2.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jan Beulich , George Dunlap Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On 18/12/2009 14:29, "Jan Beulich" wrote: >>>> George Dunlap 18.12.09 15:04 >>> >> What's the standard practice regarding freeing xenheap pages that have >> been shared with dom0 (and may currently be mapped)? Do we need to >> make sure they're unmapped before we free them, or can we just call >> free_xenheap_pages() and let the reference counting take care of >> actually freeing them when dom0 unmaps them (if ever)? > > No, free_xenheap_pages() is what would be called when the refcount > drops to zero. What you need to do is, afaics, a simply > put_page_and_type(), which undoes the one type and one general > reference share_xen_page_with_guest() installed. This will then > either free the page right away (if Dom0 doesn't have it mapped) or > defer freeing until when Dom0 unmaps it. In fact not. put_page() calls free_domheap_page() when the refcnt falls to zero. And free_domheap_page() does not actually free Xen-heap pages: it is expected that this will happen explicitly later (e.g., when domain is destroyed) -- this is to deal with Xen itself possibly still using those pages, and those uses are not reference counted. I think the right thing to do would be very roughly: On allocation: page = alloc_xenheap_page(); share_xen_page_with_guest(page); On deallocation: if (test_and_clear(PGC_allocated)) put_page(); if (page->count_info & PGC_count_mask) return -EBUSY; free_xenheap_page(page); -- Keir