From: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>, linuxppc-dev@ozlabs.org
Cc: duwe@lst.de, aneesh.kumar@linux.vnet.ibm.com,
Anton Blanchard <anton@samba.org>
Subject: Re: [PATCH 1/2] powerpc/ftrace: Separate the heuristics for checking call sites
Date: Tue, 19 Jul 2016 11:14:09 +0530 [thread overview]
Message-ID: <578DBE29.6010100@linux.vnet.ibm.com> (raw)
In-Reply-To: <1468903711-5869-1-git-send-email-mpe@ellerman.id.au>
On Tuesday 19 July 2016 10:18 AM, Michael Ellerman wrote:
> In __ftrace_make_nop() (the 64-bit version), we have code to deal with
> two ftrace ABIs. There is the original ABI, which looks mostly like a
> function call, and then the mprofile-kernel ABI which is just a branch.
>
> The code tries to handle both cases, by looking for the presence of a
> load to restore the TOC pointer (PPC_INST_LD_TOC). If we detect the TOC
> load, we assume the call site is for an mcount() call using the old ABI.
> That means we patch the mcount() call with a b +8, to branch over the
> TOC load.
>
> However if the kernel was built with mprofile-kernel, then there will
> never be a call site using the original ftrace ABI. If for some reason
> we do see a TOC load, then it's there for a good reason, and we should
> not jump over it.
>
> So split the code, using the existing CC_USING_MPROFILE_KERNEL. Kernels
> built with mprofile-kernel will only look for, and expect, the new ABI,
> and similarly for the original ABI.
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
> arch/powerpc/kernel/ftrace.c | 35 ++++++++++++++++++-----------------
> 1 file changed, 18 insertions(+), 17 deletions(-)
>
> diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
> index 7af6c4de044b..438442dac44c 100644
> --- a/arch/powerpc/kernel/ftrace.c
> +++ b/arch/powerpc/kernel/ftrace.c
> @@ -144,6 +144,21 @@ __ftrace_make_nop(struct module *mod,
> return -EINVAL;
> }
>
> +#ifdef CC_USING_MPROFILE_KERNEL
> + /* When using -mkernel_profile there is no load to jump over */
> + pop = PPC_INST_NOP;
> +
> + if (probe_kernel_read(&op, (void *)(ip - 4), 4)) {
> + pr_err("Fetching instruction at %lx failed.\n", ip - 4);
> + return -EFAULT;
> + }
> +
> + /* We expect either a mlfr r0, or a std r0, LRSAVE(r1) */
nit.. "mflr" and not "mlfr"
> + if (op != PPC_INST_MFLR && op != PPC_INST_STD_LR) {
> + pr_err("Unexpected instruction %08x around bl _mcount\n", op);
> + return -EINVAL;
> + }
> +#else
> /*
> * Our original call site looks like:
> *
> @@ -170,24 +185,10 @@ __ftrace_make_nop(struct module *mod,
> }
>
> if (op != PPC_INST_LD_TOC) {
> - unsigned int inst;
> -
> - if (probe_kernel_read(&inst, (void *)(ip - 4), 4)) {
> - pr_err("Fetching instruction at %lx failed.\n", ip - 4);
> - return -EFAULT;
> - }
> -
> - /* 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,bl,%08x)\n", inst, op);
> - return -EINVAL;
> - }
> -
> - /* When using -mkernel_profile there is no load to jump over */
> - pop = PPC_INST_NOP;
> + pr_err("Expected %08x found %08x\n", PPC_INST_LD_TOC, op);
> + return -EINVAL;
> }
> +#endif /* CC_USING_MPROFILE_KERNEL */
>
> if (patch_instruction((unsigned int *)ip, pop)) {
> pr_err("Patching NOP failed.\n");
next prev parent reply other threads:[~2016-07-19 5:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-19 4:48 [PATCH 1/2] powerpc/ftrace: Separate the heuristics for checking call sites Michael Ellerman
2016-07-19 4:48 ` [PATCH 2/2] powerpc/modules: Never restore r2 for a mprofile-kernel style mcount() call Michael Ellerman
2016-07-22 5:50 ` [2/2] " Michael Ellerman
2016-07-19 5:44 ` Madhavan Srinivasan [this message]
2016-07-21 10:36 ` [PATCH 1/2] powerpc/ftrace: Separate the heuristics for checking call sites Michael Ellerman
2016-07-22 5:50 ` [1/2] " Michael Ellerman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=578DBE29.6010100@linux.vnet.ibm.com \
--to=maddy@linux.vnet.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=anton@samba.org \
--cc=duwe@lst.de \
--cc=linuxppc-dev@ozlabs.org \
--cc=mpe@ellerman.id.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).