Skip to content

Commit a30b85d

Browse files
mhiramatIngo Molnar
authored andcommitted
kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y
We want to wait for all potentially preempted kprobes trampoline execution to have completed. This guarantees that any freed trampoline memory is not in use by any task in the system anymore. synchronize_rcu_tasks() gives such a guarantee, so use it. Also, this guarantees to wait for all potentially preempted tasks on the instructions which will be replaced with a jump. Since this becomes a problem only when CONFIG_PREEMPT=y, enable CONFIG_TASKS_RCU=y for synchronize_rcu_tasks() in that case. Signed-off-by: Masami Hiramatsu <[email protected]> Acked-by: Paul E. McKenney <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Naveen N . Rao <[email protected]> Cc: Paul E . McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/150845661962.5443.17724352636247312231.stgit@devbox Signed-off-by: Ingo Molnar <[email protected]>
1 parent 4f3a871 commit a30b85d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

arch/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ config STATIC_KEYS_SELFTEST
9090
config OPTPROBES
9191
def_bool y
9292
depends on KPROBES && HAVE_OPTPROBES
93-
depends on !PREEMPT
93+
select TASKS_RCU if PREEMPT
9494

9595
config KPROBES_ON_FTRACE
9696
def_bool y

kernel/kprobes.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,15 @@ static void kprobe_optimizer(struct work_struct *work)
573573
do_unoptimize_kprobes();
574574

575575
/*
576-
* Step 2: Wait for quiesence period to ensure all running interrupts
577-
* are done. Because optprobe may modify multiple instructions
578-
* there is a chance that Nth instruction is interrupted. In that
579-
* case, running interrupt can return to 2nd-Nth byte of jump
580-
* instruction. This wait is for avoiding it.
576+
* Step 2: Wait for quiesence period to ensure all potentially
577+
* preempted tasks to have normally scheduled. Because optprobe
578+
* may modify multiple instructions, there is a chance that Nth
579+
* instruction is preempted. In that case, such tasks can return
580+
* to 2nd-Nth byte of jump instruction. This wait is for avoiding it.
581+
* Note that on non-preemptive kernel, this is transparently converted
582+
* to synchronoze_sched() to wait for all interrupts to have completed.
581583
*/
582-
synchronize_sched();
584+
synchronize_rcu_tasks();
583585

584586
/* Step 3: Optimize kprobes after quiesence period */
585587
do_optimize_kprobes();

0 commit comments

Comments
 (0)