kprobes cleanups
cover kprobes cleanups
Hello,
This is a resend of my previous works on kprobes. All patches in this series are small cleanups and got acked by Masami. Please consider applying it.
Thanks.
---
Namhyung Kim (5):
kprobes: remove redundant address check
kprobes: verify jprobe entry point
kprobes: make functions static
kprobes: remove __dummy_buf
kprobes: add sparse context annotations
arch/x86/kernel/kprobes.c | 11 +++-------- kernel/kprobes.c | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-)
--
1.7.2.2
PATCH 1/5 kprobes: remove redundant address check
remove call to kernel_text_address() in register_jprobes() because it is called right after in register_kprobe().
--- kernel/kprobes.c | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-)
kernel/kprobes.c +5 -8
@@ -1343,14 +1343,11 @@ int __kprobes register_jprobes(struct jprobe **jps, int num) jp = jps[i]; addr =arch_deref_entry_point (jp->entry); -if (!kernel_text_address (addr)) - ret = -EINVAL ; -else { -/* Todo: Verify probepoint is a function entry point */ - jp->kp.pre_handler = setjmp_pre_handler; - jp->kp.break_handler = longjmp_break_handler; - ret =register_kprobe (&jp->kp); - } +/* Todo: Verify probepoint is a function entry point */ + jp->kp.pre_handler = setjmp_pre_handler; + jp->kp.break_handler = longjmp_break_handler; + ret =register_kprobe (&jp->kp); +if (ret <0 ) {if (i >0 )unregister_jprobes (jps, i);
Signature · 1 line
1.7.2.2
[tip:perf/core] kprobes: Remove redundant address check
Commit-ID: edbaadbe42b0b790618ec49d29626223529d8195 Gitweb: http://git.kernel.org/tip/edbaadbe42b0b790618ec49d29626223529d8195 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 15 Sep 2010 10:04:26 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 15 Sep 2010 10:44:00 +0200
kprobes: Remove redundant address check
Remove call to kernel_text_address() in register_jprobes() because it is called right after in register_kprobe().
LKML-Reference: <[email protected]>
--- kernel/kprobes.c | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-)
kernel/kprobes.c +5 -8
@@ -1343,14 +1343,11 @@ int __kprobes register_jprobes(struct jprobe **jps, int num) jp = jps[i]; addr =arch_deref_entry_point (jp->entry); -if (!kernel_text_address (addr)) - ret = -EINVAL ; -else { -/* Todo: Verify probepoint is a function entry point */ - jp->kp.pre_handler = setjmp_pre_handler; - jp->kp.break_handler = longjmp_break_handler; - ret =register_kprobe (&jp->kp); - } +/* Todo: Verify probepoint is a function entry point */ + jp->kp.pre_handler = setjmp_pre_handler; + jp->kp.break_handler = longjmp_break_handler; + ret =register_kprobe (&jp->kp); +if (ret <0 ) {if (i >0 )unregister_jprobes (jps, i);
PATCH 2/5 kprobes: verify jprobe entry point
In reply to Namhyung Kimverify jprobe's entry point is a function entry point using kallsyms' offset value.
--- kernel/kprobes.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
kernel/kprobes.c +9 -5
@@ -1339,14 +1339,18 @@ int __kprobes register_jprobes(struct jprobe **jps, int num)if (num <=0 )return -EINVAL ;for (i =0 ; i < num; i++) { -unsigned long addr; +unsigned long addr, offset; jp = jps[i]; addr =arch_deref_entry_point (jp->entry); -/* Todo: Verify probepoint is a function entry point */ - jp->kp.pre_handler = setjmp_pre_handler; - jp->kp.break_handler = longjmp_break_handler; - ret =register_kprobe (&jp->kp); +/* Verify probepoint is a function entry point */ +if (kallsyms_lookup_size_offset (addr,NULL , &offset) && + offset ==0 ) { + jp->kp.pre_handler = setjmp_pre_handler; + jp->kp.break_handler = longjmp_break_handler; + ret =register_kprobe (&jp->kp); + }else + ret = -EINVAL ;if (ret <0 ) {if (i >0 )
Signature · 1 line
1.7.2.2
[tip:perf/core] kprobes: Verify jprobe entry point
Commit-ID: 05662bdb64c746079de7ac4dc4fb4caa5e8e119f Gitweb: http://git.kernel.org/tip/05662bdb64c746079de7ac4dc4fb4caa5e8e119f Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 15 Sep 2010 10:04:27 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 15 Sep 2010 10:44:01 +0200
kprobes: Verify jprobe entry point
Verify jprobe's entry point is a function entry point using kallsyms' offset value.
LKML-Reference: <[email protected]>
--- kernel/kprobes.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
kernel/kprobes.c +9 -5
@@ -1339,14 +1339,18 @@ int __kprobes register_jprobes(struct jprobe **jps, int num)if (num <=0 )return -EINVAL ;for (i =0 ; i < num; i++) { -unsigned long addr; +unsigned long addr, offset; jp = jps[i]; addr =arch_deref_entry_point (jp->entry); -/* Todo: Verify probepoint is a function entry point */ - jp->kp.pre_handler = setjmp_pre_handler; - jp->kp.break_handler = longjmp_break_handler; - ret =register_kprobe (&jp->kp); +/* Verify probepoint is a function entry point */ +if (kallsyms_lookup_size_offset (addr,NULL , &offset) && + offset ==0 ) { + jp->kp.pre_handler = setjmp_pre_handler; + jp->kp.break_handler = longjmp_break_handler; + ret =register_kprobe (&jp->kp); + }else + ret = -EINVAL ;if (ret <0 ) {if (i >0 )
PATCH 3/5 kprobes: make functions static
In reply to Namhyung Kimmake following (internal) functions static to make sparse happier :-)
* get_optimized_kprobe: only called from static functions
* kretprobe_table_unlock: _lock function is static
* kprobes_optinsn_template_holder: never called but holding asm code
--- arch/x86/kernel/kprobes.c | 2 +- kernel/kprobes.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/kprobes.c +1 -1
@@ -1129,7 +1129,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, *(unsigned long *)addr = val; } -void __kprobes kprobes_optinsn_template_holder (void ) +static void __used __kprobes kprobes_optinsn_template_holder (void ) { asmvolatile ( ".global optprobe_template_entry\n"
kernel/kprobes.c +3 -2
@@ -399,7 +399,7 @@ static inline int kprobe_optready(struct kprobe *p)* Return an optimized kprobe whose optimizing code replaces * instructions including addr (exclude breakpoint). */ -struct kprobe *__kprobes get_optimized_kprobe (unsigned long addr) +static struct kprobe *__kprobes get_optimized_kprobe (unsigned long addr) {int i;struct kprobe *p =NULL ;
@@ -857,7 +857,8 @@ void __kprobes kretprobe_hash_unlock(struct task_struct *tsk,spin_unlock_irqrestore (hlist_lock, *flags); } -void __kprobes kretprobe_table_unlock (unsigned long hash,unsigned long *flags) +static void __kprobes kretprobe_table_unlock (unsigned long hash, +unsigned long *flags) {spinlock_t *hlist_lock =kretprobe_table_lock_ptr (hash);spin_unlock_irqrestore (hlist_lock, *flags);
Signature · 1 line
1.7.2.2
[tip:perf/core] kprobes: Make functions static
Commit-ID: 6376b2297502e72255b7eb2893c6044ad5a7b5f4 Gitweb: http://git.kernel.org/tip/6376b2297502e72255b7eb2893c6044ad5a7b5f4 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 15 Sep 2010 10:04:28 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 15 Sep 2010 10:44:01 +0200
kprobes: Make functions static
Make following (internal) functions static to make sparse happier :-)
* get_optimized_kprobe: only called from static functions
* kretprobe_table_unlock: _lock function is static
* kprobes_optinsn_template_holder: never called but holding asm code
LKML-Reference: <[email protected]>
--- arch/x86/kernel/kprobes.c | 2 +- kernel/kprobes.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/kprobes.c +1 -1
@@ -1129,7 +1129,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, *(unsigned long *)addr = val; } -void __kprobes kprobes_optinsn_template_holder (void ) +static void __used __kprobes kprobes_optinsn_template_holder (void ) { asmvolatile ( ".global optprobe_template_entry\n"
kernel/kprobes.c +3 -2
@@ -399,7 +399,7 @@ static inline int kprobe_optready(struct kprobe *p)* Return an optimized kprobe whose optimizing code replaces * instructions including addr (exclude breakpoint). */ -struct kprobe *__kprobes get_optimized_kprobe (unsigned long addr) +static struct kprobe *__kprobes get_optimized_kprobe (unsigned long addr) {int i;struct kprobe *p =NULL ;
@@ -857,7 +857,8 @@ void __kprobes kretprobe_hash_unlock(struct task_struct *tsk,spin_unlock_irqrestore (hlist_lock, *flags); } -void __kprobes kretprobe_table_unlock (unsigned long hash,unsigned long *flags) +static void __kprobes kretprobe_table_unlock (unsigned long hash, +unsigned long *flags) {spinlock_t *hlist_lock =kretprobe_table_lock_ptr (hash);spin_unlock_irqrestore (hlist_lock, *flags);
PATCH 4/5 kprobes: remove __dummy_buf
In reply to Namhyung Kimremove __dummy_buf which is needed for kallsyms_lookup only. use kallsysm_lookup_size_offset instead.
--- arch/x86/kernel/kprobes.c | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/kernel/kprobes.c +2 -7
@@ -230,9 +230,6 @@ static int recover_probed_instruction(kprobe_opcode_t *buf, unsigned long addr)return 0 ; } -/* Dummy buffers for kallsyms_lookup */ -static char __dummy_buf[KSYM_NAME_LEN ]; -/* Check if paddr is at an instruction boundary */ static int __kprobes can_probe (unsigned long paddr) {
@@ -241,7 +238,7 @@ static int __kprobes can_probe(unsigned long paddr)struct insn insn;kprobe_opcode_t buf[MAX_INSN_SIZE ]; -if (!kallsyms_lookup (paddr,NULL , &offset,NULL , __dummy_buf)) +if (!kallsyms_lookup_size_offset (paddr,NULL , &offset))return 0 ;/* Decode instructions */
@@ -1269,11 +1266,9 @@ static int __kprobes can_optimize(unsigned long paddr)unsigned long addr, size =0 , offset =0 ;struct insn insn;kprobe_opcode_t buf[MAX_INSN_SIZE ]; -/* Dummy buffers for lookup_symbol_attrs */ -static char __dummy_buf[KSYM_NAME_LEN ];/* Lookup symbol including addr */ -if (!kallsyms_lookup (paddr, &size, &offset,NULL , __dummy_buf)) +if (!kallsyms_lookup_size_offset (paddr, &size, &offset))return 0 ;/* Check there is enough space for a relative jump. */
Signature · 1 line
1.7.2.2
[tip:perf/core] kprobes: Remove __dummy_buf
Commit-ID: 6abded71d730322df96c5b7f4ab952ffd5a0080d Gitweb: http://git.kernel.org/tip/6abded71d730322df96c5b7f4ab952ffd5a0080d Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 15 Sep 2010 10:04:29 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 15 Sep 2010 10:44:02 +0200
kprobes: Remove __dummy_buf
Remove __dummy_buf which is needed for kallsyms_lookup only. use kallsysm_lookup_size_offset instead.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/kprobes.c | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/kernel/kprobes.c +2 -7
@@ -230,9 +230,6 @@ static int recover_probed_instruction(kprobe_opcode_t *buf, unsigned long addr)return 0 ; } -/* Dummy buffers for kallsyms_lookup */ -static char __dummy_buf[KSYM_NAME_LEN ]; -/* Check if paddr is at an instruction boundary */ static int __kprobes can_probe (unsigned long paddr) {
@@ -241,7 +238,7 @@ static int __kprobes can_probe(unsigned long paddr)struct insn insn;kprobe_opcode_t buf[MAX_INSN_SIZE ]; -if (!kallsyms_lookup (paddr,NULL , &offset,NULL , __dummy_buf)) +if (!kallsyms_lookup_size_offset (paddr,NULL , &offset))return 0 ;/* Decode instructions */
@@ -1269,11 +1266,9 @@ static int __kprobes can_optimize(unsigned long paddr)unsigned long addr, size =0 , offset =0 ;struct insn insn;kprobe_opcode_t buf[MAX_INSN_SIZE ]; -/* Dummy buffers for lookup_symbol_attrs */ -static char __dummy_buf[KSYM_NAME_LEN ];/* Lookup symbol including addr */ -if (!kallsyms_lookup (paddr, &size, &offset,NULL , __dummy_buf)) +if (!kallsyms_lookup_size_offset (paddr, &size, &offset))return 0 ;/* Check there is enough space for a relative jump. */
PATCH 5/5 kprobes: add sparse context annotations
In reply to Namhyung Kimthis removes following warnings when build with C=1
warning: context imbalance in 'kretprobe_hash_lock' - wrong count at exit
warning: context imbalance in 'kretprobe_table_lock' - wrong count at exit
warning: context imbalance in 'kretprobe_hash_unlock' - unexpected unlock
warning: context imbalance in 'kretprobe_table_unlock' - unexpected unlock
--- kernel/kprobes.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/kprobes.c +4 -0
@@ -831,6 +831,7 @@ void __kprobes recycle_rp_inst(struct kretprobe_instance *ri,void __kprobes kretprobe_hash_lock (struct task_struct *tsk,struct hlist_head **head,unsigned long *flags) +__acquires (hlist_lock) {unsigned long hash =hash_ptr (tsk,KPROBE_HASH_BITS );spinlock_t *hlist_lock;
@@ -842,6 +843,7 @@ void __kprobes kretprobe_hash_lock(struct task_struct *tsk,static void __kprobes kretprobe_table_lock (unsigned long hash,unsigned long *flags) +__acquires (hlist_lock) {spinlock_t *hlist_lock =kretprobe_table_lock_ptr (hash);spin_lock_irqsave (hlist_lock, *flags);
@@ -849,6 +851,7 @@ static void __kprobes kretprobe_table_lock(unsigned long hash,void __kprobes kretprobe_hash_unlock (struct task_struct *tsk,unsigned long *flags) +__releases (hlist_lock) {unsigned long hash =hash_ptr (tsk,KPROBE_HASH_BITS );spinlock_t *hlist_lock;
@@ -859,6 +862,7 @@ void __kprobes kretprobe_hash_unlock(struct task_struct *tsk,static void __kprobes kretprobe_table_unlock (unsigned long hash,unsigned long *flags) +__releases (hlist_lock) {spinlock_t *hlist_lock =kretprobe_table_lock_ptr (hash);spin_unlock_irqrestore (hlist_lock, *flags);
Signature · 1 line
1.7.2.2
[tip:perf/core] kprobes: Add sparse context annotations
Commit-ID: 635c17c2b2b4e5cd34f5dcba19d751b4e58533c2 Gitweb: http://git.kernel.org/tip/635c17c2b2b4e5cd34f5dcba19d751b4e58533c2 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 15 Sep 2010 10:04:30 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 15 Sep 2010 10:44:02 +0200
kprobes: Add sparse context annotations
This removes following warnings when build with C=1
warning: context imbalance in 'kretprobe_hash_lock' - wrong count at exit
warning: context imbalance in 'kretprobe_table_lock' - wrong count at exit
warning: context imbalance in 'kretprobe_hash_unlock' - unexpected unlock
warning: context imbalance in 'kretprobe_table_unlock' - unexpected unlock
LKML-Reference: <[email protected]>
--- kernel/kprobes.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/kprobes.c +4 -0
@@ -831,6 +831,7 @@ void __kprobes recycle_rp_inst(struct kretprobe_instance *ri,void __kprobes kretprobe_hash_lock (struct task_struct *tsk,struct hlist_head **head,unsigned long *flags) +__acquires (hlist_lock) {unsigned long hash =hash_ptr (tsk,KPROBE_HASH_BITS );spinlock_t *hlist_lock;
@@ -842,6 +843,7 @@ void __kprobes kretprobe_hash_lock(struct task_struct *tsk,static void __kprobes kretprobe_table_lock (unsigned long hash,unsigned long *flags) +__acquires (hlist_lock) {spinlock_t *hlist_lock =kretprobe_table_lock_ptr (hash);spin_lock_irqsave (hlist_lock, *flags);
@@ -849,6 +851,7 @@ static void __kprobes kretprobe_table_lock(unsigned long hash,void __kprobes kretprobe_hash_unlock (struct task_struct *tsk,unsigned long *flags) +__releases (hlist_lock) {unsigned long hash =hash_ptr (tsk,KPROBE_HASH_BITS );spinlock_t *hlist_lock;
@@ -859,6 +862,7 @@ void __kprobes kretprobe_hash_unlock(struct task_struct *tsk,static void __kprobes kretprobe_table_unlock (unsigned long hash,unsigned long *flags) +__releases (hlist_lock) {spinlock_t *hlist_lock =kretprobe_table_lock_ptr (hash);spin_unlock_irqrestore (hlist_lock, *flags);
Hi Ingo,
Could you pull it to -tip tree?
I've checked this series can be applied to the latest tip/master. :)
Thank you,
Quoted 24 lines · Namhyung Kim
Hello,
This is a resend of my previous works on kprobes. All patches in this series are small cleanups and got acked by Masami. Please consider applying it.
Thanks.
---
Namhyung Kim (5):
kprobes: remove redundant address check
kprobes: verify jprobe entry point
kprobes: make functions static
kprobes: remove__dummy_buf
kprobes: add sparse context annotationsarch/x86/kernel/kprobes.c | 11 +++-------- kernel/kprobes.c | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-)--
1.7.2.2
Quoted 4 lines · Masami Hiramatsu
Hi Ingo,
Could you pull it to -tip tree?
I've checked this series can be applied to the latest tip/master. :)
Sure, i've applied them to tip:perf/core, thanks guys!
Ingo