kprobes: Support probing module __exit function
Subsystems (2)
PATCH 4/7 kprobes: Support probing module __exit function
Allows kprobes to probe __exit routine.
This adds flags member to struct kprobe. When module is freed(kprobes hooks module_notifier to get this event), kprobes which probe the functions in that module are set to "Gone" flag to the flags member. These "Gone" probes are never be enabled.
Users can check the GONE flag through debugfs.
This also removes mod_refcounted, because we couldn't free a module if kprobe incremented the refcount of that module.
--- Documentation/kprobes.txt | 5 + include/linux/kprobes.h | 14 +++- kernel/kprobes.c | 140 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 123 insertions(+), 36 deletions(-)
include/linux/kprobes.h +11 -3
@@ -69,9 +69,6 @@ struct kprobe {/* list of kprobes for multi-handler support */ struct list_head list; -/* Indicates that the corresponding module has been ref counted */ -unsigned int mod_refcounted; -/*count the number of times this probe was temporarily disarmed */ unsigned long nmissed;
@@ -103,8 +100,19 @@ struct kprobe {/* copy of the original instruction */ struct arch_specific_insn ainsn; + +/* Indicates various status flags */ +u32 flags; }; +/* Kprobe status flags */ +#define KPROBE_FLAG_GONE 1/* breakpoint has already gone */ + +static inline int kprobe_gone (struct kprobe *p) +{ +return p->flags &KPROBE_FLAG_GONE ; +} +/* * Special probe type that uses setjmp-longjmp type tricks to resume * execution at a specified entry with a matching prototype corresponding
kernel/kprobes.c +108 -32
249 lines not on this page · raw message
Documentation/kprobes.txt +4 -1
@@ -497,7 +497,10 @@ The first column provides the kernel add The second column identifies the type of probe (k - kprobe, r - kretprobe and j - jprobe), while the third column specifies the symbol+offset of the probe. If the probed function belongs to a module, the module name -is also specified. +is also specified. Following columns show probe status. If the probe is on +a virtual address that is no longer valid (module init sections, module +virtual addresses that correspond to modules that've been unloaded), +such probes are marked with [GONE]. /debug/kprobes/enabled: Turn kprobes ON/OFF
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America) Inc. Software Solutions Division e-mail: [email protected]
Quoted 11 lines · Masami Hiramatsu
Allows kprobes to probe
__exitroutine.
This adds flags member to struct kprobe. When module isfreed(kprobes hooks module_notifier to get this event), kprobes which probe the functions in that module are set to "Gone" flag to the flags member. These "Gone" probes are never be enabled.
Users can check the GONE flag through debugfs.This also removes
mod_refcounted, because we couldn't free a module if kprobe incremented the refcount of that module.Signed-off-by Masami Hiramatsu <[email protected]>
Quoted 16 lines · On Tue, 11 Nov 2008 15:56:58 -0500 Masami Hiramatsu <[email protected]> wrote:
(quoted diff) +2
-3@@ -69,9 +69,6 @@ struct kprobe { /* list of kprobes for multi-handler support */ struct list_head list; - /* Indicates that the corresponding module has been ref counted */ - unsigned int mod_refcounted; - /*count the number of times this probe was temporarily disarmed */ unsigned long nmissed;@@ -103,8 +100,19 @@ struct kprobe { /* copy of the original instruction */ struct arch_specific_insn ainsn; + + /* Indicates various status flags */
Review struct kprobe { · line 114
Quoted 10 lines
(quoted diff) +8
-0+ u32 flags; }; +/* Kprobe status flags */ +#define KPROBE_FLAG_GONE 1 /* breakpoint has already gone */ + +static inline int kprobe_gone(struct kprobe *p) +{ + return p->flags & KPROBE_FLAG_GONE; +}
If we're not going to use atomic bitops on kprobe.flags then modifications to that member will require that the caller hold a lock. The comment above that member should describe its locking protocol. It seems that it is kprobe_mutex, so...
include/linux/kprobes.h renamed from include/linux/kprobes.h~kprobes-support-probing-module-__exit-function-fix +1 -1
@@ -101,7 +101,7 @@ struct kprobe {/* copy of the original instruction */ struct arch_specific_insn ainsn; -/* Indicates various status flags */ +/* Indicates various status flags. Protected by kprobe_mutex. */ u32 flags; };
_
yes?
Quoted 49 lines · Andrew Morton
Quoted 16 lines · On Tue, 11 Nov 2008 15:56:58 -0500 Masami Hiramatsu <[email protected]> wrote:
(quoted diff) +2
-3@@ -69,9 +69,6 @@ struct kprobe { /* list of kprobes for multi-handler support */ struct list_head list; - /* Indicates that the corresponding module has been ref counted */ - unsigned int mod_refcounted; - /*count the number of times this probe was temporarily disarmed */ unsigned long nmissed;@@ -103,8 +100,19 @@ struct kprobe { /* copy of the original instruction */ struct arch_specific_insn ainsn; + + /* Indicates various status flags */Review struct kprobe { · line 114
Quoted 10 lines
(quoted diff) +8
-0+ u32 flags; }; +/* Kprobe status flags */ +#define KPROBE_FLAG_GONE 1 /* breakpoint has already gone */ + +static inline int kprobe_gone(struct kprobe *p) +{ + return p->flags & KPROBE_FLAG_GONE; +}If we're not going to use atomic bitops on kprobe.flags then modifications to that member will require that the caller hold a lock. The comment above that member should describe its locking protocol. It seems that it is
kprobe_mutex, so...include/linux/kprobes.h renamed from include/linux/kprobes.h~kprobes-support-probing-module-__exit-function-fix +1
-1@@ -101,7 +101,7 @@ struct kprobe {/* copy of the original instruction */ struct arch_specific_insn ainsn; -/* Indicates various status flags */ +/* Indicates various status flags. Protected by kprobe_mutex. */ u32 flags; };_
Quoted 1 line
yes?
Right, setting and resetting is done under the kprobe_mutex.
Ananth