* [PATCH] powerpc/uprobes: Implement arch_uretprobe_is_alive()
@ 2017-06-14 15:44 Naveen N. Rao
2017-06-15 6:05 ` Srikar Dronamraju
2017-08-31 11:36 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Naveen N. Rao @ 2017-06-14 15:44 UTC (permalink / raw)
To: Michael Ellerman
Cc: Srikar Dronamraju, Ananth N Mavinakayanahalli,
Gustavo Luiz Duarte, zsun, linuxppc-dev
This helper is used to detect if a uprobe'd function has returned
through a setjmp/longjmp, rather than branching to the LR that was
updated previously by us. This fixes a SIGSEGV that gets generated when
programs use setjmp/longjmp with uretprobes.
We use the arm64 model (arch/arm64/kernel/probes/uprobes.c:
arch_uretprobe_is_alive()) for detecting when stack frames have been
removed from under us.
Reference:
https://marc.info/?l=linux-kernel&m=143748610330073
commit 7b868e4802a86 ("uprobes/x86: Reimplement arch_uretprobe_is_alive()")
commit db087ef69a2b1 ("uprobes/x86: Make arch_uretprobe_is_alive(RP_CHECK_CALL) more
clever")
Tested with the test program from:
https://sourceware.org/git/gitweb.cgi?p=systemtap.git;a=blob;f=testsuite/systemtap.base/bz5274.c;hb=HEAD
And this script:
$ cat test.sh
#!/bin/bash
perf probe -x ./bz5274 -a bz5274_main_return=main%return
perf probe -x ./bz5274 -a bz5274_funca_return=funca%return
perf probe -x ./bz5274 -a bz5274_funcb_return=funcb%return
perf probe -x ./bz5274 -a bz5274_funcc_return=funcc%return
perf probe -x ./bz5274 -a bz5274_funcd_return=funcd%return
perf record -e 'probe_bz5274:*' -aR ./bz5274
Reported-by: Gustavo Luiz Duarte <gduarte@redhat.com>
Reported-by: zsun@redhat.com
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/kernel/uprobes.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/powerpc/kernel/uprobes.c b/arch/powerpc/kernel/uprobes.c
index 003b20964ea0..5d105b8eeece 100644
--- a/arch/powerpc/kernel/uprobes.c
+++ b/arch/powerpc/kernel/uprobes.c
@@ -205,3 +205,12 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
return orig_ret_vaddr;
}
+
+bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx,
+ struct pt_regs *regs)
+{
+ if (ctx == RP_CHECK_CHAIN_CALL)
+ return regs->gpr[1] <= ret->stack;
+ else
+ return regs->gpr[1] < ret->stack;
+}
--
2.12.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/uprobes: Implement arch_uretprobe_is_alive()
2017-06-14 15:44 [PATCH] powerpc/uprobes: Implement arch_uretprobe_is_alive() Naveen N. Rao
@ 2017-06-15 6:05 ` Srikar Dronamraju
2017-08-31 11:36 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Srikar Dronamraju @ 2017-06-15 6:05 UTC (permalink / raw)
To: Naveen N. Rao
Cc: Michael Ellerman, Ananth N Mavinakayanahalli,
Gustavo Luiz Duarte, zsun, linuxppc-dev, Pratyush Anand,
Oleg Nesterov
Adding Oleg and Pratyush to the cc.
> This helper is used to detect if a uprobe'd function has returned
> through a setjmp/longjmp, rather than branching to the LR that was
> updated previously by us. This fixes a SIGSEGV that gets generated when
> programs use setjmp/longjmp with uretprobes.
>
> We use the arm64 model (arch/arm64/kernel/probes/uprobes.c:
> arch_uretprobe_is_alive()) for detecting when stack frames have been
> removed from under us.
>
> Reference:
> https://marc.info/?l=linux-kernel&m=143748610330073
> commit 7b868e4802a86 ("uprobes/x86: Reimplement arch_uretprobe_is_alive()")
> commit db087ef69a2b1 ("uprobes/x86: Make arch_uretprobe_is_alive(RP_CHECK_CALL) more
> clever")
>
> Tested with the test program from:
> https://sourceware.org/git/gitweb.cgi?p=systemtap.git;a=blob;f=testsuite/systemtap.base/bz5274.c;hb=HEAD
>
> And this script:
> $ cat test.sh
> #!/bin/bash
>
> perf probe -x ./bz5274 -a bz5274_main_return=main%return
> perf probe -x ./bz5274 -a bz5274_funca_return=funca%return
> perf probe -x ./bz5274 -a bz5274_funcb_return=funcb%return
> perf probe -x ./bz5274 -a bz5274_funcc_return=funcc%return
> perf probe -x ./bz5274 -a bz5274_funcd_return=funcd%return
>
> perf record -e 'probe_bz5274:*' -aR ./bz5274
>
> Reported-by: Gustavo Luiz Duarte <gduarte@redhat.com>
> Reported-by: zsun@redhat.com
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Looks good to me.
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: powerpc/uprobes: Implement arch_uretprobe_is_alive()
2017-06-14 15:44 [PATCH] powerpc/uprobes: Implement arch_uretprobe_is_alive() Naveen N. Rao
2017-06-15 6:05 ` Srikar Dronamraju
@ 2017-08-31 11:36 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2017-08-31 11:36 UTC (permalink / raw)
To: Naveen N. Rao; +Cc: linuxppc-dev, Srikar Dronamraju, zsun, Gustavo Luiz Duarte
On Wed, 2017-06-14 at 15:44:00 UTC, "Naveen N. Rao" wrote:
> This helper is used to detect if a uprobe'd function has returned
> through a setjmp/longjmp, rather than branching to the LR that was
> updated previously by us. This fixes a SIGSEGV that gets generated when
> programs use setjmp/longjmp with uretprobes.
>
> We use the arm64 model (arch/arm64/kernel/probes/uprobes.c:
> arch_uretprobe_is_alive()) for detecting when stack frames have been
> removed from under us.
>
> Reference:
> https://marc.info/?l=linux-kernel&m=143748610330073
> commit 7b868e4802a86 ("uprobes/x86: Reimplement arch_uretprobe_is_alive()")
> commit db087ef69a2b1 ("uprobes/x86: Make arch_uretprobe_is_alive(RP_CHECK_CALL) more
> clever")
>
> Tested with the test program from:
> https://sourceware.org/git/gitweb.cgi?p=systemtap.git;a=blob;f=testsuite/systemtap.base/bz5274.c;hb=HEAD
>
> And this script:
> $ cat test.sh
> #!/bin/bash
>
> perf probe -x ./bz5274 -a bz5274_main_return=main%return
> perf probe -x ./bz5274 -a bz5274_funca_return=funca%return
> perf probe -x ./bz5274 -a bz5274_funcb_return=funcb%return
> perf probe -x ./bz5274 -a bz5274_funcc_return=funcc%return
> perf probe -x ./bz5274 -a bz5274_funcd_return=funcd%return
>
> perf record -e 'probe_bz5274:*' -aR ./bz5274
>
> Reported-by: Gustavo Luiz Duarte <gduarte@redhat.com>
> Reported-by: zsun@redhat.com
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/2dea1d9c38e481051fa0e62807e518
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-08-31 11:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-14 15:44 [PATCH] powerpc/uprobes: Implement arch_uretprobe_is_alive() Naveen N. Rao
2017-06-15 6:05 ` Srikar Dronamraju
2017-08-31 11:36 ` Michael Ellerman
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).