Skip to contentSkip to conversation

Xenoprof passive domain support fixes

PATCH DaSilva, Rosilmildo 4 participants 6 messages Jul 14, 2006 – Jul 16, 2006

lore
Share & tools
lore
#0 lore raw

Ray,
A 64bit guest would never have any entry on pvmlinux?, since the code on opd_kernel.c, line 112 ( of oprofile ), hardcodes the addresses in the range of 0xC0100000 - 0xC060000. The 64bits guest has a complete different range.

Renato, seu nome parece um nome Brasileiro.
Rosimildo.

-----Original Message-----
From: Ray Bryant [mailto:[email protected]]
Sent: Friday, July 14, 2006 9:01 AM
To: [email protected]
Cc: Santos, Jose Renato G; Yang, Xiaowei; DaSilva, Rosilmildo
Subject: Re: [Xen-devel] RE: [PATCH] Xenoprof passive domain support fixes

Renato,

BTW, the HVM guest I am running (and hence the passive image) is a 64-bit
guest. We've run experiments with 32 bit guests and we do get pvmlinux

samples. There may be other differences between these experiments,
but
this is the only one we've been able to identify thus far.

So perhaps there is something broken about kernel samples in a passive domain
and 64 bit?

Signature · 3 lines
Ray Bryant
AMD Performance Labs                   Austin, Tx
512-602-0038 (o)                 512-507-7807 (c)
#1 lore raw
Quoted 9 lines · Rosilmildo

Ray,
A 64bit guest would never have any entry on pvmlinux?, since the code on opd_kernel.c, line 112 ( of oprofile ), hardcodes the addresses in the range of 0xC0100000 - 0xC060000. The 64bits guest has a complete different range.

Renato, seu nome parece um nome Brasileiro.
Rosimildo.

That would certainly explain what I am seeing. I thought Rento's patch was
intended to do away with such hard coded addresses, but perhaps not all of that is done yet. An easy test would be to change the range so it matches
what the 64 bit kernel would use. What address range should I use instead
(for 64-bit)?

Signature · 3 lines
Ray Bryant
AMD Performance Labs                   Austin, Tx
512-602-0038 (o)                 512-507-7807 (c)
#2 lore raw

Attached patch is what we have been using internally to allow HVM guest profiling on 64bit hv with 32bit hvm guest. Code generated by Rosimildo. This patch is experimental and not ready for inclusion into any repo, but might help with the next set of patches for xenoprofile support. This patch has oprofile, SVM, VT and HVM modifications all rolled into one inclusive patch file. For SVM, if you modify opd_kernel.c image start/end addresses in oprofile 0.9.1 then 64bit samples seem to work. VT does not seem to work with attached patch, but we haven't spent time debugging why.
Mods:
1) move SVM global interrupt to vmexit handler
2) add VGCF_hvm_guest_nmi flag to guest context to distinguish nmi occuring in guest rather than in host
3) oprofile model files modified to use the new VGCF_hvm_guest_nmi flag to determine a bit more properly the mode

Thanks
Tom

xen/arch/x86/hvm/svm/svm.c +18 -2
diff -r f692a0a476c5 xen/arch/x86/hvm/svm/svm.c
@@ -53,10 +53,13 @@
 #define set_segment_register(name, value)  \
        __asm__ __volatile__ ( "movw %%ax ,%%" STR(name) "" : : "a" (value) )
 
+/* set global interupts (enable) */
+#define stgi() asm( ".byte 0x0F,0x01,0xDC" );
+
 /* 
  * External functions, etc. We should move these to some suitable header file(s) */
 
-extern void do_nmi(struct cpu_user_regs *, unsigned long);
+extern void do_nmi(struct cpu_user_regs * );
 extern int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip,
                                 int inst_len);
 extern asmlinkage void do_IRQ(struct cpu_user_regs *);
@@ -2600,6 +2603,14 @@
 
     vmcb->tlb_control = 1;
 
+    if( exit_reason != VMEXIT_NMI )
+    {
+       /* this is not a guest NMI */
+       v->arch.guest_context.flags &= ~VGCF_hvm_guest_nmi;
+       stgi();
+    }
+
+
 #ifdef SVM_EXTRA_DEBUG
 {
 #if defined(__i386__)
@@ -2733,7 +2744,12 @@
     break;
 
     case VMEXIT_NMI:
-        do_nmi(&regs, 0);
+        /* this is a guest NMI */
+        v->arch.guest_context.flags |= VGCF_hvm_guest_nmi;
+        do_nmi(&regs);
+        /* this is not a guest NMI */
+        v->arch.guest_context.flags &= ~VGCF_hvm_guest_nmi;
+        stgi();
         break;
 
     case VMEXIT_SMI:
xen/arch/x86/hvm/svm/x86_32/exits.S +0 -1
diff -r f692a0a476c5 xen/arch/x86/hvm/svm/x86_32/exits.S
@@ -123,7 +123,6 @@
         VMLOAD
 
         HVM_SAVE_ALL_NOSEGREGS
-        STGI
         call svm_vmexit_handler
         jmp  svm_asm_do_resume
 
xen/arch/x86/hvm/svm/x86_64/exits.S +0 -1
diff -r f692a0a476c5 xen/arch/x86/hvm/svm/x86_64/exits.S
@@ -140,7 +140,6 @@
         VMLOAD
 
         HVM_SAVE_ALL_NOSEGREGS
-        STGI
         call svm_vmexit_handler
         jmp  svm_asm_do_resume
 
xen/arch/x86/hvm/vmx/vmx.c +5 -0
diff -r f692a0a476c5 xen/arch/x86/hvm/vmx/vmx.c
@@ -2083,6 +2083,9 @@
 
     perfc_incra(vmexits, exit_reason);
 
+    /* assume this is not a MNI */
+    v->arch.guest_context.flags &= ~VGCF_hvm_guest_nmi;
+
     if ( (exit_reason != EXIT_REASON_EXTERNAL_INTERRUPT) &&
          (exit_reason != EXIT_REASON_VMCALL) &&
          (exit_reason != EXIT_REASON_IO_INSTRUCTION) )
@@ -2219,7 +2222,9 @@
             break;
         }
         case TRAP_nmi:
+            v->arch.guest_context.flags |= VGCF_hvm_guest_nmi;
             do_nmi(&regs);
+            v->arch.guest_context.flags &= ~VGCF_hvm_guest_nmi;
             break;
         default:
             vmx_reflect_exception(v);
xen/arch/x86/oprofile/op_model_athlon.c +12 -3
diff -r f692a0a476c5 xen/arch/x86/oprofile/op_model_athlon.c
@@ -18,6 +18,8 @@
 #include <xen/sched.h>
 #include <asm/regs.h>
 #include <asm/current.h>
+#include <asm/hvm/hvm.h>
+#include <asm/hvm/support.h>
  
 #include "op_x86_model.h"
 #include "op_counter.h"
@@ -108,16 +110,23 @@
 	int ovf = 0;
 	unsigned long eip = regs->eip;
 	int mode = 0;
+        struct vcpu *v = current;
 
-	if (guest_kernel_mode(current, regs))
+        if (hvm_guest(v))
+	{
+	  mode = 2;  /* assume it is HV context */
+          if( v->arch.guest_context.flags & VGCF_hvm_guest_nmi )
+	       mode = ring_0(regs) ? 1 : 0;
+        }
+        else if ( guest_kernel_mode(v, regs) ) 
 		mode = 1;
-	else if (ring_0(regs))
+	else if ( ring_0(regs) )
 		mode = 2;
 
 	for (i = 0 ; i < NUM_COUNTERS; ++i) {
 		CTR_READ(low, high, msrs, i);
 		if (CTR_OVERFLOWED(low)) {
-			xenoprof_log_event(current, eip, mode, i);
+			xenoprof_log_event(v, eip, mode, i);
 			CTR_WRITE(reset_value[i], msrs, i);
 			ovf = 1;
 		}
xen/arch/x86/oprofile/op_model_p4.c +13 -4
diff -r f692a0a476c5 xen/arch/x86/oprofile/op_model_p4.c
@@ -16,6 +16,8 @@
 #include <xen/sched.h>
 #include <asm/regs.h>
 #include <asm/current.h>
+#include <asm/hvm/hvm.h>
+#include <asm/hvm/support.h>
 
 #include "op_x86_model.h"
 #include "op_counter.h"
@@ -633,10 +635,17 @@
 	int ovf = 0;
 	unsigned long eip = regs->eip;
 	int mode = 0;
-
-	if (guest_kernel_mode(current, regs))
+        struct vcpu *v = current;
+
+        if (hvm_guest(v))
+	{
+	  mode = 2;  /* assume it is HV context */
+          if( v->arch.guest_context.flags & VGCF_hvm_guest_nmi )
+	       mode = ring_0(regs) ? 1 : 0;
+        }
+        else if ( guest_kernel_mode(v, regs) ) 
 		mode = 1;
-	else if (ring_0(regs))
+	else if ( ring_0(regs) )
 		mode = 2;
 
 	stag = get_stagger();
@@ -668,7 +677,7 @@
 		CCCR_READ(low, high, real);
  		CTR_READ(ctr, high, real);
 		if (CCCR_OVF_P(low) || CTR_OVERFLOW_P(ctr)) {
-			xenoprof_log_event(current, eip, mode, i);
+			xenoprof_log_event(v, eip, mode, i);
  			CTR_WRITE(reset_value[i], real);
 			CCCR_CLEAR_OVF(low);
 			CCCR_WRITE(low, high, real);
xen/arch/x86/oprofile/op_model_ppro.c +10 -1
diff -r f692a0a476c5 xen/arch/x86/oprofile/op_model_ppro.c
@@ -18,6 +18,8 @@
 #include <xen/sched.h>
 #include <asm/regs.h>
 #include <asm/current.h>
+#include <asm/hvm/hvm.h>
+#include <asm/hvm/support.h>
  
 #include "op_x86_model.h"
 #include "op_counter.h"
@@ -101,8 +103,15 @@
 	int ovf = 0;
 	unsigned long eip = regs->eip;
 	int mode = 0;
+        struct vcpu *v = current;
 
-	if ( guest_kernel_mode(current, regs) ) 
+        if (hvm_guest(v))
+	{
+	  mode = 2;  /* assume it is HV context */
+          if( v->arch.guest_context.flags & VGCF_hvm_guest_nmi )
+	       mode = ring_0(regs) ? 1 : 0;
+        }
+        else if ( guest_kernel_mode(v, regs) ) 
 		mode = 1;
 	else if ( ring_0(regs) )
 		mode = 2;
xen/include/public/arch-x86_64.h +2 -0
diff -r f692a0a476c5 xen/include/public/arch-x86_64.h
@@ -233,6 +233,8 @@
 #define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
 #define _VGCF_syscall_disables_events  4
 #define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
+#define _VGCF_hvm_guest_nmi            5
+#define VGCF_hvm_guest_nmi             (1<<_VGCF_hvm_guest_nmi)
     unsigned long flags;                    /* VGCF_* flags                 */
     struct cpu_user_regs user_regs;         /* User-level CPU registers     */
     struct trap_info trap_ctxt[256];        /* Virtual IDT                  */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
In reply to DaSilva, Rosilmildo

Rosimildo,

You are correct. This explains the problem that Ray is seeing. We need to fix the kernel code to use the right address range from the image file specified with --passive-images option. And in case the image file is not specified we need to rely on the CPU mode (user/kernel/xen) to assign the sample to the right bin.
I will proabbly not have time to work on this before the Ottawa Linux Simposium next week which I will be attending.
If nobody provides a fix until them I will work something out when I come back.
Xiaowei, any change you could provide a fix for this?

Thanks

Renato

PS- Brasileiro, sim. Bom encontrar outro brasileiro por aqui ...

Quoted 46 lines
Quoted 46 lines

-----Original Message-----
From: DaSilva, Rosilmildo [mailto:[email protected]]
Sent: Friday, July 14, 2006 7:37 AM
To: Ray Bryant; [email protected]
Cc: Santos, Jose Renato G; Yang, Xiaowei
Subject: RE: [Xen-devel] RE: [PATCH] Xenoprof passive domain support fixes

Ray,
A 64bit guest would never have any entry on pvmlinux?, since the code on opd_kernel.c, line 112 ( of oprofile ), hardcodes the addresses in the range of 0xC0100000 - 0xC060000. The 64bits guest has a complete different range.

Renato, seu nome parece um nome Brasileiro.
Rosimildo.

-----Original Message-----
From: Ray Bryant [mailto:[email protected]]
Sent: Friday, July 14, 2006 9:01 AM
To: [email protected]
Cc: Santos, Jose Renato G; Yang, Xiaowei; DaSilva, Rosilmildo
Subject: Re: [Xen-devel] RE: [PATCH] Xenoprof passive domain support fixes

Renato,

BTW, the HVM guest I am running (and hence the passive image) is a 64-bit
guest. We've run experiments with 32 bit guests and we do
get pvmlinux

samples. There may be other differences between these experiments,
but
this is the only one we've been able to identify thus far.

So perhaps there is something broken about kernel samples in a passive domain and 64 bit?

--
Ray Bryant
AMD Performance Labs Austin, Tx
512-602-0038 (o) 512-507-7807 (c)

#4 lore raw

Renato, et al,

I hacked my oprofiled as follows

daemon/opd_kernel.c +5 -2
Index: oprofile-xen-0.9.1/daemon/opd_kernel.c
===================================================================
@@ -109,8 +109,11 @@ void opd_create_passive(char const *name
                image = xmalloc(sizeof(struct kernel_image));
                image->name = xstrdup(file);
                // start/end VM should be more accurate, but it works now
-               image->start = 0xc0100000;
-               image->end =   0xc0600000;
+               // image->start = 0xc0100000;
+               // image->end =   0xc0600000;
+               // hack for 64 bit test
+               image->start = 0xFFFFFFFF80100000;
+               image->end   = 0xFFFFFFFF80600000;
                image->id = id;
                list_add(&image->list, &passive_vmlinux);
 

(This is the address range that Rosimildo suggested.)

Now I get pvmlinux samples for my 64-bit guest test case, however, the profile is not any good.

Almost all of the samples (148747 out 148751) are to a single address (from the oprofiled.log):

Sample 0x167fe0(0): kern (name /boot/pvmlinux2-syms, 0xffffffff80100000-0xffffffff80600000) ...

Rosimildo's patched SVM code works correctly and provides approximately the same kernel profile under HVM as we get when we run the application under a kernel natively (where we've run two simple applications: kernbench and stress vm).

We'd like to get to a point where the SVM and VT versions both work, but at the moment, we don't have the expertise to create the VT fixes, although Rosimildo has created some patches for test purposes.

Signature · 3 lines
Ray Bryant
AMD Performance Labs                   Austin, Tx
512-602-0038 (o)                 512-507-7807 (c)
#5 lore raw
Quoted 41 lines

-----Original Message-----
From: Ray Bryant [mailto:[email protected]]
Sent: Friday, July 14, 2006 11:20 AM
To: Santos, Jose Renato G
Cc: DaSilva, Rosilmildo; [email protected]; Yang, Xiaowei
Subject: Re: [Xen-devel] RE: [PATCH] Xenoprof passive domain support fixes

Renato, et al,

I hacked my oprofiled as follows

Index: oprofile-xen-0.9.1/daemon/opd_kernel.c
===================================================================

daemon/opd_kernel.c +0 -0
@@ -109,8 +109,11 @@ void opd_create_passive(char const *name
                image = xmalloc(sizeof(struct kernel_image));
                image->name = xstrdup(file);
                // start/end VM should be more accurate, but 

it works now

daemon/opd_kernel.c +5 -2
-               image->start = 0xc0100000;
-               image->end =   0xc0600000;
+               // image->start = 0xc0100000;
+               // image->end =   0xc0600000;
+               // hack for 64 bit test
+               image->start = 0xFFFFFFFF80100000;
+               image->end   = 0xFFFFFFFF80600000;
                image->id = id;
                list_add(&image->list, &passive_vmlinux);

(This is the address range that Rosimildo suggested.)

Now I get pvmlinux samples for my 64-bit guest test case, however, the profile is not any good.

Almost all of the samples (148747 out 148751) are to a single address (from the oprofiled.log):

Quoted 8 lines

Sample 0x167fe0(0): kern (name /boot/pvmlinux2-syms, 0xffffffff80100000-0xffffffff80600000) ...

Rosimildo's patched SVM code works correctly and provides approximately the same kernel profile under HVM as we get when we run the application under a kernel natively (where we've run two simple applications: kernbench and stress vm).

Thanks for the update. It is good to confirm that XenOprofile is getting the samples right.

Quoted 5 lines

We'd like to get to a point where the SVM and VT versions both work, but at the moment, we don't have the expertise to create the VT fixes, although Rosimildo has created some patches for test purposes.
--

Ah, OK. So the problem is specific to x64 and VT processors. It seems you have XenOprofile with passive domain running fine for 32 bit fully virtualized guests (both Intel and AMD) and for x64 AMD, right?
I am not sure if I will be able to fix this
since I don't have much expertise on VT.
It would be nice if someone at Intel could take a look at this... Xiaowei, any suggestion of who can help on getting XenOprofile passive domain support working for fully virtualized guests on Intel X64?

Thanks

Renato

Quoted 6 lines

Ray Bryant
AMD Performance Labs Austin, Tx
512-602-0038 (o) 512-507-7807 (c)