From patchwork Thu Apr 7 20:25:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12805673 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 31F70C433F5 for ; Thu, 7 Apr 2022 20:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wr+YD7+SQ3gUTOOHV5v1liq6YXTeagt01Qml4oS1nyI=; b=xkjrSLadAdV1lH 6qEuY/wfamGgamd2wA38DEpDGVo7LeMKXowjI0Y+CZbB5BKulPaapDjec/TGs+K2TeuNXO7KvGsVp aAP4Qw4y67eYz2G99WTvdcqYfVopINlZ9aS2gXQViT8XipdW1Agk0rtyqMmHyH3BVC4rXwYYpXPFb ZbbiZjXysG3Py2N0T0yFzRZQwOhwZLYsDr0bTWmQcljcQjZ+kg9pBmlemAjOrbKiTf0jKlhVXB3Sa 6AbqoDtwyq9SAIWa9NouAsBBP7FgMvsBomEU9NaGOVRLsCi4j3po3j3xDKt9dOMnprgxvITp0+zTN j4dClQKlfu3mDx8MABqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncYhz-00Drfa-OY; Thu, 07 Apr 2022 20:26:23 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncYhf-00DrWg-Jq for linux-arm-kernel@lists.infradead.org; Thu, 07 Apr 2022 20:26:05 +0000 Received: from x64host.home (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 798F420B9CF0; Thu, 7 Apr 2022 13:26:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 798F420B9CF0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1649363163; bh=wbp3KQRzbL8wBuPZAF+JGlo4GHESFi/Po72T2KLLghc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=R25TWtc3BkaKmcHdSg95pqX7kI1wwu5ptGUfUsniDru1WvlWHXVlclaqU2JEnbfzf w61K70ILGt2p/F+/E9xjBa8ZTbPtw8HapvDAXXqegLfOuyVTrYDlcDTboQqXn4DvF9 W6BBgdS0l6JCAooirPH5dmPDvzUsF1HitaGFsgd0= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [RFC PATCH v1 3/9] dwarf: Build the kernel with DWARF information Date: Thu, 7 Apr 2022 15:25:12 -0500 Message-Id: <20220407202518.19780-4-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407202518.19780-1-madvenka@linux.microsoft.com> References: <95691cae4f4504f33d0fc9075541b1e7deefe96f> <20220407202518.19780-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_132603_780933_241F5F69 X-CRM114-Status: GOOD ( 19.11 ) 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 CONFIG_DWARF_FP - to include DWARF based FP validation code. Define CONFIG_STACK_VALIDATION - to enable DWARF based FP validation. When these configs are enabled, invoke objtool on relocatable files during the kernel build with the following command: objtool dwarf generate Objtool creates the following sections in each object file: .dwarf_rules Array of DWARF rules .dwarf_pcs Array of PCs, one-to-one with rules In the future, the kernel can use these sections to find the rules for a given instruction address. The unwinder can then compute the FP at an instruction address and validate the actual FP with that. NOTE: CONFIG_STACK_VALIDATION needs to be turned on here. Otherwise, objtool will not be invoked during the kernel build process. The actual stack validation code will be added separately. This is harmless. Signed-off-by: Madhavan T. Venkataraman --- arch/Kconfig | 4 +++- arch/arm64/Kconfig | 2 ++ arch/arm64/Kconfig.debug | 5 +++++ arch/arm64/configs/defconfig | 1 + arch/arm64/kernel/vmlinux.lds.S | 22 ++++++++++++++++++++++ scripts/Makefile.build | 4 ++++ scripts/link-vmlinux.sh | 6 ++++++ 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index d3c4ab249e9c..3b0d0db322b9 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1016,7 +1016,9 @@ config HAVE_STACK_VALIDATION bool help Architecture supports the 'objtool check' host tool command, which - performs compile-time stack metadata validation. + performs compile-time stack metadata validation. Or, on architectures + that use DWARF validated frame pointers, it supports the + 'objtool dwarf generate' host tool command. config HAVE_RELIABLE_STACKTRACE bool diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index c4207cf9bb17..c82a3a93297f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -220,6 +220,8 @@ config ARM64 select SWIOTLB select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK + select HAVE_STACK_VALIDATION if DWARF_FP + select STACK_VALIDATION if HAVE_STACK_VALIDATION select HAVE_ARCH_USERFAULTFD_MINOR if USERFAULTFD select TRACE_IRQFLAGS_SUPPORT help diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index 265c4461031f..585967062a1c 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -20,4 +20,9 @@ config ARM64_RELOC_TEST depends on m tristate "Relocation testing module" +config DWARF_FP + def_bool y + depends on FRAME_POINTER + depends on DEBUG_INFO_DWARF4 + source "drivers/hwtracing/coresight/Kconfig" diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index f2e2b9bdd702..a59c448f442a 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -1233,3 +1233,4 @@ CONFIG_DEBUG_KERNEL=y # CONFIG_DEBUG_PREEMPT is not set # CONFIG_FTRACE is not set CONFIG_MEMTEST=y +CONFIG_DEBUG_INFO_DWARF4=y diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 50bab186c49b..fb3b9970453b 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -122,6 +122,25 @@ jiffies = jiffies_64; #define TRAMP_TEXT #endif +#ifdef CONFIG_DWARF_FP +#define DWARF_RULES \ + . = ALIGN(8); \ + .dwarf_rules : { \ + __dwarf_rules_start = .; \ + KEEP(*(.dwarf_rules)) \ + __dwarf_rules_end = .; \ + } + +#define DWARF_PCS \ + . = ALIGN(8); \ + __dwarf_pcs_start = .; \ + KEEP(*(.dwarf_pcs)) \ + __dwarf_pcs_end = .; +#else +#define DWARF_RULES +#define DWARF_PCS +#endif + /* * The size of the PE/COFF section that covers the kernel image, which * runs from _stext to _edata, must be a round multiple of the PE/COFF @@ -239,6 +258,7 @@ SECTIONS CON_INITCALL INIT_RAM_FS *(.init.altinstructions .init.bss) /* from the EFI stub */ + DWARF_PCS } .exit.data : { EXIT_DATA @@ -291,6 +311,8 @@ SECTIONS __mmuoff_data_end = .; } + DWARF_RULES + PECOFF_EDATA_PADDING __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); _edata = .; diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 78656b527fe5..5e8d89c64572 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -227,6 +227,9 @@ ifdef CONFIG_STACK_VALIDATION objtool := $(objtree)/tools/objtool/objtool +ifdef CONFIG_DWARF_FP +objtool_args = dwarf generate +else objtool_args = \ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ $(if $(part-of-module), --module) \ @@ -235,6 +238,7 @@ objtool_args = \ $(if $(CONFIG_RETPOLINE), --retpoline) \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) +endif cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 5cdd9bc5c385..433e395f977b 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -104,6 +104,12 @@ objtool_link() local objtoolcmd; local objtoolopt; + if [ "${CONFIG_LTO_CLANG} ${CONFIG_DWARF_FP}" = "y y" ] + then + tools/objtool/objtool dwarf generate ${1} + return + fi + if [ "${CONFIG_LTO_CLANG} ${CONFIG_STACK_VALIDATION}" = "y y" ]; then # Don't perform vmlinux validation unless explicitly requested, # but run objtool on vmlinux.o now that we have an object file.