linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Ingo Molnar <mingo@kernel.org>,
	"Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H . Peter Anvin" <hpa@zytor.com>
Subject: [PATCH -tip v2] Enable optprobe on preepmtive kernel
Date: Tue, 12 Sep 2017 10:10:12 +0900	[thread overview]
Message-ID: <150517861179.26279.7649250983151178165.stgit@devbox> (raw)

This patch enables optprobe even with CONFIG_PREEMPT. The
previous patch is https://lkml.org/lkml/2017/5/24/464 .

With Paul's hack (https://lkml.org/lkml/2017/5/25/435),
now synchronize_rcu_tasks() is translated to synchronize_sched()
when TASKS_RCU=n. So this patch just replace the
synchronize_sched() with synchronize_rcu_tasks() and
select TASKS_RCU if PREEMPT=y & OPTPROBES=y. 

Here is the reason why this change is needed.
Since the jump optimized kprobes can replace multiple
instructions, there can be tasks which are interrupted
on the 2nd (or 3rd) instructions. If the kprobe
replaces those instructions by a jump instruction,
when those tasks back to the interrupted place, it is
a middle of the jump instruction and causes a kernel
panic.

To avoid such tragedies in advance, kprobe optimizer
prepare a detour route using normal kprobe (e.g.
int3 breakpoint on x86), and wait for the tasks which
is interrrupted on such place by synchronize_sched()
when CONFIG_PREEMPT=n.

If CONFIG_PREEMPT=y, things be more complicated, because
such interrupted thread can be preempted (other thread
can be scheduled in interrupt handler.) This means we
can not ensure all tasks run in safe zone by
synchronize_sched().

However, we have synchronize_rcu_tasks() which can
ensure that all preempted tasks back on track and
scheduled. kprobes optimizer can wait for those preempted
tasks scheduled normally by synchronize_rcu_tasks().

Thank you,

---

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


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

--
Masami Hiramatsu <mhiramat@kernel.org>

             reply	other threads:[~2017-09-12  1:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-12  1:10 Masami Hiramatsu [this message]
2017-09-12  1:10 ` [PATCH -tip v2] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT Masami Hiramatsu
2017-09-12  4:04   ` Paul E. McKenney
2017-09-14  4:28   ` [lkp-robot] [kprobes] e1ce3eee7d: BUG:using_smp_processor_id()in_preemptible kernel test robot
2017-09-14 10:22     ` Masami Hiramatsu
2017-09-15  0:12     ` Masami Hiramatsu

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=150517861179.26279.7649250983151178165.stgit@devbox \
    --to=mhiramat@kernel.org \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).