From: Masami Hiramatsu <mhiramat@kernel.org>
To: linux-kernel@vger.kernel.org, Peter Zijlstra <peterz@infradead.org>
Cc: Eddy Wu <Eddy_Wu@trendmicro.com>,
x86@kernel.org, "David S . Miller" <davem@davemloft.net>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
"Naveen N . Rao" <naveen.n.rao@linux.ibm.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
linux-arch@vger.kernel.org
Subject: [PATCH v2 14/15] kprobes: Remove NMI context check
Date: Thu, 27 Aug 2020 20:37:38 +0900 [thread overview]
Message-ID: <159852825822.707944.12873921829000019667.stgit@devnote2> (raw)
In-Reply-To: <159852811819.707944.12798182250041968537.stgit@devnote2>
Since the commit 9b38cc704e84 ("kretprobe: Prevent triggering
kretprobe from within kprobe_flush_task") sets a dummy current
kprobe in the trampoline handler by kprobe_busy_begin/end(),
it is not possible to run a kretprobe pre handler in kretprobe
trampoline handler context even with the NMI. If the NMI interrupts
a kretprobe_trampoline_handler() and it hits a kretprobe, the
2nd kretprobe will detect recursion correctly and it will be
skipped.
This means we have almost no double-lock issue on kretprobes by NMI.
The last one point is in cleanup_rp_inst() which also takes
kretprobe_table_lock without setting up current kprobes.
So adding kprobe_busy_begin/end() there allows us to remove
in_nmi() check.
The above commit applies kprobe_busy_begin/end() on x86, but
now all arch implementation are unified to generic one, we can
safely remove the in_nmi() check from arch independent code.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
kernel/kprobes.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index cbd2ad1af7b7..311033e4b8e4 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1359,7 +1359,8 @@ static void cleanup_rp_inst(struct kretprobe *rp)
struct hlist_node *next;
struct hlist_head *head;
- /* No race here */
+ /* To avoid recursive kretprobe by NMI, set kprobe busy here */
+ kprobe_busy_begin();
for (hash = 0; hash < KPROBE_TABLE_SIZE; hash++) {
kretprobe_table_lock(hash, &flags);
head = &kretprobe_inst_table[hash];
@@ -1369,6 +1370,8 @@ static void cleanup_rp_inst(struct kretprobe *rp)
}
kretprobe_table_unlock(hash, &flags);
}
+ kprobe_busy_end();
+
free_rp_inst(rp);
}
NOKPROBE_SYMBOL(cleanup_rp_inst);
@@ -2038,17 +2041,6 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
unsigned long hash, flags = 0;
struct kretprobe_instance *ri;
- /*
- * 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);
next prev parent reply other threads:[~2020-08-27 11:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 11:35 [PATCH v2 00/15] kprobes: Unify kretprobe trampoline handlers Masami Hiramatsu
2020-08-27 11:35 ` [PATCH v2 01/15] kprobes: Add generic kretprobe trampoline handler Masami Hiramatsu
2020-08-27 11:35 ` [PATCH v2 02/15] x86/kprobes: Use " Masami Hiramatsu
2020-08-27 11:35 ` [PATCH v2 03/15] arm: kprobes: " Masami Hiramatsu
2020-08-27 11:35 ` [PATCH v2 04/15] arm64: " Masami Hiramatsu
2020-08-27 11:36 ` [PATCH v2 05/15] arc: " Masami Hiramatsu
2020-08-27 11:36 ` [PATCH v2 06/15] csky: " Masami Hiramatsu
2020-08-27 11:36 ` [PATCH v2 07/15] ia64: " Masami Hiramatsu
2020-08-27 11:36 ` [PATCH v2 08/15] mips: " Masami Hiramatsu
2020-08-27 11:36 ` [PATCH v2 09/15] parisc: " Masami Hiramatsu
2020-08-27 11:36 ` [PATCH v2 10/15] powerpc: " Masami Hiramatsu
2020-08-27 11:37 ` [PATCH v2 11/15] s390: " Masami Hiramatsu
2020-08-27 11:37 ` [PATCH v2 12/15] sh: " Masami Hiramatsu
2020-08-27 11:37 ` [PATCH v2 13/15] sparc: " Masami Hiramatsu
2020-08-27 11:37 ` Masami Hiramatsu [this message]
2020-08-27 11:37 ` [PATCH v2 15/15] kprobes: Free kretprobe_instance with rcu callback Masami Hiramatsu
2020-08-27 11:48 ` peterz
2020-08-27 11:50 ` Masami Hiramatsu
2020-08-27 11:49 ` peterz
2020-08-27 13:02 ` 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=159852825822.707944.12873921829000019667.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=Eddy_Wu@trendmicro.com \
--cc=anil.s.keshavamurthy@intel.com \
--cc=davem@davemloft.net \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=naveen.n.rao@linux.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=x86@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;
as well as URLs for NNTP newsgroup(s).