From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mukesh Rathor Subject: Re: [V6 PATCH 6/7] pvh dom0: Add and remove foreign pages Date: Fri, 6 Dec 2013 18:09:31 -0800 Message-ID: <20131206180931.43966e83@mantra.us.oracle.com> References: <1386297524-15483-1-git-send-email-mukesh.rathor@oracle.com> <1386297524-15483-7-git-send-email-mukesh.rathor@oracle.com> <20131205185424.5986673b@mantra.us.oracle.com> <52A1C72B020000780010AD68@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 1Vp7Lu-00058l-Kd for xen-devel@lists.xenproject.org; Sat, 07 Dec 2013 02:10:42 +0000 In-Reply-To: <52A1C72B020000780010AD68@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: george.dunlap@eu.citrix.com, xen-devel , keir.xen@gmail.com, tim@xen.org List-Id: xen-devel@lists.xenproject.org On Fri, 06 Dec 2013 11:46:35 +0000 "Jan Beulich" wrote: > >>> On 06.12.13 at 03:54, Mukesh Rathor > >>> wrote: > > @@ -693,11 +695,42 @@ long do_memory_op(unsigned long cmd, > > XEN_GUEST_HANDLE_PARAM(void) arg) return rc; > > } > > > > + /* > > + * If autotranslate guest, (eg pvh), the gfn could be > > mapped to a mfn > > + * from foreign domain by the user space tool during > > domain creation. > > + * We need to check for that, free it up from the p2m, and > > release > > + * refcnt on it. In such a case, page would be NULL and > > the following > > + * call would not have refcnt'd the page. > > + * See also xenmem_add_foreign_to_p2m(). > > + */ > > page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC); > > if ( page ) > > + mfn = page_to_mfn(page); > > +#ifdef CONFIG_X86 > > I take this to mean that the code is okay for ARM now. But such a > conditional here needs explanation in a code comment, or putting > into something that's generic (i.e. "else if ()") but currently > happening to be always false for ARM. > > > + else > > { > > - guest_physmap_remove_page(d, xrfp.gpfn, > > page_to_mfn(page), 0); > > - put_page(page); > > + mfn = mfn_x(get_gfn_query(d, xrfp.gpfn, &p2mt)); > > + if ( p2m_is_foreign(p2mt) ) > > + { > > + struct domain *foreign_dom; > > + > > + foreign_dom = page_get_owner(mfn_to_page(mfn)); > > + ASSERT(is_pvh_domain(d)); > > + ASSERT(d != foreign_dom); > > + } > > + } > > +#endif > > + if ( page || p2m_is_foreign(p2mt) ) > > + { > > + guest_physmap_remove_page(d, xrfp.gpfn, mfn, 0); > > + if ( page ) > > + put_page(page); > > + > > + if ( p2m_is_foreign(p2mt) ) > > + { > > + put_page(mfn_to_page(mfn)); > > + put_gfn(d, xrfp.gpfn); > > + } > > The code as it stands gives the impression that there could be two > put_page() invocations in a single run here. Based on the comment > above I assume this should never be the case though. That would > be nice to be documented via a suitable ASSERT(), or it could be > made more obvious by doing something like > > if ( page || p2m_is_foreign(p2mt) ) > { > guest_physmap_remove_page(d, xrfp.gpfn, mfn, 0); > if ( p2m_is_foreign(p2mt) ) > { > page = mfn_to_page(mfn); > put_gfn(d, xrfp.gpfn); > } > put_page(page); > } Good idea to just have one put_page. But I reworked the code to make xenmem_rem_foreign_from_p2m like Ian C suggested. I think that may be the cleanest solution. Please take a look. thanks Mukesh