Skip to contentSkip to conversation

uprobe: Move arch_uprobe_optimize right after handlers execution

PATCH Applied Jiri Olsa 5 participants 5 messages Oct 1, 2025 – Oct 14, 2025

Subsystems (4)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 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.

---
 kernel/events/uprobes.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/uprobes.c +3 -3
index 5dcf927310fd..c14ec27b976d 100644
@@ -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;
 
Signature · 1 line
2.51.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jiri Olsa

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.

---
 kernel/events/uprobes.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

makes sense

Quoted 27 lines
kernel/events/uprobes.c +3 -4
index 5dcf927310fd..c14ec27b976d 100644
@@ -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

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Jiri Olsa
Quoted 6 lines · On Wed, 1 Oct 2025 15:24:49 +0200 Jiri Olsa <[email protected]> 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.

Looks good to me.

Thanks,

Quoted 31 lines
---
 kernel/events/uprobes.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/uprobes.c +3 -3
index 5dcf927310fd..c14ec27b976d 100644
@@ -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;
 
Signature · 1 line
2.51.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Jiri Olsa
Quoted 14 lines · Jiri Olsa
kernel/events/uprobes.c +3 -0
@@ -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.

kernel/events/uprobes.c static void handle_swbp(struct pt_regs *regs) · line 2779

Quoted 8 lines
kernel/events/uprobes.c +0 -3
@@ -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;
merge bot Applied
#4 lore raw
In reply to Jiri Olsa
The following commit has been merged into the perf/urgent branch of tip:

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 <[email protected]>
AuthorDate:    Wed, 01 Oct 2025 15:24:49 +02:00
Committer:     Peter Zijlstra <[email protected]>
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.

---
 kernel/events/uprobes.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/uprobes.c +3 -3
index 8709c69..f11ceb8 100644
@@ -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;