Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934002AbcLNQTE (ORCPT ); Wed, 14 Dec 2016 11:19:04 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47694 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933894AbcLNQTB (ORCPT ); Wed, 14 Dec 2016 11:19:01 -0500 From: Anju T Sudhakar To: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: ananth@in.ibm.com, naveen.n.rao@linux.vnet.ibm.com, paulus@samba.org, srikar@linux.vnet.ibm.com, benh@kernel.crashing.org, mpe@ellerman.id.au, mahesh@linux.vnet.ibm.com, mhiramat@kernel.org, anju@linux.vnet.ibm.com Subject: [PATCH V2 4/4] arch/powerpc: Optimize kprobe in kretprobe_trampoline Date: Wed, 14 Dec 2016 21:48:28 +0530 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481732310-7779-1-git-send-email-anju@linux.vnet.ibm.com> References: <1481732310-7779-1-git-send-email-anju@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16121416-0048-0000-0000-000001ED03BF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16121416-0049-0000-0000-0000472E1109 Message-Id: <1481732310-7779-3-git-send-email-anju@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-12-14_11:,, 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-1609300000 definitions=main-1612140263 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1900 Lines: 57 Kprobe placed on the kretprobe_trampoline during boot time can be optimized, since the instruction at probe point is a 'nop'. Signed-off-by: Anju T Sudhakar --- arch/powerpc/kernel/kprobes.c | 8 ++++++++ arch/powerpc/kernel/optprobes.c | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index e785cc9..5b0fd07 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -282,6 +282,7 @@ asm(".global kretprobe_trampoline\n" ".type kretprobe_trampoline, @function\n" "kretprobe_trampoline:\n" "nop\n" + "blr\n" ".size kretprobe_trampoline, .-kretprobe_trampoline\n"); /* @@ -334,6 +335,13 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p, kretprobe_assert(ri, orig_ret_address, trampoline_address); regs->nip = orig_ret_address; + /* + * Make LR point to the orig_ret_address. + * When the 'nop' inside the kretprobe_trampoline + * is optimized, we can do a 'blr' after executing the + * detour buffer code. + */ + regs->link = orig_ret_address; reset_current_kprobe(); kretprobe_hash_unlock(current, &flags); diff --git a/arch/powerpc/kernel/optprobes.c b/arch/powerpc/kernel/optprobes.c index ecba221..5e4c254 100644 --- a/arch/powerpc/kernel/optprobes.c +++ b/arch/powerpc/kernel/optprobes.c @@ -72,12 +72,11 @@ static unsigned long can_optimize(struct kprobe *p) /* * kprobe placed for kretprobe during boot time - * is not optimizing now. - * - * TODO: Optimize kprobe in kretprobe_trampoline + * has a 'nop' instruction, which can be emulated. + * So further checks can be skipped. */ if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline) - return 0; + return (unsigned long)p->addr + sizeof(kprobe_opcode_t); /* * We only support optimizing kernel addresses, but not -- 2.7.4