xcp-1.6-updates/xen-4.1.hg

changeset 23260:8a2e167905d3

x86/xenoprof: fix 32-bit guest stack handling after c/s 24537:3c0a533d3af0

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 <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 24971:e88a49951212
xen-unstable date: Tue Mar 06 16:43:01 2012 +0100
author Jan Beulich <jbeulich@suse.com>
date Thu Mar 08 08:58:26 2012 +0000 (2012-03-08)
parents ed5c1ad51a23
children 0bbaff574126
files xen/arch/x86/oprofile/backtrace.c
line diff
     1.1 --- a/xen/arch/x86/oprofile/backtrace.c	Wed Mar 07 10:58:25 2012 +0000
     1.2 +++ b/xen/arch/x86/oprofile/backtrace.c	Thu Mar 08 08:58:26 2012 +0000
     1.3 @@ -13,18 +13,22 @@
     1.4  #include<xen/types.h>
     1.5  #include<asm/page.h>
     1.6  #include<xen/xenoprof.h>
     1.7 -#include<asm/guest_access.h>
     1.8 +#include<xen/guest_access.h>
     1.9  
    1.10  struct frame_head {
    1.11      struct frame_head * ebp;
    1.12      unsigned long ret;
    1.13  } __attribute__((packed));
    1.14 +typedef struct frame_head frame_head_t;
    1.15 +DEFINE_XEN_GUEST_HANDLE(frame_head_t);
    1.16  
    1.17  #ifdef CONFIG_X86_64
    1.18  struct frame_head_32bit {
    1.19      uint32_t ebp;
    1.20 -    unsigned long ret;
    1.21 +    uint32_t ret;
    1.22  } __attribute__((packed));
    1.23 +typedef struct frame_head_32bit frame_head32_t;
    1.24 +DEFINE_COMPAT_HANDLE(frame_head32_t);
    1.25  #endif
    1.26  
    1.27  static struct frame_head *
    1.28 @@ -54,44 +58,47 @@ static inline int is_32bit_vcpu(struct v
    1.29  
    1.30  static struct frame_head *
    1.31  dump_guest_backtrace(struct domain *d, struct vcpu *vcpu, 
    1.32 -		     struct frame_head * head, int mode)
    1.33 +		     const struct frame_head *head, int mode)
    1.34  {
    1.35 -    struct frame_head bufhead[2];
    1.36 -    XEN_GUEST_HANDLE(char) guest_head = guest_handle_from_ptr(head, char);
    1.37 +    frame_head_t bufhead;
    1.38  
    1.39  #ifdef CONFIG_X86_64
    1.40      if ( is_32bit_vcpu(vcpu) )
    1.41      {
    1.42 -        struct frame_head_32bit bufhead32[2];
    1.43 +        __compat_handle_const_frame_head32_t guest_head =
    1.44 +            { .c = (unsigned long)head };
    1.45 +        frame_head32_t bufhead32;
    1.46 +
    1.47          /* Also check accessibility of one struct frame_head beyond */
    1.48 -        if (!guest_handle_okay(guest_head, sizeof(bufhead32)))
    1.49 +        if (!compat_handle_okay(guest_head, 2))
    1.50              return 0;
    1.51 -        if (__copy_from_guest_offset((char *)bufhead32, guest_head, 0, 
    1.52 -                                     sizeof(bufhead32)))
    1.53 +        if (__copy_from_compat(&bufhead32, guest_head, 1))
    1.54              return 0;
    1.55 -        bufhead[0].ebp=(struct frame_head *)(unsigned long)bufhead32[0].ebp;
    1.56 -        bufhead[0].ret=bufhead32[0].ret;
    1.57 +        bufhead.ebp = (struct frame_head *)(unsigned long)bufhead32.ebp;
    1.58 +        bufhead.ret = bufhead32.ret;
    1.59      }
    1.60      else
    1.61  #endif
    1.62      {
    1.63 +        XEN_GUEST_HANDLE(const_frame_head_t) guest_head =
    1.64 +            const_guest_handle_from_ptr(head, frame_head_t);
    1.65 +
    1.66          /* Also check accessibility of one struct frame_head beyond */
    1.67 -        if (!guest_handle_okay(guest_head, sizeof(bufhead)))
    1.68 +        if (!guest_handle_okay(guest_head, 2))
    1.69              return 0;
    1.70 -        if (__copy_from_guest_offset((char *)bufhead, guest_head, 0, 
    1.71 -                                     sizeof(bufhead)))
    1.72 +        if (__copy_from_guest(&bufhead, guest_head, 1))
    1.73              return 0;
    1.74      }
    1.75      
    1.76 -    if (!xenoprof_add_trace(d, vcpu, bufhead[0].ret, mode))
    1.77 +    if (!xenoprof_add_trace(d, vcpu, bufhead.ret, mode))
    1.78          return 0;
    1.79      
    1.80      /* frame pointers should strictly progress back up the stack
    1.81       * (towards higher addresses) */
    1.82 -    if (head >= bufhead[0].ebp)
    1.83 +    if (head >= bufhead.ebp)
    1.84          return NULL;
    1.85      
    1.86 -    return bufhead[0].ebp;
    1.87 +    return bufhead.ebp;
    1.88  }
    1.89  
    1.90  /*