ia64/xen-unstable

changeset 7042:7ff651a39cfc

Restructure GNTTABOP_map_grant_ref.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Sep 23 16:28:17 2005 +0100 (2005-09-23)
parents 352151393395
children ad0270abc9b9
files xen/arch/x86/mm.c xen/common/grant_table.c xen/include/asm-x86/mm.h xen/include/xen/grant_table.h
line diff
     1.1 --- a/xen/arch/x86/mm.c	Fri Sep 23 14:43:52 2005 +0100
     1.2 +++ b/xen/arch/x86/mm.c	Fri Sep 23 16:28:17 2005 +0100
     1.3 @@ -2273,8 +2273,7 @@ int do_mmu_update(
     1.4  
     1.5  
     1.6  int update_grant_pte_mapping(
     1.7 -    unsigned long pte_addr, l1_pgentry_t _nl1e, 
     1.8 -    struct domain *d, struct vcpu *v)
     1.9 +    unsigned long pte_addr, l1_pgentry_t _nl1e, struct vcpu *v)
    1.10  {
    1.11      int rc = GNTST_okay;
    1.12      void *va;
    1.13 @@ -2282,6 +2281,7 @@ int update_grant_pte_mapping(
    1.14      struct pfn_info *page;
    1.15      u32 type_info;
    1.16      l1_pgentry_t ol1e;
    1.17 +    struct domain *d = v->domain;
    1.18  
    1.19      ASSERT(spin_is_locked(&d->big_lock));
    1.20      ASSERT(!shadow_mode_refcounts(d));
    1.21 @@ -2319,8 +2319,6 @@ int update_grant_pte_mapping(
    1.22  
    1.23      put_page_from_l1e(ol1e, d);
    1.24  
    1.25 -    rc = (l1e_get_flags(ol1e) & _PAGE_PRESENT) ? GNTST_flush_all : GNTST_okay;
    1.26 -
    1.27      if ( unlikely(shadow_mode_enabled(d)) )
    1.28      {
    1.29          struct domain_mmap_cache sh_mapcache;
    1.30 @@ -2415,10 +2413,10 @@ int clear_grant_pte_mapping(
    1.31  
    1.32  
    1.33  int update_grant_va_mapping(
    1.34 -    unsigned long va, l1_pgentry_t _nl1e, struct domain *d, struct vcpu *v)
    1.35 +    unsigned long va, l1_pgentry_t _nl1e, struct vcpu *v)
    1.36  {
    1.37 -    int rc = GNTST_okay;
    1.38      l1_pgentry_t *pl1e, ol1e;
    1.39 +    struct domain *d = v->domain;
    1.40      
    1.41      ASSERT(spin_is_locked(&d->big_lock));
    1.42      ASSERT(!shadow_mode_refcounts(d));
    1.43 @@ -2439,12 +2437,10 @@ int update_grant_va_mapping(
    1.44  
    1.45      put_page_from_l1e(ol1e, d);
    1.46  
    1.47 -    rc = (l1e_get_flags(ol1e) & _PAGE_PRESENT) ? GNTST_flush_one : GNTST_okay;
    1.48 -
    1.49      if ( unlikely(shadow_mode_enabled(d)) )
    1.50          shadow_do_update_va_mapping(va, _nl1e, v);
    1.51  
    1.52 -    return rc;
    1.53 +    return GNTST_okay;
    1.54  }
    1.55  
    1.56  int clear_grant_va_mapping(unsigned long addr, unsigned long frame)
     2.1 --- a/xen/common/grant_table.c	Fri Sep 23 14:43:52 2005 +0100
     2.2 +++ b/xen/common/grant_table.c	Fri Sep 23 16:28:17 2005 +0100
     2.3 @@ -24,10 +24,6 @@
     2.4   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.5   */
     2.6  
     2.7 -#define GRANT_DEBUG 0
     2.8 -#define GRANT_DEBUG_VERBOSE 0
     2.9 -
    2.10 -#include <xen/config.h>
    2.11  #include <xen/lib.h>
    2.12  #include <xen/sched.h>
    2.13  #include <xen/shadow.h>
    2.14 @@ -68,39 +64,32 @@ put_maptrack_handle(
    2.15      t->map_count--;
    2.16  }
    2.17  
    2.18 +/*
    2.19 + * Returns 0 if TLB flush / invalidate required by caller.
    2.20 + * va will indicate the address to be invalidated.
    2.21 + * 
    2.22 + * addr is _either_ a host virtual address, or the address of the pte to
    2.23 + * update, as indicated by the GNTMAP_contains_pte flag.
    2.24 + */
    2.25  static int
    2.26 -__gnttab_activate_grant_ref(
    2.27 -    struct domain   *mapping_d,          /* IN */
    2.28 -    struct vcpu     *mapping_ed,
    2.29 -    struct domain   *granting_d,
    2.30 -    grant_ref_t      ref,
    2.31 -    u16              dev_hst_ro_flags,
    2.32 -    u64              addr,
    2.33 -    unsigned long   *pframe )            /* OUT */
    2.34 +__gnttab_map_grant_ref(
    2.35 +    gnttab_map_grant_ref_t *uop)
    2.36  {
    2.37 -    domid_t               sdom;
    2.38 -    u16                   sflags;
    2.39 +    domid_t        dom;
    2.40 +    grant_ref_t    ref;
    2.41 +    struct domain *ld, *rd;
    2.42 +    struct vcpu   *led;
    2.43 +    u16            dev_hst_ro_flags;
    2.44 +    int            handle;
    2.45 +    u64            addr;
    2.46 +    unsigned long  frame = 0;
    2.47 +    int            rc;
    2.48      active_grant_entry_t *act;
    2.49 -    grant_entry_t        *sha;
    2.50 -    s16                   rc = 1;
    2.51 -    unsigned long         frame = 0;
    2.52 -    int                   retries = 0;
    2.53  
    2.54 -    /*
    2.55 -     * Objectives of this function:
    2.56 -     * . Make the record ( granting_d, ref ) active, if not already.
    2.57 -     * . Update shared grant entry of owner, indicating frame is mapped.
    2.58 -     * . Increment the owner act->pin reference counts.
    2.59 -     * . get_page on shared frame if new mapping.
    2.60 -     * . get_page_type if this is first RW mapping of frame.
    2.61 -     * . Add PTE to virtual address space of mapping_d, if necessary.
    2.62 -     * Returns:
    2.63 -     * .  -ve: error
    2.64 -     * .    1: ok
    2.65 -     * .    0: ok and TLB invalidate of host_addr needed.
    2.66 -     *
    2.67 -     * On success, *pframe contains mfn.
    2.68 -     */
    2.69 +    /* Entry details from @rd's shared grant table. */
    2.70 +    grant_entry_t *sha;
    2.71 +    domid_t        sdom;
    2.72 +    u16            sflags;
    2.73  
    2.74      /*
    2.75       * We bound the number of times we retry CMPXCHG on memory locations that
    2.76 @@ -110,11 +99,88 @@ static int
    2.77       * the guest to race our updates (e.g., to change the GTF_readonly flag),
    2.78       * so we allow a few retries before failing.
    2.79       */
    2.80 +    int retries = 0;
    2.81  
    2.82 -    act = &granting_d->grant_table->active[ref];
    2.83 -    sha = &granting_d->grant_table->shared[ref];
    2.84 +    led = current;
    2.85 +    ld = led->domain;
    2.86  
    2.87 -    spin_lock(&granting_d->grant_table->lock);
    2.88 +    /* Bitwise-OR avoids short-circuiting which screws control flow. */
    2.89 +    if ( unlikely(__get_user(dom, &uop->dom) |
    2.90 +                  __get_user(ref, &uop->ref) |
    2.91 +                  __get_user(addr, &uop->host_addr) |
    2.92 +                  __get_user(dev_hst_ro_flags, &uop->flags)) )
    2.93 +    {
    2.94 +        DPRINTK("Fault while reading gnttab_map_grant_ref_t.\n");
    2.95 +        return -EFAULT; /* don't set status */
    2.96 +    }
    2.97 +
    2.98 +    if ( unlikely(ref >= NR_GRANT_ENTRIES) ||
    2.99 +         unlikely((dev_hst_ro_flags &
   2.100 +                   (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
   2.101 +    {
   2.102 +        DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
   2.103 +        (void)__put_user(GNTST_bad_gntref, &uop->handle);
   2.104 +        return GNTST_bad_gntref;
   2.105 +    }
   2.106 +
   2.107 +    if ( acm_pre_grant_map_ref(dom) )
   2.108 +    {
   2.109 +        (void)__put_user(GNTST_permission_denied, &uop->handle);
   2.110 +        return GNTST_permission_denied;
   2.111 +    }
   2.112 +
   2.113 +    if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   2.114 +         unlikely(ld == rd) )
   2.115 +    {
   2.116 +        if ( rd != NULL )
   2.117 +            put_domain(rd);
   2.118 +        DPRINTK("Could not find domain %d\n", dom);
   2.119 +        (void)__put_user(GNTST_bad_domain, &uop->handle);
   2.120 +        return GNTST_bad_domain;
   2.121 +    }
   2.122 +
   2.123 +    /* Get a maptrack handle. */
   2.124 +    if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
   2.125 +    {
   2.126 +        int              i;
   2.127 +        grant_mapping_t *new_mt;
   2.128 +        grant_table_t   *lgt = ld->grant_table;
   2.129 +
   2.130 +        if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
   2.131 +        {
   2.132 +            put_domain(rd);
   2.133 +            DPRINTK("Maptrack table is at maximum size.\n");
   2.134 +            (void)__put_user(GNTST_no_device_space, &uop->handle);
   2.135 +            return GNTST_no_device_space;
   2.136 +        }
   2.137 +
   2.138 +        /* Grow the maptrack table. */
   2.139 +        new_mt = alloc_xenheap_pages(lgt->maptrack_order + 1);
   2.140 +        if ( new_mt == NULL )
   2.141 +        {
   2.142 +            put_domain(rd);
   2.143 +            DPRINTK("No more map handles available.\n");
   2.144 +            (void)__put_user(GNTST_no_device_space, &uop->handle);
   2.145 +            return GNTST_no_device_space;
   2.146 +        }
   2.147 +
   2.148 +        memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   2.149 +        for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   2.150 +            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
   2.151 +
   2.152 +        free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   2.153 +        lgt->maptrack          = new_mt;
   2.154 +        lgt->maptrack_order   += 1;
   2.155 +        lgt->maptrack_limit  <<= 1;
   2.156 +
   2.157 +        DPRINTK("Doubled maptrack size\n");
   2.158 +        handle = get_maptrack_handle(ld->grant_table);
   2.159 +    }
   2.160 +
   2.161 +    act = &rd->grant_table->active[ref];
   2.162 +    sha = &rd->grant_table->shared[ref];
   2.163 +
   2.164 +    spin_lock(&rd->grant_table->lock);
   2.165  
   2.166      if ( act->pin == 0 )
   2.167      {
   2.168 @@ -132,10 +198,10 @@ static int
   2.169              u32 scombo, prev_scombo, new_scombo;
   2.170  
   2.171              if ( unlikely((sflags & GTF_type_mask) != GTF_permit_access) ||
   2.172 -                 unlikely(sdom != mapping_d->domain_id) )
   2.173 +                 unlikely(sdom != led->domain->domain_id) )
   2.174                  PIN_FAIL(unlock_out, GNTST_general_error,
   2.175                           "Bad flags (%x) or dom (%d). (NB. expected dom %d)\n",
   2.176 -                        sflags, sdom, mapping_d->domain_id);
   2.177 +                        sflags, sdom, led->domain->domain_id);
   2.178  
   2.179              /* Merge two 16-bit values into a 32-bit combined update. */
   2.180              /* NB. Endianness! */
   2.181 @@ -173,12 +239,12 @@ static int
   2.182  
   2.183          /* rmb(); */ /* not on x86 */
   2.184  
   2.185 -        frame = __gpfn_to_mfn_foreign(granting_d, sha->frame);
   2.186 +        frame = __gpfn_to_mfn_foreign(rd, sha->frame);
   2.187  
   2.188          if ( unlikely(!pfn_valid(frame)) ||
   2.189               unlikely(!((dev_hst_ro_flags & GNTMAP_readonly) ?
   2.190 -                        get_page(&frame_table[frame], granting_d) :
   2.191 -                        get_page_and_type(&frame_table[frame], granting_d,
   2.192 +                        get_page(&frame_table[frame], rd) :
   2.193 +                        get_page_and_type(&frame_table[frame], rd,
   2.194                                            PGT_writable_page))) )
   2.195          {
   2.196              clear_bit(_GTF_writing, &sha->flags);
   2.197 @@ -208,10 +274,11 @@ static int
   2.198              PIN_FAIL(unlock_out, ENOSPC,
   2.199                       "Risk of counter overflow %08x\n", act->pin);
   2.200  
   2.201 -        frame = act->frame;
   2.202 +        sflags = sha->flags;
   2.203 +        frame  = act->frame;
   2.204  
   2.205 -        if ( !(dev_hst_ro_flags & GNTMAP_readonly) && 
   2.206 -             !((sflags = sha->flags) & GTF_writing) )
   2.207 +        if ( !(dev_hst_ro_flags & GNTMAP_readonly) &&
   2.208 +             !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
   2.209          {
   2.210              for ( ; ; )
   2.211              {
   2.212 @@ -264,9 +331,9 @@ static int
   2.213       * frame contains the mfn.
   2.214       */
   2.215  
   2.216 -    spin_unlock(&granting_d->grant_table->lock);
   2.217 +    spin_unlock(&rd->grant_table->lock);
   2.218  
   2.219 -    if ( (addr != 0) && (dev_hst_ro_flags & GNTMAP_host_map) )
   2.220 +    if ( dev_hst_ro_flags & GNTMAP_host_map )
   2.221      {
   2.222          /* Write update into the pagetable. */
   2.223          l1_pgentry_t pte;
   2.224 @@ -278,18 +345,15 @@ static int
   2.225              l1e_add_flags(pte,_PAGE_RW);
   2.226  
   2.227          if ( dev_hst_ro_flags & GNTMAP_contains_pte )
   2.228 -            rc = update_grant_pte_mapping(addr, pte, mapping_d, mapping_ed);
   2.229 +            rc = update_grant_pte_mapping(addr, pte, led);
   2.230          else
   2.231 -            rc = update_grant_va_mapping(addr, pte, mapping_d, mapping_ed);
   2.232 +            rc = update_grant_va_mapping(addr, pte, led);
   2.233  
   2.234 -        /* IMPORTANT: rc indicates the degree of TLB flush that is required.
   2.235 -         * GNTST_flush_one (1) or GNTST_flush_all (2). This is done in the 
   2.236 -         * outer gnttab_map_grant_ref. */
   2.237          if ( rc < 0 )
   2.238          {
   2.239              /* Failure: undo and abort. */
   2.240  
   2.241 -            spin_lock(&granting_d->grant_table->lock);
   2.242 +            spin_lock(&rd->grant_table->lock);
   2.243  
   2.244              if ( dev_hst_ro_flags & GNTMAP_readonly )
   2.245              {
   2.246 @@ -311,160 +375,27 @@ static int
   2.247                  put_page(&frame_table[frame]);
   2.248              }
   2.249  
   2.250 -            spin_unlock(&granting_d->grant_table->lock);
   2.251 +            spin_unlock(&rd->grant_table->lock);
   2.252          }
   2.253  
   2.254      }
   2.255  
   2.256 -    *pframe = frame;
   2.257 +    ld->grant_table->maptrack[handle].domid         = dom;
   2.258 +    ld->grant_table->maptrack[handle].ref_and_flags =
   2.259 +        (ref << MAPTRACK_REF_SHIFT) |
   2.260 +        (dev_hst_ro_flags & MAPTRACK_GNTMAP_MASK);
   2.261 +
   2.262 +    (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
   2.263 +    (void)__put_user(handle, &uop->handle);
   2.264 +
   2.265 +    put_domain(rd);
   2.266      return rc;
   2.267  
   2.268 +
   2.269   unlock_out:
   2.270 -    spin_unlock(&granting_d->grant_table->lock);
   2.271 -    return rc;
   2.272 -}
   2.273 -
   2.274 -/*
   2.275 - * Returns 0 if TLB flush / invalidate required by caller.
   2.276 - * va will indicate the address to be invalidated.
   2.277 - * 
   2.278 - * addr is _either_ a host virtual address, or the address of the pte to
   2.279 - * update, as indicated by the GNTMAP_contains_pte flag.
   2.280 - */
   2.281 -static int
   2.282 -__gnttab_map_grant_ref(
   2.283 -    gnttab_map_grant_ref_t *uop,
   2.284 -    unsigned long *va)
   2.285 -{
   2.286 -    domid_t        dom;
   2.287 -    grant_ref_t    ref;
   2.288 -    struct domain *ld, *rd;
   2.289 -    struct vcpu   *led;
   2.290 -    u16            dev_hst_ro_flags;
   2.291 -    int            handle;
   2.292 -    u64            addr;
   2.293 -    unsigned long  frame = 0;
   2.294 -    int            rc;
   2.295 -
   2.296 -    led = current;
   2.297 -    ld = led->domain;
   2.298 -
   2.299 -    /* Bitwise-OR avoids short-circuiting which screws control flow. */
   2.300 -    if ( unlikely(__get_user(dom, &uop->dom) |
   2.301 -                  __get_user(ref, &uop->ref) |
   2.302 -                  __get_user(addr, &uop->host_addr) |
   2.303 -                  __get_user(dev_hst_ro_flags, &uop->flags)) )
   2.304 -    {
   2.305 -        DPRINTK("Fault while reading gnttab_map_grant_ref_t.\n");
   2.306 -        return -EFAULT; /* don't set status */
   2.307 -    }
   2.308 -
   2.309 -    if ( (dev_hst_ro_flags & GNTMAP_host_map) &&
   2.310 -         ( (addr == 0) ||
   2.311 -           (!(dev_hst_ro_flags & GNTMAP_contains_pte) && 
   2.312 -            unlikely(!__addr_ok(addr))) ) )
   2.313 -    {
   2.314 -        DPRINTK("Bad virtual address (%"PRIx64") or flags (%"PRIx16").\n",
   2.315 -                addr, dev_hst_ro_flags);
   2.316 -        (void)__put_user(GNTST_bad_virt_addr, &uop->handle);
   2.317 -        return GNTST_bad_gntref;
   2.318 -    }
   2.319 -
   2.320 -    if ( unlikely(ref >= NR_GRANT_ENTRIES) ||
   2.321 -         unlikely((dev_hst_ro_flags &
   2.322 -                   (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
   2.323 -    {
   2.324 -        DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
   2.325 -        (void)__put_user(GNTST_bad_gntref, &uop->handle);
   2.326 -        return GNTST_bad_gntref;
   2.327 -    }
   2.328 -
   2.329 -    if (acm_pre_grant_map_ref(dom)) {
   2.330 -        (void)__put_user(GNTST_permission_denied, &uop->handle);
   2.331 -        return GNTST_permission_denied;
   2.332 -    }
   2.333 -
   2.334 -    if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   2.335 -         unlikely(ld == rd) )
   2.336 -    {
   2.337 -        if ( rd != NULL )
   2.338 -            put_domain(rd);
   2.339 -        DPRINTK("Could not find domain %d\n", dom);
   2.340 -        (void)__put_user(GNTST_bad_domain, &uop->handle);
   2.341 -        return GNTST_bad_domain;
   2.342 -    }
   2.343 -
   2.344 -    /* Get a maptrack handle. */
   2.345 -    if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
   2.346 -    {
   2.347 -        int              i;
   2.348 -        grant_mapping_t *new_mt;
   2.349 -        grant_table_t   *lgt = ld->grant_table;
   2.350 -
   2.351 -        if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
   2.352 -        {
   2.353 -            put_domain(rd);
   2.354 -            DPRINTK("Maptrack table is at maximum size.\n");
   2.355 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   2.356 -            return GNTST_no_device_space;
   2.357 -        }
   2.358 -
   2.359 -        /* Grow the maptrack table. */
   2.360 -        new_mt = alloc_xenheap_pages(lgt->maptrack_order + 1);
   2.361 -        if ( new_mt == NULL )
   2.362 -        {
   2.363 -            put_domain(rd);
   2.364 -            DPRINTK("No more map handles available.\n");
   2.365 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   2.366 -            return GNTST_no_device_space;
   2.367 -        }
   2.368 -
   2.369 -        memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   2.370 -        for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   2.371 -            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
   2.372 -
   2.373 -        free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   2.374 -        lgt->maptrack          = new_mt;
   2.375 -        lgt->maptrack_order   += 1;
   2.376 -        lgt->maptrack_limit  <<= 1;
   2.377 -
   2.378 -        DPRINTK("Doubled maptrack size\n");
   2.379 -        handle = get_maptrack_handle(ld->grant_table);
   2.380 -    }
   2.381 -
   2.382 -#if GRANT_DEBUG_VERBOSE
   2.383 -    DPRINTK("Mapping grant ref (%hu) for domain (%hu) with flags (%x)\n",
   2.384 -            ref, dom, dev_hst_ro_flags);
   2.385 -#endif
   2.386 -
   2.387 -    if ( (rc = __gnttab_activate_grant_ref(ld, led, rd, ref, dev_hst_ro_flags,
   2.388 -                                           addr, &frame)) >= 0 )
   2.389 -    {
   2.390 -        /*
   2.391 -         * Only make the maptrack live _after_ writing the pte, in case we 
   2.392 -         * overwrite the same frame number, causing a maptrack walk to find it
   2.393 -         */
   2.394 -        ld->grant_table->maptrack[handle].domid = dom;
   2.395 -
   2.396 -        ld->grant_table->maptrack[handle].ref_and_flags
   2.397 -            = (ref << MAPTRACK_REF_SHIFT) |
   2.398 -              (dev_hst_ro_flags & MAPTRACK_GNTMAP_MASK);
   2.399 -
   2.400 -        (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
   2.401 -
   2.402 -        if ( ( dev_hst_ro_flags & GNTMAP_host_map ) &&
   2.403 -             !( dev_hst_ro_flags & GNTMAP_contains_pte) )
   2.404 -            *va = addr;
   2.405 -
   2.406 -        (void)__put_user(handle, &uop->handle);
   2.407 -    }
   2.408 -    else
   2.409 -    {
   2.410 -        (void)__put_user(rc, &uop->handle);
   2.411 -        put_maptrack_handle(ld->grant_table, handle);
   2.412 -    }
   2.413 -
   2.414 -    put_domain(rd);
   2.415 +    spin_unlock(&rd->grant_table->lock);
   2.416 +    (void)__put_user(rc, &uop->handle);
   2.417 +    put_maptrack_handle(ld->grant_table, handle);
   2.418      return rc;
   2.419  }
   2.420  
   2.421 @@ -472,25 +403,17 @@ static long
   2.422  gnttab_map_grant_ref(
   2.423      gnttab_map_grant_ref_t *uop, unsigned int count)
   2.424  {
   2.425 -    int i, rc, flush = 0;
   2.426 -    unsigned long va = 0;
   2.427 +    int i;
   2.428  
   2.429      for ( i = 0; i < count; i++ )
   2.430 -        if ( (rc =__gnttab_map_grant_ref(&uop[i], &va)) >= 0 )
   2.431 -            flush += rc;
   2.432 -
   2.433 -    if ( flush == 1 )
   2.434 -        flush_tlb_one_mask(current->domain->cpumask, va);
   2.435 -    else if ( flush != 0 ) 
   2.436 -        flush_tlb_mask(current->domain->cpumask);
   2.437 +        (void)__gnttab_map_grant_ref(&uop[i]);
   2.438  
   2.439      return 0;
   2.440  }
   2.441  
   2.442  static int
   2.443  __gnttab_unmap_grant_ref(
   2.444 -    gnttab_unmap_grant_ref_t *uop,
   2.445 -    unsigned long *va)
   2.446 +    gnttab_unmap_grant_ref_t *uop)
   2.447  {
   2.448      domid_t          dom;
   2.449      grant_ref_t      ref;
   2.450 @@ -500,7 +423,7 @@ static int
   2.451      grant_entry_t   *sha;
   2.452      grant_mapping_t *map;
   2.453      u16              flags;
   2.454 -    s16              rc = 1;
   2.455 +    s16              rc = 0;
   2.456      u64              addr, dev_bus_addr;
   2.457      unsigned long    frame;
   2.458  
   2.459 @@ -541,11 +464,6 @@ static int
   2.460          return GNTST_bad_domain;
   2.461      }
   2.462  
   2.463 -#if GRANT_DEBUG_VERBOSE
   2.464 -    DPRINTK("Unmapping grant ref (%hu) for domain (%hu) with handle (%hu)\n",
   2.465 -            ref, dom, handle);
   2.466 -#endif
   2.467 -
   2.468      act = &rd->grant_table->active[ref];
   2.469      sha = &rd->grant_table->shared[ref];
   2.470  
   2.471 @@ -566,8 +484,6 @@ static int
   2.472  
   2.473          map->ref_and_flags &= ~GNTMAP_device_map;
   2.474          (void)__put_user(0, &uop->dev_bus_addr);
   2.475 -
   2.476 -        /* Frame is now unmapped for device access. */
   2.477      }
   2.478  
   2.479      if ( (addr != 0) &&
   2.480 @@ -589,10 +505,6 @@ static int
   2.481  
   2.482          act->pin -= (flags & GNTMAP_readonly) ? GNTPIN_hstr_inc
   2.483                                                : GNTPIN_hstw_inc;
   2.484 -
   2.485 -        rc = 0;
   2.486 -        if ( !( flags & GNTMAP_contains_pte) )
   2.487 -            *va = addr;
   2.488      }
   2.489  
   2.490      if ( (map->ref_and_flags & (GNTMAP_device_map|GNTMAP_host_map)) == 0)
   2.491 @@ -632,17 +544,12 @@ static long
   2.492  gnttab_unmap_grant_ref(
   2.493      gnttab_unmap_grant_ref_t *uop, unsigned int count)
   2.494  {
   2.495 -    int i, flush = 0;
   2.496 -    unsigned long va = 0;
   2.497 +    int i;
   2.498  
   2.499      for ( i = 0; i < count; i++ )
   2.500 -        if ( __gnttab_unmap_grant_ref(&uop[i], &va) == 0 )
   2.501 -            flush++;
   2.502 +        (void)__gnttab_unmap_grant_ref(&uop[i]);
   2.503  
   2.504 -    if ( flush == 1 )
   2.505 -        flush_tlb_one_mask(current->domain->cpumask, va);
   2.506 -    else if ( flush != 0 ) 
   2.507 -        flush_tlb_mask(current->domain->cpumask);
   2.508 +    flush_tlb_mask(current->domain->cpumask);
   2.509  
   2.510      return 0;
   2.511  }
   2.512 @@ -703,9 +610,9 @@ gnttab_setup_table(
   2.513      return 0;
   2.514  }
   2.515  
   2.516 -#if GRANT_DEBUG
   2.517  static int
   2.518 -gnttab_dump_table(gnttab_dump_table_t *uop)
   2.519 +gnttab_dump_table(
   2.520 +    gnttab_dump_table_t *uop)
   2.521  {
   2.522      grant_table_t        *gt;
   2.523      gnttab_dump_table_t   op;
   2.524 @@ -716,6 +623,8 @@ gnttab_dump_table(gnttab_dump_table_t *u
   2.525      grant_mapping_t      *maptrack;
   2.526      int                   i;
   2.527  
   2.528 +    if ( !IS_PRIV(current->domain) )
   2.529 +        return -EPERM;
   2.530  
   2.531      if ( unlikely(copy_from_user(&op, uop, sizeof(op)) != 0) )
   2.532      {
   2.533 @@ -724,9 +633,7 @@ gnttab_dump_table(gnttab_dump_table_t *u
   2.534      }
   2.535  
   2.536      if ( op.dom == DOMID_SELF )
   2.537 -    {
   2.538          op.dom = current->domain->domain_id;
   2.539 -    }
   2.540  
   2.541      if ( unlikely((d = find_domain_by_id(op.dom)) == NULL) )
   2.542      {
   2.543 @@ -750,14 +657,11 @@ gnttab_dump_table(gnttab_dump_table_t *u
   2.544  
   2.545      for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   2.546      {
   2.547 -        sha_copy =  gt->shared[i];
   2.548 -
   2.549 +        sha_copy = gt->shared[i];
   2.550          if ( sha_copy.flags )
   2.551 -        {
   2.552              DPRINTK("Grant: dom (%hu) SHARED (%d) flags:(%hx) "
   2.553                      "dom:(%hu) frame:(%x)\n",
   2.554                      op.dom, i, sha_copy.flags, sha_copy.domid, sha_copy.frame);
   2.555 -        }
   2.556      }
   2.557  
   2.558      spin_lock(&gt->lock);
   2.559 @@ -765,28 +669,22 @@ gnttab_dump_table(gnttab_dump_table_t *u
   2.560      for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   2.561      {
   2.562          act = &gt->active[i];
   2.563 -
   2.564          if ( act->pin )
   2.565 -        {
   2.566              DPRINTK("Grant: dom (%hu) ACTIVE (%d) pin:(%x) "
   2.567                      "dom:(%hu) frame:(%lx)\n",
   2.568                      op.dom, i, act->pin, act->domid, act->frame);
   2.569 -        }
   2.570      }
   2.571  
   2.572      for ( i = 0; i < gt->maptrack_limit; i++ )
   2.573      {
   2.574          maptrack = &gt->maptrack[i];
   2.575 -
   2.576          if ( maptrack->ref_and_flags & MAPTRACK_GNTMAP_MASK )
   2.577 -        {
   2.578              DPRINTK("Grant: dom (%hu) MAP (%d) ref:(%hu) flags:(%x) "
   2.579                      "dom:(%hu)\n",
   2.580                      op.dom, i,
   2.581                      maptrack->ref_and_flags >> MAPTRACK_REF_SHIFT,
   2.582                      maptrack->ref_and_flags & MAPTRACK_GNTMAP_MASK,
   2.583                      maptrack->domid);
   2.584 -        }
   2.585      }
   2.586  
   2.587      spin_unlock(&gt->lock);
   2.588 @@ -794,10 +692,10 @@ gnttab_dump_table(gnttab_dump_table_t *u
   2.589      put_domain(d);
   2.590      return 0;
   2.591  }
   2.592 -#endif
   2.593  
   2.594  static long
   2.595 -gnttab_transfer(gnttab_transfer_t *uop, unsigned int count)
   2.596 +gnttab_transfer(
   2.597 +    gnttab_transfer_t *uop, unsigned int count)
   2.598  {
   2.599      struct domain *d = current->domain;
   2.600      struct domain *e;
   2.601 @@ -810,10 +708,7 @@ gnttab_transfer(gnttab_transfer_t *uop, 
   2.602      for ( i = 0; i < count; i++ )
   2.603      {
   2.604          gnttab_transfer_t *gop = &uop[i];
   2.605 -#if GRANT_DEBUG
   2.606 -        printk("gnttab_transfer: i=%d mfn=%lx domid=%d gref=%08x\n",
   2.607 -               i, gop->mfn, gop->domid, gop->handle);
   2.608 -#endif
   2.609 +
   2.610          page = &frame_table[gop->mfn];
   2.611          
   2.612          if ( unlikely(IS_XEN_HEAP_FRAME(page)))
   2.613 @@ -956,11 +851,9 @@ do_grant_table_op(
   2.614      case GNTTABOP_setup_table:
   2.615          rc = gnttab_setup_table((gnttab_setup_table_t *)uop, count);
   2.616          break;
   2.617 -#if GRANT_DEBUG
   2.618      case GNTTABOP_dump_table:
   2.619          rc = gnttab_dump_table((gnttab_dump_table_t *)uop);
   2.620          break;
   2.621 -#endif
   2.622      case GNTTABOP_transfer:
   2.623          if (unlikely(!array_access_ok(
   2.624              uop, count, sizeof(gnttab_transfer_t))))
   2.625 @@ -1002,12 +895,6 @@ gnttab_check_unmap(
   2.626      
   2.627      lgt = ld->grant_table;
   2.628      
   2.629 -#if GRANT_DEBUG_VERBOSE
   2.630 -    if ( ld->domain_id != 0 )
   2.631 -        DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   2.632 -                rd->domain_id, ld->domain_id, frame, readonly);
   2.633 -#endif
   2.634 -    
   2.635      /* Fast exit if we're not mapping anything using grant tables */
   2.636      if ( lgt->map_count == 0 )
   2.637          return 0;
   2.638 @@ -1098,11 +985,6 @@ gnttab_prepare_for_transfer(
   2.639      int            retries = 0;
   2.640      unsigned long  target_pfn;
   2.641  
   2.642 -#if GRANT_DEBUG_VERBOSE
   2.643 -    DPRINTK("gnttab_prepare_for_transfer rd(%hu) ld(%hu) ref(%hu).\n",
   2.644 -            rd->domain_id, ld->domain_id, ref);
   2.645 -#endif
   2.646 -
   2.647      if ( unlikely((rgt = rd->grant_table) == NULL) ||
   2.648           unlikely(ref >= NR_GRANT_ENTRIES) )
   2.649      {
     3.1 --- a/xen/include/asm-x86/mm.h	Fri Sep 23 14:43:52 2005 +0100
     3.2 +++ b/xen/include/asm-x86/mm.h	Fri Sep 23 16:28:17 2005 +0100
     3.3 @@ -380,11 +380,9 @@ extern int __sync_lazy_execstate(void);
     3.4   * hold a reference to the page.
     3.5   */
     3.6  int update_grant_va_mapping(
     3.7 -    unsigned long va, l1_pgentry_t _nl1e, 
     3.8 -    struct domain *d, struct vcpu *v);
     3.9 +    unsigned long va, l1_pgentry_t _nl1e, struct vcpu *v);
    3.10  int update_grant_pte_mapping(
    3.11 -    unsigned long pte_addr, l1_pgentry_t _nl1e, 
    3.12 -    struct domain *d, struct vcpu *v);
    3.13 +    unsigned long pte_addr, l1_pgentry_t _nl1e, struct vcpu *v);
    3.14  int clear_grant_va_mapping(unsigned long addr, unsigned long frame);
    3.15  int clear_grant_pte_mapping(
    3.16      unsigned long addr, unsigned long frame, struct domain *d);
     4.1 --- a/xen/include/xen/grant_table.h	Fri Sep 23 14:43:52 2005 +0100
     4.2 +++ b/xen/include/xen/grant_table.h	Fri Sep 23 16:28:17 2005 +0100
     4.3 @@ -110,8 +110,4 @@ gnttab_prepare_for_transfer(
     4.4  void
     4.5  gnttab_release_dev_mappings(grant_table_t *gt);
     4.6  
     4.7 -/* Extra GNTST_ values, for internal use only. */
     4.8 -#define GNTST_flush_all        (2)  /* Success, need to flush entire TLB.    */
     4.9 -#define GNTST_flush_one        (1)  /* Success, need to flush a vaddr.       */
    4.10 -
    4.11  #endif /* __XEN_GRANT_H__ */