Re: [PATCH -tip] kprobes/x86: Use preempt_enable() in optimized_callback()

From: Peter Zijlstra
Date: Sun Oct 21 2018 - 16:42:41 EST


On Sat, Oct 20, 2018 at 06:47:53PM +0900, Masami Hiramatsu wrote:
> Since commit a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from
> ftrace-based/optimized kprobesâ) removes local_irq_save/restore()
> from optimized_callback(), the handler does not protected against
> reschedule interrupt. If it is able to be preempted (rescheduled)
> by such interrupt, we don't need to use _no_resched macro.

must not.

> Let's use preempt_enable() instead.
>
> Fixes: a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from ftrace-based/optimized kprobesâ)
> Link: https://lkml.kernel.org/r/37CB98C2-AF9B-475B-8B2D-7B414DC491F3@xxxxxxxxxx
> Reported-by: Nadav Amit <namit@xxxxxxxxxx>
> Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
> ---
> arch/x86/kernel/kprobes/opt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
> index eaf02f2e7300..40b16b270656 100644
> --- a/arch/x86/kernel/kprobes/opt.c
> +++ b/arch/x86/kernel/kprobes/opt.c
> @@ -179,7 +179,7 @@ optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
> opt_pre_handler(&op->kp, regs);
> __this_cpu_write(current_kprobe, NULL);
> }
> - preempt_enable_no_resched();
> + preempt_enable();
> }

Indeed,

Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>