ia64/xen-unstable

changeset 6176:b3d76a75ff20

Less verbose grant tables when xen is verbose.

Signed-off-by: Steven Hand <steven@xensource.com>
author smh22@firebug.cl.cam.ac.uk
date Sun Aug 14 23:20:22 2005 +0000 (2005-08-14)
parents 879ff416adcc
children 01a7cde73390
files xen/common/grant_table.c
line diff
     1.1 --- a/xen/common/grant_table.c	Sun Aug 14 22:56:46 2005 +0000
     1.2 +++ b/xen/common/grant_table.c	Sun Aug 14 23:20:22 2005 +0000
     1.3 @@ -829,14 +829,16 @@ gnttab_donate(gnttab_donate_t *uop, unsi
     1.4                 i, gop->mfn, gop->domid, gop->handle);
     1.5  #endif
     1.6          page = &frame_table[gop->mfn];
     1.7 -
     1.8 +        
     1.9          if (unlikely(IS_XEN_HEAP_FRAME(page))) { 
    1.10 -            printk("gnttab_donate: xen heap frame mfn=%lx\n", (unsigned long) gop->mfn);
    1.11 +            printk("gnttab_donate: xen heap frame mfn=%lx\n", 
    1.12 +                   (unsigned long) gop->mfn);
    1.13              gop->status = GNTST_bad_virt_addr;
    1.14              continue;
    1.15          }
    1.16          if (unlikely(!pfn_valid(page_to_pfn(page)))) {
    1.17 -            printk("gnttab_donate: invalid pfn for mfn=%lx\n", (unsigned long) gop->mfn);
    1.18 +            printk("gnttab_donate: invalid pfn for mfn=%lx\n", 
    1.19 +                   (unsigned long) gop->mfn);
    1.20              gop->status = GNTST_bad_virt_addr;
    1.21              continue;
    1.22          }
    1.23 @@ -862,7 +864,8 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    1.24              if (unlikely((x & (PGC_count_mask|PGC_allocated)) !=
    1.25                           (1 | PGC_allocated)) || unlikely(_nd != _d)) {
    1.26                  printk("gnttab_donate: Bad page values %p: ed=%p(%u), sd=%p,"
    1.27 -                        " caf=%08x, taf=%" PRtype_info "\n", (void *) page_to_pfn(page),
    1.28 +                       " caf=%08x, taf=%" PRtype_info "\n", 
    1.29 +                       (void *) page_to_pfn(page),
    1.30                          d, d->domain_id, unpickle_domptr(_nd), x, 
    1.31                          page->u.inuse.type_info);
    1.32                  spin_unlock(&d->page_alloc_lock);
    1.33 @@ -921,9 +924,9 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    1.34          if (unlikely(test_bit(DOMFLAGS_DYING, &e->domain_flags)) ||
    1.35              unlikely(e->tot_pages == e->max_pages) ||
    1.36              unlikely(!gnttab_prepare_for_transfer(e, d, gop->handle))) {
    1.37 -            printk("gnttab_donate: Transferee has no reservation headroom (%d,%d), or "
    1.38 -                    "provided a bad grant ref (%08x), or is dying (%p).\n",
    1.39 -                    e->tot_pages, e->max_pages, gop->handle, e->d_flags);
    1.40 +            printk("gnttab_donate: Transferee has no reservation headroom (%d,"
    1.41 +                   "%d) or provided a bad grant ref (%08x) or is dying (%p)\n",
    1.42 +                   e->tot_pages, e->max_pages, gop->handle, e->d_flags);
    1.43              spin_unlock(&e->page_alloc_lock);
    1.44              put_domain(e);
    1.45              result = GNTST_general_error;
    1.46 @@ -936,9 +939,9 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    1.47          }
    1.48          list_add_tail(&page->list, &e->page_list);
    1.49          page_set_owner(page, e);
    1.50 -
    1.51 +        
    1.52          spin_unlock(&e->page_alloc_lock);
    1.53 -
    1.54 +        
    1.55          /*
    1.56           * Transfer is all done: tell the guest about its new page
    1.57           * frame.
    1.58 @@ -946,7 +949,7 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    1.59          gnttab_notify_transfer(e, d, gop->handle, gop->mfn);
    1.60          
    1.61          put_domain(e);
    1.62 -
    1.63 +        
    1.64          gop->status = GNTST_okay;
    1.65      }
    1.66      return result;
    1.67 @@ -958,50 +961,52 @@ do_grant_table_op(
    1.68  {
    1.69      long rc;
    1.70      struct domain *d = current->domain;
    1.71 -
    1.72 +    
    1.73      if ( count > 512 )
    1.74          return -EINVAL;
    1.75 -
    1.76 +    
    1.77      LOCK_BIGLOCK(d);
    1.78 -
    1.79 +    
    1.80      sync_pagetable_state(d);
    1.81 -
    1.82 +    
    1.83      rc = -EFAULT;
    1.84      switch ( cmd )
    1.85 -    {
    1.86 -    case GNTTABOP_map_grant_ref:
    1.87 -        if ( unlikely(!array_access_ok(
    1.88 -            uop, count, sizeof(gnttab_map_grant_ref_t))) )
    1.89 -            goto out;
    1.90 -        rc = gnttab_map_grant_ref((gnttab_map_grant_ref_t *)uop, count);
    1.91 -        break;
    1.92 -    case GNTTABOP_unmap_grant_ref:
    1.93 -        if ( unlikely(!array_access_ok(
    1.94 -            uop, count, sizeof(gnttab_unmap_grant_ref_t))) )
    1.95 -            goto out;
    1.96 -        rc = gnttab_unmap_grant_ref((gnttab_unmap_grant_ref_t *)uop, count);
    1.97 -        break;
    1.98 -    case GNTTABOP_setup_table:
    1.99 -        rc = gnttab_setup_table((gnttab_setup_table_t *)uop, count);
   1.100 -        break;
   1.101 +        {
   1.102 +        case GNTTABOP_map_grant_ref:
   1.103 +            if ( unlikely(!array_access_ok(
   1.104 +                              uop, count, sizeof(gnttab_map_grant_ref_t))) )
   1.105 +                goto out;
   1.106 +            rc = gnttab_map_grant_ref((gnttab_map_grant_ref_t *)uop, count);
   1.107 +            break;
   1.108 +        case GNTTABOP_unmap_grant_ref:
   1.109 +            if ( unlikely(!array_access_ok(
   1.110 +                              uop, count, sizeof(gnttab_unmap_grant_ref_t))) )
   1.111 +                goto out;
   1.112 +            rc = gnttab_unmap_grant_ref((gnttab_unmap_grant_ref_t *)uop, 
   1.113 +                                        count);
   1.114 +            break;
   1.115 +        case GNTTABOP_setup_table:
   1.116 +            rc = gnttab_setup_table((gnttab_setup_table_t *)uop, count);
   1.117 +            break;
   1.118  #if GRANT_DEBUG
   1.119 -    case GNTTABOP_dump_table:
   1.120 -        rc = gnttab_dump_table((gnttab_dump_table_t *)uop);
   1.121 -        break;
   1.122 +        case GNTTABOP_dump_table:
   1.123 +            rc = gnttab_dump_table((gnttab_dump_table_t *)uop);
   1.124 +            break;
   1.125  #endif
   1.126 -    case GNTTABOP_donate:
   1.127 -        if (unlikely(!array_access_ok(uop, count, sizeof(gnttab_donate_t))))
   1.128 -            goto out;
   1.129 -        rc = gnttab_donate(uop, count);
   1.130 -        break;
   1.131 -    default:
   1.132 -        rc = -ENOSYS;
   1.133 -        break;
   1.134 -    }
   1.135 -
   1.136 -out:
   1.137 +        case GNTTABOP_donate:
   1.138 +            if (unlikely(!array_access_ok(uop, count, 
   1.139 +                                          sizeof(gnttab_donate_t))))
   1.140 +                goto out;
   1.141 +            rc = gnttab_donate(uop, count);
   1.142 +            break;
   1.143 +        default:
   1.144 +            rc = -ENOSYS;
   1.145 +            break;
   1.146 +        }
   1.147 +    
   1.148 +  out:
   1.149      UNLOCK_BIGLOCK(d);
   1.150 -
   1.151 +    
   1.152      return rc;
   1.153  }
   1.154  
   1.155 @@ -1015,106 +1020,101 @@ gnttab_check_unmap(
   1.156       * Called a _lot_ at domain creation because pages mapped by priv domains
   1.157       * also traverse this.
   1.158       */
   1.159 -
   1.160 +    
   1.161      /* Note: If the same frame is mapped multiple times, and then one of
   1.162       *       the ptes is overwritten, which maptrack handle gets invalidated?
   1.163       * Advice: Don't do it. Explicitly unmap.
   1.164       */
   1.165 -
   1.166 +    
   1.167      unsigned int handle, ref, refcount;
   1.168      grant_table_t        *lgt, *rgt;
   1.169      active_grant_entry_t *act;
   1.170      grant_mapping_t      *map;
   1.171      int found = 0;
   1.172 -
   1.173 +    
   1.174      lgt = ld->grant_table;
   1.175 -
   1.176 +    
   1.177  #if GRANT_DEBUG_VERBOSE
   1.178 -    if ( ld->domain_id != 0 )
   1.179 -    {
   1.180 -        DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   1.181 -                rd->domain_id, ld->domain_id, frame, readonly);
   1.182 -    }
   1.183 +    if ( ld->domain_ id != 0 ) {
   1.184 +            DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   1.185 +                    rd->domain_id, ld->domain_id, frame, readonly);
   1.186 +      }
   1.187  #endif
   1.188 -
   1.189 +    
   1.190      /* Fast exit if we're not mapping anything using grant tables */
   1.191      if ( lgt->map_count == 0 )
   1.192          return 0;
   1.193 -
   1.194 -    if ( get_domain(rd) == 0 )
   1.195 -    {
   1.196 +    
   1.197 +    if ( get_domain(rd) == 0 ) {
   1.198          DPRINTK("gnttab_check_unmap: couldn't get_domain rd(%d)\n",
   1.199                  rd->domain_id);
   1.200          return 0;
   1.201      }
   1.202 -
   1.203 +    
   1.204      rgt = rd->grant_table;
   1.205 +    
   1.206 +    for ( handle = 0; handle < lgt->maptrack_limit; handle++ ) {
   1.207  
   1.208 -    for ( handle = 0; handle < lgt->maptrack_limit; handle++ )
   1.209 -    {
   1.210          map = &lgt->maptrack[handle];
   1.211 -
   1.212 +            
   1.213          if ( map->domid != rd->domain_id )
   1.214              continue;
   1.215 -
   1.216 +        
   1.217          if ( ( map->ref_and_flags & MAPTRACK_GNTMAP_MASK ) &&
   1.218 -             ( readonly ? 1 : (!(map->ref_and_flags & GNTMAP_readonly))))
   1.219 -        {
   1.220 +             ( readonly ? 1 : (!(map->ref_and_flags & GNTMAP_readonly)))) {
   1.221 +
   1.222              ref = (map->ref_and_flags >> MAPTRACK_REF_SHIFT);
   1.223              act = &rgt->active[ref];
   1.224 -
   1.225 +                    
   1.226              spin_lock(&rgt->lock);
   1.227 -
   1.228 -            if ( act->frame != frame )
   1.229 -            {
   1.230 +                    
   1.231 +            if ( act->frame != frame ) {
   1.232                  spin_unlock(&rgt->lock);
   1.233                  continue;
   1.234              }
   1.235 -
   1.236 +                    
   1.237              refcount = act->pin & ( readonly ? GNTPIN_hstr_mask
   1.238 -                                             : GNTPIN_hstw_mask );
   1.239 -            if ( refcount == 0 )
   1.240 -            {
   1.241 +                                    : GNTPIN_hstw_mask );
   1.242 +
   1.243 +            if ( refcount == 0 ) {
   1.244                  spin_unlock(&rgt->lock);
   1.245                  continue;
   1.246              }
   1.247 -
   1.248 +                    
   1.249              /* gotcha */
   1.250              DPRINTK("Grant unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   1.251                      rd->domain_id, ld->domain_id, frame, readonly);
   1.252 -
   1.253 +                    
   1.254              if ( readonly )
   1.255                  act->pin -= GNTPIN_hstr_inc;
   1.256 -            else
   1.257 -            {
   1.258 +            else {
   1.259                  act->pin -= GNTPIN_hstw_inc;
   1.260 -
   1.261 +                            
   1.262                  /* any more granted writable mappings? */
   1.263 -                if ( (act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) == 0 )
   1.264 -                {
   1.265 +                if ( (act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask) == 0)) {
   1.266                      clear_bit(_GTF_writing, &rgt->shared[ref].flags);
   1.267                      put_page_type(&frame_table[frame]);
   1.268                  }
   1.269              }
   1.270 -
   1.271 -            if ( act->pin == 0 )
   1.272 -            {
   1.273 +                
   1.274 +            if ( act->pin == 0 ) {
   1.275                  clear_bit(_GTF_reading, &rgt->shared[ref].flags);
   1.276                  put_page(&frame_table[frame]);
   1.277              }
   1.278 -            spin_unlock(&rgt->lock);
   1.279  
   1.280 +            spin_unlock(&rgt->lock);
   1.281 +                    
   1.282              clear_bit(GNTMAP_host_map, &map->ref_and_flags);
   1.283 -
   1.284 +                    
   1.285              if ( !(map->ref_and_flags & GNTMAP_device_map) )
   1.286                  put_maptrack_handle(lgt, handle);
   1.287 -
   1.288 +                    
   1.289              found = 1;
   1.290              break;
   1.291          }
   1.292      }
   1.293      put_domain(rd);
   1.294 -
   1.295 +    
   1.296      return found;
   1.297  }
   1.298  
   1.299 @@ -1130,8 +1130,10 @@ gnttab_prepare_for_transfer(
   1.300      int            retries = 0;
   1.301      unsigned long  target_pfn;
   1.302  
   1.303 +#ifdef GRANT_DEBUG_VERBOSE
   1.304      DPRINTK("gnttab_prepare_for_transfer rd(%hu) ld(%hu) ref(%hu).\n",
   1.305              rd->domain_id, ld->domain_id, ref);
   1.306 +#endif
   1.307  
   1.308      if ( unlikely((rgt = rd->grant_table) == NULL) ||
   1.309           unlikely(ref >= NR_GRANT_ENTRIES) )
   1.310 @@ -1209,8 +1211,10 @@ gnttab_notify_transfer(
   1.311      grant_entry_t  *sha;
   1.312      unsigned long   pfn;
   1.313  
   1.314 +#ifdef GRANT_DEBUG_VERBOSE
   1.315      DPRINTK("gnttab_notify_transfer rd(%hu) ld(%hu) ref(%hu).\n",
   1.316              rd->domain_id, ld->domain_id, ref);
   1.317 +#endif
   1.318  
   1.319      sha = &rd->grant_table->shared[ref];
   1.320