ia64/xen-unstable

changeset 17114:cb3e47897b85

x86: Foreign mappings of HVM-guest pages should not affect type count,
even when the mapping is made via a grant reference.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Feb 25 11:24:06 2008 +0000 (2008-02-25)
parents 746fc8fe9d75
children d34e99141506
files xen/common/grant_table.c xen/include/asm-ia64/grant_table.h xen/include/asm-powerpc/grant_table.h xen/include/asm-x86/grant_table.h
line diff
     1.1 --- a/xen/common/grant_table.c	Mon Feb 25 10:56:23 2008 +0000
     1.2 +++ b/xen/common/grant_table.c	Mon Feb 25 11:24:06 2008 +0000
     1.3 @@ -350,10 +350,10 @@ static void
     1.4      else
     1.5      {
     1.6          if ( unlikely(!mfn_valid(frame)) ||
     1.7 -             unlikely(!((op->flags & GNTMAP_readonly) ?
     1.8 -                        get_page(mfn_to_page(frame), rd) :
     1.9 +             unlikely(!(gnttab_host_mapping_get_page_type(op, ld, rd) ?
    1.10                          get_page_and_type(mfn_to_page(frame), rd,
    1.11 -                                          PGT_writable_page))) )
    1.12 +                                          PGT_writable_page) :
    1.13 +                        get_page(mfn_to_page(frame), rd))) )
    1.14          {
    1.15              if ( !rd->is_dying )
    1.16                  gdprintk(XENLOG_WARNING, "Could not pin grant frame %lx\n",
    1.17 @@ -367,7 +367,7 @@ static void
    1.18              rc = create_grant_host_mapping(op->host_addr, frame, op->flags, 0);
    1.19              if ( rc != GNTST_okay )
    1.20              {
    1.21 -                if ( !(op->flags & GNTMAP_readonly) )
    1.22 +                if ( gnttab_host_mapping_get_page_type(op, ld, rd) )
    1.23                      put_page_type(mfn_to_page(frame));
    1.24                  put_page(mfn_to_page(frame));
    1.25                  goto undo_out;
    1.26 @@ -604,7 +604,7 @@ static void
    1.27  
    1.28          if ( !is_iomem_page(op->frame) ) 
    1.29          {
    1.30 -            if ( !(op->flags & GNTMAP_readonly) )
    1.31 +            if ( gnttab_host_mapping_get_page_type(op, ld, rd) )
    1.32                  put_page_type(mfn_to_page(op->frame));
    1.33              put_page(mfn_to_page(op->frame));
    1.34          }
    1.35 @@ -1662,8 +1662,9 @@ gnttab_release_mappings(
    1.36              {
    1.37                  BUG_ON(!(act->pin & GNTPIN_hstr_mask));
    1.38                  act->pin -= GNTPIN_hstr_inc;
    1.39 -                if ( !is_iomem_page(act->frame) )
    1.40 -                    gnttab_release_put_page(mfn_to_page(act->frame));
    1.41 +                if ( gnttab_release_host_mappings &&
    1.42 +                     !is_iomem_page(act->frame) )
    1.43 +                    put_page(mfn_to_page(act->frame));
    1.44              }
    1.45          }
    1.46          else
    1.47 @@ -1680,8 +1681,13 @@ gnttab_release_mappings(
    1.48              {
    1.49                  BUG_ON(!(act->pin & GNTPIN_hstw_mask));
    1.50                  act->pin -= GNTPIN_hstw_inc;
    1.51 -                if ( !is_iomem_page(act->frame) )
    1.52 -                    gnttab_release_put_page_and_type(mfn_to_page(act->frame));
    1.53 +                if ( gnttab_release_host_mappings &&
    1.54 +                     !is_iomem_page(act->frame) )
    1.55 +                {
    1.56 +                    if ( gnttab_host_mapping_get_page_type(map, d, rd) )
    1.57 +                        put_page_type(mfn_to_page(act->frame));
    1.58 +                    put_page(mfn_to_page(act->frame));
    1.59 +                }
    1.60              }
    1.61  
    1.62              if ( (act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) == 0 )
     2.1 --- a/xen/include/asm-ia64/grant_table.h	Mon Feb 25 10:56:23 2008 +0000
     2.2 +++ b/xen/include/asm-ia64/grant_table.h	Mon Feb 25 11:24:06 2008 +0000
     2.3 @@ -65,8 +65,10 @@ static inline void gnttab_clear_flag(uns
     2.4  	clear_bit(nr, addr);
     2.5  }
     2.6  
     2.7 -#define gnttab_release_put_page(page)           put_page((page))
     2.8 -#define gnttab_release_put_page_and_type(page)  put_page_and_type((page))
     2.9 +#define gnttab_host_mapping_get_page_type(op, ld, rd)   \
    2.10 +    (!((op)->flags & GNTMAP_readonly))
    2.11 +
    2.12 +#define gnttab_release_host_mappings 1
    2.13  
    2.14  static inline int replace_grant_supported(void)
    2.15  {
     3.1 --- a/xen/include/asm-powerpc/grant_table.h	Mon Feb 25 10:56:23 2008 +0000
     3.2 +++ b/xen/include/asm-powerpc/grant_table.h	Mon Feb 25 11:24:06 2008 +0000
     3.3 @@ -76,17 +76,14 @@ static inline uint cpu_foreign_map_order
     3.4      return 34 - PAGE_SHIFT;
     3.5  }
     3.6  
     3.7 -#if 0
     3.8 +#define gnttab_host_mapping_get_page_type(op, ld, rd)   \
     3.9 +    (!((op)->flags & GNTMAP_readonly))
    3.10 +
    3.11  /*
    3.12   * without put_page()/put_page_and_type() page might be leaked.
    3.13   * with put_page()/put_page_and_type() freed page might be accessed.
    3.14   */
    3.15 -#define gnttab_release_put_page(page)           put_page((page))
    3.16 -#define gnttab_release_put_page_and_type(page)  put_page_and_type((page))
    3.17 -#else
    3.18 -#define gnttab_release_put_page(page)           do { } while (0)
    3.19 -#define gnttab_release_put_page_and_type(page)  do { } while (0)
    3.20 -#endif
    3.21 +#define gnttab_release_host_mappings 0
    3.22  
    3.23  static inline int replace_grant_supported(void)
    3.24  {
     4.1 --- a/xen/include/asm-x86/grant_table.h	Mon Feb 25 10:56:23 2008 +0000
     4.2 +++ b/xen/include/asm-x86/grant_table.h	Mon Feb 25 11:24:06 2008 +0000
     4.3 @@ -38,15 +38,13 @@ static inline void gnttab_clear_flag(uns
     4.4      clear_bit(nr, addr);
     4.5  }
     4.6  
     4.7 -#define gnttab_release_put_page(page)                           \
     4.8 -    do {                                                        \
     4.9 -        /* Done implicitly when page tables are destroyed. */   \
    4.10 -    } while (0)
    4.11 +/* Foreign mappings of HHVM-guest pages do not modify the type count. */
    4.12 +#define gnttab_host_mapping_get_page_type(op, ld, rd)   \
    4.13 +    (!((op)->flags & GNTMAP_readonly) &&                \
    4.14 +     (((ld) == (rd)) || !paging_mode_external(rd)))
    4.15  
    4.16 -#define gnttab_release_put_page_and_type(page)                  \
    4.17 -    do {                                                        \
    4.18 -        /* Done implicitly when page tables are destroyed. */   \
    4.19 -    } while (0)
    4.20 +/* Done implicitly when page tables are destroyed. */
    4.21 +#define gnttab_release_host_mappings 0
    4.22  
    4.23  static inline int replace_grant_supported(void)
    4.24  {