xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Mukesh Rathor <mukesh.rathor@oracle.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: george.dunlap@eu.citrix.com, Xen-devel@lists.xensource.com,
	tim@xen.org, keir.xen@gmail.com, JBeulich@suse.com
Subject: Re: [V5 PATCH 6/7] pvh dom0: Add and remove foreign pages
Date: Thu, 5 Dec 2013 17:15:04 -0800	[thread overview]
Message-ID: <20131205171504.033f3604@mantra.us.oracle.com> (raw)
In-Reply-To: <1386244824.20047.41.camel@kazak.uk.xensource.com>

On Thu, 5 Dec 2013 12:00:24 +0000
Ian Campbell <Ian.Campbell@citrix.com> wrote:

> On Wed, 2013-12-04 at 18:05 -0800, Mukesh Rathor wrote:
> > diff --git a/xen/common/memory.c b/xen/common/memory.c
> > index eb7b72b..ae11828 100644
> > --- a/xen/common/memory.c
> > +++ b/xen/common/memory.c
> > @@ -675,9 +675,11 @@ long do_memory_op(unsigned long cmd,
> > XEN_GUEST_HANDLE_PARAM(void) arg) 
> >      case XENMEM_remove_from_physmap:
> >      {
> > +        unsigned long mfn;
> >          struct xen_remove_from_physmap xrfp;
> >          struct page_info *page;
> >          struct domain *d;
> > +        p2m_type_t p2mt;
> >  
> >          if ( copy_from_guest(&xrfp, arg, 1) )
> >              return -EFAULT;
> > @@ -693,11 +695,41 @@ long do_memory_op(unsigned long cmd,
> > XEN_GUEST_HANDLE_PARAM(void) arg) return rc;
> >          }
> >  
> > -        page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC);
> > -        if ( page )
> > +        /*
> > +         * if PVH, the gfn could be mapped to a mfn from foreign
> > domain by the
> 
> s/PVH/autotranslated/ I think?
> 
> > +         * 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
> 
> Why is page NULL in this case? I'd have thought that get_page_from_gfn
> could handle the p2m_foreign case internally and still return the
> page, with the ref count taken too.
> 
> Doing that would cause a lot of the magic, and in particular the
> ifdef, in the following code to disappear.

I had brought this up earlier this year (that's how old this patch is).
get_page_from_gfn can't be used because the mfn owner is foreign
domain and not domain "d", and get_page() will barf.

> 
> > +         * the page. See also xenmem_add_foreign_to_p2m().
> > +         */
> > +        page = get_page_from_gfn(d, xrfp.gpfn, &p2mt, P2M_ALLOC);
> > +
> > +        if ( page || p2m_is_foreign(p2mt) )
> >          {
> > -            guest_physmap_remove_page(d, xrfp.gpfn,
> > page_to_mfn(page), 0);
> > -            put_page(page);
> > +            if ( page )
> > +                mfn = page_to_mfn(page);
> > +#ifdef CONFIG_X86
> > +            else
> > +            {
> > +                p2m_type_t tp;
> > +                struct domain *foreign_dom;
> > +
> > +                mfn = mfn_x(get_gfn_query(d, xrfp.gpfn, &tp));
> 
> Is it expected that tp would be different to the p2mt which you
> already got from get_page_from_gfn?

No, it's redundant. I can remove the assert. The variable tp will still
need to be defined, just not used.

> > +                foreign_dom = page_get_owner(mfn_to_page(mfn));
> 
> I'm half wondering if it would make sense to have get_page_from_gfn
> return the page owner. But since I think these asserts belong in the
> get_page_from_gfn anyhow I suppose not.
> 
> > +                ASSERT(is_pvh_domain(d));
> > +                ASSERT(d != foreign_dom);
> > +                ASSERT(p2m_is_foreign(tp));
> > +            }
> > +#endif
> > +            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);
> > +            }
> 
> Is there a reason this last bit can't be part of what
> guest_physmap_remove_page does?

Because the refcnt is not taken in guest_physmap_add_page, so would
be odd to release it in guest_physmap_remove_page.

thanks
mukesh

  reply	other threads:[~2013-12-06  1:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-05  2:05 [V5 PATCH 0/7]: PVH dom0 Mukesh Rathor
2013-12-05  2:05 ` [V5 PATCH 1/7] pvh dom0: move some pv specific code to static functions Mukesh Rathor
2013-12-05  2:05 ` [V5 PATCH 2/7] pvh dom0: construct_dom0 changes Mukesh Rathor
2013-12-05  2:05 ` [V5 PATCH 3/7] pvh dom0: implement XENMEM_add_to_physmap_range for x86 Mukesh Rathor
2013-12-05  2:05 ` [V5 PATCH 4/7] pvh dom0: Introduce p2m_map_foreign Mukesh Rathor
2013-12-05  2:05 ` [V5 PATCH 5/7] pvh: change xsm_add_to_physmap Mukesh Rathor
2013-12-05  2:05 ` [V5 PATCH 6/7] pvh dom0: Add and remove foreign pages Mukesh Rathor
2013-12-05 12:00   ` Ian Campbell
2013-12-06  1:15     ` Mukesh Rathor [this message]
2013-12-06  1:32       ` Mukesh Rathor
2013-12-06 10:18         ` Ian Campbell
2013-12-07  2:07           ` Mukesh Rathor
2013-12-06 10:15       ` Ian Campbell
2013-12-05 12:47   ` Julien Grall
2013-12-06  1:39     ` Mukesh Rathor
2013-12-05 13:12   ` Julien Grall
2013-12-06  1:57     ` Mukesh Rathor
2013-12-06  2:40       ` Mukesh Rathor
2013-12-05  2:05 ` [V5 PATCH 7/7] pvh dom0: add opt_dom0pvh to setup.c Mukesh Rathor

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=20131205171504.033f3604@mantra.us.oracle.com \
    --to=mukesh.rathor@oracle.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=Xen-devel@lists.xensource.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=keir.xen@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).