linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/kprobes: Update optprobes to use emulate_update_regs()
@ 2017-09-15 10:08 Naveen N. Rao
  2017-09-21  1:46 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Naveen N. Rao @ 2017-09-15 10:08 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: Paul Mackerras, Anju T Sudhakar, linuxppc-dev

Optprobes depended on an updated regs->nip from analyse_instr() to
identify the location to branch back from the optprobes trampoline.
However, since commit 3cdfcbfd32b9d ("powerpc: Change analyse_instr so
it doesn't modify *regs"), analyse_instr() doesn't update the registers
anymore.  Due to this, we end up branching back from the optprobes
trampoline to the same branch into the trampoline resulting in a loop.

Fix this by calling out to emulate_update_regs() before using the nip.
Additionally, explicitly compare the return value from analyse_instr()
to 1, rather than just checking for !0 so as to guard against any
future changes to analyse_instr() that may result in -1 being returned
in more scenarios.

Fixes: 3cdfcbfd32b9d ("powerpc: Change analyse_instr so it doesn't modify *regs")
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/optprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/optprobes.c b/arch/powerpc/kernel/optprobes.c
index 6f8273f5e988..91e037ab20a1 100644
--- a/arch/powerpc/kernel/optprobes.c
+++ b/arch/powerpc/kernel/optprobes.c
@@ -104,8 +104,10 @@ static unsigned long can_optimize(struct kprobe *p)
 	 * and that can be emulated.
 	 */
 	if (!is_conditional_branch(*p->ainsn.insn) &&
-			analyse_instr(&op, &regs, *p->ainsn.insn))
+			analyse_instr(&op, &regs, *p->ainsn.insn) == 1) {
+		emulate_update_regs(&regs, &op);
 		nip = regs.nip;
+	}
 
 	return nip;
 }
-- 
2.14.1

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

* Re: powerpc/kprobes: Update optprobes to use emulate_update_regs()
  2017-09-15 10:08 [PATCH] powerpc/kprobes: Update optprobes to use emulate_update_regs() Naveen N. Rao
@ 2017-09-21  1:46 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2017-09-21  1:46 UTC (permalink / raw)
  To: Naveen N. Rao; +Cc: Anju T Sudhakar, linuxppc-dev

On Fri, 2017-09-15 at 10:08:21 UTC, "Naveen N. Rao" wrote:
> Optprobes depended on an updated regs->nip from analyse_instr() to
> identify the location to branch back from the optprobes trampoline.
> However, since commit 3cdfcbfd32b9d ("powerpc: Change analyse_instr so
> it doesn't modify *regs"), analyse_instr() doesn't update the registers
> anymore.  Due to this, we end up branching back from the optprobes
> trampoline to the same branch into the trampoline resulting in a loop.
> 
> Fix this by calling out to emulate_update_regs() before using the nip.
> Additionally, explicitly compare the return value from analyse_instr()
> to 1, rather than just checking for !0 so as to guard against any
> future changes to analyse_instr() that may result in -1 being returned
> in more scenarios.
> 
> Fixes: 3cdfcbfd32b9d ("powerpc: Change analyse_instr so it doesn't modify *regs")
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/8afafa6fba7809c0785018b77c95b1

cheers

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

end of thread, other threads:[~2017-09-21  1:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-15 10:08 [PATCH] powerpc/kprobes: Update optprobes to use emulate_update_regs() Naveen N. Rao
2017-09-21  1:46 ` 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).