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 3/4] sparc64: kprobes: Resume after a delay slot at the saved next PC
Date: Fri, 9 Oct 2026 20:03:34 +0200 [thread overview]
Message-ID: <20261009180336.1315684-4-stian@itx.no> (raw)
In-Reply-To: <20261009180336.1315684-1-stian@itx.no>
After single-stepping an instruction that does not branch, execution
resumes at the saved next PC, followed by the probed address plus 8.
For an instruction in the delay slot of a taken branch the saved next
PC is the branch target, so after the target execution goes back to
the probed address plus 8 instead of continuing at the target plus 4.
Use the saved next PC plus 4, which equals the probed address plus 8
for any other instruction.
Link: https://github.com/sparclinux/issues/issues/110
Signed-off-by: Stian Halseth <stian@itx.no>
---
arch/sparc/kernel/kprobes.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/sparc/kernel/kprobes.c b/arch/sparc/kernel/kprobes.c
index 38e6d9b51a207..327d83188a978 100644
--- a/arch/sparc/kernel/kprobes.c
+++ b/arch/sparc/kernel/kprobes.c
@@ -211,13 +211,14 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
*
*/
static unsigned long __kprobes relbranch_fixup(u32 insn, struct kprobe *p,
- struct pt_regs *regs)
+ struct pt_regs *regs,
+ struct kprobe_ctlblk *kcb)
{
unsigned long real_pc = (unsigned long) p->addr;
/* Branch not taken, no mods necessary. */
if (regs->tnpc == regs->tpc + 0x4UL)
- return real_pc + 0x8UL;
+ return kcb->kprobe_orig_tnpc + 0x4UL;
/* The cases are call and the branches BPcc, Bicc, BPr, FBPfcc
* and FBfcc.
@@ -294,7 +295,7 @@ static void __kprobes resume_execution(struct kprobe *p,
{
u32 insn = p->ainsn.insn[0];
- regs->tnpc = relbranch_fixup(insn, p, regs);
+ regs->tnpc = relbranch_fixup(insn, p, regs, kcb);
/* This assignment must occur after relbranch_fixup() */
regs->tpc = kcb->kprobe_orig_tnpc;
--
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 ` [PATCH 1/4] sparc64: kprobes: Single-step from an executable instruction slot Stian Halseth
2026-11-13 9:32 ` 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 ` Stian Halseth [this message]
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-4-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®