riscv: probes: simulate c.jal instruction
PATCH v5 1/1 riscv: probes: simulate c.jal instruction
The c.jal instruction is currently marked REJECTED in kprobes instruction decoding, but it should be SIMULATED like other compressed jump instructions.
Add simulate_c_jal() which saves the return address to RA and sets the program counter to the target offset, reusing simulate_c_j for the common jump logic.
Since c.jal is RV32-only, guard the implementation with
Signed-off-by Xiaofeng Yuan <[email protected]>
#if __riscv_xlen == 32.
---
v4: use regs->ra directly; reorder SET_SIMULATE (per Nam Cao's review)
v5: add #if __riscv_xlen == 32 guard (per Charlie Li's review); removed test case (already provided by Nam Cao)
arch/riscv/kernel/probes/decode-insn.c | 4 +++- arch/riscv/kernel/probes/simulate-insn.c | 9 +++++++++ arch/riscv/kernel/probes/simulate-insn.h | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-)
arch/riscv/kernel/probes/decode-insn.c +3 -1
@@ -29,12 +29,14 @@ riscv_probe_decode_insn(probe_opcode_t *addr, struct arch_probe_insn *api)* TODO: the REJECTED ones below need to be implemented */ #ifdef CONFIG_RISCV_ISA_C -RISCV_INSN_REJECTED (c_jal, insn);RISCV_INSN_REJECTED (c_ebreak, insn);RISCV_INSN_SET_SIMULATE (c_j, insn);RISCV_INSN_SET_SIMULATE (c_jr, insn);RISCV_INSN_SET_SIMULATE (c_jalr, insn); +#if __riscv_xlen ==32 +RISCV_INSN_SET_SIMULATE (c_jal, insn); +#endif RISCV_INSN_SET_SIMULATE (c_beqz, insn);RISCV_INSN_SET_SIMULATE (c_bnez, insn);#endif
arch/riscv/kernel/probes/simulate-insn.c +9 -0
@@ -163,6 +163,15 @@ bool __kprobes simulate_c_j(u32 opcode, unsigned long addr, struct pt_regs *regsreturn true; } +#if __riscv_xlen ==32 +bool __kprobes simulate_c_jal (u32 opcode,unsigned long addr,struct pt_regs *regs) +{ + regs->ra = addr +2 ; + +return simulate_c_j (opcode, addr, regs); +} +#endif +static bool __kprobes simulate_c_jr_jalr (u32 opcode,unsigned long addr,struct pt_regs *regs,bool is_jalr) {
arch/riscv/kernel/probes/simulate-insn.h +3 -0
@@ -25,6 +25,9 @@ bool simulate_branch(u32 opcode, unsigned long addr, struct pt_regs *regs);bool simulate_jal (u32 opcode,unsigned long addr,struct pt_regs *regs);bool simulate_jalr (u32 opcode,unsigned long addr,struct pt_regs *regs);bool simulate_c_j (u32 opcode,unsigned long addr,struct pt_regs *regs); +#if __riscv_xlen ==32 +bool simulate_c_jal (u32 opcode,unsigned long addr,struct pt_regs *regs); +#endif bool simulate_c_jr (u32 opcode,unsigned long addr,struct pt_regs *regs);bool simulate_c_jalr (u32 opcode,unsigned long addr,struct pt_regs *regs);bool simulate_c_bnez (u32 opcode,unsigned long addr,struct pt_regs *regs);
Signature · 1 line
2.43.0