ia64/xen-unstable

changeset 19694:2e83c670f680

Revert 19658:28a197617286 "Fix up the synchronisation around grant
table map track handles".

There is no race since the hypercall takes the
domain-lock. Furthermore removing locking from get_maptrack_handle()
races gnttab_setup_table().

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 01 14:55:32 2009 +0100 (2009-06-01)
parents 28c6c955998c
children 027f19e97e28
files xen/common/grant_table.c xen/include/xen/grant_table.h
line diff
     1.1 --- a/xen/common/grant_table.c	Mon Jun 01 14:39:25 2009 +0100
     1.2 +++ b/xen/common/grant_table.c	Mon Jun 01 14:55:32 2009 +0100
     1.3 @@ -111,26 +111,6 @@ static unsigned inline int max_nr_maptra
     1.4  #define active_entry(t, e) \
     1.5      ((t)->active[(e)/ACGNT_PER_PAGE][(e)%ACGNT_PER_PAGE])
     1.6  
     1.7 -/* Technically, we only really need to acquire the lock for SMP
     1.8 -   guests, because you only ever touch the maptrack tables from the
     1.9 -   context of the guest which owns them, so if it's uniproc then the
    1.10 -   lock can't be contended, and is therefore pointless.  Don't bother
    1.11 -   with that optimisation for now, though, because it's scary and
    1.12 -   confusing. */
    1.13 -/* The maptrack lock is top-level: you're not allowed to be holding
    1.14 -   any other locks when you acquire it. */
    1.15 -static void
    1.16 -maptrack_lock(struct grant_table *lgt)
    1.17 -{
    1.18 -    spin_lock(&lgt->maptrack_lock);
    1.19 -}
    1.20 -
    1.21 -static void
    1.22 -maptrack_unlock(struct grant_table *lgt)
    1.23 -{
    1.24 -    spin_unlock(&lgt->maptrack_lock);
    1.25 -}
    1.26 -
    1.27  static inline int
    1.28  __get_maptrack_handle(
    1.29      struct grant_table *t)
    1.30 @@ -161,30 +141,43 @@ get_maptrack_handle(
    1.31  
    1.32      if ( unlikely((handle = __get_maptrack_handle(lgt)) == -1) )
    1.33      {
    1.34 -        nr_frames = nr_maptrack_frames(lgt);
    1.35 -        if ( nr_frames >= max_nr_maptrack_frames() )
    1.36 -            return -1;
    1.37 -
    1.38 -        new_mt = alloc_xenheap_page();
    1.39 -        if ( new_mt == NULL )
    1.40 -            return -1;
    1.41 +        spin_lock(&lgt->lock);
    1.42  
    1.43 -        clear_page(new_mt);
    1.44 -
    1.45 -        new_mt_limit = lgt->maptrack_limit + MAPTRACK_PER_PAGE;
    1.46 +        if ( unlikely((handle = __get_maptrack_handle(lgt)) == -1) )
    1.47 +        {
    1.48 +            nr_frames = nr_maptrack_frames(lgt);
    1.49 +            if ( nr_frames >= max_nr_maptrack_frames() )
    1.50 +            {
    1.51 +                spin_unlock(&lgt->lock);
    1.52 +                return -1;
    1.53 +            }
    1.54  
    1.55 -        for ( i = lgt->maptrack_limit; i < new_mt_limit; i++ )
    1.56 -        {
    1.57 -            new_mt[i % MAPTRACK_PER_PAGE].ref = i+1;
    1.58 -            new_mt[i % MAPTRACK_PER_PAGE].flags = 0;
    1.59 +            new_mt = alloc_xenheap_page();
    1.60 +            if ( new_mt == NULL )
    1.61 +            {
    1.62 +                spin_unlock(&lgt->lock);
    1.63 +                return -1;
    1.64 +            }
    1.65 +
    1.66 +            clear_page(new_mt);
    1.67 +
    1.68 +            new_mt_limit = lgt->maptrack_limit + MAPTRACK_PER_PAGE;
    1.69 +
    1.70 +            for ( i = lgt->maptrack_limit; i < new_mt_limit; i++ )
    1.71 +            {
    1.72 +                new_mt[i % MAPTRACK_PER_PAGE].ref = i+1;
    1.73 +                new_mt[i % MAPTRACK_PER_PAGE].flags = 0;
    1.74 +            }
    1.75 +
    1.76 +            lgt->maptrack[nr_frames] = new_mt;
    1.77 +            lgt->maptrack_limit      = new_mt_limit;
    1.78 +
    1.79 +            gdprintk(XENLOG_INFO,
    1.80 +                    "Increased maptrack size to %u frames.\n", nr_frames + 1);
    1.81 +            handle = __get_maptrack_handle(lgt);
    1.82          }
    1.83  
    1.84 -        lgt->maptrack[nr_frames] = new_mt;
    1.85 -        lgt->maptrack_limit      = new_mt_limit;
    1.86 -
    1.87 -        gdprintk(XENLOG_INFO,
    1.88 -                 "Increased maptrack size to %u frames.\n", nr_frames + 1);
    1.89 -        handle = __get_maptrack_handle(lgt);
    1.90 +        spin_unlock(&lgt->lock);
    1.91      }
    1.92      return handle;
    1.93  }
    1.94 @@ -1515,9 +1508,7 @@ do_grant_table_op(
    1.95              guest_handle_cast(uop, gnttab_map_grant_ref_t);
    1.96          if ( unlikely(!guest_handle_okay(map, count)) )
    1.97              goto out;
    1.98 -        maptrack_lock(current->domain->grant_table);
    1.99          rc = gnttab_map_grant_ref(map, count);
   1.100 -        maptrack_unlock(current->domain->grant_table);
   1.101          break;
   1.102      }
   1.103      case GNTTABOP_unmap_grant_ref:
   1.104 @@ -1526,9 +1517,7 @@ do_grant_table_op(
   1.105              guest_handle_cast(uop, gnttab_unmap_grant_ref_t);
   1.106          if ( unlikely(!guest_handle_okay(unmap, count)) )
   1.107              goto out;
   1.108 -        maptrack_lock(current->domain->grant_table);
   1.109          rc = gnttab_unmap_grant_ref(unmap, count);
   1.110 -        maptrack_unlock(current->domain->grant_table);
   1.111          break;
   1.112      }
   1.113      case GNTTABOP_unmap_and_replace:
   1.114 @@ -1540,9 +1529,7 @@ do_grant_table_op(
   1.115          rc = -ENOSYS;
   1.116          if ( unlikely(!replace_grant_supported()) )
   1.117              goto out;
   1.118 -        maptrack_lock(current->domain->grant_table);
   1.119          rc = gnttab_unmap_and_replace(unmap, count);
   1.120 -        maptrack_unlock(current->domain->grant_table);
   1.121          break;
   1.122      }
   1.123      case GNTTABOP_setup_table:
   1.124 @@ -1613,7 +1600,6 @@ grant_table_create(
   1.125      /* Simple stuff. */
   1.126      memset(t, 0, sizeof(*t));
   1.127      spin_lock_init(&t->lock);
   1.128 -    spin_lock_init(&t->maptrack_lock);
   1.129      t->nr_grant_frames = INITIAL_NR_GRANT_FRAMES;
   1.130  
   1.131      /* Active grant table. */
   1.132 @@ -1694,7 +1680,6 @@ gnttab_release_mappings(
   1.133  
   1.134      for ( handle = 0; handle < gt->maptrack_limit; handle++ )
   1.135      {
   1.136 -        /* Domain is dying, so don't need maptrack lock */
   1.137          map = &maptrack_entry(gt, handle);
   1.138          if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) )
   1.139              continue;
     2.1 --- a/xen/include/xen/grant_table.h	Mon Jun 01 14:39:25 2009 +0100
     2.2 +++ b/xen/include/xen/grant_table.h	Mon Jun 01 14:55:32 2009 +0100
     2.3 @@ -91,8 +91,6 @@ struct grant_table {
     2.4      struct grant_mapping **maptrack;
     2.5      unsigned int          maptrack_head;
     2.6      unsigned int          maptrack_limit;
     2.7 -    /* Lock protecting maptrack-related fields. */
     2.8 -    spinlock_t            maptrack_lock;
     2.9      /* Lock protecting updates to active and shared grant tables. */
    2.10      spinlock_t            lock;
    2.11  };