[PATCH 1/4] extable: add __sort_main_extable

From: Huang Shijie
Date: Wed Nov 22 2023 - 04:29:48 EST


The AmpereOne chip(arm64) may change the kernel exception table at
boot time, so it needs to sort the kernel extable table during
the kernel boot.

Introduce __sort_main_extable which is used to sort the kernel
exception table.

Signed-off-by: Huang Shijie <shijie@xxxxxxxxxxxxxxxxxxxxxx>
---
include/linux/extable.h | 2 ++
kernel/extable.c | 8 +++++++-
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/linux/extable.h b/include/linux/extable.h
index 4ab9e78f313b..ef70ec3633b0 100644
--- a/include/linux/extable.h
+++ b/include/linux/extable.h
@@ -15,6 +15,8 @@ search_extable(const struct exception_table_entry *base,
void sort_extable(struct exception_table_entry *start,
struct exception_table_entry *finish);
void sort_main_extable(void);
+void __sort_main_extable(void);
+
void trim_init_extable(struct module *m);

/* Given an address, look for it in the exception tables */
diff --git a/kernel/extable.c b/kernel/extable.c
index 71f482581cab..0fbe0ccb1c3a 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -32,13 +32,19 @@ extern struct exception_table_entry __stop___ex_table[];
/* Cleared by build time tools if the table is already sorted. */
u32 __initdata __visible main_extable_sort_needed = 1;

+void __sort_main_extable(void)
+{
+ if (&__stop___ex_table > &__start___ex_table)
+ sort_extable(__start___ex_table, __stop___ex_table);
+}
+
/* Sort the kernel's built-in exception table */
void __init sort_main_extable(void)
{
if (main_extable_sort_needed &&
&__stop___ex_table > &__start___ex_table) {
pr_notice("Sorting __ex_table...\n");
- sort_extable(__start___ex_table, __stop___ex_table);
+ __sort_main_extable();
}
}

--
2.40.1