From: "Jan Beulich" Subject: [PATCH] x86/xenoprof: fix 32-bit guest stack handling after c/s 24537:3c0a533d3af0 Date: Tue, 06 Mar 2012 15:04:26 +0000 Message-ID: <4F56358A0200007800076AF4@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3C12286A.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: George Dunlap , Marcus Granado List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part3C12286A.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 32-bit guests don't have 64-bit precudrure return addresses - both elements of struct frame_head_32bit should be 32 bits wide, not just the frame link pointer. Further, consolidate the whole handling here (also in the native size guest case) to properly use guest handles and guest memory accessors. Signed-off-by: Jan Beulich --- a/xen/arch/x86/oprofile/backtrace.c +++ b/xen/arch/x86/oprofile/backtrace.c @@ -13,18 +13,22 @@ #include #include #include -#include +#include =20 struct frame_head { struct frame_head * ebp; unsigned long ret; } __attribute__((packed)); +typedef struct frame_head frame_head_t; +DEFINE_XEN_GUEST_HANDLE(frame_head_t); =20 #ifdef CONFIG_X86_64 struct frame_head_32bit { uint32_t ebp; - unsigned long ret; + uint32_t ret; } __attribute__((packed)); +typedef struct frame_head_32bit frame_head32_t; +DEFINE_COMPAT_HANDLE(frame_head32_t); #endif =20 static struct frame_head * @@ -54,44 +58,47 @@ static inline int is_32bit_vcpu(struct v =20 static struct frame_head * dump_guest_backtrace(struct domain *d, struct vcpu *vcpu,=20 - struct frame_head * head, int mode) + const struct frame_head *head, int mode) { - struct frame_head bufhead[2]; - XEN_GUEST_HANDLE(char) guest_head =3D guest_handle_from_ptr(head, = char); + frame_head_t bufhead; =20 #ifdef CONFIG_X86_64 if ( is_32bit_vcpu(vcpu) ) { - struct frame_head_32bit bufhead32[2]; + __compat_handle_const_frame_head32_t guest_head =3D + { .c =3D (unsigned long)head }; + frame_head32_t bufhead32; + /* Also check accessibility of one struct frame_head beyond */ - if (!guest_handle_okay(guest_head, sizeof(bufhead32))) + if (!compat_handle_okay(guest_head, 2)) return 0; - if (__copy_from_guest_offset((char *)bufhead32, guest_head, 0,=20 - sizeof(bufhead32))) + if (__copy_from_compat(&bufhead32, guest_head, 1)) return 0; - bufhead[0].ebp=3D(struct frame_head *)(unsigned long)bufhead32[0].= ebp; - bufhead[0].ret=3Dbufhead32[0].ret; + bufhead.ebp =3D (struct frame_head *)(unsigned long)bufhead32.ebp;= + bufhead.ret =3D bufhead32.ret; } else #endif { + XEN_GUEST_HANDLE(const_frame_head_t) guest_head =3D + const_guest_handle_from_ptr(head, frame_head_t); + /* Also check accessibility of one struct frame_head beyond */ - if (!guest_handle_okay(guest_head, sizeof(bufhead))) + if (!guest_handle_okay(guest_head, 2)) return 0; - if (__copy_from_guest_offset((char *)bufhead, guest_head, 0,=20 - sizeof(bufhead))) + if (__copy_from_guest(&bufhead, guest_head, 1)) return 0; } =20 - if (!xenoprof_add_trace(d, vcpu, bufhead[0].ret, mode)) + if (!xenoprof_add_trace(d, vcpu, bufhead.ret, mode)) return 0; =20 /* frame pointers should strictly progress back up the stack * (towards higher addresses) */ - if (head >=3D bufhead[0].ebp) + if (head >=3D bufhead.ebp) return NULL; =20 - return bufhead[0].ebp; + return bufhead.ebp; } =20 /* --=__Part3C12286A.1__= Content-Type: text/plain; name="x86-oprof-fix-24537.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-oprof-fix-24537.patch" x86/xenoprof: fix 32-bit guest stack handling after c/s 24537:3c0a533d3af0 = =0A=0A32-bit guests don't have 64-bit precudrure return addresses - = both=0Aelements of struct frame_head_32bit should be 32 bits wide, not = just=0Athe frame link pointer.=0A=0AFurther, consolidate the whole = handling here (also in the native size=0Aguest case) to properly use guest = handles and guest memory accessors.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/oprofile/backtrace.c=0A+++ = b/xen/arch/x86/oprofile/backtrace.c=0A@@ -13,18 +13,22 @@=0A #include=0A #include=0A #include=0A-#include=0A+#include=0A =0A struct frame_head = {=0A struct frame_head * ebp;=0A unsigned long ret;=0A } __attribut= e__((packed));=0A+typedef struct frame_head frame_head_t;=0A+DEFINE_XEN_GUE= ST_HANDLE(frame_head_t);=0A =0A #ifdef CONFIG_X86_64=0A struct frame_head_3= 2bit {=0A uint32_t ebp;=0A- unsigned long ret;=0A+ uint32_t = ret;=0A } __attribute__((packed));=0A+typedef struct frame_head_32bit = frame_head32_t;=0A+DEFINE_COMPAT_HANDLE(frame_head32_t);=0A #endif=0A =0A = static struct frame_head *=0A@@ -54,44 +58,47 @@ static inline int = is_32bit_vcpu(struct v=0A =0A static struct frame_head *=0A dump_guest_back= trace(struct domain *d, struct vcpu *vcpu, =0A- struct = frame_head * head, int mode)=0A+ const struct = frame_head *head, int mode)=0A {=0A- struct frame_head bufhead[2];=0A- = XEN_GUEST_HANDLE(char) guest_head =3D guest_handle_from_ptr(head, = char);=0A+ frame_head_t bufhead;=0A =0A #ifdef CONFIG_X86_64=0A if = ( is_32bit_vcpu(vcpu) )=0A {=0A- struct frame_head_32bit = bufhead32[2];=0A+ __compat_handle_const_frame_head32_t guest_head = =3D=0A+ { .c =3D (unsigned long)head };=0A+ frame_head32_= t bufhead32;=0A+=0A /* Also check accessibility of one struct = frame_head beyond */=0A- if (!guest_handle_okay(guest_head, = sizeof(bufhead32)))=0A+ if (!compat_handle_okay(guest_head, 2))=0A = return 0;=0A- if (__copy_from_guest_offset((char = *)bufhead32, guest_head, 0, =0A- = sizeof(bufhead32)))=0A+ if (__copy_from_compat(&bufhead32, = guest_head, 1))=0A return 0;=0A- bufhead[0].ebp=3D(struc= t frame_head *)(unsigned long)bufhead32[0].ebp;=0A- bufhead[0].ret= =3Dbufhead32[0].ret;=0A+ bufhead.ebp =3D (struct frame_head = *)(unsigned long)bufhead32.ebp;=0A+ bufhead.ret =3D bufhead32.ret;= =0A }=0A else=0A #endif=0A {=0A+ XEN_GUEST_HANDLE(const_= frame_head_t) guest_head =3D=0A+ const_guest_handle_from_ptr(hea= d, frame_head_t);=0A+=0A /* Also check accessibility of one struct = frame_head beyond */=0A- if (!guest_handle_okay(guest_head, = sizeof(bufhead)))=0A+ if (!guest_handle_okay(guest_head, 2))=0A = return 0;=0A- if (__copy_from_guest_offset((char *)bufhead, = guest_head, 0, =0A- sizeof(bufhead)))= =0A+ if (__copy_from_guest(&bufhead, guest_head, 1))=0A = return 0;=0A }=0A =0A- if (!xenoprof_add_trace(d, vcpu, = bufhead[0].ret, mode))=0A+ if (!xenoprof_add_trace(d, vcpu, bufhead.ret,= mode))=0A return 0;=0A =0A /* frame pointers should = strictly progress back up the stack=0A * (towards higher addresses) = */=0A- if (head >=3D bufhead[0].ebp)=0A+ if (head >=3D bufhead.ebp)= =0A return NULL;=0A =0A- return bufhead[0].ebp;=0A+ = return bufhead.ebp;=0A }=0A =0A /*=0A --=__Part3C12286A.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part3C12286A.1__=--