All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dylan Hatch" <dylanbhatch@google.com>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Weinan Liu" <wnliu@google.com>, "Will Deacon" <will@kernel.org>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Indu Bhagat" <ibhagatgnu@gmail.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Jiri Kosina" <jikos@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Jens Remus" <jremus@linux.ibm.com>
Cc: "Prasanna Kumar T S M" <ptsm@linux.microsoft.com>,
	"Puranjay Mohan" <puranjay@kernel.org>,
	"Song Liu" <song@kernel.org>,
	joe.lawrence@redhat.com, live-patching@vger.kernel.org,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Mostafa Saleh" <smostafa@google.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH v9 11/11] unwind: arm64: Use sframe to unwind interrupt frames
Date: Tue, 17 Nov 2026 03:19:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-218134@kernel.org> (raw)
In-Reply-To: <20261117020648.323464-12-dylanbhatch@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] arm64: stacktrace: kunwind_next() clears state->regs after
  fallback
- [Low] unwind: arm64: consume FP stack slot in
  kunwind_next_regs_sframe()
--

commit e44539400678f653df77eaa983169650892957a4
Author: Dylan Hatch <dylanbhatch@google.com>

unwind: arm64: Use sframe to unwind interrupt frames

This commit adds kunwind_next_regs_sframe() to unwind across exception
boundaries using SFrame information, falling back to frame-pointer
unwinding and marking the stacktrace unreliable on failure.

> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> index 3ebcf8c53fb04..e876af54a4055 100644
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c

[ ... ]

> @@ -244,6 +266,163 @@ kunwind_next_frame_record(struct kunwind_state *state)

[ ... ]

> +	/*
> +	 * Consume RA and FP from the stack. The frame record puts FP at a lower
> +	 * address than RA, so we read FP first.
> +	 */
> +	switch (frame.fp.rule) {
> +	case UNWIND_RULE_RETAIN:
> +		fp = state->common.fp;
> +		break;
> +	/*
> +	 * UNWIND_RULE_CFA_OFFSET is currently not used for FP
> +	 * (e.g. SFrame cannot represent this rule).
> +	 */
> +	case UNWIND_RULE_CFA_OFFSET_DEREF:
> +		fp = cfa + frame.fp.offset;
> +		if (!get_word(&state->common, &fp))
> +			return -EINVAL;
> +		break;
> +	/*
> +	 * UNWIND_RULE_REG_OFFSET and UNWIND_RULE_REG_OFFSET_DEREF not
> +	 * implemented -- flexible FDEs are not currently generated by assembler
> +	 * for arm64.
> +	 */
> +	default:
> +		WARN_ON_ONCE(1);
> +		return -EINVAL;
> +	}
> +
> +	switch (frame.ra.rule) {
> +	case UNWIND_RULE_RETAIN:
> +		ra = regs->regs[30];
> +		source = KUNWIND_SOURCE_REGS_LR;
> +		break;
> +
> +	/*
> +	 * UNWIND_RULE_CFA_OFFSET doesn't make sense for RA.
> +	 * The return address cannot legitimately be a stack address.
> +	 */
> +	case UNWIND_RULE_CFA_OFFSET_DEREF:
> +		ra = cfa + frame.ra.offset;
> +		if (get_consume_word(&state->common, &ra))
> +			return -EINVAL;
> +		break;

[Severity: Low]
Does UNWIND_RULE_CFA_OFFSET_DEREF for frame.fp.rule miss calling
unwind_consume_stack() when frame.ra.rule is UNWIND_RULE_RETAIN (or
frame.fp.offset >= frame.ra.offset)?

get_word() reads the saved FP from the stack without consuming it, relying on
get_consume_word() for frame.ra to advance state->common.stack.low.  If RA is
retained in LR, the FP slot is never consumed, leaving state->common.stack
unadvanced (or failing to transition stacks if CFA + frame.fp.offset lies on
the previous stack) while state->unreliable stays false.  Note that the stack
should only be consumed after both frame.fp and frame.ra checks succeed so
state->common.stack remains intact if kunwind_next_regs_sframe() fails and
falls back to kunwind_next_frame_record().

[ ... ]

> @@ -259,10 +438,23 @@ kunwind_next(struct kunwind_state *state)
>  	state->flags.all = 0;
>  
>  	switch (state->source) {
> +	case KUNWIND_SOURCE_REGS_PC:
> +		if (state->regs)
> +			err = kunwind_next_regs_sframe(state);
> +		else
> +			err = -EINVAL;
> +
> +		if (err) {
> +			/* Fallback to FP based unwinder */
> +			err = kunwind_next_frame_record(state);
> +			state->unreliable = true;
> +		}
> +		state->regs = NULL;
> +		break;

[Severity: Medium]
Should state->regs be cleared before calling the fallback
kunwind_next_frame_record(state)?

When kunwind_next() falls back to kunwind_next_frame_record() (for example on
a synthetic pt_regs or an exception in entry.S without SFrame data) and
state->common.fp points directly to an on-stack FRAME_META_TYPE_PT_REGS
record, kunwind_next_frame_record() calls kunwind_next_regs_pc(), which sets
state->regs = regs and state->source = KUNWIND_SOURCE_REGS_PC for that next
exception frame.  Executing state->regs = NULL afterwards overwrites that new
pointer, preventing SFrame unwinding on the next exception boundary.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117020648.323464-1-dylanbhatch@google.com?part=11

      reply	other threads:[~2026-11-17  3:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  2:06 [PATCH v9 00/11] unwind, arm64: add sframe unwinder for kernel Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 01/11] arm64, unwind: build kernel with sframe V3 info Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 02/11] arm64/sframe: Read vmlinux .sframe header Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 03/11] sframe: Add support for reading vmlinux .sframe contents Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 04/11] sframe: Separate reading of FRE from reading of FRE data words Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 05/11] module, sframe: Add sframe support for modules Dylan Hatch
2026-11-17  2:34   ` sashiko-bot
2026-11-17  2:06 ` [PATCH v9 06/11] arm64/sframe: Validate IP addresses Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 07/11] sframe: Add debug helpers with object name Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 08/11] sframe: Add .sframe validation option Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 09/11] arm64: entry: add unwind info for call_on_irq_stack() Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 10/11] arm64, crypto/lib: Annotate leaf functions with CFI info Dylan Hatch
2026-11-17  2:06 ` [PATCH v9 11/11] unwind: arm64: Use sframe to unwind interrupt frames Dylan Hatch
2026-11-17  3:19   ` sashiko-bot [this message]

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=sashiko-outbox-218134@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=davem@davemloft.net \
    --cc=dylanbhatch@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ibhagatgnu@gmail.com \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=jremus@linux.ibm.com \
    --cc=live-patching@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=ptsm@linux.microsoft.com \
    --cc=puranjay@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=smostafa@google.com \
    --cc=song@kernel.org \
    --cc=will@kernel.org \
    --cc=wnliu@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.