Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH -tip 1/3] kprobes: Hide CONFIG_OPTPROBES and set if arch support optimized kprobes

2 views
Skip to first unread message

Masami Hiramatsu

unread,
Mar 12, 2010, 6:20:02 PM3/12/10
to
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.

Signed-off-by: Masami Hiramatsu <mhir...@redhat.com>
Cc: Dieter Ries <ma...@dieterries.net>
Cc: Ingo Molnar <mi...@elte.hu>
Cc: Ananth N Mavinakayanahalli <ana...@in.ibm.com>
---

Documentation/kprobes.txt | 10 ++--------
arch/Kconfig | 6 ++----
2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt
index 2f9115c..61c291c 100644
--- a/Documentation/kprobes.txt
+++ b/Documentation/kprobes.txt
@@ -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"
diff --git a/arch/Kconfig b/arch/Kconfig
index e5eb133..12f9dcc 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -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


--
Masami Hiramatsu
e-mail: mhir...@redhat.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Masami Hiramatsu

unread,
Mar 12, 2010, 6:20:02 PM3/12/10
to
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.

Signed-off-by: Masami Hiramatsu <mhir...@redhat.com>
Cc: Ingo Molnar <mi...@elte.hu>
---

tools/perf/builtin-probe.c | 1 -
tools/perf/util/probe-finder.c | 3 +++
2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index c30a335..152d6c9 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -47,7 +47,6 @@
#include "util/probe-event.h"

#define MAX_PATH_LEN 256
-#define MAX_PROBES 128

/* Session management structure */
static struct {
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 1e6c65e..f9cbbf1 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -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++;

Ingo Molnar

unread,
Mar 13, 2010, 2:30:01 AM3/13/10
to

* Masami Hiramatsu <mhir...@redhat.com> wrote:

> 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

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

tip-bot for Masami Hiramatsu

unread,
Mar 13, 2010, 7:30:01 AM3/13/10
to
Commit-ID: 594087a04eea544356f9c52e83c1a9bc380ce80f
Gitweb: http://git.kernel.org/tip/594087a04eea544356f9c52e83c1a9bc380ce80f
Author: Masami Hiramatsu <mhir...@redhat.com>
AuthorDate: Fri, 12 Mar 2010 18:22:17 -0500
Committer: Ingo Molnar <mi...@elte.hu>
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.

Signed-off-by: Masami Hiramatsu <mhir...@redhat.com>
Cc: systemtap <syst...@sources.redhat.com>
Cc: DLE <dle-d...@lists.sourceforge.net>
Cc: <sta...@kernel.org>
LKML-Reference: <20100312232217....@localhost6.localdomain6>
[ 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. ]
Signed-off-by: Ingo Molnar <mi...@elte.hu>

OGAWA Hirofumi

unread,
Mar 13, 2010, 7:20:01 PM3/13/10
to
Masami Hiramatsu <mhir...@redhat.com> writes:

> 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:

--
OGAWA Hirofumi <hiro...@mail.parknet.co.jp>

Masami Hiramatsu

unread,
Mar 13, 2010, 9:10:02 PM3/13/10
to
OGAWA Hirofumi wrote:
> Masami Hiramatsu <mhir...@redhat.com> writes:
>
>> 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:

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!


--
Masami Hiramatsu
e-mail: mhir...@redhat.com

Masami Hiramatsu

unread,
Mar 15, 2010, 1:00:02 PM3/15/10
to
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.

Signed-off-by: Masami Hiramatsu <mhir...@redhat.com>


Cc: Dieter Ries <ma...@dieterries.net>
Cc: Ingo Molnar <mi...@elte.hu>
Cc: Ananth N Mavinakayanahalli <ana...@in.ibm.com>

Cc: OGAWA Hirofumi <hiro...@mail.parknet.co.jp>
---

Documentation/kprobes.txt | 10 ++--------
arch/Kconfig | 9 ++-------
2 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt
index 2f9115c..61c291c 100644
--- a/Documentation/kprobes.txt
+++ b/Documentation/kprobes.txt
@@ -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"
diff --git a/arch/Kconfig b/arch/Kconfig

index e5eb133..f06010f 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -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


--
Masami Hiramatsu
e-mail: mhir...@redhat.com

tip-bot for Masami Hiramatsu

unread,
Mar 16, 2010, 10:50:02 AM3/16/10
to
Commit-ID: 5cc718b9dad682329a60e73547c6e708faa5bbe4
Gitweb: http://git.kernel.org/tip/5cc718b9dad682329a60e73547c6e708faa5bbe4
Author: Masami Hiramatsu <mhir...@redhat.com>
AuthorDate: Mon, 15 Mar 2010 13:00:54 -0400
Committer: Ingo Molnar <mi...@elte.hu>
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.

Signed-off-by: Masami Hiramatsu <mhir...@redhat.com>

Cc: Dieter Ries <ma...@dieterries.net>


Cc: Ananth N Mavinakayanahalli <ana...@in.ibm.com>
Cc: OGAWA Hirofumi <hiro...@mail.parknet.co.jp>

Cc: Peter Zijlstra <a.p.zi...@chello.nl>
Cc: Mike Galbraith <efa...@gmx.de>
Cc: Paul Mackerras <pau...@samba.org>
Cc: Arnaldo Carvalho de Melo <ac...@redhat.com>
Cc: Frederic Weisbecker <fwei...@gmail.com>
LKML-Reference: <20100315170054....@localhost6.localdomain6>
Signed-off-by: Ingo Molnar <mi...@elte.hu>

0 new messages