All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -tip v4] Enable optprobe on preepmtive kernel
@ 2017-10-19 23:43 Masami Hiramatsu
  2017-10-19 23:43 ` [PATCH -tip v4] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2017-10-19 23:43 UTC (permalink / raw)
  To: Ingo Molnar, Paul E . McKenney
  Cc: Steven Rostedt, Masami Hiramatsu, linux-kernel, Peter Zijlstra,
	Ananth N Mavinakayanahalli, Thomas Gleixner, H . Peter Anvin,
	Naveen N . Rao

This patch enables optprobe even with CONFIG_PREEMPT. The
previous patch is  https://lkml.org/lkml/2017/9/19/159 .

Sorry for taking so long to update.
I've update the patch description according to Ingo's comment
but the code is same.

Thank you,

---

Masami Hiramatsu (1):
      kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT


 arch/Kconfig     |    2 +-
 kernel/kprobes.c |   14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

--
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH -tip v4] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT
  2017-10-19 23:43 [PATCH -tip v4] Enable optprobe on preepmtive kernel Masami Hiramatsu
@ 2017-10-19 23:43 ` Masami Hiramatsu
  2017-10-19 23:55   ` Paul E. McKenney
  2017-10-20 12:24   ` [tip:perf/core] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y tip-bot for Masami Hiramatsu
  0 siblings, 2 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2017-10-19 23:43 UTC (permalink / raw)
  To: Ingo Molnar, Paul E . McKenney
  Cc: Steven Rostedt, Masami Hiramatsu, linux-kernel, Peter Zijlstra,
	Ananth N Mavinakayanahalli, Thomas Gleixner, H . Peter Anvin,
	Naveen N . Rao

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 <mhiramat@kernel.org>
---
 arch/Kconfig     |    2 +-
 kernel/kprobes.c |   14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index d789a89cb32c..7e67191a4961 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -90,7 +90,7 @@ config STATIC_KEYS_SELFTEST
 config OPTPROBES
 	def_bool y
 	depends on KPROBES && HAVE_OPTPROBES
-	depends on !PREEMPT
+	select TASKS_RCU if PREEMPT
 
 config KPROBES_ON_FTRACE
 	def_bool y
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 15fba7fe57c8..a8fc1492b308 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -573,13 +573,15 @@ static void kprobe_optimizer(struct work_struct *work)
 	do_unoptimize_kprobes();
 
 	/*
-	 * Step 2: Wait for quiesence period to ensure all running interrupts
-	 * are done. Because optprobe may modify multiple instructions
-	 * there is a chance that Nth instruction is interrupted. In that
-	 * case, running interrupt can return to 2nd-Nth byte of jump
-	 * instruction. This wait is for avoiding it.
+	 * Step 2: Wait for quiesence period to ensure all potentially
+	 * preempted tasks to have normally scheduled. Because optprobe
+	 * may modify multiple instructions, there is a chance that Nth
+	 * instruction is preempted. In that case, such tasks can return
+	 * to 2nd-Nth byte of jump instruction. This wait is for avoiding it.
+	 * Note that on non-preemptive kernel, this is transparently converted
+	 * to synchronoze_sched() to wait for all interrupts to have completed.
 	 */
-	synchronize_sched();
+	synchronize_rcu_tasks();
 
 	/* Step 3: Optimize kprobes after quiesence period */
 	do_optimize_kprobes();

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -tip v4] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT
  2017-10-19 23:43 ` [PATCH -tip v4] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT Masami Hiramatsu
@ 2017-10-19 23:55   ` Paul E. McKenney
  2017-10-20 12:24   ` [tip:perf/core] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2017-10-19 23:55 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Steven Rostedt, linux-kernel, Peter Zijlstra,
	Ananth N Mavinakayanahalli, Thomas Gleixner, H . Peter Anvin,
	Naveen N . Rao

On Fri, Oct 20, 2017 at 08:43:39AM +0900, Masami Hiramatsu wrote:
> 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 <mhiramat@kernel.org>

;-)

Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

> ---
>  arch/Kconfig     |    2 +-
>  kernel/kprobes.c |   14 ++++++++------
>  2 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/Kconfig b/arch/Kconfig
> index d789a89cb32c..7e67191a4961 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -90,7 +90,7 @@ config STATIC_KEYS_SELFTEST
>  config OPTPROBES
>  	def_bool y
>  	depends on KPROBES && HAVE_OPTPROBES
> -	depends on !PREEMPT
> +	select TASKS_RCU if PREEMPT
> 
>  config KPROBES_ON_FTRACE
>  	def_bool y
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 15fba7fe57c8..a8fc1492b308 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -573,13 +573,15 @@ static void kprobe_optimizer(struct work_struct *work)
>  	do_unoptimize_kprobes();
> 
>  	/*
> -	 * Step 2: Wait for quiesence period to ensure all running interrupts
> -	 * are done. Because optprobe may modify multiple instructions
> -	 * there is a chance that Nth instruction is interrupted. In that
> -	 * case, running interrupt can return to 2nd-Nth byte of jump
> -	 * instruction. This wait is for avoiding it.
> +	 * Step 2: Wait for quiesence period to ensure all potentially
> +	 * preempted tasks to have normally scheduled. Because optprobe
> +	 * may modify multiple instructions, there is a chance that Nth
> +	 * instruction is preempted. In that case, such tasks can return
> +	 * to 2nd-Nth byte of jump instruction. This wait is for avoiding it.
> +	 * Note that on non-preemptive kernel, this is transparently converted
> +	 * to synchronoze_sched() to wait for all interrupts to have completed.
>  	 */
> -	synchronize_sched();
> +	synchronize_rcu_tasks();
> 
>  	/* Step 3: Optimize kprobes after quiesence period */
>  	do_optimize_kprobes();
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:perf/core] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y
  2017-10-19 23:43 ` [PATCH -tip v4] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT Masami Hiramatsu
  2017-10-19 23:55   ` Paul E. McKenney
@ 2017-10-20 12:24   ` tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2017-10-20 12:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ananth, rostedt, torvalds, mingo, hpa, mhiramat, paulmck,
	linux-kernel, peterz, naveen.n.rao, tglx

Commit-ID:  a30b85df7d599f626973e9cd3056fe755bd778e0
Gitweb:     https://git.kernel.org/tip/a30b85df7d599f626973e9cd3056fe755bd778e0
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Fri, 20 Oct 2017 08:43:39 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 20 Oct 2017 09:45:15 +0200

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 <mhiramat@kernel.org>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Paul E . McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/150845661962.5443.17724352636247312231.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/Kconfig     |  2 +-
 kernel/kprobes.c | 14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 1aafb4e..f75c8e8 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -90,7 +90,7 @@ config STATIC_KEYS_SELFTEST
 config OPTPROBES
 	def_bool y
 	depends on KPROBES && HAVE_OPTPROBES
-	depends on !PREEMPT
+	select TASKS_RCU if PREEMPT
 
 config KPROBES_ON_FTRACE
 	def_bool y
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 15fba7f..a8fc149 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -573,13 +573,15 @@ static void kprobe_optimizer(struct work_struct *work)
 	do_unoptimize_kprobes();
 
 	/*
-	 * Step 2: Wait for quiesence period to ensure all running interrupts
-	 * are done. Because optprobe may modify multiple instructions
-	 * there is a chance that Nth instruction is interrupted. In that
-	 * case, running interrupt can return to 2nd-Nth byte of jump
-	 * instruction. This wait is for avoiding it.
+	 * Step 2: Wait for quiesence period to ensure all potentially
+	 * preempted tasks to have normally scheduled. Because optprobe
+	 * may modify multiple instructions, there is a chance that Nth
+	 * instruction is preempted. In that case, such tasks can return
+	 * to 2nd-Nth byte of jump instruction. This wait is for avoiding it.
+	 * Note that on non-preemptive kernel, this is transparently converted
+	 * to synchronoze_sched() to wait for all interrupts to have completed.
 	 */
-	synchronize_sched();
+	synchronize_rcu_tasks();
 
 	/* Step 3: Optimize kprobes after quiesence period */
 	do_optimize_kprobes();

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-10-20 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-19 23:43 [PATCH -tip v4] Enable optprobe on preepmtive kernel Masami Hiramatsu
2017-10-19 23:43 ` [PATCH -tip v4] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT Masami Hiramatsu
2017-10-19 23:55   ` Paul E. McKenney
2017-10-20 12:24   ` [tip:perf/core] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y tip-bot for Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.