To list all active probes in the system
Subsystems (3)
RFC PATCH 1/1 To list all active probes in the system
Hi folks
I have developed a patch, that lists all active probes in the
system. I have done this through /proc interface. Currently list is available under /proc/kprobes/list. Any suggestions for better place and name??
My patch scans through kprobe_table[],lists out all the probes, in an
order it finds them. It also takes care of aggregate handlers. Type of the probe is recognised by the kind of pre_handler it has. I have assigned letter for each probe, like "k" for kprobes, "j" for jprobes, "r" for kretprobes. Along with type of the probe,it also lists the address of the instruction,its symbolic name(function name + offset) and the module name.
Output of /proc/kprobes/list looks like this
======================
[root@llm31 a]# cat /proc/kprobes/list
c0000000000c0720 r .sys_write+0x0 c0000000000c0720 k .sys_write+0x0 c00000000004c550 k .do_fork+0x0 c00000000004c550 k .do_fork+0x0 c00000000004c550 j .do_fork+0x0 c0000000000bfed4 r .vfs_read+0x0 c0000000000bddb4 r .sys_open+0x0 c0000000000c0694 r .sys_read+0x0 c0000000000c0694 k .sys_read+0x0 c00000000004c554 k .do_fork+0x4 d0000000000781b0 k .autofs4_dentry_release+0x0 autofs4 c0000000000275d0 k kretprobe_trampoline+0x0 c0000000000bfd18 k .vfs_write+0x0
====================================
Please let me know your comments on this.
fs/proc/root.c | 4 ++ include/linux/kprobes.h | 7 +++ kernel/kprobes.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+)
kernel/kprobes.c +87 -0
@@ -39,6 +39,7 @@#include <linux/moduleloader.h> #include <linux/kallsyms.h> #include <linux/freezer.h> +#include <linux/seq_file.h> #include <asm-generic/sections.h> #include <asm/cacheflush.h> #include <asm/errno.h>
@@ -815,6 +816,92 @@ static int __init init_kprobes(void)return err; } +static void __kprobes report_probe (struct seq_file *pi,struct kprobe *p, +const char *sym,int offset,char *modname) +{ +char *kprobe_type; + +if (p->pre_handler == pre_handler_kretprobe) + kprobe_type ="r" ; +else if (p->pre_handler == setjmp_pre_handler) + kprobe_type ="j" ; +else + kprobe_type ="k" ; +if (sym) +seq_printf (pi,"%p %s %s+0x%x %s\n" , p->addr, kprobe_type, + sym, offset, (modname ? modname :" " )); +else +seq_printf (pi,"%p %s %p\n" , p->addr, kprobe_type, p->addr); +} + +void __kprobes *kprobe_seq_start (struct seq_file *f,loff_t *pos) +{ +return (*pos <KPROBE_TABLE_SIZE ) ? pos :NULL ; +} + +void __kprobes *kprobe_seq_next (struct seq_file *f,void *v,loff_t *pos) +{ + (*pos)++; +if (*pos >=KPROBE_TABLE_SIZE ) +return NULL ; +return pos; +} + +void __kprobes kprobe_seq_stop (struct seq_file *f,void *v) +{ +/* Nothing to do */ +} + +int __kprobes show_kprobe_addr (struct seq_file *pi,void *v) +{ +struct hlist_head *head; +struct hlist_node *node; +struct kprobe *p, *kp; +unsigned int i = *(loff_t *) v; +unsigned long size, offset =0 ; +char *modname, namebuf[128 ]; +const char *sym =NULL ; + + head = &kprobe_table[i]; +preempt_disable (); +hlist_for_each_entry_rcu (p, node, head, hlist) { + sym =kallsyms_lookup ((unsigned long )p->addr, &size, + &offset, &modname, namebuf); +if (p->pre_handler == aggr_pre_handler) { +list_for_each_entry_rcu (kp, &p->list, list) +report_probe (pi, kp, sym, offset, modname); + }else +report_probe (pi, p, sym, offset, modname); + } +preempt_enable (); +return 0 ; +} + +struct seq_operations kprobes_seq_ops = { + .start = kprobe_seq_start, + .next = kprobe_seq_next, + .stop = kprobe_seq_stop, + .show = show_kprobe_addr +}; + +static int __kprobes kprobes_open (struct inode *inode,struct file *filp) +{ +return seq_open (filp, &kprobes_seq_ops); +} + +static struct file_operations proc_kprobes_operations = { + .open = kprobes_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + +void __kprobes proc_kprobe_init (void ) +{ +proc_mkdir ("kprobes" ,NULL ); +create_seq_entry ("kprobes/list" ,0 , &proc_kprobes_operations); +} +__initcall (init_kprobes);EXPORT_SYMBOL_GPL (register_kprobe);
include/linux/kprobes.h +7 -0
@@ -36,6 +36,7 @@#include <linux/spinlock.h> #include <linux/rcupdate.h> #include <linux/mutex.h> +#include <linux/proc_fs.h> #ifdef CONFIG_KPROBES #include <asm/kprobes.h>
@@ -167,6 +168,8 @@ extern void show_registers(struct pt_regextern kprobe_opcode_t *get_insn_slot (void );extern void free_insn_slot (kprobe_opcode_t *slot,int dirty);extern void kprobes_inc_nmissed_count (struct kprobe *p); +extern void create_seq_entry (char *name,mode_t mode, +const struct file_operations *f);/* Get the kprobe at this addr (if any) - called with preemption disabled */ struct kprobe *get_kprobe (void *addr);
@@ -203,6 +206,7 @@ struct kretprobe_instance *get_free_rp_ivoid add_rp_inst (struct kretprobe_instance *ri);void kprobe_flush_task (struct task_struct *tk);void recycle_rp_inst (struct kretprobe_instance *ri,struct hlist_head *head); +void proc_kprobe_init (void );#else /* CONFIG_KPROBES */ #define __kprobes/**/
@@ -240,5 +244,8 @@ static inline void unregister_kretprobe(static inline void kprobe_flush_task (struct task_struct *tk) { } +static inline void proc_kprobe_init (void ) +{ +}#endif /* CONFIG_KPROBES */ #endif /* _LINUX_KPROBES_H */
fs/proc/root.c +4 -0
@@ -18,6 +18,7 @@#include <linux/bitops.h> #include <linux/smp_lock.h> #include <linux/mount.h> +#include <linux/kprobes.h> #include "internal.h"
@@ -85,6 +86,9 @@ void __init proc_root_init(void)/* just give it a mountpoint */ proc_mkdir ("openprom" ,NULL );#endif +#ifdef CONFIG_KPROBES +proc_kprobe_init (); +#endif proc_tty_init ();#ifdef CONFIG_PROC_DEVICETREE proc_device_tree_init ();
Quoted 6 lines · Srinivasa Ds
Hi folks
I have developed a patch, that lists all active probes in the
system. I have done this through /proc interface. Currently list is available under/proc/kprobes/list. Any suggestions for better place and name??
/debug/kprobes/list? :)
Quoted 2 lines · On Tue, 06 Feb 2007 15:25:35 +0530 Srinivasa Ds <[email protected]> wrote:
I have developed a patch, that lists all active probes in the
system.
userspace added the probes, so userspace should know where they all are?
Quoted 6 lines · Andrew Morton
Quoted 2 lines · On Tue, 06 Feb 2007 15:25:35 +0530 Srinivasa Ds <[email protected]> wrote:
I have developed a patch, that lists all active probes in the
system.userspace added the probes, so userspace should know where they all are?
Irrespective of the number of users/modules that use kprobes, this is one place where you can get all the info.
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Srinivasa Ds
Hi folks
I have developed a patch, that lists all active probes in the
system. I have done this through /proc interface. Currently list is available under/proc/kprobes/list. Any suggestions for better place and name??/debug/kprobes/list? :)
Good Idea, I will update my patch to use debugfs.
Quoted 11 lines · Srinivasa Ds
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Srinivasa Ds
Hi folks
I have developed a patch, that lists all active probes in the
system. I have done this through /proc interface. Currently list is available under/proc/kprobes/list. Any suggestions for better place and name??/debug/kprobes/list? :)
Good Idea, I will update my patch to use debugfs.
Patch that uses debugfs.
fs/debugfs/inode.c | 4 ++ include/linux/kprobes.h | 4 ++ kernel/kprobes.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+)
fs/debugfs/inode.c +4 -0
@@ -25,6 +25,7 @@#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/fsnotify.h> +#include <linux/kprobes.h> #define DEBUGFS_MAGIC 0x64626720
@@ -320,6 +321,9 @@ static int __init debugfs_init(void) retval =register_filesystem (&debug_fs_type);if (retval)subsystem_unregister (&debug_subsys); +#ifdef CONFIG_KPROBES +debugfs_kprobe_init (); +#endif return retval; }
kernel/kprobes.c +92 -0
104 lines not on this page · raw message
include/linux/kprobes.h +4 -0
@@ -203,6 +203,7 @@ struct kretprobe_instance *get_free_rp_ivoid add_rp_inst (struct kretprobe_instance *ri);void kprobe_flush_task (struct task_struct *tk);void recycle_rp_inst (struct kretprobe_instance *ri,struct hlist_head *head); +void debugfs_kprobe_init (void );#else /* CONFIG_KPROBES */ #define __kprobes/**/
@@ -240,5 +241,8 @@ static inline void unregister_kretprobe(static inline void kprobe_flush_task (struct task_struct *tk) { } +static inline void proc_kprobe_init (void ) +{ +}#endif /* CONFIG_KPROBES */ #endif /* _LINUX_KPROBES_H */
Hi,
Comments below,
Quoted 39 lines · Srinivasa Ds
Quoted 11 lines · Srinivasa Ds
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Srinivasa Ds
Hi folks
I have developed a patch, that lists all active probes in the
system. I have done this through /proc interface. Currently list is available under/proc/kprobes/list. Any suggestions for better place and name??/debug/kprobes/list? :)
Good Idea, I will update my patch to use debugfs.
Patch that uses debugfs.
Signed-off-by Srinivasa DS <[email protected]>fs/debugfs/inode.c | 4 ++ include/linux/kprobes.h | 4 ++ kernel/kprobes.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+)Index:
linux-2.6.20/fs/debugfs/inode.c
===================================================================fs/debugfs/inode.c +1
-0@@ -25,6 +25,7 @@#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/fsnotify.h> +#include <linux/kprobes.h> #define DEBUGFS_MAGIC 0x64626720
fs/debugfs/inode.c static int __init debugfs_init(void) · line 326
Quoted 6 lines
fs/debugfs/inode.c +3
-0@@ -320,6 +321,9 @@ static int __init debugfs_init(void) retval =register_filesystem (&debug_fs_type);if (retval)subsystem_unregister (&debug_subsys); +#ifdef CONFIG_KPROBES +debugfs_kprobe_init (); +#endif
The ifdef here could be skipped if ....
Quoted 3 lines
fs/debugfs/inode.c +0
-0return retval; }
[... snip ...]
Quoted 13 lines
Index:
linux-2.6.20/include/linux/kprobes.h
===================================================================include/linux/kprobes.h +1
-0@@ -203,6 +203,7 @@ struct kretprobe_instance *get_free_rp_ivoid add_rp_inst (struct kretprobe_instance *ri);void kprobe_flush_task (struct task_struct *tk);void recycle_rp_inst (struct kretprobe_instance *ri,struct hlist_head *head); +void debugfs_kprobe_init (void );#else /* CONFIG_KPROBES */ #define __kprobes/**/
include/linux/kprobes.h static inline void unregister_kretprobe( · line 246
Quoted 6 lines
include/linux/kprobes.h +3
-0@@ -240,5 +241,8 @@ static inline void unregister_kretprobe(static inline void kprobe_flush_task (struct task_struct *tk) { } +static inline void proc_kprobe_init (void ) +{ +}
... this was renamed to debugfs_kprobe_init() instead -which was your first intention I suppose ;)-
Regards,
Frederik
Quoted 7 lines · Andrew Morton
Quoted 2 lines · On Tue, 06 Feb 2007 15:25:35 +0530 Srinivasa Ds <[email protected]> wrote:
I have developed a patch, that lists all active probes in
the system.userspace added the probes, so userspace should know where they all are?
it's a kernel resource that user-space can influence so it's sensible to have some sort of visibility to them. For example if the userspace that has the 'info' crashes then another piece of user-space might want to recreate that info, to zap the probes.
also, this resource could leak, etc.
Ingo
Quoted 77 lines · Frederik Deweerdt
Hi,
Comments below,
Quoted 39 lines · Srinivasa Ds
Quoted 11 lines · Srinivasa Ds
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Srinivasa Ds
Hi folks
I have developed a patch, that lists all active probes in the
system. I have done this through /proc interface. Currently list is available under/proc/kprobes/list. Any suggestions for better place and name??/debug/kprobes/list? :)
Good Idea, I will update my patch to use debugfs.
Patch that uses debugfs.
Signed-off-by Srinivasa DS <[email protected]>fs/debugfs/inode.c | 4 ++ include/linux/kprobes.h | 4 ++ kernel/kprobes.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+)Index:
linux-2.6.20/fs/debugfs/inode.c
===================================================================fs/debugfs/inode.c +1
-0@@ -25,6 +25,7 @@#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/fsnotify.h> +#include <linux/kprobes.h> #define DEBUGFS_MAGIC 0x64626720fs/debugfs/inode.c static int __init debugfs_init(void) · line 326
Quoted 6 lines
fs/debugfs/inode.c +3
-0@@ -320,6 +321,9 @@ static int __init debugfs_init(void) retval =register_filesystem (&debug_fs_type);if (retval)subsystem_unregister (&debug_subsys); +#ifdef CONFIG_KPROBES +debugfs_kprobe_init (); +#endif The ifdef here could be skipped if ....
Quoted 3 lines
fs/debugfs/inode.c +0
-0return retval; }[... snip ...]
Quoted 13 lines
Index:
linux-2.6.20/include/linux/kprobes.h
===================================================================include/linux/kprobes.h +1
-0@@ -203,6 +203,7 @@ struct kretprobe_instance *get_free_rp_ivoid add_rp_inst (struct kretprobe_instance *ri);void kprobe_flush_task (struct task_struct *tk);void recycle_rp_inst (struct kretprobe_instance *ri,struct hlist_head *head); +void debugfs_kprobe_init (void );#else /* CONFIG_KPROBES */ #define __kprobes/**/ include/linux/kprobes.h static inline void unregister_kretprobe( · line 246
Quoted 6 lines
include/linux/kprobes.h +3
-0@@ -240,5 +241,8 @@ static inline void unregister_kretprobe(static inline void kprobe_flush_task (struct task_struct *tk) { } +static inline void proc_kprobe_init (void ) +{ +}... this was renamed to
debugfs_kprobe_init()instead -which was your first intention I suppose ;)-
Quoted 2 lines
Regards,
Frederik
Oh, Iam sorry, It should be renamed to debugfs_kprobe_init().
So finally
My patch lists all active probes in the system by scanning through
kprobe_table[]. It takes care of aggregate handlers and prints the type of the probe.
Letter "k" for kprobes, "j" for jprobes, "r" for kretprobes. It also lists address of the instruction,its symbolic name(function name + offset) and the module name. One can access this file through /sys/kernel/debug/kprobes/list.
Output looks like this
=====================
llm40:~/a # cat /sys/kernel/debug/kprobes/list
c0169ae3 r sys_read+0x0 c0169ae3 k sys_read+0x0 c01694c8 k vfs_write+0x0 c0167d20 r sys_open+0x0 f8e658a6 k reiserfs_delete_inode+0x0 reiserfs c0120f4a k do_fork+0x0 c0120f4a j do_fork+0x0 c0169b4a r sys_write+0x0 c0169b4a k sys_write+0x0 c0169622 r vfs_read+0x0
=================================
fs/debugfs/inode.c | 2 + include/linux/kprobes.h | 4 ++ kernel/kprobes.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+)
fs/debugfs/inode.c +2 -0
@@ -25,6 +25,7 @@#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/fsnotify.h> +#include <linux/kprobes.h> #define DEBUGFS_MAGIC 0x64626720
@@ -320,6 +321,7 @@ static int __init debugfs_init(void) retval =register_filesystem (&debug_fs_type);if (retval)subsystem_unregister (&debug_subsys); +debugfs_kprobe_init ();return retval; }
kernel/kprobes.c +92 -0
104 lines not on this page · raw message
include/linux/kprobes.h +4 -0
@@ -203,6 +203,7 @@ struct kretprobe_instance *get_free_rp_ivoid add_rp_inst (struct kretprobe_instance *ri);void kprobe_flush_task (struct task_struct *tk);void recycle_rp_inst (struct kretprobe_instance *ri,struct hlist_head *head); +void debugfs_kprobe_init (void );#else /* CONFIG_KPROBES */ #define __kprobes/**/
@@ -240,5 +241,8 @@ static inline void unregister_kretprobe(static inline void kprobe_flush_task (struct task_struct *tk) { } +static inline void debugfs_kprobe_init (void ) +{ +}#endif /* CONFIG_KPROBES */ #endif /* _LINUX_KPROBES_H */
Quoted 11 lines · On Wed, 07 Feb 2007 10:55:23 +0530 Srinivasa Ds <[email protected]> wrote:
fs/debugfs/inode.c +1
-0@@ -25,6 +25,7 @@#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/fsnotify.h> +#include <linux/kprobes.h> #define DEBUGFS_MAGIC 0x64626720
fs/debugfs/inode.c static int __init debugfs_init(void) · line 326
Quoted 6 lines
fs/debugfs/inode.c +1
-0@@ -320,6 +321,7 @@ static int __init debugfs_init(void) retval =register_filesystem (&debug_fs_type);if (retval)subsystem_unregister (&debug_subsys); +debugfs_kprobe_init ();return retval; }
eww. Didn't it feel bad when you did that?
As this module has a dependency upon debugfs, I'd have thought the approproate way of expressing that would be to run debugfs_kprobe_init() at a lower initcall priority than debugfs_init()
fs/debugfs/inode.c static int __init debugfs_init(void)
Quoted 11 lines
fs/debugfs/inode.c +10
-0+void __kprobes debugfs_kprobe_init (void ) +{ +struct dentry *dir; + + dir =debugfs_create_dir ("kprobes" ,NULL ); +if (dir ==NULL ) +return ; +debugfs_create_file ("list" ,0444 , dir ,0 , &proc_kprobes_operations); +} +__initcall (init_kprobes);
debugfs_init() already runs at core_initcall level, presumably so that debugfs clients can use plain old module_init().
fs/debugfs/inode.c
Quoted 4 lines
fs/debugfs/inode.c +3
-0+static inline void debugfs_kprobe_init (void ) +{ +}
In which case we don't need this.
Re: [RFC] [PATCH] To list all active probes in the system---Take-2
Quoted 31 lines · Andrew Morton
fs/debugfs/inode.c line 30
Quoted 9 lines · On Wed, 07 Feb 2007 10:55:23 +0530 Srinivasa Ds <[email protected]> wrote:
fs/debugfs/inode.c +1
-0@@ -25,6 +25,7 @@if (retval)subsystem_unregister (&debug_subsys); +debugfs_kprobe_init ();return retval; }eww. Didn't it feel bad when you did that?
As this module has a dependency upon debugfs, I'd have thought the approproate way of expressing that would be to run
debugfs_kprobe_init()at a lower initcall priority thandebugfs_init()fs/debugfs/inode.c
Quoted 7 lines
fs/debugfs/inode.c +6
-0+ +if (dir ==NULL ) +return ; +debugfs_create_file ("list" ,0444 , dir ,0 , &proc_kprobes_operations); +} +__initcall (init_kprobes);
debugfs_init()already runs atcore_initcalllevel, presumably so that debugfs clients can use plain oldmodule_init().
Quoted 5 lines
fs/debugfs/inode.c
Quoted 3 lines
fs/debugfs/inode.c +3
-0+static inline void debugfs_kprobe_init (void ) +{ +}In which case we don't need this.
Updating the patch according to Andrew's comment.
This patch lists all active probes in the system by scanning through
kprobe_table[]. It takes care of aggregate handlers and prints the type of the probe.
Letter "k" for kprobes, "j" for jprobes, "r" for kretprobes. It also lists address of the instruction,its symbolic name(function name + offset) and the module name. One can access this file through /sys/kernel/debug/kprobes/list.
Output looks like this
=====================
llm40:~/a # cat /sys/kernel/debug/kprobes/list
c0169ae3 r sys_read+0x0 c0169ae3 k sys_read+0x0 c01694c8 k vfs_write+0x0 c0167d20 r sys_open+0x0 f8e658a6 k reiserfs_delete_inode+0x0 reiserfs c0120f4a k do_fork+0x0 c0120f4a j do_fork+0x0 c0169b4a r sys_write+0x0 c0169b4a k sys_write+0x0 c0169622 r vfs_read+0x0
=================================
kprobes.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+)
kernel/kprobes.c +104 -0
@@ -39,6 +39,8 @@#include <linux/moduleloader.h> #include <linux/kallsyms.h> #include <linux/freezer.h> +#include <linux/seq_file.h> +#include <linux/debugfs.h> #include <asm-generic/sections.h> #include <asm/cacheflush.h> #include <asm/errno.h>
@@ -815,6 +817,108 @@ static int __init init_kprobes(void)return err; } +#ifdef CONFIG_DEBUG_FS +static void __kprobes report_probe (struct seq_file *pi,struct kprobe *p, +const char *sym,int offset,char *modname) +{ +char *kprobe_type; + +if (p->pre_handler == pre_handler_kretprobe) + kprobe_type ="r" ; +else if (p->pre_handler == setjmp_pre_handler) + kprobe_type ="j" ; +else + kprobe_type ="k" ; +if (sym) +seq_printf (pi,"%p %s %s+0x%x %s\n" , p->addr, kprobe_type, + sym, offset, (modname ? modname :" " )); +else +seq_printf (pi,"%p %s %p\n" , p->addr, kprobe_type, p->addr); +} + +void __kprobes *kprobe_seq_start (struct seq_file *f,loff_t *pos) +{ +return (*pos <KPROBE_TABLE_SIZE ) ? pos :NULL ; +} + +void __kprobes *kprobe_seq_next (struct seq_file *f,void *v,loff_t *pos) +{ + (*pos)++; +if (*pos >=KPROBE_TABLE_SIZE ) +return NULL ; +return pos; +} + +void __kprobes kprobe_seq_stop (struct seq_file *f,void *v) +{ +/* Nothing to do */ +} + +int __kprobes show_kprobe_addr (struct seq_file *pi,void *v) +{ +struct hlist_head *head; +struct hlist_node *node; +struct kprobe *p, *kp; +const char *sym =NULL ; +unsigned int i = *(loff_t *) v; +unsigned long size, offset =0 ; +char *modname, namebuf[128 ]; + + head = &kprobe_table[i]; +preempt_disable (); +hlist_for_each_entry_rcu (p, node, head, hlist) { + sym =kallsyms_lookup ((unsigned long )p->addr, &size, + &offset, &modname, namebuf); +if (p->pre_handler == aggr_pre_handler) { +list_for_each_entry_rcu (kp, &p->list, list) +report_probe (pi, kp, sym, offset, modname); + }else +report_probe (pi, p, sym, offset, modname); + } +preempt_enable (); +return 0 ; +} + +struct seq_operations kprobes_seq_ops = { + .start = kprobe_seq_start, + .next = kprobe_seq_next, + .stop = kprobe_seq_stop, + .show = show_kprobe_addr +}; + +static int __kprobes kprobes_open (struct inode *inode,struct file *filp) +{ +return seq_open (filp, &kprobes_seq_ops); +} + +static struct file_operations debugfs_kprobes_operations = { + .open = kprobes_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + +static int __kprobes debugfs_kprobe_init (void ) +{ +struct dentry *dir, *file; + + dir =debugfs_create_dir ("kprobes" ,NULL ); +if (!dir) +return -ENOMEM ; + + file =debugfs_create_file ("list" ,0444 , dir ,0 , + &debugfs_kprobes_operations); +if (!file) { +debugfs_remove (dir); +return -ENOMEM ; + } + +return 0 ; +} + +module_init (debugfs_kprobe_init); +#endif /* CONFIG_DEBUG_FS */ +__initcall (init_kprobes);EXPORT_SYMBOL_GPL (register_kprobe);
Re: [RFC] [PATCH] To list all active probes in the system---Take-2
Review
Quoted 4 lines · On Thu, 08 Feb 2007 17:16:15 +0530 Srinivasa Ds <[email protected]> wrote:
(quoted diff) +3
-0+module_init(debugfs_kprobe_init); +#endif /* CONFIG_DEBUG_FS */ + __initcall(init_kprobes);
I think you'll find this doesn't work when loaded as a module: we only support a single initcall per module. (Which might be a bit dumb of us - it's probably easy to fix and is an inconsistency between modular and built-in).
<looks>
Oh, kernel/kprobes.o can't be linked as a module. It looks like it could be though?
You have a little race: debugfs_kprobe_init() will be called before init_kprobes(). If someone were able to read from the debugfs files in that window (they probably can't as we don't support modular kprobes.ko) they'll crash the kernel. I'll switch debugfs_kprobe_init() to late_initcall to fix that.
There are quite a few things in there which could have static scope.
I'll apply this:
kernel/kprobes.c renamed from kernel/kprobes.c~kprobes-list-all-active-probes-in-the-system-tidy +7 -8
@@ -836,12 +836,12 @@ static void __kprobes report_probe(strucseq_printf (pi,"%p %s %p\n" , p->addr, kprobe_type, p->addr); } -void __kprobes *kprobe_seq_start (struct seq_file *f,loff_t *pos) +static void __kprobes *kprobe_seq_start (struct seq_file *f,loff_t *pos) {return (*pos <KPROBE_TABLE_SIZE ) ? pos :NULL ; } -void __kprobes *kprobe_seq_next (struct seq_file *f,void *v,loff_t *pos) +static void __kprobes *kprobe_seq_next (struct seq_file *f,void *v,loff_t *pos) { (*pos)++;if (*pos >=KPROBE_TABLE_SIZE )
@@ -849,12 +849,12 @@ void __kprobes *kprobe_seq_next(struct sreturn pos; } -void __kprobes kprobe_seq_stop (struct seq_file *f,void *v) +static void __kprobes kprobe_seq_stop (struct seq_file *f,void *v) {/* Nothing to do */ } -int __kprobes show_kprobe_addr (struct seq_file *pi,void *v) +static int __kprobes show_kprobe_addr (struct seq_file *pi,void *v) {struct hlist_head *head;struct hlist_node *node;
@@ -879,7 +879,7 @@ int __kprobes show_kprobe_addr(struct sereturn 0 ; } -struct seq_operations kprobes_seq_ops = { +static struct seq_operations kprobes_seq_ops = { .start = kprobe_seq_start, .next = kprobe_seq_next, .stop = kprobe_seq_stop,
@@ -916,10 +916,10 @@ static int __kprobes debugfs_kprobe_init return 0; } -module_init (debugfs_kprobe_init); +late_initcall (debugfs_kprobe_init);#endif /* CONFIG_DEBUG_FS */ -__initcall (init_kprobes); +module_init (init_kprobes);EXPORT_SYMBOL_GPL (register_kprobe);EXPORT_SYMBOL_GPL (unregister_kprobe);
@@ -928,4 +928,3 @@ EXPORT_SYMBOL_GPL(unregister_jprobe);EXPORT_SYMBOL_GPL (jprobe_return);EXPORT_SYMBOL_GPL (register_kretprobe);EXPORT_SYMBOL_GPL (unregister_kretprobe); -
_
Re: [RFC] [PATCH] To list all active probes in the system---Take-2
In reply to Srinivasa Dskernel/kprobes.c static int __init init_kprobes(void) · line 826
Quoted 1 line · On Thu, 08 Feb 2007 17:16:15 +0530 Srinivasa Ds <[email protected]> wrote:
kernel/kprobes.c +1
-0+if (p->pre_handler == pre_handler_kretprobe)
This breaks on sparc64:
kernel/kprobes.c: In function `report_probe':kernel/kprobes.c:826: error: `pre_handler_kretprobe' undeclared (first use in this function)
Re: [RFC] [PATCH] To list all active probes in the system---Take-2
Quoted 8 lines · Andrew Morton
Review
Quoted 1 line · On Thu, 08 Feb 2007 17:16:15 +0530 Srinivasa Ds <[email protected]> wrote:
(quoted diff) +1
-0+ if (p->pre_handler == pre_handler_kretprobe)This breaks on sparc64:
kernel/kprobes.c: In function `report_probe':kernel/kprobes.c:826: error: `pre_handler_kretprobe' undeclared (first use in this function)
Andrew,
Here is a patch to fix the issue, compile tested with crosstools. Sorry for the trouble.
Do you want a comprehensive patch that folds all the related changes into one?
Ananth
--
Fix kprobes compilation breakage on sparc64 caused due to kprobes-list-all-active-probes-in-the-system.patch
--- kernel/kprobes.c | 6 ++++++ 1 files changed, 6 insertions(+)
kernel/kprobes.c +6 -0
@@ -780,6 +780,12 @@ int __kprobes register_kretprobe(struct return -ENOSYS; } +static int __kprobes pre_handler_kretprobe (struct kprobe *p, +struct pt_regs *regs) +{ +return 0 ; +} +#endif /* ARCH_SUPPORTS_KRETPROBES */ void __kprobes unregister_kretprobe (struct kretprobe *rp)