Guillaume Thouvenin
2007-Feb-28 14:04 UTC
[Xen-devel] How to map machine address and pseudo-physical address?
Hello evrybody, I need to parse data structures supplied by the BIOS in machine memory. I''d like to know how I can do it in dom0? I though about mapping part of memory machine in dom0 but I have the following problem. I take the example of code taken from Linux in arch/i386/kernel/summit.c to get the pointer to the EBDA at physical @ 0x40E: ... unsigned long ptr; /* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E)*/ ptr = *(unsigned short *)phys_to_virt(0x40Eul); ptr = (unsigned long)phys_to_virt(ptr << 4); ... On a linux kernel, ptr==0xffff810000099000 If I run the same code inside dom0, I get ptr==0xffff880000000000 It''s normal because under dom0 the 0X40E corresponds to the pseudo physical address and not to the machine address. So the idea (maybe it''s not the good one, it''s a try :) is to map the machine address 0x40E to pseudo physical address 0x40E and then, I should read the correct pointer value from dom0. Thus in Xen I add a new ''case'' in the function arch/x86/plateform_hypercall.c:do_platform_op() that is: .... case XENPF_set_ebda_ptr: { unsigned long ebda_ptr = op->u.set_ebda_ptr.val; unsigned long ptr; /* the ptr value is used to see if the mapping is working */ /* The pointer to the EBDA is stored in the word @ maddr 0x40E(40:0E) */ ptr = *(unsigned short*)maddr_to_virt(ebda_ptr); ptr = (unsigned long)maddr_to_virt(ptr << 4); printk(KERN_INFO "TESTGuill: ptr = 0x%lx \n", ptr); set_gpfn_from_mfn(ebda_ptr, ebda_ptr); } break; .... I also add needed structure. Now, before reading ptr in dom0, I make an hypercall to map machine address 0x40E (value passed in op->u.set_ebda_ptr.val) and I can see in the boot messages the following: (XEN) TESTGuill: ptr = 0xffff830000099000 TESTGuill: ptr = 0xffff880000000000 I expected to see the same value under Xen and under dom0. The value 0xffff830000099000 read under Xen seems OK because it corresponds to 1:1 direct mapping of all physical memory so 0x99000 is the right value. So the question is: Is machine memory mapped in dom0? if not, can I map parts of it? Regards, Guillaume _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Bryan D. Payne
2007-Feb-28 22:30 UTC
Re: [Xen-devel] How to map machine address and pseudo-physical address?
> So the question is: Is machine memory mapped in dom0? if not, can > I map > parts of it?If I understand your question correctly, it sounds like you will want to use the xc_map_foreign_range function from libxc. That function will take an mfn, so you will need to convert the pseudo-physical address and convert it to a machine address first. There are mapping tables in xen to help you do this, but I have only used them for viewing memory from domU, not from the bios. You might find some useful code in XenAccess as much of these techniques are implemented in there. You can download the code from xenaccess.sf.net. Cheers, bryan - Bryan D. Payne Graduate Student, Computer Science Georgia Tech Information Security Center http://www.bryanpayne.org _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Guillaume Thouvenin
2007-Mar-01 08:04 UTC
Re: [Xen-devel] How to map machine address and pseudo-physical address?
On Wed, 28 Feb 2007 17:30:58 -0500 "Bryan D. Payne" <bryan@thepaynes.cc> wrote:> > So the question is: Is machine memory mapped in dom0? if not, can > > I map > > parts of it? > > If I understand your question correctly, it sounds like you will want > to use the xc_map_foreign_range function from libxc.From my understanding (please correct me if I''m wrong), libxc is (more or less) for Xen+dom0 what glibc is for Linux. It''s a set of functions that allows interactions between Xen/Dom0 and other domains. Me, I need to parse machine memory (that contains information provided by BIOS) from Dom0 during Dom0''s boot. As I''m not 100% sure I will have a closer look to your proposition but I think that it doesn''t fit to my need. Thanks for your answer Bryan, Regards, Guillaume _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Bryan D. Payne
2007-Mar-01 14:09 UTC
Re: [Xen-devel] How to map machine address and pseudo-physical address?
> Me, I need to parse machine memory (that contains information provided > by BIOS) from Dom0 during Dom0''s boot.Libxc is just a convenient way to get at this functionality. If you need to map memory while booting dom0, then you can still do this by placing code in the dom0 kernel. You would just need to call the same hypercall that libxc uses to map foreign memory ranges. If you need to do it while booting xen, then you can do similar things inside the hypervisor. -bryan - Bryan D. Payne Graduate Student, Computer Science Georgia Tech Information Security Center http://www.bryanpayne.org _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel