* [PATCH v2] riscv: provide riscv-specific is_trap_insn()
@ 2023-08-29 8:36 Nam Cao
2023-08-29 9:48 ` Guo Ren
2023-11-06 15:00 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 3+ messages in thread
From: Nam Cao @ 2023-08-29 8:36 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-riscv, linux-kernel
Cc: bjorn, guoren, conor.dooley, Nam Cao, Björn Töpel
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>
---
v2: remove #ifdef CONFIG_RISCV_ISA_C (Guo Ren)
arch/riscv/kernel/probes/uprobes.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probes/uprobes.c
index 194f166b2cc4..4b3dc8beaf77 100644
--- a/arch/riscv/kernel/probes/uprobes.c
+++ b/arch/riscv/kernel/probes/uprobes.c
@@ -3,6 +3,7 @@
#include <linux/highmem.h>
#include <linux/ptrace.h>
#include <linux/uprobes.h>
+#include <asm/insn.h>
#include "decode-insn.h"
@@ -17,6 +18,11 @@ bool is_swbp_insn(uprobe_opcode_t *insn)
#endif
}
+bool is_trap_insn(uprobe_opcode_t *insn)
+{
+ return riscv_insn_is_ebreak(*insn) || riscv_insn_is_c_ebreak(*insn);
+}
+
unsigned long uprobe_get_swbp_addr(struct pt_regs *regs)
{
return instruction_pointer(regs);
--
2.34.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] riscv: provide riscv-specific is_trap_insn()
2023-08-29 8:36 [PATCH v2] riscv: provide riscv-specific is_trap_insn() Nam Cao
@ 2023-08-29 9:48 ` Guo Ren
2023-11-06 15:00 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: Guo Ren @ 2023-08-29 9:48 UTC (permalink / raw)
To: Nam Cao
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-riscv,
linux-kernel, bjorn, conor.dooley, Björn Töpel
Thx for the fix.
Reviewed-by: Guo Ren <guoren@kernel.org>
On Tue, Aug 29, 2023 at 4:37 PM Nam Cao <namcaov@gmail.com> wrote:
>
> 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>
> ---
> v2: remove #ifdef CONFIG_RISCV_ISA_C (Guo Ren)
>
> arch/riscv/kernel/probes/uprobes.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probes/uprobes.c
> index 194f166b2cc4..4b3dc8beaf77 100644
> --- a/arch/riscv/kernel/probes/uprobes.c
> +++ b/arch/riscv/kernel/probes/uprobes.c
> @@ -3,6 +3,7 @@
> #include <linux/highmem.h>
> #include <linux/ptrace.h>
> #include <linux/uprobes.h>
> +#include <asm/insn.h>
>
> #include "decode-insn.h"
>
> @@ -17,6 +18,11 @@ bool is_swbp_insn(uprobe_opcode_t *insn)
> #endif
> }
>
> +bool is_trap_insn(uprobe_opcode_t *insn)
> +{
> + return riscv_insn_is_ebreak(*insn) || riscv_insn_is_c_ebreak(*insn);
> +}
> +
> unsigned long uprobe_get_swbp_addr(struct pt_regs *regs)
> {
> return instruction_pointer(regs);
> --
> 2.34.1
>
--
Best Regards
Guo Ren
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] riscv: provide riscv-specific is_trap_insn()
2023-08-29 8:36 [PATCH v2] riscv: provide riscv-specific is_trap_insn() Nam Cao
2023-08-29 9:48 ` Guo Ren
@ 2023-11-06 15:00 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-11-06 15:00 UTC (permalink / raw)
To: Nam Cao
Cc: linux-riscv, paul.walmsley, palmer, aou, linux-kernel, bjorn,
guoren, conor.dooley, bjorn
Hello:
This patch was applied to riscv/linux.git (for-next)
by Palmer Dabbelt <palmer@rivosinc.com>:
On Tue, 29 Aug 2023 10:36:15 +0200 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [v2] riscv: provide riscv-specific is_trap_insn()
https://git.kernel.org/riscv/c/b701f9e726f0
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-06 15:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-29 8:36 [PATCH v2] riscv: provide riscv-specific is_trap_insn() Nam Cao
2023-08-29 9:48 ` Guo Ren
2023-11-06 15:00 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).