Skip to content

Commit 8533d5b

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: stacktrace: restore terminal records
We removed the terminal frame records in commit: 6106e11 ("arm64: remove EL0 exception frame record") ... on the assumption that as we no longer used them to find the pt_regs at exception boundaries, they were no longer necessary. However, Leo reports that as an unintended side-effect, this causes traces which cross secondary_start_kernel to terminate one entry too late, with a spurious "0" entry. There are a few ways we could sovle this, but as we're planning to use terminal records for RELIABLE_STACKTRACE, let's revert the logic change for now, keeping the update comments and accounting for the changes in commit: 3c02600 ("arm64: stacktrace: Report when we reach the end of the stack") This is effectively a partial revert of commit: 6106e11 ("arm64: remove EL0 exception frame record") Signed-off-by: Mark Rutland <[email protected]> Fixes: 6106e11 ("arm64: remove EL0 exception frame record") Reported-by: Leo Yan <[email protected]> Tested-by: Leo Yan <[email protected]> Cc: Will Deacon <[email protected]> Cc: Mark Brown <[email protected]> Cc: "Madhavan T. Venkataraman" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 3887080 commit 8533d5b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

arch/arm64/kernel/entry.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,16 @@ alternative_else_nop_endif
283283
stp lr, x21, [sp, #S_LR]
284284

285285
/*
286-
* For exceptions from EL0, terminate the callchain here.
286+
* For exceptions from EL0, create a terminal frame record.
287287
* For exceptions from EL1, create a synthetic frame record so the
288288
* interrupted code shows up in the backtrace.
289289
*/
290290
.if \el == 0
291-
mov x29, xzr
291+
stp xzr, xzr, [sp, #S_STACKFRAME]
292292
.else
293293
stp x29, x22, [sp, #S_STACKFRAME]
294-
add x29, sp, #S_STACKFRAME
295294
.endif
295+
add x29, sp, #S_STACKFRAME
296296

297297
#ifdef CONFIG_ARM64_SW_TTBR0_PAN
298298
alternative_if_not ARM64_HAS_PAN

arch/arm64/kernel/stacktrace.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
6868
unsigned long fp = frame->fp;
6969
struct stack_info info;
7070

71-
/* Terminal record; nothing to unwind */
72-
if (!fp)
73-
return -ENOENT;
74-
7571
if (fp & 0xf)
7672
return -EINVAL;
7773

@@ -132,6 +128,12 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
132128

133129
frame->pc = ptrauth_strip_insn_pac(frame->pc);
134130

131+
/*
132+
* This is a terminal record, so we have finished unwinding.
133+
*/
134+
if (!frame->fp && !frame->pc)
135+
return -ENOENT;
136+
135137
return 0;
136138
}
137139
NOKPROBE_SYMBOL(unwind_frame);

0 commit comments

Comments
 (0)