From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751759AbdBOE2X (ORCPT ); Tue, 14 Feb 2017 23:28:23 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36576 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751543AbdBOE2W (ORCPT ); Tue, 14 Feb 2017 23:28:22 -0500 Date: Wed, 15 Feb 2017 09:58:14 +0530 From: Ananth N Mavinakayanahalli To: "Naveen N. Rao" Cc: Masami Hiramatsu , Michael Ellerman , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH 1/3] powerpc: kprobes: add support for KPROBES_ON_FTRACE Reply-To: ananth@linux.vnet.ibm.com References: <1cc8a5580ae3a642fea137b7fe9c526402d4af33.1487098440.git.naveen.n.rao@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1cc8a5580ae3a642fea137b7fe9c526402d4af33.1487098440.git.naveen.n.rao@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17021504-8235-0000-0000-00000AF72AF3 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006618; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000203; SDB=6.00822117; UDB=6.00402157; IPR=6.00599570; BA=6.00005137; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014285; XFM=3.00000011; UTC=2017-02-15 04:28:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17021504-8236-0000-0000-0000399AD24B Message-Id: <20170215042814.GA4660@in.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-02-15_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702150044 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 15, 2017 at 12:28:34AM +0530, Naveen N. Rao wrote: > Allow kprobes to be placed on ftrace _mcount() call sites. This > optimization avoids the use of a trap, by riding on ftrace > infrastructure. > > This depends on HAVE_DYNAMIC_FTRACE_WITH_REGS which depends on > MPROFILE_KERNEL, which is only currently enabled on powerpc64le with > newer toolchains. > > Based on the x86 code by Masami. > > Signed-off-by: Naveen N. Rao > --- > arch/powerpc/Kconfig | 1 + > arch/powerpc/include/asm/kprobes.h | 10 ++++ > arch/powerpc/kernel/Makefile | 3 ++ > arch/powerpc/kernel/kprobes-ftrace.c | 100 +++++++++++++++++++++++++++++++++++ > arch/powerpc/kernel/kprobes.c | 4 +- > arch/powerpc/kernel/optprobes.c | 3 ++ > 6 files changed, 120 insertions(+), 1 deletion(-) > create mode 100644 arch/powerpc/kernel/kprobes-ftrace.c You'll also need to update Documentation/features/debug/kprobes-on-ftrace/arch-support.txt > +/* Ftrace callback handler for kprobes */ > +void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip, > + struct ftrace_ops *ops, struct pt_regs *regs) > +{ > + struct kprobe *p; > + struct kprobe_ctlblk *kcb; > + unsigned long flags; > + > + /* Disable irq for emulating a breakpoint and avoiding preempt */ > + local_irq_save(flags); > + hard_irq_disable(); > + > + p = get_kprobe((kprobe_opcode_t *)nip); > + if (unlikely(!p) || kprobe_disabled(p)) > + goto end; > + > + kcb = get_kprobe_ctlblk(); > + if (kprobe_running()) { > + kprobes_inc_nmissed_count(p); > + } else { > + unsigned long orig_nip = regs->nip; > + /* Kprobe handler expects regs->nip = nip + 1 as breakpoint hit */ Can you clarify this? On powerpc, the regs->nip at the time of breakpoint hit points to the probed instruction, not the one after. Ananth