OK, so I am implementing a prototype where Linux hands an address into Xen, which gets decremented later (ie. when Xen is executing a different domain). It seems that map_domain_mem() is what I want, but how do I get the physical address of the variable? virt_to_phys() in Linux doesn''t seem to do the trick, nor virt_to_phys() in Xen. ie, pseudo code: linux/mydriver.c: static int foo = 1; // virt_to_phys(foo) maybe? HYPERVISOR_mytest(&foo); xen/common/test.c: int mytest(unsigned long addr) { // virt_to_phys(addr) maybe? manip_later->addr = addr; return 0; } // Some time later ... int *p = map_domain_mem(manip_later->addr); (*p)++; unmap_domain_mem(p); Sorry for the stupid question; I hate VM. Rusty. -- A bad analogy is like a leaky screwdriver -- Richard Braakman ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
There are notions like "guest/pseudo physical" and "machine physical" in Xen. Guest physical is basically virtualized physical address space, and that''s the one the bulk of the guest kernel code looks at. That way many assumptions in the kernel are met, thus we can minimize changes to the kernel when para-virtualizing. Machine physical is real one (i.e. global and unique), and the guest needs to use machine physical especially for inter-domain communications or MMU-related hypercalls typically. The macro pfn_to_mfn() converts guest physical PFN to machine PFN. So what you need to do is to give the machine address to Xen like: (pfn_to_mfn(__pa(foo) >> PAGE_SHIFT) << PAGE_SHIFT) + (foo & (PAGE_SIZE - 1)) Jun -----Original Message----- From: xen-devel-admin@lists.sourceforge.net [mailto:xen-devel-admin@lists.sourceforge.net] On Behalf Of Rusty Russell Sent: Tuesday, February 15, 2005 10:22 PM To: Xen Mailing List Subject: [Xen-devel] Confused about Xen memory management. OK, so I am implementing a prototype where Linux hands an address into Xen, which gets decremented later (ie. when Xen is executing a different domain). It seems that map_domain_mem() is what I want, but how do I get the physical address of the variable? virt_to_phys() in Linux doesn''t seem to do the trick, nor virt_to_phys() in Xen. ie, pseudo code: linux/mydriver.c: static int foo = 1; // virt_to_phys(foo) maybe? HYPERVISOR_mytest(&foo); xen/common/test.c: int mytest(unsigned long addr) { // virt_to_phys(addr) maybe? manip_later->addr = addr; return 0; } // Some time later ... int *p = map_domain_mem(manip_later->addr); (*p)++; unmap_domain_mem(p); Sorry for the stupid question; I hate VM. Rusty. -- A bad analogy is like a leaky screwdriver -- Richard Braakman ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
Mark Williamson
2005-Feb-16 14:37 UTC
Re: [Xen-devel] Confused about Xen memory management.
On Wednesday 16 February 2005 14:08, Nakajima, Jun wrote:> There are notions like "guest/pseudo physical" and "machine physical" in > Xen. Guest physical is basically virtualized physical address space, and > that''s the one the bulk of the guest kernel code looks at. That way many > assumptions in the kernel are met, thus we can minimize changes to the > kernel when para-virtualizing. Machine physical is real one (i.e. global > and unique), and the guest needs to use machine physical especially for > inter-domain communications or MMU-related hypercalls typically.BTW, there''s a virt_to_machine() macro available for convenience. Cheers, Mark> The macro pfn_to_mfn() converts guest physical PFN to machine PFN. > So what you need to do is to give the machine address to Xen like: > > (pfn_to_mfn(__pa(foo) >> PAGE_SHIFT) << PAGE_SHIFT) + (foo & (PAGE_SIZE > - 1)) > > Jun > -----Original Message----- > From: xen-devel-admin@lists.sourceforge.net > [mailto:xen-devel-admin@lists.sourceforge.net] On Behalf Of Rusty > Russell > Sent: Tuesday, February 15, 2005 10:22 PM > To: Xen Mailing List > Subject: [Xen-devel] Confused about Xen memory management. > > OK, so I am implementing a prototype where Linux hands an address into > Xen, which gets decremented later (ie. when Xen is executing a different > domain). It seems that map_domain_mem() is what I want, but how do I > get the physical address of the variable? virt_to_phys() in Linux > doesn''t seem to do the trick, nor virt_to_phys() in Xen. > > ie, pseudo code: > > linux/mydriver.c: > static int foo = 1; > > // virt_to_phys(foo) maybe? > HYPERVISOR_mytest(&foo); > > xen/common/test.c: > int mytest(unsigned long addr) > { > // virt_to_phys(addr) maybe? > manip_later->addr = addr; > return 0; > } > > // Some time later > ... > int *p = map_domain_mem(manip_later->addr); > (*p)++; > unmap_domain_mem(p); > > Sorry for the stupid question; I hate VM. > Rusty.------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
> OK, so I am implementing a prototype where Linux hands an address into > Xen, which gets decremented later (ie. when Xen is executing a different > domain). It seems that map_domain_mem() is what I want, but how do I > get the physical address of the variable? virt_to_phys() in Linux > doesn''t seem to do the trick, nor virt_to_phys() in Xen.In the Linux driver use virt_to_machine(). Then pass that machine address thru map_domain_mem() in Xen to get a temporary virtual mapping. If you care about safety (does teh machine address beliong to the domain?) then you could do a get_page() to ensure the domain really owns the page. If you know that Xen will only access the variable in your domain''s context (i.e., whil eusing that domain''s page tables) then you might get away with passing down a virtual address and directly derefercing that (perhap susing get_user/put_user for safety). -- Keir> ie, pseudo code: > > linux/mydriver.c: > static int foo = 1; > > // virt_to_phys(foo) maybe? > HYPERVISOR_mytest(&foo); > > xen/common/test.c: > int mytest(unsigned long addr) > { > // virt_to_phys(addr) maybe? > manip_later->addr = addr; > return 0; > } > > // Some time later > ... > int *p = map_domain_mem(manip_later->addr); > (*p)++; > unmap_domain_mem(p); > > Sorry for the stupid question; I hate VM. > Rusty. > -- > A bad analogy is like a leaky screwdriver -- Richard Braakman > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/xen-devel >------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel