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))
     2.1 --- a/xen/arch/x86/mm.c	Fri Sep 23 16:56:46 2005 +0100
     2.2 +++ b/xen/arch/x86/mm.c	Fri Sep 23 16:57:13 2005 +0100
     2.3 @@ -2273,8 +2273,7 @@ int do_mmu_update(
     2.4  
     2.5  
     2.6  int update_grant_pte_mapping(
     2.7 -    unsigned long pte_addr, l1_pgentry_t _nl1e, 
     2.8 -    struct domain *d, struct vcpu *v)
     2.9 +    unsigned long pte_addr, l1_pgentry_t _nl1e, struct vcpu *v)
    2.10  {
    2.11      int rc = GNTST_okay;
    2.12      void *va;
    2.13 @@ -2282,6 +2281,7 @@ int update_grant_pte_mapping(
    2.14      struct pfn_info *page;
    2.15      u32 type_info;
    2.16      l1_pgentry_t ol1e;
    2.17 +    struct domain *d = v->domain;
    2.18  
    2.19      ASSERT(spin_is_locked(&d->big_lock));
    2.20      ASSERT(!shadow_mode_refcounts(d));
    2.21 @@ -2319,8 +2319,6 @@ int update_grant_pte_mapping(
    2.22  
    2.23      put_page_from_l1e(ol1e, d);
    2.24  
    2.25 -    rc = (l1e_get_flags(ol1e) & _PAGE_PRESENT) ? GNTST_flush_all : GNTST_okay;
    2.26 -
    2.27      if ( unlikely(shadow_mode_enabled(d)) )
    2.28      {
    2.29          struct domain_mmap_cache sh_mapcache;
    2.30 @@ -2415,10 +2413,10 @@ int clear_grant_pte_mapping(
    2.31  
    2.32  
    2.33  int update_grant_va_mapping(
    2.34 -    unsigned long va, l1_pgentry_t _nl1e, struct domain *d, struct vcpu *v)
    2.35 +    unsigned long va, l1_pgentry_t _nl1e, struct vcpu *v)
    2.36  {
    2.37 -    int rc = GNTST_okay;
    2.38      l1_pgentry_t *pl1e, ol1e;
    2.39 +    struct domain *d = v->domain;
    2.40      
    2.41      ASSERT(spin_is_locked(&d->big_lock));
    2.42      ASSERT(!shadow_mode_refcounts(d));
    2.43 @@ -2439,12 +2437,10 @@ int update_grant_va_mapping(
    2.44  
    2.45      put_page_from_l1e(ol1e, d);
    2.46  
    2.47 -    rc = (l1e_get_flags(ol1e) & _PAGE_PRESENT) ? GNTST_flush_one : GNTST_okay;
    2.48 -
    2.49      if ( unlikely(shadow_mode_enabled(d)) )
    2.50          shadow_do_update_va_mapping(va, _nl1e, v);
    2.51  
    2.52 -    return rc;
    2.53 +    return GNTST_okay;
    2.54  }
    2.55  
    2.56  int clear_grant_va_mapping(unsigned long addr, unsigned long frame)
     3.1 --- a/xen/common/grant_table.c	Fri Sep 23 16:56:46 2005 +0100
     3.2 +++ b/xen/common/grant_table.c	Fri Sep 23 16:57:13 2005 +0100
     3.3 @@ -24,10 +24,6 @@
     3.4   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     3.5   */
     3.6  
     3.7 -#define GRANT_DEBUG 0
     3.8 -#define GRANT_DEBUG_VERBOSE 0
     3.9 -
    3.10 -#include <xen/config.h>
    3.11  #include <xen/lib.h>
    3.12  #include <xen/sched.h>
    3.13  #include <xen/shadow.h>
    3.14 @@ -68,39 +64,32 @@ put_maptrack_handle(
    3.15      t->map_count--;
    3.16  }
    3.17  
    3.18 +/*
    3.19 + * Returns 0 if TLB flush / invalidate required by caller.
    3.20 + * va will indicate the address to be invalidated.
    3.21 + * 
    3.22 + * addr is _either_ a host virtual address, or the address of the pte to
    3.23 + * update, as indicated by the GNTMAP_contains_pte flag.
    3.24 + */
    3.25  static int
    3.26 -__gnttab_activate_grant_ref(
    3.27 -    struct domain   *mapping_d,          /* IN */
    3.28 -    struct vcpu     *mapping_ed,
    3.29 -    struct domain   *granting_d,
    3.30 -    grant_ref_t      ref,
    3.31 -    u16              dev_hst_ro_flags,
    3.32 -    u64              addr,
    3.33 -    unsigned long   *pframe )            /* OUT */
    3.34 +__gnttab_map_grant_ref(
    3.35 +    gnttab_map_grant_ref_t *uop)
    3.36  {
    3.37 -    domid_t               sdom;
    3.38 -    u16                   sflags;
    3.39 +    domid_t        dom;
    3.40 +    grant_ref_t    ref;
    3.41 +    struct domain *ld, *rd;
    3.42 +    struct vcpu   *led;
    3.43 +    u16            dev_hst_ro_flags;
    3.44 +    int            handle;
    3.45 +    u64            addr;
    3.46 +    unsigned long  frame = 0;
    3.47 +    int            rc;
    3.48      active_grant_entry_t *act;
    3.49 -    grant_entry_t        *sha;
    3.50 -    s16                   rc = 1;
    3.51 -    unsigned long         frame = 0;
    3.52 -    int                   retries = 0;
    3.53  
    3.54 -    /*
    3.55 -     * Objectives of this function:
    3.56 -     * . Make the record ( granting_d, ref ) active, if not already.
    3.57 -     * . Update shared grant entry of owner, indicating frame is mapped.
    3.58 -     * . Increment the owner act->pin reference counts.
    3.59 -     * . get_page on shared frame if new mapping.
    3.60 -     * . get_page_type if this is first RW mapping of frame.
    3.61 -     * . Add PTE to virtual address space of mapping_d, if necessary.
    3.62 -     * Returns:
    3.63 -     * .  -ve: error
    3.64 -     * .    1: ok
    3.65 -     * .    0: ok and TLB invalidate of host_addr needed.
    3.66 -     *
    3.67 -     * On success, *pframe contains mfn.
    3.68 -     */
    3.69 +    /* Entry details from @rd's shared grant table. */
    3.70 +    grant_entry_t *sha;
    3.71 +    domid_t        sdom;
    3.72 +    u16            sflags;
    3.73  
    3.74      /*
    3.75       * We bound the number of times we retry CMPXCHG on memory locations that
    3.76 @@ -110,11 +99,88 @@ static int
    3.77       * the guest to race our updates (e.g., to change the GTF_readonly flag),
    3.78       * so we allow a few retries before failing.
    3.79       */
    3.80 +    int retries = 0;
    3.81  
    3.82 -    act = &granting_d->grant_table->active[ref];
    3.83 -    sha = &granting_d->grant_table->shared[ref];
    3.84 +    led = current;
    3.85 +    ld = led->domain;
    3.86  
    3.87 -    spin_lock(&granting_d->grant_table->lock);
    3.88 +    /* Bitwise-OR avoids short-circuiting which screws control flow. */
    3.89 +    if ( unlikely(__get_user(dom, &uop->dom) |
    3.90 +                  __get_user(ref, &uop->ref) |
    3.91 +                  __get_user(addr, &uop->host_addr) |
    3.92 +                  __get_user(dev_hst_ro_flags, &uop->flags)) )
    3.93 +    {
    3.94 +        DPRINTK("Fault while reading gnttab_map_grant_ref_t.\n");
    3.95 +        return -EFAULT; /* don't set status */
    3.96 +    }
    3.97 +
    3.98 +    if ( unlikely(ref >= NR_GRANT_ENTRIES) ||
    3.99 +         unlikely((dev_hst_ro_flags &
   3.100 +                   (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
   3.101 +    {
   3.102 +        DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
   3.103 +        (void)__put_user(GNTST_bad_gntref, &uop->handle);
   3.104 +        return GNTST_bad_gntref;
   3.105 +    }
   3.106 +
   3.107 +    if ( acm_pre_grant_map_ref(dom) )
   3.108 +    {
   3.109 +        (void)__put_user(GNTST_permission_denied, &uop->handle);
   3.110 +        return GNTST_permission_denied;
   3.111 +    }
   3.112 +
   3.113 +    if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   3.114 +         unlikely(ld == rd) )
   3.115 +    {
   3.116 +        if ( rd != NULL )
   3.117 +            put_domain(rd);
   3.118 +        DPRINTK("Could not find domain %d\n", dom);
   3.119 +        (void)__put_user(GNTST_bad_domain, &uop->handle);
   3.120 +        return GNTST_bad_domain;
   3.121 +    }
   3.122 +
   3.123 +    /* Get a maptrack handle. */
   3.124 +    if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
   3.125 +    {
   3.126 +        int              i;
   3.127 +        grant_mapping_t *new_mt;
   3.128 +        grant_table_t   *lgt = ld->grant_table;
   3.129 +
   3.130 +        if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
   3.131 +        {
   3.132 +            put_domain(rd);
   3.133 +            DPRINTK("Maptrack table is at maximum size.\n");
   3.134 +            (void)__put_user(GNTST_no_device_space, &uop->handle);
   3.135 +            return GNTST_no_device_space;
   3.136 +        }
   3.137 +
   3.138 +        /* Grow the maptrack table. */
   3.139 +        new_mt = alloc_xenheap_pages(lgt->maptrack_order + 1);
   3.140 +        if ( new_mt == NULL )
   3.141 +        {
   3.142 +            put_domain(rd);
   3.143 +            DPRINTK("No more map handles available.\n");
   3.144 +            (void)__put_user(GNTST_no_device_space, &uop->handle);
   3.145 +            return GNTST_no_device_space;
   3.146 +        }
   3.147 +
   3.148 +        memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   3.149 +        for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   3.150 +            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
   3.151 +
   3.152 +        free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   3.153 +        lgt->maptrack          = new_mt;
   3.154 +        lgt->maptrack_order   += 1;
   3.155 +        lgt->maptrack_limit  <<= 1;
   3.156 +
   3.157 +        DPRINTK("Doubled maptrack size\n");
   3.158 +        handle = get_maptrack_handle(ld->grant_table);
   3.159 +    }
   3.160 +
   3.161 +    act = &rd->grant_table->active[ref];
   3.162 +    sha = &rd->grant_table->shared[ref];
   3.163 +
   3.164 +    spin_lock(&rd->grant_table->lock);
   3.165  
   3.166      if ( act->pin == 0 )
   3.167      {
   3.168 @@ -132,10 +198,10 @@ static int
   3.169              u32 scombo, prev_scombo, new_scombo;
   3.170  
   3.171              if ( unlikely((sflags & GTF_type_mask) != GTF_permit_access) ||
   3.172 -                 unlikely(sdom != mapping_d->domain_id) )
   3.173 +                 unlikely(sdom != led->domain->domain_id) )
   3.174                  PIN_FAIL(unlock_out, GNTST_general_error,
   3.175                           "Bad flags (%x) or dom (%d). (NB. expected dom %d)\n",
   3.176 -                        sflags, sdom, mapping_d->domain_id);
   3.177 +                        sflags, sdom, led->domain->domain_id);
   3.178  
   3.179              /* Merge two 16-bit values into a 32-bit combined update. */
   3.180              /* NB. Endianness! */
   3.181 @@ -173,12 +239,12 @@ static int
   3.182  
   3.183          /* rmb(); */ /* not on x86 */
   3.184  
   3.185 -        frame = __gpfn_to_mfn_foreign(granting_d, sha->frame);
   3.186 +        frame = __gpfn_to_mfn_foreign(rd, sha->frame);
   3.187  
   3.188          if ( unlikely(!pfn_valid(frame)) ||
   3.189               unlikely(!((dev_hst_ro_flags & GNTMAP_readonly) ?
   3.190 -                        get_page(&frame_table[frame], granting_d) :
   3.191 -                        get_page_and_type(&frame_table[frame], granting_d,
   3.192 +                        get_page(&frame_table[frame], rd) :
   3.193 +                        get_page_and_type(&frame_table[frame], rd,
   3.194                                            PGT_writable_page))) )
   3.195          {
   3.196              clear_bit(_GTF_writing, &sha->flags);
   3.197 @@ -208,10 +274,11 @@ static int
   3.198              PIN_FAIL(unlock_out, ENOSPC,
   3.199                       "Risk of counter overflow %08x\n", act->pin);
   3.200  
   3.201 -        frame = act->frame;
   3.202 +        sflags = sha->flags;
   3.203 +        frame  = act->frame;
   3.204  
   3.205 -        if ( !(dev_hst_ro_flags & GNTMAP_readonly) && 
   3.206 -             !((sflags = sha->flags) & GTF_writing) )
   3.207 +        if ( !(dev_hst_ro_flags & GNTMAP_readonly) &&
   3.208 +             !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
   3.209          {
   3.210              for ( ; ; )
   3.211              {
   3.212 @@ -264,9 +331,9 @@ static int
   3.213       * frame contains the mfn.
   3.214       */
   3.215  
   3.216 -    spin_unlock(&granting_d->grant_table->lock);
   3.217 +    spin_unlock(&rd->grant_table->lock);
   3.218  
   3.219 -    if ( (addr != 0) && (dev_hst_ro_flags & GNTMAP_host_map) )
   3.220 +    if ( dev_hst_ro_flags & GNTMAP_host_map )
   3.221      {
   3.222          /* Write update into the pagetable. */
   3.223          l1_pgentry_t pte;
   3.224 @@ -278,18 +345,15 @@ static int
   3.225              l1e_add_flags(pte,_PAGE_RW);
   3.226  
   3.227          if ( dev_hst_ro_flags & GNTMAP_contains_pte )
   3.228 -            rc = update_grant_pte_mapping(addr, pte, mapping_d, mapping_ed);
   3.229 +            rc = update_grant_pte_mapping(addr, pte, led);
   3.230          else
   3.231 -            rc = update_grant_va_mapping(addr, pte, mapping_d, mapping_ed);
   3.232 +            rc = update_grant_va_mapping(addr, pte, led);
   3.233  
   3.234 -        /* IMPORTANT: rc indicates the degree of TLB flush that is required.
   3.235 -         * GNTST_flush_one (1) or GNTST_flush_all (2). This is done in the 
   3.236 -         * outer gnttab_map_grant_ref. */
   3.237          if ( rc < 0 )
   3.238          {
   3.239              /* Failure: undo and abort. */
   3.240  
   3.241 -            spin_lock(&granting_d->grant_table->lock);
   3.242 +            spin_lock(&rd->grant_table->lock);
   3.243  
   3.244              if ( dev_hst_ro_flags & GNTMAP_readonly )
   3.245              {
   3.246 @@ -311,160 +375,27 @@ static int
   3.247                  put_page(&frame_table[frame]);
   3.248              }
   3.249  
   3.250 -            spin_unlock(&granting_d->grant_table->lock);
   3.251 +            spin_unlock(&rd->grant_table->lock);
   3.252          }
   3.253  
   3.254      }
   3.255  
   3.256 -    *pframe = frame;
   3.257 +    ld->grant_table->maptrack[handle].domid         = dom;
   3.258 +    ld->grant_table->maptrack[handle].ref_and_flags =
   3.259 +        (ref << MAPTRACK_REF_SHIFT) |
   3.260 +        (dev_hst_ro_flags & MAPTRACK_GNTMAP_MASK);
   3.261 +
   3.262 +    (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
   3.263 +    (void)__put_user(handle, &uop->handle);
   3.264 +
   3.265 +    put_domain(rd);
   3.266      return rc;
   3.267  
   3.268 +
   3.269   unlock_out:
   3.270 -    spin_unlock(&granting_d->grant_table->lock);
   3.271 -    return rc;
   3.272 -}
   3.273 -
   3.274 -/*
   3.275 - * Returns 0 if TLB flush / invalidate required by caller.
   3.276 - * va will indicate the address to be invalidated.
   3.277 - * 
   3.278 - * addr is _either_ a host virtual address, or the address of the pte to
   3.279 - * update, as indicated by the GNTMAP_contains_pte flag.
   3.280 - */
   3.281 -static int
   3.282 -__gnttab_map_grant_ref(
   3.283 -    gnttab_map_grant_ref_t *uop,
   3.284 -    unsigned long *va)
   3.285 -{
   3.286 -    domid_t        dom;
   3.287 -    grant_ref_t    ref;
   3.288 -    struct domain *ld, *rd;
   3.289 -    struct vcpu   *led;
   3.290 -    u16            dev_hst_ro_flags;
   3.291 -    int            handle;
   3.292 -    u64            addr;
   3.293 -    unsigned long  frame = 0;
   3.294 -    int            rc;
   3.295 -
   3.296 -    led = current;
   3.297 -    ld = led->domain;
   3.298 -
   3.299 -    /* Bitwise-OR avoids short-circuiting which screws control flow. */
   3.300 -    if ( unlikely(__get_user(dom, &uop->dom) |
   3.301 -                  __get_user(ref, &uop->ref) |
   3.302 -                  __get_user(addr, &uop->host_addr) |
   3.303 -                  __get_user(dev_hst_ro_flags, &uop->flags)) )
   3.304 -    {
   3.305 -        DPRINTK("Fault while reading gnttab_map_grant_ref_t.\n");
   3.306 -        return -EFAULT; /* don't set status */
   3.307 -    }
   3.308 -
   3.309 -    if ( (dev_hst_ro_flags & GNTMAP_host_map) &&
   3.310 -         ( (addr == 0) ||
   3.311 -           (!(dev_hst_ro_flags & GNTMAP_contains_pte) && 
   3.312 -            unlikely(!__addr_ok(addr))) ) )
   3.313 -    {
   3.314 -        DPRINTK("Bad virtual address (%"PRIx64") or flags (%"PRIx16").\n",
   3.315 -                addr, dev_hst_ro_flags);
   3.316 -        (void)__put_user(GNTST_bad_virt_addr, &uop->handle);
   3.317 -        return GNTST_bad_gntref;
   3.318 -    }
   3.319 -
   3.320 -    if ( unlikely(ref >= NR_GRANT_ENTRIES) ||
   3.321 -         unlikely((dev_hst_ro_flags &
   3.322 -                   (GNTMAP_device_map|GNTMAP_host_map)) == 0) )
   3.323 -    {
   3.324 -        DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
   3.325 -        (void)__put_user(GNTST_bad_gntref, &uop->handle);
   3.326 -        return GNTST_bad_gntref;
   3.327 -    }
   3.328 -
   3.329 -    if (acm_pre_grant_map_ref(dom)) {
   3.330 -        (void)__put_user(GNTST_permission_denied, &uop->handle);
   3.331 -        return GNTST_permission_denied;
   3.332 -    }
   3.333 -
   3.334 -    if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   3.335 -         unlikely(ld == rd) )
   3.336 -    {
   3.337 -        if ( rd != NULL )
   3.338 -            put_domain(rd);
   3.339 -        DPRINTK("Could not find domain %d\n", dom);
   3.340 -        (void)__put_user(GNTST_bad_domain, &uop->handle);
   3.341 -        return GNTST_bad_domain;
   3.342 -    }
   3.343 -
   3.344 -    /* Get a maptrack handle. */
   3.345 -    if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
   3.346 -    {
   3.347 -        int              i;
   3.348 -        grant_mapping_t *new_mt;
   3.349 -        grant_table_t   *lgt = ld->grant_table;
   3.350 -
   3.351 -        if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
   3.352 -        {
   3.353 -            put_domain(rd);
   3.354 -            DPRINTK("Maptrack table is at maximum size.\n");
   3.355 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   3.356 -            return GNTST_no_device_space;
   3.357 -        }
   3.358 -
   3.359 -        /* Grow the maptrack table. */
   3.360 -        new_mt = alloc_xenheap_pages(lgt->maptrack_order + 1);
   3.361 -        if ( new_mt == NULL )
   3.362 -        {
   3.363 -            put_domain(rd);
   3.364 -            DPRINTK("No more map handles available.\n");
   3.365 -            (void)__put_user(GNTST_no_device_space, &uop->handle);
   3.366 -            return GNTST_no_device_space;
   3.367 -        }
   3.368 -
   3.369 -        memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   3.370 -        for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   3.371 -            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
   3.372 -
   3.373 -        free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   3.374 -        lgt->maptrack          = new_mt;
   3.375 -        lgt->maptrack_order   += 1;
   3.376 -        lgt->maptrack_limit  <<= 1;
   3.377 -
   3.378 -        DPRINTK("Doubled maptrack size\n");
   3.379 -        handle = get_maptrack_handle(ld->grant_table);
   3.380 -    }
   3.381 -
   3.382 -#if GRANT_DEBUG_VERBOSE
   3.383 -    DPRINTK("Mapping grant ref (%hu) for domain (%hu) with flags (%x)\n",
   3.384 -            ref, dom, dev_hst_ro_flags);
   3.385 -#endif
   3.386 -
   3.387 -    if ( (rc = __gnttab_activate_grant_ref(ld, led, rd, ref, dev_hst_ro_flags,
   3.388 -                                           addr, &frame)) >= 0 )
   3.389 -    {
   3.390 -        /*
   3.391 -         * Only make the maptrack live _after_ writing the pte, in case we 
   3.392 -         * overwrite the same frame number, causing a maptrack walk to find it
   3.393 -         */
   3.394 -        ld->grant_table->maptrack[handle].domid = dom;
   3.395 -
   3.396 -        ld->grant_table->maptrack[handle].ref_and_flags
   3.397 -            = (ref << MAPTRACK_REF_SHIFT) |
   3.398 -              (dev_hst_ro_flags & MAPTRACK_GNTMAP_MASK);
   3.399 -
   3.400 -        (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
   3.401 -
   3.402 -        if ( ( dev_hst_ro_flags & GNTMAP_host_map ) &&
   3.403 -             !( dev_hst_ro_flags & GNTMAP_contains_pte) )
   3.404 -            *va = addr;
   3.405 -
   3.406 -        (void)__put_user(handle, &uop->handle);
   3.407 -    }
   3.408 -    else
   3.409 -    {
   3.410 -        (void)__put_user(rc, &uop->handle);
   3.411 -        put_maptrack_handle(ld->grant_table, handle);
   3.412 -    }
   3.413 -
   3.414 -    put_domain(rd);
   3.415 +    spin_unlock(&rd->grant_table->lock);
   3.416 +    (void)__put_user(rc, &uop->handle);
   3.417 +    put_maptrack_handle(ld->grant_table, handle);
   3.418      return rc;
   3.419  }
   3.420  
   3.421 @@ -472,25 +403,17 @@ static long
   3.422  gnttab_map_grant_ref(
   3.423      gnttab_map_grant_ref_t *uop, unsigned int count)
   3.424  {
   3.425 -    int i, rc, flush = 0;
   3.426 -    unsigned long va = 0;
   3.427 +    int i;
   3.428  
   3.429      for ( i = 0; i < count; i++ )
   3.430 -        if ( (rc =__gnttab_map_grant_ref(&uop[i], &va)) >= 0 )
   3.431 -            flush += rc;
   3.432 -
   3.433 -    if ( flush == 1 )
   3.434 -        flush_tlb_one_mask(current->domain->cpumask, va);
   3.435 -    else if ( flush != 0 ) 
   3.436 -        flush_tlb_mask(current->domain->cpumask);
   3.437 +        (void)__gnttab_map_grant_ref(&uop[i]);
   3.438  
   3.439      return 0;
   3.440  }
   3.441  
   3.442  static int
   3.443  __gnttab_unmap_grant_ref(
   3.444 -    gnttab_unmap_grant_ref_t *uop,
   3.445 -    unsigned long *va)
   3.446 +    gnttab_unmap_grant_ref_t *uop)
   3.447  {
   3.448      domid_t          dom;
   3.449      grant_ref_t      ref;
   3.450 @@ -500,7 +423,7 @@ static int
   3.451      grant_entry_t   *sha;
   3.452      grant_mapping_t *map;
   3.453      u16              flags;
   3.454 -    s16              rc = 1;
   3.455 +    s16              rc = 0;
   3.456      u64              addr, dev_bus_addr;
   3.457      unsigned long    frame;
   3.458  
   3.459 @@ -541,11 +464,6 @@ static int
   3.460          return GNTST_bad_domain;
   3.461      }
   3.462  
   3.463 -#if GRANT_DEBUG_VERBOSE
   3.464 -    DPRINTK("Unmapping grant ref (%hu) for domain (%hu) with handle (%hu)\n",
   3.465 -            ref, dom, handle);
   3.466 -#endif
   3.467 -
   3.468      act = &rd->grant_table->active[ref];
   3.469      sha = &rd->grant_table->shared[ref];
   3.470  
   3.471 @@ -566,8 +484,6 @@ static int
   3.472  
   3.473          map->ref_and_flags &= ~GNTMAP_device_map;
   3.474          (void)__put_user(0, &uop->dev_bus_addr);
   3.475 -
   3.476 -        /* Frame is now unmapped for device access. */
   3.477      }
   3.478  
   3.479      if ( (addr != 0) &&
   3.480 @@ -589,10 +505,6 @@ static int
   3.481  
   3.482          act->pin -= (flags & GNTMAP_readonly) ? GNTPIN_hstr_inc
   3.483                                                : GNTPIN_hstw_inc;
   3.484 -
   3.485 -        rc = 0;
   3.486 -        if ( !( flags & GNTMAP_contains_pte) )
   3.487 -            *va = addr;
   3.488      }
   3.489  
   3.490      if ( (map->ref_and_flags & (GNTMAP_device_map|GNTMAP_host_map)) == 0)
   3.491 @@ -632,17 +544,12 @@ static long
   3.492  gnttab_unmap_grant_ref(
   3.493      gnttab_unmap_grant_ref_t *uop, unsigned int count)
   3.494  {
   3.495 -    int i, flush = 0;
   3.496 -    unsigned long va = 0;
   3.497 +    int i;
   3.498  
   3.499      for ( i = 0; i < count; i++ )
   3.500 -        if ( __gnttab_unmap_grant_ref(&uop[i], &va) == 0 )
   3.501 -            flush++;
   3.502 +        (void)__gnttab_unmap_grant_ref(&uop[i]);
   3.503  
   3.504 -    if ( flush == 1 )
   3.505 -        flush_tlb_one_mask(current->domain->cpumask, va);
   3.506 -    else if ( flush != 0 ) 
   3.507 -        flush_tlb_mask(current->domain->cpumask);
   3.508 +    flush_tlb_mask(current->domain->cpumask);
   3.509  
   3.510      return 0;
   3.511  }
   3.512 @@ -703,9 +610,9 @@ gnttab_setup_table(
   3.513      return 0;
   3.514  }
   3.515  
   3.516 -#if GRANT_DEBUG
   3.517  static int
   3.518 -gnttab_dump_table(gnttab_dump_table_t *uop)
   3.519 +gnttab_dump_table(
   3.520 +    gnttab_dump_table_t *uop)
   3.521  {
   3.522      grant_table_t        *gt;
   3.523      gnttab_dump_table_t   op;
   3.524 @@ -716,6 +623,8 @@ gnttab_dump_table(gnttab_dump_table_t *u
   3.525      grant_mapping_t      *maptrack;
   3.526      int                   i;
   3.527  
   3.528 +    if ( !IS_PRIV(current->domain) )
   3.529 +        return -EPERM;
   3.530  
   3.531      if ( unlikely(copy_from_user(&op, uop, sizeof(op)) != 0) )
   3.532      {
   3.533 @@ -724,9 +633,7 @@ gnttab_dump_table(gnttab_dump_table_t *u
   3.534      }
   3.535  
   3.536      if ( op.dom == DOMID_SELF )
   3.537 -    {
   3.538          op.dom = current->domain->domain_id;
   3.539 -    }
   3.540  
   3.541      if ( unlikely((d = find_domain_by_id(op.dom)) == NULL) )
   3.542      {
   3.543 @@ -750,14 +657,11 @@ gnttab_dump_table(gnttab_dump_table_t *u
   3.544  
   3.545      for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   3.546      {
   3.547 -        sha_copy =  gt->shared[i];
   3.548 -
   3.549 +        sha_copy = gt->shared[i];
   3.550          if ( sha_copy.flags )
   3.551 -        {
   3.552              DPRINTK("Grant: dom (%hu) SHARED (%d) flags:(%hx) "
   3.553                      "dom:(%hu) frame:(%x)\n",
   3.554                      op.dom, i, sha_copy.flags, sha_copy.domid, sha_copy.frame);
   3.555 -        }
   3.556      }
   3.557  
   3.558      spin_lock(&gt->lock);
   3.559 @@ -765,28 +669,22 @@ gnttab_dump_table(gnttab_dump_table_t *u
   3.560      for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   3.561      {
   3.562          act = &gt->active[i];
   3.563 -
   3.564          if ( act->pin )
   3.565 -        {
   3.566              DPRINTK("Grant: dom (%hu) ACTIVE (%d) pin:(%x) "
   3.567                      "dom:(%hu) frame:(%lx)\n",
   3.568                      op.dom, i, act->pin, act->domid, act->frame);
   3.569 -        }
   3.570      }
   3.571  
   3.572      for ( i = 0; i < gt->maptrack_limit; i++ )
   3.573      {
   3.574          maptrack = &gt->maptrack[i];
   3.575 -
   3.576          if ( maptrack->ref_and_flags & MAPTRACK_GNTMAP_MASK )
   3.577 -        {
   3.578              DPRINTK("Grant: dom (%hu) MAP (%d) ref:(%hu) flags:(%x) "
   3.579                      "dom:(%hu)\n",
   3.580                      op.dom, i,
   3.581                      maptrack->ref_and_flags >> MAPTRACK_REF_SHIFT,
   3.582                      maptrack->ref_and_flags & MAPTRACK_GNTMAP_MASK,
   3.583                      maptrack->domid);
   3.584 -        }
   3.585      }
   3.586  
   3.587      spin_unlock(&gt->lock);
   3.588 @@ -794,10 +692,10 @@ gnttab_dump_table(gnttab_dump_table_t *u
   3.589      put_domain(d);
   3.590      return 0;
   3.591  }
   3.592 -#endif
   3.593  
   3.594  static long
   3.595 -gnttab_transfer(gnttab_transfer_t *uop, unsigned int count)
   3.596 +gnttab_transfer(
   3.597 +    gnttab_transfer_t *uop, unsigned int count)
   3.598  {
   3.599      struct domain *d = current->domain;
   3.600      struct domain *e;
   3.601 @@ -810,10 +708,7 @@ gnttab_transfer(gnttab_transfer_t *uop, 
   3.602      for ( i = 0; i < count; i++ )
   3.603      {
   3.604          gnttab_transfer_t *gop = &uop[i];
   3.605 -#if GRANT_DEBUG
   3.606 -        printk("gnttab_transfer: i=%d mfn=%lx domid=%d gref=%08x\n",
   3.607 -               i, gop->mfn, gop->domid, gop->handle);
   3.608 -#endif
   3.609 +
   3.610          page = &frame_table[gop->mfn];
   3.611          
   3.612          if ( unlikely(IS_XEN_HEAP_FRAME(page)))
   3.613 @@ -956,11 +851,9 @@ do_grant_table_op(
   3.614      case GNTTABOP_setup_table:
   3.615          rc = gnttab_setup_table((gnttab_setup_table_t *)uop, count);
   3.616          break;
   3.617 -#if GRANT_DEBUG
   3.618      case GNTTABOP_dump_table:
   3.619          rc = gnttab_dump_table((gnttab_dump_table_t *)uop);
   3.620          break;
   3.621 -#endif
   3.622      case GNTTABOP_transfer:
   3.623          if (unlikely(!array_access_ok(
   3.624              uop, count, sizeof(gnttab_transfer_t))))
   3.625 @@ -1002,12 +895,6 @@ gnttab_check_unmap(
   3.626      
   3.627      lgt = ld->grant_table;
   3.628      
   3.629 -#if GRANT_DEBUG_VERBOSE
   3.630 -    if ( ld->domain_id != 0 )
   3.631 -        DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   3.632 -                rd->domain_id, ld->domain_id, frame, readonly);
   3.633 -#endif
   3.634 -    
   3.635      /* Fast exit if we're not mapping anything using grant tables */
   3.636      if ( lgt->map_count == 0 )
   3.637          return 0;
   3.638 @@ -1098,11 +985,6 @@ gnttab_prepare_for_transfer(
   3.639      int            retries = 0;
   3.640      unsigned long  target_pfn;
   3.641  
   3.642 -#if GRANT_DEBUG_VERBOSE
   3.643 -    DPRINTK("gnttab_prepare_for_transfer rd(%hu) ld(%hu) ref(%hu).\n",
   3.644 -            rd->domain_id, ld->domain_id, ref);
   3.645 -#endif
   3.646 -
   3.647      if ( unlikely((rgt = rd->grant_table) == NULL) ||
   3.648           unlikely(ref >= NR_GRANT_ENTRIES) )
   3.649      {
     4.1 --- a/xen/include/asm-x86/mm.h	Fri Sep 23 16:56:46 2005 +0100
     4.2 +++ b/xen/include/asm-x86/mm.h	Fri Sep 23 16:57:13 2005 +0100
     4.3 @@ -380,11 +380,9 @@ extern int __sync_lazy_execstate(void);
     4.4   * hold a reference to the page.
     4.5   */
     4.6  int update_grant_va_mapping(
     4.7 -    unsigned long va, l1_pgentry_t _nl1e, 
     4.8 -    struct domain *d, struct vcpu *v);
     4.9 +    unsigned long va, l1_pgentry_t _nl1e, struct vcpu *v);
    4.10  int update_grant_pte_mapping(
    4.11 -    unsigned long pte_addr, l1_pgentry_t _nl1e, 
    4.12 -    struct domain *d, struct vcpu *v);
    4.13 +    unsigned long pte_addr, l1_pgentry_t _nl1e, struct vcpu *v);
    4.14  int clear_grant_va_mapping(unsigned long addr, unsigned long frame);
    4.15  int clear_grant_pte_mapping(
    4.16      unsigned long addr, unsigned long frame, struct domain *d);
     5.1 --- a/xen/include/xen/grant_table.h	Fri Sep 23 16:56:46 2005 +0100
     5.2 +++ b/xen/include/xen/grant_table.h	Fri Sep 23 16:57:13 2005 +0100
     5.3 @@ -110,8 +110,4 @@ gnttab_prepare_for_transfer(
     5.4  void
     5.5  gnttab_release_dev_mappings(grant_table_t *gt);
     5.6  
     5.7 -/* Extra GNTST_ values, for internal use only. */
     5.8 -#define GNTST_flush_all        (2)  /* Success, need to flush entire TLB.    */
     5.9 -#define GNTST_flush_one        (1)  /* Success, need to flush a vaddr.       */
    5.10 -
    5.11  #endif /* __XEN_GRANT_H__ */