The patch titled Subject: kprobes: use synchronize_rcu_tasks_rude in kprobe_optimizer has been added to the -mm mm-nonmm-unstable branch. Its filename is kprobes-use-synchronize_rcu_tasks_rude-in-kprobe_optimizer.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/kprobes-use-synchronize_rcu_tasks_rude-in-kprobe_optimizer.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Chen Zhongjin <chenzhongjin@xxxxxxxxxx> Subject: kprobes: use synchronize_rcu_tasks_rude in kprobe_optimizer Date: Wed, 17 Jan 2024 06:16:36 +0000 There is a deadlock scenario in kprobe_optimizer(): pid A pid B pid C kprobe_optimizer() do_exit() perf_kprobe_init() mutex_lock(&kprobe_mutex) exit_tasks_rcu_start() mutex_lock(&kprobe_mutex) synchronize_rcu_tasks() zap_pid_ns_processes() // waiting kprobe_mutex // waiting tasks_rcu_exit_srcu kernel_wait4() // waiting pid C exit To avoid this deadlock loop, use synchronize_rcu_tasks_rude() in kprobe_optimizer() rather than synchronize_rcu_tasks(). synchronize_rcu_tasks_rude() can also promise that all preempted tasks have scheduled, but it will not wait tasks_rcu_exit_srcu. Link: https://lkml.kernel.org/r/20240117061636.288412-1-chenzhongjin@xxxxxxxxxx Signed-off-by: Chen Zhongjin <chenzhongjin@xxxxxxxxxx> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@xxxxxxxxx> Cc: David S. Miller <davem@xxxxxxxxxxxxx> Cc: Douglas Anderson <dianders@xxxxxxxxxxxx> Cc: Eric DeVolder <eric.devolder@xxxxxxxxxx> Cc: Jakob Koschel <jkl820.git@xxxxxxxxx> Cc: Juerg Haefliger <juerg.haefliger@xxxxxxxxxxxxx> Cc: "Masami Hiramatsu (Google)" <mhiramat@xxxxxxxxxx> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx> (powerpc) Cc: Mickaël Salaün <mic@xxxxxxxxxxx> Cc: "Naveen N. Rao" <naveen.n.rao@xxxxxxxxxxxxx> Cc: Nicholas Piggin <npiggin@xxxxxxxxx> Cc: Paul E. McKenney <paulmck@xxxxxxxxxx> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Cc: Petr Mladek <pmladek@xxxxxxxx> Cc: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Yang Jihong <yangjihong1@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- arch/Kconfig | 2 +- kernel/kprobes.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- a/arch/Kconfig~kprobes-use-synchronize_rcu_tasks_rude-in-kprobe_optimizer +++ a/arch/Kconfig @@ -104,7 +104,7 @@ config STATIC_CALL_SELFTEST config OPTPROBES def_bool y depends on KPROBES && HAVE_OPTPROBES - select TASKS_RCU if PREEMPTION + select TASKS_RUDE_RCU config KPROBES_ON_FTRACE def_bool y --- a/kernel/kprobes.c~kprobes-use-synchronize_rcu_tasks_rude-in-kprobe_optimizer +++ a/kernel/kprobes.c @@ -623,7 +623,7 @@ static void kprobe_optimizer(struct work * Note that on non-preemptive kernel, this is transparently converted * to synchronoze_sched() to wait for all interrupts to have completed. */ - synchronize_rcu_tasks(); + synchronize_rcu_tasks_rude(); /* Step 3: Optimize kprobes after quiesence period */ do_optimize_kprobes(); _ Patches currently in -mm which might be from chenzhongjin@xxxxxxxxxx are kprobes-use-synchronize_rcu_tasks_rude-in-kprobe_optimizer.patch