lkml.org 
[lkml]   [2020]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH] arm64/ftrace: support dynamically allocated trampolines
On Fri, Jan 10, 2020 at 07:28:17PM +0800, chengjian (D) wrote:
> On 2020/1/10 0:48, Mark Rutland wrote:
> > On Thu, Jan 09, 2020 at 02:27:36PM +0000, Cheng Jian wrote:
> > > + /*
> > > + * Update the trampoline ops REF
> > > + *
> > > + * OLD INSNS : ldr_l x2, function_trace_op
> > > + * adrp x2, sym
> > > + * ldr x2, [x2, :lo12:\sym]
> > > + *
> > > + * NEW INSNS:
> > > + * nop
> > > + * ldr x2, <ftrace_ops>
> > > + */
> > > + op_offset -= start_offset_common;
> > > + ip = (unsigned long)trampoline + caller_size + op_offset;
> > > + nop = aarch64_insn_gen_nop();
> > > + memcpy((void *)ip, &nop, AARCH64_INSN_SIZE);
> > > +
> > > + op_offset += AARCH64_INSN_SIZE;
> > > + ip = (unsigned long)trampoline + caller_size + op_offset;
> > > + offset = (unsigned long)ptr - ip;
> > > + if (WARN_ON(offset % AARCH64_INSN_SIZE != 0))
> > > + goto free;
> > > + offset = offset / AARCH64_INSN_SIZE;
> > > + pc_ldr |= (offset & mask) << shift;
> > > + memcpy((void *)ip, &pc_ldr, AARCH64_INSN_SIZE);
> > I think it would be much better to have a separate template for the
> > trampoline which we don't have to patch in this way. It can even be
> > placed into a non-executable RO section, since the template shouldn't be
> > executed directly.
>
> A separate template !
>
> This may be a good way, and I think the patching here is very HACK too(Not
> very friendly).
>
> I had thought of other ways before, similar to the method on X86_64,
> remove the ftrace_common(), directly modifying
> ftrace_caller/ftrace_reg_caller, We will only need to copy the code
> once in this way, and these is no need to modify call ftrace_common to
> NOP.
>
> Using a trampoline template sounds great. but this also means that we
> need to aintain a template(or maybe two templates: one for caller,
> another for regs_caller).
>
> Hi, Mark, what do you think about it ?

I think that having two templates is fine. We can factor
ftrace_common_return into a macro mirroring ftrace_regs_entry, and I
suspect we can probably figure out some way to factor the common
portion.

Thanks,
Mark.

\
 
 \ /
  Last update: 2020-01-10 13:12    [W:0.052 / U:3.488 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site