riscv: kprobes: implement optprobes
openEuler inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I5QM0N CVE: NA -------------------------------- Add jump optimization support for RISC-V. Replaces ebreak instructions used by normal kprobes with an auipc+jalr instruction pair, at the aim of suppressing the probe-hit overhead. All known optprobe-capable RISC architectures have been using a single jump or branch instructions while this patch chooses not. RISC-V has a quite limited jump range (4KB or 2MB) for both its branch and jump instructions, which prevent optimizations from supporting probes that spread all over the kernel. Auipc-jalr instruction pair is introduced with a much wider jump range (4GB), where auipc loads the upper 12 bits to a free register and jalr appends the lower 20 bits to form a 32 bit immediate. Note that returning from probe handler requires another free register. As kprobes can appear almost anywhere inside the kernel, the free register should be found in a generic way, not depending on calling convention or any other regulations. The algorithm for finding the free register is inspired by the register renaming in modern processors. From the perspective of register renaming, a register could be represented as two different registers if two neighbour instructions both write to it but no one ever reads. Extending this fact, a register is considered to be free if there is no read before its next write in the execution flow. We are free to change its value without interfering normal execution. Static analysis shows that 51% instructions of the kernel (default config) is capable of being replaced i.e. two free registers can be found at both the start and end of replaced instruction pairs while the replaced instructions can be directly executed. Signed-off-by: NChen Guokai <chenguokai17@mails.ucas.ac.cn>
Showing
arch/riscv/kernel/probes/opt.c
0 → 100644
想要评论请 注册 或 登录