mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] kprobes cleanups
@ 2010-09-02  5:02 Namhyung Kim
  2010-09-02  5:02 ` [PATCH 1/5] kprobes: remove redundant address check Namhyung Kim
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Namhyung Kim @ 2010-09-02  5:02 UTC (permalink / raw)
  To: linux-kernel, Masami Hiramatsu, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S. Miller

This patchset is a series of small fixups on kprobes.

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


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

* [PATCH 1/5] kprobes: remove redundant address check
  2010-09-02  5:02 [PATCH 0/5] kprobes cleanups Namhyung Kim
@ 2010-09-02  5:02 ` Namhyung Kim
  2010-09-02  5:02 ` [PATCH 2/5] kprobes: verify jprobe entry point Namhyung Kim
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2010-09-02  5:02 UTC (permalink / raw)
  To: linux-kernel, Masami Hiramatsu, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S. Miller

remove call to kernel_text_address() in register_jprobes()
because it is called right after in register_kprobe().

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 kernel/kprobes.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 282035f..8f96701 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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);
-- 
1.7.2.2


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

* [PATCH 2/5] kprobes: verify jprobe entry point
  2010-09-02  5:02 [PATCH 0/5] kprobes cleanups Namhyung Kim
  2010-09-02  5:02 ` [PATCH 1/5] kprobes: remove redundant address check Namhyung Kim
@ 2010-09-02  5:02 ` Namhyung Kim
  2010-09-02  5:02 ` [PATCH 3/5] kprobes: make functions static Namhyung Kim
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2010-09-02  5:02 UTC (permalink / raw)
  To: linux-kernel, Masami Hiramatsu, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S. Miller

verify jprobe's entry point is a function entry point
using kallsyms' offset value.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 kernel/kprobes.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 8f96701..1b0dbe0 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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)
-- 
1.7.2.2


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

* [PATCH 3/5] kprobes: make functions static
  2010-09-02  5:02 [PATCH 0/5] kprobes cleanups Namhyung Kim
  2010-09-02  5:02 ` [PATCH 1/5] kprobes: remove redundant address check Namhyung Kim
  2010-09-02  5:02 ` [PATCH 2/5] kprobes: verify jprobe entry point Namhyung Kim
@ 2010-09-02  5:02 ` Namhyung Kim
  2010-09-02  5:02 ` [PATCH 4/5] kprobes: remove __dummy_buf Namhyung Kim
  2010-09-02  5:02 ` [PATCH 5/5] kprobes: add sparse context annotations Namhyung Kim
  4 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2010-09-02  5:02 UTC (permalink / raw)
  To: linux-kernel, Masami Hiramatsu, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S. Miller

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

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 arch/x86/kernel/kprobes.c |    2 +-
 kernel/kprobes.c          |    5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index 770ebfb..05c20a4 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -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)
 {
 	asm volatile (
 			".global optprobe_template_entry\n"
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 1b0dbe0..c53aad5 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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);
-- 
1.7.2.2


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

* [PATCH 4/5] kprobes: remove __dummy_buf
  2010-09-02  5:02 [PATCH 0/5] kprobes cleanups Namhyung Kim
                   ` (2 preceding siblings ...)
  2010-09-02  5:02 ` [PATCH 3/5] kprobes: make functions static Namhyung Kim
@ 2010-09-02  5:02 ` Namhyung Kim
  2010-09-02  5:02 ` [PATCH 5/5] kprobes: add sparse context annotations Namhyung Kim
  4 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2010-09-02  5:02 UTC (permalink / raw)
  To: linux-kernel, Masami Hiramatsu, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S. Miller

remove __dummy_buf which is needed for kallsyms_lookup only.
use kallsysm_lookup_size_offset instead.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 arch/x86/kernel/kprobes.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index 05c20a4..e05952a 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -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. */
-- 
1.7.2.2


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

* [PATCH 5/5] kprobes: add sparse context annotations
  2010-09-02  5:02 [PATCH 0/5] kprobes cleanups Namhyung Kim
                   ` (3 preceding siblings ...)
  2010-09-02  5:02 ` [PATCH 4/5] kprobes: remove __dummy_buf Namhyung Kim
@ 2010-09-02  5:02 ` Namhyung Kim
  4 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2010-09-02  5:02 UTC (permalink / raw)
  To: linux-kernel, Masami Hiramatsu, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S. Miller

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

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 kernel/kprobes.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index c53aad5..6dd5359 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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);
-- 
1.7.2.2


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

* [PATCH 1/5] kprobes: remove redundant address check
  2010-09-15  1:04 [PATCH RESEND 0/5] kprobes cleanups Namhyung Kim
@ 2010-09-15  1:04 ` Namhyung Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2010-09-15  1:04 UTC (permalink / raw)
  To: Andrew Morton, Ingo Molnar; +Cc: Masami Hiramatsu, linux-kernel

remove call to kernel_text_address() in register_jprobes()
because it is called right after in register_kprobe().

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
 kernel/kprobes.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 282035f..8f96701 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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);
-- 
1.7.2.2


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

end of thread, other threads:[~2010-09-15  1:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-02  5:02 [PATCH 0/5] kprobes cleanups Namhyung Kim
2010-09-02  5:02 ` [PATCH 1/5] kprobes: remove redundant address check Namhyung Kim
2010-09-02  5:02 ` [PATCH 2/5] kprobes: verify jprobe entry point Namhyung Kim
2010-09-02  5:02 ` [PATCH 3/5] kprobes: make functions static Namhyung Kim
2010-09-02  5:02 ` [PATCH 4/5] kprobes: remove __dummy_buf Namhyung Kim
2010-09-02  5:02 ` [PATCH 5/5] kprobes: add sparse context annotations Namhyung Kim
2010-09-15  1:04 [PATCH RESEND 0/5] kprobes cleanups Namhyung Kim
2010-09-15  1:04 ` [PATCH 1/5] kprobes: remove redundant address check Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®