Skip to content

Commit b2d473a

Browse files
bjorn-rivospalmer-dabbelt
authored andcommitted
riscv, kprobes: Stricter c.jr/c.jalr decoding
In the compressed instruction extension, c.jr, c.jalr, c.mv, and c.add is encoded the following way (each instruction is 16b): ---+-+-----------+-----------+-- 100 0 rs1[4:0]!=0 00000 10 : c.jr 100 1 rs1[4:0]!=0 00000 10 : c.jalr 100 0 rd[4:0]!=0 rs2[4:0]!=0 10 : c.mv 100 1 rd[4:0]!=0 rs2[4:0]!=0 10 : c.add The following logic is used to decode c.jr and c.jalr: insn & 0xf007 == 0x8002 => instruction is an c.jr insn & 0xf007 == 0x9002 => instruction is an c.jalr When 0xf007 is used to mask the instruction, c.mv can be incorrectly decoded as c.jr, and c.add as c.jalr. Correct the decoding by changing the mask from 0xf007 to 0xf07f. Fixes: c22b0bc ("riscv: Add kprobes supported") Signed-off-by: Björn Töpel <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Guo Ren <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1b929c0 commit b2d473a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/riscv/kernel/probes/simulate-insn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f);
3131
} while (0)
3232

3333
__RISCV_INSN_FUNCS(c_j, 0xe003, 0xa001);
34-
__RISCV_INSN_FUNCS(c_jr, 0xf007, 0x8002);
34+
__RISCV_INSN_FUNCS(c_jr, 0xf07f, 0x8002);
3535
__RISCV_INSN_FUNCS(c_jal, 0xe003, 0x2001);
36-
__RISCV_INSN_FUNCS(c_jalr, 0xf007, 0x9002);
36+
__RISCV_INSN_FUNCS(c_jalr, 0xf07f, 0x9002);
3737
__RISCV_INSN_FUNCS(c_beqz, 0xe003, 0xc001);
3838
__RISCV_INSN_FUNCS(c_bnez, 0xe003, 0xe001);
3939
__RISCV_INSN_FUNCS(c_ebreak, 0xffff, 0x9002);

0 commit comments

Comments
 (0)