[4.14,66/75] powerpc/kprobes: Disable preemption before invoking probe handler for optprobes
diff mbox series

Message ID 20171207130821.480148818@linuxfoundation.org
State New, archived
Headers show
  • 4.14.5-stable review
Related show

Commit Message

Greg Kroah-Hartman Dec. 7, 2017, 1:08 p.m. UTC
4.14-stable review patch.  If anyone has any objections, please let me know.


From: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>

commit 8a2d71a3f2737e2448aa68de2b6052cb570d3d2a upstream.

Per Documentation/kprobes.txt, probe handlers need to be invoked with
preemption disabled. Update optimized_callback() to do so. Also move
get_kprobe_ctlblk() invocation post preemption disable, since it
accesses pre-cpu data.

This was not an issue so far since optprobes wasn't selected if
CONFIG_PREEMPT was enabled. Commit a30b85df7d599f ("kprobes: Use
synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y") changes

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

 arch/powerpc/kernel/optprobes.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff mbox series

--- a/arch/powerpc/kernel/optprobes.c
+++ b/arch/powerpc/kernel/optprobes.c
@@ -115,7 +115,6 @@  static unsigned long can_optimize(struct
 static void optimized_callback(struct optimized_kprobe *op,
 			       struct pt_regs *regs)
-	struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
 	unsigned long flags;
 	/* This is possible if op is under delayed unoptimizing */
@@ -124,13 +123,14 @@  static void optimized_callback(struct op
+	preempt_disable();
 	if (kprobe_running()) {
 	} else {
 		__this_cpu_write(current_kprobe, &op->kp);
 		regs->nip = (unsigned long)op->kp.addr;
-		kcb->kprobe_status = KPROBE_HIT_ACTIVE;
+		get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
 		opt_pre_handler(&op->kp, regs);
 		__this_cpu_write(current_kprobe, NULL);
@@ -140,6 +140,7 @@  static void optimized_callback(struct op
 	 * local_irq_restore() will re-enable interrupts,
 	 * if they were hard disabled.
+	preempt_enable_no_resched();