netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	lkml <linux-kernel@vger.kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Naveen N . Rao" <naveen.n.rao@linux.ibm.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
	"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH v11 07/12] ARM: rethook: Add rethook arm implementation
Date: Tue, 15 Mar 2022 19:08:48 +0900	[thread overview]
Message-ID: <20220315190848.a28a889802b71820650f5478@kernel.org> (raw)
In-Reply-To: <164701440314.268462.2664594020245236625.stgit@devnote2>

On Sat, 12 Mar 2022 01:00:03 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> +void __naked arch_rethook_trampoline(void)
> +{
> +	__asm__ __volatile__ (
> +#ifdef CONFIG_FRAME_POINTER
> +		"ldr	lr, =arch_rethook_trampoline	\n\t"

Oops, this must have the same issue reported by 0day build bot recently[1].

[1] https://lore.kernel.org/all/202203150516.KTorSVVU-lkp@intel.com/T/#u

I'll update this series with same fix.

Thank you,

> +	/* this makes a framepointer on pt_regs. */
> +#ifdef CONFIG_CC_IS_CLANG
> +		"stmdb	sp, {sp, lr, pc}	\n\t"
> +		"sub	sp, sp, #12		\n\t"
> +		/* In clang case, pt_regs->ip = lr. */
> +		"stmdb	sp!, {r0 - r11, lr}	\n\t"
> +		/* fp points regs->r11 (fp) */
> +		"add	fp, sp,	#44		\n\t"
> +#else /* !CONFIG_CC_IS_CLANG */
> +		/* In gcc case, pt_regs->ip = fp. */
> +		"stmdb	sp, {fp, sp, lr, pc}	\n\t"
> +		"sub	sp, sp, #16		\n\t"
> +		"stmdb	sp!, {r0 - r11}		\n\t"
> +		/* fp points regs->r15 (pc) */
> +		"add	fp, sp, #60		\n\t"
> +#endif /* CONFIG_CC_IS_CLANG */
> +#else /* !CONFIG_FRAME_POINTER */
> +		"sub	sp, sp, #16		\n\t"
> +		"stmdb	sp!, {r0 - r11}		\n\t"
> +#endif /* CONFIG_FRAME_POINTER */
> +		"mov	r0, sp			\n\t"
> +		"bl	arch_rethook_trampoline_callback	\n\t"
> +		"mov	lr, r0			\n\t"
> +		"ldmia	sp!, {r0 - r11}		\n\t"
> +		"add	sp, sp, #16		\n\t"
> +#ifdef CONFIG_THUMB2_KERNEL
> +		"bx	lr			\n\t"
> +#else
> +		"mov	pc, lr			\n\t"
> +#endif
> +		: : : "memory");
> +}
> +NOKPROBE_SYMBOL(arch_rethook_trampoline);
> +
> +/*
> + * At the entry of function with mcount. The stack and registers are prepared
> + * for the mcount function as below.
> + *
> + * mov     ip, sp
> + * push    {fp, ip, lr, pc}
> + * sub     fp, ip, #4	; FP[0] = PC, FP[-4] = LR, and FP[-12] = call-site FP.
> + * push    {lr}
> + * bl      <__gnu_mcount_nc> ; call ftrace
> + *
> + * And when returning from the function, call-site FP, SP and PC are restored
> + * from stack as below;
> + *
> + * ldm     sp, {fp, sp, pc}
> + *
> + * Thus, if the arch_rethook_prepare() is called from real function entry,
> + * it must change the LR and save FP in pt_regs. But if it is called via
> + * mcount context (ftrace), it must change the LR on stack, which is next
> + * to the PC (= FP[-4]), and save the FP value at FP[-12].
> + */
> +void arch_rethook_prepare(struct rethook_node *rh, struct pt_regs *regs, bool mcount)
> +{
> +	unsigned long *ret_addr, *frame;
> +
> +	if (mcount) {
> +		ret_addr = (unsigned long *)(regs->ARM_fp - 4);
> +		frame = (unsigned long *)(regs->ARM_fp - 12);
> +	} else {
> +		ret_addr = &regs->ARM_lr;
> +		frame = &regs->ARM_fp;
> +	}
> +
> +	rh->ret_addr = *ret_addr;
> +	rh->frame = *frame;
> +
> +	/* Replace the return addr with trampoline addr. */
> +	*ret_addr = (unsigned long)arch_rethook_trampoline;
> +}
> +NOKPROBE_SYMBOL(arch_rethook_prepare);
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2022-03-15 10:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 15:58 [PATCH v11 00/12] fprobe: Introduce fprobe function entry/exit probe Masami Hiramatsu
2022-03-11 15:58 ` [PATCH v11 01/12] ftrace: Add ftrace_set_filter_ips function Masami Hiramatsu
2022-03-11 15:59 ` [PATCH v11 02/12] fprobe: Add ftrace based probe APIs Masami Hiramatsu
2022-03-11 15:59 ` [PATCH v11 03/12] rethook: Add a generic return hook Masami Hiramatsu
2022-03-11 15:59 ` [PATCH v11 04/12] rethook: x86: Add rethook x86 implementation Masami Hiramatsu
2022-03-11 15:59 ` [PATCH v11 05/12] arm64: rethook: Add arm64 rethook implementation Masami Hiramatsu
2022-03-11 15:59 ` [PATCH v11 06/12] powerpc: Add rethook support Masami Hiramatsu
2022-03-11 16:00 ` [PATCH v11 07/12] ARM: rethook: Add rethook arm implementation Masami Hiramatsu
2022-03-15 10:08   ` Masami Hiramatsu [this message]
2022-03-11 16:00 ` [PATCH v11 08/12] fprobe: Add exit_handler support Masami Hiramatsu
2022-03-11 16:00 ` [PATCH v11 09/12] fprobe: Add sample program for fprobe Masami Hiramatsu
2022-03-11 16:00 ` [PATCH v11 10/12] fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag " Masami Hiramatsu
2022-03-11 16:00 ` [PATCH v11 11/12] docs: fprobe: Add fprobe description to ftrace-use.rst Masami Hiramatsu
2022-03-11 16:01 ` [PATCH v11 12/12] fprobe: Add a selftest for fprobe Masami Hiramatsu

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=20220315190848.a28a889802b71820650f5478@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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;
as well as URLs for NNTP newsgroup(s).