Skip to contentSkip to conversation

ARM: module: Add all unwind tables when load module

PATCH New Chen Zhongjin 1 participant 1 message May 20, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 ARM: module: Add all unwind tables when load module

For EABI stack unwinding, when loading .ko module the EXIDX sections will be added to a unwind_table list.

However not all EXIDX sections are added because EXIDX sections are searched by hardcoded section names.

For functions in other sections such as .ref.text or .kprobes.text, gcc generates seprated EXIDX sections (such as .ARM.exidx.ref.text or .ARM.exidx.kprobes.text).

These extra EXIDX sections are not loaded, so when unwinding functions in these sections, we will failed with:

unwind: Index not found xxx

To fix that, I refactor the code for searching and adding EXIDX sections:

- Check section type to search EXIDX tables (0x70000001) instead of strcmp() the hardcoded names. Then find the corresponding text sections by their section names.

- Add a unwind_table list in module->arch to save their own unwind_table instead of the fixed-lenth array.

- Save .ARM.exidx.init.text section ptr, because it should be cleaned after module init.

Now all EXIDX sections of .ko can be added correctly.

---
Changes v4 -> v5:
- replace "unwind_table" with "list_head" in "mod_arch_specific" because only the "list_head" is used.
- make check of "sh_flags" & "sh_type" in advance so that it won't run "find_mod_section" for all sections.
- clear "mod_arch_specific.init_table" in "module_arch_cleanup"

Changes v3 -> v4:
- Fix indent by replace tab with code.

Changes v2 -> v3:
- Unwind "txtname" and add some blank, to make code more clear.

Changes v1 -> v2:
- Rename "table_list" to "unwind_list" for consistency.
- Drop unnecessary locals variable "txtname" and "sectype".
- Merge condition checks for sh_flags and sh_type.

---
 arch/arm/include/asm/module.h | 17 ++------
 arch/arm/include/asm/unwind.h |  1 +
 arch/arm/kernel/module.c      | 78 ++++++++++++++++++-----------------
 3 files changed, 45 insertions(+), 51 deletions(-)
arch/arm/include/asm/module.h +4 -13
index cfffae67c04e..5546c9751478 100644
@@ -3,20 +3,10 @@
 #define _ASM_ARM_MODULE_H
 
 #include <asm-generic/module.h>
-
-struct unwind_table;
+#include <asm/unwind.h>
 
 #ifdef CONFIG_ARM_UNWIND
-enum {
-	ARM_SEC_INIT,
-	ARM_SEC_DEVINIT,
-	ARM_SEC_CORE,
-	ARM_SEC_EXIT,
-	ARM_SEC_DEVEXIT,
-	ARM_SEC_HOT,
-	ARM_SEC_UNLIKELY,
-	ARM_SEC_MAX,
-};
+#define ELF_SECTION_UNWIND 0x70000001
 #endif
 
 #define PLT_ENT_STRIDE		L1_CACHE_BYTES
@@ -36,7 +26,8 @@ struct mod_plt_sec {
 
 struct mod_arch_specific {
 #ifdef CONFIG_ARM_UNWIND
-	struct unwind_table *unwind[ARM_SEC_MAX];
+	struct list_head unwind_list;
+	struct unwind_table *init_table;
 #endif
 #ifdef CONFIG_ARM_MODULE_PLTS
 	struct mod_plt_sec	core;
arch/arm/include/asm/unwind.h +1 -0
index 0f8a3439902d..b51f85417f58 100644
@@ -24,6 +24,7 @@ struct unwind_idx {
 
 struct unwind_table {
 	struct list_head list;
+	struct list_head mod_list;
 	const struct unwind_idx *start;
 	const struct unwind_idx *origin;
 	const struct unwind_idx *stop;
arch/arm/kernel/module.c +40 -38

105 lines not on this page · raw message

Signature · 1 line
2.17.1