All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@citrix.com>
To: Mukesh Rathor <mukesh.rathor@oracle.com>
Cc: "Xen-devel@lists.xensource.com" <Xen-devel@lists.xensource.com>,
	Tim Deegan <tim@xen.org>, Keir Fraser <keir.xen@gmail.com>,
	Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Subject: Re: [hybrid]: code review for function mapping pfn to foreign mfn
Date: Mon, 16 Apr 2012 14:53:22 +0100	[thread overview]
Message-ID: <1334584402.14560.184.camel@zakaz.uk.xensource.com> (raw)
In-Reply-To: <20120413182952.504e2775@mantra.us.oracle.com>

On Sat, 2012-04-14 at 02:29 +0100, Mukesh Rathor wrote:
> Hi,
> 
> I wrote up some code to map/unmap pfn to mfn for hybrid. I wonder if anyone
> can please look at it and give any comments. I tested it and seems to work
> ok.

I'm not all that familiar with x86 p2m stuff but I'll try. (I've also
added Tim, who is familiar with this stuff)

> Basically, the library, xl running in hybrid dom0, needs to map domU pages
> during guest creation. I tried using existing add to physmap, mmu_update,
> but nothing was feasible. So wrote this. Its called from
> privcmd_ioctl_mmap_batch().
> 
> thanks,
> Mukesh
> 
> 
> /* add frames from foreign domain to current domain physmap. Similar to 
>  * XENMEM_add_to_physmap

Why a whole new hypercall rather than a new XENMAPSPACE for the exiting
XENMEM_add_to_physmap.

>  but the mfn frame is foreign, is being mapped into 
>  * current privileged domain, and is not removed from foreign domain. 
>  * Usage: libxl when creating guest in hybrid dom0 doing privcmd_ioctl_mmap
>  * Return: 0 success
>  */
> static long _add_foreign_to_pmap_batch(XEN_GUEST_HANDLE(void) arg)
> {
>     struct xen_add_to_foreign_pmap_batch pmapb;

Ideally we'd have the definition of this (or the equivalent mod to the
XENMEM_add_to_physmap associated struct) for context, but I can probably
guess what the content looks like.

>     unsigned long rc=0, i, prev_mfn, mfn = 0;
>     struct domain *fdom, *currd = current->domain;
>     p2m_type_t p2mt;
> 
>     if ( copy_from_guest(&pmapb, arg, 1) )
>         return -EFAULT;
> 
>     fdom = get_pg_owner(pmapb.foreign_domid);
> 
>     if ( fdom== NULL ) {
>         put_pg_owner(fdom);
>         return -EPERM;
>     }
> 
>     for (i=0; (rc == 0) && (i < pmapb.count); i++) {
>         unsigned long fgmfn = pmapb.gmfn+i, gpfn = pmapb.gpfn+i;
>         mfn = mfn_x(gfn_to_mfn_query(p2m_get_hostp2m(fdom), fgmfn, &p2mt));

I don't see gfn_to_mfn_query anywhere, I presume it's just a pretty
straight forward p2m lookup? Surprised there is no existing API but OK.

> 	if ( !p2m_is_valid(p2mt) )
>             rc = -EINVAL;
> 
>         if ( !rc && !get_page_from_pagenr(mfn, fdom) )
>             rc = -EPERM;
> 
>         if (!rc) 
>             put_page(mfn_to_page(mfn));
>         else 
>             break;
> 
>         /* Remove previously mapped page if it was present. */
>         prev_mfn = gmfn_to_mfn(currd, gpfn);
>         if ( mfn_valid(prev_mfn) )
>         {
>             if ( is_xen_heap_mfn(prev_mfn) )
>                 /* Xen heap frames are simply unhooked from this phys slot */
>                 guest_physmap_remove_page(currd, gpfn, prev_mfn, 0);
>             else
>                 /* Normal domain memory is freed, to avoid leaking memory. */
>                 guest_remove_page(currd, gpfn);

Do you mean "unrefd" here rather than freed? Presumably the remote
domain (which owns the page) is still using it?

>         }
>         /* Map at new location. */
> 	/* Can't use guest_physmap_add_page() because it will update the m2p
> 	 * table so mfn ---> gpfn in dom0 and not gpfn of domU.
> 	 */
>         /* rc = guest_physmap_add_page(currd, gpfn, mfn, 0); */
> 
> 	rc = set_mmio_p2m_entry(p2m_get_hostp2m(currd), gpfn, mfn);

This ends up setting the page type to p2m_mmio_direct, which doesn't
seem likely to be correct. Perhaps you should be calling
set_p2m_entry()? Or adding a set_ram_p2m_entry which does similar checks
etc to set_mmio_p2m_entry (or maybe you could abstract out some generic
bits there)?

>         if (rc==0) {
>             printk("guest_physmap_add_page failed.gpfn:%lx mfn:%lx fgmfn:%lx\n",
>                    gpfn, mfn, fgmfn);
>             rc == -EINVAL;
>         } else 
>             rc = 0;
>     }
> 
>     pmapb.count = i;
>     copy_to_guest(arg, &pmapb, 1);
>     put_pg_owner(fdom);
>     return rc;
> }
> 
> static long noinline _rem_foreign_pmap_batch(XEN_GUEST_HANDLE(void) arg)

Can't XENMEM_remove_from_physmap be used here?

> {
>     xen_pfn_t gmfn;
>     struct xen_rem_foreign_pmap_batch pmapb;
>     p2m_type_t p2mt;
>     int i, rc=0;
>     struct domain *currd = current->domain;
> 
>     if ( copy_from_guest(&pmapb, arg, 1) )
>         return -EFAULT;
> 
>     for ( gmfn=pmapb.s_gpfn, i=0;  i < pmapb.count;  i++, gmfn++ ) {
> 
>         mfn_t mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(currd), gmfn, &p2mt));
>         if ( unlikely(!mfn_valid(mfn)) )
>         {
>             gdprintk(XENLOG_INFO, "%s: Domain:%u gmfn:%lx invalid\n",
>                      __FUNCTION__, currd->domain_id, gmfn);
>             rc = -EINVAL;
>             break;
>         }
>         /* guest_physmap_remove_page(currd, gmfn, mfn, 0); */
> 	clear_mmio_p2m_entry(p2m_get_hostp2m(currd), gmfn);
>     }
>     pmapb.count = i;
>     copy_to_guest(arg, &pmapb, 1);
>     return rc;
> }
> 

  reply	other threads:[~2012-04-16 13:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-14  1:29 [hybrid]: code review for function mapping pfn to foreign mfn Mukesh Rathor
2012-04-16 13:53 ` Ian Campbell [this message]
2012-04-16 14:02   ` Tim Deegan
2012-04-17  1:53   ` Mukesh Rathor
2012-04-17  9:05     ` Ian Campbell
2012-04-18 23:29       ` Mukesh Rathor
2012-04-19  7:22         ` Ian Campbell
2012-04-19 14:15 ` Tim Deegan
2012-04-24  1:37   ` Mukesh Rathor
2012-04-24  9:36     ` Tim Deegan
2012-04-24 23:06       ` Mukesh Rathor
2012-04-26  9:08         ` Tim Deegan
2012-04-26 18:18           ` Mukesh Rathor
2012-04-26 19:57             ` Tim Deegan
2012-04-27  1:56               ` Mukesh Rathor
2012-04-27  8:51                 ` Tim Deegan
     [not found] <mailman.2710.1334825330.1399.xen-devel@lists.xen.org>
2012-04-19 14:40 ` Andres Lagar-Cavilla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334584402.14560.184.camel@zakaz.uk.xensource.com \
    --to=ian.campbell@citrix.com \
    --cc=Stefano.Stabellini@eu.citrix.com \
    --cc=Xen-devel@lists.xensource.com \
    --cc=keir.xen@gmail.com \
    --cc=mukesh.rathor@oracle.com \
    --cc=tim@xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.