linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Huang Pei <huangpei@loongson.cn>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	ambrosehua@gmail.com, Bibo Mao <maobibo@loongson.cn>,
	linux-mips@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-mm@kvack.org, Jiaxun Yang <jiaxun.yang@flygoat.com>,
	Paul Burton <paulburton@kernel.org>,
	Li Xuefeng <lixuefeng@loongson.cn>,
	Yang Tiezhu <yangtiezhu@loongson.cn>,
	Gao Juxin <gaojuxin@loongson.cn>,
	Huacai Chen <chenhuacai@loongson.cn>,
	Jinyang He <hejinyang@loongson.cn>,
	"Maciej W . Rozycki" <macro@orcam.me.uk>,
	Jisheng Zhang <Jisheng.Zhang@synaptics.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	"Naveen N . Rao" <naveen.n.rao@linux.vnet.ibm.com>
Subject: Re: [PATCH 4/6] kprobes/ftrace: Use ftrace_location() when [dis]arming probes
Date: Thu, 25 Mar 2021 15:44:33 -0400	[thread overview]
Message-ID: <20210325154433.7ed7e56a@gandalf.local.home> (raw)
In-Reply-To: <20210313064149.29276-5-huangpei@loongson.cn>

On Sat, 13 Mar 2021 14:41:47 +0800
Huang Pei <huangpei@loongson.cn> wrote:

> From: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> 

Looks like this was sent before, but was missing the proper authorship
(which is not Jisheng).

   https://lore.kernel.org/linux-arm-kernel/20191225173219.4f9db436@xhacker.debian/

-- Steve


> Ftrace location could include more than a single instruction in case
> of some architectures (powerpc64, for now). In this case, kprobe is
> permitted on any of those instructions, and uses ftrace infrastructure
> for functioning.
> 
> However, [dis]arm_kprobe_ftrace() uses the kprobe address when setting
> up ftrace filter IP. This won't work if the address points to any
> instruction apart from the one that has a branch to _mcount(). To
> resolve this, have [dis]arm_kprobe_ftrace() use ftrace_function() to
> identify the filter IP.
> 
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  kernel/kprobes.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 41fdbb7953c6..66ee28b071c2 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1045,9 +1045,10 @@ static int prepare_kprobe(struct kprobe *p)
>  static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
>  			       int *cnt)
>  {
> +	unsigned long ftrace_ip = ftrace_location((unsigned long)p->addr);
>  	int ret = 0;
>  
> -	ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0);
> +	ret = ftrace_set_filter_ip(ops, ftrace_ip, 0, 0);
>  	if (ret) {
>  		pr_debug("Failed to arm kprobe-ftrace at %pS (%d)\n",
>  			 p->addr, ret);
> @@ -1070,7 +1071,7 @@ static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
>  	 * At this point, sinec ops is not registered, we should be sefe from
>  	 * registering empty filter.
>  	 */
> -	ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0);
> +	ftrace_set_filter_ip(ops, ftrace_ip, 1, 0);
>  	return ret;
>  }
>  
> @@ -1087,6 +1088,7 @@ static int arm_kprobe_ftrace(struct kprobe *p)
>  static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
>  				  int *cnt)
>  {
> +	unsigned long ftrace_ip = ftrace_location((unsigned long)p->addr);
>  	int ret = 0;
>  
>  	if (*cnt == 1) {
> @@ -1097,7 +1099,7 @@ static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
>  
>  	(*cnt)--;
>  
> -	ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0);
> +	ret = ftrace_set_filter_ip(ops, ftrace_ip, 1, 0);
>  	WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (%d)\n",
>  		  p->addr, ret);
>  	return ret;



  reply	other threads:[~2021-03-25 19:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-13  6:41 [RFC PATCH V2]: add DYNAMC_FTRACE_WITH_REGS and Huang Pei
2021-03-13  6:41 ` [PATCH 1/6] MIPS: replace -pg with CC_FLAGS_FTRACE Huang Pei
2021-03-25 19:38   ` Steven Rostedt
2021-03-26  1:48     ` Huang Pei
2021-03-13  6:41 ` [PATCH 2/6] MIPS: move FTRACE_SYSCALLS from ftrace.c into syscall.c Huang Pei
2021-03-25 19:38   ` Steven Rostedt
2021-03-26 14:01     ` Huang Pei
2021-03-13  6:41 ` [PATCH 3/6] MIPS: prepare for new ftrace implementation Huang Pei
2021-03-25 19:39   ` Steven Rostedt
2021-03-13  6:41 ` [PATCH 4/6] kprobes/ftrace: Use ftrace_location() when [dis]arming probes Huang Pei
2021-03-25 19:44   ` Steven Rostedt [this message]
2021-03-26 14:12     ` Huang Pei
2021-03-26 14:23       ` Steven Rostedt
2021-03-13  6:41 ` [PATCH 5/6] ftrace: introduce FTRACE_IP_EXTENSION Huang Pei
2021-03-13  9:26   ` Sergei Shtylyov
2021-03-13  6:41 ` [PATCH 6/6] MIPS: add DYNAMIC_FTRACE_WITH_REGS and KPROBES_ON_FTACE Huang Pei
2021-03-13 21:37   ` kernel test robot

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=20210325154433.7ed7e56a@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=Jisheng.Zhang@synaptics.com \
    --cc=ambrosehua@gmail.com \
    --cc=chenhuacai@loongson.cn \
    --cc=gaojuxin@loongson.cn \
    --cc=hejinyang@loongson.cn \
    --cc=huangpei@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lixuefeng@loongson.cn \
    --cc=macro@orcam.me.uk \
    --cc=maobibo@loongson.cn \
    --cc=mhiramat@kernel.org \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=paulburton@kernel.org \
    --cc=tsbogend@alpha.franken.de \
    --cc=yangtiezhu@loongson.cn \
    /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