direct-io.hg

changeset 2325:5678a9fdb972

bitkeeper revision 1.1159.45.15 (4126390c2dSRHYLR3YNd9JysCy4XTw)

Export new mapping interface 'xc_map_foreign'
author iap10@tetris.cl.cam.ac.uk
date Fri Aug 20 17:46:52 2004 +0000 (2004-08-20)
parents f606a346ef33
children 9cb13e3d3f3a
files tools/libxc/xc.h tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/python/xen/lowlevel/xu/xu.c
line diff
     1.1 --- a/tools/libxc/xc.h	Fri Aug 20 16:42:16 2004 +0000
     1.2 +++ b/tools/libxc/xc.h	Fri Aug 20 17:46:52 2004 +0000
     1.3 @@ -231,4 +231,11 @@ int xc_domain_setmaxmem(int xc_handle,
     1.4                              unsigned int max_memkb);
     1.5  
     1.6  
     1.7 +void *xc_map_foreign_range(int xc_handle, u32 dom,
     1.8 +                            int size, int prot,
     1.9 +                            unsigned long mfn );
    1.10 +
    1.11 +void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
    1.12 +                           unsigned long *arr, int num );
    1.13 +
    1.14  #endif /* __XC_H__ */
     2.1 --- a/tools/libxc/xc_linux_restore.c	Fri Aug 20 16:42:16 2004 +0000
     2.2 +++ b/tools/libxc/xc_linux_restore.c	Fri Aug 20 17:46:52 2004 +0000
     2.3 @@ -325,7 +325,7 @@ int xc_linux_restore(int xc_handle, XcIO
     2.4              }          
     2.5          }
     2.6   
     2.7 -        if ( (region_base = mfn_mapper_map_batch( xc_handle, dom, 
     2.8 +        if ( (region_base = xc_map_foreign_batch( xc_handle, dom, 
     2.9                                                    PROT_WRITE,
    2.10                                                    region_mfn,
    2.11                                                    j )) == 0 )
    2.12 @@ -631,7 +631,7 @@ printf("XXXXXXXXXXXXXXX pin L2\n");
    2.13      }
    2.14      
    2.15      if ( (live_pfn_to_mfn_table = 
    2.16 -          mfn_mapper_map_batch(xc_handle, dom, 
    2.17 +	  xc_map_foreign_batch(xc_handle, dom, 
    2.18                                 PROT_WRITE,
    2.19                                 pfn_to_mfn_frame_list,
    2.20                                 (nr_pfns+1023)/1024 )) == 0 )
     3.1 --- a/tools/libxc/xc_linux_save.c	Fri Aug 20 16:42:16 2004 +0000
     3.2 +++ b/tools/libxc/xc_linux_save.c	Fri Aug 20 17:46:52 2004 +0000
     3.3 @@ -30,18 +30,8 @@
     3.4  /*
     3.5   * Returns TRUE if the given machine frame number has a unique mapping
     3.6   * in the guest's pseudophysical map.
     3.7 - * 0x80000000-3 mark the shared_info, and blk/net rings
     3.8   */
     3.9  
    3.10 -#if 0 
    3.11 -#define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn)                                    \
    3.12 -    (((_mfn) < (1024*1024)) &&                                            \
    3.13 -     (((live_mfn_to_pfn_table[_mfn] < nr_pfns) &&                         \
    3.14 -       (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == (_mfn))) || \
    3.15 -      ((live_mfn_to_pfn_table[_mfn] >= 0x80000000) &&                     \
    3.16 -       (live_mfn_to_pfn_table[_mfn] <= 0x80000003)) ||                    \
    3.17 -      (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == 0x80000004)))
    3.18 -#endif
    3.19  #define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn)                                    \
    3.20      (((_mfn) < (1024*1024)) &&                                            \
    3.21       ((live_mfn_to_pfn_table[_mfn] < nr_pfns) &&                         \
    3.22 @@ -60,6 +50,8 @@
    3.23      _res;                                      \
    3.24  })
    3.25  
    3.26 +#define is_mapped(pfn) (!((pfn) & 0x80000000UL))
    3.27 +
    3.28  static inline int test_bit ( int nr, volatile void * addr)
    3.29  {
    3.30      return (((unsigned long*)addr)[nr/(sizeof(unsigned long)*8)] >> 
    3.31 @@ -384,7 +376,7 @@ int xc_linux_save(int xc_handle, XcIOCon
    3.32  
    3.33  
    3.34      /* Map the shared info frame */
    3.35 -    live_shinfo = mfn_mapper_map_single(xc_handle, domid,
    3.36 +    live_shinfo = xc_map_foreign_range(xc_handle, domid,
    3.37                                          PAGE_SIZE, PROT_READ,
    3.38                                          shared_info_frame);
    3.39  
    3.40 @@ -395,7 +387,7 @@ int xc_linux_save(int xc_handle, XcIOCon
    3.41  
    3.42      /* the pfn_to_mfn_frame_list fits in a single page */
    3.43      live_pfn_to_mfn_frame_list = 
    3.44 -        mfn_mapper_map_single(xc_handle, domid, 
    3.45 +        xc_map_foreign_range(xc_handle, domid, 
    3.46                                PAGE_SIZE, PROT_READ, 
    3.47                                live_shinfo->arch.pfn_to_mfn_frame_list );
    3.48  
    3.49 @@ -410,7 +402,7 @@ int xc_linux_save(int xc_handle, XcIOCon
    3.50         (its not clear why it would want to change them, and we'll be OK
    3.51         from a safety POV anyhow. */
    3.52  
    3.53 -    live_pfn_to_mfn_table = mfn_mapper_map_batch(xc_handle, domid, 
    3.54 +    live_pfn_to_mfn_table = xc_map_foreign_batch(xc_handle, domid, 
    3.55                                                   PROT_READ,
    3.56                                                   live_pfn_to_mfn_frame_list,
    3.57                                                   (nr_pfns+1023)/1024 );  
    3.58 @@ -421,12 +413,12 @@ int xc_linux_save(int xc_handle, XcIOCon
    3.59  
    3.60      /* Setup the mfn_to_pfn table mapping */
    3.61      mfn_to_pfn_table_start_mfn = xc_get_m2p_start_mfn( xc_handle );
    3.62 -
    3.63 +printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
    3.64      live_mfn_to_pfn_table = 
    3.65 -	mfn_mapper_map_single(xc_handle, DOMID_XEN, 
    3.66 +	xc_map_foreign_range(xc_handle, DOMID_XEN, 
    3.67  			      PAGE_SIZE*1024, PROT_READ, 
    3.68  			      mfn_to_pfn_table_start_mfn );
    3.69 -
    3.70 +printf("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");
    3.71      /* Canonicalise the pfn-to-mfn table frame-number list. */
    3.72      memcpy( pfn_to_mfn_frame_list, live_pfn_to_mfn_frame_list, PAGE_SIZE );
    3.73  
    3.74 @@ -530,7 +522,7 @@ printf("GO LIVE!!\n");
    3.75  	{
    3.76  	    mfn = live_pfn_to_mfn_table[i];
    3.77  	    
    3.78 -	    if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0x80000001) )
    3.79 +	    if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0xffffffffUL) )
    3.80  	    {
    3.81  		printf("i=0x%x mfn=%lx live_mfn_to_pfn_table=%lx\n",
    3.82  		       i,mfn,live_mfn_to_pfn_table[mfn]);
    3.83 @@ -629,7 +621,8 @@ printf("GO LIVE!!\n");
    3.84                  pfn_batch[batch] = n;
    3.85                  pfn_type[batch] = live_pfn_to_mfn_table[n];
    3.86  
    3.87 -                if( pfn_type[batch] == 0x80000001 ){
    3.88 +                if( ! is_mapped(pfn_type[batch]) )
    3.89 +		{
    3.90                      /* not currently in pusedo-physical map -- set bit
    3.91                         in to_fix that we must send this page in last_iter
    3.92                         unless its sent sooner anyhow */
    3.93 @@ -660,7 +653,7 @@ printf("GO LIVE!!\n");
    3.94              if ( batch == 0 )
    3.95                  goto skip; /* vanishingly unlikely... */
    3.96        
    3.97 -            if ( (region_base = mfn_mapper_map_batch(xc_handle, domid, 
    3.98 +            if ( (region_base = xc_map_foreign_batch(xc_handle, domid, 
    3.99                                                       PROT_READ,
   3.100                                                       pfn_type,
   3.101                                                       batch)) == 0 ){
   3.102 @@ -870,7 +863,7 @@ printf("type fail: page %i mfn %08lx\n",
   3.103  
   3.104  	for ( i = 0, j = 0; i < nr_pfns; i++ )
   3.105  	{
   3.106 -	    if ( live_pfn_to_mfn_table[i] >= 0x80000000UL )
   3.107 +	    if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
   3.108  		j++;
   3.109  	}
   3.110  
   3.111 @@ -882,7 +875,7 @@ printf("type fail: page %i mfn %08lx\n",
   3.112  
   3.113  	for ( i = 0, j = 0; i < nr_pfns; )
   3.114  	{
   3.115 -	    if ( live_pfn_to_mfn_table[i] >= 0x80000000UL )
   3.116 +	    if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
   3.117  	    {
   3.118  		pfntab[j++] = i;
   3.119  	    }
   3.120 @@ -901,7 +894,7 @@ printf("type fail: page %i mfn %08lx\n",
   3.121  
   3.122      /* Map the suspend-record MFN to pin it. The page must be owned by 
   3.123         domid for this to succeed. */
   3.124 -    p_srec = mfn_mapper_map_single(xc_handle, domid,
   3.125 +    p_srec = xc_map_foreign_range(xc_handle, domid,
   3.126                                     sizeof(*p_srec), PROT_READ, 
   3.127                                     ctxt.cpu_ctxt.esi);
   3.128      if (!p_srec){
     4.1 --- a/tools/libxc/xc_private.c	Fri Aug 20 16:42:16 2004 +0000
     4.2 +++ b/tools/libxc/xc_private.c	Fri Aug 20 17:46:52 2004 +0000
     4.3 @@ -133,7 +133,7 @@ void unmap_pfn(void *pm_handle, void *va
     4.4  
     4.5  /*******************/
     4.6  
     4.7 -void *mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
     4.8 +void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
     4.9                             unsigned long *arr, int num )
    4.10  {
    4.11      privcmd_mmapbatch_t ioctlx; 
    4.12 @@ -158,7 +158,7 @@ void *mfn_mapper_map_batch(int xc_handle
    4.13  
    4.14  /*******************/
    4.15  
    4.16 -void *mfn_mapper_map_single(int xc_handle, domid_t dom,
    4.17 +void *xc_map_foreign_range(int xc_handle, u32 dom,
    4.18                              int size, int prot,
    4.19                              unsigned long mfn )
    4.20  {
     5.1 --- a/tools/libxc/xc_private.h	Fri Aug 20 16:42:16 2004 +0000
     5.2 +++ b/tools/libxc/xc_private.h	Fri Aug 20 17:46:52 2004 +0000
     5.3 @@ -220,23 +220,6 @@ typedef struct mfn_mapper {
     5.4      
     5.5  } mfn_mapper_t;
     5.6  
     5.7 -void * mfn_mapper_map_single(int xc_handle, domid_t dom, int size, int prot, 
     5.8 -			     unsigned long mfn );
     5.9 -
    5.10 -void * mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
    5.11 -			    unsigned long *arr, int num );
    5.12 -
    5.13 -mfn_mapper_t * mfn_mapper_init(int xc_handle, domid_t dom, int size, int prot);
    5.14 -
    5.15 -void * mfn_mapper_base(mfn_mapper_t *t);
    5.16 -
    5.17 -void mfn_mapper_close(mfn_mapper_t *t);
    5.18 -
    5.19 -int mfn_mapper_flush_queue(mfn_mapper_t *t);
    5.20 -
    5.21 -void * mfn_mapper_queue_entry(mfn_mapper_t *t, int offset, 
    5.22 -			      unsigned long mfn, int size );
    5.23 -
    5.24  long long  xc_domain_get_cpu_usage( int xc_handle, domid_t domid );
    5.25  
    5.26  #include "xc_io.h"
     6.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Fri Aug 20 16:42:16 2004 +0000
     6.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Fri Aug 20 17:46:52 2004 +0000
     6.3 @@ -679,11 +679,12 @@ static PyTypeObject xu_message_type = {
     6.4   * *********************** PORT ***********************
     6.5   */
     6.6  
     6.7 -static control_if_t *map_control_interface(int fd, unsigned long pfn)
     6.8 +static control_if_t *map_control_interface(int fd, unsigned long pfn,
     6.9 +					   u32 dom)
    6.10  {
    6.11 -    char *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE,
    6.12 -                       MAP_SHARED, fd, pfn * PAGE_SIZE);
    6.13 -    if ( vaddr == MAP_FAILED )
    6.14 +    char *vaddr = xc_map_foreign_range( fd, dom, PAGE_SIZE,
    6.15 +					PROT_READ|PROT_WRITE, pfn );
    6.16 +    if ( vaddr == NULL )
    6.17          return NULL;
    6.18      return (control_if_t *)(vaddr + 2048);
    6.19  }
    6.20 @@ -695,8 +696,8 @@ static void unmap_control_interface(int 
    6.21  
    6.22  typedef struct xu_port_object {
    6.23      PyObject_HEAD;
    6.24 -    int mem_fd;
    6.25      int xc_handle;
    6.26 +    int connected;
    6.27      u32 remote_dom;
    6.28      int local_port, remote_port;
    6.29      control_if_t    *interface;
    6.30 @@ -908,35 +909,25 @@ static int __xu_port_connect(xu_port_obj
    6.31  {
    6.32      xc_dominfo_t info;
    6.33  
    6.34 -    if ( xup->mem_fd != -1 )
    6.35 -        return 0;
    6.36 -
    6.37 -    if ( (xup->mem_fd = open("/dev/mem", O_RDWR)) == -1 )
    6.38 +    if ( xup->connected )
    6.39      {
    6.40 -        PyErr_SetString(port_error, "Could not open '/dev/mem'");
    6.41 -        return -1;
    6.42 +	return 0;
    6.43      }
    6.44 -    set_cloexec(xup->mem_fd);
    6.45 -
    6.46 -    /* Set the General-Purpose Subject whose page frame will be mapped. */
    6.47 -    (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)xup->remote_dom);
    6.48  
    6.49      if ( (xc_domain_getinfo(xup->xc_handle, xup->remote_dom, 1, &info) != 1) ||
    6.50           (info.domid != xup->remote_dom) )
    6.51      {
    6.52          PyErr_SetString(port_error, "Failed to obtain domain status");
    6.53 -        (void)close(xup->mem_fd);
    6.54 -        xup->mem_fd = -1;
    6.55          return -1;
    6.56      }
    6.57  
    6.58      xup->interface = 
    6.59 -        map_control_interface(xup->mem_fd, info.shared_info_frame);
    6.60 +        map_control_interface(xup->xc_handle, info.shared_info_frame,
    6.61 +			      xup->remote_dom);
    6.62 +
    6.63      if ( xup->interface == NULL )
    6.64      {
    6.65          PyErr_SetString(port_error, "Failed to map domain control interface");
    6.66 -        (void)close(xup->mem_fd);
    6.67 -        xup->mem_fd = -1;
    6.68          return -1;
    6.69      }
    6.70  
    6.71 @@ -946,16 +937,16 @@ static int __xu_port_connect(xu_port_obj
    6.72      xup->rx_req_prod  = xup->interface->rx_req_prod;
    6.73      xup->rx_resp_cons = xup->interface->rx_resp_prod;
    6.74  
    6.75 +    xup->connected = 1;
    6.76 +
    6.77      return 0;
    6.78  }
    6.79  
    6.80  static void __xu_port_disconnect(xu_port_object *xup)
    6.81  {
    6.82 -    if ( xup->mem_fd == -1 )
    6.83 -        return;
    6.84 -    unmap_control_interface(xup->mem_fd, xup->interface);
    6.85 -    (void)close(xup->mem_fd);
    6.86 -    xup->mem_fd = -1;
    6.87 +    if ( xup->connected )
    6.88 +	unmap_control_interface(xup->xc_handle, xup->interface);
    6.89 +    xup->connected = 0;
    6.90  }
    6.91  
    6.92  static PyObject *xu_port_connect(PyObject *self, PyObject *args)
    6.93 @@ -1057,8 +1048,8 @@ static PyObject *xu_port_new(PyObject *s
    6.94  
    6.95      xup = PyObject_New(xu_port_object, &xu_port_type);
    6.96  
    6.97 +    xup->connected  = 0;
    6.98      xup->remote_dom = dom;
    6.99 -    xup->mem_fd     = -1; /* currently disconnected */
   6.100  
   6.101      if ( (xup->xc_handle = xc_interface_open()) == -1 )
   6.102      {