From patchwork Mon Dec 9 15:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13899989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96775E7717D for ; Mon, 9 Dec 2024 15:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=LiKgV1wOeWsrmvP9WbszKOOPwP/h5XEdIkZzfRjySYg=; b=Y8n+e9Sd/rS0GX 7d9aQlLL/lxyl3adbo/rflBw8mylVE8NW5KnPo5Q6Eu1Seu2h1SaOGFiqAm6zRdyWTdXwnIl0pQ6i 1tul9rqPW++pf0dQg4oU7Ruzc9h/0aGn2F6N3GFVNeR8+Cd6FQ/QaSxlCAo4IcQxHR9qDdHGFpFtT NxYQY19AqtsKzkkAjkXewvTaIoxa+jWeDP/4ZEAXTe9w1wtZzmQbRMR82Rn4NrCVXapY3CYmhaZ7C vK0rcwK4qKY+LQiCrGIX+Ag1Yl1EnHhaoq8IenGUxU+L04YJc0qYbdbh91xn91zUWg76nupVSaNKJ RQ4KeoL0hzHzFNo/EJnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKg8q-00000008SW1-2nCY; Mon, 09 Dec 2024 15:57:48 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKg8m-00000008SUl-413x for linux-riscv@lists.infradead.org; Mon, 09 Dec 2024 15:57:46 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-724d23df764so4217037b3a.1 for ; Mon, 09 Dec 2024 07:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1733759864; x=1734364664; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HJgfJRwWboyVVdp2yBixPX3pFCmRzBh4c7ZZuQR90II=; b=MJwcYJ6ciywF2nnGnBKXwpTfqpNlH1vfoKG5za0n/WNuyFfmCEIA9e0sZtnvxfV1LN n2zWU+GR9i+kBgdNmpcFAw5CB9s9JnP/j6+yqRvqRi6E6kdTtpo5OpI9IGLK5AR2D08Q ktNG+Nm+wCRMZqE9VX+T1GnB2ZLAHdrMYkYUwA0Sv7ClCBYgNeSoA/UrHfMRAJ4kcyUM lr+J4wy+z9CyxmUOqYikp/ytws9cQWjPV1dLRof6i/s40AtXqUtIL7EZJTV8bLx6oofQ sorI30VFoqWonsITQ1/bwG9LLuSOfXjIqcXJ8Y9QHBvL+dsHvmbh+MnCyuKHrCzgQgtq hOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733759864; x=1734364664; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HJgfJRwWboyVVdp2yBixPX3pFCmRzBh4c7ZZuQR90II=; b=hMhmE852MXP51sOksDXWfTxyfqQSTHlAM/Is4LZxzwzumNCw7XTY327gHg/QeJH9Oe B0QJWPXr/aF1Y2EG0VxH+hma6P92rTN5bnlt92uVYHFhLYp47uBFhMaYknSCyBdZTO1S GrB4DoC3KQR1BYgyCDyUsaokl+B2qtA+QhSE3fDKu1VeL95/XSPYn5CKeaHcCtKFgvg9 xuG+dtT/lKT22LxHxkoo/lUtPU7BXkfzQ1L54xV2NvZ7eT8eDTLuC4PRqOfAq3cLZqNu swiiou1wkXZMwU1f+KYm+27wt947Rbl7QGIvib8uKScWSNbH4nws7CLMMfWcGLzJkcMO rSkw== X-Forwarded-Encrypted: i=1; AJvYcCVMyGj297cioSEUYmu5HB2xJXmY0HG3yRXUrw0w+XLgXFWSCheJK9USwupMRU2m9UBRce/3QflFOc7yrQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yyc0a/UbUAIN1SI53LCLB6RES8iK56/nrSk+sB5Cwc7e7G3Ixok VjABMSVl2znOOv0r+bsC9CFl/TypSxZdfFbKdAWME+Bp98os7YxQ9ppMBiWgU+o= X-Gm-Gg: ASbGnct9kASXxlXKZpjZrVYoEuinO92Mveg6PCugyOzv6TjNsqIGp8p4ACimOGUReA7 5rzDz/pwlUynjnlWnfFjfp/da9NKqw5o8EDc63LMkolblR3+CQhd8OtvCQfWUEVRtCfkAV2Uvah seaCI+F0oeDtt7TmKLUGs7/Zb8n+6WFFpTQ1JFm9FfswTkjEeITfZrfIwEXSmawf82AlHaGTh54 R/aW+My4IpIb0glQvYOqWKqehbGmv9u6Qz3zTgCBhc0ZNmi5PU= X-Google-Smtp-Source: AGHT+IF3SUxS6Oqh6v3V6CqksS4a3Vo4POx1ea0PFAbtVS5ly1340Tat37ZVq9GoRLgSr76MMFbbzQ== X-Received: by 2002:a05:6a00:9289:b0:725:e499:5b8b with SMTP id d2e1a72fcca58-725e4995cc6mr7699800b3a.17.1733759863799; Mon, 09 Dec 2024 07:57:43 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725d16e7132sm4295833b3a.152.2024.12.09.07.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 07:57:43 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , linux-riscv@lists.infradead.org (open list:RISC-V ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Anton Blanchard Subject: [PATCH] riscv: stacktrace: fix backtracing through exceptions Date: Mon, 9 Dec 2024 16:57:12 +0100 Message-ID: <20241209155714.1239665-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_075745_257113_89084D7C X-CRM114-Status: GOOD ( 10.95 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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;