From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BF5D606A899 for ; Tue, 17 Nov 2026 04:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=g2Wmek+5; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Fxj7vJun 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-Type:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=9ljMd+8qHZtmdzxzGXfXq4+janfrVyX1V/6KLR49owU=; b=g2Wmek+5cJkHD+1W6g5KfJ+/yv U6NdcNSkDMpz0d7eQLQr91auaXItdWtpWxCoKXTn04VrLX6v0GcLnh2DsSoX5WzHRoWLuI+ZyX3+2 MLuC+L5l8keVg6e30u8GEFwxkADTnuWE6k1cTDd/xb+q1t9JfbANlcNQgGuwX8IBnVZ9NTVljeb1P OwJB9yHvrd5dy4981Lgi3iUna/YPEW/wjJT0DRSbKd4/9X60N3nRv1MRP3cm/oRqh4ybZ6qWmKLRZ RmKvMdru1R39iqRQ1pTITK35O33/0gy6GptwLk4u9mIoa5hjCUbzJOj3Cr8GflhvBduRaP80rVV8H OOq2oXRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTAuV-00000004Xn4-1mlr; Tue, 17 Nov 2026 04:35:11 +0000 Received: from mail-pj1-x1046.google.com ([2607:f8b0:4864:20::1046]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTAuS-00000004XmN-42T9 for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2026 04:35:10 +0000 Received: by mail-pj1-x1046.google.com with SMTP id 98e67ed59e1d1-3b175a69ab8so2720110a91.1 for ; Mon, 16 Nov 2026 20:35:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794890107; x=1795494907; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9ljMd+8qHZtmdzxzGXfXq4+janfrVyX1V/6KLR49owU=; b=Fxj7vJunQ97kU3hQI7laXUTxJulQuhxa1yCqY2FzqQ5SrLi87Ck+z4S5pdj8qHU5+r hXYf39CJJ06bm0e4rS29FnijH54lg+D9EnF0klaHzvHjhfOO+Rqyv9hMEGoerRj7RBWp 437XRryM1P990FYoUU+u2xpjie6ncntWGUGawj9SZkdYTdK8h6DDleHGvu8t9ZqPnL9Y 5BZn+c5/vJqpmHO9J+eKhf+h/mv3pCjy6Oza5l8xx+Ryx4vTVG1GPQNVHHirP2H3jROO NLX/EapWlgrHv/dwDsC72t+f7jF57WFe4I9Y7e+44t/PM7reMvo2fWZvZzngC7P7yjz2 gj+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794890107; x=1795494907; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9ljMd+8qHZtmdzxzGXfXq4+janfrVyX1V/6KLR49owU=; b=f6oRXs9rDrcYRahcT0fAIvr05W6KuERZ7rcovFScAcNajKsi9DjqHocJVcsClSGW06 y2uvzm4TTFbnpyNBaEt3MkQLdiIMVbia4Cwm/EpUekC5O8UgfChsdT41IJT7Vgq0qdc2 byw4ecyGEQajzdbtRet7HKJBXgw05aGAnzc+GmEmrXJOvkLjgaKA1+p6YjVPdC4l/yTX ICHH/pNyeZ3e20ZHssGS87eKBQR8CDkK2OMufuKhGgQOV/86MPKosbvpEwkx7Ytv6O4u M9VgvO+gOHBSd12xcIIZU2WAbwdmXsJpjyqAcd/fHIueuPvnclNLoftb+Fa85fL7nEqZ 6Aqw== X-Forwarded-Encrypted: i=1; AL+hErHJvEJlLStoYvGqfwDuWJ68L+uUUJxGDjy9i0rEYovMZhY7o8YAHmfo/RZ92GrSgXb3A6Q5ATHUbyqgOfvqcf4r@lists.infradead.org X-Gm-Message-State: APuU4Z8uGzR413HsLwaruLyb/UDSDrkCDQfj8IPz9bNaje9w0O+xb8y4 CM+hZr5iZpGYUIaCiYAIdD+8Aqfpei8oRgV7vVBLoIYGwQJwLUf0wfG5W0xG4+oKqqDWVONULUw ArO4jrIsrQOY0DHjpceOg5Zqd1g== X-Received: from pgfd23-n2.prod.google.com ([2002:a05:6a02:6557:20b0:cd6:1195:61cb]) (user=dylanbhatch job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3841:b0:3a6:e99b:bbdb with SMTP id 98e67ed59e1d1-3b1b0cfe3d9mr12853706a91.50.1794890106931; Mon, 16 Nov 2026 20:35:06 -0800 (PST) Date: Tue, 17 Nov 2026 04:34:52 +0000 X-Archived-By: Mime-Version: 1.0 X-Mailer: git-send-email 2.56.0.679.gc527c65306-goog Message-ID: <20261117043504.1021063-1-dylanbhatch@google.com> Subject: [RFC PATCH 00/12] arm64, unwind: add .lr_unwind unwinder for reliable stacktrace From: Dylan Hatch To: Catalin Marinas , Will Deacon , Mark Rutland Cc: Herbert Xu , "David S . Miller" , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Weinan Liu , Jens Remus , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-crypto@vger.kernel.org, llvm@lists.linux.dev, Josh Poimboeuf , Steven Rostedt , Ard Biesheuvel , Indu Bhagat , Prasanna Kumar T S M , live-patching@vger.kernel.org, Dylan Hatch Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261116_203509_014154_7BD2744E X-CRM114-Status: GOOD ( 20.30 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Implement a build-time .eh_frame-to-.lr_unwind table generator and in-kernel unwinder for arm64. The primary goal is to support reliable stacktrace (arch_stack_walk_reliable()) across in-kernel exception boundaries (pt_regs). On arm64, normal stack unwinding follows frame pointer (x29) chains. However, when an asynchronous exception or interrupt occurs inside the kernel, the frame pointer chain alone is insufficient to unwind reliably from the interrupted context (pt_regs): 1. Before the prologue updates x29 (mov x29, sp), after the epilogue restores x29/x30, or throughout a leaf function, the interrupted function's return address is live in x30 (pt_regs->regs[30]) while x29 still points to the caller's frame record. 2. Between saving the frame record on the stack (e.g. stp x29, x30, [sp, #-N]!) and updating x29 (mov x29, sp), or in functions where the compiler restores x29/x30 before adjusting sp, the interrupted function's frame record resides at [sp + sp_off] while x29 still points to the caller's frame record. 3. Inside the function body after mov x29, sp, [x29] points to the interrupted function's own frame record and x30 may have been clobbered by nested calls. Without knowing which state holds at the interrupted PC, the unwinder cannot determine whether pt_regs->regs[30] is a valid frame or a duplicate of [x29 + 8], nor can it recover a frame record at [sp + sp_off] before x29 is updated, forcing arch_stack_walk_reliable() to reject stack traces that cross an in-kernel exception boundary. This RFC is proposed as an alternative to an SFrame [1] based solution: [2]. While SFrame works well with recent GNU binutils (2.46+), it is not yet supported by LLVM/Clang toolchains. Conversely, compiler-generated .eh_frame tables (-fasynchronous-unwind-tables, enabled by CONFIG_UNWIND_TABLES) are supported today by both GCC and Clang/LLVM, and arm64 already includes a DWARF .eh_frame parser in arch/arm64/kernel/pi/patch-scs.c for dynamic Shadow Call Stack patching. Rather than retaining bulky raw .eh_frame sections in kernel memory and interpreting variable-length DWARF CFI opcodes during stack unwinding, this series introduces a build-time host tool (scripts/gen_lr_unwind) that reuses and extends arm64's .eh_frame parser () to distill .eh_frame into compact, fixed-width .lr_unwind_fde and .lr_unwind_ranges sections, and strips .eh_frame from the final vmlinux and module binaries. Each annotated function is described by an 8-byte struct lr_fde entry (32-bit PC-relative start_offset + 32-bit range_desc), sorted at build time by scripts/sorttable (and at module load time) for O(log N) lookup. Each instruction range within a function is classified into one of three exception-boundary unwind modes: - LR_UNWIND_LIVE: x30 holds the return address, x29 is the caller's FP - LR_UNWIND_FP: [x29] holds the saved {x29, x30} frame record - LR_UNWIND_SP: [sp + sp_off] holds the saved {x29, x30} frame record Functions with non-standard x30 spills (such as frameless leaf functions spilling x30 without x29) are omitted from .lr_unwind_fde so the unwinder treats them as unreliable. For functions following the canonical 4-phase LIVE -> FP/SP -> SP -> LIVE layout (prologue <= 31 insns, body <= 4095 insns, epilogue/return <= 15 insns each, and sp_off <= 496 bytes), the ranges and sp_off are packed directly into the 32-bit range_desc word of struct lr_fde; functions with more ranges or larger lengths reference 2-byte lr_range_t entries in .lr_unwind_ranges. Across vmlinux, .lr_unwind_fde and .lr_unwind_ranges total ~800-935 KiB (~4x smaller than raw .eh_frame). This series is available on github: [3]. Structure of the series: - Patches 1-6: Enable .eh_frame generation for CONFIG_ARM64_LR_UNWIND, factor the .eh_frame parser out of patch-scs.c into , extend it to track CFA and x29/x30 state, and implement scripts/gen_lr_unwind (including --dump) to emit .lr_unwind sections. - Patch 7: Teach scripts/sorttable to sort .lr_unwind_fde at build time. - Patches 8-9: Add in-kernel .lr_unwind lookup, optional boot/module validation (CONFIG_ARM64_LR_UNWIND_VALIDATION), and module support. - Patches 10-11: Annotate call_on_irq_stack() and arm64 leaf assembly functions (SYM_LEAF_FUNC_START / SYM_LEAF_FUNC_END) with CFI directives so they are covered by .lr_unwind. - Patch 12: Use .lr_unwind in arch/arm64/kernel/stacktrace.c to reliably unwind across in-kernel exception boundaries. Ref: [1]: https://sourceware.org/binutils/docs/sframe-spec.html [2]: https://lore.kernel.org/all/20261117020648.323464-1-dylanbhatch@google.com/ [3]: https://github.com/dylanbhatch/linux/tree/eh_frame Dylan Hatch (11): arm64, unwind: build with .eh_frame and add gen_lr_unwind skeleton arm64: factor .eh_frame parser out of patch-scs.c into arm64: eh_frame: track CFA and x29/x30 register state in CFI parser arm64, unwind: parse .eh_frame into .lr_unwind entries in gen_lr_unwind scripts/gen_lr_unwind: emit .lr_unwind_fde and .lr_unwind_ranges scripts/gen_lr_unwind: add --dump option to inspect .lr_unwind tables scripts/sorttable: sort .lr_unwind_fde by start_offset arm64, unwind: add in-kernel .lr_unwind lookup and validation arm64/module, unwind: add .lr_unwind support for modules arm64, crypto/lib: annotate leaf functions with CFI info unwind: arm64: use .lr_unwind to unwind interrupt frames Weinan Liu (1): arm64: entry: add unwind info for call_on_irq_stack() MAINTAINERS | 1 + arch/arm64/Kconfig | 20 + arch/arm64/crypto/aes-ce-ccm-core.S | 12 +- arch/arm64/crypto/aes-neonbs-core.S | 16 +- arch/arm64/crypto/ghash-ce-core.S | 20 +- arch/arm64/crypto/sm4-ce-ccm-core.S | 16 +- arch/arm64/crypto/sm4-ce-cipher-core.S | 4 +- arch/arm64/crypto/sm4-ce-core.S | 44 +- arch/arm64/crypto/sm4-ce-gcm-core.S | 16 +- arch/arm64/crypto/sm4-neon-core.S | 12 +- arch/arm64/include/asm/eh_frame.h | 552 +++++++++++++++++ arch/arm64/include/asm/linkage.h | 33 + arch/arm64/include/asm/lr_unwind.h | 149 +++++ arch/arm64/include/asm/module.h | 6 + arch/arm64/include/asm/module.lds.h | 2 +- arch/arm64/include/asm/scs.h | 7 - arch/arm64/include/asm/sections.h | 3 + arch/arm64/kernel/Makefile | 5 + arch/arm64/kernel/entry.S | 12 +- arch/arm64/kernel/lr_unwind.c | 395 ++++++++++++ arch/arm64/kernel/module.c | 11 + arch/arm64/kernel/pi/patch-scs.c | 259 +------- arch/arm64/kernel/setup.c | 3 + arch/arm64/kernel/stacktrace.c | 85 ++- arch/arm64/kernel/vmlinux.lds.S | 27 +- arch/arm64/lib/clear_user.S | 4 +- arch/arm64/lib/copy_from_user.S | 4 +- arch/arm64/lib/copy_page.S | 4 +- arch/arm64/lib/copy_to_user.S | 4 +- arch/arm64/lib/memchr.S | 4 +- arch/arm64/lib/memcmp.S | 4 +- arch/arm64/lib/memcpy.S | 8 +- arch/arm64/lib/memset.S | 8 +- arch/arm64/lib/mte.S | 28 +- arch/arm64/lib/strchr.S | 4 +- arch/arm64/lib/strcmp.S | 4 +- arch/arm64/lib/strlen.S | 4 +- arch/arm64/lib/strncmp.S | 4 +- arch/arm64/lib/strnlen.S | 4 +- arch/arm64/lib/strrchr.S | 4 +- arch/arm64/lib/tishift.S | 12 +- scripts/.gitignore | 1 + scripts/Makefile | 2 + scripts/Makefile.modfinal | 10 +- scripts/Makefile.vmlinux_o | 8 +- scripts/gen_lr_unwind.c | 821 +++++++++++++++++++++++++ scripts/link-vmlinux.sh | 2 +- scripts/sorttable.c | 50 +- 48 files changed, 2325 insertions(+), 383 deletions(-) create mode 100644 arch/arm64/include/asm/eh_frame.h create mode 100644 arch/arm64/include/asm/lr_unwind.h create mode 100644 arch/arm64/kernel/lr_unwind.c create mode 100644 scripts/gen_lr_unwind.c base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 -- 2.56.0.679.gc527c65306-goog