riscv: provide riscv-specific is_trap_insn()
authorNam Cao <namcaov@gmail.com>
Tue, 29 Aug 2023 08:36:15 +0000 (10:36 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Sun, 5 Nov 2023 22:12:28 +0000 (14:12 -0800)
commitb701f9e726f0a30a94ea6af596b74c1f07b95b6b
tree731d9ce1dc2aff4a2da59761e46d950cc7d62caf
parent3ce99bd6357d4789c138898d9a07916d0f3b7f29
riscv: provide riscv-specific is_trap_insn()

uprobes expects is_trap_insn() to return true for any trap instructions,
not just the one used for installing uprobe. The current default
implementation only returns true for 16-bit c.ebreak if C extension is
enabled. This can confuse uprobes if a 32-bit ebreak generates a trap
exception from userspace: uprobes asks is_trap_insn() who says there is no
trap, so uprobes assume a probe was there before but has been removed, and
return to the trap instruction. This causes an infinite loop of entering
and exiting trap handler.

Instead of using the default implementation, implement this function
speficially for riscv with checks for both ebreak and c.ebreak.

Fixes: 74784081aac8 ("riscv: Add uprobes supported")
Signed-off-by: Nam Cao <namcaov@gmail.com>
Tested-by: Björn Töpel <bjorn@rivosinc.com>
Reviewed-by: Guo Ren <guoren@kernel.org>
Link: https://lore.kernel.org/r/20230829083614.117748-1-namcaov@gmail.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/kernel/probes/uprobes.c