From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1A893A6F1A; Tue, 2 Jun 2026 11:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780400258; cv=none; b=YreXgs2KqybfEjCdst+g15STxmgzPYPERGJ2vbywr7sH1/4aDV63QvsZ0pE/lbMDzlXMdPNtAAJXpF+ckKvwCLwKaU3/ETZdLZzCOsZAoXvGeSfN6okhce56owYp8od52R7eJ5sekN8zBlFpBXWCvpzUeIfKLOPsZtXQvghyUic= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780400258; c=relaxed/simple; bh=185K9IDgIj/Feo66qKQnCyRFQ1fH9VLKwHJVJJOu/ts=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=e9SbaEmGWtyIQBZ4SBztXWg57Ackfp6CS0J6ObeIAdK5AUoeRHV70pODsiV6djJ9djyIJWAyFkPYBEvATBzV2xB+N27DSdY+lqPhtqtJSXF48EiTxqBGCkt7WegAZk/ozVMpSEJX2O25UjQmkYvSdCdnlPiS/7fH9SRtrAIoTXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=vwotUiYD; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="vwotUiYD" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1780400248; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=185K9IDgIj/Feo66qKQnCyRFQ1fH9VLKwHJVJJOu/ts=; b=vwotUiYDpASiJ9IaEOoBQJvZhQroxl5futEA+zan9w/t6r4g2F5uP73i4Ke8L0EqgA2K+k7GKRgvHYTAa+FOt1GcFIOke6LdsgWxea/nRz8PURJbz4NWavmWufie7JeqbAMVhwBufPCwumw3x00v6Svv3JnzbspCnWcpMA01MK4= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R321e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=34;SR=0;TI=SMTPD_---0X44RHXL_1780400244; Received: from 30.100.154.88(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0X44RHXL_1780400244 cluster:ay36) by smtp.aliyun-inc.com; Tue, 02 Jun 2026 19:37:26 +0800 Message-ID: Date: Tue, 2 Jun 2026 19:37:23 +0800 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/8] riscv: ftrace: always preserve s0 in dynamic ftrace register frame To: Wang Han , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Steven Rostedt , Alexandre Ghiti , Masami Hiramatsu , Mark Rutland , Catalin Marinas , Chen Pei , Andy Chiu , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Deepak Gupta , Puranjay Mohan , Conor Dooley , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Shuah Khan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , oliver.yang@linux.alibaba.com, zhuo.song@linux.alibaba.com, jkchen@linux.alibaba.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-perf-users@vger.kernel.org References: <20260527123530.2593918-1-wanghan@linux.alibaba.com> <20260528082310.1994388-5-wanghan@linux.alibaba.com> From: Shuai Xue In-Reply-To: <20260528082310.1994388-5-wanghan@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/28/26 4:23 PM, Wang Han wrote: > The dynamic ftrace entry/exit only saved s0 (the architectural frame > pointer) when HAVE_FUNCTION_GRAPH_FP_TEST was selected. The upcoming > reliable frame-pointer unwinder needs s0 to be present in > ftrace_regs unconditionally so it can use the frame pointer as the > function-graph return-address cookie regardless of FP_TEST. Nit: A prefered commit log: 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. 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 Thanks. Shuai