Thread (5 messages) 5 messages, 2 authors, 2020-01-13

Re: [RFC PATCH] arm64/ftrace: support dynamically allocated trampolines

From: chengjian (D) <hidden>
Date: 2020-01-13 06:18:29
Also in: lkml

On 2020/1/10 20:12, Mark Rutland wrote:
On Fri, Jan 10, 2020 at 07:28:17PM +0800, chengjian (D) wrote:
quoted
On 2020/1/10 0:48, Mark Rutland wrote:
quoted
On Thu, Jan 09, 2020 at 02:27:36PM +0000, Cheng Jian wrote:
quoted
+	/*
+	 * 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.

.

OK, I will do it.

Thank you, Mark.



   --Cheng Jian



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help