Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiri Olsa" <jolsa@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH 09/13] x86/kprobes: Use kprobe iterator in arch_check_optimized_kprobe
Date: Wed, 11 Nov 2026 00:17:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-208007@kernel.org> (raw)
In-Reply-To: <20261109195731.1091241-1-jolsa@kernel.org>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] kprobes: sibling re-optimization failure in __disarm_kprobe()
  [1]
--

commit 8174a2b0aeefac5511bfa58a9428f79328aae112
Author: Jiri Olsa <jolsa@kernel.org>

x86/kprobes: Use kprobe iterator in arch_check_optimized_kprobe

This commit replaces the byte-by-byte get_kprobe() lookups in
arch_check_optimized_kprobe() with for_each_kprobe() over the optimized
instruction range.

> diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
> index 9da41424be777..cdf69c939631d 100644
> --- a/arch/x86/kernel/kprobes/opt.c
> +++ b/arch/x86/kernel/kprobes/opt.c
> @@ -334,12 +334,13 @@ static int can_optimize(unsigned long paddr)
>  /* Check optimized_kprobe can actually be optimized. */
>  int arch_check_optimized_kprobe(struct optimized_kprobe *op)
>  {
> -	int i;
> +	unsigned long start = (unsigned long)op->kp.addr;
> +	unsigned long end = start + op->optinsn.size - 1;
> +	struct kprobe_iter iter;
>  	struct kprobe *p;
>  
> -	for (i = 1; i < op->optinsn.size; i++) {
> -		p = get_kprobe(op->kp.addr + i);
> -		if (p && !kprobe_disarmed(p))
> +	for_each_kprobe(iter, p, start + 1, end) {
> +		if (!kprobe_disarmed(p))
>  			return -EEXIST;
>  	}

[Severity: Medium]
This problem wasn't introduced by this patch, but can kprobe_disarmed(p)
here reject sibling re-optimization during __disable_kprobe() [1]?

In __disable_kprobe(), disarm_kprobe(orig_p, true) runs before
KPROBE_FLAG_DISABLED is set on orig_p->flags:

kernel/kprobes.c:__disable_kprobe() {
	...
		if (!kprobes_all_disarmed && !kprobe_disabled(orig_p)) {
			ret = disarm_kprobe(orig_p, true);
			if (ret) {
				p->flags &= ~KPROBE_FLAG_DISABLED;
				return ERR_PTR(ret);
			}
		}
		orig_p->flags |= KPROBE_FLAG_DISABLED;
	...
}

When __disarm_kprobe() disarms a probe that overlapped the jump range of a
sibling optprobe, it calls optimize_kprobe() -> arch_check_optimized_kprobe()
to re-optimize that sibling.  Because orig_p is still registered and lacks
KPROBE_FLAG_DISABLED at that point, kprobe_disarmed(orig_p) returns false
and arch_check_optimized_kprobe() fails with -EEXIST, leaving the sibling
probe permanently unoptimized.

[1] https://sashiko.dev/#/bug/linux-504cacc5-65e4-4f67-bdd9-fa0c7244bee6

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109194916.1089703-1-jolsa@kernel.org?part=9

  reply	other threads:[~2026-11-11  0:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 19:49 [PATCH 00/13] kprobes: Reduce registration and optimization lookup costs Jiri Olsa
2026-11-09 19:49 ` [PATCH 01/13] static_call: Index code text reservation lookups Jiri Olsa
2026-11-09 19:49 ` [PATCH 02/13] jump_label: Index " Jiri Olsa
2026-11-09 19:49 ` [PATCH 03/13] jump_label/x86: Avoid decoding instructions for jump entry size Jiri Olsa
2026-11-09 19:55 ` [PATCH 04/13] kprobes: Maintain an rbtree of registered probes Jiri Olsa
2026-11-10  8:12   ` Masami Hiramatsu (Google)
2026-11-10 10:37     ` Jiri Olsa
2026-11-10 15:38       ` Masami Hiramatsu (Google)
2026-11-11 10:49         ` Jiri Olsa
2026-11-10 23:45   ` sashiko-bot
2026-11-09 19:56 ` [PATCH 05/13] kprobes: Add an iterator for address ranges Jiri Olsa
2026-11-09 19:56 ` [PATCH 06/13] kprobes: Add an address iterator for probe lookup Jiri Olsa
2026-11-09 19:56 ` [PATCH 07/13] kprobes: Use kprobe iterator in get_optimized_kprobe Jiri Olsa
2026-11-09 19:57 ` [PATCH 08/13] x86/kprobes: Use kprobe iterator in __recover_optprobed_insn Jiri Olsa
2026-11-09 19:57 ` [PATCH 09/13] x86/kprobes: Use kprobe iterator in arch_check_optimized_kprobe Jiri Olsa
2026-11-11  0:17   ` sashiko-bot [this message]
2026-11-09 19:57 ` [PATCH 10/13] x86/kprobes: Use kprobe address iterator in can_optimize Jiri Olsa
2026-11-09 19:57 ` [PATCH 11/13] x86/kprobes: Use kprobe address iterator in can_probe Jiri Olsa
2026-11-09 19:58 ` [PATCH 12/13] x86/kprobes: Use kprobe address iterator in in copy_optimized_instructions Jiri Olsa
2026-11-09 19:58 ` [PATCH 13/13] samples/kprobes: Add batch probe example Jiri Olsa
2026-11-11  0:49   ` sashiko-bot
2026-11-11  2:20   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-208007@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox