hello, I would like to map (Read/Write) pages owned by a HVM guest from my Dom0 Linux kernel module. I have access to the "machine frame numbers" of these pages. 1. What is the right interface to do this? kmap needs ''struct page'' ptrs which I doubt exist for pages owned by a HVM guest. Is there a hypercall to do this then? 2. Do I need to modify the HVM behavior in any way for this? (e.g., load a driver in the guest that will setup grant tables?). I need to keep my guest "pure HVM". thanks, ./satya _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
pradeep singh rautela
2008-Sep-26 22:25 UTC
Re: [Xen-devel] Mapping hvm guest pages in Dom0
On Sat, Sep 27, 2008 at 12:32 AM, Satya <satyakiran@gmail.com> wrote:> hello, > I would like to map (Read/Write) pages owned by a HVM guest from my Dom0 > Linux kernel module. I have access to the "machine frame numbers" of these > pages.Won''t this make your HVM guest go boom? After all you are changing the state of the pages *supposedly* owned by a HVM domain.> > 1. What is the right interface to do this? kmap needs ''struct page'' ptrs > which I doubt exist for pages owned by a HVM guest. Is there a hypercall to > do this then?Do grant tables exist for HVM guests, I doubt it?> > 2. Do I need to modify the HVM behavior in any way for this? (e.g., load a > driver in the guest that will setup grant tables?). I need to keep my guest > "pure HVM".pure HVM which knows that some pages are being used by the domain0 will essentially make them non pure I guess :). BTW perhaps you can make sure that a HVM domain sees a region of memory as shared with some other kernel. To do this you can write a kernel module in the HVM domain( I hope it is linux ). But this is all pure guess work, so please do not take my word. May be you can think something better on similar lines. :) Thanks, --Pradeep> > thanks, > ./satya > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel > >-- Pradeep Singh Rautela http://eagain.wordpress.com http://emptydomain.googlepages.com _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hi, On Fri, Sep 26, 2008 at 8:02 PM, Satya <satyakiran@gmail.com> wrote:> hello, > I would like to map (Read/Write) pages owned by a HVM guest from my Dom0 > Linux kernel module. I have access to the "machine frame numbers" of these > pages. > > 1. What is the right interface to do this? kmap needs ''struct page'' ptrs > which I doubt exist for pages owned by a HVM guest. Is there a hypercall to > do this then? >You can use xc_map_foreign_ranges function inside libxc (link with xenctrl).> 2. Do I need to modify the HVM behavior in any way for this? (e.g., load a > driver in the guest that will setup grant tables?). I need to keep my guest > "pure HVM". >You don''t need to modify your hvm for doing that. -- Jean Guyader _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Am Freitag, 26. September 2008 schrieb Satya:> hello, > I would like to map (Read/Write) pages owned by a HVM guest from my Dom0 > Linux kernel module. I have access to the "machine frame numbers" of these > pages. > > 1. What is the right interface to do this? kmap needs ''struct page'' ptrs > which I doubt exist for pages owned by a HVM guest. Is there a hypercall to > do this then? > > 2. Do I need to modify the HVM behavior in any way for this? (e.g., load a > driver in the guest that will setup grant tables?). I need to keep my guest > "pure HVM". > > thanks, > ./satyaIf you have the gmfn''s from the HVM domU (I''am not sure where you get this from if you want to keep your guest "pure" HVM) and the domU id, you can map the domU memory into the dom0 kernel memory with struct vm_struct area; area = alloc_vm_area(num_pages * PAGE_SIZE); direct_kernel_remap_pfn_range(((unsigned long)) area->addr, gmfn, PAGE_SIZE*num_pages, prots, domU_id); Dietmar. -- Dietmar Hahn IP SW OS6 Telephone: +49 (0) 89 636 40274 Fujitsu Siemens Computers Email: dietmar.hahn@fujitsu-siemens.com Otto-Hahn-Ring 6 Internet: http://www.fujitsu-siemens.com D-81739 München Company details: www.fujitsu-siemens.com/imprint.html _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
If you have the gmfn''s from the HVM domU (I''am not sure where you get this> from if you want to keep your guest "pure" HVM) and the domU id, you can > map > the domU memory into the dom0 kernel memory with > > struct vm_struct area; > area = alloc_vm_area(num_pages * PAGE_SIZE); > direct_kernel_remap_pfn_range(((unsigned long)) area->addr, gmfn, > PAGE_SIZE*num_pages, prots, domU_id); >I did that but the hypercall from __direct_remap_pfn_range() errors out (-EINVAL) if prots include _PAGE_PRESENT. Without this flag the kernel cannot handle reads and writes to these pages (will essentially page fault). Any thoughts? ./satya ps: Thanks to everyone for the replies. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Am Dienstag, 7. Oktober 2008 schrieb Satya:> If you have the gmfn''s from the HVM domU (I''am not sure where you get this > > > from if you want to keep your guest "pure" HVM) and the domU id, you can > > map > > the domU memory into the dom0 kernel memory with > > > > struct vm_struct area; > > area = alloc_vm_area(num_pages * PAGE_SIZE); > > direct_kernel_remap_pfn_range(((unsigned long)) area->addr, gmfn, > > PAGE_SIZE*num_pages, prots, domU_id); > > I did that but the hypercall from __direct_remap_pfn_range() errors out > (-EINVAL) if prots include _PAGE_PRESENT. Without this flag the kernel > cannot handle reads and writes to these pages (will essentially page > fault). Any thoughts? > > ./satya > > ps: Thanks to everyone for the replies.Maybe your gmfn is wrong. Are you seeing a message on serial console or ''xm log'' ? What I do is: domU gives the gmfn''s to dom0 prot = __pgprot(_KERNPG_TABLE); // _KERNPG_TABLE contains _PAGE_PRESENT area = alloc_vm_area(num_pages * PAGE_SIZE); direct_kernel_remap_pfn_range(((unsigned long)) area->addr, gmfn, PAGE_SIZE*num_pages, prots, domU_id); Now I can read and write the domU memory from dom0 kernel! You can find an example in xenoprof part in the dom0 linux kernel: xenoprof_arch_map_shared_buffer() or xenoprof_arch_set_passive() in arch/i386/oprofile/xenoprof.c Dietmar. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Thu, Oct 9, 2008 at 2:56 AM, Dietmar Hahn < dietmar.hahn@fujitsu-siemens.com> wrote:> Am Dienstag, 7. Oktober 2008 schrieb Satya: > > If you have the gmfn''s from the HVM domU (I''am not sure where you get > this > > > > > from if you want to keep your guest "pure" HVM) and the domU id, you > can > > > map > > > the domU memory into the dom0 kernel memory with > > > > > > struct vm_struct area; > > > area = alloc_vm_area(num_pages * PAGE_SIZE); > > > direct_kernel_remap_pfn_range(((unsigned long)) area->addr, gmfn, > > > PAGE_SIZE*num_pages, prots, domU_id); > > > > I did that but the hypercall from __direct_remap_pfn_range() errors out > > (-EINVAL) if prots include _PAGE_PRESENT. Without this flag the kernel > > cannot handle reads and writes to these pages (will essentially page > > fault). Any thoughts? > > > > ./satya > > > > ps: Thanks to everyone for the replies. > > Maybe your gmfn is wrong.yeah, I only have the host machine frame numbers. I don''t have the ''gmfn'' - which is I believe is the guest''s view of this machine frame number. Is there a function f(hostmfn, domid) that will give me the corresponding gmfn? i.e I should be able to read the guest''s p2m table. I sent out another message to xen-devel asking the same question, but I don''t see it posted to the list yet.> > Are you seeing a message on serial console or ''xm log'' ?Well ''xm dmesg'' showed nothing relevant.> > What I do is: > domU gives the gmfn''s to dom0 > prot = __pgprot(_KERNPG_TABLE); // _KERNPG_TABLE contains > _PAGE_PRESENT > area = alloc_vm_area(num_pages * PAGE_SIZE); > direct_kernel_remap_pfn_range(((unsigned long)) area->addr, gmfn, > PAGE_SIZE*num_pages, prots, domU_id); > Now I can read and write the domU memory from dom0 kernel! > > You can find an example in xenoprof part in the dom0 linux kernel: > xenoprof_arch_map_shared_buffer() or xenoprof_arch_set_passive() > in arch/i386/oprofile/xenoprof.c >Thanks, that was helpful. ./satya _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel