[PATCH v2 3/6] riscv: ftrace: prepare ftrace for atomic code patching
Björn Töpel
bjorn at kernel.org
Tue Aug 13 05:59:33 PDT 2024
Andy Chiu <andy.chiu at sifive.com> writes:
> We use an AUIPC+JALR pair to jump into a ftrace trampoline. Since
> instruction fetch can break down to 4 byte at a time, it is impossible
> to update two instructions without a race. In order to mitigate it, we
> initialize the patchable entry to AUIPC + NOP4. Then, the run-time code
> patching can change NOP4 to JALR to eable/disable ftrcae from a
enable ftrace
> function. This limits the reach of each ftrace entry to +-2KB displacing
> from ftrace_caller.
>
> Starting from the trampoline, we add a level of indirection for it to
> reach ftrace caller target. Now, it loads the target address from a
> memory location, then perform the jump. This enable the kernel to update
> the target atomically.
The +-2K limit is for direct calls, right?
...and this I would say breaks DIRECT_CALLS (which should be implemented
using call_ops later)?
Björn
More information about the linux-riscv
mailing list