ia64/xen-unstable

changeset 7049:ad0270abc9b9

Merged.
author emellor@ewan
date Fri Sep 23 16:57:13 2005 +0100 (2005-09-23)
parents ab1c362ba0d1 7ff651a39cfc
children 9f50bd7a478f
files tools/libxc/xg_private.h tools/python/xen/xend/PrettyPrint.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/python/xen/xm/main.py 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/tools/libxc/xg_private.h	Fri Sep 23 16:56:46 2005 +0100
     1.2 +++ b/tools/libxc/xg_private.h	Fri Sep 23 16:57:13 2005 +0100
     1.3 @@ -28,25 +28,27 @@ unsigned long csum_page (void * page);
     1.4  #define _PAGE_PSE       0x080
     1.5  #define _PAGE_GLOBAL    0x100
     1.6  
     1.7 -#if defined(__i386__)
     1.8 -#define L1_PAGETABLE_SHIFT       12
     1.9 -#define L2_PAGETABLE_SHIFT       22
    1.10  #define L1_PAGETABLE_SHIFT_PAE   12
    1.11  #define L2_PAGETABLE_SHIFT_PAE   21
    1.12  #define L3_PAGETABLE_SHIFT_PAE   30
    1.13 +
    1.14 +#if defined(__i386__)
    1.15 +#define L1_PAGETABLE_SHIFT       12
    1.16 +#define L2_PAGETABLE_SHIFT       22
    1.17  #elif defined(__x86_64__)
    1.18 -#define L1_PAGETABLE_SHIFT      12
    1.19 -#define L2_PAGETABLE_SHIFT      21
    1.20 -#define L3_PAGETABLE_SHIFT      30
    1.21 -#define L4_PAGETABLE_SHIFT      39
    1.22 +#define L1_PAGETABLE_SHIFT       12
    1.23 +#define L2_PAGETABLE_SHIFT       21
    1.24 +#define L3_PAGETABLE_SHIFT       30
    1.25 +#define L4_PAGETABLE_SHIFT       39
    1.26  #endif
    1.27  
    1.28 -#if defined(__i386__) 
    1.29 -#define ENTRIES_PER_L1_PAGETABLE 1024
    1.30 -#define ENTRIES_PER_L2_PAGETABLE 1024
    1.31  #define L1_PAGETABLE_ENTRIES_PAE  512
    1.32  #define L2_PAGETABLE_ENTRIES_PAE  512
    1.33  #define L3_PAGETABLE_ENTRIES_PAE    4
    1.34 +
    1.35 +#if defined(__i386__) 
    1.36 +#define L1_PAGETABLE_ENTRIES   1024
    1.37 +#define L2_PAGETABLE_ENTRIES   1024
    1.38  #elif defined(__x86_64__)
    1.39  #define L1_PAGETABLE_ENTRIES    512
    1.40  #define L2_PAGETABLE_ENTRIES    512
    1.41 @@ -70,17 +72,18 @@ typedef unsigned long l3_pgentry_t;
    1.42  typedef unsigned long l4_pgentry_t;
    1.43  #endif
    1.44  
    1.45 -#if defined(__i386__)
    1.46 -#define l1_table_offset(_a) \
    1.47 -          (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
    1.48 -#define l2_table_offset(_a) \
    1.49 -          ((_a) >> L2_PAGETABLE_SHIFT)
    1.50  #define l1_table_offset_pae(_a) \
    1.51    (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1))
    1.52  #define l2_table_offset_pae(_a) \
    1.53    (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1))
    1.54  #define l3_table_offset_pae(_a) \
    1.55  	(((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
    1.56 +
    1.57 +#if defined(__i386__)
    1.58 +#define l1_table_offset(_a) \
    1.59 +          (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
    1.60 +#define l2_table_offset(_a) \
    1.61 +          ((_a) >> L2_PAGETABLE_SHIFT)
    1.62  #elif defined(__x86_64__)
    1.63  #define l1_table_offset(_a) \
    1.64    (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
     6.1 --- a/xen/arch/x86/mm.c	Fri Sep 23 16:56:46 2005 +0100
     6.2 +++ b/xen/arch/x86/mm.c	Fri Sep 23 16:57:13 2005 +0100
     6.3 @@ -2273,8 +2273,7 @@ int do_mmu_update(
     6.4  
     6.5  
     6.6  int update_grant_pte_mapping(
     6.7 -    unsigned long pte_addr, l1_pgentry_t _nl1e, 
     6.8 -    struct domain *d, struct vcpu *v)
     6.9 +    unsigned long pte_addr, l1_pgentry_t _nl1e, struct vcpu *v)
    6.10  {
    6.11      int rc = GNTST_okay;
    6.12      void *va;
    6.13 @@ -2282,6 +2281,7 @@ int update_grant_pte_mapping(
    6.14      struct pfn_info *page;
    6.15      u32 type_info;
    6.16      l1_pgentry_t ol1e;
    6.17 +    struct domain *d = v->domain;
    6.18  
    6.19      ASSERT(spin_is_locked(&d->big_lock));
    6.20      ASSERT(!shadow_mode_refcounts(d));
    6.21 @@ -2319,8 +2319,6 @@ int update_grant_pte_mapping(
    6.22  
    6.23      put_page_from_l1e(ol1e, d);
    6.24  
    6.25 -    rc = (l1e_get_flags(ol1e) & _PAGE_PRESENT) ? GNTST_flush_all : GNTST_okay;
    6.26 -
    6.27      if ( unlikely(shadow_mode_enabled(d)) )
    6.28      {
    6.29          struct domain_mmap_cache sh_mapcache;
    6.30 @@ -2415,10 +2413,10 @@ int clear_grant_pte_mapping(
    6.31  
    6.32  
    6.33  int update_grant_va_mapping(
    6.34 -    unsigned long va, l1_pgentry_t _nl1e, struct domain *d, struct vcpu *v)
    6.35 +    unsigned long va, l1_pgentry_t _nl1e, struct vcpu *v)
    6.36  {
    6.37 -    int rc = GNTST_okay;
    6.38      l1_pgentry_t *pl1e, ol1e;
    6.39 +    struct domain *d = v->domain;
    6.40      
    6.41      ASSERT(spin_is_locked(&d->big_lock));
    6.42      ASSERT(!shadow_mode_refcounts(d));
    6.43 @@ -2439,12 +2437,10 @@ int update_grant_va_mapping(
    6.44  
    6.45      put_page_from_l1e(ol1e, d);
    6.46  
    6.47 -    rc = (l1e_get_flags(ol1e) & _PAGE_PRESENT) ? GNTST_flush_one : GNTST_okay;
    6.48 -
    6.49      if ( unlikely(shadow_mode_enabled(d)) )
    6.50          shadow_do_update_va_mapping(va, _nl1e, v);
    6.51  
    6.52 -    return rc;
    6.53 +    return GNTST_okay;
    6.54  }
    6.55  
    6.56  int clear_grant_va_mapping(unsigned long addr, unsigned long frame)
     7.1 --- a/xen/common/grant_table.c	Fri Sep 23 16:56:46 2005 +0100
     7.2 +++ b/xen/common/grant_table.c	Fri Sep 23 16:57:13 2005 +0100
     7.3 @@ -24,10 +24,6 @@
     7.4   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     7.5   */
     7.6  
     7.7 -#define GRANT_DEBUG 0
     7.8 -#define GRANT_DEBUG_VERBOSE 0
     7.9 -
    7.10 -#include <xen/config.h>
    7.11  #include <xen/lib.h>
    7.12  #include <xen/sched.h>
    7.13  #include <xen/shadow.h>
    7.14 @@ -68,39 +64,32 @@ put_maptrack_handle(
    7.15      t->map_count--;
    7.16  }
    7.17  
    7.18 +/*
    7.19 + * Returns 0 if TLB flush / invalidate required by caller.
    7.20 + * va will indicate the address to be invalidated.
    7.21 + * 
    7.22 + * addr is _either_ a host virtual address, or the address of the pte to
    7.23 + * update, as indicated by the GNTMAP_contains_pte flag.
    7.24 + */
    7.25  static int
    7.26 -__gnttab_activate_grant_ref(
    7.27 -    struct domain   *mapping_d,          /* IN */
    7.28 -    struct vcpu     *mapping_ed,
    7.29 -    struct domain   *granting_d,
    7.30 -    grant_ref_t      ref,
    7.31 -    u16              dev_hst_ro_flags,
    7.32 -    u64              addr,
    7.33 -    unsigned long   *pframe )            /* OUT */
    7.34 +__gnttab_map_grant_ref(
    7.35 +    gnttab_map_grant_ref_t *uop)
    7.36  {
    7.37 -    domid_t               sdom;
    7.38 -    u16                   sflags;
    7.39 +    domid_t        dom;
    7.40 +    grant_ref_t    ref;
    7.41 +    struct domain *ld, *rd;
    7.42 +    struct vcpu   *led;
    7.43 +    u16            dev_hst_ro_flags;
    7.44 +    int            handle;
    7.45 +    u64            addr;
    7.46 +    unsigned long  frame = 0;
    7.47 +    int            rc;
    7.48      active_grant_entry_t *act;
    7.49 -    grant_entry_t        *sha;
    7.50 -    s16                   rc = 1;
    7.51 -    unsigned long         frame = 0;
    7.52 -    int                   retries = 0;
    7.53  
    7.54 -    /*
    7.55 -     * Objectives of this function:
    7.56 -     * . Make the record ( granting_d, ref ) active, if not already.
    7.57 -     * . Update shared grant entry of owner, indicating frame is mapped.
    7.58 -     * . Increment the owner act->pin reference counts.
    7.59 -     * . get_page on shared frame if new mapping.
    7.60 -     * . get_page_type if this is first RW mapping of frame.
    7.61 -     * . Add PTE to virtual address space of mapping_d, if necessary.
    7.62 -     * Returns:
    7.63 -     * .  -ve: error
    7.64 -     * .    1: ok
    7.65 -     * .    0: ok and TLB invalidate of host_addr needed.
    7.66 -     *
    7.67 -     * On success, *pframe contains mfn.
    7.68 -     */
    7.69 +    /* Entry details from @rd's shared grant table. */
    7.70 +    grant_entry_t *sha;
    7.71 +    domid_t        sdom;
    7.72 +    u16            sflags;
    7.73  
    7.74      /*
    7.75       * We bound the number of times we retry CMPXCHG on memory locations that
    7.76 @@ -110,11 +99,88 @@ static int
    7.77       * the guest to race our updates (e.g., to change the GTF_readonly flag),
    7.78       * so we allow a few retries before failing.
    7.79       */
    7.80 +    int retries = 0;
    7.81  
    7.82 -    act = &granting_d->grant_table->active[ref];
    7.83 -    sha = &granting_d->grant_table->shared[ref];
    7.84 +    led = current;
    7.85 +    ld = led->domain;
    7.86 +
    7.87 +    /* Bitwise-OR avoids short-circuiting which screws control flow. */
    7.88 +    if ( unlikely(__get_user(dom, &uop->dom) |
    7.89 +                  __get_user(ref, &uop->ref) |
    7.90 +                  __get_user(addr, &uop->host_addr) |
    7.91 +                  __get_user(dev_hst_ro_flags, &uop->flags)) )
    7.92 +    {
    7.93 +        DPRINTK("Fault while reading gnttab_map_grant_ref_t.\n");
    7.94 +        return -EFAULT; /* don't set status */
    7.95 +    }
    7.96 +
    7.97 +    if ( unlikely(ref >= NR_GRANT_ENTRIES) ||
    7.98 +         unlikely((dev_hst_ro_flags &
    7.99 +                   (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
   7.100 +    {
   7.101 +        DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
   7.102 +        (void)__put_user(GNTST_bad_gntref, &uop->handle);
   7.103 +        return GNTST_bad_gntref;
   7.104 +    }
   7.105 +
   7.106 +    if ( acm_pre_grant_map_ref(dom) )
   7.107 +    {
   7.108 +        (void)__put_user(GNTST_permission_denied, &uop->handle);
   7.109 +        return GNTST_permission_denied;
   7.110 +    }
   7.111 +
   7.112 +    if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   7.113 +         unlikely(ld == rd) )
   7.114 +    {
   7.115 +        if ( rd != NULL )
   7.116 +            put_domain(rd);
   7.117 +        DPRINTK("Could not find domain %d\n", dom);
   7.118 +        (void)__put_user(GNTST_bad_domain, &uop->handle);
   7.119 +        return GNTST_bad_domain;
   7.120 +    }
   7.121  
   7.122 -    spin_lock(&granting_d->grant_table->lock);
   7.123 +    /* Get a maptrack handle. */
   7.124 +    if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
   7.125 +    {
   7.126 +        int              i;
   7.127 +        grant_mapping_t *new_mt;
   7.128 +        grant_table_t   *lgt = ld->grant_table;
   7.129 +
   7.130 +        if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
   7.131 +        {
   7.132 +            put_domain(rd);
   7.133 +            DPRINTK("Maptrack table is at maximum size.\n");
   7.134 +            (void)__put_user(GNTST_no_device_space, &uop->handle);
   7.135 +            return GNTST_no_device_space;
   7.136 +        }
   7.137 +
   7.138 +        /* Grow the maptrack table. */
   7.139 +        new_mt = alloc_xenheap_pages(lgt->maptrack_order + 1);
   7.140 +        if ( new_mt == NULL )
   7.141 +        {
   7.142 +            put_domain(rd);
   7.143 +            DPRINTK("No more map handles available.\n");
   7.144 +            (void)__put_user(GNTST_no_device_space, &uop->handle);
   7.145 +            return GNTST_no_device_space;
   7.146 +        }
   7.147 +
   7.148 +        memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   7.149 +        for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   7.150 +            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
   7.151 +
   7.152 +        free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   7.153 +        lgt->maptrack          = new_mt;
   7.154 +        lgt->maptrack_order   += 1;
   7.155 +        lgt->maptrack_limit  <<= 1;
   7.156 +
   7.157 +        DPRINTK("Doubled maptrack size\n");
   7.158 +        handle = get_maptrack_handle(ld->grant_table);
   7.159 +    }
   7.160 +
   7.161 +    act = &rd->grant_table->active[ref];
   7.162 +    sha = &rd->grant_table->shared[ref];
   7.163 +
   7.164 +    spin_lock(&rd->grant_table->lock);
   7.165  
   7.166      if ( act->pin == 0 )
   7.167      {
   7.168 @@ -132,10 +198,10 @@ static int
   7.169              u32 scombo, prev_scombo, new_scombo;
   7.170  
   7.171              if ( unlikely((sflags & GTF_type_mask) != GTF_permit_access) ||
   7.172 -                 unlikely(sdom != mapping_d->domain_id) )
   7.173 +                 unlikely(sdom != led->domain->domain_id) )
   7.174                  PIN_FAIL(unlock_out, GNTST_general_error,
   7.175                           "Bad flags (%x) or dom (%d). (NB. expected dom %d)\n",
   7.176 -                        sflags, sdom, mapping_d->domain_id);
   7.177 +                        sflags, sdom, led->domain->domain_id);
   7.178  
   7.179              /* Merge two 16-bit values into a 32-bit combined update. */
   7.180              /* NB. Endianness! */
   7.181 @@ -173,12 +239,12 @@ static int
   7.182  
   7.183          /* rmb(); */ /* not on x86 */
   7.184  
   7.185 -        frame = __gpfn_to_mfn_foreign(granting_d, sha->frame);
   7.186 +        frame = __gpfn_to_mfn_foreign(rd, sha->frame);
   7.187  
   7.188          if ( unlikely(!pfn_valid(frame)) ||
   7.189               unlikely(!((dev_hst_ro_flags & GNTMAP_readonly) ?
   7.190 -                        get_page(&frame_table[frame], granting_d) :
   7.191 -                        get_page_and_type(&frame_table[frame], granting_d,
   7.192 +                        get_page(&frame_table[frame], rd) :
   7.193 +                        get_page_and_type(&frame_table[frame], rd,
   7.194                                            PGT_writable_page))) )
   7.195          {
   7.196              clear_bit(_GTF_writing, &sha->flags);
   7.197 @@ -208,10 +274,11 @@ static int
   7.198              PIN_FAIL(unlock_out, ENOSPC,
   7.199                       "Risk of counter overflow %08x\n", act->pin);
   7.200  
   7.201 -        frame = act->frame;
   7.202 +        sflags = sha->flags;
   7.203 +        frame  = act->frame;
   7.204  
   7.205 -        if ( !(dev_hst_ro_flags & GNTMAP_readonly) && 
   7.206 -             !((sflags = sha->flags) & GTF_writing) )
   7.207 +        if ( !(dev_hst_ro_flags & GNTMAP_readonly) &&
   7.208 +             !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
   7.209          {
   7.210              for ( ; ; )
   7.211              {
   7.212 @@ -264,9 +331,9 @@ static int
   7.213       * frame contains the mfn.
   7.214       */
   7.215  
   7.216 -    spin_unlock(&granting_d->grant_table->lock);
   7.217 +    spin_unlock(&rd->grant_table->lock);
   7.218  
   7.219 -    if ( (addr != 0) && (dev_hst_ro_flags & GNTMAP_host_map) )
   7.220 +    if ( dev_hst_ro_flags & GNTMAP_host_map )
   7.221      {
   7.222          /* Write update into the pagetable. */
   7.223          l1_pgentry_t pte;
   7.224 @@ -278,18 +345,15 @@ static int
   7.225              l1e_add_flags(pte,_PAGE_RW);
   7.226  
   7.227          if ( dev_hst_ro_flags & GNTMAP_contains_pte )
   7.228 -            rc = update_grant_pte_mapping(addr, pte, mapping_d, mapping_ed);
   7.229 +            rc = update_grant_pte_mapping(addr, pte, led);
   7.230          else
   7.231 -            rc = update_grant_va_mapping(addr, pte, mapping_d, mapping_ed);
   7.232 +            rc = update_grant_va_mapping(addr, pte, led);
   7.233  
   7.234 -        /* IMPORTANT: rc indicates the degree of TLB flush that is required.
   7.235 -         * GNTST_flush_one (1) or GNTST_flush_all (2). This is done in the 
   7.236 -         * outer gnttab_map_grant_ref. */
   7.237          if ( rc < 0 )
   7.238          {
   7.239              /* Failure: undo and abort. */
   7.240  
   7.241 -            spin_lock(&granting_d->grant_table->lock);
   7.242 +            spin_lock(&rd->grant_table->lock);
   7.243  
   7.244              if ( dev_hst_ro_flags & GNTMAP_readonly )
   7.245              {
   7.246 @@ -311,160 +375,27 @@ static int
   7.247                  put_page(&frame_table[frame]);
   7.248              }
   7.249  
   7.250 -            spin_unlock(&granting_d->grant_table->lock);
   7.251 +            spin_unlock(&rd->grant_table->lock);
   7.252          }
   7.253  
   7.254      }
   7.255  
   7.256 -    *pframe = frame;
   7.257 +    ld->grant_table->maptrack[handle].domid         = dom;
   7.258 +    ld->grant_table->maptrack[handle].ref_and_flags =
   7.259 +        (ref << MAPTRACK_REF_SHIFT) |
   7.260 +        (dev_hst_ro_flags & MAPTRACK_GNTMAP_MASK);
   7.261 +
   7.262 +    (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
   7.263 +    (void)__put_user(handle, &uop->handle);
   7.264 +
   7.265 +    put_domain(rd);
   7.266      return rc;
   7.267  
   7.268 +
   7.269   unlock_out:
   7.270 -    spin_unlock(&granting_d->grant_table->lock);
   7.271 -    return rc;
   7.272 -}
   7.273 -
   7.274 -/*
   7.275 - * Returns 0 if TLB flush / invalidate required by caller.
   7.276 - * va will indicate the address to be invalidated.
   7.277 - * 
   7.278 - * addr is _either_ a host virtual address, or the address of the pte to
   7.279 - * update, as indicated by the GNTMAP_contains_pte flag.
   7.280 - */
   7.281 -static int
   7.282 -__gnttab_map_grant_ref(
   7.283 -    gnttab_map_grant_ref_t *uop,
   7.284 -    unsigned long *va)
   7.285 -{
   7.286 -    domid_t        dom;
   7.287 -    grant_ref_t    ref;
   7.288 -    struct domain *ld, *rd;
   7.289 -    struct vcpu   *led;
   7.290 -    u16            dev_hst_ro_flags;
   7.291 -    int            handle;
   7.292 -    u64            addr;
   7.293 -    unsigned long  frame = 0;
   7.294 -    int            rc;
   7.295 -
   7.296 -    led = current;
   7.297 -    ld = led->domain;
   7.298 -
   7.299 -    /* Bitwise-OR avoids short-circuiting which screws control flow. */
   7.300 -    if ( unlikely(__get_user(dom, &uop->dom) |
   7.301 -                  __get_user(ref, &uop->ref) |
   7.302 -                  __get_user(addr, &uop->host_addr) |
   7.303 -                  __get_user(dev_hst_ro_flags, &uop->flags)) )
   7.304 -    {
   7.305 -        DPRINTK("Fault while reading gnttab_map_grant_ref_t.\n");
   7.306 -        return -EFAULT; /* don't set status */
   7.307 -    }
   7.308 -
   7.309 -    if ( (dev_hst_ro_flags & GNTMAP_host_map) &&
   7.310 -         ( (addr == 0) ||
   7.311 -           (!(dev_hst_ro_flags & GNTMAP_contains_pte) && 
   7.312 -            unlikely(!__addr_ok(addr))) ) )
   7.313 -    {
   7.314 -        DPRINTK("Bad virtual address (%"PRIx64") or flags (%"PRIx16").\n",
   7.315 -                addr, dev_hst_ro_flags);
   7.316 -        (void)__put_user(GNTST_bad_virt_addr, &uop->handle);
   7.317 -        return GNTST_bad_gntref;
   7.318 -    }
   7.319 -
   7.320 -    if ( unlikely(ref >= NR_GRANT_ENTRIES) ||
   7.321 -         unlikely((dev_hst_ro_flags &
   7.322 -                   (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
   7.323 -    {
   7.324 -        DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
   7.325 -        (void)__put_user(GNTST_bad_gntref, &uop->handle);
   7.326 -        return GNTST_bad_gntref;
   7.327 -    }
   7.328 -
   7.329 -    if (acm_pre_grant_map_ref(dom)) {
   7.330 -        (void)__put_user(GNTST_permission_denied, &uop->handle);
   7.331 -        return GNTST_permission_denied;
   7.332 -    }
   7.333 -
   7.334 -    if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   7.335 -         unlikely(ld == rd) )
   7.336 -    {
   7.337 -        if ( rd != NULL )
   7.338 -            put_domain(rd);
   7.339 -        DPRINTK("Could not find domain %d\n", dom);
   7.340 -        (void)__put_user(GNTST_bad_domain, &uop->handle);
   7.341 -        return GNTST_bad_domain;
   7.342 -    }
   7.343 -
   7.344 -    /* Get a maptrack handle. */
   7.345 -    if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
   7.346 -    {
   7.347 -        int              i;
   7.348 -        grant_mapping_t *new_mt;
   7.349 -        grant_table_t   *lgt = ld->grant_table;
   7.350 -
   7.351 -        if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
   7.352 -        {
   7.353 -            put_domain(rd);
   7.354 -            DPRINTK("Maptrack table is at maximum size.\n");
   7.355 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   7.356 -            return GNTST_no_device_space;
   7.357 -        }
   7.358 -
   7.359 -        /* Grow the maptrack table. */
   7.360 -        new_mt = alloc_xenheap_pages(lgt->maptrack_order + 1);
   7.361 -        if ( new_mt == NULL )
   7.362 -        {
   7.363 -            put_domain(rd);
   7.364 -            DPRINTK("No more map handles available.\n");
   7.365 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   7.366 -            return GNTST_no_device_space;
   7.367 -        }
   7.368 -
   7.369 -        memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   7.370 -        for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   7.371 -            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
   7.372 -
   7.373 -        free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   7.374 -        lgt->maptrack          = new_mt;
   7.375 -        lgt->maptrack_order   += 1;
   7.376 -        lgt->maptrack_limit  <<= 1;
   7.377 -
   7.378 -        DPRINTK("Doubled maptrack size\n");
   7.379 -        handle = get_maptrack_handle(ld->grant_table);
   7.380 -    }
   7.381 -
   7.382 -#if GRANT_DEBUG_VERBOSE
   7.383 -    DPRINTK("Mapping grant ref (%hu) for domain (%hu) with flags (%x)\n",
   7.384 -            ref, dom, dev_hst_ro_flags);
   7.385 -#endif
   7.386 -
   7.387 -    if ( (rc = __gnttab_activate_grant_ref(ld, led, rd, ref, dev_hst_ro_flags,
   7.388 -                                           addr, &frame)) >= 0 )
   7.389 -    {
   7.390 -        /*
   7.391 -         * Only make the maptrack live _after_ writing the pte, in case we 
   7.392 -         * overwrite the same frame number, causing a maptrack walk to find it
   7.393 -         */
   7.394 -        ld->grant_table->maptrack[handle].domid = dom;
   7.395 -
   7.396 -        ld->grant_table->maptrack[handle].ref_and_flags
   7.397 -            = (ref << MAPTRACK_REF_SHIFT) |
   7.398 -              (dev_hst_ro_flags & MAPTRACK_GNTMAP_MASK);
   7.399 -
   7.400 -        (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
   7.401 -
   7.402 -        if ( ( dev_hst_ro_flags & GNTMAP_host_map ) &&
   7.403 -             !( dev_hst_ro_flags & GNTMAP_contains_pte) )
   7.404 -            *va = addr;
   7.405 -
   7.406 -        (void)__put_user(handle, &uop->handle);
   7.407 -    }
   7.408 -    else
   7.409 -    {
   7.410 -        (void)__put_user(rc, &uop->handle);
   7.411 -        put_maptrack_handle(ld->grant_table, handle);
   7.412 -    }
   7.413 -
   7.414 -    put_domain(rd);
   7.415 +    spin_unlock(&rd->grant_table->lock);
   7.416 +    (void)__put_user(rc, &uop->handle);
   7.417 +    put_maptrack_handle(ld->grant_table, handle);
   7.418      return rc;
   7.419  }
   7.420  
   7.421 @@ -472,25 +403,17 @@ static long
   7.422  gnttab_map_grant_ref(
   7.423      gnttab_map_grant_ref_t *uop, unsigned int count)
   7.424  {
   7.425 -    int i, rc, flush = 0;
   7.426 -    unsigned long va = 0;
   7.427 +    int i;
   7.428  
   7.429      for ( i = 0; i < count; i++ )
   7.430 -        if ( (rc =__gnttab_map_grant_ref(&uop[i], &va)) >= 0 )
   7.431 -            flush += rc;
   7.432 -
   7.433 -    if ( flush == 1 )
   7.434 -        flush_tlb_one_mask(current->domain->cpumask, va);
   7.435 -    else if ( flush != 0 ) 
   7.436 -        flush_tlb_mask(current->domain->cpumask);
   7.437 +        (void)__gnttab_map_grant_ref(&uop[i]);
   7.438  
   7.439      return 0;
   7.440  }
   7.441  
   7.442  static int
   7.443  __gnttab_unmap_grant_ref(
   7.444 -    gnttab_unmap_grant_ref_t *uop,
   7.445 -    unsigned long *va)
   7.446 +    gnttab_unmap_grant_ref_t *uop)
   7.447  {
   7.448      domid_t          dom;
   7.449      grant_ref_t      ref;
   7.450 @@ -500,7 +423,7 @@ static int
   7.451      grant_entry_t   *sha;
   7.452      grant_mapping_t *map;
   7.453      u16              flags;
   7.454 -    s16              rc = 1;
   7.455 +    s16              rc = 0;
   7.456      u64              addr, dev_bus_addr;
   7.457      unsigned long    frame;
   7.458  
   7.459 @@ -541,11 +464,6 @@ static int
   7.460          return GNTST_bad_domain;
   7.461      }
   7.462  
   7.463 -#if GRANT_DEBUG_VERBOSE
   7.464 -    DPRINTK("Unmapping grant ref (%hu) for domain (%hu) with handle (%hu)\n",
   7.465 -            ref, dom, handle);
   7.466 -#endif
   7.467 -
   7.468      act = &rd->grant_table->active[ref];
   7.469      sha = &rd->grant_table->shared[ref];
   7.470  
   7.471 @@ -566,8 +484,6 @@ static int
   7.472  
   7.473          map->ref_and_flags &= ~GNTMAP_device_map;
   7.474          (void)__put_user(0, &uop->dev_bus_addr);
   7.475 -
   7.476 -        /* Frame is now unmapped for device access. */
   7.477      }
   7.478  
   7.479      if ( (addr != 0) &&
   7.480 @@ -589,10 +505,6 @@ static int
   7.481  
   7.482          act->pin -= (flags & GNTMAP_readonly) ? GNTPIN_hstr_inc
   7.483                                                : GNTPIN_hstw_inc;
   7.484 -
   7.485 -        rc = 0;
   7.486 -        if ( !( flags & GNTMAP_contains_pte) )
   7.487 -            *va = addr;
   7.488      }
   7.489  
   7.490      if ( (map->ref_and_flags & (GNTMAP_device_map|GNTMAP_host_map)) == 0)
   7.491 @@ -632,17 +544,12 @@ static long
   7.492  gnttab_unmap_grant_ref(
   7.493      gnttab_unmap_grant_ref_t *uop, unsigned int count)
   7.494  {
   7.495 -    int i, flush = 0;
   7.496 -    unsigned long va = 0;
   7.497 +    int i;
   7.498  
   7.499      for ( i = 0; i < count; i++ )
   7.500 -        if ( __gnttab_unmap_grant_ref(&uop[i], &va) == 0 )
   7.501 -            flush++;
   7.502 +        (void)__gnttab_unmap_grant_ref(&uop[i]);
   7.503  
   7.504 -    if ( flush == 1 )
   7.505 -        flush_tlb_one_mask(current->domain->cpumask, va);
   7.506 -    else if ( flush != 0 ) 
   7.507 -        flush_tlb_mask(current->domain->cpumask);
   7.508 +    flush_tlb_mask(current->domain->cpumask);
   7.509  
   7.510      return 0;
   7.511  }
   7.512 @@ -703,9 +610,9 @@ gnttab_setup_table(
   7.513      return 0;
   7.514  }
   7.515  
   7.516 -#if GRANT_DEBUG
   7.517  static int
   7.518 -gnttab_dump_table(gnttab_dump_table_t *uop)
   7.519 +gnttab_dump_table(
   7.520 +    gnttab_dump_table_t *uop)
   7.521  {
   7.522      grant_table_t        *gt;
   7.523      gnttab_dump_table_t   op;
   7.524 @@ -716,6 +623,8 @@ gnttab_dump_table(gnttab_dump_table_t *u
   7.525      grant_mapping_t      *maptrack;
   7.526      int                   i;
   7.527  
   7.528 +    if ( !IS_PRIV(current->domain) )
   7.529 +        return -EPERM;
   7.530  
   7.531      if ( unlikely(copy_from_user(&op, uop, sizeof(op)) != 0) )
   7.532      {
   7.533 @@ -724,9 +633,7 @@ gnttab_dump_table(gnttab_dump_table_t *u
   7.534      }
   7.535  
   7.536      if ( op.dom == DOMID_SELF )
   7.537 -    {
   7.538          op.dom = current->domain->domain_id;
   7.539 -    }
   7.540  
   7.541      if ( unlikely((d = find_domain_by_id(op.dom)) == NULL) )
   7.542      {
   7.543 @@ -750,14 +657,11 @@ gnttab_dump_table(gnttab_dump_table_t *u
   7.544  
   7.545      for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   7.546      {
   7.547 -        sha_copy =  gt->shared[i];
   7.548 -
   7.549 +        sha_copy = gt->shared[i];
   7.550          if ( sha_copy.flags )
   7.551 -        {
   7.552              DPRINTK("Grant: dom (%hu) SHARED (%d) flags:(%hx) "
   7.553                      "dom:(%hu) frame:(%x)\n",
   7.554                      op.dom, i, sha_copy.flags, sha_copy.domid, sha_copy.frame);
   7.555 -        }
   7.556      }
   7.557  
   7.558      spin_lock(&gt->lock);
   7.559 @@ -765,28 +669,22 @@ gnttab_dump_table(gnttab_dump_table_t *u
   7.560      for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   7.561      {
   7.562          act = &gt->active[i];
   7.563 -
   7.564          if ( act->pin )
   7.565 -        {
   7.566              DPRINTK("Grant: dom (%hu) ACTIVE (%d) pin:(%x) "
   7.567                      "dom:(%hu) frame:(%lx)\n",
   7.568                      op.dom, i, act->pin, act->domid, act->frame);
   7.569 -        }
   7.570      }
   7.571  
   7.572      for ( i = 0; i < gt->maptrack_limit; i++ )
   7.573      {
   7.574          maptrack = &gt->maptrack[i];
   7.575 -
   7.576          if ( maptrack->ref_and_flags & MAPTRACK_GNTMAP_MASK )
   7.577 -        {
   7.578              DPRINTK("Grant: dom (%hu) MAP (%d) ref:(%hu) flags:(%x) "
   7.579                      "dom:(%hu)\n",
   7.580                      op.dom, i,
   7.581                      maptrack->ref_and_flags >> MAPTRACK_REF_SHIFT,
   7.582                      maptrack->ref_and_flags & MAPTRACK_GNTMAP_MASK,
   7.583                      maptrack->domid);
   7.584 -        }
   7.585      }
   7.586  
   7.587      spin_unlock(&gt->lock);
   7.588 @@ -794,10 +692,10 @@ gnttab_dump_table(gnttab_dump_table_t *u
   7.589      put_domain(d);
   7.590      return 0;
   7.591  }
   7.592 -#endif
   7.593  
   7.594  static long
   7.595 -gnttab_transfer(gnttab_transfer_t *uop, unsigned int count)
   7.596 +gnttab_transfer(
   7.597 +    gnttab_transfer_t *uop, unsigned int count)
   7.598  {
   7.599      struct domain *d = current->domain;
   7.600      struct domain *e;
   7.601 @@ -810,10 +708,7 @@ gnttab_transfer(gnttab_transfer_t *uop, 
   7.602      for ( i = 0; i < count; i++ )
   7.603      {
   7.604          gnttab_transfer_t *gop = &uop[i];
   7.605 -#if GRANT_DEBUG
   7.606 -        printk("gnttab_transfer: i=%d mfn=%lx domid=%d gref=%08x\n",
   7.607 -               i, gop->mfn, gop->domid, gop->handle);
   7.608 -#endif
   7.609 +
   7.610          page = &frame_table[gop->mfn];
   7.611          
   7.612          if ( unlikely(IS_XEN_HEAP_FRAME(page)))
   7.613 @@ -956,11 +851,9 @@ do_grant_table_op(
   7.614      case GNTTABOP_setup_table:
   7.615          rc = gnttab_setup_table((gnttab_setup_table_t *)uop, count);
   7.616          break;
   7.617 -#if GRANT_DEBUG
   7.618      case GNTTABOP_dump_table:
   7.619          rc = gnttab_dump_table((gnttab_dump_table_t *)uop);
   7.620          break;
   7.621 -#endif
   7.622      case GNTTABOP_transfer:
   7.623          if (unlikely(!array_access_ok(
   7.624              uop, count, sizeof(gnttab_transfer_t))))
   7.625 @@ -1002,12 +895,6 @@ gnttab_check_unmap(
   7.626      
   7.627      lgt = ld->grant_table;
   7.628      
   7.629 -#if GRANT_DEBUG_VERBOSE
   7.630 -    if ( ld->domain_id != 0 )
   7.631 -        DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   7.632 -                rd->domain_id, ld->domain_id, frame, readonly);
   7.633 -#endif
   7.634 -    
   7.635      /* Fast exit if we're not mapping anything using grant tables */
   7.636      if ( lgt->map_count == 0 )
   7.637          return 0;
   7.638 @@ -1098,11 +985,6 @@ gnttab_prepare_for_transfer(
   7.639      int            retries = 0;
   7.640      unsigned long  target_pfn;
   7.641  
   7.642 -#if GRANT_DEBUG_VERBOSE
   7.643 -    DPRINTK("gnttab_prepare_for_transfer rd(%hu) ld(%hu) ref(%hu).\n",
   7.644 -            rd->domain_id, ld->domain_id, ref);
   7.645 -#endif
   7.646 -
   7.647      if ( unlikely((rgt = rd->grant_table) == NULL) ||
   7.648           unlikely(ref >= NR_GRANT_ENTRIES) )
   7.649      {
     8.1 --- a/xen/include/asm-x86/mm.h	Fri Sep 23 16:56:46 2005 +0100
     8.2 +++ b/xen/include/asm-x86/mm.h	Fri Sep 23 16:57:13 2005 +0100
     8.3 @@ -380,11 +380,9 @@ extern int __sync_lazy_execstate(void);
     8.4   * hold a reference to the page.
     8.5   */
     8.6  int update_grant_va_mapping(
     8.7 -    unsigned long va, l1_pgentry_t _nl1e, 
     8.8 -    struct domain *d, struct vcpu *v);
     8.9 +    unsigned long va, l1_pgentry_t _nl1e, struct vcpu *v);
    8.10  int update_grant_pte_mapping(
    8.11 -    unsigned long pte_addr, l1_pgentry_t _nl1e, 
    8.12 -    struct domain *d, struct vcpu *v);
    8.13 +    unsigned long pte_addr, l1_pgentry_t _nl1e, struct vcpu *v);
    8.14  int clear_grant_va_mapping(unsigned long addr, unsigned long frame);
    8.15  int clear_grant_pte_mapping(
    8.16      unsigned long addr, unsigned long frame, struct domain *d);
     9.1 --- a/xen/include/xen/grant_table.h	Fri Sep 23 16:56:46 2005 +0100
     9.2 +++ b/xen/include/xen/grant_table.h	Fri Sep 23 16:57:13 2005 +0100
     9.3 @@ -110,8 +110,4 @@ gnttab_prepare_for_transfer(
     9.4  void
     9.5  gnttab_release_dev_mappings(grant_table_t *gt);
     9.6  
     9.7 -/* Extra GNTST_ values, for internal use only. */
     9.8 -#define GNTST_flush_all        (2)  /* Success, need to flush entire TLB.    */
     9.9 -#define GNTST_flush_one        (1)  /* Success, need to flush a vaddr.       */
    9.10 -
    9.11  #endif /* __XEN_GRANT_H__ */