Re: [RFC] x86/alternatives: Merge first and second step in text_poke_bp_batch

From: Google
Date: Thu Jan 16 2025 - 00:58:03 EST


On Tue, 14 Jan 2025 15:02:37 +0100
Jiri Olsa <jolsa@xxxxxxxxxx> wrote:

> hi,
> while checking on similar code for uprobes I was wondering if we
> can merge first 2 steps of instruction update in text_poke_bp_batch
> function.
>
> Basically the first step now would be to write int3 byte together
> with the rest of the bytes of the new instruction instead of doing
> that separately. And the second step would be to overwrite int3
> byte with first byte of the new instruction.
>
> Would that work or do I miss some x86 detail that could lead to crash?

I agree with Peterz and David. My original idea is that the putting
int3 is safe anyway because it is just 1 byte. Then we can update
following bytes (only after we ensure no one executing(e.g. interrupted)
that part). The another good point of int3 is that can avoid writing
over cache-line boundary because it is 1 byte.

Without this int3 detour, it is possible to see half-way updated
instruction from some other CPU cores :(

Thank you,

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>