Re: [PATCH -tip v3 7/7] kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT

From: Steven Rostedt
Date: Tue Oct 03 2017 - 19:57:31 EST



Sorry for the late reply. Coming back from Kernel Recipes, I fell way
behind in email.

On Fri, 29 Sep 2017 00:29:38 -0700
Masami Hiramatsu <mhiramat@xxxxxxxxxx> wrote:

> > > + * are done. Because optprobe may modify multiple instructions,
> > > + * there is a chance that the Nth instruction is interrupted. In that
> > > + * case, running interrupt can return to the Nth byte of jump
> > > + * instruction. This can be avoided by waiting for returning of
> > > + * such interrupts, since (until here) the first byte of the optimized
> > > + * probe is already replaced with normal kprobe (sw breakpoint) and
> > > + * all threads which reach to the probed address will hit it and
> > > + * bypass the copied instructions (instead of executing the original.)
> > > + * With CONFIG_PREEMPT, such interrupts can be preepmted. To wait
> > > + * for such thread, we will use synchronize_rcu_tasks() which ensures
> > > + * all preeempted tasks are scheduled normally (not preempted).
> > > + * So we can ensure there is no threads preempted at probed address.
> >
> > What? Interrupts cannot be preempted.
>
> Steve, could you correct me if I'm wrong. I thought if the kernel is
> compiled with CONFIG_PREEMPT=y, even in the kernel, it can be preempted
> suddenly. It means timer interrupt occurs at kernel path and it yield
> to new task (=preempt.) Do I miss something?

The above sounds correct. I believe Ingo was pointing out the line that
states "With CONFIG_PREEMPT, such interrupts can be preempted", which
is not true. I think you meant that interrupts can preempt the kernel
and cause it to schedule out. The line above sounds like you meant the
interrupt was preempted, which can't happen.

-- Steve