From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 0F74A1DCB3F for ; Mon, 6 Jan 2025 11:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736162134; cv=none; b=gmYKdOJWxYxnhdFgJ3TvUva0W6pqCCGQ2jsNqDK0ypIdXWEl9TTW18E2/u8XD6mkHKV4yt+PmjWbq+AkOk5V+9v2+J5bZUo0ESkm43ntbdiYuVNG5H+5n+vy8PU/NdUipZaSG4Y/yqKks2qQBVFcCZiZb5nns+8CKXxHVh5jlVI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736162134; c=relaxed/simple; bh=7OBFF42Hm/p5LVT67Sm544yZ9YaaB2amJpdU650Cufo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=K8o46vp9WmoZAx0SaKfYnPWWH3KraAGOwmPTx0qTm6GANQX7vlGB5KSpJA8rbUunXZEmF/07l2PnSMZPszZc3A+FpPwAWwlGVxa8xLE9e8wH0+lci9MqdxCULSHEYkAFKEOxCz18vRjTw8wh+1wU0y7dJPTQaMK4BqNte0olF4g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr; spf=pass smtp.mailfrom=ghiti.fr; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id AC9DE1BF204; Mon, 6 Jan 2025 11:15:21 +0000 (UTC) Message-ID: <8264591a-68ad-4d11-ab78-2ebd73c8cb02@ghiti.fr> Date: Mon, 6 Jan 2025 12:15:21 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] riscv: stacktrace: fix backtracing through exceptions Content-Language: en-US To: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Paul Walmsley , Palmer Dabbelt , "open list:RISC-V ARCHITECTURE" , open list Cc: Anton Blanchard References: <20241209155714.1239665-1-cleger@rivosinc.com> From: Alexandre Ghiti In-Reply-To: <20241209155714.1239665-1-cleger@rivosinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Sasl: alex@ghiti.fr Hi Clément, On 09/12/2024 16:57, Clément Léger wrote: > Prior to commit 5d5fc33ce58e ("riscv: Improve exception and system call > latency"), backtrace through exception worked since ra was filled with > ret_from_exception symbol address and the stacktrace code checked 'pc' to > be equal to that symbol. Now that handle_exception uses regular 'call' > instructions, this isn't working anymore and backtrace stops at > handle_exception(). Since there are multiple call site to C code in the > exception handling path, rather than checking multiple potential return > addresses, add a new symbol at the end of exception handling and check pc > to be in that range. > > Fixes: 5d5fc33ce58e ("riscv: Improve exception and system call latency") > Signed-off-by: Clément Léger > > --- > arch/riscv/kernel/entry.S | 1 + > arch/riscv/kernel/stacktrace.c | 4 +++- > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S > index 216581835eb0..33a5a9f2a0d4 100644 > --- a/arch/riscv/kernel/entry.S > +++ b/arch/riscv/kernel/entry.S > @@ -278,6 +278,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception) > #else > sret > #endif > +SYM_INNER_LABEL(ret_from_exception_end, SYM_L_GLOBAL) > SYM_CODE_END(ret_from_exception) > ASM_NOKPROBE(ret_from_exception) > > diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c > index 153a2db4c5fa..d4355c770c36 100644 > --- a/arch/riscv/kernel/stacktrace.c > +++ b/arch/riscv/kernel/stacktrace.c > @@ -17,6 +17,7 @@ > #ifdef CONFIG_FRAME_POINTER > > extern asmlinkage void handle_exception(void); > +extern unsigned long ret_from_exception_end; > > static inline int fp_is_valid(unsigned long fp, unsigned long sp) > { > @@ -71,7 +72,8 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, > fp = frame->fp; > pc = ftrace_graph_ret_addr(current, &graph_idx, frame->ra, > &frame->ra); > - if (pc == (unsigned long)handle_exception) { > + if (pc >= (unsigned long)handle_exception && > + pc < (unsigned long)&ret_from_exception_end) { > if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc))) > break; > You can add: Tested-by: Alexandre Ghiti Reviewed-by: Alexandre Ghiti Thanks, Alex