riscv: probes: simulate c.jal instruction
PATCH v2 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 x1 (ra) and sets the program counter to the target offset, reusing simulate_c_j for the common jump logic.
Signed-off-by Xiaofeng Yuan <[email protected]>
---
v2: reuse simulate_c_j() for common jump logic (per Nam Cao's review)
arch/riscv/kernel/probes/decode-insn.c | 2 +- arch/riscv/kernel/probes/simulate-insn.c | 16 ++++++++++++++++ arch/riscv/kernel/probes/simulate-insn.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-)
arch/riscv/kernel/probes/decode-insn.c +1 -1
@@ -29,7 +29,7 @@ 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_SET_SIMULATE (c_jal, insn);RISCV_INSN_REJECTED (c_ebreak, insn);RISCV_INSN_SET_SIMULATE (c_j, insn);
arch/riscv/kernel/probes/simulate-insn.c +16 -0
@@ -163,6 +163,22 @@ bool __kprobes simulate_c_j(u32 opcode, unsigned long addr, struct pt_regs *regsreturn true; } +bool __kprobes simulate_c_jal (u32 opcode,unsigned long addr,struct pt_regs *regs) +{ +bool ret; +s32 imm; + + ret =rv_insn_reg_set_val (regs,1 , addr +2 ); +if (!ret) +return ret; + + imm =RVC_EXTRACT_JTYPE_IMM (opcode); + +instruction_pointer_set (regs, addr + imm); + +return ret; +} +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 +1 -0
@@ -25,6 +25,7 @@ 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); +bool simulate_c_jal (u32 opcode,unsigned long addr,struct pt_regs *regs);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