Skip to contentSkip to conversation

Dom heap virtual address question

DISCUSSION Daniel Magenheimer 2 participants 5 messages Aug 26, 2008 – Aug 27, 2008

lore
Share & tools
lore
#0 lore raw

Silly x86-related memory question from someone who has only used global virtual address machines for too many years:

Is it possible to take the result of an alloc_domheap_pages() (struct page_info *) and convert this to a virtual address that can be used at a later time in the hypervisor (not in a domain)? E.g.

va = mfn_to_virt(page_to_mfn(alloc_domheap_pages()))
:
(many seconds later, still in hypervisor)
:
a = *(unsigned int *)va;

Or is it necessary to do a va = map_domain_page(mfn) then unmap_domain_page(va) around each usage? (And if so do I need the _global version of these?)

I'm willing to restrict this to 64-bit hypervisor only if that matters... but ideally I'd like it to be portable (i.e. to ia64/ppc).

Also, if it matters, I'd probably use anonymous domain (NULL) rather than current->domain.

Thanks,
Dan

#1 lore raw
Quoted 11 lines

From: Daniel Magenheimer
Sent: 2008年8月27日 7:49

Silly x86-related memory question from someone who has only used global virtual address machines for too many years:

Is it possible to take the result of an alloc_domheap_pages() (struct page_info *) and convert this to a virtual address that can be used at a later time in the hypervisor (not in a domain)? E.g.

Quoted 5 lines

va = mfn_to_virt(page_to_mfn(alloc_domheap_pages()))
:
(many seconds later, still in hypervisor)
:
a = *(unsigned int *)va;

This only applies to 64bit xen which directly maps all memory in a large enough virtual address range. For 32bit xen, mfn_to_virt only applies to xenheap pages.

Quoted 4 lines

Or is it necessary to do a va = map_domain_page(mfn) then unmap_domain_page(va) around each usage? (And if so do I need the _global version of these?)

map/unmap_domain_page is cleaner wrap, suitable for both 32bit and 64bit xen. For 64bit xen, it's actually a macro to mfn_to_virt and thus map/unmap is light. you can use _global version if you'd like to access that page from any domain context and don't want to local map/unmap frequently.

Thanks,
Kevin

#2 lore raw

Hi Kevin --

Thanks much for the reply.

Further clarification on the _global versions:
If domainA makes a hypercall that results in the

va = mfn_to_virt(page_to_mfn(alloc_domheap_pages()))

(or equivalent wrapped in map/unmap_domain_page)

and then domainB makes a hypercall but IN THE HYPERVISOR I want to make use of the previously saved va (or mapped mfn), is that still in the context of domainA? In other words, I must use _global?

Thanks,
Dan

Quoted 47 lines

-----Original Message-----
From: Tian, Kevin [mailto:[email protected]]
Sent: Tuesday, August 26, 2008 6:35 PM
To: Daniel Magenheimer; Xen-Devel (E-mail)
Subject: RE: [Xen-devel] Dom heap virtual address question

Quoted 11 lines

From: Daniel Magenheimer
Sent: 2008年8月27日 7:49

Silly x86-related memory question from someone who has only used global virtual address machines for too many years:

Is it possible to take the result of an alloc_domheap_pages() (struct page_info *) and convert this to a virtual address that can be used at a later time in the hypervisor (not in a domain)? E.g.

Quoted 5 lines

va = mfn_to_virt(page_to_mfn(alloc_domheap_pages()))
:
(many seconds later, still in hypervisor)
:
a = *(unsigned int *)va;

This only applies to 64bit xen which directly maps all memory in a large enough virtual address range. For 32bit xen, mfn_to_virt only applies to xenheap pages.

Quoted 4 lines

Or is it necessary to do a va = map_domain_page(mfn) then unmap_domain_page(va) around each usage? (And if so do I need the _global version of these?)

map/unmap_domain_page is cleaner wrap, suitable for both 32bit and 64bit xen. For 64bit xen, it's actually a macro to mfn_to_virt and thus map/unmap is light. you can use _global version if you'd like to access that page from any domain context and don't want to local map/unmap frequently.

Thanks,
Kevin

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 10 lines

From: Daniel Magenheimer [mailto:[email protected]]
Sent: 2008年8月27日 9:20

Hi Kevin --

Thanks much for the reply.

Further clarification on the _global versions:
If domainA makes a hypercall that results in the

Quoted 9 lines

va = mfn_to_virt(page_to_mfn(alloc_domheap_pages()))

(or equivalent wrapped in map/unmap_domain_page)

and then domainB makes a hypercall but IN THE HYPERVISOR I want to make use of the previously saved va (or mapped mfn), is that still in the context of domainA? In other words, I must use _global?

Yes. The ptes used for non global version is domain specific, which is changed along with context switch. However ptes for _global version are persistent across domains. This is for 32bit xen.

For 64bit xen, both local and global version are simply macros to mfn_to_virt which is a directly mapping style setuped at boot time. In such case, you can always access previously mapped va from any domain context, regardless of which interface is used.

But for portability, it's better to have 32bit implication in mind to avoid mistake. :-)

Thanks,
Kevin

#4 lore raw
Quoted 2 lines

But for portability, it's better to have 32bit implication in mind to avoid mistake. :-)

Yes, exactly what I was thinking!

Quoted 2 lines

For 64bit xen, both local and global version are simply macros to mfn_to_virt which is a directly mapping

OK, I found this in xen/include/xen/domain_page.h but was confused because CONFIG_DOMAIN_PAGE must be set to zero and include/asm-x86/config.h sets it to one. But apparently the 64-bit build scripts override the config.h setting and CONFIG_DOMAIN_PAGE=1 is used.

Thanks again!
Dan

Quoted 44 lines

-----Original Message-----
From: Tian, Kevin [mailto:[email protected]]
Sent: Tuesday, August 26, 2008 7:29 PM
To: Daniel Magenheimer; Xen-Devel (E-mail)
Subject: RE: [Xen-devel] Dom heap virtual address question

Quoted 10 lines

From: Daniel Magenheimer [mailto:[email protected]]
Sent: 2008年8月27日 9:20

Hi Kevin --

Thanks much for the reply.

Further clarification on the _global versions:
If domainA makes a hypercall that results in the

Quoted 9 lines

va = mfn_to_virt(page_to_mfn(alloc_domheap_pages()))

(or equivalent wrapped in map/unmap_domain_page)

and then domainB makes a hypercall but IN THE HYPERVISOR I want to make use of the previously saved va (or mapped mfn), is that still in the context of domainA? In other words, I must use _global?

Yes. The ptes used for non global version is domain specific, which is changed along with context switch. However ptes for _global version are persistent across domains. This is for 32bit xen.

For 64bit xen, both local and global version are simply macros to mfn_to_virt which is a directly mapping style setuped at boot time. In such case, you can always access previously mapped va from any domain context, regardless of which interface is used.

But for portability, it's better to have 32bit implication in mind to avoid mistake. :-)

Thanks,
Kevin