xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* question regarding foreign memory mapping in xen
@ 2013-05-27 13:06 Sengul Thomas
  2013-05-27 13:17 ` Andrew Cooper
  2013-05-28 10:20 ` Ian Campbell
  0 siblings, 2 replies; 3+ messages in thread
From: Sengul Thomas @ 2013-05-27 13:06 UTC (permalink / raw)
  To: Xen Devel

Hello xen developers :)

I'm reading source codes of xen and got a question in tool-stack part
and got series of questions:

In file tools/libxc/xc_linux_osdep.c, function linux_privcmd_map_foreign_bulk,
I notice that mmap and ioctl IOCTL_PRIVCMD_MMAPBATCH_V2, are used
for mapping a foreign memory into dom0.

Is it because mmap is for mapping from /proc/xen/privcmd to dom0 memory and
ioctl is for mapping from foreign memory (probably domU) into /proc/xen/privcmd?

Also, I am trying to understand how ioctl IOCTL_PRIVCMD_MMAPBATCH_V2 works,
and it is quite hard.
In function privcmd_ioctl_mmap_batch, it allocates pages in dom0 side,
and I don't understand why do we need this allocation.
If we map a page from foreign domain, just changing grant table is not enough?
Please enlighten me.

Also, I see that in function mmap_batch_fn (i.e., called with the
newly allocated pages),
xen_remap_domain_mfn_range function is called.
Could you tell me what does this function (xen_remap_domain_mfn_range)
do briefly.
It would help me understand xen more!

Best regards,
Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: question regarding foreign memory mapping in xen
  2013-05-27 13:06 question regarding foreign memory mapping in xen Sengul Thomas
@ 2013-05-27 13:17 ` Andrew Cooper
  2013-05-28 10:20 ` Ian Campbell
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2013-05-27 13:17 UTC (permalink / raw)
  To: Sengul Thomas; +Cc: Xen Devel

On 27/05/13 14:06, Sengul Thomas wrote:
> Hello xen developers :)
>
> I'm reading source codes of xen and got a question in tool-stack part
> and got series of questions:
>
> In file tools/libxc/xc_linux_osdep.c, function linux_privcmd_map_foreign_bulk,
> I notice that mmap and ioctl IOCTL_PRIVCMD_MMAPBATCH_V2, are used
> for mapping a foreign memory into dom0.
>
> Is it because mmap is for mapping from /proc/xen/privcmd to dom0 memory and
> ioctl is for mapping from foreign memory (probably domU) into /proc/xen/privcmd?
>
> Also, I am trying to understand how ioctl IOCTL_PRIVCMD_MMAPBATCH_V2 works,
> and it is quite hard.
> In function privcmd_ioctl_mmap_batch, it allocates pages in dom0 side,
> and I don't understand why do we need this allocation.
> If we map a page from foreign domain, just changing grant table is not enough?
> Please enlighten me.

A foreign mapping is unrelated to grant tables.

Grant tables are used for a domain to negotiate to allow other domains
access to parts of its memory.

Foreign mappings are for the toolstack needing to play with a domains
memory without its knowledge.  It is the basis of domain create/migrate etc.

~Andrew

>
> Also, I see that in function mmap_batch_fn (i.e., called with the
> newly allocated pages),
> xen_remap_domain_mfn_range function is called.
> Could you tell me what does this function (xen_remap_domain_mfn_range)
> do briefly.
> It would help me understand xen more!
>
> Best regards,
> Thomas
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: question regarding foreign memory mapping in xen
  2013-05-27 13:06 question regarding foreign memory mapping in xen Sengul Thomas
  2013-05-27 13:17 ` Andrew Cooper
@ 2013-05-28 10:20 ` Ian Campbell
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Campbell @ 2013-05-28 10:20 UTC (permalink / raw)
  To: Sengul Thomas; +Cc: Xen Devel

On Mon, 2013-05-27 at 22:06 +0900, Sengul Thomas wrote:
> Hello xen developers :)
> 
> I'm reading source codes of xen and got a question in tool-stack part
> and got series of questions:
> 
> In file tools/libxc/xc_linux_osdep.c, function linux_privcmd_map_foreign_bulk,
> I notice that mmap and ioctl IOCTL_PRIVCMD_MMAPBATCH_V2, are used
> for mapping a foreign memory into dom0.
> 
> Is it because mmap is for mapping from /proc/xen/privcmd to dom0 memory and
> ioctl is for mapping from foreign memory (probably domU) into /proc/xen/privcmd?

As far as privcmd is concerned mmap is effectively used as a way to
reserve some virtual address in the current process, while the ioctl is
used to fill it with memory mapped from a foreign domain.

> Also, I am trying to understand how ioctl IOCTL_PRIVCMD_MMAPBATCH_V2 works,
> and it is quite hard.
> In function privcmd_ioctl_mmap_batch, it allocates pages in dom0 side,
> and I don't understand why do we need this allocation.

Just to give us a hole where we can then map the domU page, i.e. it just
gives us the dom0 internal datastructures, like struct page *.

> If we map a page from foreign domain, just changing grant table is not enough?

No because as Andrew says grant tables and privileged foreign maps are
not the same thing.

> Also, I see that in function mmap_batch_fn (i.e., called with the
> newly allocated pages),
> xen_remap_domain_mfn_range function is called.
> Could you tell me what does this function (xen_remap_domain_mfn_range)
> do briefly.

IIRC it calls a callback function for each PTE involved in mapping the
given range of addresses, which we then use to make the foreign mapping.

Ian.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-05-28 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-27 13:06 question regarding foreign memory mapping in xen Sengul Thomas
2013-05-27 13:17 ` Andrew Cooper
2013-05-28 10:20 ` Ian Campbell

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).