ia64/xen-unstable

changeset 7745:8f83f7ccf185

Fix shadow bitmap sizing for logdirty mode.

Signed-off-by: Steven Hand <steven@xensource.com>
author smh22@firebug.cl.cam.ac.uk
date Wed Nov 09 19:18:47 2005 +0100 (2005-11-09)
parents 5823dbfbb4cd
children 8a5dca8c1e8f
files xen/arch/x86/shadow32.c xen/arch/x86/shadow_public.c
line diff
     1.1 --- a/xen/arch/x86/shadow32.c	Wed Nov 09 17:23:46 2005 +0100
     1.2 +++ b/xen/arch/x86/shadow32.c	Wed Nov 09 19:18:47 2005 +0100
     1.3 @@ -997,7 +997,8 @@ int __shadow_mode_enable(struct domain *
     1.4      if ( new_modes & SHM_log_dirty )
     1.5      {
     1.6          ASSERT( !d->arch.shadow_dirty_bitmap );
     1.7 -        d->arch.shadow_dirty_bitmap_size = (d->max_pages + 63) & ~63;
     1.8 +        d->arch.shadow_dirty_bitmap_size = 
     1.9 +            (d->shared_info->arch.max_pfn +  63) & ~63;
    1.10          d->arch.shadow_dirty_bitmap = 
    1.11              xmalloc_array(unsigned long, d->arch.shadow_dirty_bitmap_size /
    1.12                                           (8 * sizeof(unsigned long)));
    1.13 @@ -1287,34 +1288,28 @@ static int shadow_mode_table_op(
    1.14          d->arch.shadow_dirty_net_count   = 0;
    1.15          d->arch.shadow_dirty_block_count = 0;
    1.16   
    1.17 -        if ( (d->max_pages > sc->pages) || 
    1.18 -             (sc->dirty_bitmap == NULL) || 
    1.19 +        if ( (sc->dirty_bitmap == NULL) || 
    1.20               (d->arch.shadow_dirty_bitmap == NULL) )
    1.21          {
    1.22              rc = -EINVAL;
    1.23              break;
    1.24          }
    1.25 - 
    1.26 -        sc->pages = d->max_pages;
    1.27 +
    1.28 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
    1.29 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
    1.30  
    1.31  #define chunk (8*1024) /* Transfer and clear in 1kB chunks for L1 cache. */
    1.32 -        for ( i = 0; i < d->max_pages; i += chunk )
    1.33 +        for ( i = 0; i < sc->pages; i += chunk )
    1.34          {
    1.35 -            int bytes = ((((d->max_pages - i) > chunk) ?
    1.36 -                          chunk : (d->max_pages - i)) + 7) / 8;
    1.37 +            int bytes = ((((sc->pages - i) > chunk) ?
    1.38 +                          chunk : (sc->pages - i)) + 7) / 8;
    1.39       
    1.40              if (copy_to_user(
    1.41                      sc->dirty_bitmap + (i/(8*sizeof(unsigned long))),
    1.42                      d->arch.shadow_dirty_bitmap +(i/(8*sizeof(unsigned long))),
    1.43                      bytes))
    1.44              {
    1.45 -                // copy_to_user can fail when copying to guest app memory.
    1.46 -                // app should zero buffer after mallocing, and pin it
    1.47                  rc = -EINVAL;
    1.48 -                memset(
    1.49 -                    d->arch.shadow_dirty_bitmap + 
    1.50 -                    (i/(8*sizeof(unsigned long))),
    1.51 -                    0, (d->max_pages/8) - (i/(8*sizeof(unsigned long))));
    1.52                  break;
    1.53              }
    1.54  
    1.55 @@ -1331,17 +1326,19 @@ static int shadow_mode_table_op(
    1.56          sc->stats.dirty_net_count   = d->arch.shadow_dirty_net_count;
    1.57          sc->stats.dirty_block_count = d->arch.shadow_dirty_block_count;
    1.58   
    1.59 -        if ( (d->max_pages > sc->pages) || 
    1.60 -             (sc->dirty_bitmap == NULL) || 
    1.61 +
    1.62 +        if ( (sc->dirty_bitmap == NULL) || 
    1.63               (d->arch.shadow_dirty_bitmap == NULL) )
    1.64          {
    1.65              rc = -EINVAL;
    1.66              break;
    1.67          }
    1.68   
    1.69 -        sc->pages = d->max_pages;
    1.70 -        if (copy_to_user(
    1.71 -            sc->dirty_bitmap, d->arch.shadow_dirty_bitmap, (d->max_pages+7)/8))
    1.72 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
    1.73 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
    1.74 +
    1.75 +        if (copy_to_user(sc->dirty_bitmap, 
    1.76 +                         d->arch.shadow_dirty_bitmap, (sc->pages+7)/8))
    1.77          {
    1.78              rc = -EINVAL;
    1.79              break;
     2.1 --- a/xen/arch/x86/shadow_public.c	Wed Nov 09 17:23:46 2005 +0100
     2.2 +++ b/xen/arch/x86/shadow_public.c	Wed Nov 09 19:18:47 2005 +0100
     2.3 @@ -1009,7 +1009,8 @@ int __shadow_mode_enable(struct domain *
     2.4      if ( new_modes & SHM_log_dirty )
     2.5      {
     2.6          ASSERT( !d->arch.shadow_dirty_bitmap );
     2.7 -        d->arch.shadow_dirty_bitmap_size = (d->max_pages + 63) & ~63;
     2.8 +        d->arch.shadow_dirty_bitmap_size = 
     2.9 +            (d->shared_info->arch.max_pfn +  63) & ~63;
    2.10          d->arch.shadow_dirty_bitmap = 
    2.11              xmalloc_array(unsigned long, d->arch.shadow_dirty_bitmap_size /
    2.12                            (8 * sizeof(unsigned long)));
    2.13 @@ -1163,34 +1164,29 @@ static int shadow_mode_table_op(
    2.14          d->arch.shadow_dirty_net_count   = 0;
    2.15          d->arch.shadow_dirty_block_count = 0;
    2.16   
    2.17 -        if ( (d->max_pages > sc->pages) || 
    2.18 -             (sc->dirty_bitmap == NULL) || 
    2.19 +
    2.20 +        if ( (sc->dirty_bitmap == NULL) || 
    2.21               (d->arch.shadow_dirty_bitmap == NULL) )
    2.22          {
    2.23              rc = -EINVAL;
    2.24              break;
    2.25          }
    2.26 - 
    2.27 -        sc->pages = d->max_pages;
    2.28 +
    2.29 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
    2.30 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
    2.31  
    2.32  #define chunk (8*1024) /* Transfer and clear in 1kB chunks for L1 cache. */
    2.33 -        for ( i = 0; i < d->max_pages; i += chunk )
    2.34 +        for ( i = 0; i < sc->pages; i += chunk )
    2.35          {
    2.36 -            int bytes = ((((d->max_pages - i) > chunk) ?
    2.37 -                          chunk : (d->max_pages - i)) + 7) / 8;
    2.38 +            int bytes = ((((sc->pages - i) > chunk) ?
    2.39 +                          chunk : (sc->pages - i)) + 7) / 8;
    2.40  
    2.41              if (copy_to_user(
    2.42                  sc->dirty_bitmap + (i/(8*sizeof(unsigned long))),
    2.43                  d->arch.shadow_dirty_bitmap +(i/(8*sizeof(unsigned long))),
    2.44                  bytes))
    2.45              {
    2.46 -                // copy_to_user can fail when copying to guest app memory.
    2.47 -                // app should zero buffer after mallocing, and pin it
    2.48                  rc = -EINVAL;
    2.49 -                memset(
    2.50 -                    d->arch.shadow_dirty_bitmap + 
    2.51 -                    (i/(8*sizeof(unsigned long))),
    2.52 -                    0, (d->max_pages/8) - (i/(8*sizeof(unsigned long))));
    2.53                  break;
    2.54              }
    2.55              memset(
    2.56 @@ -1206,17 +1202,18 @@ static int shadow_mode_table_op(
    2.57          sc->stats.dirty_net_count   = d->arch.shadow_dirty_net_count;
    2.58          sc->stats.dirty_block_count = d->arch.shadow_dirty_block_count;
    2.59   
    2.60 -        if ( (d->max_pages > sc->pages) || 
    2.61 -             (sc->dirty_bitmap == NULL) || 
    2.62 +        if ( (sc->dirty_bitmap == NULL) || 
    2.63               (d->arch.shadow_dirty_bitmap == NULL) )
    2.64          {
    2.65              rc = -EINVAL;
    2.66              break;
    2.67          }
    2.68   
    2.69 -        sc->pages = d->max_pages;
    2.70 -        if (copy_to_user(
    2.71 -            sc->dirty_bitmap, d->arch.shadow_dirty_bitmap, (d->max_pages+7)/8))
    2.72 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
    2.73 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
    2.74 +
    2.75 +        if (copy_to_user(sc->dirty_bitmap, 
    2.76 +                         d->arch.shadow_dirty_bitmap, (sc->pages+7)/8))
    2.77          {
    2.78              rc = -EINVAL;
    2.79              break;