From: "Jan Beulich" Subject: [PATCH] tmem: fix 32-on-64 support Date: Tue, 16 Jun 2009 15:59:06 +0100 Message-ID: <4A37CF5A0200007800005F75@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: dan.magenheimer@oracle.com List-Id: xen-devel@lists.xenproject.org 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 --- 2009-06-10.orig/tools/libxc/xc_tmem.c 2009-05-27 13:54:05.0000000= 00 +0200 +++ 2009-06-10/tools/libxc/xc_tmem.c 2009-06-16 16:39:08.000000000 = +0200 @@ -43,11 +43,11 @@ int xc_tmem_control(int xc, =20 op.cmd =3D TMEM_CONTROL; op.pool_id =3D pool_id; - op.subop =3D subop; - op.cli_id =3D cli_id; - op.arg1 =3D arg1; - op.arg2 =3D arg2; - op.buf.p =3D buf; + op.u.ctrl.subop =3D subop; + op.u.ctrl.cli_id =3D cli_id; + op.u.ctrl.arg1 =3D arg1; + op.u.ctrl.arg2 =3D arg2; + op.u.ctrl.buf.p =3D buf; =20 if (subop =3D=3D TMEMC_LIST) { if ((arg1 !=3D 0) && (lock_pages(buf, arg1) !=3D 0)) --- 2009-06-10.orig/xen/common/tmem.c 2009-06-16 16:38:02.000000000 = +0200 +++ 2009-06-10/xen/common/tmem.c 2009-06-16 11:34:21.000000000 = +0200 @@ -1842,7 +1842,8 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop { tmem_write_lock(&tmem_rwlock); tmem_write_lock_set =3D 1; - rc =3D do_tmem_control(op.subop, op.cli_id, op.arg1, op.arg2, = op.buf); + rc =3D do_tmem_control(op.u.ctrl.subop, op.u.ctrl.cli_id, + op.u.ctrl.arg1, op.u.ctrl.arg2, op.u.ctrl.buf= ); goto out; } =20 @@ -1887,27 +1888,31 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop switch ( op.cmd ) { case TMEM_NEW_POOL: - rc =3D do_tmem_new_pool(op.flags,op.uuid[0],op.uuid[1]); + rc =3D do_tmem_new_pool(op.u.new.flags, + op.u.new.uuid[0], op.u.new.uuid[1]); break; case TMEM_NEW_PAGE: - rc =3D do_tmem_put(pool, op.object, op.index, op.cmfn, 0, 0, 0); + rc =3D do_tmem_put(pool, op.u.gen.object, op.u.gen.index, = op.u.gen.cmfn, + 0, 0, 0); break; case TMEM_PUT_PAGE: - rc =3D do_tmem_put(pool, op.object, op.index, op.cmfn, 0, 0, = PAGE_SIZE); + rc =3D do_tmem_put(pool, op.u.gen.object, op.u.gen.index, = op.u.gen.cmfn, + 0, 0, PAGE_SIZE); if (rc =3D=3D 1) succ_put =3D 1; else non_succ_put =3D 1; break; case TMEM_GET_PAGE: - rc =3D do_tmem_get(pool, op.object, op.index, op.cmfn, 0, 0, = PAGE_SIZE); + rc =3D do_tmem_get(pool, op.u.gen.object, op.u.gen.index, = op.u.gen.cmfn, + 0, 0, PAGE_SIZE); if (rc =3D=3D 1) succ_get =3D 1; else non_succ_get =3D 1; break; case TMEM_FLUSH_PAGE: flush =3D 1; - rc =3D do_tmem_flush_page(pool, op.object, op.index); + rc =3D do_tmem_flush_page(pool, op.u.gen.object, op.u.gen.index); break; case TMEM_FLUSH_OBJECT: - rc =3D do_tmem_flush_object(pool, op.object); + rc =3D do_tmem_flush_object(pool, op.u.gen.object); flush_obj =3D 1; break; case TMEM_DESTROY_POOL: @@ -1915,12 +1920,14 @@ EXPORT long do_tmem_op(tmem_cli_op_t uop rc =3D do_tmem_destroy_pool(op.pool_id); break; case TMEM_READ: - rc =3D do_tmem_get(pool, op.object, op.index, op.cmfn, - op.tmem_offset, op.pfn_offset, op.len); + rc =3D do_tmem_get(pool, op.u.gen.object, op.u.gen.index, = op.u.gen.cmfn, + op.u.gen.tmem_offset, op.u.gen.pfn_offset, + op.u.gen.len); break; case TMEM_WRITE: - rc =3D do_tmem_put(pool, op.object, op.index, op.cmfn, - op.tmem_offset, op.pfn_offset, op.len); + rc =3D do_tmem_put(pool, op.u.gen.object, op.u.gen.index, = op.u.gen.cmfn, + op.u.gen.tmem_offset, op.u.gen.pfn_offset, + op.u.gen.len); break; case TMEM_XCHG: /* need to hold global lock to ensure xchg is atomic */ --- 2009-06-10.orig/xen/include/xen/tmem_xen.h 2009-06-15 15:11:54.0000000= 00 +0200 +++ 2009-06-10/xen/include/xen/tmem_xen.h 2009-06-16 15:09:40.0000000= 00 +0200 @@ -16,6 +16,9 @@ #include /* copy_from_guest */ #include /* hash_long */ #include +#ifdef CONFIG_COMPAT +#include +#endif =20 struct tmem_host_dependent_client { struct domain *domain; @@ -286,6 +289,29 @@ typedef XEN_GUEST_HANDLE(tmem_op_t) tmem =20 static inline int tmh_get_tmemop_from_client(tmem_op_t *op, tmem_cli_op_t = uops) { +#ifdef CONFIG_COMPAT + if ( is_pv_32on64_vcpu(current) ) + { + int rc; + enum XLAT_tmem_op_u u; + tmem_op_compat_t cop; + + rc =3D copy_from_guest(&cop, guest_handle_cast(uops, void), 1); + if ( rc ) + return rc; + switch ( cop.cmd ) + { + case TMEM_NEW_POOL: u =3D XLAT_tmem_op_u_new; break; + case TMEM_CONTROL: u =3D XLAT_tmem_op_u_ctrl; break; + default: u =3D XLAT_tmem_op_u_gen; break; + } +#define XLAT_tmem_op_HNDL_u_ctrl_buf(_d_, _s_) \ + guest_from_compat_handle((_d_)->u.ctrl.buf, (_s_)->u.ctrl.buf) + XLAT_tmem_op(op, &cop); +#undef XLAT_tmem_op_HNDL_u_ctrl_buf + return 0; + } +#endif return copy_from_guest(op, uops, 1); } =20 --- 2009-06-10.orig/xen/include/xlat.lst 2009-06-16 16:38:02.0000000= 00 +0200 +++ 2009-06-10/xen/include/xlat.lst 2009-06-15 15:14:25.000000000 = +0200 @@ -57,6 +57,7 @@ ! sched_poll sched.h ? sched_remote_shutdown sched.h ? sched_shutdown sched.h +! tmem_op tmem.h ? t_buf trace.h ? vcpu_get_physid vcpu.h ? vcpu_register_vcpu_info vcpu.h @@ -74,6 +75,3 @@ ? processor_px platform.h ! psd_package platform.h ! processor_performance platform.h -# ? tmem_op_t tmem.h -# ? tmem_cli_mfn_t tmem.h -# ? tmem_cli_va_t tmem.h --- 2009-06-10.orig/xen/include/public/tmem.h 2009-06-15 14:58:25.0000000= 00 +0200 +++ 2009-06-10/xen/include/public/tmem.h 2009-06-16 11:30:05.0000000= 00 +0200 @@ -75,14 +75,14 @@ struct tmem_op { struct { /* for cmd =3D=3D TMEM_NEW_POOL */ uint64_t uuid[2]; uint32_t flags; - }; + } new; struct { /* for cmd =3D=3D TMEM_CONTROL */ uint32_t subop; uint32_t cli_id; uint32_t arg1; uint32_t arg2; tmem_cli_va_t buf; - }; + } ctrl; struct { uint64_t object; uint32_t index; @@ -90,8 +90,8 @@ struct tmem_op { uint32_t pfn_offset; uint32_t len; tmem_cli_mfn_t cmfn; /* client machine page frame */ - }; - }; + } gen; + } u; }; typedef struct tmem_op tmem_op_t; DEFINE_XEN_GUEST_HANDLE(tmem_op_t); --- 2009-06-10.orig/xen/tools/get-fields.sh 2009-06-16 16:38:02.0000000= 00 +0200 +++ 2009-06-10/xen/tools/get-fields.sh 2009-06-16 15:08:22.000000000 = +0200 @@ -34,6 +34,34 @@ get_fields () done } =20 +get_typedefs () +{ + local level=3D1 state=3D + for token in $1 + do + case "$token" in + typedef) + test $level !=3D 1 || state=3D1 + ;; + COMPAT_HANDLE\(*\)) + test $level !=3D 1 -o "$state" !=3D 1 || state=3D2 + ;; + [\{\[]) + level=3D$(expr $level + 1) + ;; + [\}\]]) + level=3D$(expr $level - 1) + ;; + ";") + test $level !=3D 1 || state=3D + ;; + [a-zA-Z_]*) + test $level !=3D 1 -o "$state" !=3D 2 || echo = "$token" + ;; + esac + done +} + build_enums () { local level=3D1 kind=3D fields=3D members=3D named=3D id=3D token @@ -166,7 +194,21 @@ for line in sys.stdin.readlines(): fi ;; [a-zA-Z]*) - id=3D$token + if [ -z "$id" -a -z "$type" -a -z = "$array_type" ] + then + for id in $typedefs + do + test $id !=3D "$token" || = type=3D$id + done + if [ -z "$type" ] + then + id=3D$token + else + id=3D + fi + else + id=3D$token + fi ;; [\,\;]) if [ $level =3D 2 -a -n "$(echo $id | $SED = 's,^_pad[[:digit:]]*,,')" ] @@ -281,6 +323,18 @@ build_body () if [ -n "$array" ] then array=3D"$array $token" + elif [ -z "$id" -a -z "$type" -a -z "$array_type" = ] + then + for id in $typedefs + do + test $id !=3D "$token" || = type=3D$id + done + if [ -z "$type" ] + then + id=3D$token + else + id=3D + fi else id=3D$token fi @@ -419,7 +473,8 @@ build_check () echo "" } =20 -fields=3D"$(get_fields $(echo $2 | $SED 's,^compat_xen,compat_,') "$($SED = -e 's,^[[:space:]]#.*,,' -e 's!\([]\[,;:{}]\)! \1 !g' $3)")" +list=3D"$($SED -e 's,^[[:space:]]#.*,,' -e 's!\([]\[,;:{}]\)! \1 !g' $3)" +fields=3D"$(get_fields $(echo $2 | $SED 's,^compat_xen,compat_,') = "$list")" if [ -z "$fields" ] then echo "Fields of '$2' not found in '$3'" >&2 @@ -429,6 +484,7 @@ name=3D${2#compat_} name=3D${name#xen} case "$1" in "!") + typedefs=3D"$(get_typedefs "$list")" build_enums $name "$fields" build_body $name "$fields" ;;