Re: [PATCH 08/15] x86/alternatives: Teach text_poke_bp() to emulate instructions

From: Steven Rostedt
Date: Tue Jun 11 2019 - 12:15:47 EST

On Tue, 11 Jun 2019 08:54:23 -0700
Andy Lutomirski <luto@xxxxxxxxxxxxxx> wrote:

> How does that help? If RIP == x+2 and you want to put a 5-byte jump
> at address x, no amount of 0xcc is going to change the fact that RIP
> is in the middle of the jump.
> Live patching can handle this by detecting this condition on each
> CPU, but performance wonât be great. Maybe some synchronize_sched
> trickery could help.

We have synchronize_rcu_tasks() which return after all tasks have
either entered user space or did a voluntary schedule (was not
preempted). Or have not run (still in a sleeping state).

That way we guarantee that all tasks are no longer on any trampoline
or code paths that do not call schedule. I use this to free dynamically
allocated trampolines used by ftrace. And kprobes uses this too for its
own trampolines.

-- Steve