Linux Trace Kernel
 help / color / mirror / Atom feed
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>,
	Danish Khateeb <danishkhateeb03@gmail.com>,
	sparclinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kernel@vger.kernel.org, Stian Halseth <stian@itx.no>
Subject: [PATCH v2 3/4] sparc64: kprobes: Resume after a delay slot at the saved next PC
Date: Fri, 13 Nov 2026 15:40:56 +0100	[thread overview]
Message-ID: <20261113144057.1697874-4-stian@itx.no> (raw)
In-Reply-To: <20261113144057.1697874-1-stian@itx.no>

After single-stepping an instruction that does not branch, execution
resumes at the saved next PC. The probed address plus 8 comes next.
For an instruction in the delay slot of a taken branch the saved next
PC is the branch target. Execution then goes back to the probed
address plus 8. It should continue at the target plus 4.

Use the saved next PC plus 4. For any other instruction that is the
probed address plus 8.

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


  parent reply	other threads:[~2026-11-13 14:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 14:40 [PATCH v2 0/4] sparc64: kprobes: Make kprobes work on sun4v Stian Halseth
2026-11-13 14:40 ` [PATCH v2 1/4] sparc64: kprobes: Single-step from an executable instruction slot Stian Halseth
2026-11-13 14:40 ` [PATCH v2 2/4] sparc64: kprobes: Fix up register and FP branches after single-step Stian Halseth
2026-11-13 14:40 ` Stian Halseth [this message]
2026-11-13 14:47   ` [PATCH v2 3/4] sparc64: kprobes: Resume after a delay slot at the saved next PC sashiko-bot
2026-11-13 14:40 ` [PATCH v2 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=20261113144057.1697874-4-stian@itx.no \
    --to=stian@itx.no \
    --cc=andreas@gaisler.com \
    --cc=danishkhateeb03@gmail.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