Skip to contentSkip to conversation

kprobes: Hide CONFIG_OPTPROBES and set if arch support optimized kprobes

PATCH Superseded Masami Hiramatsu 3 participants 10 messages Mar 12, 2010 – Mar 16, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 kprobes: Hide CONFIG_OPTPROBES and set if arch support optimized kprobes

Hide CONFIG_OPTPROBES and set if arch support optimized kprobes, since this option doesn't change the behavior of kprobes, but just reduces the overhead.

Cc Dieter Ries <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Ananth N Mavinakayanahalli <[email protected]>

---

 Documentation/kprobes.txt |   10 ++--------
 arch/Kconfig              |    6 ++----
 2 files changed, 4 insertions(+), 12 deletions(-)
Documentation/kprobes.txt +2 -8
index 2f9115c..61c291c 100644
@@ -165,8 +165,8 @@ the user entry_handler invocation is also skipped.
 
 1.4 How Does Jump Optimization Work?
 
-If you configured your kernel with CONFIG_OPTPROBES=y (currently
-this option is supported on x86/x86-64, non-preemptive kernel) and
+If your kernel is built with CONFIG_OPTPROBES=y (currently this flag
+is automatically set 'y' on x86/x86-64, non-preemptive kernel) and
 the "debug.kprobes_optimization" kernel parameter is set to 1 (see
 sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump
 instruction instead of a breakpoint instruction at each probepoint.
@@ -271,8 +271,6 @@ tweak the kernel's execution path, you need to suppress optimization,
 using one of the following techniques:
 - Specify an empty function for the kprobe's post_handler or break_handler.
  or
-- Config CONFIG_OPTPROBES=n.
- or
 - Execute 'sysctl -w debug.kprobes_optimization=n'
 
 2. Architectures Supported
@@ -307,10 +305,6 @@ it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO),
 so you can use "objdump -d -l vmlinux" to see the source-to-object
 code mapping.
 
-If you want to reduce probing overhead, set "Kprobes jump optimization
-support" (CONFIG_OPTPROBES) to "y". You can find this option under the
-"Kprobes" line.
-
 4. API Reference
 
 The Kprobes API includes a "register" function and an "unregister"
arch/Kconfig +2 -4
index e5eb133..12f9dcc 100644
@@ -42,11 +42,9 @@ config KPROBES
 	  If in doubt, say "N".
 
 config OPTPROBES
-	bool "Kprobes jump optimization support (EXPERIMENTAL)"
-	default y
-	depends on KPROBES
+	def_bool y
+	depends on KPROBES && HAVE_OPTPROBES
 	depends on !PREEMPT
-	depends on HAVE_OPTPROBES
 	select KALLSYMS_ALL
 	help
 	  This option will allow kprobes to optimize breakpoint to
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#1 lore raw

PATCH 2/3 perf probe: Fix probe_point buffer overrun

Fix probe_point array-size overrun problem. In some cases (e.g. inline function), one user-specified probe-point can be translated to many probe address, and it overruns pre-defined array-size.
This also removes redundant MAX_PROBES macro definition.

---

 tools/perf/builtin-probe.c     |    1 -
 tools/perf/util/probe-finder.c |    3 +++
 2 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/builtin-probe.c +0 -1
index c30a335..152d6c9 100644
@@ -47,7 +47,6 @@
 #include "util/probe-event.h"
 
 #define MAX_PATH_LEN 256
-#define MAX_PROBES 128
 
 /* Session management structure */
 static struct {
tools/perf/util/probe-finder.c +3 -0
index 1e6c65e..f9cbbf1 100644
@@ -455,6 +455,9 @@ static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
 	/* *pf->fb_ops will be cached in libdw. Don't free it. */
 	pf->fb_ops = NULL;
 
+	if (pp->found == MAX_PROBES)
+		die("Too many( > %d) probe point found.\n", MAX_PROBES);
+
 	pp->probes[pp->found] = strdup(tmp);
 	pp->found++;
 }
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#2 lore raw

[tip:perf/urgent] perf probe: Fix probe_point buffer overrun

Commit-ID:  594087a04eea544356f9c52e83c1a9bc380ce80f
Gitweb:     http://git.kernel.org/tip/594087a04eea544356f9c52e83c1a9bc380ce80f
Author:     Masami Hiramatsu <[email protected]>
AuthorDate: Fri, 12 Mar 2010 18:22:17 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 13 Mar 2010 08:32:22 +0100

perf probe: Fix probe_point buffer overrun

Fix probe_point array-size overrun problem. In some cases (e.g. inline function), one user-specified probe-point can be translated to many probe address, and it overruns pre-defined array-size. This also removes redundant MAX_PROBES macro definition.

LKML-Reference: <[email protected]> [ Note that only root can create new probes. Eventually we should remove
the MAX_PROBES limit, but that is a larger patch not eligible to perf/urgent treatment. ]

---
 tools/perf/builtin-probe.c     |    1 -
 tools/perf/util/probe-finder.c |    3 +++
 2 files changed, 3 insertions(+), 1 deletions(-)
tools/perf/builtin-probe.c +0 -1
index c30a335..152d6c9 100644
@@ -47,7 +47,6 @@
 #include "util/probe-event.h"
 
 #define MAX_PATH_LEN 256
-#define MAX_PROBES 128
 
 /* Session management structure */
 static struct {
tools/perf/util/probe-finder.c +3 -0
index 1e6c65e..f9cbbf1 100644
@@ -455,6 +455,9 @@ static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
 	/* *pf->fb_ops will be cached in libdw. Don't free it. */
 	pf->fb_ops = NULL;
 
+	if (pp->found == MAX_PROBES)
+		die("Too many( > %d) probe point found.\n", MAX_PROBES);
+
 	pp->probes[pp->found] = strdup(tmp);
 	pp->found++;
 }
#3 lore raw

PATCH 3/3 perf probe: Set need_dwarf if lazy matching is used

In reply to Masami Hiramatsu

Set need_dwarf if lazy matching pattern is specified, because lazy matching requires real source path for which we must use debuginfo.

---

 tools/perf/util/probe-event.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/probe-event.c +1 -1
index 53181db..7c004b6 100644
@@ -242,7 +242,7 @@ void parse_perf_probe_event(const char *str, struct probe_point *pp,
 
 	/* Parse probe point */
 	parse_perf_probe_probepoint(argv[0], pp);
-	if (pp->file || pp->line)
+	if (pp->file || pp->line || pp->lazy_line)
 		*need_dwarf = true;
 
 	/* Copy arguments and ensure return probe has no C argument */
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#4 lore raw

[tip:perf/urgent] perf probe: Fix need_dwarf flag if lazy matching is used

Commit-ID:  fc6ceea045031658d0b59af562369eae980b4370
Gitweb:     http://git.kernel.org/tip/fc6ceea045031658d0b59af562369eae980b4370
Author:     Masami Hiramatsu <[email protected]>
AuthorDate: Fri, 12 Mar 2010 18:22:24 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 13 Mar 2010 08:32:22 +0100

perf probe: Fix need_dwarf flag if lazy matching is used

Set need_dwarf if lazy matching pattern is specified, because lazy matching requires real source path for which we must use debuginfo.

LKML-Reference: <[email protected]>

---
 tools/perf/util/probe-event.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/probe-event.c +1 -1
index 53181db..7c004b6 100644
@@ -242,7 +242,7 @@ void parse_perf_probe_event(const char *str, struct probe_point *pp,
 
 	/* Parse probe point */
 	parse_perf_probe_probepoint(argv[0], pp);
-	if (pp->file || pp->line)
+	if (pp->file || pp->line || pp->lazy_line)
 		*need_dwarf = true;
 
 	/* Copy arguments and ensure return probe has no C argument */
#5 lore raw
In reply to Masami Hiramatsu

arch/Kconfig config KPROBES · line 50

Quoted 11 lines · Masami Hiramatsu

config OPTPROBES

arch/Kconfig +2 -4
-	bool "Kprobes jump optimization support (EXPERIMENTAL)"
-	default y
-	depends on KPROBES
+	def_bool y
+	depends on KPROBES && HAVE_OPTPROBES
 	depends on !PREEMPT
-	depends on HAVE_OPTPROBES
 	select KALLSYMS_ALL
 	help
 	  This option will allow kprobes to optimize breakpoint to

The help text can be removed too, now that it's not interactive. Also, i'd suggest to add a comment that this just relays HAVE_OPTPROBES now, set by the arch.

Ingo

#6 lore raw

PATCH v3 1/1 kprobes: Hide CONFIG_OPTPROBES and set if arch support optimized kprobes

Hide CONFIG_OPTPROBES and set if the arch supports optimized kprobes (IOW, HAVE_OPTPROBES=y), since this option doesn't change the major behavior of kprobes, and workarounds for minor changes are documented.

Cc Dieter Ries <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Ananth N Mavinakayanahalli <[email protected]>
Cc OGAWA Hirofumi <[email protected]>

---

 Documentation/kprobes.txt |   10 ++--------
 arch/Kconfig              |    9 ++-------
 2 files changed, 4 insertions(+), 15 deletions(-)
Documentation/kprobes.txt +2 -8
index 2f9115c..61c291c 100644
@@ -165,8 +165,8 @@ the user entry_handler invocation is also skipped.
 
 1.4 How Does Jump Optimization Work?
 
-If you configured your kernel with CONFIG_OPTPROBES=y (currently
-this option is supported on x86/x86-64, non-preemptive kernel) and
+If your kernel is built with CONFIG_OPTPROBES=y (currently this flag
+is automatically set 'y' on x86/x86-64, non-preemptive kernel) and
 the "debug.kprobes_optimization" kernel parameter is set to 1 (see
 sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump
 instruction instead of a breakpoint instruction at each probepoint.
@@ -271,8 +271,6 @@ tweak the kernel's execution path, you need to suppress optimization,
 using one of the following techniques:
 - Specify an empty function for the kprobe's post_handler or break_handler.
  or
-- Config CONFIG_OPTPROBES=n.
- or
 - Execute 'sysctl -w debug.kprobes_optimization=n'
 
 2. Architectures Supported
@@ -307,10 +305,6 @@ it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO),
 so you can use "objdump -d -l vmlinux" to see the source-to-object
 code mapping.
 
-If you want to reduce probing overhead, set "Kprobes jump optimization
-support" (CONFIG_OPTPROBES) to "y". You can find this option under the
-"Kprobes" line.
-
 4. API Reference
 
 The Kprobes API includes a "register" function and an "unregister"
arch/Kconfig +2 -7
index e5eb133..f06010f 100644
@@ -42,15 +42,10 @@ config KPROBES
 	  If in doubt, say "N".
 
 config OPTPROBES
-	bool "Kprobes jump optimization support (EXPERIMENTAL)"
-	default y
-	depends on KPROBES
+	def_bool y
+	depends on KPROBES && HAVE_OPTPROBES
 	depends on !PREEMPT
-	depends on HAVE_OPTPROBES
 	select KALLSYMS_ALL
-	help
-	  This option will allow kprobes to optimize breakpoint to
-	  a jump for reducing its overhead.
 
 config HAVE_EFFICIENT_UNALIGNED_ACCESS
 	bool
Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#7 lore raw

[tip:perf/core] kprobes: Hide CONFIG_OPTPROBES and set if arch supports optimized kprobes

Commit-ID:  5cc718b9dad682329a60e73547c6e708faa5bbe4
Gitweb:     http://git.kernel.org/tip/5cc718b9dad682329a60e73547c6e708faa5bbe4
Author:     Masami Hiramatsu <[email protected]>
AuthorDate: Mon, 15 Mar 2010 13:00:54 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 16 Mar 2010 11:07:23 +0100

kprobes: Hide CONFIG_OPTPROBES and set if arch supports optimized kprobes

Hide CONFIG_OPTPROBES and set if the arch supports optimized kprobes (IOW, HAVE_OPTPROBES=y), since this option doesn't change the major behavior of kprobes, and workarounds for minor changes are documented.

Cc systemtap <[email protected]>
Cc Dieter Ries <[email protected]>
Cc Ananth N Mavinakayanahalli <[email protected]>
Cc OGAWA Hirofumi <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Frederic Weisbecker <[email protected]>

LKML-Reference: <[email protected]>

---
 Documentation/kprobes.txt |   10 ++--------
 arch/Kconfig              |    9 ++-------
 2 files changed, 4 insertions(+), 15 deletions(-)
Documentation/kprobes.txt +2 -8
index 2f9115c..61c291c 100644
@@ -165,8 +165,8 @@ the user entry_handler invocation is also skipped.
 
 1.4 How Does Jump Optimization Work?
 
-If you configured your kernel with CONFIG_OPTPROBES=y (currently
-this option is supported on x86/x86-64, non-preemptive kernel) and
+If your kernel is built with CONFIG_OPTPROBES=y (currently this flag
+is automatically set 'y' on x86/x86-64, non-preemptive kernel) and
 the "debug.kprobes_optimization" kernel parameter is set to 1 (see
 sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump
 instruction instead of a breakpoint instruction at each probepoint.
@@ -271,8 +271,6 @@ tweak the kernel's execution path, you need to suppress optimization,
 using one of the following techniques:
 - Specify an empty function for the kprobe's post_handler or break_handler.
  or
-- Config CONFIG_OPTPROBES=n.
- or
 - Execute 'sysctl -w debug.kprobes_optimization=n'
 
 2. Architectures Supported
@@ -307,10 +305,6 @@ it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO),
 so you can use "objdump -d -l vmlinux" to see the source-to-object
 code mapping.
 
-If you want to reduce probing overhead, set "Kprobes jump optimization
-support" (CONFIG_OPTPROBES) to "y". You can find this option under the
-"Kprobes" line.
-
 4. API Reference
 
 The Kprobes API includes a "register" function and an "unregister"
arch/Kconfig +2 -7
index e5eb133..f06010f 100644
@@ -42,15 +42,10 @@ config KPROBES
 	  If in doubt, say "N".
 
 config OPTPROBES
-	bool "Kprobes jump optimization support (EXPERIMENTAL)"
-	default y
-	depends on KPROBES
+	def_bool y
+	depends on KPROBES && HAVE_OPTPROBES
 	depends on !PREEMPT
-	depends on HAVE_OPTPROBES
 	select KALLSYMS_ALL
-	help
-	  This option will allow kprobes to optimize breakpoint to
-	  a jump for reducing its overhead.
 
 config HAVE_EFFICIENT_UNALIGNED_ACCESS
 	bool
#8 lore raw
In reply to Masami Hiramatsu
Quoted 3 lines · Masami Hiramatsu

Hide CONFIG_OPTPROBES and set if arch support optimized kprobes, since this option doesn't change the behavior of kprobes, but just reduces the overhead.

I don't so care whether this is configurable or not, but this confuses me now. The following seems to say it's changed, but now this comment says it wasn't changed. The following docs was obsoleted?

Thanks.

NOTE for geeks:
The jump optimization changes the kprobe's pre_handler behavior. Without optimization, the pre_handler can change the kernel's execution path by changing regs->ip and returning 1. However, when the probe is optimized, that modification is ignored. Thus, if you want to tweak the kernel's execution path, you need to suppress optimization, using one of the following techniques:

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#9 lore raw
Quoted 12 lines · OGAWA Hirofumi
Quoted 3 lines · Masami Hiramatsu

Hide CONFIG_OPTPROBES and set if arch support optimized kprobes, since this option doesn't change the behavior of kprobes, but just reduces the overhead.

I don't so care whether this is configurable or not, but this confuses me now. The following seems to say it's changed, but now this comment says it wasn't changed. The following docs was obsoleted?

Thanks.

Quoted 7 lines

NOTE for geeks:
The jump optimization changes the kprobe's pre_handler behavior. Without optimization, the pre_handler can change the kernel's execution path by changing regs->ip and returning 1. However, when the probe is optimized, that modification is ignored. Thus, if you want to tweak the kernel's execution path, you need to suppress optimization, using one of the following techniques:

Ah, good point. This is only one point of changing the behavior. So if someone makes an out of tree module for changing the ip address by using kprobes, e.g. live code patching or something like that, it will be affected by this change. However, I think using kprobes for this way is not obviously documented, moreover, some workarounds for that are documented as above. So I don't worried about it.

Anyway, indeed, the patch comment is wrong. I need to say "this option doesn't change the major behavior of kprobes, and workarounds for minor change are documented." :)

Thank you for pointing it out!

Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]