> On Jan 9, 2019, at 2:59 PM, Josh Poimboeuf <jpoim...@redhat.com> wrote: > > With this version, I stopped trying to use text_poke_bp(), and instead > went with a different approach: if the call site destination doesn't > cross a cacheline boundary, just do an atomic write. Otherwise, keep > using the trampoline indefinitely. > > NOTE: At least experimentally, the call destination writes seem to be > atomic with respect to instruction fetching. On Nehalem I can easily > trigger crashes when writing a call destination across cachelines while > reading the instruction on other CPU; but I get no such crashes when > respecting cacheline boundaries. > > BUT, the SDM doesn't document this approach, so it would be great if any > CPU people can confirm that it's safe! >
I (still) think that having a compiler plugin can make things much cleaner (as done in [1]). The callers would not need to be changed, and the key can be provided through an attribute. Using a plugin should also allow to use Steven’s proposal for doing text_poke() safely: by changing 'func()' into 'asm (“call func”)', as done by the plugin, you can be guaranteed that registers are clobbered. Then, you can store in the assembly block the return address in one of these registers. [1] https://lkml.org/lkml/2018/12/31/25