Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753017AbdI1K5r (ORCPT ); Thu, 28 Sep 2017 06:57:47 -0400 Received: from terminus.zytor.com ([65.50.211.136]:48497 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752947AbdI1K5p (ORCPT ); Thu, 28 Sep 2017 06:57:45 -0400 Date: Thu, 28 Sep 2017 03:54:10 -0700 From: tip-bot for Masami Hiramatsu Message-ID: Cc: hpa@zytor.com, tglx@linutronix.de, paulmck@linux.vnet.ibm.com, mhiramat@kernel.org, ast@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, rostedt@goodmis.org, peterz@infradead.org, ast@fb.com, torvalds@linux-foundation.org, ananth@linux.vnet.ibm.com Reply-To: linux-kernel@vger.kernel.org, mingo@kernel.org, rostedt@goodmis.org, torvalds@linux-foundation.org, ast@fb.com, peterz@infradead.org, ananth@linux.vnet.ibm.com, hpa@zytor.com, tglx@linutronix.de, ast@kernel.org, mhiramat@kernel.org, paulmck@linux.vnet.ibm.com In-Reply-To: <150581530024.32348.9863783558598926771.stgit@devbox> References: <150581530024.32348.9863783558598926771.stgit@devbox> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] kprobes/x86: Disable preemption in ftrace-based jprobes Git-Commit-ID: 5bb4fc2d8641219732eb2bb654206775a4219aca X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3187 Lines: 92 Commit-ID: 5bb4fc2d8641219732eb2bb654206775a4219aca Gitweb: https://git.kernel.org/tip/5bb4fc2d8641219732eb2bb654206775a4219aca Author: Masami Hiramatsu AuthorDate: Tue, 19 Sep 2017 19:01:40 +0900 Committer: Ingo Molnar CommitDate: Thu, 28 Sep 2017 09:23:04 +0200 kprobes/x86: Disable preemption in ftrace-based jprobes Disable preemption in ftrace-based jprobe handlers as described in Documentation/kprobes.txt: "Probe handlers are run with preemption disabled." This will fix jprobes behavior when CONFIG_PREEMPT=y. Signed-off-by: Masami Hiramatsu Cc: Alexei Starovoitov Cc: Alexei Starovoitov Cc: Ananth N Mavinakayanahalli Cc: Linus Torvalds Cc: Paul E . McKenney Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/150581530024.32348.9863783558598926771.stgit@devbox Signed-off-by: Ingo Molnar --- arch/x86/kernel/kprobes/ftrace.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c index 041f7b6..bcfee4f 100644 --- a/arch/x86/kernel/kprobes/ftrace.c +++ b/arch/x86/kernel/kprobes/ftrace.c @@ -26,7 +26,7 @@ #include "common.h" static nokprobe_inline -int __skip_singlestep(struct kprobe *p, struct pt_regs *regs, +void __skip_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb, unsigned long orig_ip) { /* @@ -41,20 +41,21 @@ int __skip_singlestep(struct kprobe *p, struct pt_regs *regs, __this_cpu_write(current_kprobe, NULL); if (orig_ip) regs->ip = orig_ip; - return 1; } int skip_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb) { - if (kprobe_ftrace(p)) - return __skip_singlestep(p, regs, kcb, 0); - else - return 0; + if (kprobe_ftrace(p)) { + __skip_singlestep(p, regs, kcb, 0); + preempt_enable_no_resched(); + return 1; + } + return 0; } NOKPROBE_SYMBOL(skip_singlestep); -/* Ftrace callback handler for kprobes */ +/* Ftrace callback handler for kprobes -- called under preepmt disabed */ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *ops, struct pt_regs *regs) { @@ -77,13 +78,17 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */ regs->ip = ip + sizeof(kprobe_opcode_t); + /* To emulate trap based kprobes, preempt_disable here */ + preempt_disable(); __this_cpu_write(current_kprobe, p); kcb->kprobe_status = KPROBE_HIT_ACTIVE; - if (!p->pre_handler || !p->pre_handler(p, regs)) + if (!p->pre_handler || !p->pre_handler(p, regs)) { __skip_singlestep(p, regs, kcb, orig_ip); + preempt_enable_no_resched(); + } /* * If pre_handler returns !0, it sets regs->ip and - * resets current kprobe. + * resets current kprobe, and keep preempt count +1. */ } end: