Re: [PATCH] Add a text_poke syscall

From: H. Peter Anvin
Date: Wed Nov 20 2013 - 11:42:53 EST


On 11/19/2013 10:49 AM, Andi Kleen wrote:
>
> We already have all the code. Why not just use it?
>

We're talking user space here, which has different requirement (COW,
memory protection, ...) which means it is not really the same code. You
can't take a page fault while patching the kernel.

> Note I'm not adding any new mechanism, just exporting the existing one.
> So the usual "do things in user space" arguments do not really
> apply here.
>
> Also this is subtle enough that there is definitely benefit from
> having only a single canonical code that does it.
>
> If we ever need any new errata workarounds for this they could be also
> all done in a single central place.
>
>>
>> All we really need in the kernel is the IPI broadcasts - the rest can be
>> done in user space, including intercepting SIGTRAP. For userspace it is
>> probably the best to just put a thread to sleep until the patching is
>> done, which can be done with a futex.
>
> I'm not sure that's worth it. IPIs are reasonably fast (a few 1000s cycles).
> Sleeping likely only becomes beneficial with much longer delays, like
> ms. But if the IPIs start taking ms we have much more problems.

I'm referring to if some thread actually stumbles over INT 3, which is
indeed not very long for one patch site (as long as you don't end up
with page faults.) However, for tracing, you may want to do tens of
thousands of patches, and you really want to batch them.

>> One advantage with doing this in userspace is that the kernel doesn't
>> have to be responsible avoiding holding a thread due to a slightly
>> different SIGTRAP -- it will all come out after the signal handler is
>> restored, anyway.
>
> It's just some spinning, not a new task state. I don't think any
> task states make sense here.

I'd rather spin in user space, though.

-hpa

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/