xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/xenoprof: Fix kernel/user mode detection for HVM
@ 2012-10-12 16:11 Jacob Shin
  2012-10-15 11:51 ` [PATCH, v2] x86/xenoprof: fix " Jan Beulich
  0 siblings, 1 reply; 3+ messages in thread
From: Jacob Shin @ 2012-10-12 16:11 UTC (permalink / raw)
  To: xen-devel

x86/xenoprof: Fix kernel/user mode detection for HVM

While trying oprofile under Xen, I noticed that HVM passive domain's kernel 
addresses were showing up as user application. It turns out under HVM 
get_cpu_user_regs()->cs contains 0x0000beef.

Signed-off-by: Jacob Shin <jacob.shin@amd.com>

diff -r e0e1350dfe9b xen/arch/x86/oprofile/xenoprof.c
--- a/xen/arch/x86/oprofile/xenoprof.c	Thu Oct 11 15:57:00 2012 +0100
+++ b/xen/arch/x86/oprofile/xenoprof.c	Fri Oct 12 10:48:37 2012 -0500
@@ -81,7 +81,11 @@ int xenoprofile_get_mode(const struct vc
         return 2;
 
     if ( is_hvm_vcpu(v) )
-        return ((regs->cs & 3) != 3);
+    {
+        struct segment_register cs;
+        hvm_get_segment_register((struct vcpu *)v, x86_seg_cs, &cs);
+        return ((cs.sel & 3) != 3);
+    }
 
     return guest_kernel_mode(v, regs);  
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH, v2] x86/xenoprof: fix kernel/user mode detection for HVM
  2012-10-12 16:11 [PATCH] x86/xenoprof: Fix kernel/user mode detection for HVM Jacob Shin
@ 2012-10-15 11:51 ` Jan Beulich
  2012-10-15 12:09   ` Keir Fraser
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2012-10-15 11:51 UTC (permalink / raw)
  To: xen-devel; +Cc: Jacob Shin

[-- Attachment #1: Type: text/plain, Size: 1720 bytes --]

While trying oprofile under Xen, I noticed that HVM passive domain's
kernel addresses were showing up as user application. It turns out
under HVM get_cpu_user_regs()->cs contains 0x0000beef.

Signed-off-by: Jacob Shin <jacob.shin@amd.com>

Don't cast away const-ness. Use SS instead of CS to determine ring.
Special-case real and protected mode.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/oprofile/xenoprof.c
+++ b/xen/arch/x86/oprofile/xenoprof.c
@@ -74,16 +74,26 @@ int compat_oprof_arch_counter(XEN_GUEST_
     return 0;
 }
 
-int xenoprofile_get_mode(const struct vcpu *v,
-                         const struct cpu_user_regs *regs)
+int xenoprofile_get_mode(struct vcpu *curr, const struct cpu_user_regs *regs)
 {
     if ( !guest_mode(regs) )
         return 2;
 
-    if ( is_hvm_vcpu(v) )
-        return ((regs->cs & 3) != 3);
+    if ( !is_hvm_vcpu(curr) )
+        return guest_kernel_mode(curr, regs);
 
-    return guest_kernel_mode(v, regs);  
+    switch ( hvm_guest_x86_mode(curr) )
+    {
+        struct segment_register ss;
+
+    case 0: /* real mode */
+        return 1;
+    case 1: /* vm86 mode */
+        return 0;
+    default:
+        hvm_get_segment_register(curr, x86_seg_ss, &ss);
+        return (ss.sel & 3) != 3;
+    }
 }
 
 /*
--- a/xen/include/asm-x86/xenoprof.h
+++ b/xen/include/asm-x86/xenoprof.h
@@ -51,7 +51,7 @@ struct cpu_user_regs;
 void ibs_init(void);
 extern u32 ibs_caps;
 
-int xenoprofile_get_mode(const struct vcpu *, const struct cpu_user_regs *);
+int xenoprofile_get_mode(struct vcpu *, const struct cpu_user_regs *);
 
 static inline int xenoprof_backtrace_supported(void)
 {




[-- Attachment #2: x86-oprof-hvm-mode.patch --]
[-- Type: text/plain, Size: 1770 bytes --]

x86/xenoprof: fix kernel/user mode detection for HVM

While trying oprofile under Xen, I noticed that HVM passive domain's
kernel addresses were showing up as user application. It turns out
under HVM get_cpu_user_regs()->cs contains 0x0000beef.

Signed-off-by: Jacob Shin <jacob.shin@amd.com>

Don't cast away const-ness. Use SS instead of CS to determine ring.
Special-case real and protected mode.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/oprofile/xenoprof.c
+++ b/xen/arch/x86/oprofile/xenoprof.c
@@ -74,16 +74,26 @@ int compat_oprof_arch_counter(XEN_GUEST_
     return 0;
 }
 
-int xenoprofile_get_mode(const struct vcpu *v,
-                         const struct cpu_user_regs *regs)
+int xenoprofile_get_mode(struct vcpu *curr, const struct cpu_user_regs *regs)
 {
     if ( !guest_mode(regs) )
         return 2;
 
-    if ( is_hvm_vcpu(v) )
-        return ((regs->cs & 3) != 3);
+    if ( !is_hvm_vcpu(curr) )
+        return guest_kernel_mode(curr, regs);
 
-    return guest_kernel_mode(v, regs);  
+    switch ( hvm_guest_x86_mode(curr) )
+    {
+        struct segment_register ss;
+
+    case 0: /* real mode */
+        return 1;
+    case 1: /* vm86 mode */
+        return 0;
+    default:
+        hvm_get_segment_register(curr, x86_seg_ss, &ss);
+        return (ss.sel & 3) != 3;
+    }
 }
 
 /*
--- a/xen/include/asm-x86/xenoprof.h
+++ b/xen/include/asm-x86/xenoprof.h
@@ -51,7 +51,7 @@ struct cpu_user_regs;
 void ibs_init(void);
 extern u32 ibs_caps;
 
-int xenoprofile_get_mode(const struct vcpu *, const struct cpu_user_regs *);
+int xenoprofile_get_mode(struct vcpu *, const struct cpu_user_regs *);
 
 static inline int xenoprof_backtrace_supported(void)
 {

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, v2] x86/xenoprof: fix kernel/user mode detection for HVM
  2012-10-15 11:51 ` [PATCH, v2] x86/xenoprof: fix " Jan Beulich
@ 2012-10-15 12:09   ` Keir Fraser
  0 siblings, 0 replies; 3+ messages in thread
From: Keir Fraser @ 2012-10-15 12:09 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Jacob Shin

On 15/10/2012 12:51, "Jan Beulich" <JBeulich@suse.com> wrote:

> While trying oprofile under Xen, I noticed that HVM passive domain's
> kernel addresses were showing up as user application. It turns out
> under HVM get_cpu_user_regs()->cs contains 0x0000beef.
> 
> Signed-off-by: Jacob Shin <jacob.shin@amd.com>
> 
> Don't cast away const-ness. Use SS instead of CS to determine ring.
> Special-case real and protected mode.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Keir Fraser <keir@xen.org>

> --- a/xen/arch/x86/oprofile/xenoprof.c
> +++ b/xen/arch/x86/oprofile/xenoprof.c
> @@ -74,16 +74,26 @@ int compat_oprof_arch_counter(XEN_GUEST_
>      return 0;
>  }
>  
> -int xenoprofile_get_mode(const struct vcpu *v,
> -                         const struct cpu_user_regs *regs)
> +int xenoprofile_get_mode(struct vcpu *curr, const struct cpu_user_regs *regs)
>  {
>      if ( !guest_mode(regs) )
>          return 2;
>  
> -    if ( is_hvm_vcpu(v) )
> -        return ((regs->cs & 3) != 3);
> +    if ( !is_hvm_vcpu(curr) )
> +        return guest_kernel_mode(curr, regs);
>  
> -    return guest_kernel_mode(v, regs);
> +    switch ( hvm_guest_x86_mode(curr) )
> +    {
> +        struct segment_register ss;
> +
> +    case 0: /* real mode */
> +        return 1;
> +    case 1: /* vm86 mode */
> +        return 0;
> +    default:
> +        hvm_get_segment_register(curr, x86_seg_ss, &ss);
> +        return (ss.sel & 3) != 3;
> +    }
>  }
>  
>  /*
> --- a/xen/include/asm-x86/xenoprof.h
> +++ b/xen/include/asm-x86/xenoprof.h
> @@ -51,7 +51,7 @@ struct cpu_user_regs;
>  void ibs_init(void);
>  extern u32 ibs_caps;
>  
> -int xenoprofile_get_mode(const struct vcpu *, const struct cpu_user_regs *);
> +int xenoprofile_get_mode(struct vcpu *, const struct cpu_user_regs *);
>  
>  static inline int xenoprof_backtrace_supported(void)
>  {
> 
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-15 12:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-12 16:11 [PATCH] x86/xenoprof: Fix kernel/user mode detection for HVM Jacob Shin
2012-10-15 11:51 ` [PATCH, v2] x86/xenoprof: fix " Jan Beulich
2012-10-15 12:09   ` Keir Fraser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).