> From: Wang Han <[email protected]>
> 
> struct __arch_ftrace_regs declares s0 unconditionally, and both
> ftrace_regs_get_frame_pointer() and ftrace_partial_regs() read it
> unconditionally. But the SAVE_ABI_REGS / RESTORE_ABI_REGS macros in
> mcount-dyn.S only stored s0 under HAVE_FUNCTION_GRAPH_FP_TEST
> (CONFIG_FUNCTION_GRAPH_TRACER && CONFIG_FRAME_POINTER). With
> CONFIG_FRAME_POINTER=n the slot held whatever was on the stack before,
> so any callback going through ftrace_partial_regs() saw a garbage
> regs->s0. RISC-V kernels default to FRAME_POINTER=y, which is why this
> has not bitten in practice.
> 
> Save and restore s0 unconditionally in the dynamic ftrace ABI register
> frame. This fixes the latent garbage-s0 case, brings the dynamic ftrace
> path in line with the static _mcount path (mcount.S SAVE_ABI_STATE
> already saves s0 unconditionally), and matches the frame layout already
> documented in the comment above SAVE_ABI_REGS. It is also a prerequisite
> for the upcoming reliable unwinder, which reads
> ftrace_regs_get_frame_pointer(fregs) directly.
> 
> The cost is one extra REG_S/REG_L pair per traced call, negligible
> compared to the overall ftrace cost; the existing FREGS_SIZE_ON_STACK
> already reserved the slot, so no extra stack space is used.
> 
> Reviewed-by: Shuai Xue <[email protected]>
> Assisted-by: Qoder:Qwen-3.8-MAX-Preview
> Signed-off-by: Wang Han <[email protected]>
> Signed-off-by: Shuai Xue <[email protected]>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=3


Reply via email to