From: Steven Rostedt <rostedt@goodmis.org>
To: Alan Kao <nonerkao@gmail.com>
Cc: Palmer Dabbelt <palmer@sifive.com>, Albert Ou <albert@sifive.com>,
Ingo Molnar <mingo@redhat.com>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Kamil Rytarowski <n54@gmx.com>,
Andrew Morton <akpm@linux-foundation.org>,
patches@groups.riscv.org, linux-kernel@vger.kernel.org,
Alan Kao <alankao@andestech.com>,
Greentime Hu <greentime@andestech.com>
Subject: Re: [PATCH 2/6] riscv/ftrace: Add dynamic function tracer support
Date: Wed, 10 Jan 2018 11:36:43 -0500 [thread overview]
Message-ID: <20180110113643.7622a7d3@vmware.local.home> (raw)
In-Reply-To: <20180110073814.32338-3-alankao@andestech.com>
On Wed, 10 Jan 2018 15:38:10 +0800
Alan Kao <nonerkao@gmail.com> wrote:
> +static int __ftrace_modify_call(unsigned long hook_pos, unsigned long target,
> + bool enable)
> +{
> + unsigned int offset = (unsigned int)(target - hook_pos);
> + unsigned int auipc_call = to_auipc_insn(offset);
> + unsigned int jalr_call = to_jalr_insn(offset);
> + unsigned int calls[2] = {auipc_call, jalr_call};
> + unsigned int nops[2] = {NOP4, NOP4};
> + int ret = 0;
> +
> + /* when ftrace_make_nop is called */
> + if (!enable)
> + ret = ftrace_check_current_call(hook_pos, calls);
> +
> + if (ret)
> + goto out;
> +
> + /* replace the auipc-jalr pair at once */
> + ret = probe_kernel_write((void *)hook_pos, enable ? calls : nops,
> + MCOUNT_INSN_SIZE);
> + if (ret)
You don't want to return the return of probe_kernel_write() here. For
ftrace bug to work properly, if a fail to write occurs, you need to
return -EPERM.
-- Steve
> + goto out;
> +
> + smp_mb();
> + flush_icache_range((void *)hook_pos, (void *)hook_pos + MCOUNT_INSN_SIZE);
> +
> +out:
> + return ret;
> +}
> +
> +int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
> +{
> + int ret = ftrace_check_current_call(rec->ip, NULL);
> +
> + if (ret)
> + return ret;
> +
> + return __ftrace_modify_call(rec->ip, addr, true);
> +}
> +
> +int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
> + unsigned long addr)
> +{
> + return __ftrace_modify_call(rec->ip, addr, false);
> +}
> +
> +int ftrace_update_ftrace_func(ftrace_func_t func)
> +{
> + int ret = __ftrace_modify_call((unsigned long)&ftrace_call,
> + (unsigned long)func, true);
> + if (!ret) {
> + ret = __ftrace_modify_call((unsigned long)&ftrace_regs_call,
> + (unsigned long)func, true);
> + }
> +
> + return ret;
> +}
> +
> +int __init ftrace_dyn_arch_init(void)
> +{
> + return 0;
> +}
> +#endif
next prev parent reply other threads:[~2018-01-10 16:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-10 7:38 [PATCH 0/6] Add dynamic ftrace support for RISC-V platforms Alan Kao
2018-01-10 7:38 ` [PATCH 1/6] riscv/ftrace: Add RECORD_MCOUNT support Alan Kao
2018-01-10 7:43 ` [patches] " Christoph Hellwig
2018-01-10 7:54 ` Alan Kao
2018-01-10 7:38 ` [PATCH 2/6] riscv/ftrace: Add dynamic function tracer support Alan Kao
2018-01-10 16:32 ` Steven Rostedt
2018-01-10 16:36 ` Steven Rostedt [this message]
2018-01-11 8:02 ` Alan Kao
2018-01-10 7:38 ` [PATCH 3/6] riscv/ftrace: Add dynamic function graph " Alan Kao
2018-01-10 7:38 ` [PATCH 4/6] riscv/ftrace: Add ARCH_SUPPORTS_FTRACE_OPS support Alan Kao
2018-01-10 7:38 ` [PATCH 5/6] riscv/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Alan Kao
2018-01-10 7:38 ` [PATCH 6/6] riscv/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support Alan Kao
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=20180110113643.7622a7d3@vmware.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=alankao@andestech.com \
--cc=albert@sifive.com \
--cc=greentime@andestech.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=n54@gmx.com \
--cc=nonerkao@gmail.com \
--cc=palmer@sifive.com \
--cc=patches@groups.riscv.org \
--cc=yamada.masahiro@socionext.com \
/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