From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757705AbcBXO3v (ORCPT ); Wed, 24 Feb 2016 09:29:51 -0500 Received: from ozlabs.org ([103.22.144.67]:55155 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757263AbcBXO25 (ORCPT ); Wed, 24 Feb 2016 09:28:57 -0500 From: Michael Ellerman To: Cc: bsingharora@gmail.com, duwe@lst.de, , rostedt@goodmis.org, kamalesh@linux.vnet.ibm.com, pmladek@suse.com, jeyu@redhat.com, jkosina@suse.cz, live-patching@vger.kernel.org, mbenes@suse.cz Subject: [PATCH 11/12] powerpc/ftrace: Rework __ftrace_make_nop() Date: Thu, 25 Feb 2016 01:28:34 +1100 Message-Id: <1456324115-21144-11-git-send-email-mpe@ellerman.id.au> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456324115-21144-1-git-send-email-mpe@ellerman.id.au> References: <1456324115-21144-1-git-send-email-mpe@ellerman.id.au> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __ftrace_make_nop() needs to detect either the two instruction or the three instruction versions of the _mcount() sequence. But if we're running a kernel with the two instruction sequence, we need to be careful not to read from ip - 8, or we'll fault and (possibly) incorrectly declare the sequence doesn't match. To keep the code simpler just look at ip - 4, and if it is either of the expected instructions declare it good. We've already passed a lot of other checks. Signed-off-by: Michael Ellerman --- arch/powerpc/kernel/ftrace.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) Squash. diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c index f190528e3781..fe7486f9849e 100644 --- a/arch/powerpc/kernel/ftrace.c +++ b/arch/powerpc/kernel/ftrace.c @@ -174,28 +174,19 @@ __ftrace_make_nop(struct module *mod, return -EFAULT; } - if (op != PPC_INST_LD_TOC) - { - unsigned int op0, op1; + if (op != PPC_INST_LD_TOC) { + unsigned int inst; - if (probe_kernel_read(&op0, (void *)(ip-8), MCOUNT_INSN_SIZE)) { - pr_err("Fetching op0 failed.\n"); + if (probe_kernel_read(&inst, (void *)(ip - 4), 4)) { + pr_err("Fetching instruction at %lx failed.\n", ip - 4); return -EFAULT; } - if (probe_kernel_read(&op1, (void *)(ip-4), MCOUNT_INSN_SIZE)) { - pr_err("Fetching op1 failed.\n"); - return -EFAULT; - } - - /* mflr r0 ; [ std r0,LRSAVE(r1) ]? */ - if ( (op0 != PPC_INST_MFLR || - op1 != PPC_INST_STD_LR) - && op1 != PPC_INST_MFLR ) - { + /* We expect either a mlfr r0, or a std r0, LRSAVE(r1) */ + if (inst != PPC_INST_MFLR && inst != PPC_INST_STD_LR) { pr_err("Unexpected instructions around bl _mcount\n" "when enabling dynamic ftrace!\t" - "(%08x,%08x,bl,%08x)\n", op0, op1, op); + "(%08x,bl,%08x)\n", inst, op); return -EINVAL; } -- 2.5.0