ia64/xen-unstable

changeset 19771:0ea75c3b7743

tmem: fix 32-on-64 support

This implicitly required coverting the tmem_op structure from
anonymous to standard struct/union sub-fields, and extending the
get-fields.sh helper script to deal with typedef-ed guest handles used
as types of translated compound type fields.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 17 07:14:02 2009 +0100 (2009-06-17)
parents 64a932c92a7c
children aaab04808ee7
files tools/libxc/xc_tmem.c xen/common/tmem.c xen/include/public/tmem.h xen/include/xen/tmem_xen.h xen/include/xlat.lst xen/tools/get-fields.sh
line diff
     1.1 --- a/tools/libxc/xc_tmem.c	Tue Jun 16 14:19:34 2009 +0100
     1.2 +++ b/tools/libxc/xc_tmem.c	Wed Jun 17 07:14:02 2009 +0100
     1.3 @@ -43,11 +43,11 @@ int xc_tmem_control(int xc,
     1.4  
     1.5      op.cmd = TMEM_CONTROL;
     1.6      op.pool_id = pool_id;
     1.7 -    op.subop = subop;
     1.8 -    op.cli_id = cli_id;
     1.9 -    op.arg1 = arg1;
    1.10 -    op.arg2 = arg2;
    1.11 -    op.buf.p = buf;
    1.12 +    op.u.ctrl.subop = subop;
    1.13 +    op.u.ctrl.cli_id = cli_id;
    1.14 +    op.u.ctrl.arg1 = arg1;
    1.15 +    op.u.ctrl.arg2 = arg2;
    1.16 +    op.u.ctrl.buf.p = buf;
    1.17  
    1.18      if (subop == TMEMC_LIST) {
    1.19          if ((arg1 != 0) && (lock_pages(buf, arg1) != 0))
     2.1 --- a/xen/common/tmem.c	Tue Jun 16 14:19:34 2009 +0100
     2.2 +++ b/xen/common/tmem.c	Wed Jun 17 07:14:02 2009 +0100
     2.3 @@ -1842,7 +1842,8 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop
     2.4      {
     2.5          tmem_write_lock(&tmem_rwlock);
     2.6          tmem_write_lock_set = 1;
     2.7 -        rc = do_tmem_control(op.subop, op.cli_id, op.arg1, op.arg2, op.buf);
     2.8 +        rc = do_tmem_control(op.u.ctrl.subop, op.u.ctrl.cli_id,
     2.9 +                             op.u.ctrl.arg1, op.u.ctrl.arg2, op.u.ctrl.buf);
    2.10          goto out;
    2.11      }
    2.12  
    2.13 @@ -1887,27 +1888,31 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop
    2.14      switch ( op.cmd )
    2.15      {
    2.16      case TMEM_NEW_POOL:
    2.17 -        rc = do_tmem_new_pool(op.flags,op.uuid[0],op.uuid[1]);
    2.18 +        rc = do_tmem_new_pool(op.u.new.flags,
    2.19 +                              op.u.new.uuid[0], op.u.new.uuid[1]);
    2.20          break;
    2.21      case TMEM_NEW_PAGE:
    2.22 -        rc = do_tmem_put(pool, op.object, op.index, op.cmfn, 0, 0, 0);
    2.23 +        rc = do_tmem_put(pool, op.u.gen.object, op.u.gen.index, op.u.gen.cmfn,
    2.24 +                         0, 0, 0);
    2.25          break;
    2.26      case TMEM_PUT_PAGE:
    2.27 -        rc = do_tmem_put(pool, op.object, op.index, op.cmfn, 0, 0, PAGE_SIZE);
    2.28 +        rc = do_tmem_put(pool, op.u.gen.object, op.u.gen.index, op.u.gen.cmfn,
    2.29 +                         0, 0, PAGE_SIZE);
    2.30          if (rc == 1) succ_put = 1;
    2.31          else non_succ_put = 1;
    2.32          break;
    2.33      case TMEM_GET_PAGE:
    2.34 -        rc = do_tmem_get(pool, op.object, op.index, op.cmfn, 0, 0, PAGE_SIZE);
    2.35 +        rc = do_tmem_get(pool, op.u.gen.object, op.u.gen.index, op.u.gen.cmfn,
    2.36 +                         0, 0, PAGE_SIZE);
    2.37          if (rc == 1) succ_get = 1;
    2.38          else non_succ_get = 1;
    2.39          break;
    2.40      case TMEM_FLUSH_PAGE:
    2.41          flush = 1;
    2.42 -        rc = do_tmem_flush_page(pool, op.object, op.index);
    2.43 +        rc = do_tmem_flush_page(pool, op.u.gen.object, op.u.gen.index);
    2.44          break;
    2.45      case TMEM_FLUSH_OBJECT:
    2.46 -        rc = do_tmem_flush_object(pool, op.object);
    2.47 +        rc = do_tmem_flush_object(pool, op.u.gen.object);
    2.48          flush_obj = 1;
    2.49          break;
    2.50      case TMEM_DESTROY_POOL:
    2.51 @@ -1915,12 +1920,14 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop
    2.52          rc = do_tmem_destroy_pool(op.pool_id);
    2.53          break;
    2.54      case TMEM_READ:
    2.55 -        rc = do_tmem_get(pool, op.object, op.index, op.cmfn,
    2.56 -                         op.tmem_offset, op.pfn_offset, op.len);
    2.57 +        rc = do_tmem_get(pool, op.u.gen.object, op.u.gen.index, op.u.gen.cmfn,
    2.58 +                         op.u.gen.tmem_offset, op.u.gen.pfn_offset,
    2.59 +                         op.u.gen.len);
    2.60          break;
    2.61      case TMEM_WRITE:
    2.62 -        rc = do_tmem_put(pool, op.object, op.index, op.cmfn,
    2.63 -                         op.tmem_offset, op.pfn_offset, op.len);
    2.64 +        rc = do_tmem_put(pool, op.u.gen.object, op.u.gen.index, op.u.gen.cmfn,
    2.65 +                         op.u.gen.tmem_offset, op.u.gen.pfn_offset,
    2.66 +                         op.u.gen.len);
    2.67          break;
    2.68      case TMEM_XCHG:
    2.69          /* need to hold global lock to ensure xchg is atomic */
     3.1 --- a/xen/include/public/tmem.h	Tue Jun 16 14:19:34 2009 +0100
     3.2 +++ b/xen/include/public/tmem.h	Wed Jun 17 07:14:02 2009 +0100
     3.3 @@ -75,14 +75,14 @@ struct tmem_op {
     3.4          struct {  /* for cmd == TMEM_NEW_POOL */
     3.5              uint64_t uuid[2];
     3.6              uint32_t flags;
     3.7 -        };
     3.8 +        } new;
     3.9          struct {  /* for cmd == TMEM_CONTROL */
    3.10              uint32_t subop;
    3.11              uint32_t cli_id;
    3.12              uint32_t arg1;
    3.13              uint32_t arg2;
    3.14              tmem_cli_va_t buf;
    3.15 -        };
    3.16 +        } ctrl;
    3.17          struct {
    3.18              uint64_t object;
    3.19              uint32_t index;
    3.20 @@ -90,8 +90,8 @@ struct tmem_op {
    3.21              uint32_t pfn_offset;
    3.22              uint32_t len;
    3.23              tmem_cli_mfn_t cmfn; /* client machine page frame */
    3.24 -        };
    3.25 -    };
    3.26 +        } gen;
    3.27 +    } u;
    3.28  };
    3.29  typedef struct tmem_op tmem_op_t;
    3.30  DEFINE_XEN_GUEST_HANDLE(tmem_op_t);
     4.1 --- a/xen/include/xen/tmem_xen.h	Tue Jun 16 14:19:34 2009 +0100
     4.2 +++ b/xen/include/xen/tmem_xen.h	Wed Jun 17 07:14:02 2009 +0100
     4.3 @@ -16,6 +16,9 @@
     4.4  #include <xen/guest_access.h> /* copy_from_guest */
     4.5  #include <xen/hash.h> /* hash_long */
     4.6  #include <public/tmem.h>
     4.7 +#ifdef CONFIG_COMPAT
     4.8 +#include <compat/tmem.h>
     4.9 +#endif
    4.10  
    4.11  struct tmem_host_dependent_client {
    4.12      struct domain *domain;
    4.13 @@ -286,6 +289,29 @@ typedef XEN_GUEST_HANDLE(tmem_op_t) tmem
    4.14  
    4.15  static inline int tmh_get_tmemop_from_client(tmem_op_t *op, tmem_cli_op_t uops)
    4.16  {
    4.17 +#ifdef CONFIG_COMPAT
    4.18 +    if ( is_pv_32on64_vcpu(current) )
    4.19 +    {
    4.20 +        int rc;
    4.21 +        enum XLAT_tmem_op_u u;
    4.22 +        tmem_op_compat_t cop;
    4.23 +
    4.24 +        rc = copy_from_guest(&cop, guest_handle_cast(uops, void), 1);
    4.25 +        if ( rc )
    4.26 +            return rc;
    4.27 +        switch ( cop.cmd )
    4.28 +        {
    4.29 +        case TMEM_NEW_POOL: u = XLAT_tmem_op_u_new;  break;
    4.30 +        case TMEM_CONTROL:  u = XLAT_tmem_op_u_ctrl; break;
    4.31 +        default:            u = XLAT_tmem_op_u_gen;  break;
    4.32 +        }
    4.33 +#define XLAT_tmem_op_HNDL_u_ctrl_buf(_d_, _s_) \
    4.34 +        guest_from_compat_handle((_d_)->u.ctrl.buf, (_s_)->u.ctrl.buf)
    4.35 +        XLAT_tmem_op(op, &cop);
    4.36 +#undef XLAT_tmem_op_HNDL_u_ctrl_buf
    4.37 +        return 0;
    4.38 +    }
    4.39 +#endif
    4.40      return copy_from_guest(op, uops, 1);
    4.41  }
    4.42  
     5.1 --- a/xen/include/xlat.lst	Tue Jun 16 14:19:34 2009 +0100
     5.2 +++ b/xen/include/xlat.lst	Wed Jun 17 07:14:02 2009 +0100
     5.3 @@ -57,6 +57,7 @@
     5.4  !	sched_poll			sched.h
     5.5  ?	sched_remote_shutdown		sched.h
     5.6  ?	sched_shutdown			sched.h
     5.7 +!	tmem_op				tmem.h
     5.8  ?	t_buf				trace.h
     5.9  ?	vcpu_get_physid			vcpu.h
    5.10  ?	vcpu_register_vcpu_info		vcpu.h
    5.11 @@ -74,6 +75,3 @@
    5.12  ?	processor_px			platform.h
    5.13  !	psd_package			platform.h
    5.14  !	processor_performance		platform.h
    5.15 -# ?	tmem_op_t			tmem.h
    5.16 -# ?	tmem_cli_mfn_t			tmem.h
    5.17 -# ?	tmem_cli_va_t			tmem.h
     6.1 --- a/xen/tools/get-fields.sh	Tue Jun 16 14:19:34 2009 +0100
     6.2 +++ b/xen/tools/get-fields.sh	Wed Jun 17 07:14:02 2009 +0100
     6.3 @@ -34,6 +34,34 @@ get_fields ()
     6.4  	done
     6.5  }
     6.6  
     6.7 +get_typedefs ()
     6.8 +{
     6.9 +	local level=1 state=
    6.10 +	for token in $1
    6.11 +	do
    6.12 +		case "$token" in
    6.13 +		typedef)
    6.14 +			test $level != 1 || state=1
    6.15 +			;;
    6.16 +		COMPAT_HANDLE\(*\))
    6.17 +			test $level != 1 -o "$state" != 1 || state=2
    6.18 +			;;
    6.19 +		[\{\[])
    6.20 +			level=$(expr $level + 1)
    6.21 +			;;
    6.22 +		[\}\]])
    6.23 +			level=$(expr $level - 1)
    6.24 +			;;
    6.25 +		";")
    6.26 +			test $level != 1 || state=
    6.27 +			;;
    6.28 +		[a-zA-Z_]*)
    6.29 +			test $level != 1 -o "$state" != 2 || echo "$token"
    6.30 +			;;
    6.31 +		esac
    6.32 +	done
    6.33 +}
    6.34 +
    6.35  build_enums ()
    6.36  {
    6.37  	local level=1 kind= fields= members= named= id= token
    6.38 @@ -166,7 +194,21 @@ for line in sys.stdin.readlines():
    6.39  				fi
    6.40  				;;
    6.41  			[a-zA-Z]*)
    6.42 -				id=$token
    6.43 +				if [ -z "$id" -a -z "$type" -a -z "$array_type" ]
    6.44 +				then
    6.45 +					for id in $typedefs
    6.46 +					do
    6.47 +						test $id != "$token" || type=$id
    6.48 +					done
    6.49 +					if [ -z "$type" ]
    6.50 +					then
    6.51 +						id=$token
    6.52 +					else
    6.53 +						id=
    6.54 +					fi
    6.55 +				else
    6.56 +					id=$token
    6.57 +				fi
    6.58  				;;
    6.59  			[\,\;])
    6.60  				if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
    6.61 @@ -281,6 +323,18 @@ build_body ()
    6.62  			if [ -n "$array" ]
    6.63  			then
    6.64  				array="$array $token"
    6.65 +			elif [ -z "$id" -a -z "$type" -a -z "$array_type" ]
    6.66 +			then
    6.67 +				for id in $typedefs
    6.68 +				do
    6.69 +					test $id != "$token" || type=$id
    6.70 +				done
    6.71 +				if [ -z "$type" ]
    6.72 +				then
    6.73 +					id=$token
    6.74 +				else
    6.75 +					id=
    6.76 +				fi
    6.77  			else
    6.78  				id=$token
    6.79  			fi
    6.80 @@ -419,7 +473,8 @@ build_check ()
    6.81  	echo ""
    6.82  }
    6.83  
    6.84 -fields="$(get_fields $(echo $2 | $SED 's,^compat_xen,compat_,') "$($SED -e 's,^[[:space:]]#.*,,' -e 's!\([]\[,;:{}]\)! \1 !g' $3)")"
    6.85 +list="$($SED -e 's,^[[:space:]]#.*,,' -e 's!\([]\[,;:{}]\)! \1 !g' $3)"
    6.86 +fields="$(get_fields $(echo $2 | $SED 's,^compat_xen,compat_,') "$list")"
    6.87  if [ -z "$fields" ]
    6.88  then
    6.89  	echo "Fields of '$2' not found in '$3'" >&2
    6.90 @@ -429,6 +484,7 @@ name=${2#compat_}
    6.91  name=${name#xen}
    6.92  case "$1" in
    6.93  "!")
    6.94 +	typedefs="$(get_typedefs "$list")"
    6.95  	build_enums $name "$fields"
    6.96  	build_body $name "$fields"
    6.97  	;;