linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -tip v2] [BUGFIX] kprobes: Skip kretprobe hit in NMI context to avoid deadlock
@ 2014-08-04  3:10 Masami Hiramatsu
  2014-08-08  9:19 ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Masami Hiramatsu @ 2014-08-04  3:10 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-kernel, David S. Miller, Ananth N Mavinakayanahalli

Skip kretprobe hit in NMI context, because if an NMI happens
inside the critical section protected by kretprobe_table.lock
and another(or same) kretprobe hit, pre_kretprobe_handler
tries to lock kretprobe_table.lock again.
Normal interrupts have no problem because they are disabled
with the lock.

Changes in v2:
 - Add unlikely for in_nmi.
 - Add a comment for nmissed counter.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
---
 kernel/kprobes.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 734e9a7..138219b 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1778,6 +1778,16 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
 	unsigned long hash, flags = 0;
 	struct kretprobe_instance *ri;
 
+	/* To avoid deadlock, prohibit return probing in NMI context */
+	if (unlikely(in_nmi())) {
+		/*
+		 * Do not get a lock. nmissed is not accurate.
+		 * This just informs user some misses are happened.
+		 */
+		rp->nmissed++;
+		return 0;
+	}
+
 	/*TODO: consider to only swap the RA after the last pre_handler fired */
 	hash = hash_ptr(current, KPROBE_HASH_BITS);
 	raw_spin_lock_irqsave(&rp->lock, flags);



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

* [tip:perf/urgent] kprobes: Skip kretprobe hit in NMI context to avoid deadlock
  2014-08-04  3:10 [PATCH -tip v2] [BUGFIX] kprobes: Skip kretprobe hit in NMI context to avoid deadlock Masami Hiramatsu
@ 2014-08-08  9:19 ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2014-08-08  9:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, ananth, hpa, mingo, masami.hiramatsu.pt, tglx, davem

Commit-ID:  f96f56780ca584930bb3a2769d73fd9a101bcbbe
Gitweb:     http://git.kernel.org/tip/f96f56780ca584930bb3a2769d73fd9a101bcbbe
Author:     Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
AuthorDate: Mon, 4 Aug 2014 03:10:16 +0000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 8 Aug 2014 10:38:04 +0200

kprobes: Skip kretprobe hit in NMI context to avoid deadlock

Skip kretprobe hit in NMI context, because if an NMI happens
inside the critical section protected by kretprobe_table.lock
and another(or same) kretprobe hit, pre_kretprobe_handler
tries to lock kretprobe_table.lock again.
Normal interrupts have no problem because they are disabled
with the lock.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: David S. Miller <davem@davemloft.net>
Link: http://lkml.kernel.org/r/20140804031016.11433.65539.stgit@kbuild-fedora.novalocal
[ Minor edits for clarity. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 734e9a7..3995f54 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1778,7 +1778,18 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
 	unsigned long hash, flags = 0;
 	struct kretprobe_instance *ri;
 
-	/*TODO: consider to only swap the RA after the last pre_handler fired */
+	/*
+	 * To avoid deadlocks, prohibit return probing in NMI contexts,
+	 * just skip the probe and increase the (inexact) 'nmissed'
+	 * statistical counter, so that the user is informed that
+	 * something happened:
+	 */
+	if (unlikely(in_nmi())) {
+		rp->nmissed++;
+		return 0;
+	}
+
+	/* TODO: consider to only swap the RA after the last pre_handler fired */
 	hash = hash_ptr(current, KPROBE_HASH_BITS);
 	raw_spin_lock_irqsave(&rp->lock, flags);
 	if (!hlist_empty(&rp->free_instances)) {

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

end of thread, other threads:[~2014-08-08  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-04  3:10 [PATCH -tip v2] [BUGFIX] kprobes: Skip kretprobe hit in NMI context to avoid deadlock Masami Hiramatsu
2014-08-08  9:19 ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu

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).