linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] riscv: kprobe: Fixup misaligned load text
@ 2023-02-04  6:35 guoren
  2023-02-06  8:15 ` Björn Töpel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: guoren @ 2023-02-04  6:35 UTC (permalink / raw)
  To: guoren, palmer, conor.dooley, liaochang1, bjorn, jrtc27
  Cc: linux-arch, linux-kernel, linux-riscv, Guo Ren, Bjorn Topel

From: Guo Ren <guoren@linux.alibaba.com>

The current kprobe would cause a misaligned load for the probe point.
This patch fixup it with two half-word loads instead.

Fixes: c22b0bcb1dd0 ("riscv: Add kprobes supported")
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Link: https://lore.kernel.org/linux-riscv/878rhig9zj.fsf@all.your.base.are.belong.to.us/
Reported-by: Bjorn Topel <bjorn.topel@gmail.com>
Cc: Jessica Clarke <jrtc27@jrtc27.com>
---
Changelog
V2:
 - Optimize coding convention (Thx Bjorn & Jessica)
---
 arch/riscv/kernel/probes/kprobes.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c
index c41bd8509032..d3b18e868f30 100644
--- a/arch/riscv/kernel/probes/kprobes.c
+++ b/arch/riscv/kernel/probes/kprobes.c
@@ -71,16 +71,18 @@ static bool __kprobes arch_check_kprobe(struct kprobe *p)
 
 int __kprobes arch_prepare_kprobe(struct kprobe *p)
 {
-	unsigned long probe_addr = (unsigned long)p->addr;
+	u16 *insn = (u16 *)p->addr;
 
-	if (probe_addr & 0x1)
+	if ((unsigned long)insn & 0x1)
 		return -EILSEQ;
 
 	if (!arch_check_kprobe(p))
 		return -EILSEQ;
 
 	/* copy instruction */
-	p->opcode = *p->addr;
+	p->opcode = (kprobe_opcode_t)(*insn++);
+	if (GET_INSN_LENGTH(p->opcode) == 4)
+		p->opcode |= (kprobe_opcode_t)(*insn) << 16;
 
 	/* decode instruction */
 	switch (riscv_probe_decode_insn(p->addr, &p->ainsn.api)) {
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] riscv: kprobe: Fixup misaligned load text
  2023-02-04  6:35 [PATCH V2] riscv: kprobe: Fixup misaligned load text guoren
@ 2023-02-06  8:15 ` Björn Töpel
  2023-02-09 23:37 ` Palmer Dabbelt
  2023-02-09 23:40 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 4+ messages in thread
From: Björn Töpel @ 2023-02-06  8:15 UTC (permalink / raw)
  To: guoren, guoren, palmer, conor.dooley, liaochang1, jrtc27
  Cc: linux-arch, linux-kernel, linux-riscv, Guo Ren, Bjorn Topel

guoren@kernel.org writes:

> From: Guo Ren <guoren@linux.alibaba.com>
>
> The current kprobe would cause a misaligned load for the probe point.
> This patch fixup it with two half-word loads instead.
>
> Fixes: c22b0bcb1dd0 ("riscv: Add kprobes supported")
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> Link: https://lore.kernel.org/linux-riscv/878rhig9zj.fsf@all.your.base.are.belong.to.us/
> Reported-by: Bjorn Topel <bjorn.topel@gmail.com>
> Cc: Jessica Clarke <jrtc27@jrtc27.com>
> ---
> Changelog
> V2:
>  - Optimize coding convention (Thx Bjorn & Jessica)

Thank you for fixing this!

Reviewed-by: Björn Töpel <bjorn@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] riscv: kprobe: Fixup misaligned load text
  2023-02-04  6:35 [PATCH V2] riscv: kprobe: Fixup misaligned load text guoren
  2023-02-06  8:15 ` Björn Töpel
@ 2023-02-09 23:37 ` Palmer Dabbelt
  2023-02-09 23:40 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2023-02-09 23:37 UTC (permalink / raw)
  To: Conor Dooley, liaochang1, bjorn, jrtc27, guoren
  Cc: linux-arch, linux-kernel, linux-riscv, Guo Ren,
	=C3=B6rn_T=C3=B6pel?=


On Sat, 04 Feb 2023 01:35:31 -0500, guoren@kernel.org wrote:
> The current kprobe would cause a misaligned load for the probe point.
> This patch fixup it with two half-word loads instead.
> 
> 

Applied, thanks!

[1/1] riscv: kprobe: Fixup misaligned load text
      https://git.kernel.org/palmer/c/eb7423273cc9

Best regards,
-- 
Palmer Dabbelt <palmer@rivosinc.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] riscv: kprobe: Fixup misaligned load text
  2023-02-04  6:35 [PATCH V2] riscv: kprobe: Fixup misaligned load text guoren
  2023-02-06  8:15 ` Björn Töpel
  2023-02-09 23:37 ` Palmer Dabbelt
@ 2023-02-09 23:40 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-02-09 23:40 UTC (permalink / raw)
  To: Guo Ren
  Cc: linux-riscv, palmer, conor.dooley, liaochang1, bjorn, jrtc27,
	linux-arch, linux-kernel, guoren, bjorn.topel

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Sat,  4 Feb 2023 01:35:31 -0500 you wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
> 
> The current kprobe would cause a misaligned load for the probe point.
> This patch fixup it with two half-word loads instead.
> 
> Fixes: c22b0bcb1dd0 ("riscv: Add kprobes supported")
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> Link: https://lore.kernel.org/linux-riscv/878rhig9zj.fsf@all.your.base.are.belong.to.us/
> Reported-by: Bjorn Topel <bjorn.topel@gmail.com>
> Cc: Jessica Clarke <jrtc27@jrtc27.com>
> 
> [...]

Here is the summary with links:
  - [V2] riscv: kprobe: Fixup misaligned load text
    https://git.kernel.org/riscv/c/eb7423273cc9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-09 23:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-04  6:35 [PATCH V2] riscv: kprobe: Fixup misaligned load text guoren
2023-02-06  8:15 ` Björn Töpel
2023-02-09 23:37 ` Palmer Dabbelt
2023-02-09 23:40 ` 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).