[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [V5 PATCH 6/7] pvh dom0: Add and remove foreign pages



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.

> +         * 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?

> +                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?

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.