From patchwork Thu Oct 17 09:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13839691 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 74391D21268 for ; Thu, 17 Oct 2024 09:33: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=aNW/N54Br/zUjHNdSBlaAQCCtqAfemq4XDcpxtIL5Vo=; b=Oc50fANmjZFUf/lNAi2RjCcPbV dJrqC5+UYv1cet9xQW7ZAn+GnwU3fh2VV3L9FEzZ7RZ1lcUEN0EnlOfBTsYLPNgh+wBxAnWvyDsi9 HcVi5d8cd7C/T0SCwnN6eQ7nlAkEzuIdDjsTaYBaTcfnXBYrwANnyestUsbG7RHq9KwYmeREuWDQb TJS9gjnhaA5oDDsRWe8WjxImtqZw8Gh9aK5/ywrMFO7W5WXsvasNUlH49gS5cAD1XnjpnjH9uoZ3d /wp664NoTPE1Un78WEGkV1hE6s35Ni7blkDtaGSePMIIInyedY0kSz7j3IhrGG4mYSLZHDLQWkVx0 b3NXOeFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1MsD-0000000EM8Q-1zyu; Thu, 17 Oct 2024 09:32:49 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1MlR-0000000EKex-1g5X for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 09:25:51 +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 314B2FEC; Thu, 17 Oct 2024 02:26:14 -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 804943F528; Thu, 17 Oct 2024 02:25:42 -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 v2 00/10] arm64: stacktrace: improve unwind reporting Date: Thu, 17 Oct 2024 10:25:28 +0100 Message-Id: <20241017092538.1859841-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-20241017_022549_661395_B61987DE X-CRM114-Status: GOOD ( 10.73 ) 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. I've pushed the series to my arm64/stacktrace/metadata branch on kernel.org, based on v6.12-rc2: https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=arm64/stacktrace/metadata git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arm64/stacktrace/metadata Since v1 [1]: * Fix typos in commit messages * Apply Reviewed-by tags [1] https://lore.kernel.org/linux-arm-kernel/20241010101510.1487477-1-mark.rutland@arm.com/ 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/process.c | 5 +- arch/arm64/kernel/signal.c | 5 - arch/arm64/kernel/stacktrace.c | 176 +++++++++++++++++++-- 11 files changed, 287 insertions(+), 69 deletions(-) create mode 100644 arch/arm64/include/asm/stacktrace/frame.h