Randy Thelen
2006-Oct-24 18:33 UTC
[Xen-devel] Can I use xc_map_foreign_range() on a paused domain?
Folks -- I''ve written a pretty simple program to peer into a guest domain and I''m getting an error. I''m wondering what the explanation is and I''m hoping one of you can help. Here''s my program which I wrote in xen- unstable/tools/libxc/ as test.c and linked against the libxenctrl.a: # cat test.c #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include "xenctrl.h" int main(int argc, char **argv) { int xc_handle, dom_id, mfn; unsigned char *p; if (argc != 3) { fprintf(stderr, "USAGE: %s <dom-id> <mfn-within-dom>\n", argv [0]); exit(-1); } dom_id = strtol(argv[1], NULL, 0); mfn = strtol(argv[2], NULL, 0); xc_handle = xc_interface_open(); p = xc_map_foreign_range(xc_handle, dom_id, 4096, PROT_READ| PROT_WRITE, mfn); printf("handle = %d, dom_id = %d, mfn == %#x, p == %p\n", xc_handle, dom_id, mfn, p); if (p) { munmap(p, 4096); } xc_interface_close(xc_handle); return 0; } /* * Local variables: * mode: C * c-set-style: "BSD" * c-basic-offset: 4 * tab-width: 4 * indent-tabs-mode: nil * End: */ Here''s my modification to Makefile to build it: # hg diff Makefile diff -r 0dc4ae151be2 tools/libxc/Makefile --- a/tools/libxc/Makefile Thu Oct 5 08:30:07 2006 +++ b/tools/libxc/Makefile Tue Oct 24 11:12:53 2006 @@ -41,7 +41,7 @@ # Define this to make it possible to run valgrind on code linked with these # libraries. -#CFLAGS += -DVALGRIND -O0 -ggdb3 +CFLAGS += -DVALGRIND -O0 -ggdb3 # Get gcc to generate the dependencies for us. CFLAGS += -Wp,-MD,.$(@F).d @@ -112,6 +112,13 @@ mv staging/i386/*.rpm . rm -rf staging +test: libxenctrl.a test.o + $(CC) $(CFLAGS) $(LDFLAGS) -lxenctrl -o $@ $^ + # libxenctrl libxenctrl.a: $(CTRL_LIB_OBJS) So, make works like expected: # make test gcc -O1 -fno-omit-frame-pointer -g -m32 -march=i686 -Wall -Wstrict- prototypes -Wdeclaration-after-statement -D__XEN_TOOLS__ -Werror - fno-strict-aliasing -I. -DVALGRIND -O0 -ggdb3 -Wp,-MD,.test.o.d -c - o test.o test.c gcc -O1 -fno-omit-frame-pointer -g -m32 -march=i686 -Wall -Wstrict- prototypes -Wdeclaration-after-statement -D__XEN_TOOLS__ -Werror - fno-strict-aliasing -I. -DVALGRIND -O0 -ggdb3 -Wp,-MD,.test.d -L. - lxenctrl -o test libxenctrl.a test.o # And, last, here''s my output with an mfn (which I believe the interface takes as input): # ./test 3 0xd1756 handle = 3, dom_id = 3, mfn == 0xd1756, p == (nil) # For good measure, I tried with pfn: # ./test 3 0x3ae handle = 3, dom_id = 3, mfn == 0x3ae, p == (nil) # To show that my dom is 3: # xm list Name ID Mem(MiB) VCPUs State Time(s) Domain-0 0 694 1 r----- 270.4 rthelen-bsd 3 1200 1 -- p--- 0.0 I determined 0x3ae as being the machine frame page of a page in my domain by using the pt_base of my domain. Note that the link address of my domain is 0xC000.0000: (gdb) p *xen_start_info $1 = {magic = "xen-3.0-x86_32p", ''\0'' <repeats 16 times>, nr_pages = 307200, shared_info = 2310144, flags = 0, store_mfn = 857944, store_evtchn = 1, console_mfn = 857943, console_evtchn = 2, pt_base = 3225083904, nr_pt_frames = 9, mfn_list = 3223842816, mod_start = 0, mod_len = 0, cmd_line = " root=/dev/hda1 ro", ''\0'' <repeats 1005 times>} (gdb) p/x xen_start_info->pt_base $2 = 0xc03ae000 (gdb) p/x $2-0xc0000000 $3 = 0x3ae000 (gdb) p/x ((int *) xen_start_info->mfn_list)[$3>>12] $4 = 0xd1756 So, 0xd1756 is the machine frame number for the physical page 0x3ae. Am I wrong in that basic understanding? Any idea why I can''t access the mfn of my guest domain using xc_map_foreign_range()? -- Randy _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2006-Oct-24 19:24 UTC
Re: [Xen-devel] Can I use xc_map_foreign_range() on a paused domain?
On 24/10/06 7:33 pm, "Randy Thelen" <rthelen@netapp.com> wrote:> I''ve written a pretty simple program to peer into a guest domain and > I''m getting an error. I''m wondering what the explanation is and I''m > hoping one of you can help. Here''s my program which I wrote in xen- > unstable/tools/libxc/ as test.c and linked against the libxenctrl.a:You specifically chose a page-table page. You cannot map that for write access, even in domain 0. If you try to map it read-only, the mapping should succeed. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Randy Thelen
2006-Oct-24 19:57 UTC
Re: [Xen-devel] Can I use xc_map_foreign_range() on a paused domain?
Keir Fraser wrote:> You specifically chose a page-table page. You cannot map that for > write > access, even in domain 0. If you try to map it read-only, the > mapping should > succeed.Excellent. Thank you. -- Randy _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel