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 [thread overview]
Message-ID: <20220407202518.19780-4-madvenka@linux.microsoft.com> (raw)
In-Reply-To: <20220407202518.19780-1-madvenka@linux.microsoft.com>
From: "Madhavan T. Venkataraman" <madvenka@linux.microsoft.com>
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 <object-file>
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 <madvenka@linux.microsoft.com>
---
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.
--
2.25.1
next prev parent reply other threads:[~2022-04-07 20:38 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <95691cae4f4504f33d0fc9075541b1e7deefe96f>
2022-01-17 14:55 ` [PATCH v13 00/11] arm64: Reorganize the unwinder and implement stack trace reliability checks madvenka
2022-01-17 14:55 ` [PATCH v13 01/11] arm64: Remove NULL task check from unwind_frame() madvenka
2022-01-17 14:55 ` [PATCH v13 02/11] arm64: Rename unwinder functions madvenka
2022-01-17 14:56 ` [PATCH v13 03/11] arm64: Rename stackframe to unwind_state madvenka
2022-01-17 14:56 ` [PATCH v13 04/11] arm64: Split unwind_init() madvenka
2022-02-02 18:44 ` Mark Brown
2022-02-03 0:26 ` Madhavan T. Venkataraman
2022-02-03 0:39 ` Madhavan T. Venkataraman
2022-02-03 11:29 ` Mark Brown
2022-02-15 13:07 ` Mark Rutland
2022-02-15 18:04 ` Madhavan T. Venkataraman
2022-01-17 14:56 ` [PATCH v13 05/11] arm64: Copy the task argument to unwind_state madvenka
2022-02-02 18:45 ` Mark Brown
2022-02-15 13:22 ` Mark Rutland
2022-02-22 16:53 ` Madhavan T. Venkataraman
2022-01-17 14:56 ` [PATCH v13 06/11] arm64: Use stack_trace_consume_fn and rename args to unwind() madvenka
2022-02-02 18:46 ` Mark Brown
2022-02-03 0:34 ` Madhavan T. Venkataraman
2022-02-03 11:30 ` Mark Brown
2022-02-03 14:45 ` Madhavan T. Venkataraman
2022-02-15 13:39 ` Mark Rutland
2022-02-15 18:12 ` Madhavan T. Venkataraman
2022-03-07 16:51 ` Madhavan T. Venkataraman
2022-03-07 17:01 ` Mark Brown
2022-03-08 22:00 ` Madhavan T. Venkataraman
2022-03-09 11:47 ` Mark Brown
2022-03-09 15:34 ` Madhavan T. Venkataraman
2022-03-10 8:33 ` Miroslav Benes
2022-03-10 12:36 ` Madhavan T. Venkataraman
2022-03-16 3:43 ` Josh Poimboeuf
2022-04-08 14:44 ` Mark Rutland
2022-04-08 17:58 ` Mark Rutland
2022-04-10 17:42 ` Madhavan T. Venkataraman
2022-04-10 17:33 ` Madhavan T. Venkataraman
2022-04-10 17:45 ` Madhavan T. Venkataraman
2022-01-17 14:56 ` [PATCH v13 07/11] arm64: Make the unwind loop in unwind() similar to other architectures madvenka
2022-01-17 14:56 ` [PATCH v13 08/11] arm64: Introduce stack trace reliability checks in the unwinder madvenka
2022-01-17 14:56 ` [PATCH v13 09/11] arm64: Create a list of SYM_CODE functions, check return PC against list madvenka
2022-01-17 14:56 ` [PATCH v13 10/11] arm64: Introduce arch_stack_walk_reliable() madvenka
2022-01-17 14:56 ` [PATCH v13 11/11] arm64: Select HAVE_RELIABLE_STACKTRACE madvenka
2022-01-25 5:21 ` nobuta.keiya
2022-01-25 13:43 ` Madhavan T. Venkataraman
2022-01-26 10:20 ` nobuta.keiya
2022-01-26 17:14 ` Madhavan T. Venkataraman
2022-01-27 1:13 ` nobuta.keiya
2022-01-26 17:16 ` Mark Brown
2022-04-07 20:25 ` [RFC PATCH v1 0/9] arm64: livepatch: Use DWARF Call Frame Information for frame pointer validation madvenka
2022-04-07 20:25 ` [RFC PATCH v1 1/9] objtool: Parse DWARF Call Frame Information in object files madvenka
2022-04-07 20:25 ` [RFC PATCH v1 2/9] objtool: Generate DWARF rules and place them in a special section madvenka
2022-04-07 20:25 ` madvenka [this message]
2022-04-07 20:25 ` [RFC PATCH v1 4/9] dwarf: Implement DWARF rule processing in the kernel madvenka
2022-04-07 20:25 ` [RFC PATCH v1 5/9] dwarf: Implement DWARF support for modules madvenka
2022-04-07 20:25 ` [RFC PATCH v1 6/9] arm64: unwinder: Add a reliability check in the unwinder based on DWARF CFI madvenka
2022-04-07 20:25 ` [RFC PATCH v1 7/9] arm64: dwarf: Implement unwind hints madvenka
2022-04-07 20:25 ` [RFC PATCH v1 8/9] dwarf: Miscellaneous changes required for enabling livepatch madvenka
2022-04-07 20:25 ` [RFC PATCH v1 9/9] dwarf: Enable livepatch for ARM64 madvenka
2022-04-08 0:21 ` [RFC PATCH v1 0/9] arm64: livepatch: Use DWARF Call Frame Information for frame pointer validation Josh Poimboeuf
2022-04-08 11:41 ` Peter Zijlstra
2022-04-11 17:26 ` Madhavan T. Venkataraman
2022-04-11 17:18 ` Madhavan T. Venkataraman
2022-04-12 8:32 ` Chen Zhongjin
2022-04-16 0:56 ` Josh Poimboeuf
2022-04-18 12:28 ` Chen Zhongjin
2022-04-18 16:11 ` Josh Poimboeuf
2022-04-18 18:38 ` Madhavan T. Venkataraman
[not found] ` <844b3ede-eddb-cbe6-80e0-3529e2da2eb6@huawei.com>
2022-04-12 17:27 ` Madhavan T. Venkataraman
2022-04-16 1:07 ` Josh Poimboeuf
2022-04-14 14:11 ` Madhavan T. Venkataraman
2022-04-08 10:55 ` Peter Zijlstra
2022-04-08 11:54 ` Peter Zijlstra
2022-04-08 14:34 ` Josh Poimboeuf
2022-04-10 17:47 ` Madhavan T. Venkataraman
2022-04-11 16:34 ` Josh Poimboeuf
2022-04-08 12:06 ` Peter Zijlstra
2022-04-11 17:35 ` Madhavan T. Venkataraman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220407202518.19780-4-madvenka@linux.microsoft.com \
--to=madvenka@linux.microsoft.com \
--cc=ardb@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=jmorris@namei.org \
--cc=jpoimboe@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=nobuta.keiya@fujitsu.com \
--cc=sjitindarsingh@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).