From patchwork Mon Jan 27 21:33:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951739 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 DCC75C02188 for ; Mon, 27 Jan 2025 21:37:08 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pMhIr+En9Z5bHr+SI41rtrYzgjvtxfxDwtbSrjCCifE=; b=1U/MENxr3dhGJoEuiNej2M1GpI rVMI939A0Uhy26OMVecv5mgeWlfQKkBpB0WLRxAaMocB6jbTCoL4THRSLaJi6rQNLDACmXcFVWeSQ +fJPhOB44QCZI5kAMz94UR7z/5m8ACkLe201KuyjkfBotMw36FYDOojSyQiJhQS9YQf6iZqJJ+ZIU pDNjPmwCdM2lC8DYMVaGydTeRM09hB9HSEW+UCUyFR3/THUmp3SOuC3ci2ixbEuloRH9pgDODZNwn ljVs9StD5ZVOfG/pAdC5QbWLxrmzJuodernG2zeEIEj+IVk/HAp9FezsyHQfG46qe2iNMh7z9vDL6 KDHgGlxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWmu-00000003Jsj-3kNc; Mon, 27 Jan 2025 21:36:56 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWjV-00000003J7A-2AAR for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:26 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-2163dc0f689so144567615ad.1 for ; Mon, 27 Jan 2025 13:33:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013603; x=1738618403; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pMhIr+En9Z5bHr+SI41rtrYzgjvtxfxDwtbSrjCCifE=; b=mAwoFjq9jHo7oD+vzMzjuDQcTHeirGF4vZzUeVIHxZEklaQakiccN40BVaouES6YoC agx8mn2qP5w5uLe4WC30s32qaaOvmrGkQ8G6adHAs/6ePrkmp3+3MyQVtxPVOqinkA68 RSDXJSnoTbb7f2fuYZPsRmGmPSToIZ7jQXS3WncZ/IuXYyW0AVKqhO7hzbynTe/Ge+U9 KSFEIkL83LznqWjBeyp/Y9zfhbPoGjoWzYkYausCndwnuOpQAMTpOuzHi78sk6Yk3JB3 633DmJ6A1YWRWRLQ9E35N6IJAd6PYz6Hz80nJxJp7I+eg6rc3fw1HOwp5VPi2bRXuE/X FjJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013603; x=1738618403; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pMhIr+En9Z5bHr+SI41rtrYzgjvtxfxDwtbSrjCCifE=; b=ROUh8ZlUyqm6YyVk2QQh+Yg2pT9uoDCwAxEjgIkIyMXVLpzOWzVRZzDD+wrxvdC9lx IYYRjbTEQ2ewDEJI6CcL1ZQfTpr7JQHkLeje3tEAOCkYYDAnExq19SXv8jsGkWXa/Sn7 8CZtgkg2znnFbjOee6hRT8o01EafexvlPs5bMQrAXB5tWbTTKRZJxMchv2uX8iu15SVM eL3Jl+JMGY56YUbE937uInArvjOgWRCRgy0vWF0ccurGKEaYBv+fTQAdTXuatERIm5io 8JD18XQdwnJSP7Ldeso1Hgy/i4/6U7SnE2CSUt5AsuE+Tdg7eUEknDuNukVgAyg2C+IU SZHw== X-Forwarded-Encrypted: i=1; AJvYcCW4rsysglwHjqOIF+DcIsMGenYUIYNe9WlpT+oHL6isGn5zfMfwbZ04ulZW1stqneC6jJFr51FyDl/Z5LLuF0He@lists.infradead.org X-Gm-Message-State: AOJu0Ywc6xbFnQCEvJHB6+HEnZ5J6g0j/z2KJ15HqHFKsIqwsavWUcpy UFATlRqfOK1PHb1/nwIIt9tnXJJBxQXfxF4PkJr4JwSQSvvgL71w2VO/rFBARh83oQJrAcbMMA= = X-Google-Smtp-Source: AGHT+IFf6J6rV9/t9kV/JQeXUvSzBEZruRhcKXoKcnyF96aSdB43mkOwhOGscpzW9zOTOb0X7BG/2BEB9g== X-Received: from pfbjc33.prod.google.com ([2002:a05:6a00:6ca1:b0:728:b3dd:ba8c]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:430d:b0:1e1:aef4:9ce7 with SMTP id adf61e73a8af0-1eb214a08b6mr60696359637.17.1738013603568; Mon, 27 Jan 2025 13:33:23 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:03 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-2-wnliu@google.com> Subject: [PATCH 1/8] unwind: build kernel with sframe info From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133325_552297_71581EA4 X-CRM114-Status: GOOD ( 14.95 ) 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 Use the -Wa,--gsframe flags to build the code, so GAS will generate a new .sframe section for the stack trace information. Currently, the sframe format only supports arm64 and x86_64 architectures. Add this configuration on arm64 to enable sframe unwinder in the future. Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- Makefile | 6 ++++++ arch/Kconfig | 8 ++++++++ arch/arm64/Kconfig.debug | 10 ++++++++++ include/asm-generic/vmlinux.lds.h | 12 ++++++++++++ 4 files changed, 36 insertions(+) diff --git a/Makefile b/Makefile index b9464c88ac72..35200c39b98d 100644 --- a/Makefile +++ b/Makefile @@ -1064,6 +1064,12 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += -fconserve-stack endif +# build with sframe table +ifdef CONFIG_SFRAME_UNWIND_TABLE +KBUILD_CFLAGS += -Wa,--gsframe +KBUILD_AFLAGS += -Wa,--gsframe +endif + # change __FILE__ to the relative path to the source directory ifdef building_out_of_srctree KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=) diff --git a/arch/Kconfig b/arch/Kconfig index 6682b2a53e34..ae70f7dbe326 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1736,4 +1736,12 @@ config ARCH_WANTS_PRE_LINK_VMLINUX An architecture can select this if it provides arch//tools/Makefile with .arch.vmlinux.o target to be linked into vmlinux. +config AS_HAS_SFRAME_SUPPORT + # Detect availability of the AS option -Wa,--gsframe for generating + # sframe unwind table. + def_bool $(cc-option,-Wa$(comma)--gsframe) + +config SFRAME_UNWIND_TABLE + bool + endmenu diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index 265c4461031f..ed619fcb18b3 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -20,4 +20,14 @@ config ARM64_RELOC_TEST depends on m tristate "Relocation testing module" +config SFRAME_UNWINDER + bool "Sframe unwinder" + depends on AS_HAS_SFRAME_SUPPORT + depends on 64BIT + select SFRAME_UNWIND_TABLE + help + This option enables the sframe (Simple Frame) unwinder for unwinding + kernel stack traces. It uses unwind table that is direclty generated + by toolchain based on DWARF CFI information + source "drivers/hwtracing/coresight/Kconfig" diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 54504013c749..6a437bd084c7 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -469,6 +469,8 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) *(.rodata1) \ } \ \ + SFRAME \ + \ /* PCI quirks */ \ .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \ BOUNDED_SECTION_PRE_LABEL(.pci_fixup_early, _pci_fixups_early, __start, __end) \ @@ -886,6 +888,16 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) #define TRACEDATA #endif +#ifdef CONFIG_SFRAME_UNWIND_TABLE +#define SFRAME \ + /* sframe */ \ + .sframe : AT(ADDR(.sframe) - LOAD_OFFSET) { \ + BOUNDED_SECTION_BY(.sframe, _sframe_header) \ + } +#else +#define SFRAME +#endif + #ifdef CONFIG_PRINTK_INDEX #define PRINTK_INDEX \ .printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \ From patchwork Mon Jan 27 21:33:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951740 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 C7F1DC0218A for ; Mon, 27 Jan 2025 21:38:32 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jWq1XbSkyOkuYcVulfJjVxpq/eHKTQbF0thAv0NyIGs=; b=cpKxKjluymcL9m2bTSPHtrOlKn hMlMLEZrJuw3gtbLRy0trW2MWBiQlN/SUsgdbari96MYdavyVappk0opjJR70cxdG8sXRl7EyovcW 8VQCfHs8t/3QzV4H/GdIOtSWjVg1QQiYkbrxJpqCDH98XJaTGUNShmobbziAIPZBpITkQrAV2+uM5 jvl9QN95wch77N6fAESr4lJyKK3q3TsQ43gl91G/5o/lWEci1bihGOOhMWLzvRNzljMoJ3+3eMMvL /sbB5DIN+WfFDBGEI71b68d+Bttv9BmTGrILsNKt9gPoxGr19n7pwJ1aHJVDEMZ8hpNN/pFFHGOnu B+yyJOyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWoD-00000003K47-2IAY; Mon, 27 Jan 2025 21:38:17 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWjZ-00000003J9m-11fa for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:31 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2ef9204f898so9422900a91.2 for ; Mon, 27 Jan 2025 13:33:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013608; x=1738618408; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jWq1XbSkyOkuYcVulfJjVxpq/eHKTQbF0thAv0NyIGs=; b=eT4meLmHYWSn2uWvRgwp9cQx3gKc9jttznJY6U3pn3+UldfAPY98tXH01B90ZiMK1J IO2jIDi/MLeAjtebu03Tt2cqzZ4JR/dIAodNi7OzNTuesMrAWzsBU24qA5DuUsIDI0na I7siAjFkqFWJ8LW9NIFi6B5STK7e+ucydFm/89ZfjIrVZOPz8Ti1z0mtDw5gCzUlG/Xd 25PmyDoeHY7/4iadlnb/HB2lKs2KWq6Kq/nVgh15UBekNyZmpbCvvp53CNDdLLYWbO7T egy69OslQcstSuze9c72W0qjvrd7bvWfFbB/K8CoU2fW4XwIJwyDChHeoeMboJ7Ennqx xalA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013608; x=1738618408; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jWq1XbSkyOkuYcVulfJjVxpq/eHKTQbF0thAv0NyIGs=; b=Dy7MacwA9h0jTI3TXrPnMxCel0ftMbQD1ZGu//8rSXm5d0x+rhg/8vmIAWhFl3eN3n mPy+1xba37EPpqc3EkAaaU2K4b2AkNINSo3SMEORhsF9HagnUTKUpFLLT/ctEH9tb0/c uV59Kj5wwN1dJPaPbyZTsiXZ509TOYcyawK8tEaiOqbmcDG9eK3YaFkDc9P+og8gRWVW Ilfwsz/kR18aacMqi6v/C47YsKrCv46Gfg3BKYzlHsHJKSfm600gF6x6mOKmgMC0wMwX 9VEKcSwG2xwHhdxeX06A4aPjmrukv57GtVAPTNCliEzjAncAR8wkFqZIDua0LLfRUs7X 9kgg== X-Forwarded-Encrypted: i=1; AJvYcCUDPp5xPLa2P9qxUbq6tr1kZuM4jtQxB8YHaBDQQ/wG95+dTy/+wuoFTqh9OOaqoGpSZVliIttQOepK4U4jQJM0@lists.infradead.org X-Gm-Message-State: AOJu0YwH8PxxLJ99t2hSvj3czA0paoD/JRzT/8tNpaGb8wFNC0bL1tpV ntBqM7/NVFuGFr1aO9QBAMotET1bJuBmAHmFdYNL4BH5FEBE3bYkdBvMyIZHBG4ZOjhyE//LqA= = X-Google-Smtp-Source: AGHT+IGsA2oXsBLBU6n+vsGTmoyiK5KDPDDibU+y8Mvqe4ndlxlznHpYDael7KmNjQ8dikt+jPZ/Btay/Q== X-Received: from pjbse3.prod.google.com ([2002:a17:90b:5183:b0:2ea:4139:e72d]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:6c6:b0:2ee:889b:b11e with SMTP id 98e67ed59e1d1-2f782d972eamr59541677a91.30.1738013607746; Mon, 27 Jan 2025 13:33:27 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:04 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-3-wnliu@google.com> Subject: [PATCH 2/8] arm64: entry: add unwind info for various kernel entries From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133329_287962_981C5829 X-CRM114-Status: GOOD ( 12.39 ) 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 DWARF CFI (Call Frame Information) specifies how to recover the return address and callee-saved registers at each PC in a given function. Compilers are able to generate the CFI annotations when they compile the code to assembly language. For handcrafted assembly, we need to annotate them by hand. Annotate CFI unwind info for assembly for interrupt and exception handlers. Signed-off-by: Weinan Liu --- arch/arm64/kernel/entry.S | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 5ae2a34b50bd..fe3e3e29ee5d 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -579,7 +579,12 @@ SYM_CODE_START_LOCAL(el\el\ht\()_\regsize\()_\label) .if \el == 0 b ret_to_user .else + .cfi_startproc + .cfi_def_cfa_offset PT_REGS_SIZE + .cfi_offset 29, S_FP - PT_REGS_SIZE + .cfi_offset 30, S_LR - PT_REGS_SIZE b ret_to_kernel + .cfi_endproc .endif SYM_CODE_END(el\el\ht\()_\regsize\()_\label) .endm @@ -889,6 +894,10 @@ SYM_FUNC_START(call_on_irq_stack) /* Move to the new stack and call the function there */ add sp, x16, #IRQ_STACK_SIZE blr x1 + .cfi_startproc + .cfi_def_cfa 29, 16 + .cfi_offset 29, -16 + .cfi_offset 30, -8 /* * Restore the SP from the FP, and restore the FP and LR from the frame @@ -898,6 +907,7 @@ SYM_FUNC_START(call_on_irq_stack) ldp x29, x30, [sp], #16 scs_load_current ret + .cfi_endproc SYM_FUNC_END(call_on_irq_stack) NOKPROBE(call_on_irq_stack) From patchwork Mon Jan 27 21:33:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951741 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 B74F9C02188 for ; Mon, 27 Jan 2025 21:39:53 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nDvBLRnKYJqb7wLRycvSsM5KYAbB3Uj/Gas8Bcx9QpY=; b=34x5xfT7LTH7+KvLVZR/f5VuFJ dqmTTOD3xc0OweDSBtmRG4awtqkDQYZbawctXLHcs2n66MdnTeUAttT2uUVvKKIJgEPmq2f0+sO8T KQvhn6fRJpV2TBYaC4WzEbgO842i1zpwPTULYQAMGStl7jGQo1XiUq0d8gdccRhxY3lrnCx3pRtBr pHVZ6OP8uyErPvTiSoLUPu9oFDZxvhxGhhWiDp9LPJgpKWy8rhX2QpL4I/VzmRyflu1VEGKpXIOUi L+q+kBNMhpW+jaAp6VdV/l0LC//z+LZvmvdrLHXUiZGSkX/WV/IhwywORS66UjhnmLbIyTStHovRt LNaQOc2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWpX-00000003KGw-0kpf; Mon, 27 Jan 2025 21:39:39 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWjb-00000003JAy-16gX for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:32 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2ef9da03117so13860132a91.1 for ; Mon, 27 Jan 2025 13:33:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013610; x=1738618410; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nDvBLRnKYJqb7wLRycvSsM5KYAbB3Uj/Gas8Bcx9QpY=; b=ZT2mkIzaS3KV6s2koh0qS37MWzzuRKWoZnapKWgKNJ0E1iJzSnWp800HSkvr7mbpij 8bZW6DiocSLAFO984Jfl6+4EqLVdrql+bv7sCw1cUtpTL6htyeVC3LxtlF+kJF3xo/CS SzwRMbjzebz0tqg1Kvw5oMdcCqZjltdnqAHmbrcf3pFFji0lw/Qnyv9q4uq2qVGKPiHC M0wvw6qHqgb/LiIg0UhPPs+jX+92V7iXZtTeMRWpySCawGb8ITgwu094jICbt1lfM1M7 xalKPf9LMhxdKrjzPAbMHzXWmTWme539gsQDjb/JCQN2BjpE7ZRfXtqFb8qDsbObVP1t IicQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013610; x=1738618410; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nDvBLRnKYJqb7wLRycvSsM5KYAbB3Uj/Gas8Bcx9QpY=; b=iLJuX5V/AQfUXupf5b/lnwlWs1el47Z49VZVXKd7f1x58tXHmVb2JgKJ62z+kCZ3Rw aVeJwGmaNuPtfP7BUDlqLQ4dAGBZtlL8uVlvajC4Z9Vd+yZn7RbRANEwh0CXtE3jNybq oKbnXUVRXMV8oi+FvPtCvuEr59D1u+phMY0icBybjp84kC7jaHu8+mRzmSHdK98d9Jn8 29gt+eGvNrcSm4IBbfD6p4F0qxrePN12GKpzGik590VhruIV6BoJjaChGSgKz6pJ8h2G tRPczyK2S3RMVJJTvxxcTCKNoaYT4WAoJmWMUr3QyVH93wfCDfWjSVsYZwxLDsq1fF/G 0RKg== X-Forwarded-Encrypted: i=1; AJvYcCVYVBgP+DcRTuxOXpyeJaUa8/9VRnIuw0oSSJtm59cj85JxOZ8W9/sKt0toQF4WsnpDarOLz9wLXRxtJ0+LZiai@lists.infradead.org X-Gm-Message-State: AOJu0YzmlMCSFx0VISSbpqvxexZzp7zW2vztL8Z04xlvs800d0VXSsgY iFCtrVYg038Mqtze8MTZPpL3rxFLFgoq+SHSbB9ejQeqQes9yIQ0xT1LArf7wFPXtVodbszVlQ= = X-Google-Smtp-Source: AGHT+IE7cBiyjRItliwSAg3VmD1SKevW9jTi2EfBECUlXP+PwVTan7NlAVSGrkNopkq3143PUhyvXE76zA== X-Received: from pfd10.prod.google.com ([2002:a05:6a00:a80a:b0:725:d350:a304]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:ad8a:b0:72a:bc54:84f7 with SMTP id d2e1a72fcca58-72dafa03117mr57971799b3a.12.1738013610397; Mon, 27 Jan 2025 13:33:30 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:05 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-4-wnliu@google.com> Subject: [PATCH 3/8] unwind: add sframe v2 header From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133331_310937_CB846804 X-CRM114-Status: GOOD ( 28.46 ) 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 Add sframe header so that we know how to access the sframe section generated by compilers. This is the sframe header file borrowed from the patchset [1] Josh Poimboeuf according to sframe v2 spec [2]. [1]: https://lore.kernel.org/lkml/42c0a99236af65c09c8182e260af7bcf5aa1e158.1730150953.git.jpoimboe@kernel.org/ [2]: https://sourceware.org/binutils/docs/sframe-spec.html Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- kernel/sframe.h | 215 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 kernel/sframe.h diff --git a/kernel/sframe.h b/kernel/sframe.h new file mode 100644 index 000000000000..11b9be7ad82e --- /dev/null +++ b/kernel/sframe.h @@ -0,0 +1,215 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023, Oracle and/or its affiliates. + * + * This file contains definitions for the SFrame stack tracing format, which is + * documented at https://sourceware.org/binutils/docs + */ +#ifndef _SFRAME_H +#define _SFRAME_H + +#include + +#define SFRAME_VERSION_1 1 +#define SFRAME_VERSION_2 2 +#define SFRAME_MAGIC 0xdee2 + +/* Function Descriptor Entries are sorted on PC. */ +#define SFRAME_F_FDE_SORTED 0x1 +/* Frame-pointer based stack tracing. Defined, but not set. */ +#define SFRAME_F_FRAME_POINTER 0x2 + +#define SFRAME_CFA_FIXED_FP_INVALID 0 +#define SFRAME_CFA_FIXED_RA_INVALID 0 + +/* Supported ABIs/Arch. */ +#define SFRAME_ABI_AARCH64_ENDIAN_BIG 1 /* AARCH64 big endian. */ +#define SFRAME_ABI_AARCH64_ENDIAN_LITTLE 2 /* AARCH64 little endian. */ +#define SFRAME_ABI_AMD64_ENDIAN_LITTLE 3 /* AMD64 little endian. */ + +/* SFrame FRE types. */ +#define SFRAME_FRE_TYPE_ADDR1 0 +#define SFRAME_FRE_TYPE_ADDR2 1 +#define SFRAME_FRE_TYPE_ADDR4 2 + +/* + * SFrame Function Descriptor Entry types. + * + * The SFrame format has two possible representations for functions. The + * choice of which type to use is made according to the instruction patterns + * in the relevant program stub. + */ + +/* Unwinders perform a (PC >= FRE_START_ADDR) to look up a matching FRE. */ +#define SFRAME_FDE_TYPE_PCINC 0 +/* + * Unwinders perform a (PC & FRE_START_ADDR_AS_MASK >= FRE_START_ADDR_AS_MASK) + * to look up a matching FRE. Typical usecases are pltN entries, trampolines + * etc. + */ +#define SFRAME_FDE_TYPE_PCMASK 1 + +/** + * struct sframe_preamble - SFrame Preamble. + * @magic: Magic number (SFRAME_MAGIC). + * @version: Format version number (SFRAME_VERSION). + * @flags: Various flags. + */ +struct sframe_preamble { + u16 magic; + u8 version; + u8 flags; +} __packed; + +/** + * struct sframe_header - SFrame Header. + * @preamble: SFrame preamble. + * @abi_arch: Identify the arch (including endianness) and ABI. + * @cfa_fixed_fp_offset: Offset for the Frame Pointer (FP) from CFA may be + * fixed for some ABIs ((e.g, in AMD64 when -fno-omit-frame-pointer is + * used). When fixed, this field specifies the fixed stack frame offset + * and the individual FREs do not need to track it. When not fixed, it + * is set to SFRAME_CFA_FIXED_FP_INVALID, and the individual FREs may + * provide the applicable stack frame offset, if any. + * @cfa_fixed_ra_offset: Offset for the Return Address from CFA is fixed for + * some ABIs. When fixed, this field specifies the fixed stack frame + * offset and the individual FREs do not need to track it. When not + * fixed, it is set to SFRAME_CFA_FIXED_FP_INVALID. + * @auxhdr_len: Number of bytes making up the auxiliary header, if any. + * Some ABI/arch, in the future, may use this space for extending the + * information in SFrame header. Auxiliary header is contained in bytes + * sequentially following the sframe_header. + * @num_fdes: Number of SFrame FDEs in this SFrame section. + * @num_fres: Number of SFrame Frame Row Entries. + * @fre_len: Number of bytes in the SFrame Frame Row Entry section. + * @fdes_off: Offset of SFrame Function Descriptor Entry section. + * @fres_off: Offset of SFrame Frame Row Entry section. + */ +struct sframe_header { + struct sframe_preamble preamble; + u8 abi_arch; + s8 cfa_fixed_fp_offset; + s8 cfa_fixed_ra_offset; + u8 auxhdr_len; + u32 num_fdes; + u32 num_fres; + u32 fre_len; + u32 fdes_off; + u32 fres_off; +} __packed; + +#define SFRAME_HDR_SIZE(sframe_hdr) \ + ((sizeof(struct sframe_header) + (sframe_hdr).auxhdr_len)) + +/* Two possible keys for executable (instruction) pointers signing. */ +#define SFRAME_AARCH64_PAUTH_KEY_A 0 /* Key A. */ +#define SFRAME_AARCH64_PAUTH_KEY_B 1 /* Key B. */ + +/** + * struct sframe_fde - SFrame Function Descriptor Entry. + * @start_addr: Function start address. Encoded as a signed offset, + * relative to the current FDE. + * @size: Size of the function in bytes. + * @fres_off: Offset of the first SFrame Frame Row Entry of the function, + * relative to the beginning of the SFrame Frame Row Entry sub-section. + * @fres_num: Number of frame row entries for the function. + * @info: Additional information for deciphering the stack trace + * information for the function. Contains information about SFrame FRE + * type, SFrame FDE type, PAC authorization A/B key, etc. + * @rep_size: Block size for SFRAME_FDE_TYPE_PCMASK + * @padding: Unused + */ +struct sframe_fde { + s32 start_addr; + u32 size; + u32 fres_off; + u32 fres_num; + u8 info; + u8 rep_size; + u16 padding; +} __packed; + +/* + * 'func_info' in SFrame FDE contains additional information for deciphering + * the stack trace information for the function. In V1, the information is + * organized as follows: + * - 4-bits: Identify the FRE type used for the function. + * - 1-bit: Identify the FDE type of the function - mask or inc. + * - 1-bit: PAC authorization A/B key (aarch64). + * - 2-bits: Unused. + * --------------------------------------------------------------------- + * | Unused | PAC auth A/B key (aarch64) | FDE type | FRE type | + * | | Unused (amd64) | | | + * --------------------------------------------------------------------- + * 8 6 5 4 0 + */ + +/* Note: Set PAC auth key to SFRAME_AARCH64_PAUTH_KEY_A by default. */ +#define SFRAME_FUNC_INFO(fde_type, fre_enc_type) \ + (((SFRAME_AARCH64_PAUTH_KEY_A & 0x1) << 5) | \ + (((fde_type) & 0x1) << 4) | ((fre_enc_type) & 0xf)) + +#define SFRAME_FUNC_FRE_TYPE(data) ((data) & 0xf) +#define SFRAME_FUNC_FDE_TYPE(data) (((data) >> 4) & 0x1) +#define SFRAME_FUNC_PAUTH_KEY(data) (((data) >> 5) & 0x1) + +/* + * Size of stack frame offsets in an SFrame Frame Row Entry. A single + * SFrame FRE has all offsets of the same size. Offset size may vary + * across frame row entries. + */ +#define SFRAME_FRE_OFFSET_1B 0 +#define SFRAME_FRE_OFFSET_2B 1 +#define SFRAME_FRE_OFFSET_4B 2 + +/* An SFrame Frame Row Entry can be SP or FP based. */ +#define SFRAME_BASE_REG_FP 0 +#define SFRAME_BASE_REG_SP 1 + +/* + * The index at which a specific offset is presented in the variable length + * bytes of an FRE. + */ +#define SFRAME_FRE_CFA_OFFSET_IDX 0 +/* + * The RA stack offset, if present, will always be at index 1 in the variable + * length bytes of the FRE. + */ +#define SFRAME_FRE_RA_OFFSET_IDX 1 +/* + * The FP stack offset may appear at offset 1 or 2, depending on the ABI as RA + * may or may not be tracked. + */ +#define SFRAME_FRE_FP_OFFSET_IDX 2 + +/* + * 'fre_info' in SFrame FRE contains information about: + * - 1 bit: base reg for CFA + * - 4 bits: Number of offsets (N). A value of up to 3 is allowed to track + * all three of CFA, FP and RA (fixed implicit order). + * - 2 bits: information about size of the offsets (S) in bytes. + * Valid values are SFRAME_FRE_OFFSET_1B, SFRAME_FRE_OFFSET_2B, + * SFRAME_FRE_OFFSET_4B + * - 1 bit: Mangled RA state bit (aarch64 only). + * --------------------------------------------------------------- + * | Mangled-RA (aarch64) | Size of | Number of | base_reg | + * | Unused (amd64) | offsets | offsets | | + * --------------------------------------------------------------- + * 8 7 5 1 0 + */ + +/* Note: Set mangled_ra_p to zero by default. */ +#define SFRAME_FRE_INFO(base_reg_id, offset_num, offset_size) \ + (((0 & 0x1) << 7) | (((offset_size) & 0x3) << 5) | \ + (((offset_num) & 0xf) << 1) | ((base_reg_id) & 0x1)) + +/* Set the mangled_ra_p bit as indicated. */ +#define SFRAME_FRE_INFO_UPDATE_MANGLED_RA_P(mangled_ra_p, fre_info) \ + ((((mangled_ra_p) & 0x1) << 7) | ((fre_info) & 0x7f)) + +#define SFRAME_FRE_CFA_BASE_REG_ID(data) ((data) & 0x1) +#define SFRAME_FRE_OFFSET_COUNT(data) (((data) >> 1) & 0xf) +#define SFRAME_FRE_OFFSET_SIZE(data) (((data) >> 5) & 0x3) +#define SFRAME_FRE_MANGLED_RA_P(data) (((data) >> 7) & 0x1) + +#endif /* _SFRAME_H */ From patchwork Mon Jan 27 21:33:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951742 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 CB372C02188 for ; Mon, 27 Jan 2025 21:41:17 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vFxyJQizGcViiMZLcjGdqbFKo+O4vKLRWZRU/ldO2O0=; b=nB+KEY7hS5ScQXhsSTDf3AOfxj 5WGRgBFCSJquaERXsXANZNgwZFhnQpLGcCRONLnKjXSuF5CjBZ5XMrnPUY+rQg/66UgVqGPvuJjY7 2QyHet8Tbx8xcrahRI2hBzoFdgNPGVSucaony5DNF6El8RKskUEZnS1lki/yJ6lneGOnD9MDBpPNU OyJqK9vtZGVvWA5M5y5fK1i3tD914ck20OFx39j3X55DBh7iKrj4GOT0ECgyhn811zbpnyHGwN89d YaRA31GquabcIZthvNJxY4xI8WvFWWhrS5Q7HhPynblFbJkMcCpn9hhqgEgs5DIVjYRhttBrEC8nz cWrVyOUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWqp-00000003KRf-3s1r; Mon, 27 Jan 2025 21:40:59 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWjg-00000003JCl-1QKp for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:38 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2f81a0d0a18so3287190a91.3 for ; Mon, 27 Jan 2025 13:33:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013615; x=1738618415; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vFxyJQizGcViiMZLcjGdqbFKo+O4vKLRWZRU/ldO2O0=; b=ylwTFUi4pytW5SeWFDWcpy9Wk1JlqDHNIHG1tOR5xhD6sLmff6+y+8esj01EGRQtOG l4nHghmVqchfmq2viXzWCvGEUDJKbBQAuyn3UqLzkQ8GWVy1iWwfxRUgecFMhKqce4wt hOmTyiULh5Jaw/pLl7VXAkepZIWjPMSP9/oM8Y0WA0LrG6wxVxNw/zOCHIlnxj8KVB+s 0sfhN9mZHeWgGvvR/jEeahc4wPt7Vn+YPsDJwGfmlH6pznHa5z94DKeQ+API7Uh/glzR GqDlHp8/Yi9BWHcc9WFVT/+anT7Vu/eHMKRFz9f0Oo1UMmmupX1iO9hpGuQ/bwz5Qi/L Y4ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013615; x=1738618415; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vFxyJQizGcViiMZLcjGdqbFKo+O4vKLRWZRU/ldO2O0=; b=cKQ8EyrqKHFpFUGlUsms4/SqAr0d/fXKvnGVLxnTTKttDQaCrBeWagIjHRxBdpHMaC S/eUShPm0J2uWI6ZfJFdAlAaOWPSK50d2aWVao4xd2Vz0m6VaoXdGJzRTSh4euFO/ozX cOj0qUDSBatj97OtFYqC+imNRGFl//M6zmyjfJV0Cjx61cs7ZoFmmAPU35owuB30oc7H BUDlHmzY55qPK+4G7ZOGfTjZdMCkW3sGBf0Ap0YBREZjDSQoLXf8poMZZi8X+0aE+hyu GKcYftuvUy6QWHUky4TmRPxHJrzlQa7na5VPbocpoDYjskyjQnXBJz454VMfvlBCtd4t kpyQ== X-Forwarded-Encrypted: i=1; AJvYcCWGRURxcd2Ycne8GXexlZzjT/qhM3z19og+PFThjYcDec3qyXVVl2HkMvTtRII7IKOG2dGGfbi4noZVru4n/YbX@lists.infradead.org X-Gm-Message-State: AOJu0Yycg4Hi7f/AvYmYHCC02yjQ+vrWSNC9RQytq5u1JfRzn95xFUUE Gt+/mJtqTi2SqILYP4UgQ+Hr0vknPUQbEmaBkAHX6iVGYR97nATR28W97p4l7VhVcaU4aVbJpA= = X-Google-Smtp-Source: AGHT+IHHPT3SHafekGNUGDZsLxe9xIeZEZ7pS5XFwvuSD16m5Qqb3+3tw3GkG+JemAl3HyjyegOXze/WMg== X-Received: from pjbpa16.prod.google.com ([2002:a17:90b:2650:b0:2da:ac73:93e0]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2751:b0:2ee:f440:53ed with SMTP id 98e67ed59e1d1-2f782d9a1d5mr60272909a91.31.1738013614965; Mon, 27 Jan 2025 13:33:34 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:06 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-5-wnliu@google.com> Subject: [PATCH 4/8] unwind: Implement generic sframe unwinder library From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133336_380862_C31A98E4 X-CRM114-Status: GOOD ( 27.50 ) 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 change introduces a kernel space unwinder using sframe table for architectures without ORC unwinder support. The implementation is adapted from Josh's userspace sframe unwinder proposal[1] according to the sframe v2 spec[2]. [1] https://lore.kernel.org/lkml/42c0a99236af65c09c8182e260af7bcf5aa1e158.1730150953.git.jpoimboe@kernel.org/ [2] https://sourceware.org/binutils/docs/sframe-spec.html Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- include/linux/sframe_lookup.h | 43 ++++++++ kernel/Makefile | 1 + kernel/sframe_lookup.c | 196 ++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+) create mode 100644 include/linux/sframe_lookup.h create mode 100644 kernel/sframe_lookup.c diff --git a/include/linux/sframe_lookup.h b/include/linux/sframe_lookup.h new file mode 100644 index 000000000000..1c26cf1f38d4 --- /dev/null +++ b/include/linux/sframe_lookup.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_SFRAME_LOOKUP_H +#define _LINUX_SFRAME_LOOKUP_H + +/** + * struct sframe_ip_entry - sframe unwind info for given ip + * @cfa_offset: Offset for the Canonical Frame Address(CFA) from Frame + * Pointer(FP) or Stack Pointer(SP) + * @ra_offset: Offset for the Return Address from CFA. + * @fp_offset: Offset for the Frame Pointer (FP) from CFA. + * @use_fp: Use FP to get next CFA or not + */ +struct sframe_ip_entry { + int32_t cfa_offset; + int32_t ra_offset; + int32_t fp_offset; + bool use_fp; +}; + +/** + * struct sframe_table - sframe struct of a table + * @sfhdr_p: Pointer to sframe header + * @fde_p: Pointer to the first of sframe frame description entry(FDE). + * @fre_p: Pointer to the first of sframe frame row entry(FRE). + */ +struct sframe_table { + struct sframe_header *sfhdr_p; + struct sframe_fde *fde_p; + char *fre_p; +}; + +#ifdef CONFIG_SFRAME_UNWINDER +void init_sframe_table(void); +int sframe_find_pc(unsigned long pc, struct sframe_ip_entry *entry); +#else +static inline void init_sframe_table(void) {} +static inline int sframe_find_pc(unsigned long pc, struct sframe_ip_entry *entry) +{ + return -EINVAL; +} +#endif + +#endif /* _LINUX_SFRAME_LOOKUP_H */ diff --git a/kernel/Makefile b/kernel/Makefile index 87866b037fbe..705c9277e5cd 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -131,6 +131,7 @@ obj-$(CONFIG_WATCH_QUEUE) += watch_queue.o obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o +obj-$(CONFIG_SFRAME_UNWINDER) += sframe_lookup.o CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN) obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o diff --git a/kernel/sframe_lookup.c b/kernel/sframe_lookup.c new file mode 100644 index 000000000000..846f1da95d89 --- /dev/null +++ b/kernel/sframe_lookup.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include "sframe.h" + +#define pr_fmt(fmt) "sframe: " fmt + +extern char __start_sframe_header[]; +extern char __stop_sframe_header[]; + +static bool sframe_init __ro_after_init; +static struct sframe_table sftbl; + +#define SFRAME_READ_TYPE(in, out, type) \ +({ \ + type __tmp; \ + memcpy(&__tmp, in, sizeof(__tmp)); \ + in += sizeof(__tmp); \ + out = __tmp; \ +}) + +#define SFRAME_READ_ROW_ADDR(in_addr, out_addr, type) \ +({ \ + switch (type) { \ + case SFRAME_FRE_TYPE_ADDR1: \ + SFRAME_READ_TYPE(in_addr, out_addr, u8); \ + break; \ + case SFRAME_FRE_TYPE_ADDR2: \ + SFRAME_READ_TYPE(in_addr, out_addr, u16); \ + break; \ + case SFRAME_FRE_TYPE_ADDR4: \ + SFRAME_READ_TYPE(in_addr, out_addr, u32); \ + break; \ + default: \ + break; \ + } \ +}) + +#define SFRAME_READ_ROW_OFFSETS(in_addr, out_addr, size) \ +({ \ + switch (size) { \ + case 1: \ + SFRAME_READ_TYPE(in_addr, out_addr, s8); \ + break; \ + case 2: \ + SFRAME_READ_TYPE(in_addr, out_addr, s16); \ + break; \ + case 4: \ + SFRAME_READ_TYPE(in_addr, out_addr, s32); \ + break; \ + default: \ + break; \ + } \ +}) + +static struct sframe_fde *find_fde(const struct sframe_table *tbl, unsigned long pc) +{ + int l, r, m, f; + int32_t ip; + struct sframe_fde *fdep; + + if (!tbl || !tbl->sfhdr_p || !tbl->fde_p) + return NULL; + + ip = (pc - (unsigned long)tbl->sfhdr_p); + + /* Do a binary range search to find the rightmost FDE start_addr < ip */ + l = m = f = 0; + r = tbl->sfhdr_p->num_fdes; + while (l < r) { + m = l + ((r - l) / 2); + fdep = tbl->fde_p + m; + if (fdep->start_addr > ip) + r = m; + else + l = m + 1; + } + /* use l - 1 because l will be the first item fdep->start_addr > ip */ + f = l - 1; + if (f >= tbl->sfhdr_p->num_fdes || f < 0) + return NULL; + fdep = tbl->fde_p + f; + if (ip < fdep->start_addr || ip >= fdep->start_addr + fdep->size) + return NULL; + + return fdep; +} + +static int find_fre(const struct sframe_table *tbl, unsigned long pc, + const struct sframe_fde *fdep, struct sframe_ip_entry *entry) +{ + int i, offset_size, offset_count; + char *fres, *offsets_loc; + int32_t ip_off; + uint32_t next_row_ip_off; + uint8_t fre_info, fde_type = SFRAME_FUNC_FDE_TYPE(fdep->info), + fre_type = SFRAME_FUNC_FRE_TYPE(fdep->info); + + fres = tbl->fre_p + fdep->fres_off; + + /* Whether PCs in the FREs should be treated as masks or not */ + if (fde_type == SFRAME_FDE_TYPE_PCMASK) + ip_off = pc % fdep->rep_size; + else + ip_off = (int32_t)(pc - (unsigned long)tbl->sfhdr_p) - fdep->start_addr; + + if (ip_off < 0 || ip_off >= fdep->size) + return -EINVAL; + + /* + * FRE structure starts by address of the entry with variants length. Use + * two pointers to track current head(fres) and the address of last + * offset(offsets_loc) + */ + for (i = 0; i < fdep->fres_num; i++) { + SFRAME_READ_ROW_ADDR(fres, next_row_ip_off, fre_type); + if (ip_off < next_row_ip_off) + break; + SFRAME_READ_TYPE(fres, fre_info, u8); + offsets_loc = fres; + /* + * jump to the start of next fre + * fres += fre_offets_cnt*offset_size + */ + fres += SFRAME_FRE_OFFSET_COUNT(fre_info) << SFRAME_FRE_OFFSET_SIZE(fre_info); + } + + offset_size = 1 << SFRAME_FRE_OFFSET_SIZE(fre_info); + offset_count = SFRAME_FRE_OFFSET_COUNT(fre_info); + + if (offset_count > 0) { + SFRAME_READ_ROW_OFFSETS(offsets_loc, entry->cfa_offset, offset_size); + offset_count--; + } + if (offset_count > 0 && !entry->ra_offset) { + SFRAME_READ_ROW_OFFSETS(offsets_loc, entry->ra_offset, offset_size); + offset_count--; + } + if (offset_count > 0 && !entry->fp_offset) { + SFRAME_READ_ROW_OFFSETS(offsets_loc, entry->fp_offset, offset_size); + offset_count--; + } + if (offset_count) + return -EINVAL; + + entry->use_fp = SFRAME_FRE_CFA_BASE_REG_ID(fre_info) == SFRAME_BASE_REG_FP; + + return 0; +} + +int sframe_find_pc(unsigned long pc, struct sframe_ip_entry *entry) +{ + struct sframe_fde *fdep; + struct sframe_table *sftbl_p = &sftbl; + int err; + + if (!sframe_init) + return -EINVAL; + + memset(entry, 0, sizeof(*entry)); + entry->ra_offset = sftbl_p->sfhdr_p->cfa_fixed_ra_offset; + entry->fp_offset = sftbl_p->sfhdr_p->cfa_fixed_fp_offset; + + fdep = find_fde(sftbl_p, pc); + if (!fdep) + return -EINVAL; + err = find_fre(sftbl_p, pc, fdep, entry); + if (err) + return err; + + return 0; +} + +void __init init_sframe_table(void) +{ + size_t sframe_size = (void *)__stop_sframe_header - (void *)__start_sframe_header; + void *sframe_buf = __start_sframe_header; + + if (sframe_size <= 0) + return; + sftbl.sfhdr_p = sframe_buf; + if (!sftbl.sfhdr_p || sftbl.sfhdr_p->preamble.magic != SFRAME_MAGIC || + sftbl.sfhdr_p->preamble.version != SFRAME_VERSION_2 || + !(sftbl.sfhdr_p->preamble.flags & SFRAME_F_FDE_SORTED)) { + pr_warn("WARNING: Unable to read sframe header. Disabling unwinder.\n"); + return; + } + + sftbl.fde_p = (struct sframe_fde *)(__start_sframe_header + SFRAME_HDR_SIZE(*sftbl.sfhdr_p) + + sftbl.sfhdr_p->fdes_off); + sftbl.fre_p = __start_sframe_header + SFRAME_HDR_SIZE(*sftbl.sfhdr_p) + + sftbl.sfhdr_p->fres_off; + sframe_init = true; +} From patchwork Mon Jan 27 21:33:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951743 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 57338C02188 for ; Mon, 27 Jan 2025 21:42:32 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mFZXsTdloa5FzORw/CsOyUNbSmbFrEPnylJyQFApTRk=; b=WgHRzS77i84QmRH39h7UuvQ6tY 9hbV0f6ABoV4jTC3RLW8xUtwpgcdz9jYcTSFCVIcs0x0aJKYdcjcOrKR52QklzwYZv8pUPVH3uCyz qNM8T2F6V3FL2iGvEn+p+WmHda+fdI83YWNAJyywTzJsHkT+nA0ZsJ55Nmi9Xvrb94cSOCYz/BMXK veHlE1qEPGxB5GqNqHJ06BaF56R5Vq6bhN+YNxSqiuI/ZZ0dGSUkXAEtpdsomDoffoiDeq+IPKd8w A+ASPz6N8wU5Exg3N+ozImrAzTUB8xyRdETkZT6UFp6ycpBatEIVZV7Vqa9LFmS0XENWyeiwDNRfx iQcUdQDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWs8-00000003KY7-3ZmA; Mon, 27 Jan 2025 21:42:20 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWji-00000003JDM-18H1 for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:39 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-2163dc0f689so144572375ad.1 for ; Mon, 27 Jan 2025 13:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013617; x=1738618417; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mFZXsTdloa5FzORw/CsOyUNbSmbFrEPnylJyQFApTRk=; b=ul3T77Ou9GC/JBPD+vh5FEig8Je2Y5BTJxMwIOkwv0D/S54Qm2Oe2GGJSCehcNebd9 tOkJ69CAaCbfdQQ0zDEXHZcgZaOUdYaJr5Ydi8HDTjiJQy/TAttEdn2yIMk5EZDw+bEQ CQb+PuTbE0sMOXRXKEva4zNbie1ifkDVvbmPxVSb1DMgsQEM6hW4JXSqCxSPfA3OdCZ6 K0UKSr8li5XY88MOYS9BhrXrAxO9Pk12Zp5G9VtvdsEDIc0vaA08RKFLdDXrC04yEp4e 4cfHkr8AZkLqKlaTP2pEh+HqVgLN/X8c198L/CWKYAlwbMJgxWWNt9sIG9mR0+TKeiZf /+1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013617; x=1738618417; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mFZXsTdloa5FzORw/CsOyUNbSmbFrEPnylJyQFApTRk=; b=fdxJz92B944cPtdZpX0Snyhb99Ih9DLqpoEObRp6gGi75GCyLKfeXZfa+M9IqyFdWO AVNFPGy+KMNKSO0+V80jzvDGEeQOt3pybZZQUpjKdWdzZBJRd5ic4R9A2pB/ZVXYXAR3 g/1DSRvOO3GPqLl9Z59XdAdKmitSzb/bKkvpHEWJ3VRMF+vHVFBpxeGemEEzmYhxZmhC q/IYe2xfb5OZJS3oMvkbg5e7xcG2ZMre9OzUBf276kiNpfwerIEntbgBJ7K9UKpudAah wp1Vmka8CiA88tILrzaaxO4Kgalz3qhZfRW7vq1ZfG5rdDEuUl5UGpUHbhiugFL5I/Rs pijQ== X-Forwarded-Encrypted: i=1; AJvYcCXgRgR9/o3QSO9UrE68qQv94uo5PBYbvJSD6ADtDK82UiGD5YEQg040gSXYEoHrt4weekktBHE9Hev4HTX0FMey@lists.infradead.org X-Gm-Message-State: AOJu0YwJX/ZxvssbTsdxJiLaBWWx0sx2XvIsu6TormV/OdPEvoHuDAgg 5sGyRIefGAdGa/IhuX/0HVfJTvtnZeHhLEpmCTAoeevPUI/4MBdotzlJ5gjAzOghfg3NS26RDQ= = X-Google-Smtp-Source: AGHT+IENha76YNN6DTFkO6aZG4PVMEo+T4QLkeiQTYtMA7zB4aNyty+JXRxi3cxPQYVRs4yLEbvYOf/KmQ== X-Received: from pfbbx20.prod.google.com ([2002:a05:6a00:4294:b0:729:14f9:2f50]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:12c6:b0:1e0:e000:ca60 with SMTP id adf61e73a8af0-1eb215ec22fmr70877628637.28.1738013617138; Mon, 27 Jan 2025 13:33:37 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:07 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-6-wnliu@google.com> Subject: [PATCH 5/8] unwind: arm64: Add sframe unwinder on arm64 From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133338_312338_CFF35A12 X-CRM114-Status: GOOD ( 18.72 ) 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 Add unwind_next_frame_sframe() function to unwind by sframe info. Built with GNU Binutils 2.42 to verify that this sframe unwinder can backtrace correctly on arm64. Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- arch/arm64/include/asm/stacktrace/common.h | 4 ++ arch/arm64/kernel/setup.c | 2 + arch/arm64/kernel/stacktrace.c | 59 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h index 821a8fdd31af..19edae8a5b1a 100644 --- a/arch/arm64/include/asm/stacktrace/common.h +++ b/arch/arm64/include/asm/stacktrace/common.h @@ -25,6 +25,7 @@ struct stack_info { * @stack: The stack currently being unwound. * @stacks: An array of stacks which can be unwound. * @nr_stacks: The number of stacks in @stacks. + * @cfa: The sp value at the call site of the current function. */ struct unwind_state { unsigned long fp; @@ -33,6 +34,9 @@ struct unwind_state { struct stack_info stack; struct stack_info *stacks; int nr_stacks; +#ifdef CONFIG_SFRAME_UNWINDER + unsigned long cfa; +#endif }; static inline struct stack_info stackinfo_get_unknown(void) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 4f613e8e0745..d3ac92b624f3 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -377,6 +378,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) "This indicates a broken bootloader or old kernel\n", boot_args[1], boot_args[2], boot_args[3]); } + init_sframe_table(); } static inline bool cpu_can_disable(unsigned int cpu) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 1d9d51d7627f..c035adb8fe8a 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -242,6 +243,53 @@ kunwind_next_frame_record(struct kunwind_state *state) return 0; } +#ifdef CONFIG_SFRAME_UNWINDER +/* + * Unwind to the next frame according to sframe. + */ +static __always_inline int +unwind_next_frame_sframe(struct unwind_state *state) +{ + unsigned long fp = state->fp, ip = state->pc; + unsigned long base_reg, cfa; + unsigned long pc_addr, fp_addr; + struct sframe_ip_entry entry; + struct stack_info *info; + struct frame_record *record = (struct frame_record *)fp; + + int err; + + /* frame record alignment 8 bytes */ + if (fp & 0x7) + return -EINVAL; + + info = unwind_find_stack(state, fp, sizeof(*record)); + if (!info) + return -EINVAL; + + err = sframe_find_pc(ip, &entry); + if (err) + return -EINVAL; + + unwind_consume_stack(state, info, fp, sizeof(*record)); + + base_reg = entry.use_fp ? fp : state->cfa; + + /* Set up the initial CFA using fp based info if CFA is not set */ + if (!state->cfa) + cfa = fp - entry.fp_offset; + else + cfa = base_reg + entry.cfa_offset; + fp_addr = cfa + entry.fp_offset; + pc_addr = cfa + entry.ra_offset; + state->cfa = cfa; + state->fp = READ_ONCE(*(unsigned long *)(fp_addr)); + state->pc = READ_ONCE(*(unsigned long *)(pc_addr)); + + return 0; +} +#endif + /* * Unwind from one frame record (A) to the next frame record (B). * @@ -261,7 +309,15 @@ kunwind_next(struct kunwind_state *state) case KUNWIND_SOURCE_CALLER: case KUNWIND_SOURCE_TASK: case KUNWIND_SOURCE_REGS_PC: +#ifdef CONFIG_SFRAME_UNWINDER + err = unwind_next_frame_sframe(&state->common); + + /* Fallback to FP based unwinder */ + if (err) err = kunwind_next_frame_record(state); +#else + err = kunwind_next_frame_record(state); +#endif break; default: err = -EINVAL; @@ -347,6 +403,9 @@ kunwind_stack_walk(kunwind_consume_fn consume_state, .common = { .stacks = stacks, .nr_stacks = ARRAY_SIZE(stacks), +#ifdef CONFIG_SFRAME_UNWINDER + .cfa = 0, +#endif }, }; From patchwork Mon Jan 27 21:33:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951744 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 510D4C02188 for ; Mon, 27 Jan 2025 21:43:56 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FcMmLMqjQF9870LrAMy1ogNf6Ad9PcDDaPxJ25OGjiY=; b=HuWA9PuRVMRJqlJw/4vTdbBWC3 5acIkDz5UroOzFvc4TfWf6tMTkgsjowtBwORJ6X6WhnRvzo4/CED5fszdOEJtV5xu2eO/WHUVXq9J xoBsSA35hGGs0q/j/FnOP5Uu5f+Yho57voC/jNJz209NJTCBH7VBpYhTm1aR08k8tIYgUrT3aZZQf cfokBNOFdGmnHVSmlQ9r+5MDe16itJ0P6gv56+n95YOOOzPFhGzmhfqAmRCwUIxpZeBV/r98Em9Lt oTRBi0ZMNvrIRBRZtzXhrjsg17515bDReqxfqixwBEQVJOGs+vIje8wRfC/t/LsUtnvZ+9dDsGpKq oiwWOhyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWtS-00000003Kjy-2LTj; Mon, 27 Jan 2025 21:43:42 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWjk-00000003JFZ-2TSe for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:42 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-2164fad3792so82086295ad.0 for ; Mon, 27 Jan 2025 13:33:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013619; x=1738618419; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FcMmLMqjQF9870LrAMy1ogNf6Ad9PcDDaPxJ25OGjiY=; b=ShM+XGCFwDCWOEvSJ6jW9uUbrB0RkWur7OSKqTJAsXSu1dXP6TuPx3IXDEPE9Ygalx vtpPTUhywc+P4QzArUdIS6bXL7yM9so0OJgN9Q9CvDqSHrQuvrPhXfgHtR2LhnslrRJM eyLxzf0AZkBPnl5BHLWauMCIDPR0F5PeELqv+KOpkoCkzJacQQddnpI8NmnrujCP9pSa 6mPD42wUzcZbHZotlIBFjXL1MoU+hyiv7DmPQJlHg1VeA7PBbax0cjjcuM/+Yc6RWQDK YfoWSPerkEebuZPvoycPxMEl3xruN46N8Nvod/23bawvkYX2nTEyKsGtscLIV/Ua5p0C K/LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013619; x=1738618419; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FcMmLMqjQF9870LrAMy1ogNf6Ad9PcDDaPxJ25OGjiY=; b=eZGRddrrR2DKCO2LK8f7zKPVuTG6euDE6nohwNrmcEKTI5kUK2aQZqS/+kf8YshWmd KUCPEiYWDsKm0SbDvaaCaecexxmYcGTpQVkWDKl/Yn17pMhaksc5x8CmQfZr9o2tuSTR sPZIFTTucp+e3OS1G9pS/9KHMYWLvMt1SC28rZI62qp+RPOCy1m6KEzVZKDsqmuvKx0D cX+CXYanBJfCt8dTclFhSmPVdq2aC0r4yMyJRTgNDzgNVIUNF+V9dlroOBkNcFfgikuF GTlcWtCucrsDTKJbku6rk6JqdQqMbNTolOtZzR0YRzJMXzP4HfQ1xjr59xm9+1bDL9SR rIGw== X-Forwarded-Encrypted: i=1; AJvYcCXc9rtIE3JtkJQj+lSssM5CIiIWEB7zKYzb9sR8mBDthlFaZO9Trye/6a9XLEOCWfJYheDVDbOIU4qBo3ESfFcA@lists.infradead.org X-Gm-Message-State: AOJu0YwkSeFsxhmkeEa06bw/uWbKtrkG+kddkmXlcZbmwnKjBFwRDoyY ZIfGU8Uety683BvZVituJgV+6wlUBtwkp9g8TLSYNztnXnIfriKfXxAUusdSfPm3FVamHVHcOQ= = X-Google-Smtp-Source: AGHT+IENqQ4a+JpNNuEyJE6twpdJLH79mb1KDwUiISYTqFmJctu2Pc5D2j5e3Ta7eQhNemgumBMfeJjRgA== X-Received: from pgbbg17.prod.google.com ([2002:a05:6a02:111:b0:7fc:2b57:38f5]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:841c:b0:1e0:d9a0:4ff7 with SMTP id adf61e73a8af0-1eb21599eecmr80987482637.32.1738013619557; Mon, 27 Jan 2025 13:33:39 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:08 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-7-wnliu@google.com> Subject: [PATCH 6/8] unwind: arm64: add reliable stacktrace support for arm64 From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133340_671696_FDD0B976 X-CRM114-Status: GOOD ( 16.93 ) 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 To support livepatch, we need to add arch_stack_walk_reliable to support reliable stacktrace according to https://docs.kernel.org/livepatch/reliable-stacktrace.html#requirements report stacktrace is not reliable if we are not able to unwind the stack by sframe unwinder and fallback to FP based unwinder Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- arch/arm64/include/asm/stacktrace/common.h | 2 + arch/arm64/kernel/stacktrace.c | 47 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h index 19edae8a5b1a..26449cd402db 100644 --- a/arch/arm64/include/asm/stacktrace/common.h +++ b/arch/arm64/include/asm/stacktrace/common.h @@ -26,6 +26,7 @@ struct stack_info { * @stacks: An array of stacks which can be unwound. * @nr_stacks: The number of stacks in @stacks. * @cfa: The sp value at the call site of the current function. + * @unreliable: Stacktrace is unreliable. */ struct unwind_state { unsigned long fp; @@ -36,6 +37,7 @@ struct unwind_state { int nr_stacks; #ifdef CONFIG_SFRAME_UNWINDER unsigned long cfa; + bool unreliable; #endif }; diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index c035adb8fe8a..eab16dc05bb5 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -310,11 +310,16 @@ kunwind_next(struct kunwind_state *state) case KUNWIND_SOURCE_TASK: case KUNWIND_SOURCE_REGS_PC: #ifdef CONFIG_SFRAME_UNWINDER - err = unwind_next_frame_sframe(&state->common); + if (!state->common.unreliable) + err = unwind_next_frame_sframe(&state->common); /* Fallback to FP based unwinder */ - if (err) + if (err || state->common.unreliable) { err = kunwind_next_frame_record(state); + /* Mark its stacktrace result as unreliable if it is unwindable via FP */ + if (!err) + state->common.unreliable = true; + } #else err = kunwind_next_frame_record(state); #endif @@ -446,6 +451,44 @@ noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry, kunwind_stack_walk(arch_kunwind_consume_entry, &data, task, regs); } +#ifdef CONFIG_SFRAME_UNWINDER +struct kunwind_reliable_consume_entry_data { + stack_trace_consume_fn consume_entry; + void *cookie; + bool unreliable; +}; + +static __always_inline bool +arch_kunwind_reliable_consume_entry(const struct kunwind_state *state, void *cookie) +{ + struct kunwind_reliable_consume_entry_data *data = cookie; + + if (state->common.unreliable) { + data->unreliable = true; + return false; + } + return data->consume_entry(data->cookie, state->common.pc); +} + +noinline notrace int arch_stack_walk_reliable( + stack_trace_consume_fn consume_entry, + void *cookie, struct task_struct *task) +{ + struct kunwind_reliable_consume_entry_data data = { + .consume_entry = consume_entry, + .cookie = cookie, + .unreliable = false, + }; + + kunwind_stack_walk(arch_kunwind_reliable_consume_entry, &data, task, NULL); + + if (data.unreliable) + return -EINVAL; + + return 0; +} +#endif + struct bpf_unwind_consume_entry_data { bool (*consume_entry)(void *cookie, u64 ip, u64 sp, u64 fp); void *cookie; From patchwork Mon Jan 27 21:33:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951749 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 D7561C02188 for ; Mon, 27 Jan 2025 21:45:15 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rrEAyoRWIZk//3vjAjFd2Tppwtrq4EACKZ1CutvRWx8=; b=uFhY7nBhPp2588vftiCrKiZ9+8 jXx/At3w/mOpmFhrJtw5rX7DFYCiidQoVzMggcI+l7HKY2P5SAt4mNnYFZPXD4nXzHzFfa67TGwNF MEzYGTLN16LpGsFFmtyZPluYDJ5I/8/SonFZ0M0i9fCRBBWZhvsmmVv4ssorZDOlPzrZMN+uFn20g xoddWya5YIk6bZ1bpIZoqFXqR94VCWXY/bIxYgqRTj/FgizOIjjNaZjS+AYQtec4N48VLBLrw19Fm v28uUUqSNpA06A8HQOdVC1OpbFYWmquqKxglimBwdxCmiKazEiGU3P2jHcmLl27jIkqbfrBU3oO9o qLcwv9OQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWul-00000003Kxc-0q8F; Mon, 27 Jan 2025 21:45:03 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWjm-00000003JH7-2ig1 for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:43 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-2163dc0f689so144574015ad.1 for ; Mon, 27 Jan 2025 13:33:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013622; x=1738618422; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rrEAyoRWIZk//3vjAjFd2Tppwtrq4EACKZ1CutvRWx8=; b=h5Y+tORcSjx6t6KNVPOWwVGtFTGgO1v80jEz3sLv+hCSnIJAfyyapwVskgXw8djdHJ tRuoZA8bkhcU9ZhzVYM267ik4CuotgaLvBhY5vI1gdfiUc+VnLgXIMvdcbTHo4uGFR2T PjYenWfZuOwV7LV2t4fWiN/vt1GrpPQXd75xs+AsdVJpvJYm+XsUb1uoeR+3cw6kuwNh W453UX5HV/zC1A1sekIO5HiUMcnHztVlQH9ek/FKi+mpeO2gum+w8rIKPh3gVOfXmxSp kRe7tHJqg6y6aDCeKTgItDtpzwIw0ckolMeoCgNjdtYn2eV5m9P3B2VlL1WPJwaSeLbL VEcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013622; x=1738618422; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rrEAyoRWIZk//3vjAjFd2Tppwtrq4EACKZ1CutvRWx8=; b=guw2/cnzVSyS7fPx6q2bbS9NY/Gite3q0wgztQ2kTCctOsSY01LaCIPDsf2vpStuTa ayUxnfM/AlJfkVTElZhDjXRcAU8MwvO5goR7QqQJdV97sQt6YFnLhr/UXfVHKYZq96Im Tz7t3lRKpATzDvIYGhwIp1h/d+TAgPkaPc/eyTrrS43LbtigTaIWKxocgJznrmWce3Ra kwno06e9PUea5BTTXH2Tos6TajJzbrzdmDQCQk0RWXQswSeMuASv0bm+qrSKjeQ9njsa ISnrAgNwXq+pB0/FJGR50k3jzwtmYWzb+TcNbhdwgr5j5hqiNddyihsDGT0BWHd12RLn pOgQ== X-Forwarded-Encrypted: i=1; AJvYcCXR0hCfGcXf4jly/YvCjXi0HruJtpTmIkMIAbVSt0pNa9R4mn/sypFgopYm7Q8i5bgagFcfv5VbHk4hgqqUfp/1@lists.infradead.org X-Gm-Message-State: AOJu0YxGNttNtGi64H5K6E510sAUA1xM+3apnq8j6+ewUht1gCeMm7IF XkwzbqiVXVsakeE035vMLCkOJ9TgfnXkG9VF5BQ4o5gg6M6qiiQvkYcn0ZWJ5BJeU/ybbwJ7Qw= = X-Google-Smtp-Source: AGHT+IFFYVquifAUjWGrSZ5hEYAV0U5je02EgbAStisFUtw2EXTxIW8KfHqT+GqGJXHAuJ9zxlbXu/WPRQ== X-Received: from plblq6.prod.google.com ([2002:a17:903:1446:b0:215:515c:124e]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d2d2:b0:215:b01a:627f with SMTP id d9443c01a7336-21c352de4c0mr685131525ad.4.1738013621760; Mon, 27 Jan 2025 13:33:41 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:09 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-8-wnliu@google.com> Subject: [PATCH 7/8] arm64: Define TIF_PATCH_PENDING for livepatch From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, "Madhavan T. Venkataraman" , Suraj Jitindar Singh , Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133342_691838_BBAC99C1 X-CRM114-Status: GOOD ( 14.55 ) 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 From: "Madhavan T. Venkataraman" - Define TIF_PATCH_PENDING in arch/arm64/include/asm/thread_info.h for livepatch. - Check TIF_PATCH_PENDING in do_notify_resume() to patch the current task for livepatch. Signed-off-by: Suraj Jitindar Singh Signed-off-by: Madhavan T. Venkataraman Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- arch/arm64/include/asm/thread_info.h | 4 +++- arch/arm64/kernel/entry-common.c | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index 1114c1c3300a..3810c2f3914e 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -64,6 +64,7 @@ void arch_setup_new_exec(void); #define TIF_UPROBE 4 /* uprobe breakpoint or singlestep */ #define TIF_MTE_ASYNC_FAULT 5 /* MTE Asynchronous Tag Check Fault */ #define TIF_NOTIFY_SIGNAL 6 /* signal notifications exist */ +#define TIF_PATCH_PENDING 7 /* pending live patching update */ #define TIF_SYSCALL_TRACE 8 /* syscall trace active */ #define TIF_SYSCALL_AUDIT 9 /* syscall auditing */ #define TIF_SYSCALL_TRACEPOINT 10 /* syscall tracepoint for ftrace */ @@ -99,11 +100,12 @@ void arch_setup_new_exec(void); #define _TIF_MTE_ASYNC_FAULT (1 << TIF_MTE_ASYNC_FAULT) #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL) #define _TIF_TSC_SIGSEGV (1 << TIF_TSC_SIGSEGV) +#define _TIF_PATCH_PENDING (1 << TIF_PATCH_PENDING) #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \ _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \ _TIF_UPROBE | _TIF_MTE_ASYNC_FAULT | \ - _TIF_NOTIFY_SIGNAL) + _TIF_NOTIFY_SIGNAL | _TIF_PATCH_PENDING) #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index b260ddc4d3e9..b537af333b42 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,9 @@ static void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags) (void __user *)NULL, current); } + if (thread_flags & _TIF_PATCH_PENDING) + klp_update_patch_state(current); + if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) do_signal(regs); From patchwork Mon Jan 27 21:33:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weinan Liu X-Patchwork-Id: 13951750 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 5F029C02188 for ; Mon, 27 Jan 2025 21:46:38 +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-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rDc9oon22Zy8JtV6oJyK3eShWNaKTPBJnRLwhRmq6mE=; b=CYhUjRKe+GBumJvGU4wG6LwY8J AhXphTjs5awQmbczEIofeKlcAEzm64ojViGE6mDvuOcPtIhM5qCFYFMkrWtkykrKgGtdONcLFr7ED QDsJTDepslNYsvJNk+mxFLScS3Km49b58JbLGsoDSmWI8S+qiaa+eqHfqlR41wfZyIvsc6h8JNUAn 2uO1vVzqvpOx68NpTll5AH2NGs+8QWHFvllGRX8gsXXBKSFnD7ioaQBzIvN+MShAgR0+peAWCOco6 C4l1dovgSYk4Xa8qIdBiZgHz3paTB+DBmV9sj7D8q+t+XzvyXMKyYjhFivCZ6YAURggmzBBpCtb7q 9n5mM5kQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tcWw3-00000003L4U-3v5X; Mon, 27 Jan 2025 21:46:23 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcWjp-00000003JIN-24WB for linux-arm-kernel@lists.infradead.org; Mon, 27 Jan 2025 21:33:46 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2ef9204f898so9423218a91.2 for ; Mon, 27 Jan 2025 13:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738013624; x=1738618424; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rDc9oon22Zy8JtV6oJyK3eShWNaKTPBJnRLwhRmq6mE=; b=twwlMm8i35i51mw/lK+xl9IGTv8nxH7siLUTeUBCwFmURgy6yZaqHXK776X+O30c/F HCjkzbbngDH4q+dQt1EzNKCsDFRtjhKQbvQBMtUIDpC7C0+BzTGAz9kjoXg8W8Bg9Qgl KaecbMelcTIctn87xRQCXnCwPfjeZf0PhTLyyQxy6raDvKE8UtBxFPIMCe+3JVInNipL 6gjbwrdD/exE4XgumOT8VjWqNxSTDslDo2OEnY/izZ4TeomczGmoy+34DOMSH7hQS+Qa ZMckzZYL+pJIe+LJOfdrooJF+eCNLrcbsPHfPAR1NwYsujY+VgdCAng3/dbE/s/LGND+ CqBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738013624; x=1738618424; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rDc9oon22Zy8JtV6oJyK3eShWNaKTPBJnRLwhRmq6mE=; b=t2TDsveiv8R7m6IRS52quoMVXft7RcSdYQi+/T9jjurGxqHUj8jfA/J4njYHH+0ibm DSfX9dFe9BiRZBT4fbGDOFTJTC7sS5uEK06HsgmzEvGF1lxZ9tmWWhBFAMV+gReOY6M0 ou820ZEjETDE7Bjlq5YHIBUEnBcVhLcm77mPMMETK2iVwtGuz+fePd/XOl4AXyVzwtAT X6mOiPGsjeBBf+gCnqaCW/0jxBplLBm9yq1dYqkID+uH5odl6eMIfZCjoT7Uyh0YsunK qRcVIy45or9FFokATXQ2rqbBzut3hW110VJjwJfESFTghNpAePU/IYP1IkZ+LQlCkTe/ 2YVQ== X-Forwarded-Encrypted: i=1; AJvYcCUJs4uQqGW2urUEnALwjPwI+qn1X+B4BDjKpN6HllAAzJwo/xGdrRWrnKBKWZ3sFOVHOXA8GD/drQIorwBUTp53@lists.infradead.org X-Gm-Message-State: AOJu0YyQq1l42HiiZDEGzK1Cmb5NfUu/xih/MvQx5g4ZNibLc2uNvb4r HGV2jOoSaZ2WZ0kMrhE2I/2lR6V0ZDAisKq63zf5zaffMcc+Agd6NyYTWhH9u9GzR1gbnwXKvA= = X-Google-Smtp-Source: AGHT+IEfHevdTTJtb6AigZBRpVD2FnhyEzVTYMnATEtYpNkPmzEcW9Tro1KWiXPv1Vj43sJ3+gY4o9DCZA== X-Received: from pjbqo13.prod.google.com ([2002:a17:90b:3dcd:b0:2f4:47fc:7f17]) (user=wnliu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2808:b0:2ee:5edc:4b2 with SMTP id 98e67ed59e1d1-2f782cc0114mr60880084a91.20.1738013624271; Mon, 27 Jan 2025 13:33:44 -0800 (PST) Date: Mon, 27 Jan 2025 21:33:10 +0000 In-Reply-To: <20250127213310.2496133-1-wnliu@google.com> Mime-Version: 1.0 References: <20250127213310.2496133-1-wnliu@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127213310.2496133-9-wnliu@google.com> Subject: [PATCH 8/8] arm64: Enable livepatch for ARM64 From: Weinan Liu To: Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org, Weinan Liu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_133345_529492_014EFDDE X-CRM114-Status: UNSURE ( 9.22 ) X-CRM114-Notice: Please train this message. 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 Since SFrame is considered as reliable stacktrace, enable livepatch in arch/arm64/Kconfig Signed-off-by: Weinan Liu Reviewed-by: Prasanna Kumar T S M . --- arch/arm64/Kconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 100570a048c5..c292bc73b65c 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -271,6 +271,8 @@ config ARM64 select HAVE_SOFTIRQ_ON_OWN_STACK select USER_STACKTRACE_SUPPORT select VDSO_GETRANDOM + select HAVE_RELIABLE_STACKTRACE if SFRAME_UNWINDER + select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_ARGS && HAVE_RELIABLE_STACKTRACE help ARM 64-bit (AArch64) Linux support. @@ -2498,3 +2500,4 @@ source "drivers/acpi/Kconfig" source "arch/arm64/kvm/Kconfig" +source "kernel/livepatch/Kconfig"