Re: [PATCH 2/6] riscv/ftrace: Add dynamic function tracer support
From: Alan Kao
Date: Thu Jan 11 2018 - 03:03:09 EST
On Wed, Jan 10, 2018 at 11:36:43AM -0500, Steven Rostedt wrote:
> On Wed, 10 Jan 2018 15:38:10 +0800
> Alan Kao <nonerkao@xxxxxxxxx> 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
>
Thanks for the correction and the style fix in the previous mail.
These problems will be fixed in the next version patch.
Alan