From: Stian Halseth <stian@itx.no>
To: "David S. Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Naveen N Rao <naveen@kernel.org>,
sparclinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org, Stian Halseth <stian@itx.no>
Subject: [PATCH 1/4] sparc64: kprobes: Single-step from an executable instruction slot
Date: Fri, 9 Oct 2026 20:03:32 +0200 [thread overview]
Message-ID: <20261009180336.1315684-2-stian@itx.no> (raw)
In-Reply-To: <20261009180336.1315684-1-stian@itx.no>
kprobes single-steps the probed instruction from kprobe->ainsn.insn[],
which is part of the kprobe itself and so lives in the linear mapping.
The sun4v linear mapping is not executable, and every probe hit oopses:
sun4v_insn_access_exception: ADDR[fff800005b0cd66c] CTX[0000] TYPE[0006], going.
Allocate the slot with get_insn_slot(), as other architectures do. It
comes from executable memory in the module area.
Fixes: c4bce90ea2069 ("[SPARC64]: Deal with PTE layout differences in SUN4V.")
Closes: https://github.com/sparclinux/issues/issues/110
Signed-off-by: Stian Halseth <stian@itx.no>
---
arch/sparc/include/asm/kprobes.h | 7 +++++--
arch/sparc/kernel/kprobes.c | 12 ++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/include/asm/kprobes.h b/arch/sparc/include/asm/kprobes.h
index aec742cd898f2..8cc9697846fa1 100644
--- a/arch/sparc/include/asm/kprobes.h
+++ b/arch/sparc/include/asm/kprobes.h
@@ -11,13 +11,16 @@
#include <linux/types.h>
#include <linux/percpu.h>
+#define __ARCH_WANT_KPROBES_INSN_SLOT
+
typedef u32 kprobe_opcode_t;
#define MAX_INSN_SIZE 2
#define kretprobe_blacklist_size 0
-#define arch_remove_kprobe(p) do {} while (0)
+struct kprobe;
+void arch_remove_kprobe(struct kprobe *p);
#define flush_insn_slot(p) \
do { flushi(&(p)->ainsn.insn[0]); \
@@ -29,7 +32,7 @@ void __kretprobe_trampoline(void);
/* Architecture specific copy of original instruction*/
struct arch_specific_insn {
/* copy of the original instruction */
- kprobe_opcode_t insn[MAX_INSN_SIZE];
+ kprobe_opcode_t *insn;
};
struct prev_kprobe {
diff --git a/arch/sparc/kernel/kprobes.c b/arch/sparc/kernel/kprobes.c
index 191bbaca99212..608efda8cb948 100644
--- a/arch/sparc/kernel/kprobes.c
+++ b/arch/sparc/kernel/kprobes.c
@@ -52,6 +52,10 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
if ((unsigned long) p->addr & 0x3UL)
return -EILSEQ;
+ p->ainsn.insn = get_insn_slot();
+ if (!p->ainsn.insn)
+ return -ENOMEM;
+
p->ainsn.insn[0] = *p->addr;
flushi(&p->ainsn.insn[0]);
@@ -62,6 +66,14 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
return 0;
}
+void __kprobes arch_remove_kprobe(struct kprobe *p)
+{
+ if (p->ainsn.insn) {
+ free_insn_slot(p->ainsn.insn, 0);
+ p->ainsn.insn = NULL;
+ }
+}
+
void __kprobes arch_arm_kprobe(struct kprobe *p)
{
*p->addr = BREAKPOINT_INSTRUCTION;
--
2.43.0
next prev parent reply other threads:[~2026-10-09 18:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 18:03 [PATCH 0/4] sparc64: kprobes: Make kprobes work on sun4v Stian Halseth
2026-10-09 18:03 ` Stian Halseth [this message]
2026-11-13 9:32 ` [PATCH 1/4] sparc64: kprobes: Single-step from an executable instruction slot Masami Hiramatsu (Google)
2026-11-13 11:09 ` Stian Halseth
2026-10-09 18:03 ` [PATCH 2/4] sparc64: kprobes: Fix up register and FP branches after single-step Stian Halseth
2026-10-09 18:03 ` [PATCH 3/4] sparc64: kprobes: Resume after a delay slot at the saved next PC Stian Halseth
2026-10-09 18:03 ` [PATCH 4/4] sparc64: kprobes: Handle annulled branches Stian Halseth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261009180336.1315684-2-stian@itx.no \
--to=stian@itx.no \
--cc=andreas@gaisler.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=naveen@kernel.org \
--cc=sparclinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®