# \[PATCH 08/13\] x86/kprobes: Use kprobe iterator in \_\_recover\_optprobed\_insn

- From: Jiri Olsa \<jolsa@kernel.org\>
- Date: 2026-11-09 19:57:22 
- List: linux-trace-kernel
- Page: https://ratatoskr.run/linux-trace-kernel/2026/11/17899785
- Thread: https://ratatoskr.run/linux-trace-kernel/2026/11/17899746/t.md

```text
Use the kprobe range iterator to find an optimized probe covering the
address being recovered. This replaces repeated hash lookups across the
JMP32 instruction range.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/kernel/kprobes/opt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 3f8fea52619f..9da41424be77 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -37,12 +37,11 @@
 unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr)
 {
 	struct optimized_kprobe *op;
+	struct kprobe_iter iter;
 	struct kprobe *kp;
 	long offs;
-	int i;
 
-	for (i = 0; i < JMP32_INSN_SIZE; i++) {
-		kp = get_kprobe((void *)addr - i);
+	for_each_kprobe(iter, kp, addr - (JMP32_INSN_SIZE - 1), addr) {
 		/* This function only handles jump-optimized kprobe */
 		if (kp && kprobe_optimized(kp)) {
 			op = container_of(kp, struct optimized_kprobe, kp);
-- 
2.43.0

```
