From patchwork Thu Oct 10 10:15:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13829918 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 D0F83CF11CC for ; Thu, 10 Oct 2024 10:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=0tUDqDtX2IIQB0F4bnoAG3oNUW47D4ZiFczDgYjU/Z8=; b=sCR3T92JbgDdbzSUK7ZLkd66/v P6jyyvRrNJiAp5rK4R8AZbu3ZYht6/A/mXYu04DYui9wKgx1NkWElJc3KDYid0zQjrc83bsDgEsbk w58I48mG6RFEsJ/bjfT4i+3ALo9hqMQcf0i6E70gZHU+HbMUzTL/yeUY1tVUh51hjeAZxTCE8dwAD 8So4kzS3Ot4Erjmwm7p2Pdv1ucQsRQ4Rax/wknLiLEk/VBWof1zCDvh7z/DVX9lpHIMQIbU4vdTCV U2og70P/Dwr2XoRkOP8cdgxJcSmIrAjMJWeSv9mAArbmz1N8MCnn6fB8+xyQxBPwIF9ZCuiczE8gz b6pn8sew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syqXN-0000000CPJ1-2HfF; Thu, 10 Oct 2024 10:36:53 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syqCV-0000000CMbb-0RZ0 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 10:15:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E0F28497; Thu, 10 Oct 2024 03:15:47 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4B4183F58B; Thu, 10 Oct 2024 03:15:16 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: ardb@kernel.org, broonie@kernel.org, catalin.marinas@arm.com, jpoimboe@kernel.org, kaleshsingh@google.com, madvenka@linux.microsoft.com, mark.rutland@arm.com, maz@kernel.org, mbenes@suse.cz, puranjay12@gmail.com, will@kernel.org Subject: [PATCH 00/10] arm64: stacktrace: improve unwind reporting Date: Thu, 10 Oct 2024 11:15:00 +0100 Message-Id: <20241010101510.1487477-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_031519_257780_35FB5C76 X-CRM114-Status: GOOD ( 11.23 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This series improves arm64's unwinder to explicitly identify exception boundaries, reporting both pt_regs::pc and pt_regs::lr and explicitly identifying the source of elements in the stacktrace. This is useful to humans when reviewing a stacktrace, and serves as infrastructure that can be used for RELIABLE_STACKTRACE in future. The first 6 patches are preparatory work that are not intended to have any functional impact, with patches 7 to 10 making the key changes. Largely this involves teaching the unwinder to track metadata for each unwind step, and modifying the way we manage pt_regs::stackframe so that exception boundaries can be identifier explcitily. With this series applied, the unwinder will report when unwind elements are not simply the result of a frame pointer based unwind, e.g. | Call trace: | show_stack+0x20/0x38 (CF) | dump_stack_lvl+0x60/0x80 (F) | dump_stack+0x18/0x28 | nmi_cpu_backtrace+0xfc/0x140 | nmi_trigger_cpumask_backtrace+0x1c8/0x200 | arch_trigger_cpumask_backtrace+0x20/0x40 | sysrq_handle_showallcpus+0x24/0x38 (F) | __handle_sysrq+0xa8/0x1b0 (F) | handle_sysrq+0x38/0x50 (F) | pl011_int+0x420/0x570 (F) | __handle_irq_event_percpu+0x60/0x220 (F) | handle_irq_event+0x54/0xc0 (F) | handle_fasteoi_irq+0xa8/0x1d0 (F) | generic_handle_domain_irq+0x34/0x58 (F) | gic_handle_irq+0x54/0x140 (FK) | call_on_irq_stack+0x24/0x58 (F) | do_interrupt_handler+0x88/0xa0 | el1_interrupt+0x34/0x68 (F) | el1h_64_irq_handler+0x18/0x28 | el1h_64_irq+0x6c/0x70 | default_idle_call+0x34/0x180 (P) | default_idle_call+0x28/0x180 (L) | do_idle+0x204/0x268 | cpu_startup_entry+0x3c/0x50 (F) | rest_init+0xe4/0xf0 | start_kernel+0x738/0x740 | __primary_switched+0x88/0x98 ... where: * "C" indicates that the first element of the trace was the caller of an unwind function (vs "T" for a blocked task's stave PC, or "P" for a pt_regs::pc). * "F" indicates that the element was recovered from fgraph (and would otherwise have been reported as return_to_handler). * "K" indicates that the element was recovered from kretprobes (and would otherwise have been reported as __kretprobe_trampoline). * "P" indicates that the element was recovered from pt_regs::pc, and therefore this is the first element after an exception boundary. * "L" indidates that the element was recovered from pt_regs::lr, and therefore this may or may not be reliable depending on whether the LR was live at the moment the exception was taken. Mark. Mark Rutland (10): arm64: pt_regs: assert pt_regs is a multiple of 16 bytes arm64: pt_regs: remove stale big-endian layout arm64: pt_regs: rename "pmr_save" -> "pmr" arm64: pt_regs: swap 'unused' and 'pmr' fields arm64: use a common struct frame_record arm64: stacktrace: move dump_backtrace() to kunwind_stack_walk() arm64: stacktrace: report source of unwind data arm64: stacktrace: report recovered PCs arm64: stacktrace: split unwind_consume_stack() arm64: stacktrace: unwind exception boundaries arch/arm64/include/asm/daifflags.h | 2 +- arch/arm64/include/asm/processor.h | 2 +- arch/arm64/include/asm/ptrace.h | 22 ++- arch/arm64/include/asm/stacktrace/common.h | 74 +++++---- arch/arm64/include/asm/stacktrace/frame.h | 48 ++++++ arch/arm64/kernel/asm-offsets.c | 3 +- arch/arm64/kernel/entry.S | 16 +- arch/arm64/kernel/head.S | 3 + arch/arm64/kernel/probes/stBV5U5j | 0 arch/arm64/kernel/process.c | 5 +- arch/arm64/kernel/signal.c | 5 - arch/arm64/kernel/stacktrace.c | 176 +++++++++++++++++++-- 12 files changed, 287 insertions(+), 69 deletions(-) create mode 100644 arch/arm64/include/asm/stacktrace/frame.h create mode 100644 arch/arm64/kernel/probes/stBV5U5j Reviewed-by: Miroslav Benes Reviewed-by: Puranjay Mohan