kernel/events/uprobes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
It's less confusing to optimize uprobe right after handlers execution
and before we do the check for changed ip register to avoid situations
where changed ip register would skip uprobe optimization.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/events/uprobes.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 5dcf927310fd..c14ec27b976d 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -2765,6 +2765,9 @@ static void handle_swbp(struct pt_regs *regs)
handler_chain(uprobe, regs);
+ /* Try to optimize after first hit. */
+ arch_uprobe_optimize(&uprobe->arch, bp_vaddr);
+
/*
* If user decided to take execution elsewhere, it makes little sense
* to execute the original instruction, so let's skip it.
@@ -2772,9 +2775,6 @@ static void handle_swbp(struct pt_regs *regs)
if (instruction_pointer(regs) != bp_vaddr)
goto out;
- /* Try to optimize after first hit. */
- arch_uprobe_optimize(&uprobe->arch, bp_vaddr);
-
if (arch_uprobe_skip_sstep(&uprobe->arch, regs))
goto out;
--
2.51.0
On 10/01, Jiri Olsa wrote: > > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -2765,6 +2765,9 @@ static void handle_swbp(struct pt_regs *regs) > > handler_chain(uprobe, regs); > > + /* Try to optimize after first hit. */ > + arch_uprobe_optimize(&uprobe->arch, bp_vaddr); > + > /* > * If user decided to take execution elsewhere, it makes little sense > * to execute the original instruction, so let's skip it. > @@ -2772,9 +2775,6 @@ static void handle_swbp(struct pt_regs *regs) > if (instruction_pointer(regs) != bp_vaddr) > goto out; > > - /* Try to optimize after first hit. */ > - arch_uprobe_optimize(&uprobe->arch, bp_vaddr); > - > if (arch_uprobe_skip_sstep(&uprobe->arch, regs)) > goto out; Acked-by: Oleg Nesterov <oleg@redhat.com>
On Wed, 1 Oct 2025 15:24:49 +0200 Jiri Olsa <jolsa@kernel.org> wrote: > It's less confusing to optimize uprobe right after handlers execution > and before we do the check for changed ip register to avoid situations > where changed ip register would skip uprobe optimization. > > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> > Signed-off-by: Jiri Olsa <jolsa@kernel.org> Looks good to me. Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Thanks, > --- > kernel/events/uprobes.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c > index 5dcf927310fd..c14ec27b976d 100644 > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -2765,6 +2765,9 @@ static void handle_swbp(struct pt_regs *regs) > > handler_chain(uprobe, regs); > > + /* Try to optimize after first hit. */ > + arch_uprobe_optimize(&uprobe->arch, bp_vaddr); > + > /* > * If user decided to take execution elsewhere, it makes little sense > * to execute the original instruction, so let's skip it. > @@ -2772,9 +2775,6 @@ static void handle_swbp(struct pt_regs *regs) > if (instruction_pointer(regs) != bp_vaddr) > goto out; > > - /* Try to optimize after first hit. */ > - arch_uprobe_optimize(&uprobe->arch, bp_vaddr); > - > if (arch_uprobe_skip_sstep(&uprobe->arch, regs)) > goto out; > > -- > 2.51.0 > -- Masami Hiramatsu (Google) <mhiramat@kernel.org>
On Wed, Oct 1, 2025 at 6:25 AM Jiri Olsa <jolsa@kernel.org> wrote: > > It's less confusing to optimize uprobe right after handlers execution > and before we do the check for changed ip register to avoid situations > where changed ip register would skip uprobe optimization. > > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> > Signed-off-by: Jiri Olsa <jolsa@kernel.org> > --- > kernel/events/uprobes.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > makes sense Acked-by: Andrii Nakryiko <andrii@kernel.org> > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c > index 5dcf927310fd..c14ec27b976d 100644 > --- a/kernel/events/uprobes.c > +++ b/kernel/events/uprobes.c > @@ -2765,6 +2765,9 @@ static void handle_swbp(struct pt_regs *regs) > > handler_chain(uprobe, regs); > > + /* Try to optimize after first hit. */ > + arch_uprobe_optimize(&uprobe->arch, bp_vaddr); > + > /* > * If user decided to take execution elsewhere, it makes little sense > * to execute the original instruction, so let's skip it. > @@ -2772,9 +2775,6 @@ static void handle_swbp(struct pt_regs *regs) > if (instruction_pointer(regs) != bp_vaddr) > goto out; > > - /* Try to optimize after first hit. */ > - arch_uprobe_optimize(&uprobe->arch, bp_vaddr); > - > if (arch_uprobe_skip_sstep(&uprobe->arch, regs)) > goto out; > > -- > 2.51.0 >
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 62685ab071de7c39499212bff19f1b5bc0148bc7
Gitweb: https://git.kernel.org/tip/62685ab071de7c39499212bff19f1b5bc0148bc7
Author: Jiri Olsa <jolsa@kernel.org>
AuthorDate: Wed, 01 Oct 2025 15:24:49 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 14 Oct 2025 10:38:09 +02:00
uprobe: Move arch_uprobe_optimize right after handlers execution
It's less confusing to optimize uprobe right after handlers execution
and before we do the check for changed ip register to avoid situations
where changed ip register would skip uprobe optimization.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/events/uprobes.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 8709c69..f11ceb8 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -2765,6 +2765,9 @@ static void handle_swbp(struct pt_regs *regs)
handler_chain(uprobe, regs);
+ /* Try to optimize after first hit. */
+ arch_uprobe_optimize(&uprobe->arch, bp_vaddr);
+
/*
* If user decided to take execution elsewhere, it makes little sense
* to execute the original instruction, so let's skip it.
@@ -2772,9 +2775,6 @@ static void handle_swbp(struct pt_regs *regs)
if (instruction_pointer(regs) != bp_vaddr)
goto out;
- /* Try to optimize after first hit. */
- arch_uprobe_optimize(&uprobe->arch, bp_vaddr);
-
if (arch_uprobe_skip_sstep(&uprobe->arch, regs))
goto out;
© 2016 - 2026 Red Hat, Inc.