xcp-1.6-updates/xen-4.1.hg

changeset 23229:8435c27b3499

gnttab: miscellaneous fixes

- _GTF_* constants name bit positions, so binary arithmetic on them is
wrong
- gnttab_clear_flag() cannot (on x86 and ia64 at least) simply use
clear_bit(), as that may access more than the two bytes that are
intended to be accessed

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 24742:9fc810bb8145
xen-unstable date: Thu Feb 09 16:39:16 2012 +0100
author Jan Beulich <jbeulich@suse.com>
date Thu Feb 23 10:34:14 2012 +0000 (2012-02-23)
parents 0b0d74c97010
children bc8f88be9e4b
files xen/common/grant_table.c xen/include/asm-ia64/grant_table.h xen/include/asm-x86/grant_table.h
line diff
     1.1 --- a/xen/common/grant_table.c	Thu Feb 23 10:32:48 2012 +0000
     1.2 +++ b/xen/common/grant_table.c	Thu Feb 23 10:34:14 2012 +0000
     1.3 @@ -389,7 +389,8 @@ static int _set_status_v2(domid_t  domid
     1.4               (id != domid) ||
     1.5               (!readonly && (flags & GTF_readonly)) )
     1.6          {
     1.7 -            gnttab_clear_flag(_GTF_reading | _GTF_writing, status);
     1.8 +            gnttab_clear_flag(_GTF_writing, status);
     1.9 +            gnttab_clear_flag(_GTF_reading, status);
    1.10              PIN_FAIL(done, GNTST_general_error,
    1.11                       "Unstable flags (%x) or dom (%d). (expected dom %d) "
    1.12                       "(r/w: %d)\n",
    1.13 @@ -1703,14 +1704,14 @@ static void
    1.14     under the domain's grant table lock. */
    1.15  /* Only safe on transitive grants.  Even then, note that we don't
    1.16     attempt to drop any pin on the referent grant. */
    1.17 -static void __fixup_status_for_pin(struct active_grant_entry *act,
    1.18 +static void __fixup_status_for_pin(const struct active_grant_entry *act,
    1.19                                     uint16_t *status)
    1.20  {
    1.21      if ( !(act->pin & GNTPIN_hstw_mask) )
    1.22 -        *status &= ~_GTF_writing;
    1.23 +        *status &= ~GTF_writing;
    1.24  
    1.25      if ( !(act->pin & GNTPIN_hstr_mask) )
    1.26 -        *status &= ~_GTF_reading;
    1.27 +        *status &= ~GTF_reading;
    1.28  }
    1.29  
    1.30  /* Grab a frame number from a grant entry and update the flags and pin
     2.1 --- a/xen/include/asm-ia64/grant_table.h	Thu Feb 23 10:32:48 2012 +0000
     2.2 +++ b/xen/include/asm-ia64/grant_table.h	Thu Feb 23 10:34:14 2012 +0000
     2.3 @@ -5,6 +5,8 @@
     2.4  #ifndef __ASM_GRANT_TABLE_H__
     2.5  #define __ASM_GRANT_TABLE_H__
     2.6  
     2.7 +#include <asm/intrinsics.h>
     2.8 +
     2.9  #define INITIAL_NR_GRANT_FRAMES 1
    2.10  
    2.11  // for grant map/unmap
    2.12 @@ -82,9 +84,19 @@ int guest_physmap_add_page(struct domain
    2.13  
    2.14  #define gnttab_mark_dirty(d, f) ((void)f)
    2.15  
    2.16 -static inline void gnttab_clear_flag(unsigned long nr, uint16_t *addr)
    2.17 +static inline void gnttab_clear_flag(unsigned int nr, volatile uint16_t *st)
    2.18  {
    2.19 -	clear_bit(nr, addr);
    2.20 +	/*
    2.21 +	 * Note that this cannot be clear_bit(), as the access must be
    2.22 +	 * confined to the specified 2 bytes.
    2.23 +	 */
    2.24 +	uint16_t mask = ~(1 << nr), old;
    2.25 +	CMPXCHG_BUGCHECK_DECL
    2.26 +
    2.27 +	do {
    2.28 +		CMPXCHG_BUGCHECK(st);
    2.29 +		old = *st;
    2.30 +	} while (cmpxchg_rel(st, old, old & mask) != old);
    2.31  }
    2.32  
    2.33  #define gnttab_host_mapping_get_page_type(op, ld, rd)   \
     3.1 --- a/xen/include/asm-x86/grant_table.h	Thu Feb 23 10:32:48 2012 +0000
     3.2 +++ b/xen/include/asm-x86/grant_table.h	Thu Feb 23 10:34:14 2012 +0000
     3.3 @@ -48,9 +48,13 @@ int replace_grant_host_mapping(
     3.4  
     3.5  #define gnttab_mark_dirty(d, f) paging_mark_dirty((d), (f))
     3.6  
     3.7 -static inline void gnttab_clear_flag(unsigned long nr, uint16_t *addr)
     3.8 +static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st)
     3.9  {
    3.10 -    clear_bit(nr, (unsigned long *)addr);
    3.11 +    /*
    3.12 +     * Note that this cannot be clear_bit(), as the access must be
    3.13 +     * confined to the specified 2 bytes.
    3.14 +     */
    3.15 +    asm volatile ("lock btrw %1,%0" : "=m" (*st) : "Ir" (nr), "m" (*st));
    3.16  }
    3.17  
    3.18  /* Foreign mappings of HHVM-guest pages do not modify the type count. */