From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 2CDD232B132; Tue, 21 Jul 2026 19:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784661958; cv=none; b=Oa6fO5iVbD6G511ClcUhxAT0Cp6BgiaPCc1wV5eWIbV7Cj7P/Xf1p9JfUNEG4aWbiw0pjn8jkPEHomJ3III77s9tgNSHT+T10nxcU4omu3FPoZZkLkQxxYH70UX4TsTvEAykpPagdgqTi/IYXshiD1SvT2CkEB/yPQgIup7cyPw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784661958; c=relaxed/simple; bh=ECEAn6NVjt9b8VyjV1+7mEQsWw6g8tZL728Mta8wFgY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FG7DlSkjEVzrZBY3FKjRcduDsGTH7Zixc2m+GVA8iCn62vEqtsZAd2296bdrTAin6XR7lUFjCWzB4ql8UYbEIJJtdhdNEDC9ZLJEXwIJA74oPsWEaUOIAKT0Xc9vcEF7QOFQ5NNuVflypJWHFbqHRskCPcEPh0fDIrf6SKSvRR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ygfYATVc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ygfYATVc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D1761F000E9; Tue, 21 Jul 2026 19:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784661956; bh=5WTC8EmRkT5bDFosgxm0OnMlYAmE1goBg3ts9UJeIfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ygfYATVc6qJF0DaMZxuMgQq16RnCIz1JyewO5UMQ60fL2YKSj84DCoU94qhvWzMPi W2Iw2obW2twQN/VCRO0Bjr7y5Z1NmvVRbD3MPJu/sEzBxPe9UtAUIcPjg663ApDxoD cS9N33WqU/JS6QVbtJT7kn1uvRw57v6mP3eZXqjA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rui Qi , Paul Walmsley , Sasha Levin Subject: [PATCH 6.12 0261/1276] riscv: stacktrace: Remove bogus -0x4 offset in non-FP walk_stackframe Date: Tue, 21 Jul 2026 17:11:44 +0200 Message-ID: <20260721152451.925877512@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rui Qi [ Upstream commit 8ac35bac70e7e581d673b76878f7691cdadc33b8 ] In the non-frame-pointer version of walk_stackframe, each value read from the stack is treated as a potential return address and has 0x4 subtracted before being used as the program counter. This was intended to convert the return address (the instruction after a call) back to the call site, but it is incorrect: 1. RISC-V has variable-length instructions due to the RVC (compressed instruction) extension. A call instruction can be either 4 bytes (regular) or 2 bytes (compressed, e.g. c.jal). Subtracting a fixed 0x4 assumes all call instructions are 4 bytes, which is wrong for compressed instructions. 2. Stack traces conventionally report return addresses, not call sites. Other architectures (ARM64, x86, ARM) do not subtract instruction size from return addresses in their stack unwinding code. 3. The frame-pointer version of walk_stackframe already dropped the -0x4 offset. Commit b785ec129bd9 ("riscv/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support") replaced "pc = frame->ra - 0x4" with ftrace_graph_ret_addr(), and the commit message explicitly noted that "the original calculation, pc = frame->ra - 4, is buggy when the instruction at the return address happened to be a compressed inst." The non-FP version was simply overlooked. Remove the bogus -0x4 offset to match the FP version and the conventions used by other architectures. Fixes: 5d8544e2d007 ("RISC-V: Generic library routines and assembly") Signed-off-by: Rui Qi Link: https://patch.msgid.link/20260603115329.791603-2-qirui.001@bytedance.com Signed-off-by: Paul Walmsley Signed-off-by: Sasha Levin --- arch/riscv/kernel/stacktrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c index 5a0c0d5b449edf..81d6d9d331e08f 100644 --- a/arch/riscv/kernel/stacktrace.c +++ b/arch/riscv/kernel/stacktrace.c @@ -129,7 +129,7 @@ void notrace walk_stackframe(struct task_struct *task, while (!kstack_end(ksp)) { if (__kernel_text_address(pc) && unlikely(!fn(arg, pc))) break; - pc = READ_ONCE_NOCHECK(*ksp++) - 0x4; + pc = READ_ONCE_NOCHECK(*ksp++); } } -- 2.53.0