linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: kprobes/ftrace: Add recursion protection to the ftrace callback
@ 2021-03-29 18:14 Jisheng Zhang
  2021-03-30 19:39 ` Steven Rostedt
  2021-04-12  1:09 ` Palmer Dabbelt
  0 siblings, 2 replies; 3+ messages in thread
From: Jisheng Zhang @ 2021-03-29 18:14 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Masami Hiramatsu,
	Steven Rostedt (VMware),
	Guo Ren
  Cc: linux-riscv, linux-kernel

From: Jisheng Zhang <jszhang@kernel.org>

Currently, the riscv's kprobes(powerred by ftrace) handler is
preemptible. Futher check indicates we miss something similar as the
commit c536aa1c5b17 ("kprobes/ftrace: Add recursion protection to the
ftrace callback"), so do similar modifications as the commit does.

Fixes: 829adda597fe ("riscv: Add KPROBES_ON_FTRACE supported")
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 arch/riscv/kernel/probes/ftrace.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/probes/ftrace.c b/arch/riscv/kernel/probes/ftrace.c
index 17ca5e923bb0..aab85a82f419 100644
--- a/arch/riscv/kernel/probes/ftrace.c
+++ b/arch/riscv/kernel/probes/ftrace.c
@@ -9,10 +9,16 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 	struct kprobe *p;
 	struct pt_regs *regs;
 	struct kprobe_ctlblk *kcb;
+	int bit;
 
+	bit = ftrace_test_recursion_trylock(ip, parent_ip);
+	if (bit < 0)
+		return;
+
+	preempt_disable_notrace();
 	p = get_kprobe((kprobe_opcode_t *)ip);
 	if (unlikely(!p) || kprobe_disabled(p))
-		return;
+		goto out;
 
 	regs = ftrace_get_regs(fregs);
 	kcb = get_kprobe_ctlblk();
@@ -45,6 +51,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 		 */
 		__this_cpu_write(current_kprobe, NULL);
 	}
+out:
+	preempt_enable_notrace();
+	ftrace_test_recursion_unlock(bit);
 }
 NOKPROBE_SYMBOL(kprobe_ftrace_handler);
 
-- 
2.31.0



_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: kprobes/ftrace: Add recursion protection to the ftrace callback
  2021-03-29 18:14 [PATCH] riscv: kprobes/ftrace: Add recursion protection to the ftrace callback Jisheng Zhang
@ 2021-03-30 19:39 ` Steven Rostedt
  2021-04-12  1:09 ` Palmer Dabbelt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-03-30 19:39 UTC (permalink / raw)
  To: Jisheng Zhang
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Masami Hiramatsu,
	Guo Ren, linux-riscv, linux-kernel

On Tue, 30 Mar 2021 02:14:40 +0800
Jisheng Zhang <jszhang3@mail.ustc.edu.cn> wrote:

> From: Jisheng Zhang <jszhang@kernel.org>
> 
> Currently, the riscv's kprobes(powerred by ftrace) handler is
> preemptible. Futher check indicates we miss something similar as the
> commit c536aa1c5b17 ("kprobes/ftrace: Add recursion protection to the
> ftrace callback"), so do similar modifications as the commit does.
> 
> Fixes: 829adda597fe ("riscv: Add KPROBES_ON_FTRACE supported")
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>

Looks fine to me.

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: kprobes/ftrace: Add recursion protection to the ftrace callback
  2021-03-29 18:14 [PATCH] riscv: kprobes/ftrace: Add recursion protection to the ftrace callback Jisheng Zhang
  2021-03-30 19:39 ` Steven Rostedt
@ 2021-04-12  1:09 ` Palmer Dabbelt
  1 sibling, 0 replies; 3+ messages in thread
From: Palmer Dabbelt @ 2021-04-12  1:09 UTC (permalink / raw)
  To: jszhang3
  Cc: Paul Walmsley, aou, mhiramat, rostedt, guoren, linux-riscv, linux-kernel

On Mon, 29 Mar 2021 11:14:40 PDT (-0700), jszhang3@mail.ustc.edu.cn wrote:
> From: Jisheng Zhang <jszhang@kernel.org>
>
> Currently, the riscv's kprobes(powerred by ftrace) handler is
> preemptible. Futher check indicates we miss something similar as the
> commit c536aa1c5b17 ("kprobes/ftrace: Add recursion protection to the
> ftrace callback"), so do similar modifications as the commit does.
>
> Fixes: 829adda597fe ("riscv: Add KPROBES_ON_FTRACE supported")
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
>  arch/riscv/kernel/probes/ftrace.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/probes/ftrace.c b/arch/riscv/kernel/probes/ftrace.c
> index 17ca5e923bb0..aab85a82f419 100644
> --- a/arch/riscv/kernel/probes/ftrace.c
> +++ b/arch/riscv/kernel/probes/ftrace.c
> @@ -9,10 +9,16 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
>  	struct kprobe *p;
>  	struct pt_regs *regs;
>  	struct kprobe_ctlblk *kcb;
> +	int bit;
>
> +	bit = ftrace_test_recursion_trylock(ip, parent_ip);
> +	if (bit < 0)
> +		return;
> +
> +	preempt_disable_notrace();
>  	p = get_kprobe((kprobe_opcode_t *)ip);
>  	if (unlikely(!p) || kprobe_disabled(p))
> -		return;
> +		goto out;
>
>  	regs = ftrace_get_regs(fregs);
>  	kcb = get_kprobe_ctlblk();
> @@ -45,6 +51,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
>  		 */
>  		__this_cpu_write(current_kprobe, NULL);
>  	}
> +out:
> +	preempt_enable_notrace();
> +	ftrace_test_recursion_unlock(bit);
>  }
>  NOKPROBE_SYMBOL(kprobe_ftrace_handler);

Thanks, this is on fixes.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-12  1:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29 18:14 [PATCH] riscv: kprobes/ftrace: Add recursion protection to the ftrace callback Jisheng Zhang
2021-03-30 19:39 ` Steven Rostedt
2021-04-12  1:09 ` Palmer Dabbelt

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).