Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762298AbcLSNS4 (ORCPT ); Mon, 19 Dec 2016 08:18:56 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53508 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759884AbcLSNSv (ORCPT ); Mon, 19 Dec 2016 08:18:51 -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 V3 4/4] arch/powerpc: Optimize kprobe in kretprobe_trampoline Date: Mon, 19 Dec 2016 18:48:25 +0530 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482153507-17350-1-git-send-email-anju@linux.vnet.ibm.com> References: <1482153507-17350-1-git-send-email-anju@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16121913-0052-0000-0000-000001FFA954 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16121913-0053-0000-0000-0000077401A9 Message-Id: <1482153507-17350-3-git-send-email-anju@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-12-19_10:,, 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-1612190184 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1949 Lines: 58 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 Acked-by: Masami Hiramatsu --- 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