Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Josef Bacik" <josef@toxicpanda.com>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RFC v2 04/15] kprobes: Let Tasks RCU recognise tasks preempted in an optprobe jump window
Date: Fri, 11 Sep 2026 14:26:26 +0000	[thread overview]
Message-ID: <20260911142626.ACAED1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911-b4-rcu-tasks-preempt-qs-v2-4-eaaa61ed2da4@toxicpanda.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Lockless traversal of the RCU-protected `kprobe_table` in `kprobe_in_optimized_region()` lacks `rcu_read_lock()`, leading to lockdep splats on PREEMPT_RCU kernels.
--

commit dc16333e12fedda231a4417b135bef649425955b
Author: Josef Bacik <josef@toxicpanda.com>

kprobes: Let Tasks RCU recognise tasks preempted in an optprobe jump window

This commit adds a lockless check kprobe_in_optimized_region() to allow Tasks
RCU to recognize tasks preempted within an instruction boundary about to be
overwritten by an optimized jump kprobe. It evaluates registered kprobes 
inside the optimizer's Tasks RCU grace period.

> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 6337da5cab9e7..cf2ea278fdf5b 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c

[ ... ]

> @@ -511,6 +511,48 @@ static struct kprobe *get_optimized_kprobe(kprobe_opcode_t *addr)
>  	return NULL;
>  }
>  
> +/*
> + * True while kprobe_optimizer() is waiting for its Tasks RCU grace period.
> + * Only in that window can a preemption inside an optprobe's jump region
> + * matter to it, so kprobe_in_optimized_region() does no work otherwise.
> + */
> +static bool kprobe_optimizer_waiting;
> +
> +/**
> + * kprobe_in_optimized_region - Could @addr be inside bytes a jump-optimized
> + *	kprobe replaces?
> + * @addr: kernel text address, typically an interrupted instruction pointer
> + *
> + * kprobe_optimizer() relies on synchronize_rcu_tasks() to wait for tasks that
> + * were preempted on an instruction boundary inside the region about to be
> + * overwritten by the optimized jump; such a task must not report a Tasks RCU
> + * quiescent state when it is preempted (see rcu_tasks_ip_in_trampoline()).
> + * This is the lockless, conservative form of get_optimized_kprobe(): it does
> + * not care whether the kprobe found is, or ever will be, optimized.  May be
> + * called from any context with preemption disabled; the kprobe hash is
> + * RCU-protected and every free path waits for a grace period after unhashing.
> + *
> + * The hash walk only runs while the optimizer is actually waiting.  A
> + * preemption that does not observe kprobe_optimizer_waiting predates the
> + * grace period (its leading synchronize_rcu() publishes the store to every
> + * interrupts-disabled reader before any task is sampled as a holdout); such a
> + * task is then an ordinary preempted holdout, and the jump is not written
> + * until it has run again and left the region.
> + */
> +bool kprobe_in_optimized_region(unsigned long addr)
> +{
> +	int i;
> +
> +	if (!READ_ONCE(kprobe_optimizer_waiting))
> +		return false;
> +
> +	for (i = 1; i < MAX_OPTIMIZED_LENGTH / sizeof(kprobe_opcode_t); i++)
> +		if (get_kprobe((kprobe_opcode_t *)addr - i))

[Severity: Medium]
When kprobe_in_optimized_region() calls get_kprobe(), neither rcu_read_lock()
nor kprobe_mutex is held (for example, when called from the Tasks RCU GP
kthread).

get_kprobe() iterates the hash list using:

    hlist_for_each_entry_rcu(p, head, hlist,
                             lockdep_is_held(&kprobe_mutex)) {

Without explicitly acquiring rcu_read_lock() around get_kprobe(), lockdep
will complain about suspicious RCU usage, because preempt_disable() (or
running from a kthread) does not satisfy rcu_read_lock_held() on
CONFIG_PREEMPT_RCU.

Could this lockless traversal of kprobe_table trigger a lockdep warning on
PREEMPT_RCU kernels?

> +			return true;
> +	return false;
> +}
> +NOKPROBE_SYMBOL(kprobe_in_optimized_region);
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911-b4-rcu-tasks-preempt-qs-v2-0-eaaa61ed2da4@toxicpanda.com?part=4

  reply	other threads:[~2026-09-11 14:26 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 14:08 [PATCH RFC v2 00/15] rcu-tasks: let preemption outside trampolines be a quiescent state Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 01/15] rcu-tasks: Add per-task trampoline nesting count Josef Bacik
2026-09-11 17:23   ` Paul E. McKenney
2026-09-11 14:08 ` [PATCH RFC v2 02/15] entry: Pass pt_regs to irqentry_exit_cond_resched() Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 03/15] rcu-tasks: Hold trampoline nesting across irq-exit preemption in trampoline text Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 04/15] kprobes: Let Tasks RCU recognise tasks preempted in an optprobe jump window Josef Bacik
2026-09-11 14:26   ` sashiko-bot [this message]
2026-09-11 17:27     ` Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 05/15] ftrace: Mark modules hosting direct-call trampolines for Tasks RCU Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 06/15] x86/ftrace: Maintain Tasks RCU trampoline nesting in ftrace_caller Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 07/15] x86/kprobes: Maintain Tasks RCU trampoline nesting in the optprobe template Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 08/15] bpf, x86: Maintain Tasks RCU trampoline nesting in the BPF trampoline Josef Bacik
2026-09-12  3:27   ` Alexei Starovoitov
2026-09-12  5:10     ` Paul E. McKenney
2026-09-12 17:18       ` Alexei Starovoitov
2026-09-12 18:03         ` Paul E. McKenney
2026-09-12 19:40           ` Alexei Starovoitov
2026-09-12 22:28             ` Paul E. McKenney
2026-09-12 23:59               ` Alexei Starovoitov
2026-09-13  3:07                 ` Paul E. McKenney
2026-09-12 21:14           ` David Laight
2026-09-12 22:31             ` Paul E. McKenney
2026-09-13 11:28               ` David Laight
2026-09-13 18:20                 ` Paul E. McKenney
2026-09-11 14:08 ` [PATCH RFC v2 09/15] arm64: ftrace: Maintain Tasks RCU trampoline nesting in ftrace_caller Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 10/15] bpf, arm64: Maintain Tasks RCU trampoline nesting in the BPF trampoline Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 11/15] samples: ftrace: Maintain Tasks RCU trampoline nesting in direct-call trampolines Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 12/15] rcutorture: Bracket Tasks RCU readers with trampoline nesting Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 13/15] rcu-tasks: Treat preemption outside trampolines as a quiescent state Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 14/15] rcu-tasks: Retire switched-out tasks with no trampoline nesting at scan time Josef Bacik
2026-09-11 14:08 ` [PATCH RFC v2 15/15] rcu-tasks: Kick running holdouts through the scheduler Josef Bacik
2026-09-11 18:46   ` Paul E. McKenney
2026-09-13  7:13 ` [PATCH RFC v2 00/15] rcu-tasks: let preemption outside trampolines be a quiescent state Yafang Shao

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=20260911142626.ACAED1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=josef@toxicpanda.com \
    --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