Re: [PATCH 1/3] kprobes: Disarm disabled optprobe on forced unoptimization

From
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date
2026-11-04 06:49:41
Also in
lkml
Reply to
Mani Tofigh via B4 Relay, 2026-11-03
Hi Mani,

On Tue, 03 Nov 2026 13:45:59 -0500, Mani Tofigh [off-list ref] wrote:
quoted hunk ↗ jump to hunk
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1006,6 +1006,9 @@ static void unoptimize_kprobe(struct kprobe *p, bool force)
 					list_move(&op->list, &cur->freeing_list);
 				} else {
+					/* Disarm probes if marked disabled and not gone */
+					if (kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp))
Nice catch!

BTW, since `kprobe_unused(&op->kp)` checks `kprobe_disabled(&op->kp)`
(see definition in `kprobe_unused()`), both the `kprobe_unused()` block
and this `else` block execute the same `arch_disarm_kprobe(&op->kp)`
under `kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp)`.

So we can factor this disarm check out above the
`if (kprobe_unused(&op->kp))` block as below:

	force_unoptimize_kprobe(op);
	/* Disarm probes if marked disabled and not gone */
	if (kprobe_disabled(&op->kp) && !kprobe_gone(&op->kp))
		arch_disarm_kprobe(&op->kp);

	if (kprobe_unused(&op->kp)) {
		hlist_del_init_rcu(&op->kp.hlist);
		list_move(&op->list, &cur->freeing_list);
	} else {
		list_move(&op->list, &cur->cooling_list);
	}

This makes the invariant clearer: once an optprobe is forcibly unoptimized,
if it is disabled it is immediately disarmed, regardless of whether it is
queued for freeing or cooling.

Thanks!
quoted hunk ↗ jump to hunk
+						arch_disarm_kprobe(&op->kp);
 					list_move(&op->list, &cur->cooling_list);
 				}
-- 
Masami Hiramatsu (Google) [off-list ref]
Thread (8 messages) 8 messages, 3 authors, last reply 11d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help