Re: [PATCH] Add a text_poke syscall v2

Andy Lutomirski
2013-11-26T19:05:57Z

On 11/25/2013 04:37 PM, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> [Addressed all addressable review feedback in v2]
>
> Properly patching running code ("cross modification")
> is a quite complicated business on x86.
>
> The CPU has specific rules that need to be followed, including
> multiple global barriers.
>
> Self modifying code is getting more popular, so it's important
> to make it easy to follow the rules.
>
> The kernel does it properly with text_poke_bp(). But the same
> method is hard to do for user programs.
>
> This patch adds a (x86 specific) text_poke() syscall that exposes
> the text_poke_bp() machinery to user programs.
>
> The interface is practically the same as text_poke_bp, just as
> a syscall. I added an extra flags parameter, for future
> extension. Right now it is enforced to be 0.
>
> The call also still has a global lock, so it has some scaling
> limitations. If it was commonly used this could be fixed
> by setting up a list of break point locations. Then
> a lock would only be hold to modify the list.
>
> Right now the implementation is just as simple as possible.

IIRC someone proposed that, rather than specifying a "handler", that any
user thread that traps just wait until the poke completes. This would
complicate the kernel implementation a bit, but it would make the user
code a good deal simpler. Is there any reason that this is a bad idea?

--Andy