Commit a272858a authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Catalin Marinas

extable: add support for relative extables to search and sort routines

This adds support to the generic search_extable() and sort_extable()
implementations for dealing with exception table entries whose fields
contain relative offsets rather than absolute addresses.
Acked-by: default avatarHelge Deller <deller@gmx.de>
Acked-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Acked-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
Acked-by: default avatarTony Luck <tony.luck@intel.com>
Acked-by: default avatarWill Deacon <will.deacon@arm.com>
Acked-by: default avatarRichard Henderson <rth@twiddle.net>
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 7b957b6e
...@@ -14,7 +14,37 @@ ...@@ -14,7 +14,37 @@
#include <linux/sort.h> #include <linux/sort.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#ifndef ARCH_HAS_RELATIVE_EXTABLE
#define ex_to_insn(x) ((x)->insn)
#else
static inline unsigned long ex_to_insn(const struct exception_table_entry *x)
{
return (unsigned long)&x->insn + x->insn;
}
#endif
#ifndef ARCH_HAS_SORT_EXTABLE #ifndef ARCH_HAS_SORT_EXTABLE
#ifndef ARCH_HAS_RELATIVE_EXTABLE
#define swap_ex NULL
#else
static void swap_ex(void *a, void *b, int size)
{
struct exception_table_entry *x = a, *y = b, tmp;
int delta = b - a;
tmp = *x;
x->insn = y->insn + delta;
y->insn = tmp.insn - delta;
#ifdef swap_ex_entry_fixup
swap_ex_entry_fixup(x, y, tmp, delta);
#else
x->fixup = y->fixup + delta;
y->fixup = tmp.fixup - delta;
#endif
}
#endif /* ARCH_HAS_RELATIVE_EXTABLE */
/* /*
* The exception table needs to be sorted so that the binary * The exception table needs to be sorted so that the binary
* search that we use to find entries in it works properly. * search that we use to find entries in it works properly.
...@@ -26,9 +56,9 @@ static int cmp_ex(const void *a, const void *b) ...@@ -26,9 +56,9 @@ static int cmp_ex(const void *a, const void *b)
const struct exception_table_entry *x = a, *y = b; const struct exception_table_entry *x = a, *y = b;
/* avoid overflow */ /* avoid overflow */
if (x->insn > y->insn) if (ex_to_insn(x) > ex_to_insn(y))
return 1; return 1;
if (x->insn < y->insn) if (ex_to_insn(x) < ex_to_insn(y))
return -1; return -1;
return 0; return 0;
} }
...@@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start, ...@@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start,
struct exception_table_entry *finish) struct exception_table_entry *finish)
{ {
sort(start, finish - start, sizeof(struct exception_table_entry), sort(start, finish - start, sizeof(struct exception_table_entry),
cmp_ex, NULL); cmp_ex, swap_ex);
} }
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
...@@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start, ...@@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start,
void trim_init_extable(struct module *m) void trim_init_extable(struct module *m)
{ {
/*trim the beginning*/ /*trim the beginning*/
while (m->num_exentries && within_module_init(m->extable[0].insn, m)) { while (m->num_exentries &&
within_module_init(ex_to_insn(&m->extable[0]), m)) {
m->extable++; m->extable++;
m->num_exentries--; m->num_exentries--;
} }
/*trim the end*/ /*trim the end*/
while (m->num_exentries && while (m->num_exentries &&
within_module_init(m->extable[m->num_exentries-1].insn, m)) within_module_init(ex_to_insn(&m->extable[m->num_exentries - 1]),
m))
m->num_exentries--; m->num_exentries--;
} }
#endif /* CONFIG_MODULES */ #endif /* CONFIG_MODULES */
...@@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first, ...@@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first,
* careful, the distance between value and insn * careful, the distance between value and insn
* can be larger than MAX_LONG: * can be larger than MAX_LONG:
*/ */
if (mid->insn < value) if (ex_to_insn(mid) < value)
first = mid + 1; first = mid + 1;
else if (mid->insn > value) else if (ex_to_insn(mid) > value)
last = mid - 1; last = mid - 1;
else else
return mid; return mid;
} }
return NULL; return NULL;
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment