__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 <m...@ellerman.id.au>
---
 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

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Reply via email to