public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [RFC] [PATCH] To make systemtap work on 2.6.24-rc4-mm1
@ 2007-12-11  9:41 Srinivasa Ds
  2007-12-11 15:05 ` Frank Ch. Eigler
  0 siblings, 1 reply; 4+ messages in thread
From: Srinivasa Ds @ 2007-12-11  9:41 UTC (permalink / raw)
  To: SystemTAP


I was testing Masami's kprobes patch on x86_64. I found that some 
changes in vfs and Roland's fix (those are present in -mm1) have made
systemtap not to work on -mm1.
===========================================
/home/systemtap/tmp/stap_testing_200712110755/install/share/systemtap/runtime/regs.c:37: error: 'struct pt_regs' has no member named 'rsp'
 _stp_print_regs
/home/systemtap/tmp/stap_testing_200712110755/install/share/systemtap/runtime/regs.c: In function '_stp_print_regs':
/home/systemtap/tmp/stap_testing_200712110755/install/share/systemtap/runtime/regs.c:87: error: 'struct pt_regs' has no member named 'rip'
/home/systemtap/tmp/stap_testing_200712110755/install/share/systemtap/runtime/regs.c:87: error: 'struct pt_regs' has no member named 'rsp'
==========================================

I have developed the patch, which fixes this issue. Since Roland's and
vfs patches may get pulled to rc tree from mm, this patch might be helpful
to people.


Please let me know your comments on this patch.

=======================================================

Signed-off-by: Srinivasa DS <srinivasa@in.ibm.com>

diff -Naurp src-orig/runtime/loc2c-runtime.h src/runtime/loc2c-runtime.h
--- src-orig/runtime/loc2c-runtime.h    2007-10-03 02:03:22.000000000 +0530
+++ src/runtime/loc2c-runtime.h 2007-12-11 13:44:55.000000000 +0530
@@ -104,14 +104,14 @@
 
 #elif defined __x86_64__
 
-#define dwarf_register_0(regs) regs->rax
-#define dwarf_register_1(regs) regs->rdx
-#define dwarf_register_2(regs) regs->rcx
-#define dwarf_register_3(regs) regs->rbx
-#define dwarf_register_4(regs) regs->rsi
-#define dwarf_register_5(regs) regs->rdi
-#define dwarf_register_6(regs) regs->rbp
-#define dwarf_register_7(regs) regs->rsp
+#define dwarf_register_0(regs) regs->ax
+#define dwarf_register_1(regs) regs->dx
+#define dwarf_register_2(regs) regs->cx
+#define dwarf_register_3(regs) regs->bx
+#define dwarf_register_4(regs) regs->si
+#define dwarf_register_5(regs) regs->di
+#define dwarf_register_6(regs) regs->bp
+#define dwarf_register_7(regs) regs->sp
 #define dwarf_register_8(regs) regs->r8
 #define dwarf_register_9(regs) regs->r9
 #define dwarf_register_10(regs)        regs->r10
diff -Naurp src-orig/runtime/procfs.c src/runtime/procfs.c
--- src-orig/runtime/procfs.c   2007-09-19 18:34:57.000000000 +0530
+++ src/runtime/procfs.c        2007-12-11 14:19:59.000000000 +0530
@@ -87,8 +87,8 @@ int _stp_mkdir_proc_module(void)
                                goto done;
                        }
                } else {
-                       _stp_proc_stap = PDE(nd.dentry->d_inode);
-                       path_release (&nd);
+                       _stp_proc_stap = PDE(nd.path.dentry->d_inode);
+                       path_put (&nd.path);
                }
 
                _stp_proc_root = proc_mkdir(THIS_MODULE->name, _stp_proc_stap);
diff -Naurp src-orig/runtime/regs.c src/runtime/regs.c
--- src-orig/runtime/regs.c     2007-07-04 22:35:00.000000000 +0530
+++ src/runtime/regs.c  2007-12-11 13:44:11.000000000 +0530
@@ -34,7 +34,7 @@
 unsigned long _stp_ret_addr (struct pt_regs *regs)
 {
 #ifdef __x86_64__
-       unsigned long *ra = (unsigned long *)regs->rsp;
+       unsigned long *ra = (unsigned long *)regs->sp;
        if (ra)
                return *ra;
        else
@@ -84,13 +84,13 @@ void _stp_print_regs(struct pt_regs * re
         unsigned int fsindex,gsindex;
         unsigned int ds,cs,es;
 
-        _stp_printf("RIP: %016lx\nRSP: %016lx  EFLAGS: %08lx\n", regs->rip, regs->rsp, regs->eflags);
+        _stp_printf("RIP: %016lx\nRSP: %016lx  EFLAGS: %08lx\n", regs->ip, regs->sp, regs->flags);
         _stp_printf("RAX: %016lx RBX: %016lx RCX: %016lx\n",
-               regs->rax, regs->rbx, regs->rcx);
+               regs->ax, regs->bx, regs->cx);
         _stp_printf("RDX: %016lx RSI: %016lx RDI: %016lx\n",
-               regs->rdx, regs->rsi, regs->rdi);
+               regs->dx, regs->si, regs->di);
         _stp_printf("RBP: %016lx R08: %016lx R09: %016lx\n",
-               regs->rbp, regs->r8, regs->r9);
+               regs->bp, regs->r8, regs->r9);
         _stp_printf("R10: %016lx R11: %016lx R12: %016lx\n",
                regs->r10, regs->r11, regs->r12);
         _stp_printf("R13: %016lx R14: %016lx R15: %016lx\n",
diff -Naurp src-orig/runtime/regs.h src/runtime/regs.h
--- src-orig/runtime/regs.h     2007-05-30 20:03:55.000000000 +0530
+++ src/runtime/regs.h  2007-12-11 13:51:04.000000000 +0530
@@ -14,8 +14,8 @@
 
 #ifdef __x86_64__
 
-#define REG_IP(regs) regs->rip
-#define REG_SP(regs) regs->rsp
+#define REG_IP(regs) regs->ip
+#define REG_SP(regs) regs->sp
 
 #elif defined (__i386__)
 

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

* Re: [RFC] [PATCH] To make systemtap work on 2.6.24-rc4-mm1
  2007-12-11  9:41 [RFC] [PATCH] To make systemtap work on 2.6.24-rc4-mm1 Srinivasa Ds
@ 2007-12-11 15:05 ` Frank Ch. Eigler
  2007-12-11 15:34   ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Ch. Eigler @ 2007-12-11 15:05 UTC (permalink / raw)
  To: Srinivasa Ds; +Cc: SystemTAP

Srinivasa Ds <srinivasa@in.ibm.com> writes:

> I was testing Masami's kprobes patch on x86_64. I found that some
> changes in vfs and Roland's fix (those are present in -mm1) have
> made systemtap not to work on -mm1. [...]  I have developed the
> patch, which fixes this issue. [...]

In order to retain backward compatibility with older kernels, the code
would need to have #if KERNEL_VERSION conditionals to retain the old
ones too.

- FChE

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

* Re: [RFC] [PATCH] To make systemtap work on 2.6.24-rc4-mm1
  2007-12-11 15:05 ` Frank Ch. Eigler
@ 2007-12-11 15:34   ` Masami Hiramatsu
  2008-01-17  6:56     ` [RFC] [PATCH] To make systemtap work on Peter Anvin's register renaming patch Srinivasa Ds
  0 siblings, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2007-12-11 15:34 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: Srinivasa Ds, SystemTAP

Hi Srinivasa,

Frank Ch. Eigler wrote:
> Srinivasa Ds <srinivasa@in.ibm.com> writes:
> 
>> I was testing Masami's kprobes patch on x86_64. I found that some
>> changes in vfs and Roland's fix (those are present in -mm1) have
>> made systemtap not to work on -mm1. [...]  I have developed the
>> patch, which fixes this issue. [...]
> 
> In order to retain backward compatibility with older kernels, the code
> would need to have #if KERNEL_VERSION conditionals to retain the old
> ones too.

That patch is for -mm tree, so we can't use KERNEL_VERSION.
Instead of that, I recommend using autoconf.

> 
> - FChE

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com, masami.hiramatsu.pt@hitachi.com

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

* Re: [RFC] [PATCH] To make systemtap work on Peter Anvin's register  renaming patch
  2007-12-11 15:34   ` Masami Hiramatsu
@ 2008-01-17  6:56     ` Srinivasa Ds
  0 siblings, 0 replies; 4+ messages in thread
From: Srinivasa Ds @ 2008-01-17  6:56 UTC (permalink / raw)
  To: Masami Hiramatsu; +Cc: Frank Ch. Eigler, SystemTAP

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

Masami Hiramatsu wrote:
>
> 
> That patch is for -mm tree, so we can't use KERNEL_VERSION.
> Instead of that, I recommend using autoconf.
> 

The below attached patch makes systemtap to work on Peter Anvin's register renaming patch for x86/x86_64 (which is currently present in -mm tree). 
The same patch is attached in bug#5549. http://sources.redhat.com/bugzilla/attachment.cgi?id=2182&action=view

Please let me know the comments on this.

Signed-off-by: Srinivasa DS <srinivasa@in.ibm.com>





[-- Attachment #2: reg_rename.patch --]
[-- Type: text/x-patch, Size: 8987 bytes --]

---
 buildrun.cxx                   |    3 +
 runtime/autoconf-nameidata.c   |    4 ++
 runtime/autoconf-x86-uniregs.c |    6 +++
 runtime/loc2c-runtime.h        |   32 ++++++++++++++++
 runtime/procfs.c               |    6 +++
 runtime/regs.c                 |   79 +++++++++++++++++++++++++++++++++++++++--
 runtime/regs.h                 |    5 ++
 runtime/stack-i386.c           |    4 ++
 8 files changed, 135 insertions(+), 4 deletions(-)

Index: src/buildrun.cxx
===================================================================
--- src.orig/buildrun.cxx
+++ src/buildrun.cxx
@@ -88,6 +88,9 @@ compile_pass (systemtap_session& s)
   o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-constant-tsc.c, -DSTAPCONF_CONSTANT_TSC,)" << endl;
   o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-tsc-khz.c, -DSTAPCONF_TSC_KHZ,)" << endl;
   o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-ktime-get-real.c, -DSTAPCONF_KTIME_GET_REAL,)" << endl;
+  o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-x86-uniregs.c, -DSTAPCONF_X86_UNIREGS,)" << endl;
+
+  o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-nameidata.c, -DSTAPCONF_NAMEIDATA_CLEANUP,)" << endl;
 
   for (unsigned i=0; i<s.macros.size(); i++)
     o << "EXTRA_CFLAGS += -D " << lex_cast_qstring(s.macros[i]) << endl;
Index: src/runtime/autoconf-nameidata.c
===================================================================
--- /dev/null
+++ src/runtime/autoconf-nameidata.c
@@ -0,0 +1,4 @@
+#include <linux/namei.h>
+
+struct nameidata nd  __attribute__ ((unused)) = {.path={(void *)0}};
+
Index: src/runtime/autoconf-x86-uniregs.c
===================================================================
--- /dev/null
+++ src/runtime/autoconf-x86-uniregs.c
@@ -0,0 +1,6 @@
+#include <asm/ptrace.h>
+
+#if defined (__i386__) || defined (__x86_64__)
+struct pt_regs regs = {.ax = 0x0};
+#endif
+
Index: src/runtime/loc2c-runtime.h
===================================================================
--- src.orig/runtime/loc2c-runtime.h
+++ src/runtime/loc2c-runtime.h
@@ -75,7 +75,37 @@
     })
 
 
-#if defined __i386__
+#if defined (STAPCONF_X86_UNIREGS) && defined (__i386__)
+
+#define dwarf_register_0(regs)  regs->ax
+#define dwarf_register_1(regs)  regs->cx
+#define dwarf_register_2(regs)  regs->dx
+#define dwarf_register_3(regs)  regs->bx
+#define dwarf_register_4(regs)  ((long) &regs->sp)
+#define dwarf_register_5(regs)  regs->bp
+#define dwarf_register_6(regs)  regs->si
+#define dwarf_register_7(regs)  regs->di
+
+#elif defined (STAPCONF_X86_UNIREGS) && defined (__x86_64__)
+
+#define dwarf_register_0(regs)  regs->ax
+#define dwarf_register_1(regs)  regs->dx
+#define dwarf_register_2(regs)  regs->cx
+#define dwarf_register_3(regs)  regs->bx
+#define dwarf_register_4(regs)  regs->si
+#define dwarf_register_5(regs)  regs->di
+#define dwarf_register_6(regs)  regs->bp
+#define dwarf_register_7(regs)  regs->sp
+#define dwarf_register_8(regs)  regs->r8
+#define dwarf_register_9(regs)  regs->r9
+#define dwarf_register_10(regs) regs->r10
+#define dwarf_register_11(regs) regs->r11
+#define dwarf_register_12(regs) regs->r12
+#define dwarf_register_13(regs) regs->r13
+#define dwarf_register_14(regs) regs->r14
+#define dwarf_register_15(regs) regs->r15
+
+#elif defined __i386__
 
 /* The stack pointer is unlike other registers.  When a trap happens in
    kernel mode, it is not saved in the trap frame (struct pt_regs).
Index: src/runtime/procfs.c
===================================================================
--- src.orig/runtime/procfs.c
+++ src/runtime/procfs.c
@@ -87,8 +87,14 @@ int _stp_mkdir_proc_module(void)
 				goto done;
 			}
 		} else {
+                        #ifdef STAPCONF_NAMEIDATA_CLEANUP
+                        _stp_proc_stap = PDE(nd.path.dentry->d_inode);
+                        path_put (&nd.path);
+
+                        #else
 			_stp_proc_stap = PDE(nd.dentry->d_inode);
 			path_release (&nd);
+			#endif
 		}
 		
 		_stp_proc_root = proc_mkdir(THIS_MODULE->name, _stp_proc_stap);
Index: src/runtime/regs.c
===================================================================
--- src.orig/runtime/regs.c
+++ src/runtime/regs.c
@@ -33,7 +33,13 @@
  
 unsigned long _stp_ret_addr (struct pt_regs *regs)
 {
-#ifdef __x86_64__
+#if defined  (STAPCONF_X86_UNIREGS)  && (defined (__x86_64__) || defined (__i386__))
+         unsigned long *ra = (unsigned long *)regs->sp;
+          if (ra)
+                  return *ra;
+          else
+                  return 0;
+#elif defined  (__x86_64__)
 	unsigned long *ra = (unsigned long *)regs->rsp;
 	if (ra)
 		return *ra;
@@ -77,7 +83,76 @@ unsigned long _stp_ret_addr (struct pt_r
  */
 #define _stp_probe_addr_r(ri) (ri->rp->kp.addr)
 
-#ifdef  __x86_64__
+#if defined  (STAPCONF_X86_UNIREGS)  && defined (__x86_64__)
+
+void _stp_print_regs(struct pt_regs * regs)
+{
+        unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
+        unsigned int fsindex,gsindex;
+        unsigned int ds,cs,es;
+
+        _stp_printf("RIP: %016lx\nRSP: %016lx  EFLAGS: %08lx\n", regs->ip, regs->sp, regs->flags);
+        _stp_printf("RAX: %016lx RBX: %016lx RCX: %016lx\n",
+               regs->ax, regs->bx, regs->cx);
+        _stp_printf("RDX: %016lx RSI: %016lx RDI: %016lx\n",
+               regs->dx, regs->si, regs->di);
+        _stp_printf("RBP: %016lx R08: %016lx R09: %016lx\n",
+               regs->bp, regs->r8, regs->r9);
+        _stp_printf("R10: %016lx R11: %016lx R12: %016lx\n",
+               regs->r10, regs->r11, regs->r12);
+        _stp_printf("R13: %016lx R14: %016lx R15: %016lx\n",
+               regs->r13, regs->r14, regs->r15);
+
+        asm("movl %%ds,%0" : "=r" (ds));
+        asm("movl %%cs,%0" : "=r" (cs));
+        asm("movl %%es,%0" : "=r" (es));
+        asm("movl %%fs,%0" : "=r" (fsindex));
+        asm("movl %%gs,%0" : "=r" (gsindex));
+
+        rdmsrl(MSR_FS_BASE, fs);
+        rdmsrl(MSR_GS_BASE, gs);
+        rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
+
+        asm("movq %%cr0, %0": "=r" (cr0));
+        asm("movq %%cr2, %0": "=r" (cr2));
+        asm("movq %%cr3, %0": "=r" (cr3));
+        asm("movq %%cr4, %0": "=r" (cr4));
+
+        _stp_printf("FS:  %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
+               fs,fsindex,gs,gsindex,shadowgs);
+        _stp_printf("CS:  %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds, es, cr0);
+        _stp_printf("CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3, cr4);
+}
+
+ #elif defined (STAPCONF_X86_UNIREGS) && defined (__i386__)
+
+void _stp_print_regs(struct pt_regs * regs)
+{
+       unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
+
+       _stp_printf ("EIP: %08lx\n",regs->ip);
+       _stp_printf ("ESP: %08lx\n",regs->sp);
+       _stp_printf ("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
+                     regs->ax,regs->bx,regs->cx,regs->dx);
+       _stp_printf ("ESI: %08lx EDI: %08lx EBP: %08lx",
+                     regs->si, regs->di, regs->bp);
+       _stp_printf (" DS: %04x ES: %04x\n",
+                     0xffff & regs->ds,0xffff & regs->es);
+
+       __asm__("movl %%cr0, %0": "=r" (cr0));
+       __asm__("movl %%cr2, %0": "=r" (cr2));
+       __asm__("movl %%cr3, %0": "=r" (cr3));
+       /* This could fault if %cr4 does not exist */
+       __asm__("1: movl %%cr4, %0              \n"
+               "2:                             \n"
+               ".section __ex_table,\"a\"      \n"
+               ".long 1b,2b                    \n"
+               ".previous                      \n"
+               : "=r" (cr4): "0" (0));
+       _stp_printf ("CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n", cr0, cr2, cr3, cr4);
+}
+
+#elif defined  (__x86_64__)
 void _stp_print_regs(struct pt_regs * regs)
 {
         unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
Index: src/runtime/regs.h
===================================================================
--- src.orig/runtime/regs.h
+++ src/runtime/regs.h
@@ -11,8 +11,11 @@
 #ifndef _REGS_H_ /* -*- linux-c -*- */
 #define _REGS_H_
 
+#if defined  (STAPCONF_X86_UNIREGS) && (defined (__x86_64__) || defined (__i386__))
+#define REG_IP(regs) regs->ip
+#define REG_SP(regs) regs->sp
 
-#ifdef __x86_64__
+#elif defined  (__x86_64__)
 
 #define REG_IP(regs) regs->rip
 #define REG_SP(regs) regs->rsp
Index: src/runtime/stack-i386.c
===================================================================
--- src.orig/runtime/stack-i386.c
+++ src/runtime/stack-i386.c
@@ -21,7 +21,11 @@ static void __stp_stack_print (struct pt
 
 #ifdef	CONFIG_FRAME_POINTER
 	{
+                #ifdef STAPCONF_X86_UNIREGS
+                unsigned long ebp = regs->bp;
+                #elif
 		unsigned long ebp = regs->ebp;
+		#endif
 		
 		while (_stp_valid_stack_ptr(context, (unsigned long)ebp)) {
 			addr = *(unsigned long *)(ebp + 4);

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

end of thread, other threads:[~2008-01-17  6:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-11  9:41 [RFC] [PATCH] To make systemtap work on 2.6.24-rc4-mm1 Srinivasa Ds
2007-12-11 15:05 ` Frank Ch. Eigler
2007-12-11 15:34   ` Masami Hiramatsu
2008-01-17  6:56     ` [RFC] [PATCH] To make systemtap work on Peter Anvin's register renaming patch Srinivasa Ds

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 read-only IMAP folder(s) and NNTP newsgroup(s).