Commit 7984eaba authored by Tiezhu Yang's avatar Tiezhu Yang
Browse files

LoongArch: Add ORC stack unwinder support

mainline inclusion
from mainline-v6.9
commit cb8a2ef0848ca80d67d6d56e2df757cfdf6b3355
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IB3IRE

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cb8a2ef0848ca80d67d6d56e2df757cfdf6b3355



---------------------------------------------------------------------------

The kernel CONFIG_UNWINDER_ORC option enables the ORC unwinder, which is
similar in concept to a DWARF unwinder. The difference is that the format
of the ORC data is much simpler than DWARF, which in turn allows the ORC
unwinder to be much simpler and faster.

The ORC data consists of unwind tables which are generated by objtool.
After analyzing all the code paths of a .o file, it determines information
about the stack state at each instruction address in the file and outputs
that information to the .orc_unwind and .orc_unwind_ip sections.

The per-object ORC sections are combined at link time and are sorted and
post-processed at boot time. The unwinder uses the resulting data to
correlate instruction addresses with their stack states at run time.

Most of the logic are similar with x86, in order to get ra info before ra
is saved into stack, add ra_reg and ra_offset into orc_entry. At the same
time, modify some arch-specific code to silence the objtool warnings.

Co-developed-by: default avatarJinyang He <hejinyang@loongson.cn>
Signed-off-by: default avatarJinyang He <hejinyang@loongson.cn>
Co-developed-by: default avatarYouling Tang <tangyouling@loongson.cn>
Signed-off-by: default avatarYouling Tang <tangyouling@loongson.cn>
Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
parent 8c6f1e77
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ config LOONGARCH
	select HAVE_KVM
	select HAVE_MOD_ARCH_SPECIFIC
	select HAVE_NMI
	select HAVE_OBJTOOL if AS_HAS_EXPLICIT_RELOCS
	select HAVE_PCI
	select HAVE_PERF_EVENTS
	select HAVE_PERF_REGS
@@ -147,6 +148,7 @@ config LOONGARCH
	select HAVE_SAMPLE_FTRACE_DIRECT
	select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
	select HAVE_SETUP_PER_CPU_AREA if NUMA
	select HAVE_STACK_VALIDATION if HAVE_OBJTOOL
	select HAVE_STACKPROTECTOR
	select ARCH_HAS_PHYS_TO_DMA
	select HAVE_SYSCALL_TRACEPOINTS
+11 −0
Original line number Diff line number Diff line
@@ -26,4 +26,15 @@ config UNWINDER_PROLOGUE
	  Some of the addresses it reports may be incorrect (but better than the
	  Guess unwinder).

config UNWINDER_ORC
	bool "ORC unwinder"
	select OBJTOOL
	help
	  This option enables the ORC (Oops Rewind Capability) unwinder for
	  unwinding kernel stack traces.  It uses a custom data format which is
	  a simplified version of the DWARF Call Frame Information standard.

	  Enabling this option will increase the kernel's runtime memory usage
	  by roughly 2-4MB, depending on your kernel config.

endchoice
+21 −2
Original line number Diff line number Diff line
@@ -25,6 +25,18 @@ endif
32bit-emul		= elf32loongarch
64bit-emul		= elf64loongarch

ifdef CONFIG_UNWINDER_ORC
orc_hash_h := arch/$(SRCARCH)/include/generated/asm/orc_hash.h
orc_hash_sh := $(srctree)/scripts/orc_hash.sh
targets += $(orc_hash_h)
quiet_cmd_orc_hash = GEN     $@
      cmd_orc_hash = mkdir -p $(dir $@); \
		     $(CONFIG_SHELL) $(orc_hash_sh) < $< > $@
$(orc_hash_h): $(srctree)/arch/loongarch/include/asm/orc_types.h $(orc_hash_sh) FORCE
	$(call if_changed,orc_hash)
archprepare: $(orc_hash_h)
endif

ifdef CONFIG_DYNAMIC_FTRACE
KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
CC_FLAGS_FTRACE := -fpatchable-function-entry=2
@@ -68,8 +80,6 @@ LDFLAGS_vmlinux += -static -n -nostdlib
ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
cflags-y			+= $(call cc-option,-mexplicit-relocs)
KBUILD_CFLAGS_KERNEL		+= $(call cc-option,-mdirect-extern-access)
KBUILD_AFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
KBUILD_CFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
else
cflags-y			+= $(call cc-option,-mno-explicit-relocs)
KBUILD_AFLAGS_KERNEL		+= -Wa,-mla-global-with-pcrel
@@ -78,6 +88,15 @@ KBUILD_AFLAGS_MODULE += -Wa,-mla-global-with-abs
KBUILD_CFLAGS_MODULE		+= -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
endif

KBUILD_AFLAGS			+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
KBUILD_CFLAGS			+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
KBUILD_AFLAGS			+= $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
KBUILD_CFLAGS			+= $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)

ifdef CONFIG_OBJTOOL
KBUILD_CFLAGS			+= -fno-jump-tables
endif

ifeq ($(CONFIG_RELOCATABLE),y)
KBUILD_CFLAGS_KERNEL		+= -fPIE
LDFLAGS_vmlinux			+= -static -pie --no-dynamic-linker -z notext $(call ld-option, --apply-dynamic-relocs)
+2 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
generated-y += orc_hash.h

generic-y += dma-contiguous.h
generic-y += mcs_spinlock.h
generic-y += parport.h
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
do {								\
	instrumentation_begin();				\
	__BUG_FLAGS(BUGFLAG_WARNING|(flags));			\
	annotate_reachable();					\
	instrumentation_end();					\
} while (0)

Loading