From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Subject: [PATCH -tip v2] [BUGFIX] kprobes: Skip kretprobe hit in NMI context to avoid deadlock
Date: Mon, 04 Aug 2014 03:10:16 +0000 [thread overview]
Message-ID: <20140804031016.11433.65539.stgit@kbuild-fedora.novalocal> (raw)
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);
next reply other threads:[~2014-08-04 3:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-04 3:10 Masami Hiramatsu [this message]
2014-08-08 9:19 ` [tip:perf/urgent] " tip-bot for 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=20140804031016.11433.65539.stgit@kbuild-fedora.novalocal \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=ananth@in.ibm.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
/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
all inboxes | Powered by JetHome®