Skip to contentSkip to conversation

riscv: kprobe: Fixup misaligned load text

PATCH Applied [email protected] 4 participants 4 messages Feb 4, 2023 – Feb 9, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 riscv: kprobe: Fixup misaligned load text

From: Guo Ren <[email protected]>

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")
Cc Jessica Clarke <[email protected]>

---
Changelog
V2:
- Optimize coding convention (Thx Bjorn & Jessica)

---
 arch/riscv/kernel/probes/kprobes.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/riscv/kernel/probes/kprobes.c +5 -3
index c41bd8509032..d3b18e868f30 100644
@@ -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)) {
Signature · 1 line
2.36.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · [email protected] writes:

From: Guo Ren <[email protected]>

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")
Cc Jessica Clarke <[email protected]>
Quoted 4 lines

---
Changelog
V2:
- Optimize coding convention (Thx Bjorn & Jessica)

Thank you for fixing this!

#2 lore raw
In reply to [email protected]
Quoted 4 lines · On Sat, 04 Feb 2023 01:35:31 -0500, [email protected] 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,

Signature · 7 lines
Palmer Dabbelt <[email protected]>


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw
In reply to [email protected]
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:

Quoted 5 lines · On Sat, 4 Feb 2023 01:35:31 -0500 you wrote:

From: Guo Ren <[email protected]>

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

Quoted 8 lines
Fixes c22b0bcb1dd0 ("riscv: Add kprobes supported")
Cc Jessica Clarke <[email protected]>

[...]

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!

Signature · 9 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv