From: Tim Deegan Subject: Re: [PATCH v5 1/4] xen: move steal_page and donate_page to common code Date: Tue, 10 Sep 2013 19:06:51 +0100 Message-ID: <20130910180651.GD26833@ocelot.phlegethon.org> References: <1378742763-24299-1-git-send-email-stefano.stabellini@eu.citrix.com> <522F12FC02000078000F1CDB@nat28.tlf.novell.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 1VJSL0-0001mU-Fy for xen-devel@lists.xenproject.org; Tue, 10 Sep 2013 18:06:54 +0000 Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: xen-devel , keir@xen.org, Ian.Campbell@citrix.com, Jan Beulich List-Id: xen-devel@lists.xenproject.org At 18:20 +0100 on 10 Sep (1378837226), Stefano Stabellini wrote: > On Tue, 10 Sep 2013, Jan Beulich wrote: > > >>> On 09.09.13 at 18:06, Stefano Stabellini wrote: > > > --- a/xen/common/memory.c > > > +++ b/xen/common/memory.c > > > @@ -230,6 +230,91 @@ int guest_remove_page(struct domain *d, unsigned long gmfn) > > > return 1; > > > } > > > > > > +int donate_page( > > > + struct domain *d, struct page_info *page, unsigned int memflags) > > > +{ > > > + spin_lock(&d->page_alloc_lock); > > > + > > > + if ( is_xen_heap_page(page) || (page_get_owner(page) != NULL) ) > > > + goto fail; > > > + > > > + if ( d->is_dying ) > > > + goto fail; > > > + > > > + if ( page->count_info & ~(PGC_allocated | 1) ) > > > > While the literal 1 was acceptable in arch specific code, I'm not sure > > it really is in generic code. Nothing enforces that an arch has the > > count starting at bit 0. Even if it reads a little odd, using > > (-PGC_count_mask & PGC_count_mask) would probably be an > > acceptable replacement here and further down. > > (-PGC_count_mask & PGC_count_mask) is always 0. 'x & -x' always gives you the lowest set bit in x, though as Jan points out it's a bit opaque. Maybe it needs a friendly macro name? Tim.