diff options
author | iap10@tetris.cl.cam.ac.uk <iap10@tetris.cl.cam.ac.uk> | 2004-08-20 17:46:52 +0000 |
---|---|---|
committer | iap10@tetris.cl.cam.ac.uk <iap10@tetris.cl.cam.ac.uk> | 2004-08-20 17:46:52 +0000 |
commit | 6e92cd3227a9d10e90dea2e4f687f1386d706508 (patch) | |
tree | f56f74b2aad64801c2b422eb94492b2c9f93e23d | |
parent | ec114986f0332aedfb148ca5aa19570bc14c6740 (diff) | |
download | xen-6e92cd3227a9d10e90dea2e4f687f1386d706508.tar.gz xen-6e92cd3227a9d10e90dea2e4f687f1386d706508.tar.bz2 xen-6e92cd3227a9d10e90dea2e4f687f1386d706508.zip |
bitkeeper revision 1.1159.45.15 (4126390c2dSRHYLR3YNd9JysCy4XTw)
Export new mapping interface 'xc_map_foreign'
-rw-r--r-- | tools/libxc/xc.h | 7 | ||||
-rw-r--r-- | tools/libxc/xc_linux_restore.c | 4 | ||||
-rw-r--r-- | tools/libxc/xc_linux_save.c | 37 | ||||
-rw-r--r-- | tools/libxc/xc_private.c | 4 | ||||
-rw-r--r-- | tools/libxc/xc_private.h | 17 | ||||
-rw-r--r-- | tools/python/xen/lowlevel/xu/xu.c | 43 |
6 files changed, 43 insertions, 69 deletions
diff --git a/tools/libxc/xc.h b/tools/libxc/xc.h index 8b54ed0207..0da159d870 100644 --- a/tools/libxc/xc.h +++ b/tools/libxc/xc.h @@ -231,4 +231,11 @@ int xc_domain_setmaxmem(int xc_handle, unsigned int max_memkb); +void *xc_map_foreign_range(int xc_handle, u32 dom, + int size, int prot, + unsigned long mfn ); + +void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot, + unsigned long *arr, int num ); + #endif /* __XC_H__ */ diff --git a/tools/libxc/xc_linux_restore.c b/tools/libxc/xc_linux_restore.c index 6d4f0906aa..3c984b4f19 100644 --- a/tools/libxc/xc_linux_restore.c +++ b/tools/libxc/xc_linux_restore.c @@ -325,7 +325,7 @@ int xc_linux_restore(int xc_handle, XcIOContext *ioctxt) } } - if ( (region_base = mfn_mapper_map_batch( xc_handle, dom, + if ( (region_base = xc_map_foreign_batch( xc_handle, dom, PROT_WRITE, region_mfn, j )) == 0 ) @@ -631,7 +631,7 @@ printf("XXXXXXXXXXXXXXX pin L2\n"); } if ( (live_pfn_to_mfn_table = - mfn_mapper_map_batch(xc_handle, dom, + xc_map_foreign_batch(xc_handle, dom, PROT_WRITE, pfn_to_mfn_frame_list, (nr_pfns+1023)/1024 )) == 0 ) diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c index cfcc6cd0c8..57b4f1ab56 100644 --- a/tools/libxc/xc_linux_save.c +++ b/tools/libxc/xc_linux_save.c @@ -30,18 +30,8 @@ /* * Returns TRUE if the given machine frame number has a unique mapping * in the guest's pseudophysical map. - * 0x80000000-3 mark the shared_info, and blk/net rings */ -#if 0 -#define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn) \ - (((_mfn) < (1024*1024)) && \ - (((live_mfn_to_pfn_table[_mfn] < nr_pfns) && \ - (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == (_mfn))) || \ - ((live_mfn_to_pfn_table[_mfn] >= 0x80000000) && \ - (live_mfn_to_pfn_table[_mfn] <= 0x80000003)) || \ - (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == 0x80000004))) -#endif #define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn) \ (((_mfn) < (1024*1024)) && \ ((live_mfn_to_pfn_table[_mfn] < nr_pfns) && \ @@ -60,6 +50,8 @@ _res; \ }) +#define is_mapped(pfn) (!((pfn) & 0x80000000UL)) + static inline int test_bit ( int nr, volatile void * addr) { return (((unsigned long*)addr)[nr/(sizeof(unsigned long)*8)] >> @@ -384,7 +376,7 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) /* Map the shared info frame */ - live_shinfo = mfn_mapper_map_single(xc_handle, domid, + live_shinfo = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, PROT_READ, shared_info_frame); @@ -395,7 +387,7 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) /* the pfn_to_mfn_frame_list fits in a single page */ live_pfn_to_mfn_frame_list = - mfn_mapper_map_single(xc_handle, domid, + xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, PROT_READ, live_shinfo->arch.pfn_to_mfn_frame_list ); @@ -410,7 +402,7 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) (its not clear why it would want to change them, and we'll be OK from a safety POV anyhow. */ - live_pfn_to_mfn_table = mfn_mapper_map_batch(xc_handle, domid, + live_pfn_to_mfn_table = xc_map_foreign_batch(xc_handle, domid, PROT_READ, live_pfn_to_mfn_frame_list, (nr_pfns+1023)/1024 ); @@ -421,12 +413,12 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt) /* Setup the mfn_to_pfn table mapping */ mfn_to_pfn_table_start_mfn = xc_get_m2p_start_mfn( xc_handle ); - +printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); live_mfn_to_pfn_table = - mfn_mapper_map_single(xc_handle, DOMID_XEN, + xc_map_foreign_range(xc_handle, DOMID_XEN, PAGE_SIZE*1024, PROT_READ, mfn_to_pfn_table_start_mfn ); - +printf("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); /* Canonicalise the pfn-to-mfn table frame-number list. */ memcpy( pfn_to_mfn_frame_list, live_pfn_to_mfn_frame_list, PAGE_SIZE ); @@ -530,7 +522,7 @@ printf("GO LIVE!!\n"); { mfn = live_pfn_to_mfn_table[i]; - if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0x80000001) ) + if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0xffffffffUL) ) { printf("i=0x%x mfn=%lx live_mfn_to_pfn_table=%lx\n", i,mfn,live_mfn_to_pfn_table[mfn]); @@ -629,7 +621,8 @@ printf("GO LIVE!!\n"); pfn_batch[batch] = n; pfn_type[batch] = live_pfn_to_mfn_table[n]; - if( pfn_type[batch] == 0x80000001 ){ + if( ! is_mapped(pfn_type[batch]) ) + { /* not currently in pusedo-physical map -- set bit in to_fix that we must send this page in last_iter unless its sent sooner anyhow */ @@ -660,7 +653,7 @@ printf("GO LIVE!!\n"); if ( batch == 0 ) goto skip; /* vanishingly unlikely... */ - if ( (region_base = mfn_mapper_map_batch(xc_handle, domid, + if ( (region_base = xc_map_foreign_batch(xc_handle, domid, PROT_READ, pfn_type, batch)) == 0 ){ @@ -870,7 +863,7 @@ printf("type fail: page %i mfn %08lx\n",j,pfn_type[j]); for ( i = 0, j = 0; i < nr_pfns; i++ ) { - if ( live_pfn_to_mfn_table[i] >= 0x80000000UL ) + if ( ! is_mapped(live_pfn_to_mfn_table[i]) ) j++; } @@ -882,7 +875,7 @@ printf("type fail: page %i mfn %08lx\n",j,pfn_type[j]); for ( i = 0, j = 0; i < nr_pfns; ) { - if ( live_pfn_to_mfn_table[i] >= 0x80000000UL ) + if ( ! is_mapped(live_pfn_to_mfn_table[i]) ) { pfntab[j++] = i; } @@ -901,7 +894,7 @@ printf("type fail: page %i mfn %08lx\n",j,pfn_type[j]); /* Map the suspend-record MFN to pin it. The page must be owned by domid for this to succeed. */ - p_srec = mfn_mapper_map_single(xc_handle, domid, + p_srec = xc_map_foreign_range(xc_handle, domid, sizeof(*p_srec), PROT_READ, ctxt.cpu_ctxt.esi); if (!p_srec){ diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index 47d2fa5230..795ac6e83b 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -133,7 +133,7 @@ void unmap_pfn(void *pm_handle, void *vaddr) /*******************/ -void *mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot, +void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot, unsigned long *arr, int num ) { privcmd_mmapbatch_t ioctlx; @@ -158,7 +158,7 @@ void *mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot, /*******************/ -void *mfn_mapper_map_single(int xc_handle, domid_t dom, +void *xc_map_foreign_range(int xc_handle, u32 dom, int size, int prot, unsigned long mfn ) { diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index d70f7df58a..9da98a25ab 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -220,23 +220,6 @@ typedef struct mfn_mapper { } mfn_mapper_t; -void * mfn_mapper_map_single(int xc_handle, domid_t dom, int size, int prot, - unsigned long mfn ); - -void * mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot, - unsigned long *arr, int num ); - -mfn_mapper_t * mfn_mapper_init(int xc_handle, domid_t dom, int size, int prot); - -void * mfn_mapper_base(mfn_mapper_t *t); - -void mfn_mapper_close(mfn_mapper_t *t); - -int mfn_mapper_flush_queue(mfn_mapper_t *t); - -void * mfn_mapper_queue_entry(mfn_mapper_t *t, int offset, - unsigned long mfn, int size ); - long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid ); #include "xc_io.h" diff --git a/tools/python/xen/lowlevel/xu/xu.c b/tools/python/xen/lowlevel/xu/xu.c index 3b078e7d33..344cb8cc4b 100644 --- a/tools/python/xen/lowlevel/xu/xu.c +++ b/tools/python/xen/lowlevel/xu/xu.c @@ -679,11 +679,12 @@ static PyTypeObject xu_message_type = { * *********************** PORT *********************** */ -static control_if_t *map_control_interface(int fd, unsigned long pfn) +static control_if_t *map_control_interface(int fd, unsigned long pfn, + u32 dom) { - char *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, - MAP_SHARED, fd, pfn * PAGE_SIZE); - if ( vaddr == MAP_FAILED ) + char *vaddr = xc_map_foreign_range( fd, dom, PAGE_SIZE, + PROT_READ|PROT_WRITE, pfn ); + if ( vaddr == NULL ) return NULL; return (control_if_t *)(vaddr + 2048); } @@ -695,8 +696,8 @@ static void unmap_control_interface(int fd, control_if_t *c) typedef struct xu_port_object { PyObject_HEAD; - int mem_fd; int xc_handle; + int connected; u32 remote_dom; int local_port, remote_port; control_if_t *interface; @@ -908,35 +909,25 @@ static int __xu_port_connect(xu_port_object *xup) { xc_dominfo_t info; - if ( xup->mem_fd != -1 ) - return 0; - - if ( (xup->mem_fd = open("/dev/mem", O_RDWR)) == -1 ) + if ( xup->connected ) { - PyErr_SetString(port_error, "Could not open '/dev/mem'"); - return -1; + return 0; } - set_cloexec(xup->mem_fd); - - /* Set the General-Purpose Subject whose page frame will be mapped. */ - (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)xup->remote_dom); if ( (xc_domain_getinfo(xup->xc_handle, xup->remote_dom, 1, &info) != 1) || (info.domid != xup->remote_dom) ) { PyErr_SetString(port_error, "Failed to obtain domain status"); - (void)close(xup->mem_fd); - xup->mem_fd = -1; return -1; } xup->interface = - map_control_interface(xup->mem_fd, info.shared_info_frame); + map_control_interface(xup->xc_handle, info.shared_info_frame, + xup->remote_dom); + if ( xup->interface == NULL ) { PyErr_SetString(port_error, "Failed to map domain control interface"); - (void)close(xup->mem_fd); - xup->mem_fd = -1; return -1; } @@ -946,16 +937,16 @@ static int __xu_port_connect(xu_port_object *xup) xup->rx_req_prod = xup->interface->rx_req_prod; xup->rx_resp_cons = xup->interface->rx_resp_prod; + xup->connected = 1; + return 0; } static void __xu_port_disconnect(xu_port_object *xup) { - if ( xup->mem_fd == -1 ) - return; - unmap_control_interface(xup->mem_fd, xup->interface); - (void)close(xup->mem_fd); - xup->mem_fd = -1; + if ( xup->connected ) + unmap_control_interface(xup->xc_handle, xup->interface); + xup->connected = 0; } static PyObject *xu_port_connect(PyObject *self, PyObject *args) @@ -1057,8 +1048,8 @@ static PyObject *xu_port_new(PyObject *self, PyObject *args) xup = PyObject_New(xu_port_object, &xu_port_type); + xup->connected = 0; xup->remote_dom = dom; - xup->mem_fd = -1; /* currently disconnected */ if ( (xup->xc_handle = xc_interface_open()) == -1 ) { |