From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= Subject: Re: [V11 PATCH 3/4] pvh dom0: Add and remove foreign pages Date: Wed, 7 May 2014 17:36:22 +0200 Message-ID: <536A52F6.2050206@citrix.com> References: <1398995707-12657-1-git-send-email-mukesh.rathor@oracle.com> <1398995707-12657-4-git-send-email-mukesh.rathor@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wi3tU-00082D-3R for xen-devel@lists.xenproject.org; Wed, 07 May 2014 15:36:28 +0000 In-Reply-To: <1398995707-12657-4-git-send-email-mukesh.rathor@oracle.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: Mukesh Rathor , xen-devel@lists.xenproject.org Cc: JBeulich@suse.com, George.Dunlap@eu.citrix.com, tim@xen.org, eddie.dong@intel.com, keir.xen@gmail.com, jun.nakajima@intel.com List-Id: xen-devel@lists.xenproject.org On 02/05/14 03:55, Mukesh Rathor wrote: > +int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, > + unsigned long gpfn, domid_t foreigndom) > +{ > + p2m_type_t p2mt, p2mt_prev; > + unsigned long prev_mfn, mfn; > + struct page_info *page; > + int rc = -EINVAL; > + struct domain *fdom = NULL; > + > + ASSERT(tdom); > + if ( foreigndom == DOMID_SELF || !is_pvh_domain(tdom) ) > + return -EINVAL; > + > + /* > + * pvh fixme: until support is added to p2m teardown code to cleanup any > + * foreign entries, limit this to hardware domain only. > + */ > + if ( !is_hardware_domain(tdom) ) > + return -EPERM; > + > + fdom = get_pg_owner(foreigndom); > + if ( fdom == NULL ) > + return -ESRCH; > + > + if ( tdom == fdom ) > + goto out; > + > + rc = xsm_map_gmfn_foreign(XSM_TARGET, tdom, fdom); > + if ( rc ) > + goto out; > + > + /* > + * Take a refcnt on the mfn. NB: following supported for foreign mapping: > + * ram_rw | ram_logdirty | ram_ro | paging_out. > + */ > + page = get_page_from_gfn(fdom, fgfn, &p2mt, P2M_ALLOC); > + if ( !page || > + !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) ) > + { > + if ( page ) > + put_page(page); This is missing setting rc to an error value, something like the following is needed: rc = -EINVAL; Roger. > + goto out; > + } > + mfn = mfn_x(page_to_mfn(page)); > + > + /* Remove previously mapped page if it is present. */ > + prev_mfn = mfn_x(get_gfn(tdom, gpfn, &p2mt_prev)); > + if ( mfn_valid(_mfn(prev_mfn)) ) > + { > + if ( is_xen_heap_mfn(prev_mfn) ) > + /* Xen heap frames are simply unhooked from this phys slot */ > + guest_physmap_remove_page(tdom, gpfn, prev_mfn, 0); > + else > + /* Normal domain memory is freed, to avoid leaking memory. */ > + guest_remove_page(tdom, gpfn); > + } > + /* > + * Create the new mapping. Can't use guest_physmap_add_page() because it > + * will update the m2p table which will result in mfn -> gpfn of dom0 > + * and not fgfn of domU. > + */ > + rc = set_foreign_p2m_entry(tdom, gpfn, _mfn(mfn)); > + if ( rc ) > + gdprintk(XENLOG_WARNING, "set_foreign_p2m_entry failed. " > + "gpfn:%lx mfn:%lx fgfn:%lx td:%d fd:%d\n", > + gpfn, mfn, fgfn, tdom->domain_id, fdom->domain_id); > + > + put_page(page); > + > + /* > + * This put_gfn for the above get_gfn for prev_mfn. We must do this > + * after set_foreign_p2m_entry so another cpu doesn't populate the gpfn > + * before us. > + */ > + put_gfn(tdom, gpfn); > + > +out: > + if ( fdom ) > + put_pg_owner(fdom); > + return rc; > +}