All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] generic relative extable support
@ 2016-01-03 16:05 ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

There are currently four architectures (x86, ia64, alpha and s390) whose
user-access exception tables are relative to the table entry address rather
than absolute. Each of these architectures has its own search_extable() and
sort_extable() implementation, which are not only mostly identical to each
other, but also deviate very little from the generic absolute implementations
in lib/extable.c that they override.

So before making arm64 the fifth architecture that reimplements this, let's
refactor the existing code so that all of these architectures use common code
for searching and sorting the relative extables. Archs may set
ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
special treatment in the swapping step of the sorting routine (such as alpha).

Note that the s390 patch applies on top of the following patch:

  http://article.gmane.org/gmane.linux.kernel/2117036

which fixes a bug I spotted while working on this code. Since that probably
needs to go to -stable, I broke it out and posted it separately.

Ard Biesheuvel (6):
  extable: add support for relative extables to search and sort routines
  alpha/extable: use generic search and sort routines
  s390/extable: use generic search and sort routines
  x86/extable: use generic search and sort routines
  ia64/extable: use generic search and sort routines
  arm64: switch to relative exception tables

 arch/alpha/include/asm/uaccess.h     |  10 +-
 arch/alpha/mm/Makefile               |   2 +-
 arch/alpha/mm/extable.c              |  92 -----------------
 arch/arm64/include/asm/assembler.h   |   2 +-
 arch/arm64/include/asm/futex.h       |   4 +-
 arch/arm64/include/asm/uaccess.h     |  18 ++--
 arch/arm64/kernel/armv8_deprecated.c |   4 +-
 arch/arm64/mm/extable.c              |   2 +-
 arch/ia64/include/asm/uaccess.h      |   8 +-
 arch/ia64/mm/extable.c               |  97 +-----------------
 arch/s390/include/asm/uaccess.h      |   8 +-
 arch/s390/mm/Makefile                |   2 +-
 arch/s390/mm/extable.c               |  85 ----------------
 arch/x86/include/asm/uaccess.h       |   5 +-
 arch/x86/mm/extable.c                | 106 +-------------------
 lib/extable.c                        |  50 +++++++--
 scripts/sortextable.c                |   2 +-
 17 files changed, 77 insertions(+), 420 deletions(-)
 delete mode 100644 arch/alpha/mm/extable.c
 delete mode 100644 arch/s390/mm/extable.c

-- 
1.9.1


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 0/6] generic relative extable support
@ 2016-01-03 16:05 ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-arm-kernel

There are currently four architectures (x86, ia64, alpha and s390) whose
user-access exception tables are relative to the table entry address rather
than absolute. Each of these architectures has its own search_extable() and
sort_extable() implementation, which are not only mostly identical to each
other, but also deviate very little from the generic absolute implementations
in lib/extable.c that they override.

So before making arm64 the fifth architecture that reimplements this, let's
refactor the existing code so that all of these architectures use common code
for searching and sorting the relative extables. Archs may set
ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
special treatment in the swapping step of the sorting routine (such as alpha).

Note that the s390 patch applies on top of the following patch:

  http://article.gmane.org/gmane.linux.kernel/2117036

which fixes a bug I spotted while working on this code. Since that probably
needs to go to -stable, I broke it out and posted it separately.

Ard Biesheuvel (6):
  extable: add support for relative extables to search and sort routines
  alpha/extable: use generic search and sort routines
  s390/extable: use generic search and sort routines
  x86/extable: use generic search and sort routines
  ia64/extable: use generic search and sort routines
  arm64: switch to relative exception tables

 arch/alpha/include/asm/uaccess.h     |  10 +-
 arch/alpha/mm/Makefile               |   2 +-
 arch/alpha/mm/extable.c              |  92 -----------------
 arch/arm64/include/asm/assembler.h   |   2 +-
 arch/arm64/include/asm/futex.h       |   4 +-
 arch/arm64/include/asm/uaccess.h     |  18 ++--
 arch/arm64/kernel/armv8_deprecated.c |   4 +-
 arch/arm64/mm/extable.c              |   2 +-
 arch/ia64/include/asm/uaccess.h      |   8 +-
 arch/ia64/mm/extable.c               |  97 +-----------------
 arch/s390/include/asm/uaccess.h      |   8 +-
 arch/s390/mm/Makefile                |   2 +-
 arch/s390/mm/extable.c               |  85 ----------------
 arch/x86/include/asm/uaccess.h       |   5 +-
 arch/x86/mm/extable.c                | 106 +-------------------
 lib/extable.c                        |  50 +++++++--
 scripts/sortextable.c                |   2 +-
 17 files changed, 77 insertions(+), 420 deletions(-)
 delete mode 100644 arch/alpha/mm/extable.c
 delete mode 100644 arch/s390/mm/extable.c

-- 
1.9.1

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 0/6] generic relative extable support
@ 2016-01-03 16:05 ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

There are currently four architectures (x86, ia64, alpha and s390) whose
user-access exception tables are relative to the table entry address rather
than absolute. Each of these architectures has its own search_extable() and
sort_extable() implementation, which are not only mostly identical to each
other, but also deviate very little from the generic absolute implementations
in lib/extable.c that they override.

So before making arm64 the fifth architecture that reimplements this, let's
refactor the existing code so that all of these architectures use common code
for searching and sorting the relative extables. Archs may set
ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
special treatment in the swapping step of the sorting routine (such as alpha).

Note that the s390 patch applies on top of the following patch:

  http://article.gmane.org/gmane.linux.kernel/2117036

which fixes a bug I spotted while working on this code. Since that probably
needs to go to -stable, I broke it out and posted it separately.

Ard Biesheuvel (6):
  extable: add support for relative extables to search and sort routines
  alpha/extable: use generic search and sort routines
  s390/extable: use generic search and sort routines
  x86/extable: use generic search and sort routines
  ia64/extable: use generic search and sort routines
  arm64: switch to relative exception tables

 arch/alpha/include/asm/uaccess.h     |  10 +-
 arch/alpha/mm/Makefile               |   2 +-
 arch/alpha/mm/extable.c              |  92 -----------------
 arch/arm64/include/asm/assembler.h   |   2 +-
 arch/arm64/include/asm/futex.h       |   4 +-
 arch/arm64/include/asm/uaccess.h     |  18 ++--
 arch/arm64/kernel/armv8_deprecated.c |   4 +-
 arch/arm64/mm/extable.c              |   2 +-
 arch/ia64/include/asm/uaccess.h      |   8 +-
 arch/ia64/mm/extable.c               |  97 +-----------------
 arch/s390/include/asm/uaccess.h      |   8 +-
 arch/s390/mm/Makefile                |   2 +-
 arch/s390/mm/extable.c               |  85 ----------------
 arch/x86/include/asm/uaccess.h       |   5 +-
 arch/x86/mm/extable.c                | 106 +-------------------
 lib/extable.c                        |  50 +++++++--
 scripts/sortextable.c                |   2 +-
 17 files changed, 77 insertions(+), 420 deletions(-)
 delete mode 100644 arch/alpha/mm/extable.c
 delete mode 100644 arch/s390/mm/extable.c

-- 
1.9.1


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 1/6] extable: add support for relative extables to search and sort routines
  2016-01-03 16:05 ` Ard Biesheuvel
  (?)
@ 2016-01-03 16:05   ` Ard Biesheuvel
  -1 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

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.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 lib/extable.c | 50 ++++++++++++++++----
 1 file changed, 41 insertions(+), 9 deletions(-)

diff --git a/lib/extable.c b/lib/extable.c
index 4cac81ec225e..0be02ad561e9 100644
--- a/lib/extable.c
+++ b/lib/extable.c
@@ -14,7 +14,37 @@
 #include <linux/sort.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_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
  * 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)
 	const struct exception_table_entry *x = a, *y = b;
 
 	/* avoid overflow */
-	if (x->insn > y->insn)
+	if (ex_to_insn(x) > ex_to_insn(y))
 		return 1;
-	if (x->insn < y->insn)
+	if (ex_to_insn(x) < ex_to_insn(y))
 		return -1;
 	return 0;
 }
@@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start,
 		  struct exception_table_entry *finish)
 {
 	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, NULL);
+	     cmp_ex, swap_ex);
 }
 
 #ifdef CONFIG_MODULES
@@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start,
 void trim_init_extable(struct module *m)
 {
 	/*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->num_exentries--;
 	}
 	/*trim the end*/
 	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--;
 }
 #endif /* CONFIG_MODULES */
@@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first,
 		 * careful, the distance between value and insn
 		 * can be larger than MAX_LONG:
 		 */
-		if (mid->insn < value)
+		if (ex_to_insn(mid) < value)
 			first = mid + 1;
-		else if (mid->insn > value)
+		else if (ex_to_insn(mid) > value)
 			last = mid - 1;
 		else
 			return mid;
-        }
-        return NULL;
+	}
+	return NULL;
 }
 #endif
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 1/6] extable: add support for relative extables to search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 lib/extable.c | 50 ++++++++++++++++----
 1 file changed, 41 insertions(+), 9 deletions(-)

diff --git a/lib/extable.c b/lib/extable.c
index 4cac81ec225e..0be02ad561e9 100644
--- a/lib/extable.c
+++ b/lib/extable.c
@@ -14,7 +14,37 @@
 #include <linux/sort.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_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
  * 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)
 	const struct exception_table_entry *x = a, *y = b;
 
 	/* avoid overflow */
-	if (x->insn > y->insn)
+	if (ex_to_insn(x) > ex_to_insn(y))
 		return 1;
-	if (x->insn < y->insn)
+	if (ex_to_insn(x) < ex_to_insn(y))
 		return -1;
 	return 0;
 }
@@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start,
 		  struct exception_table_entry *finish)
 {
 	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, NULL);
+	     cmp_ex, swap_ex);
 }
 
 #ifdef CONFIG_MODULES
@@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start,
 void trim_init_extable(struct module *m)
 {
 	/*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->num_exentries--;
 	}
 	/*trim the end*/
 	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--;
 }
 #endif /* CONFIG_MODULES */
@@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first,
 		 * careful, the distance between value and insn
 		 * can be larger than MAX_LONG:
 		 */
-		if (mid->insn < value)
+		if (ex_to_insn(mid) < value)
 			first = mid + 1;
-		else if (mid->insn > value)
+		else if (ex_to_insn(mid) > value)
 			last = mid - 1;
 		else
 			return mid;
-        }
-        return NULL;
+	}
+	return NULL;
 }
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 1/6] extable: add support for relative extables to search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

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.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 lib/extable.c | 50 ++++++++++++++++----
 1 file changed, 41 insertions(+), 9 deletions(-)

diff --git a/lib/extable.c b/lib/extable.c
index 4cac81ec225e..0be02ad561e9 100644
--- a/lib/extable.c
+++ b/lib/extable.c
@@ -14,7 +14,37 @@
 #include <linux/sort.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_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
  * 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)
 	const struct exception_table_entry *x = a, *y = b;
 
 	/* avoid overflow */
-	if (x->insn > y->insn)
+	if (ex_to_insn(x) > ex_to_insn(y))
 		return 1;
-	if (x->insn < y->insn)
+	if (ex_to_insn(x) < ex_to_insn(y))
 		return -1;
 	return 0;
 }
@@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start,
 		  struct exception_table_entry *finish)
 {
 	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, NULL);
+	     cmp_ex, swap_ex);
 }
 
 #ifdef CONFIG_MODULES
@@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start,
 void trim_init_extable(struct module *m)
 {
 	/*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->num_exentries--;
 	}
 	/*trim the end*/
 	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--;
 }
 #endif /* CONFIG_MODULES */
@@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first,
 		 * careful, the distance between value and insn
 		 * can be larger than MAX_LONG:
 		 */
-		if (mid->insn < value)
+		if (ex_to_insn(mid) < value)
 			first = mid + 1;
-		else if (mid->insn > value)
+		else if (ex_to_insn(mid) > value)
 			last = mid - 1;
 		else
 			return mid;
-        }
-        return NULL;
+	}
+	return NULL;
 }
 #endif
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 2/6] alpha/extable: use generic search and sort routines
  2016-01-03 16:05 ` Ard Biesheuvel
  (?)
@ 2016-01-03 16:05   ` Ard Biesheuvel
  -1 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/alpha/include/asm/uaccess.h | 10 ++-
 arch/alpha/mm/Makefile           |  2 +-
 arch/alpha/mm/extable.c          | 92 --------------------
 3 files changed, 9 insertions(+), 95 deletions(-)

diff --git a/arch/alpha/include/asm/uaccess.h b/arch/alpha/include/asm/uaccess.h
index 9b0d40093c9a..c419b43c461d 100644
--- a/arch/alpha/include/asm/uaccess.h
+++ b/arch/alpha/include/asm/uaccess.h
@@ -483,7 +483,13 @@ struct exception_table_entry
 	(pc) + (_fixup)->fixup.bits.nextinsn;			\
 })
 
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
+
+#define swap_ex_entry_fixup(a, b, tmp, delta)			\
+	do {							\
+		(a)->fixup.unit = (b)->fixup.unit;		\
+		(b)->fixup.unit = (tmp).fixup.unit;		\
+	} while (0)
+
 
 #endif /* __ALPHA_UACCESS_H */
diff --git a/arch/alpha/mm/Makefile b/arch/alpha/mm/Makefile
index c993d3f93cf6..5a9807936411 100644
--- a/arch/alpha/mm/Makefile
+++ b/arch/alpha/mm/Makefile
@@ -4,6 +4,6 @@
 
 ccflags-y := -Werror
 
-obj-y	:= init.o fault.o extable.o
+obj-y	:= init.o fault.o
 
 obj-$(CONFIG_DISCONTIGMEM) += numa.o
diff --git a/arch/alpha/mm/extable.c b/arch/alpha/mm/extable.c
deleted file mode 100644
index 813c9b63c0e1..000000000000
--- a/arch/alpha/mm/extable.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * linux/arch/alpha/mm/extable.c
- */
-
-#include <linux/module.h>
-#include <linux/sort.h>
-#include <asm/uaccess.h>
-
-static inline unsigned long ex_to_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-
-static void swap_ex(void *a, void *b, int size)
-{
-	struct exception_table_entry *ex_a = a, *ex_b = b;
-	unsigned long addr_a = ex_to_addr(ex_a), addr_b = ex_to_addr(ex_b);
-	unsigned int t = ex_a->fixup.unit;
-
-	ex_a->fixup.unit = ex_b->fixup.unit;
-	ex_b->fixup.unit = t;
-	ex_a->insn = (int)(addr_b - (unsigned long)&ex_a->insn);
-	ex_b->insn = (int)(addr_a - (unsigned long)&ex_b->insn);
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/* avoid overflow */
-	if (ex_to_addr(x) > ex_to_addr(y))
-		return 1;
-	if (ex_to_addr(x) < ex_to_addr(y))
-		return -1;
-	return 0;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, swap_ex);
-}
-
-#ifdef CONFIG_MODULES
-/*
- * Any entry referring to the module init will be at the beginning or
- * the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[m->num_exentries-1]),
-				  m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-        while (first <= last) {
-		const struct exception_table_entry *mid;
-		unsigned long mid_value;
-
-		mid = (last - first) / 2 + first;
-		mid_value = ex_to_addr(mid);
-                if (mid_value == value)
-                        return mid;
-                else if (mid_value < value)
-                        first = mid+1;
-                else
-                        last = mid-1;
-        }
-
-        return NULL;
-}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 2/6] alpha/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-arm-kernel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/alpha/include/asm/uaccess.h | 10 ++-
 arch/alpha/mm/Makefile           |  2 +-
 arch/alpha/mm/extable.c          | 92 --------------------
 3 files changed, 9 insertions(+), 95 deletions(-)

diff --git a/arch/alpha/include/asm/uaccess.h b/arch/alpha/include/asm/uaccess.h
index 9b0d40093c9a..c419b43c461d 100644
--- a/arch/alpha/include/asm/uaccess.h
+++ b/arch/alpha/include/asm/uaccess.h
@@ -483,7 +483,13 @@ struct exception_table_entry
 	(pc) + (_fixup)->fixup.bits.nextinsn;			\
 })
 
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
+
+#define swap_ex_entry_fixup(a, b, tmp, delta)			\
+	do {							\
+		(a)->fixup.unit = (b)->fixup.unit;		\
+		(b)->fixup.unit = (tmp).fixup.unit;		\
+	} while (0)
+
 
 #endif /* __ALPHA_UACCESS_H */
diff --git a/arch/alpha/mm/Makefile b/arch/alpha/mm/Makefile
index c993d3f93cf6..5a9807936411 100644
--- a/arch/alpha/mm/Makefile
+++ b/arch/alpha/mm/Makefile
@@ -4,6 +4,6 @@
 
 ccflags-y := -Werror
 
-obj-y	:= init.o fault.o extable.o
+obj-y	:= init.o fault.o
 
 obj-$(CONFIG_DISCONTIGMEM) += numa.o
diff --git a/arch/alpha/mm/extable.c b/arch/alpha/mm/extable.c
deleted file mode 100644
index 813c9b63c0e1..000000000000
--- a/arch/alpha/mm/extable.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * linux/arch/alpha/mm/extable.c
- */
-
-#include <linux/module.h>
-#include <linux/sort.h>
-#include <asm/uaccess.h>
-
-static inline unsigned long ex_to_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-
-static void swap_ex(void *a, void *b, int size)
-{
-	struct exception_table_entry *ex_a = a, *ex_b = b;
-	unsigned long addr_a = ex_to_addr(ex_a), addr_b = ex_to_addr(ex_b);
-	unsigned int t = ex_a->fixup.unit;
-
-	ex_a->fixup.unit = ex_b->fixup.unit;
-	ex_b->fixup.unit = t;
-	ex_a->insn = (int)(addr_b - (unsigned long)&ex_a->insn);
-	ex_b->insn = (int)(addr_a - (unsigned long)&ex_b->insn);
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/* avoid overflow */
-	if (ex_to_addr(x) > ex_to_addr(y))
-		return 1;
-	if (ex_to_addr(x) < ex_to_addr(y))
-		return -1;
-	return 0;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, swap_ex);
-}
-
-#ifdef CONFIG_MODULES
-/*
- * Any entry referring to the module init will be@the beginning or
- * the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[m->num_exentries-1]),
-				  m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-        while (first <= last) {
-		const struct exception_table_entry *mid;
-		unsigned long mid_value;
-
-		mid = (last - first) / 2 + first;
-		mid_value = ex_to_addr(mid);
-                if (mid_value == value)
-                        return mid;
-                else if (mid_value < value)
-                        first = mid+1;
-                else
-                        last = mid-1;
-        }
-
-        return NULL;
-}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 2/6] alpha/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/alpha/include/asm/uaccess.h | 10 ++-
 arch/alpha/mm/Makefile           |  2 +-
 arch/alpha/mm/extable.c          | 92 --------------------
 3 files changed, 9 insertions(+), 95 deletions(-)

diff --git a/arch/alpha/include/asm/uaccess.h b/arch/alpha/include/asm/uaccess.h
index 9b0d40093c9a..c419b43c461d 100644
--- a/arch/alpha/include/asm/uaccess.h
+++ b/arch/alpha/include/asm/uaccess.h
@@ -483,7 +483,13 @@ struct exception_table_entry
 	(pc) + (_fixup)->fixup.bits.nextinsn;			\
 })
 
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
+
+#define swap_ex_entry_fixup(a, b, tmp, delta)			\
+	do {							\
+		(a)->fixup.unit = (b)->fixup.unit;		\
+		(b)->fixup.unit = (tmp).fixup.unit;		\
+	} while (0)
+
 
 #endif /* __ALPHA_UACCESS_H */
diff --git a/arch/alpha/mm/Makefile b/arch/alpha/mm/Makefile
index c993d3f93cf6..5a9807936411 100644
--- a/arch/alpha/mm/Makefile
+++ b/arch/alpha/mm/Makefile
@@ -4,6 +4,6 @@
 
 ccflags-y := -Werror
 
-obj-y	:= init.o fault.o extable.o
+obj-y	:= init.o fault.o
 
 obj-$(CONFIG_DISCONTIGMEM) += numa.o
diff --git a/arch/alpha/mm/extable.c b/arch/alpha/mm/extable.c
deleted file mode 100644
index 813c9b63c0e1..000000000000
--- a/arch/alpha/mm/extable.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * linux/arch/alpha/mm/extable.c
- */
-
-#include <linux/module.h>
-#include <linux/sort.h>
-#include <asm/uaccess.h>
-
-static inline unsigned long ex_to_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-
-static void swap_ex(void *a, void *b, int size)
-{
-	struct exception_table_entry *ex_a = a, *ex_b = b;
-	unsigned long addr_a = ex_to_addr(ex_a), addr_b = ex_to_addr(ex_b);
-	unsigned int t = ex_a->fixup.unit;
-
-	ex_a->fixup.unit = ex_b->fixup.unit;
-	ex_b->fixup.unit = t;
-	ex_a->insn = (int)(addr_b - (unsigned long)&ex_a->insn);
-	ex_b->insn = (int)(addr_a - (unsigned long)&ex_b->insn);
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/* avoid overflow */
-	if (ex_to_addr(x) > ex_to_addr(y))
-		return 1;
-	if (ex_to_addr(x) < ex_to_addr(y))
-		return -1;
-	return 0;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, swap_ex);
-}
-
-#ifdef CONFIG_MODULES
-/*
- * Any entry referring to the module init will be at the beginning or
- * the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[m->num_exentries-1]),
-				  m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-        while (first <= last) {
-		const struct exception_table_entry *mid;
-		unsigned long mid_value;
-
-		mid = (last - first) / 2 + first;
-		mid_value = ex_to_addr(mid);
-                if (mid_value = value)
-                        return mid;
-                else if (mid_value < value)
-                        first = mid+1;
-                else
-                        last = mid-1;
-        }
-
-        return NULL;
-}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 3/6] s390/extable: use generic search and sort routines
  2016-01-03 16:05 ` Ard Biesheuvel
  (?)
@ 2016-01-03 16:05   ` Ard Biesheuvel
  -1 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/s390/include/asm/uaccess.h |  8 +-
 arch/s390/mm/Makefile           |  2 +-
 arch/s390/mm/extable.c          | 85 --------------------
 3 files changed, 2 insertions(+), 93 deletions(-)

diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
index 9dd4cc47ddc7..e0900ddf91dd 100644
--- a/arch/s390/include/asm/uaccess.h
+++ b/arch/s390/include/asm/uaccess.h
@@ -79,18 +79,12 @@ struct exception_table_entry
 	int insn, fixup;
 };
 
-static inline unsigned long extable_insn(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-
 static inline unsigned long extable_fixup(const struct exception_table_entry *x)
 {
 	return (unsigned long)&x->fixup + x->fixup;
 }
 
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 /**
  * __copy_from_user: - Copy a block of data from user space, with less checking.
diff --git a/arch/s390/mm/Makefile b/arch/s390/mm/Makefile
index 839592ca265c..479550dae80e 100644
--- a/arch/s390/mm/Makefile
+++ b/arch/s390/mm/Makefile
@@ -3,7 +3,7 @@
 #
 
 obj-y		:= init.o fault.o extmem.o mmap.o vmem.o pgtable.o maccess.o
-obj-y		+= page-states.o gup.o extable.o pageattr.o mem_detect.o
+obj-y		+= page-states.o gup.o pageattr.o mem_detect.o
 
 obj-$(CONFIG_CMM)		+= cmm.o
 obj-$(CONFIG_HUGETLB_PAGE)	+= hugetlbpage.o
diff --git a/arch/s390/mm/extable.c b/arch/s390/mm/extable.c
deleted file mode 100644
index 18c8b819b0aa..000000000000
--- a/arch/s390/mm/extable.c
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <linux/module.h>
-#include <linux/sort.h>
-#include <asm/uaccess.h>
-
-/*
- * Search one exception table for an entry corresponding to the
- * given instruction address, and return the address of the entry,
- * or NULL if none is found.
- * We use a binary search, and thus we assume that the table is
- * already sorted.
- */
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-	const struct exception_table_entry *mid;
-	unsigned long addr;
-
-	while (first <= last) {
-		mid = ((last - first) >> 1) + first;
-		addr = extable_insn(mid);
-		if (addr < value)
-			first = mid + 1;
-		else if (addr > value)
-			last = mid - 1;
-		else
-			return mid;
-	}
-	return NULL;
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- *
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/* This compare is only valid after normalization. */
-	return x->insn - y->insn;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	struct exception_table_entry *p;
-	int i;
-
-	/* Normalize entries to being relative to the start of the section */
-	for (p = start, i = 0; p < finish; p++, i += 8) {
-		p->insn += i;
-		p->fixup += i + 4;
-	}
-	sort(start, finish - start, sizeof(*start), cmp_ex, NULL);
-	/* Denormalize all entries */
-	for (p = start, i = 0; p < finish; p++, i += 8) {
-		p->insn -= i;
-		p->fixup -= i + 4;
-	}
-}
-
-#ifdef CONFIG_MODULES
-/*
- * If the exception table is sorted, any referring to the module init
- * will be at the beginning or the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/* Trim the beginning */
-	while (m->num_exentries &&
-	       within_module_init(extable_insn(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/* Trim the end */
-	while (m->num_exentries &&
-	       within_module_init(extable_insn(&m->extable[m->num_exentries-1]), m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 3/6] s390/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-arm-kernel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/s390/include/asm/uaccess.h |  8 +-
 arch/s390/mm/Makefile           |  2 +-
 arch/s390/mm/extable.c          | 85 --------------------
 3 files changed, 2 insertions(+), 93 deletions(-)

diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
index 9dd4cc47ddc7..e0900ddf91dd 100644
--- a/arch/s390/include/asm/uaccess.h
+++ b/arch/s390/include/asm/uaccess.h
@@ -79,18 +79,12 @@ struct exception_table_entry
 	int insn, fixup;
 };
 
-static inline unsigned long extable_insn(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-
 static inline unsigned long extable_fixup(const struct exception_table_entry *x)
 {
 	return (unsigned long)&x->fixup + x->fixup;
 }
 
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 /**
  * __copy_from_user: - Copy a block of data from user space, with less checking.
diff --git a/arch/s390/mm/Makefile b/arch/s390/mm/Makefile
index 839592ca265c..479550dae80e 100644
--- a/arch/s390/mm/Makefile
+++ b/arch/s390/mm/Makefile
@@ -3,7 +3,7 @@
 #
 
 obj-y		:= init.o fault.o extmem.o mmap.o vmem.o pgtable.o maccess.o
-obj-y		+= page-states.o gup.o extable.o pageattr.o mem_detect.o
+obj-y		+= page-states.o gup.o pageattr.o mem_detect.o
 
 obj-$(CONFIG_CMM)		+= cmm.o
 obj-$(CONFIG_HUGETLB_PAGE)	+= hugetlbpage.o
diff --git a/arch/s390/mm/extable.c b/arch/s390/mm/extable.c
deleted file mode 100644
index 18c8b819b0aa..000000000000
--- a/arch/s390/mm/extable.c
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <linux/module.h>
-#include <linux/sort.h>
-#include <asm/uaccess.h>
-
-/*
- * Search one exception table for an entry corresponding to the
- * given instruction address, and return the address of the entry,
- * or NULL if none is found.
- * We use a binary search, and thus we assume that the table is
- * already sorted.
- */
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-	const struct exception_table_entry *mid;
-	unsigned long addr;
-
-	while (first <= last) {
-		mid = ((last - first) >> 1) + first;
-		addr = extable_insn(mid);
-		if (addr < value)
-			first = mid + 1;
-		else if (addr > value)
-			last = mid - 1;
-		else
-			return mid;
-	}
-	return NULL;
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- *
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/* This compare is only valid after normalization. */
-	return x->insn - y->insn;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	struct exception_table_entry *p;
-	int i;
-
-	/* Normalize entries to being relative to the start of the section */
-	for (p = start, i = 0; p < finish; p++, i += 8) {
-		p->insn += i;
-		p->fixup += i + 4;
-	}
-	sort(start, finish - start, sizeof(*start), cmp_ex, NULL);
-	/* Denormalize all entries */
-	for (p = start, i = 0; p < finish; p++, i += 8) {
-		p->insn -= i;
-		p->fixup -= i + 4;
-	}
-}
-
-#ifdef CONFIG_MODULES
-/*
- * If the exception table is sorted, any referring to the module init
- * will be at the beginning or the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/* Trim the beginning */
-	while (m->num_exentries &&
-	       within_module_init(extable_insn(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/* Trim the end */
-	while (m->num_exentries &&
-	       within_module_init(extable_insn(&m->extable[m->num_exentries-1]), m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 3/6] s390/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/s390/include/asm/uaccess.h |  8 +-
 arch/s390/mm/Makefile           |  2 +-
 arch/s390/mm/extable.c          | 85 --------------------
 3 files changed, 2 insertions(+), 93 deletions(-)

diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
index 9dd4cc47ddc7..e0900ddf91dd 100644
--- a/arch/s390/include/asm/uaccess.h
+++ b/arch/s390/include/asm/uaccess.h
@@ -79,18 +79,12 @@ struct exception_table_entry
 	int insn, fixup;
 };
 
-static inline unsigned long extable_insn(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-
 static inline unsigned long extable_fixup(const struct exception_table_entry *x)
 {
 	return (unsigned long)&x->fixup + x->fixup;
 }
 
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 /**
  * __copy_from_user: - Copy a block of data from user space, with less checking.
diff --git a/arch/s390/mm/Makefile b/arch/s390/mm/Makefile
index 839592ca265c..479550dae80e 100644
--- a/arch/s390/mm/Makefile
+++ b/arch/s390/mm/Makefile
@@ -3,7 +3,7 @@
 #
 
 obj-y		:= init.o fault.o extmem.o mmap.o vmem.o pgtable.o maccess.o
-obj-y		+= page-states.o gup.o extable.o pageattr.o mem_detect.o
+obj-y		+= page-states.o gup.o pageattr.o mem_detect.o
 
 obj-$(CONFIG_CMM)		+= cmm.o
 obj-$(CONFIG_HUGETLB_PAGE)	+= hugetlbpage.o
diff --git a/arch/s390/mm/extable.c b/arch/s390/mm/extable.c
deleted file mode 100644
index 18c8b819b0aa..000000000000
--- a/arch/s390/mm/extable.c
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <linux/module.h>
-#include <linux/sort.h>
-#include <asm/uaccess.h>
-
-/*
- * Search one exception table for an entry corresponding to the
- * given instruction address, and return the address of the entry,
- * or NULL if none is found.
- * We use a binary search, and thus we assume that the table is
- * already sorted.
- */
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-	const struct exception_table_entry *mid;
-	unsigned long addr;
-
-	while (first <= last) {
-		mid = ((last - first) >> 1) + first;
-		addr = extable_insn(mid);
-		if (addr < value)
-			first = mid + 1;
-		else if (addr > value)
-			last = mid - 1;
-		else
-			return mid;
-	}
-	return NULL;
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- *
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/* This compare is only valid after normalization. */
-	return x->insn - y->insn;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	struct exception_table_entry *p;
-	int i;
-
-	/* Normalize entries to being relative to the start of the section */
-	for (p = start, i = 0; p < finish; p++, i += 8) {
-		p->insn += i;
-		p->fixup += i + 4;
-	}
-	sort(start, finish - start, sizeof(*start), cmp_ex, NULL);
-	/* Denormalize all entries */
-	for (p = start, i = 0; p < finish; p++, i += 8) {
-		p->insn -= i;
-		p->fixup -= i + 4;
-	}
-}
-
-#ifdef CONFIG_MODULES
-/*
- * If the exception table is sorted, any referring to the module init
- * will be at the beginning or the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/* Trim the beginning */
-	while (m->num_exentries &&
-	       within_module_init(extable_insn(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/* Trim the end */
-	while (m->num_exentries &&
-	       within_module_init(extable_insn(&m->extable[m->num_exentries-1]), m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 4/6] x86/extable: use generic search and sort routines
  2016-01-03 16:05 ` Ard Biesheuvel
  (?)
@ 2016-01-03 16:05   ` Ard Biesheuvel
  -1 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/include/asm/uaccess.h |   5 +-
 arch/x86/mm/extable.c          | 106 +-------------------
 2 files changed, 4 insertions(+), 107 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 09b1b0ab94b7..6d130c4cb7de 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -106,9 +106,8 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
 struct exception_table_entry {
 	int insn, fixup;
 };
-/* This is not the generic standard exception_table_entry format */
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 extern int fixup_exception(struct pt_regs *regs);
 extern int early_fixup_exception(unsigned long *ip);
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 903ec1e9c326..0b172b656f43 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,14 +1,9 @@
+
 #include <linux/module.h>
-#include <linux/spinlock.h>
-#include <linux/sort.h>
+
 #include <asm/uaccess.h>
 
 static inline unsigned long
-ex_insn_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-static inline unsigned long
 ex_fixup_addr(const struct exception_table_entry *x)
 {
 	return (unsigned long)&x->fixup + x->fixup;
@@ -70,100 +65,3 @@ int __init early_fixup_exception(unsigned long *ip)
 
 	return 0;
 }
-
-/*
- * Search one exception table for an entry corresponding to the
- * given instruction address, and return the address of the entry,
- * or NULL if none is found.
- * We use a binary search, and thus we assume that the table is
- * already sorted.
- */
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-	while (first <= last) {
-		const struct exception_table_entry *mid;
-		unsigned long addr;
-
-		mid = ((last - first) >> 1) + first;
-		addr = ex_insn_addr(mid);
-		if (addr < value)
-			first = mid + 1;
-		else if (addr > value)
-			last = mid - 1;
-		else
-			return mid;
-        }
-        return NULL;
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- *
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/*
-	 * This value will always end up fittin in an int, because on
-	 * both i386 and x86-64 the kernel symbol-reachable address
-	 * space is < 2 GiB.
-	 *
-	 * This compare is only valid after normalization.
-	 */
-	return x->insn - y->insn;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	struct exception_table_entry *p;
-	int i;
-
-	/* Convert all entries to being relative to the start of the section */
-	i = 0;
-	for (p = start; p < finish; p++) {
-		p->insn += i;
-		i += 4;
-		p->fixup += i;
-		i += 4;
-	}
-
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, NULL);
-
-	/* Denormalize all entries */
-	i = 0;
-	for (p = start; p < finish; p++) {
-		p->insn -= i;
-		i += 4;
-		p->fixup -= i;
-		i += 4;
-	}
-}
-
-#ifdef CONFIG_MODULES
-/*
- * If the exception table is sorted, any referring to the module init
- * will be at the beginning or the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_insn_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_insn_addr(&m->extable[m->num_exentries-1]), m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 4/6] x86/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-arm-kernel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/include/asm/uaccess.h |   5 +-
 arch/x86/mm/extable.c          | 106 +-------------------
 2 files changed, 4 insertions(+), 107 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 09b1b0ab94b7..6d130c4cb7de 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -106,9 +106,8 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
 struct exception_table_entry {
 	int insn, fixup;
 };
-/* This is not the generic standard exception_table_entry format */
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 extern int fixup_exception(struct pt_regs *regs);
 extern int early_fixup_exception(unsigned long *ip);
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 903ec1e9c326..0b172b656f43 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,14 +1,9 @@
+
 #include <linux/module.h>
-#include <linux/spinlock.h>
-#include <linux/sort.h>
+
 #include <asm/uaccess.h>
 
 static inline unsigned long
-ex_insn_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-static inline unsigned long
 ex_fixup_addr(const struct exception_table_entry *x)
 {
 	return (unsigned long)&x->fixup + x->fixup;
@@ -70,100 +65,3 @@ int __init early_fixup_exception(unsigned long *ip)
 
 	return 0;
 }
-
-/*
- * Search one exception table for an entry corresponding to the
- * given instruction address, and return the address of the entry,
- * or NULL if none is found.
- * We use a binary search, and thus we assume that the table is
- * already sorted.
- */
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-	while (first <= last) {
-		const struct exception_table_entry *mid;
-		unsigned long addr;
-
-		mid = ((last - first) >> 1) + first;
-		addr = ex_insn_addr(mid);
-		if (addr < value)
-			first = mid + 1;
-		else if (addr > value)
-			last = mid - 1;
-		else
-			return mid;
-        }
-        return NULL;
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- *
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/*
-	 * This value will always end up fittin in an int, because on
-	 * both i386 and x86-64 the kernel symbol-reachable address
-	 * space is < 2 GiB.
-	 *
-	 * This compare is only valid after normalization.
-	 */
-	return x->insn - y->insn;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	struct exception_table_entry *p;
-	int i;
-
-	/* Convert all entries to being relative to the start of the section */
-	i = 0;
-	for (p = start; p < finish; p++) {
-		p->insn += i;
-		i += 4;
-		p->fixup += i;
-		i += 4;
-	}
-
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, NULL);
-
-	/* Denormalize all entries */
-	i = 0;
-	for (p = start; p < finish; p++) {
-		p->insn -= i;
-		i += 4;
-		p->fixup -= i;
-		i += 4;
-	}
-}
-
-#ifdef CONFIG_MODULES
-/*
- * If the exception table is sorted, any referring to the module init
- * will be at the beginning or the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_insn_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_insn_addr(&m->extable[m->num_exentries-1]), m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 4/6] x86/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/include/asm/uaccess.h |   5 +-
 arch/x86/mm/extable.c          | 106 +-------------------
 2 files changed, 4 insertions(+), 107 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 09b1b0ab94b7..6d130c4cb7de 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -106,9 +106,8 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
 struct exception_table_entry {
 	int insn, fixup;
 };
-/* This is not the generic standard exception_table_entry format */
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 extern int fixup_exception(struct pt_regs *regs);
 extern int early_fixup_exception(unsigned long *ip);
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 903ec1e9c326..0b172b656f43 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,14 +1,9 @@
+
 #include <linux/module.h>
-#include <linux/spinlock.h>
-#include <linux/sort.h>
+
 #include <asm/uaccess.h>
 
 static inline unsigned long
-ex_insn_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->insn + x->insn;
-}
-static inline unsigned long
 ex_fixup_addr(const struct exception_table_entry *x)
 {
 	return (unsigned long)&x->fixup + x->fixup;
@@ -70,100 +65,3 @@ int __init early_fixup_exception(unsigned long *ip)
 
 	return 0;
 }
-
-/*
- * Search one exception table for an entry corresponding to the
- * given instruction address, and return the address of the entry,
- * or NULL if none is found.
- * We use a binary search, and thus we assume that the table is
- * already sorted.
- */
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-	       const struct exception_table_entry *last,
-	       unsigned long value)
-{
-	while (first <= last) {
-		const struct exception_table_entry *mid;
-		unsigned long addr;
-
-		mid = ((last - first) >> 1) + first;
-		addr = ex_insn_addr(mid);
-		if (addr < value)
-			first = mid + 1;
-		else if (addr > value)
-			last = mid - 1;
-		else
-			return mid;
-        }
-        return NULL;
-}
-
-/*
- * The exception table needs to be sorted so that the binary
- * search that we use to find entries in it works properly.
- * This is used both for the kernel exception table and for
- * the exception tables of modules that get loaded.
- *
- */
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *x = a, *y = b;
-
-	/*
-	 * This value will always end up fittin in an int, because on
-	 * both i386 and x86-64 the kernel symbol-reachable address
-	 * space is < 2 GiB.
-	 *
-	 * This compare is only valid after normalization.
-	 */
-	return x->insn - y->insn;
-}
-
-void sort_extable(struct exception_table_entry *start,
-		  struct exception_table_entry *finish)
-{
-	struct exception_table_entry *p;
-	int i;
-
-	/* Convert all entries to being relative to the start of the section */
-	i = 0;
-	for (p = start; p < finish; p++) {
-		p->insn += i;
-		i += 4;
-		p->fixup += i;
-		i += 4;
-	}
-
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, NULL);
-
-	/* Denormalize all entries */
-	i = 0;
-	for (p = start; p < finish; p++) {
-		p->insn -= i;
-		i += 4;
-		p->fixup -= i;
-		i += 4;
-	}
-}
-
-#ifdef CONFIG_MODULES
-/*
- * If the exception table is sorted, any referring to the module init
- * will be at the beginning or the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_insn_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_insn_addr(&m->extable[m->num_exentries-1]), m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 5/6] ia64/extable: use generic search and sort routines
  2016-01-03 16:05 ` Ard Biesheuvel
  (?)
@ 2016-01-03 16:05   ` Ard Biesheuvel
  -1 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/ia64/include/asm/uaccess.h |  8 +-
 arch/ia64/mm/extable.c          | 97 +-------------------
 2 files changed, 4 insertions(+), 101 deletions(-)

diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
index 4f3fb6ccbf21..2189d5ddc1ee 100644
--- a/arch/ia64/include/asm/uaccess.h
+++ b/arch/ia64/include/asm/uaccess.h
@@ -341,13 +341,11 @@ extern unsigned long __strnlen_user (const char __user *, long);
 	__su_ret;						\
 })
 
-/* Generic code can't deal with the location-relative format that we use for compactness.  */
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 struct exception_table_entry {
-	int addr;	/* location-relative address of insn this fixup is for */
-	int cont;	/* location-relative continuation addr.; if bit 2 is set, r9 is set to 0 */
+	int insn;	/* location-relative address of insn this fixup is for */
+	int fixup;	/* location-relative continuation addr.; if bit 2 is set, r9 is set to 0 */
 };
 
 extern void ia64_handle_exception (struct pt_regs *regs, const struct exception_table_entry *e);
diff --git a/arch/ia64/mm/extable.c b/arch/ia64/mm/extable.c
index c99a41e29fe8..8f70bb2d0c37 100644
--- a/arch/ia64/mm/extable.c
+++ b/arch/ia64/mm/extable.c
@@ -5,107 +5,12 @@
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  */
 
-#include <linux/sort.h>
-
 #include <asm/uaccess.h>
-#include <linux/module.h>
-
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *l = a, *r = b;
-	u64 lip = (u64) &l->addr + l->addr;
-	u64 rip = (u64) &r->addr + r->addr;
-
-	/* avoid overflow */
-	if (lip > rip)
-		return 1;
-	if (lip < rip)
-		return -1;
-	return 0;
-}
-
-static void swap_ex(void *a, void *b, int size)
-{
-	struct exception_table_entry *l = a, *r = b, tmp;
-	u64 delta = (u64) r - (u64) l;
-
-	tmp = *l;
-	l->addr = r->addr + delta;
-	l->cont = r->cont + delta;
-	r->addr = tmp.addr - delta;
-	r->cont = tmp.cont - delta;
-}
-
-/*
- * Sort the exception table. It's usually already sorted, but there
- * may be unordered entries due to multiple text sections (such as the
- * .init text section). Note that the exception-table-entries contain
- * location-relative addresses, which requires a bit of care during
- * sorting to avoid overflows in the offset members (e.g., it would
- * not be safe to make a temporary copy of an exception-table entry on
- * the stack, because the stack may be more than 2GB away from the
- * exception-table).
- */
-void sort_extable (struct exception_table_entry *start,
-		   struct exception_table_entry *finish)
-{
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, swap_ex);
-}
-
-static inline unsigned long ex_to_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->addr + x->addr;
-}
-
-#ifdef CONFIG_MODULES
-/*
- * Any entry referring to the module init will be at the beginning or
- * the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[m->num_exentries-1]),
-				  m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-
-const struct exception_table_entry *
-search_extable (const struct exception_table_entry *first,
-		const struct exception_table_entry *last,
-		unsigned long ip)
-{
-	const struct exception_table_entry *mid;
-	unsigned long mid_ip;
-	long diff;
-
-        while (first <= last) {
-		mid = &first[(last - first)/2];
-		mid_ip = (u64) &mid->addr + mid->addr;
-		diff = mid_ip - ip;
-                if (diff == 0)
-                        return mid;
-                else if (diff < 0)
-                        first = mid + 1;
-                else
-                        last = mid - 1;
-        }
-        return NULL;
-}
 
 void
 ia64_handle_exception (struct pt_regs *regs, const struct exception_table_entry *e)
 {
-	long fix = (u64) &e->cont + e->cont;
+	long fix = (u64) &e->fixup + e->fixup;
 
 	regs->r8 = -EFAULT;
 	if (fix & 4)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 5/6] ia64/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-arm-kernel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/ia64/include/asm/uaccess.h |  8 +-
 arch/ia64/mm/extable.c          | 97 +-------------------
 2 files changed, 4 insertions(+), 101 deletions(-)

diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
index 4f3fb6ccbf21..2189d5ddc1ee 100644
--- a/arch/ia64/include/asm/uaccess.h
+++ b/arch/ia64/include/asm/uaccess.h
@@ -341,13 +341,11 @@ extern unsigned long __strnlen_user (const char __user *, long);
 	__su_ret;						\
 })
 
-/* Generic code can't deal with the location-relative format that we use for compactness.  */
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 struct exception_table_entry {
-	int addr;	/* location-relative address of insn this fixup is for */
-	int cont;	/* location-relative continuation addr.; if bit 2 is set, r9 is set to 0 */
+	int insn;	/* location-relative address of insn this fixup is for */
+	int fixup;	/* location-relative continuation addr.; if bit 2 is set, r9 is set to 0 */
 };
 
 extern void ia64_handle_exception (struct pt_regs *regs, const struct exception_table_entry *e);
diff --git a/arch/ia64/mm/extable.c b/arch/ia64/mm/extable.c
index c99a41e29fe8..8f70bb2d0c37 100644
--- a/arch/ia64/mm/extable.c
+++ b/arch/ia64/mm/extable.c
@@ -5,107 +5,12 @@
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  */
 
-#include <linux/sort.h>
-
 #include <asm/uaccess.h>
-#include <linux/module.h>
-
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *l = a, *r = b;
-	u64 lip = (u64) &l->addr + l->addr;
-	u64 rip = (u64) &r->addr + r->addr;
-
-	/* avoid overflow */
-	if (lip > rip)
-		return 1;
-	if (lip < rip)
-		return -1;
-	return 0;
-}
-
-static void swap_ex(void *a, void *b, int size)
-{
-	struct exception_table_entry *l = a, *r = b, tmp;
-	u64 delta = (u64) r - (u64) l;
-
-	tmp = *l;
-	l->addr = r->addr + delta;
-	l->cont = r->cont + delta;
-	r->addr = tmp.addr - delta;
-	r->cont = tmp.cont - delta;
-}
-
-/*
- * Sort the exception table. It's usually already sorted, but there
- * may be unordered entries due to multiple text sections (such as the
- * .init text section). Note that the exception-table-entries contain
- * location-relative addresses, which requires a bit of care during
- * sorting to avoid overflows in the offset members (e.g., it would
- * not be safe to make a temporary copy of an exception-table entry on
- * the stack, because the stack may be more than 2GB away from the
- * exception-table).
- */
-void sort_extable (struct exception_table_entry *start,
-		   struct exception_table_entry *finish)
-{
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, swap_ex);
-}
-
-static inline unsigned long ex_to_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->addr + x->addr;
-}
-
-#ifdef CONFIG_MODULES
-/*
- * Any entry referring to the module init will be at the beginning or
- * the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[m->num_exentries-1]),
-				  m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-
-const struct exception_table_entry *
-search_extable (const struct exception_table_entry *first,
-		const struct exception_table_entry *last,
-		unsigned long ip)
-{
-	const struct exception_table_entry *mid;
-	unsigned long mid_ip;
-	long diff;
-
-        while (first <= last) {
-		mid = &first[(last - first)/2];
-		mid_ip = (u64) &mid->addr + mid->addr;
-		diff = mid_ip - ip;
-                if (diff == 0)
-                        return mid;
-                else if (diff < 0)
-                        first = mid + 1;
-                else
-                        last = mid - 1;
-        }
-        return NULL;
-}
 
 void
 ia64_handle_exception (struct pt_regs *regs, const struct exception_table_entry *e)
 {
-	long fix = (u64) &e->cont + e->cont;
+	long fix = (u64) &e->fixup + e->fixup;
 
 	regs->r8 = -EFAULT;
 	if (fix & 4)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 5/6] ia64/extable: use generic search and sort routines
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Replace the arch specific versions of search_extable() and sort_extable()
with calls to the generic ones, which now support relative exception
tables as well.

Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/ia64/include/asm/uaccess.h |  8 +-
 arch/ia64/mm/extable.c          | 97 +-------------------
 2 files changed, 4 insertions(+), 101 deletions(-)

diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
index 4f3fb6ccbf21..2189d5ddc1ee 100644
--- a/arch/ia64/include/asm/uaccess.h
+++ b/arch/ia64/include/asm/uaccess.h
@@ -341,13 +341,11 @@ extern unsigned long __strnlen_user (const char __user *, long);
 	__su_ret;						\
 })
 
-/* Generic code can't deal with the location-relative format that we use for compactness.  */
-#define ARCH_HAS_SORT_EXTABLE
-#define ARCH_HAS_SEARCH_EXTABLE
+#define ARCH_HAS_RELATIVE_EXTABLE
 
 struct exception_table_entry {
-	int addr;	/* location-relative address of insn this fixup is for */
-	int cont;	/* location-relative continuation addr.; if bit 2 is set, r9 is set to 0 */
+	int insn;	/* location-relative address of insn this fixup is for */
+	int fixup;	/* location-relative continuation addr.; if bit 2 is set, r9 is set to 0 */
 };
 
 extern void ia64_handle_exception (struct pt_regs *regs, const struct exception_table_entry *e);
diff --git a/arch/ia64/mm/extable.c b/arch/ia64/mm/extable.c
index c99a41e29fe8..8f70bb2d0c37 100644
--- a/arch/ia64/mm/extable.c
+++ b/arch/ia64/mm/extable.c
@@ -5,107 +5,12 @@
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  */
 
-#include <linux/sort.h>
-
 #include <asm/uaccess.h>
-#include <linux/module.h>
-
-static int cmp_ex(const void *a, const void *b)
-{
-	const struct exception_table_entry *l = a, *r = b;
-	u64 lip = (u64) &l->addr + l->addr;
-	u64 rip = (u64) &r->addr + r->addr;
-
-	/* avoid overflow */
-	if (lip > rip)
-		return 1;
-	if (lip < rip)
-		return -1;
-	return 0;
-}
-
-static void swap_ex(void *a, void *b, int size)
-{
-	struct exception_table_entry *l = a, *r = b, tmp;
-	u64 delta = (u64) r - (u64) l;
-
-	tmp = *l;
-	l->addr = r->addr + delta;
-	l->cont = r->cont + delta;
-	r->addr = tmp.addr - delta;
-	r->cont = tmp.cont - delta;
-}
-
-/*
- * Sort the exception table. It's usually already sorted, but there
- * may be unordered entries due to multiple text sections (such as the
- * .init text section). Note that the exception-table-entries contain
- * location-relative addresses, which requires a bit of care during
- * sorting to avoid overflows in the offset members (e.g., it would
- * not be safe to make a temporary copy of an exception-table entry on
- * the stack, because the stack may be more than 2GB away from the
- * exception-table).
- */
-void sort_extable (struct exception_table_entry *start,
-		   struct exception_table_entry *finish)
-{
-	sort(start, finish - start, sizeof(struct exception_table_entry),
-	     cmp_ex, swap_ex);
-}
-
-static inline unsigned long ex_to_addr(const struct exception_table_entry *x)
-{
-	return (unsigned long)&x->addr + x->addr;
-}
-
-#ifdef CONFIG_MODULES
-/*
- * Any entry referring to the module init will be at the beginning or
- * the end.
- */
-void trim_init_extable(struct module *m)
-{
-	/*trim the beginning*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[0]), m)) {
-		m->extable++;
-		m->num_exentries--;
-	}
-	/*trim the end*/
-	while (m->num_exentries &&
-	       within_module_init(ex_to_addr(&m->extable[m->num_exentries-1]),
-				  m))
-		m->num_exentries--;
-}
-#endif /* CONFIG_MODULES */
-
-const struct exception_table_entry *
-search_extable (const struct exception_table_entry *first,
-		const struct exception_table_entry *last,
-		unsigned long ip)
-{
-	const struct exception_table_entry *mid;
-	unsigned long mid_ip;
-	long diff;
-
-        while (first <= last) {
-		mid = &first[(last - first)/2];
-		mid_ip = (u64) &mid->addr + mid->addr;
-		diff = mid_ip - ip;
-                if (diff = 0)
-                        return mid;
-                else if (diff < 0)
-                        first = mid + 1;
-                else
-                        last = mid - 1;
-        }
-        return NULL;
-}
 
 void
 ia64_handle_exception (struct pt_regs *regs, const struct exception_table_entry *e)
 {
-	long fix = (u64) &e->cont + e->cont;
+	long fix = (u64) &e->fixup + e->fixup;
 
 	regs->r8 = -EFAULT;
 	if (fix & 4)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-03 16:05 ` Ard Biesheuvel
  (?)
@ 2016-01-03 16:05   ` Ard Biesheuvel
  -1 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Instead of using absolute addresses for both the exception location
and the fixup, use offsets relative to the exception table entry values.
Not only does this cut the size of the exception table in half, it is
also a prerequisite for KASLR, since absolute exception table entries
are subject to dynamic relocation, which is incompatible with the sorting
of the exception table that occurs at build time.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---

Note that this patch supersedes the version I sent as part of the series that
implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531

 arch/arm64/include/asm/assembler.h   |  2 +-
 arch/arm64/include/asm/futex.h       |  4 ++--
 arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
 arch/arm64/kernel/armv8_deprecated.c |  4 ++--
 arch/arm64/mm/extable.c              |  2 +-
 scripts/sortextable.c                |  2 +-
 6 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index 12eff928ef8b..8094d50f05bc 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -98,7 +98,7 @@
 9999:	x;					\
 	.section __ex_table,"a";		\
 	.align	3;				\
-	.quad	9999b,l;			\
+	.long	(9999b - .), (l - .);		\
 	.previous
 
 /*
diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
index 007a69fc4f40..35e73e255ad3 100644
--- a/arch/arm64/include/asm/futex.h
+++ b/arch/arm64/include/asm/futex.h
@@ -44,7 +44,7 @@
 "	.popsection\n"							\
 "	.pushsection __ex_table,\"a\"\n"				\
 "	.align	3\n"							\
-"	.quad	1b, 4b, 2b, 4b\n"					\
+"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"		\
 "	.popsection\n"							\
 	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,		\
 		    CONFIG_ARM64_PAN)					\
@@ -135,7 +135,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 "	.popsection\n"
 "	.pushsection __ex_table,\"a\"\n"
 "	.align	3\n"
-"	.quad	1b, 4b, 2b, 4b\n"
+"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"
 "	.popsection\n"
 	: "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
 	: "r" (oldval), "r" (newval), "Ir" (-EFAULT)
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index b2ede967fe7d..ab627e6c06c9 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -36,11 +36,11 @@
 #define VERIFY_WRITE 1
 
 /*
- * The exception table consists of pairs of addresses: the first is the
- * address of an instruction that is allowed to fault, and the second is
- * the address at which the program should continue.  No registers are
- * modified, so it is entirely up to the continuation code to figure out
- * what to do.
+ * The exception table consists of pairs of relative offsets: the first
+ * is the relative offset to an instruction that is allowed to fault,
+ * and the second is the relative offset at which the program should
+ * continue. No registers are modified, so it is entirely up to the
+ * continuation code to figure out what to do.
  *
  * All the routines below use bits of fixup code that are out of line
  * with the main instruction path.  This means when everything is well,
@@ -50,9 +50,11 @@
 
 struct exception_table_entry
 {
-	unsigned long insn, fixup;
+	int insn, fixup;
 };
 
+#define ARCH_HAS_RELATIVE_EXTABLE
+
 extern int fixup_exception(struct pt_regs *regs);
 
 #define KERNEL_DS	(-1UL)
@@ -125,7 +127,7 @@ static inline void set_fs(mm_segment_t fs)
 	"	.previous\n"						\
 	"	.section __ex_table,\"a\"\n"				\
 	"	.align	3\n"						\
-	"	.quad	1b, 3b\n"					\
+	"	.long	(1b - .), (3b - .)\n"				\
 	"	.previous"						\
 	: "+r" (err), "=&r" (x)						\
 	: "r" (addr), "i" (-EFAULT))
@@ -192,7 +194,7 @@ do {									\
 	"	.previous\n"						\
 	"	.section __ex_table,\"a\"\n"				\
 	"	.align	3\n"						\
-	"	.quad	1b, 3b\n"					\
+	"	.long	(1b - .), (3b - .)\n"				\
 	"	.previous"						\
 	: "+r" (err)							\
 	: "r" (x), "r" (addr), "i" (-EFAULT))
diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
index 937f5e58a4d3..8f21b1363387 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -299,8 +299,8 @@ static void register_insn_emulation_sysctl(struct ctl_table *table)
 	"	.popsection"					\
 	"	.pushsection	 __ex_table,\"a\"\n"		\
 	"	.align		3\n"				\
-	"	.quad		0b, 4b\n"			\
-	"	.quad		1b, 4b\n"			\
+	"	.long		(0b - .), (4b - .)\n"		\
+	"	.long		(1b - .), (4b - .)\n"		\
 	"	.popsection\n"					\
 	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,	\
 		CONFIG_ARM64_PAN)				\
diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
index 79444279ba8c..81acd4706878 100644
--- a/arch/arm64/mm/extable.c
+++ b/arch/arm64/mm/extable.c
@@ -11,7 +11,7 @@ int fixup_exception(struct pt_regs *regs)
 
 	fixup = search_exception_tables(instruction_pointer(regs));
 	if (fixup)
-		regs->pc = fixup->fixup;
+		regs->pc = (unsigned long)&fixup->fixup + fixup->fixup;
 
 	return fixup != NULL;
 }
diff --git a/scripts/sortextable.c b/scripts/sortextable.c
index c2423d913b46..af247c70fb66 100644
--- a/scripts/sortextable.c
+++ b/scripts/sortextable.c
@@ -282,12 +282,12 @@ do_file(char const *const fname)
 	case EM_386:
 	case EM_X86_64:
 	case EM_S390:
+	case EM_AARCH64:
 		custom_sort = sort_relative_table;
 		break;
 	case EM_ARCOMPACT:
 	case EM_ARCV2:
 	case EM_ARM:
-	case EM_AARCH64:
 	case EM_MICROBLAZE:
 	case EM_MIPS:
 	case EM_XTENSA:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-arm-kernel

Instead of using absolute addresses for both the exception location
and the fixup, use offsets relative to the exception table entry values.
Not only does this cut the size of the exception table in half, it is
also a prerequisite for KASLR, since absolute exception table entries
are subject to dynamic relocation, which is incompatible with the sorting
of the exception table that occurs at build time.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---

Note that this patch supersedes the version I sent as part of the series that
implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531

 arch/arm64/include/asm/assembler.h   |  2 +-
 arch/arm64/include/asm/futex.h       |  4 ++--
 arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
 arch/arm64/kernel/armv8_deprecated.c |  4 ++--
 arch/arm64/mm/extable.c              |  2 +-
 scripts/sortextable.c                |  2 +-
 6 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index 12eff928ef8b..8094d50f05bc 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -98,7 +98,7 @@
 9999:	x;					\
 	.section __ex_table,"a";		\
 	.align	3;				\
-	.quad	9999b,l;			\
+	.long	(9999b - .), (l - .);		\
 	.previous
 
 /*
diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
index 007a69fc4f40..35e73e255ad3 100644
--- a/arch/arm64/include/asm/futex.h
+++ b/arch/arm64/include/asm/futex.h
@@ -44,7 +44,7 @@
 "	.popsection\n"							\
 "	.pushsection __ex_table,\"a\"\n"				\
 "	.align	3\n"							\
-"	.quad	1b, 4b, 2b, 4b\n"					\
+"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"		\
 "	.popsection\n"							\
 	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,		\
 		    CONFIG_ARM64_PAN)					\
@@ -135,7 +135,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 "	.popsection\n"
 "	.pushsection __ex_table,\"a\"\n"
 "	.align	3\n"
-"	.quad	1b, 4b, 2b, 4b\n"
+"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"
 "	.popsection\n"
 	: "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
 	: "r" (oldval), "r" (newval), "Ir" (-EFAULT)
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index b2ede967fe7d..ab627e6c06c9 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -36,11 +36,11 @@
 #define VERIFY_WRITE 1
 
 /*
- * The exception table consists of pairs of addresses: the first is the
- * address of an instruction that is allowed to fault, and the second is
- * the address at which the program should continue.  No registers are
- * modified, so it is entirely up to the continuation code to figure out
- * what to do.
+ * The exception table consists of pairs of relative offsets: the first
+ * is the relative offset to an instruction that is allowed to fault,
+ * and the second is the relative offset at which the program should
+ * continue. No registers are modified, so it is entirely up to the
+ * continuation code to figure out what to do.
  *
  * All the routines below use bits of fixup code that are out of line
  * with the main instruction path.  This means when everything is well,
@@ -50,9 +50,11 @@
 
 struct exception_table_entry
 {
-	unsigned long insn, fixup;
+	int insn, fixup;
 };
 
+#define ARCH_HAS_RELATIVE_EXTABLE
+
 extern int fixup_exception(struct pt_regs *regs);
 
 #define KERNEL_DS	(-1UL)
@@ -125,7 +127,7 @@ static inline void set_fs(mm_segment_t fs)
 	"	.previous\n"						\
 	"	.section __ex_table,\"a\"\n"				\
 	"	.align	3\n"						\
-	"	.quad	1b, 3b\n"					\
+	"	.long	(1b - .), (3b - .)\n"				\
 	"	.previous"						\
 	: "+r" (err), "=&r" (x)						\
 	: "r" (addr), "i" (-EFAULT))
@@ -192,7 +194,7 @@ do {									\
 	"	.previous\n"						\
 	"	.section __ex_table,\"a\"\n"				\
 	"	.align	3\n"						\
-	"	.quad	1b, 3b\n"					\
+	"	.long	(1b - .), (3b - .)\n"				\
 	"	.previous"						\
 	: "+r" (err)							\
 	: "r" (x), "r" (addr), "i" (-EFAULT))
diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
index 937f5e58a4d3..8f21b1363387 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -299,8 +299,8 @@ static void register_insn_emulation_sysctl(struct ctl_table *table)
 	"	.popsection"					\
 	"	.pushsection	 __ex_table,\"a\"\n"		\
 	"	.align		3\n"				\
-	"	.quad		0b, 4b\n"			\
-	"	.quad		1b, 4b\n"			\
+	"	.long		(0b - .), (4b - .)\n"		\
+	"	.long		(1b - .), (4b - .)\n"		\
 	"	.popsection\n"					\
 	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,	\
 		CONFIG_ARM64_PAN)				\
diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
index 79444279ba8c..81acd4706878 100644
--- a/arch/arm64/mm/extable.c
+++ b/arch/arm64/mm/extable.c
@@ -11,7 +11,7 @@ int fixup_exception(struct pt_regs *regs)
 
 	fixup = search_exception_tables(instruction_pointer(regs));
 	if (fixup)
-		regs->pc = fixup->fixup;
+		regs->pc = (unsigned long)&fixup->fixup + fixup->fixup;
 
 	return fixup != NULL;
 }
diff --git a/scripts/sortextable.c b/scripts/sortextable.c
index c2423d913b46..af247c70fb66 100644
--- a/scripts/sortextable.c
+++ b/scripts/sortextable.c
@@ -282,12 +282,12 @@ do_file(char const *const fname)
 	case EM_386:
 	case EM_X86_64:
 	case EM_S390:
+	case EM_AARCH64:
 		custom_sort = sort_relative_table;
 		break;
 	case EM_ARCOMPACT:
 	case EM_ARCV2:
 	case EM_ARM:
-	case EM_AARCH64:
 	case EM_MICROBLAZE:
 	case EM_MIPS:
 	case EM_XTENSA:
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-03 16:05   ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-03 16:05 UTC (permalink / raw)
  To: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas,
	will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier, Ard Biesheuvel

Instead of using absolute addresses for both the exception location
and the fixup, use offsets relative to the exception table entry values.
Not only does this cut the size of the exception table in half, it is
also a prerequisite for KASLR, since absolute exception table entries
are subject to dynamic relocation, which is incompatible with the sorting
of the exception table that occurs at build time.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---

Note that this patch supersedes the version I sent as part of the series that
implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531

 arch/arm64/include/asm/assembler.h   |  2 +-
 arch/arm64/include/asm/futex.h       |  4 ++--
 arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
 arch/arm64/kernel/armv8_deprecated.c |  4 ++--
 arch/arm64/mm/extable.c              |  2 +-
 scripts/sortextable.c                |  2 +-
 6 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index 12eff928ef8b..8094d50f05bc 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -98,7 +98,7 @@
 9999:	x;					\
 	.section __ex_table,"a";		\
 	.align	3;				\
-	.quad	9999b,l;			\
+	.long	(9999b - .), (l - .);		\
 	.previous
 
 /*
diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
index 007a69fc4f40..35e73e255ad3 100644
--- a/arch/arm64/include/asm/futex.h
+++ b/arch/arm64/include/asm/futex.h
@@ -44,7 +44,7 @@
 "	.popsection\n"							\
 "	.pushsection __ex_table,\"a\"\n"				\
 "	.align	3\n"							\
-"	.quad	1b, 4b, 2b, 4b\n"					\
+"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"		\
 "	.popsection\n"							\
 	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,		\
 		    CONFIG_ARM64_PAN)					\
@@ -135,7 +135,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 "	.popsection\n"
 "	.pushsection __ex_table,\"a\"\n"
 "	.align	3\n"
-"	.quad	1b, 4b, 2b, 4b\n"
+"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"
 "	.popsection\n"
 	: "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
 	: "r" (oldval), "r" (newval), "Ir" (-EFAULT)
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index b2ede967fe7d..ab627e6c06c9 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -36,11 +36,11 @@
 #define VERIFY_WRITE 1
 
 /*
- * The exception table consists of pairs of addresses: the first is the
- * address of an instruction that is allowed to fault, and the second is
- * the address at which the program should continue.  No registers are
- * modified, so it is entirely up to the continuation code to figure out
- * what to do.
+ * The exception table consists of pairs of relative offsets: the first
+ * is the relative offset to an instruction that is allowed to fault,
+ * and the second is the relative offset at which the program should
+ * continue. No registers are modified, so it is entirely up to the
+ * continuation code to figure out what to do.
  *
  * All the routines below use bits of fixup code that are out of line
  * with the main instruction path.  This means when everything is well,
@@ -50,9 +50,11 @@
 
 struct exception_table_entry
 {
-	unsigned long insn, fixup;
+	int insn, fixup;
 };
 
+#define ARCH_HAS_RELATIVE_EXTABLE
+
 extern int fixup_exception(struct pt_regs *regs);
 
 #define KERNEL_DS	(-1UL)
@@ -125,7 +127,7 @@ static inline void set_fs(mm_segment_t fs)
 	"	.previous\n"						\
 	"	.section __ex_table,\"a\"\n"				\
 	"	.align	3\n"						\
-	"	.quad	1b, 3b\n"					\
+	"	.long	(1b - .), (3b - .)\n"				\
 	"	.previous"						\
 	: "+r" (err), "=&r" (x)						\
 	: "r" (addr), "i" (-EFAULT))
@@ -192,7 +194,7 @@ do {									\
 	"	.previous\n"						\
 	"	.section __ex_table,\"a\"\n"				\
 	"	.align	3\n"						\
-	"	.quad	1b, 3b\n"					\
+	"	.long	(1b - .), (3b - .)\n"				\
 	"	.previous"						\
 	: "+r" (err)							\
 	: "r" (x), "r" (addr), "i" (-EFAULT))
diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
index 937f5e58a4d3..8f21b1363387 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -299,8 +299,8 @@ static void register_insn_emulation_sysctl(struct ctl_table *table)
 	"	.popsection"					\
 	"	.pushsection	 __ex_table,\"a\"\n"		\
 	"	.align		3\n"				\
-	"	.quad		0b, 4b\n"			\
-	"	.quad		1b, 4b\n"			\
+	"	.long		(0b - .), (4b - .)\n"		\
+	"	.long		(1b - .), (4b - .)\n"		\
 	"	.popsection\n"					\
 	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,	\
 		CONFIG_ARM64_PAN)				\
diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
index 79444279ba8c..81acd4706878 100644
--- a/arch/arm64/mm/extable.c
+++ b/arch/arm64/mm/extable.c
@@ -11,7 +11,7 @@ int fixup_exception(struct pt_regs *regs)
 
 	fixup = search_exception_tables(instruction_pointer(regs));
 	if (fixup)
-		regs->pc = fixup->fixup;
+		regs->pc = (unsigned long)&fixup->fixup + fixup->fixup;
 
 	return fixup != NULL;
 }
diff --git a/scripts/sortextable.c b/scripts/sortextable.c
index c2423d913b46..af247c70fb66 100644
--- a/scripts/sortextable.c
+++ b/scripts/sortextable.c
@@ -282,12 +282,12 @@ do_file(char const *const fname)
 	case EM_386:
 	case EM_X86_64:
 	case EM_S390:
+	case EM_AARCH64:
 		custom_sort = sort_relative_table;
 		break;
 	case EM_ARCOMPACT:
 	case EM_ARCV2:
 	case EM_ARM:
-	case EM_AARCH64:
 	case EM_MICROBLAZE:
 	case EM_MIPS:
 	case EM_XTENSA:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 56+ messages in thread

* Re: [PATCH 0/6] generic relative extable support
  2016-01-03 16:05 ` Ard Biesheuvel
  (?)
@ 2016-01-04 11:20   ` Heiko Carstens
  -1 siblings, 0 replies; 56+ messages in thread
From: Heiko Carstens @ 2016-01-04 11:20 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, schwidefsky, mattst88, ink, rth,
	tony.luck, fenghua.yu, catalin.marinas, will.deacon, arnd, akpm,
	mark.rutland, marc.zyngier

On Sun, Jan 03, 2016 at 05:05:51PM +0100, Ard Biesheuvel wrote:
> There are currently four architectures (x86, ia64, alpha and s390) whose
> user-access exception tables are relative to the table entry address rather
> than absolute. Each of these architectures has its own search_extable() and
> sort_extable() implementation, which are not only mostly identical to each
> other, but also deviate very little from the generic absolute implementations
> in lib/extable.c that they override.
> 
> So before making arm64 the fifth architecture that reimplements this, let's
> refactor the existing code so that all of these architectures use common code
> for searching and sorting the relative extables. Archs may set
> ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
> relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
> special treatment in the swapping step of the sorting routine (such as alpha).
> 
> Note that the s390 patch applies on top of the following patch:
> 
>   http://article.gmane.org/gmane.linux.kernel/2117036
> 
> which fixes a bug I spotted while working on this code. Since that probably
> needs to go to -stable, I broke it out and posted it separately.
> 
> Ard Biesheuvel (6):
>   extable: add support for relative extables to search and sort routines
>   alpha/extable: use generic search and sort routines
>   s390/extable: use generic search and sort routines
>   x86/extable: use generic search and sort routines
>   ia64/extable: use generic search and sort routines
>   arm64: switch to relative exception tables

For the s390 bits:

Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 0/6] generic relative extable support
@ 2016-01-04 11:20   ` Heiko Carstens
  0 siblings, 0 replies; 56+ messages in thread
From: Heiko Carstens @ 2016-01-04 11:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Jan 03, 2016 at 05:05:51PM +0100, Ard Biesheuvel wrote:
> There are currently four architectures (x86, ia64, alpha and s390) whose
> user-access exception tables are relative to the table entry address rather
> than absolute. Each of these architectures has its own search_extable() and
> sort_extable() implementation, which are not only mostly identical to each
> other, but also deviate very little from the generic absolute implementations
> in lib/extable.c that they override.
> 
> So before making arm64 the fifth architecture that reimplements this, let's
> refactor the existing code so that all of these architectures use common code
> for searching and sorting the relative extables. Archs may set
> ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
> relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
> special treatment in the swapping step of the sorting routine (such as alpha).
> 
> Note that the s390 patch applies on top of the following patch:
> 
>   http://article.gmane.org/gmane.linux.kernel/2117036
> 
> which fixes a bug I spotted while working on this code. Since that probably
> needs to go to -stable, I broke it out and posted it separately.
> 
> Ard Biesheuvel (6):
>   extable: add support for relative extables to search and sort routines
>   alpha/extable: use generic search and sort routines
>   s390/extable: use generic search and sort routines
>   x86/extable: use generic search and sort routines
>   ia64/extable: use generic search and sort routines
>   arm64: switch to relative exception tables

For the s390 bits:

Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 0/6] generic relative extable support
@ 2016-01-04 11:20   ` Heiko Carstens
  0 siblings, 0 replies; 56+ messages in thread
From: Heiko Carstens @ 2016-01-04 11:20 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, schwidefsky, mattst88, ink, rth,
	tony.luck, fenghua.yu, catalin.marinas, will.deacon, arnd, akpm,
	mark.rutland, marc.zyngier

On Sun, Jan 03, 2016 at 05:05:51PM +0100, Ard Biesheuvel wrote:
> There are currently four architectures (x86, ia64, alpha and s390) whose
> user-access exception tables are relative to the table entry address rather
> than absolute. Each of these architectures has its own search_extable() and
> sort_extable() implementation, which are not only mostly identical to each
> other, but also deviate very little from the generic absolute implementations
> in lib/extable.c that they override.
> 
> So before making arm64 the fifth architecture that reimplements this, let's
> refactor the existing code so that all of these architectures use common code
> for searching and sorting the relative extables. Archs may set
> ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
> relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
> special treatment in the swapping step of the sorting routine (such as alpha).
> 
> Note that the s390 patch applies on top of the following patch:
> 
>   http://article.gmane.org/gmane.linux.kernel/2117036
> 
> which fixes a bug I spotted while working on this code. Since that probably
> needs to go to -stable, I broke it out and posted it separately.
> 
> Ard Biesheuvel (6):
>   extable: add support for relative extables to search and sort routines
>   alpha/extable: use generic search and sort routines
>   s390/extable: use generic search and sort routines
>   x86/extable: use generic search and sort routines
>   ia64/extable: use generic search and sort routines
>   arm64: switch to relative exception tables

For the s390 bits:

Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-03 16:05   ` Ard Biesheuvel
  (?)
@ 2016-01-04 14:46     ` Will Deacon
  -1 siblings, 0 replies; 56+ messages in thread
From: Will Deacon @ 2016-01-04 14:46 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas, arnd,
	akpm, mark.rutland, marc.zyngier

On Sun, Jan 03, 2016 at 05:05:57PM +0100, Ard Biesheuvel wrote:
> Instead of using absolute addresses for both the exception location
> and the fixup, use offsets relative to the exception table entry values.
> Not only does this cut the size of the exception table in half, it is
> also a prerequisite for KASLR, since absolute exception table entries
> are subject to dynamic relocation, which is incompatible with the sorting
> of the exception table that occurs at build time.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> 
> Note that this patch supersedes the version I sent as part of the series that
> implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531
> 
>  arch/arm64/include/asm/assembler.h   |  2 +-
>  arch/arm64/include/asm/futex.h       |  4 ++--
>  arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
>  arch/arm64/kernel/armv8_deprecated.c |  4 ++--
>  arch/arm64/mm/extable.c              |  2 +-
>  scripts/sortextable.c                |  2 +-
>  6 files changed, 17 insertions(+), 15 deletions(-)

This looks good to me, so for the arm64 part (i.e. this patch):

  Acked-by: Will Deacon <will.deacon@arm.com>

Will

> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> index 12eff928ef8b..8094d50f05bc 100644
> --- a/arch/arm64/include/asm/assembler.h
> +++ b/arch/arm64/include/asm/assembler.h
> @@ -98,7 +98,7 @@
>  9999:	x;					\
>  	.section __ex_table,"a";		\
>  	.align	3;				\
> -	.quad	9999b,l;			\
> +	.long	(9999b - .), (l - .);		\
>  	.previous
>  
>  /*
> diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
> index 007a69fc4f40..35e73e255ad3 100644
> --- a/arch/arm64/include/asm/futex.h
> +++ b/arch/arm64/include/asm/futex.h
> @@ -44,7 +44,7 @@
>  "	.popsection\n"							\
>  "	.pushsection __ex_table,\"a\"\n"				\
>  "	.align	3\n"							\
> -"	.quad	1b, 4b, 2b, 4b\n"					\
> +"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"		\
>  "	.popsection\n"							\
>  	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,		\
>  		    CONFIG_ARM64_PAN)					\
> @@ -135,7 +135,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
>  "	.popsection\n"
>  "	.pushsection __ex_table,\"a\"\n"
>  "	.align	3\n"
> -"	.quad	1b, 4b, 2b, 4b\n"
> +"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"
>  "	.popsection\n"
>  	: "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
>  	: "r" (oldval), "r" (newval), "Ir" (-EFAULT)
> diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
> index b2ede967fe7d..ab627e6c06c9 100644
> --- a/arch/arm64/include/asm/uaccess.h
> +++ b/arch/arm64/include/asm/uaccess.h
> @@ -36,11 +36,11 @@
>  #define VERIFY_WRITE 1
>  
>  /*
> - * The exception table consists of pairs of addresses: the first is the
> - * address of an instruction that is allowed to fault, and the second is
> - * the address at which the program should continue.  No registers are
> - * modified, so it is entirely up to the continuation code to figure out
> - * what to do.
> + * The exception table consists of pairs of relative offsets: the first
> + * is the relative offset to an instruction that is allowed to fault,
> + * and the second is the relative offset at which the program should
> + * continue. No registers are modified, so it is entirely up to the
> + * continuation code to figure out what to do.
>   *
>   * All the routines below use bits of fixup code that are out of line
>   * with the main instruction path.  This means when everything is well,
> @@ -50,9 +50,11 @@
>  
>  struct exception_table_entry
>  {
> -	unsigned long insn, fixup;
> +	int insn, fixup;
>  };
>  
> +#define ARCH_HAS_RELATIVE_EXTABLE
> +
>  extern int fixup_exception(struct pt_regs *regs);
>  
>  #define KERNEL_DS	(-1UL)
> @@ -125,7 +127,7 @@ static inline void set_fs(mm_segment_t fs)
>  	"	.previous\n"						\
>  	"	.section __ex_table,\"a\"\n"				\
>  	"	.align	3\n"						\
> -	"	.quad	1b, 3b\n"					\
> +	"	.long	(1b - .), (3b - .)\n"				\
>  	"	.previous"						\
>  	: "+r" (err), "=&r" (x)						\
>  	: "r" (addr), "i" (-EFAULT))
> @@ -192,7 +194,7 @@ do {									\
>  	"	.previous\n"						\
>  	"	.section __ex_table,\"a\"\n"				\
>  	"	.align	3\n"						\
> -	"	.quad	1b, 3b\n"					\
> +	"	.long	(1b - .), (3b - .)\n"				\
>  	"	.previous"						\
>  	: "+r" (err)							\
>  	: "r" (x), "r" (addr), "i" (-EFAULT))
> diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
> index 937f5e58a4d3..8f21b1363387 100644
> --- a/arch/arm64/kernel/armv8_deprecated.c
> +++ b/arch/arm64/kernel/armv8_deprecated.c
> @@ -299,8 +299,8 @@ static void register_insn_emulation_sysctl(struct ctl_table *table)
>  	"	.popsection"					\
>  	"	.pushsection	 __ex_table,\"a\"\n"		\
>  	"	.align		3\n"				\
> -	"	.quad		0b, 4b\n"			\
> -	"	.quad		1b, 4b\n"			\
> +	"	.long		(0b - .), (4b - .)\n"		\
> +	"	.long		(1b - .), (4b - .)\n"		\
>  	"	.popsection\n"					\
>  	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,	\
>  		CONFIG_ARM64_PAN)				\
> diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
> index 79444279ba8c..81acd4706878 100644
> --- a/arch/arm64/mm/extable.c
> +++ b/arch/arm64/mm/extable.c
> @@ -11,7 +11,7 @@ int fixup_exception(struct pt_regs *regs)
>  
>  	fixup = search_exception_tables(instruction_pointer(regs));
>  	if (fixup)
> -		regs->pc = fixup->fixup;
> +		regs->pc = (unsigned long)&fixup->fixup + fixup->fixup;
>  
>  	return fixup != NULL;
>  }
> diff --git a/scripts/sortextable.c b/scripts/sortextable.c
> index c2423d913b46..af247c70fb66 100644
> --- a/scripts/sortextable.c
> +++ b/scripts/sortextable.c
> @@ -282,12 +282,12 @@ do_file(char const *const fname)
>  	case EM_386:
>  	case EM_X86_64:
>  	case EM_S390:
> +	case EM_AARCH64:
>  		custom_sort = sort_relative_table;
>  		break;
>  	case EM_ARCOMPACT:
>  	case EM_ARCV2:
>  	case EM_ARM:
> -	case EM_AARCH64:
>  	case EM_MICROBLAZE:
>  	case EM_MIPS:
>  	case EM_XTENSA:
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 14:46     ` Will Deacon
  0 siblings, 0 replies; 56+ messages in thread
From: Will Deacon @ 2016-01-04 14:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Jan 03, 2016 at 05:05:57PM +0100, Ard Biesheuvel wrote:
> Instead of using absolute addresses for both the exception location
> and the fixup, use offsets relative to the exception table entry values.
> Not only does this cut the size of the exception table in half, it is
> also a prerequisite for KASLR, since absolute exception table entries
> are subject to dynamic relocation, which is incompatible with the sorting
> of the exception table that occurs at build time.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> 
> Note that this patch supersedes the version I sent as part of the series that
> implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531
> 
>  arch/arm64/include/asm/assembler.h   |  2 +-
>  arch/arm64/include/asm/futex.h       |  4 ++--
>  arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
>  arch/arm64/kernel/armv8_deprecated.c |  4 ++--
>  arch/arm64/mm/extable.c              |  2 +-
>  scripts/sortextable.c                |  2 +-
>  6 files changed, 17 insertions(+), 15 deletions(-)

This looks good to me, so for the arm64 part (i.e. this patch):

  Acked-by: Will Deacon <will.deacon@arm.com>

Will

> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> index 12eff928ef8b..8094d50f05bc 100644
> --- a/arch/arm64/include/asm/assembler.h
> +++ b/arch/arm64/include/asm/assembler.h
> @@ -98,7 +98,7 @@
>  9999:	x;					\
>  	.section __ex_table,"a";		\
>  	.align	3;				\
> -	.quad	9999b,l;			\
> +	.long	(9999b - .), (l - .);		\
>  	.previous
>  
>  /*
> diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
> index 007a69fc4f40..35e73e255ad3 100644
> --- a/arch/arm64/include/asm/futex.h
> +++ b/arch/arm64/include/asm/futex.h
> @@ -44,7 +44,7 @@
>  "	.popsection\n"							\
>  "	.pushsection __ex_table,\"a\"\n"				\
>  "	.align	3\n"							\
> -"	.quad	1b, 4b, 2b, 4b\n"					\
> +"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"		\
>  "	.popsection\n"							\
>  	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,		\
>  		    CONFIG_ARM64_PAN)					\
> @@ -135,7 +135,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
>  "	.popsection\n"
>  "	.pushsection __ex_table,\"a\"\n"
>  "	.align	3\n"
> -"	.quad	1b, 4b, 2b, 4b\n"
> +"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"
>  "	.popsection\n"
>  	: "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
>  	: "r" (oldval), "r" (newval), "Ir" (-EFAULT)
> diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
> index b2ede967fe7d..ab627e6c06c9 100644
> --- a/arch/arm64/include/asm/uaccess.h
> +++ b/arch/arm64/include/asm/uaccess.h
> @@ -36,11 +36,11 @@
>  #define VERIFY_WRITE 1
>  
>  /*
> - * The exception table consists of pairs of addresses: the first is the
> - * address of an instruction that is allowed to fault, and the second is
> - * the address at which the program should continue.  No registers are
> - * modified, so it is entirely up to the continuation code to figure out
> - * what to do.
> + * The exception table consists of pairs of relative offsets: the first
> + * is the relative offset to an instruction that is allowed to fault,
> + * and the second is the relative offset at which the program should
> + * continue. No registers are modified, so it is entirely up to the
> + * continuation code to figure out what to do.
>   *
>   * All the routines below use bits of fixup code that are out of line
>   * with the main instruction path.  This means when everything is well,
> @@ -50,9 +50,11 @@
>  
>  struct exception_table_entry
>  {
> -	unsigned long insn, fixup;
> +	int insn, fixup;
>  };
>  
> +#define ARCH_HAS_RELATIVE_EXTABLE
> +
>  extern int fixup_exception(struct pt_regs *regs);
>  
>  #define KERNEL_DS	(-1UL)
> @@ -125,7 +127,7 @@ static inline void set_fs(mm_segment_t fs)
>  	"	.previous\n"						\
>  	"	.section __ex_table,\"a\"\n"				\
>  	"	.align	3\n"						\
> -	"	.quad	1b, 3b\n"					\
> +	"	.long	(1b - .), (3b - .)\n"				\
>  	"	.previous"						\
>  	: "+r" (err), "=&r" (x)						\
>  	: "r" (addr), "i" (-EFAULT))
> @@ -192,7 +194,7 @@ do {									\
>  	"	.previous\n"						\
>  	"	.section __ex_table,\"a\"\n"				\
>  	"	.align	3\n"						\
> -	"	.quad	1b, 3b\n"					\
> +	"	.long	(1b - .), (3b - .)\n"				\
>  	"	.previous"						\
>  	: "+r" (err)							\
>  	: "r" (x), "r" (addr), "i" (-EFAULT))
> diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
> index 937f5e58a4d3..8f21b1363387 100644
> --- a/arch/arm64/kernel/armv8_deprecated.c
> +++ b/arch/arm64/kernel/armv8_deprecated.c
> @@ -299,8 +299,8 @@ static void register_insn_emulation_sysctl(struct ctl_table *table)
>  	"	.popsection"					\
>  	"	.pushsection	 __ex_table,\"a\"\n"		\
>  	"	.align		3\n"				\
> -	"	.quad		0b, 4b\n"			\
> -	"	.quad		1b, 4b\n"			\
> +	"	.long		(0b - .), (4b - .)\n"		\
> +	"	.long		(1b - .), (4b - .)\n"		\
>  	"	.popsection\n"					\
>  	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,	\
>  		CONFIG_ARM64_PAN)				\
> diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
> index 79444279ba8c..81acd4706878 100644
> --- a/arch/arm64/mm/extable.c
> +++ b/arch/arm64/mm/extable.c
> @@ -11,7 +11,7 @@ int fixup_exception(struct pt_regs *regs)
>  
>  	fixup = search_exception_tables(instruction_pointer(regs));
>  	if (fixup)
> -		regs->pc = fixup->fixup;
> +		regs->pc = (unsigned long)&fixup->fixup + fixup->fixup;
>  
>  	return fixup != NULL;
>  }
> diff --git a/scripts/sortextable.c b/scripts/sortextable.c
> index c2423d913b46..af247c70fb66 100644
> --- a/scripts/sortextable.c
> +++ b/scripts/sortextable.c
> @@ -282,12 +282,12 @@ do_file(char const *const fname)
>  	case EM_386:
>  	case EM_X86_64:
>  	case EM_S390:
> +	case EM_AARCH64:
>  		custom_sort = sort_relative_table;
>  		break;
>  	case EM_ARCOMPACT:
>  	case EM_ARCV2:
>  	case EM_ARM:
> -	case EM_AARCH64:
>  	case EM_MICROBLAZE:
>  	case EM_MIPS:
>  	case EM_XTENSA:
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 14:46     ` Will Deacon
  0 siblings, 0 replies; 56+ messages in thread
From: Will Deacon @ 2016-01-04 14:46 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, hpa, mingo, heiko.carstens, schwidefsky,
	mattst88, ink, rth, tony.luck, fenghua.yu, catalin.marinas, arnd,
	akpm, mark.rutland, marc.zyngier

On Sun, Jan 03, 2016 at 05:05:57PM +0100, Ard Biesheuvel wrote:
> Instead of using absolute addresses for both the exception location
> and the fixup, use offsets relative to the exception table entry values.
> Not only does this cut the size of the exception table in half, it is
> also a prerequisite for KASLR, since absolute exception table entries
> are subject to dynamic relocation, which is incompatible with the sorting
> of the exception table that occurs at build time.
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> 
> Note that this patch supersedes the version I sent as part of the series that
> implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531
> 
>  arch/arm64/include/asm/assembler.h   |  2 +-
>  arch/arm64/include/asm/futex.h       |  4 ++--
>  arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
>  arch/arm64/kernel/armv8_deprecated.c |  4 ++--
>  arch/arm64/mm/extable.c              |  2 +-
>  scripts/sortextable.c                |  2 +-
>  6 files changed, 17 insertions(+), 15 deletions(-)

This looks good to me, so for the arm64 part (i.e. this patch):

  Acked-by: Will Deacon <will.deacon@arm.com>

Will

> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> index 12eff928ef8b..8094d50f05bc 100644
> --- a/arch/arm64/include/asm/assembler.h
> +++ b/arch/arm64/include/asm/assembler.h
> @@ -98,7 +98,7 @@
>  9999:	x;					\
>  	.section __ex_table,"a";		\
>  	.align	3;				\
> -	.quad	9999b,l;			\
> +	.long	(9999b - .), (l - .);		\
>  	.previous
>  
>  /*
> diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
> index 007a69fc4f40..35e73e255ad3 100644
> --- a/arch/arm64/include/asm/futex.h
> +++ b/arch/arm64/include/asm/futex.h
> @@ -44,7 +44,7 @@
>  "	.popsection\n"							\
>  "	.pushsection __ex_table,\"a\"\n"				\
>  "	.align	3\n"							\
> -"	.quad	1b, 4b, 2b, 4b\n"					\
> +"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"		\
>  "	.popsection\n"							\
>  	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,		\
>  		    CONFIG_ARM64_PAN)					\
> @@ -135,7 +135,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
>  "	.popsection\n"
>  "	.pushsection __ex_table,\"a\"\n"
>  "	.align	3\n"
> -"	.quad	1b, 4b, 2b, 4b\n"
> +"	.long	(1b - .), (4b - .), (2b - .), (4b - .)\n"
>  "	.popsection\n"
>  	: "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
>  	: "r" (oldval), "r" (newval), "Ir" (-EFAULT)
> diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
> index b2ede967fe7d..ab627e6c06c9 100644
> --- a/arch/arm64/include/asm/uaccess.h
> +++ b/arch/arm64/include/asm/uaccess.h
> @@ -36,11 +36,11 @@
>  #define VERIFY_WRITE 1
>  
>  /*
> - * The exception table consists of pairs of addresses: the first is the
> - * address of an instruction that is allowed to fault, and the second is
> - * the address at which the program should continue.  No registers are
> - * modified, so it is entirely up to the continuation code to figure out
> - * what to do.
> + * The exception table consists of pairs of relative offsets: the first
> + * is the relative offset to an instruction that is allowed to fault,
> + * and the second is the relative offset at which the program should
> + * continue. No registers are modified, so it is entirely up to the
> + * continuation code to figure out what to do.
>   *
>   * All the routines below use bits of fixup code that are out of line
>   * with the main instruction path.  This means when everything is well,
> @@ -50,9 +50,11 @@
>  
>  struct exception_table_entry
>  {
> -	unsigned long insn, fixup;
> +	int insn, fixup;
>  };
>  
> +#define ARCH_HAS_RELATIVE_EXTABLE
> +
>  extern int fixup_exception(struct pt_regs *regs);
>  
>  #define KERNEL_DS	(-1UL)
> @@ -125,7 +127,7 @@ static inline void set_fs(mm_segment_t fs)
>  	"	.previous\n"						\
>  	"	.section __ex_table,\"a\"\n"				\
>  	"	.align	3\n"						\
> -	"	.quad	1b, 3b\n"					\
> +	"	.long	(1b - .), (3b - .)\n"				\
>  	"	.previous"						\
>  	: "+r" (err), "=&r" (x)						\
>  	: "r" (addr), "i" (-EFAULT))
> @@ -192,7 +194,7 @@ do {									\
>  	"	.previous\n"						\
>  	"	.section __ex_table,\"a\"\n"				\
>  	"	.align	3\n"						\
> -	"	.quad	1b, 3b\n"					\
> +	"	.long	(1b - .), (3b - .)\n"				\
>  	"	.previous"						\
>  	: "+r" (err)							\
>  	: "r" (x), "r" (addr), "i" (-EFAULT))
> diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
> index 937f5e58a4d3..8f21b1363387 100644
> --- a/arch/arm64/kernel/armv8_deprecated.c
> +++ b/arch/arm64/kernel/armv8_deprecated.c
> @@ -299,8 +299,8 @@ static void register_insn_emulation_sysctl(struct ctl_table *table)
>  	"	.popsection"					\
>  	"	.pushsection	 __ex_table,\"a\"\n"		\
>  	"	.align		3\n"				\
> -	"	.quad		0b, 4b\n"			\
> -	"	.quad		1b, 4b\n"			\
> +	"	.long		(0b - .), (4b - .)\n"		\
> +	"	.long		(1b - .), (4b - .)\n"		\
>  	"	.popsection\n"					\
>  	ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,	\
>  		CONFIG_ARM64_PAN)				\
> diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
> index 79444279ba8c..81acd4706878 100644
> --- a/arch/arm64/mm/extable.c
> +++ b/arch/arm64/mm/extable.c
> @@ -11,7 +11,7 @@ int fixup_exception(struct pt_regs *regs)
>  
>  	fixup = search_exception_tables(instruction_pointer(regs));
>  	if (fixup)
> -		regs->pc = fixup->fixup;
> +		regs->pc = (unsigned long)&fixup->fixup + fixup->fixup;
>  
>  	return fixup != NULL;
>  }
> diff --git a/scripts/sortextable.c b/scripts/sortextable.c
> index c2423d913b46..af247c70fb66 100644
> --- a/scripts/sortextable.c
> +++ b/scripts/sortextable.c
> @@ -282,12 +282,12 @@ do_file(char const *const fname)
>  	case EM_386:
>  	case EM_X86_64:
>  	case EM_S390:
> +	case EM_AARCH64:
>  		custom_sort = sort_relative_table;
>  		break;
>  	case EM_ARCOMPACT:
>  	case EM_ARCV2:
>  	case EM_ARM:
> -	case EM_AARCH64:
>  	case EM_MICROBLAZE:
>  	case EM_MIPS:
>  	case EM_XTENSA:
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-04 14:46     ` Will Deacon
  (?)
@ 2016-01-04 18:13       ` H. Peter Anvin
  -1 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:13 UTC (permalink / raw)
  To: Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, tony.luck, fenghua.yu, catalin.marinas, arnd, akpm,
	mark.rutland, marc.zyngier

On 01/04/2016 06:46 AM, Will Deacon wrote:
> On Sun, Jan 03, 2016 at 05:05:57PM +0100, Ard Biesheuvel wrote:
>> Instead of using absolute addresses for both the exception location
>> and the fixup, use offsets relative to the exception table entry values.
>> Not only does this cut the size of the exception table in half, it is
>> also a prerequisite for KASLR, since absolute exception table entries
>> are subject to dynamic relocation, which is incompatible with the sorting
>> of the exception table that occurs at build time.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>
>> Note that this patch supersedes the version I sent as part of the series that
>> implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531
>>
>>  arch/arm64/include/asm/assembler.h   |  2 +-
>>  arch/arm64/include/asm/futex.h       |  4 ++--
>>  arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
>>  arch/arm64/kernel/armv8_deprecated.c |  4 ++--
>>  arch/arm64/mm/extable.c              |  2 +-
>>  scripts/sortextable.c                |  2 +-
>>  6 files changed, 17 insertions(+), 15 deletions(-)
> 
> This looks good to me, so for the arm64 part (i.e. this patch):
> 
>   Acked-by: Will Deacon <will.deacon@arm.com>

May I humbly ask why the [Finnish] you don't use the equivalent of the
x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:13       ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:13 UTC (permalink / raw)
  To: linux-arm-kernel

On 01/04/2016 06:46 AM, Will Deacon wrote:
> On Sun, Jan 03, 2016 at 05:05:57PM +0100, Ard Biesheuvel wrote:
>> Instead of using absolute addresses for both the exception location
>> and the fixup, use offsets relative to the exception table entry values.
>> Not only does this cut the size of the exception table in half, it is
>> also a prerequisite for KASLR, since absolute exception table entries
>> are subject to dynamic relocation, which is incompatible with the sorting
>> of the exception table that occurs at build time.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>
>> Note that this patch supersedes the version I sent as part of the series that
>> implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531
>>
>>  arch/arm64/include/asm/assembler.h   |  2 +-
>>  arch/arm64/include/asm/futex.h       |  4 ++--
>>  arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
>>  arch/arm64/kernel/armv8_deprecated.c |  4 ++--
>>  arch/arm64/mm/extable.c              |  2 +-
>>  scripts/sortextable.c                |  2 +-
>>  6 files changed, 17 insertions(+), 15 deletions(-)
> 
> This looks good to me, so for the arm64 part (i.e. this patch):
> 
>   Acked-by: Will Deacon <will.deacon@arm.com>

May I humbly ask why the [Finnish] you don't use the equivalent of the
x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?

	-hpa

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:13       ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:13 UTC (permalink / raw)
  To: Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, tony.luck, fenghua.yu, catalin.marinas, arnd, akpm,
	mark.rutland, marc.zyngier

On 01/04/2016 06:46 AM, Will Deacon wrote:
> On Sun, Jan 03, 2016 at 05:05:57PM +0100, Ard Biesheuvel wrote:
>> Instead of using absolute addresses for both the exception location
>> and the fixup, use offsets relative to the exception table entry values.
>> Not only does this cut the size of the exception table in half, it is
>> also a prerequisite for KASLR, since absolute exception table entries
>> are subject to dynamic relocation, which is incompatible with the sorting
>> of the exception table that occurs at build time.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>
>> Note that this patch supersedes the version I sent as part of the series that
>> implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531
>>
>>  arch/arm64/include/asm/assembler.h   |  2 +-
>>  arch/arm64/include/asm/futex.h       |  4 ++--
>>  arch/arm64/include/asm/uaccess.h     | 18 ++++++++++--------
>>  arch/arm64/kernel/armv8_deprecated.c |  4 ++--
>>  arch/arm64/mm/extable.c              |  2 +-
>>  scripts/sortextable.c                |  2 +-
>>  6 files changed, 17 insertions(+), 15 deletions(-)
> 
> This looks good to me, so for the arm64 part (i.e. this patch):
> 
>   Acked-by: Will Deacon <will.deacon@arm.com>

May I humbly ask why the [Finnish] you don't use the equivalent of the
x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 0/6] generic relative extable support
  2016-01-04 11:20   ` Heiko Carstens
  (?)
@ 2016-01-04 18:15     ` H. Peter Anvin
  -1 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:15 UTC (permalink / raw)
  To: Heiko Carstens, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, schwidefsky, mattst88, ink, rth,
	tony.luck, fenghua.yu, catalin.marinas, will.deacon, arnd, akpm,
	mark.rutland, marc.zyngier

On 01/04/2016 03:20 AM, Heiko Carstens wrote:
> On Sun, Jan 03, 2016 at 05:05:51PM +0100, Ard Biesheuvel wrote:
>> There are currently four architectures (x86, ia64, alpha and s390) whose
>> user-access exception tables are relative to the table entry address rather
>> than absolute. Each of these architectures has its own search_extable() and
>> sort_extable() implementation, which are not only mostly identical to each
>> other, but also deviate very little from the generic absolute implementations
>> in lib/extable.c that they override.
>>
>> So before making arm64 the fifth architecture that reimplements this, let's
>> refactor the existing code so that all of these architectures use common code
>> for searching and sorting the relative extables. Archs may set
>> ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
>> relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
>> special treatment in the swapping step of the sorting routine (such as alpha).
>>
>> Note that the s390 patch applies on top of the following patch:
>>
>>   http://article.gmane.org/gmane.linux.kernel/2117036
>>
>> which fixes a bug I spotted while working on this code. Since that probably
>> needs to go to -stable, I broke it out and posted it separately.
>>
>> Ard Biesheuvel (6):
>>   extable: add support for relative extables to search and sort routines
>>   alpha/extable: use generic search and sort routines
>>   s390/extable: use generic search and sort routines
>>   x86/extable: use generic search and sort routines
>>   ia64/extable: use generic search and sort routines
>>   arm64: switch to relative exception tables
> 
> For the s390 bits:
> 
> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
> 

For the x86 bits:

Acked-by: H. Peter Anvin <hpa@linux.intel.com>

*However*, please see my comment about generalizing _ASM_EXTABLE() for
the non-x86 architectures.

	-hpa


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 0/6] generic relative extable support
@ 2016-01-04 18:15     ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:15 UTC (permalink / raw)
  To: linux-arm-kernel

On 01/04/2016 03:20 AM, Heiko Carstens wrote:
> On Sun, Jan 03, 2016 at 05:05:51PM +0100, Ard Biesheuvel wrote:
>> There are currently four architectures (x86, ia64, alpha and s390) whose
>> user-access exception tables are relative to the table entry address rather
>> than absolute. Each of these architectures has its own search_extable() and
>> sort_extable() implementation, which are not only mostly identical to each
>> other, but also deviate very little from the generic absolute implementations
>> in lib/extable.c that they override.
>>
>> So before making arm64 the fifth architecture that reimplements this, let's
>> refactor the existing code so that all of these architectures use common code
>> for searching and sorting the relative extables. Archs may set
>> ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
>> relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
>> special treatment in the swapping step of the sorting routine (such as alpha).
>>
>> Note that the s390 patch applies on top of the following patch:
>>
>>   http://article.gmane.org/gmane.linux.kernel/2117036
>>
>> which fixes a bug I spotted while working on this code. Since that probably
>> needs to go to -stable, I broke it out and posted it separately.
>>
>> Ard Biesheuvel (6):
>>   extable: add support for relative extables to search and sort routines
>>   alpha/extable: use generic search and sort routines
>>   s390/extable: use generic search and sort routines
>>   x86/extable: use generic search and sort routines
>>   ia64/extable: use generic search and sort routines
>>   arm64: switch to relative exception tables
> 
> For the s390 bits:
> 
> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
> 

For the x86 bits:

Acked-by: H. Peter Anvin <hpa@linux.intel.com>

*However*, please see my comment about generalizing _ASM_EXTABLE() for
the non-x86 architectures.

	-hpa

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 0/6] generic relative extable support
@ 2016-01-04 18:15     ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:15 UTC (permalink / raw)
  To: Heiko Carstens, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, schwidefsky, mattst88, ink, rth,
	tony.luck, fenghua.yu, catalin.marinas, will.deacon, arnd, akpm,
	mark.rutland, marc.zyngier

On 01/04/2016 03:20 AM, Heiko Carstens wrote:
> On Sun, Jan 03, 2016 at 05:05:51PM +0100, Ard Biesheuvel wrote:
>> There are currently four architectures (x86, ia64, alpha and s390) whose
>> user-access exception tables are relative to the table entry address rather
>> than absolute. Each of these architectures has its own search_extable() and
>> sort_extable() implementation, which are not only mostly identical to each
>> other, but also deviate very little from the generic absolute implementations
>> in lib/extable.c that they override.
>>
>> So before making arm64 the fifth architecture that reimplements this, let's
>> refactor the existing code so that all of these architectures use common code
>> for searching and sorting the relative extables. Archs may set
>> ARCH_HAS_RELATIVE_EXTABLE to indicate that the table consists of a pair of
>> relative ints, and may define swap_ex_entry_fixup() if the fixup member needs
>> special treatment in the swapping step of the sorting routine (such as alpha).
>>
>> Note that the s390 patch applies on top of the following patch:
>>
>>   http://article.gmane.org/gmane.linux.kernel/2117036
>>
>> which fixes a bug I spotted while working on this code. Since that probably
>> needs to go to -stable, I broke it out and posted it separately.
>>
>> Ard Biesheuvel (6):
>>   extable: add support for relative extables to search and sort routines
>>   alpha/extable: use generic search and sort routines
>>   s390/extable: use generic search and sort routines
>>   x86/extable: use generic search and sort routines
>>   ia64/extable: use generic search and sort routines
>>   arm64: switch to relative exception tables
> 
> For the s390 bits:
> 
> Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
> 

For the x86 bits:

Acked-by: H. Peter Anvin <hpa@linux.intel.com>

*However*, please see my comment about generalizing _ASM_EXTABLE() for
the non-x86 architectures.

	-hpa


^ permalink raw reply	[flat|nested] 56+ messages in thread

* RE: [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-04 18:13       ` H. Peter Anvin
  (?)
  (?)
@ 2016-01-04 18:20         ` Luck, Tony
  -1 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 18:20 UTC (permalink / raw)
  To: H. Peter Anvin, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngier

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 633 bytes --]

> May I humbly ask why the [Finnish] you don't use the equivalent of the
> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?

I'm messing with that right now (with help from Andy Lutomirski and Boris) to
add different classes of exception table (so I can tag some instructions as being
suitable for fixup from the machine check handler).  So it might not be generic
for much longer.

http://marc.info/?l=linux-kernel&m=145187079504846&w=2

-Tony
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:20         ` Luck, Tony
  0 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 18:20 UTC (permalink / raw)
  To: linux-arm-kernel

> May I humbly ask why the [Finnish] you don't use the equivalent of the
> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?

I'm messing with that right now (with help from Andy Lutomirski and Boris) to
add different classes of exception table (so I can tag some instructions as being
suitable for fixup from the machine check handler).  So it might not be generic
for much longer.

http://marc.info/?l=linux-kernel&m=145187079504846&w=2

-Tony

^ permalink raw reply	[flat|nested] 56+ messages in thread

* RE: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:20         ` Luck, Tony
  0 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 18:20 UTC (permalink / raw)
  To: H. Peter Anvin, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngier

PiBNYXkgSSBodW1ibHkgYXNrIHdoeSB0aGUgW0Zpbm5pc2hdIHlvdSBkb24ndCB1c2UgdGhlIGVx
dWl2YWxlbnQgb2YgdGhlDQo+IHg4NiBfQVNNX0VYVEFCTEUoKSBtYWNybz8gIEluIGZhY3QsIHdo
eSBkb24ndCB3ZSBtYWtlIHRoYXQgb25lIGdlbmVyaWMsIHRvbz8NCg0KSSdtIG1lc3Npbmcgd2l0
aCB0aGF0IHJpZ2h0IG5vdyAod2l0aCBoZWxwIGZyb20gQW5keSBMdXRvbWlyc2tpIGFuZCBCb3Jp
cykgdG8NCmFkZCBkaWZmZXJlbnQgY2xhc3NlcyBvZiBleGNlcHRpb24gdGFibGUgKHNvIEkgY2Fu
IHRhZyBzb21lIGluc3RydWN0aW9ucyBhcyBiZWluZw0Kc3VpdGFibGUgZm9yIGZpeHVwIGZyb20g
dGhlIG1hY2hpbmUgY2hlY2sgaGFuZGxlcikuICBTbyBpdCBtaWdodCBub3QgYmUgZ2VuZXJpYw0K
Zm9yIG11Y2ggbG9uZ2VyLg0KDQpodHRwOi8vbWFyYy5pbmZvLz9sPWxpbnV4LWtlcm5lbCZtPTE0
NTE4NzA3OTUwNDg0NiZ3PTINCg0KLVRvbnkNCg=

^ permalink raw reply	[flat|nested] 56+ messages in thread

* RE: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:20         ` Luck, Tony
  0 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 18:20 UTC (permalink / raw)
  To: H. Peter Anvin, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngi

> May I humbly ask why the [Finnish] you don't use the equivalent of the
> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?

I'm messing with that right now (with help from Andy Lutomirski and Boris) to
add different classes of exception table (so I can tag some instructions as being
suitable for fixup from the machine check handler).  So it might not be generic
for much longer.

http://marc.info/?l=linux-kernel&m=145187079504846&w=2

-Tony

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-04 18:20         ` Luck, Tony
  (?)
  (?)
@ 2016-01-04 18:47           ` H. Peter Anvin
  -1 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:47 UTC (permalink / raw)
  To: Luck, Tony, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngier

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
> 

That doesn't mean it can't be overridden.

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:47           ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:47 UTC (permalink / raw)
  To: linux-arm-kernel

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
> 

That doesn't mean it can't be overridden.

	-hpa

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:47           ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:47 UTC (permalink / raw)
  To: Luck, Tony, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngier

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m\x145187079504846&w=2
> 

That doesn't mean it can't be overridden.

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 18:47           ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 18:47 UTC (permalink / raw)
  To: Luck, Tony, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngi

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
> 

That doesn't mean it can't be overridden.

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-04 18:20         ` Luck, Tony
  (?)
  (?)
@ 2016-01-04 19:21           ` H. Peter Anvin
  -1 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 19:21 UTC (permalink / raw)
  To: Luck, Tony, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngier

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
> 

I suspect that means we will also need to go back to arch-specific
sorting for x86.

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:21           ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 19:21 UTC (permalink / raw)
  To: linux-arm-kernel

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
> 

I suspect that means we will also need to go back to arch-specific
sorting for x86.

	-hpa

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:21           ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 19:21 UTC (permalink / raw)
  To: Luck, Tony, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngier

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m\x145187079504846&w=2
> 

I suspect that means we will also need to go back to arch-specific
sorting for x86.

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:21           ` H. Peter Anvin
  0 siblings, 0 replies; 56+ messages in thread
From: H. Peter Anvin @ 2016-01-04 19:21 UTC (permalink / raw)
  To: Luck, Tony, Will Deacon, Ard Biesheuvel
  Cc: linux-alpha, linux-kernel, linux-arm-kernel, linux-ia64,
	linux-s390, x86, mingo, heiko.carstens, schwidefsky, mattst88,
	ink, rth, Yu, Fenghua, catalin.marinas, arnd, akpm, mark.rutland,
	marc.zyngi

On 01/04/2016 10:20 AM, Luck, Tony wrote:
>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
> 
> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
> add different classes of exception table (so I can tag some instructions as being
> suitable for fixup from the machine check handler).  So it might not be generic
> for much longer.
> 
> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
> 

I suspect that means we will also need to go back to arch-specific
sorting for x86.

	-hpa



^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-04 19:21           ` H. Peter Anvin
  (?)
  (?)
@ 2016-01-04 19:28             ` Ard Biesheuvel
  -1 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-04 19:28 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Luck, Tony, Will Deacon, linux-alpha, linux-kernel,
	linux-arm-kernel, linux-ia64, linux-s390, x86, mingo,
	heiko.carstens, schwidefsky, mattst88, ink, rth, Yu, Fenghua,
	catalin.marinas, arnd, akpm, mark.rutland, marc.zyngier

On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> On 01/04/2016 10:20 AM, Luck, Tony wrote:
>>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
>>
>> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
>> add different classes of exception table (so I can tag some instructions as being
>> suitable for fixup from the machine check handler).  So it might not be generic
>> for much longer.
>>
>> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
>>
>
> I suspect that means we will also need to go back to arch-specific
> sorting for x86.
>

AFAICT, Tony's patches are not incompatible with mine. The fixup
address is offset with a large constant, but this does not affect the
sort order (since that is based on the other member), and the swap
operation that adds/subtracts the delta should not care about the
class bits. (I don't see any changes to sort_extable() in Tony's
patch)

@Tony: any comments? And do you have any objections to the ia64 patch
in this series?

I agree that it makes sense to define a macro to emit the extable
entries in this patch, but I am not sure how that extrapolates to the
other architectures, and testing those is going to be cumbersome for
me, so I'd prefer to keep that a local change for arm64 for now.

Thanks,
Ard.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:28             ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-04 19:28 UTC (permalink / raw)
  To: linux-arm-kernel

On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> On 01/04/2016 10:20 AM, Luck, Tony wrote:
>>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
>>
>> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
>> add different classes of exception table (so I can tag some instructions as being
>> suitable for fixup from the machine check handler).  So it might not be generic
>> for much longer.
>>
>> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
>>
>
> I suspect that means we will also need to go back to arch-specific
> sorting for x86.
>

AFAICT, Tony's patches are not incompatible with mine. The fixup
address is offset with a large constant, but this does not affect the
sort order (since that is based on the other member), and the swap
operation that adds/subtracts the delta should not care about the
class bits. (I don't see any changes to sort_extable() in Tony's
patch)

@Tony: any comments? And do you have any objections to the ia64 patch
in this series?

I agree that it makes sense to define a macro to emit the extable
entries in this patch, but I am not sure how that extrapolates to the
other architectures, and testing those is going to be cumbersome for
me, so I'd prefer to keep that a local change for arm64 for now.

Thanks,
Ard.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:28             ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-04 19:28 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Luck, Tony, Will Deacon, linux-alpha, linux-kernel,
	linux-arm-kernel, linux-ia64, linux-s390, x86, mingo,
	heiko.carstens, schwidefsky, mattst88, ink, rth, Yu, Fenghua,
	catalin.marinas, arnd, akpm, mark.rutland, marc.zyngier

On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> On 01/04/2016 10:20 AM, Luck, Tony wrote:
>>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
>>
>> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
>> add different classes of exception table (so I can tag some instructions as being
>> suitable for fixup from the machine check handler).  So it might not be generic
>> for much longer.
>>
>> http://marc.info/?l=linux-kernel&m\x145187079504846&w=2
>>
>
> I suspect that means we will also need to go back to arch-specific
> sorting for x86.
>

AFAICT, Tony's patches are not incompatible with mine. The fixup
address is offset with a large constant, but this does not affect the
sort order (since that is based on the other member), and the swap
operation that adds/subtracts the delta should not care about the
class bits. (I don't see any changes to sort_extable() in Tony's
patch)

@Tony: any comments? And do you have any objections to the ia64 patch
in this series?

I agree that it makes sense to define a macro to emit the extable
entries in this patch, but I am not sure how that extrapolates to the
other architectures, and testing those is going to be cumbersome for
me, so I'd prefer to keep that a local change for arm64 for now.

Thanks,
Ard.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:28             ` Ard Biesheuvel
  0 siblings, 0 replies; 56+ messages in thread
From: Ard Biesheuvel @ 2016-01-04 19:28 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Luck, Tony, Will Deacon, linux-alpha, linux-kernel,
	linux-arm-kernel, linux-ia64, linux-s390, x86, mingo,
	heiko.carstens, schwidefsky, mattst88, ink, rth, Yu, Fenghua,
	catalin.marinas, arnd, akpm@linux-foundation.org

On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> On 01/04/2016 10:20 AM, Luck, Tony wrote:
>>> May I humbly ask why the [Finnish] you don't use the equivalent of the
>>> x86 _ASM_EXTABLE() macro?  In fact, why don't we make that one generic, too?
>>
>> I'm messing with that right now (with help from Andy Lutomirski and Boris) to
>> add different classes of exception table (so I can tag some instructions as being
>> suitable for fixup from the machine check handler).  So it might not be generic
>> for much longer.
>>
>> http://marc.info/?l=linux-kernel&m=145187079504846&w=2
>>
>
> I suspect that means we will also need to go back to arch-specific
> sorting for x86.
>

AFAICT, Tony's patches are not incompatible with mine. The fixup
address is offset with a large constant, but this does not affect the
sort order (since that is based on the other member), and the swap
operation that adds/subtracts the delta should not care about the
class bits. (I don't see any changes to sort_extable() in Tony's
patch)

@Tony: any comments? And do you have any objections to the ia64 patch
in this series?

I agree that it makes sense to define a macro to emit the extable
entries in this patch, but I am not sure how that extrapolates to the
other architectures, and testing those is going to be cumbersome for
me, so I'd prefer to keep that a local change for arm64 for now.

Thanks,
Ard.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
  2016-01-04 19:28             ` Ard Biesheuvel
  (?)
  (?)
@ 2016-01-04 19:49               ` Luck, Tony
  -1 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 19:49 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: H. Peter Anvin, Will Deacon, linux-alpha, linux-kernel,
	linux-arm-kernel, linux-ia64, linux-s390, x86, mingo,
	heiko.carstens, schwidefsky, mattst88, ink, rth, Yu, Fenghua,
	catalin.marinas, arnd, akpm, mark.rutland, marc.zyngier

On Mon, Jan 04, 2016 at 08:28:52PM +0100, Ard Biesheuvel wrote:
> On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> > I suspect that means we will also need to go back to arch-specific
> > sorting for x86.
> >
> 
> AFAICT, Tony's patches are not incompatible with mine. The fixup
> address is offset with a large constant, but this does not affect the
> sort order (since that is based on the other member), and the swap
> operation that adds/subtracts the delta should not care about the
> class bits. (I don't see any changes to sort_extable() in Tony's
> patch)

Correct. Sorting is by the "insn" field (which I did not change).
The "fixup" field is just modified by an offset value, so survives
the math when moved to a new slot by the sort.

> @Tony: any comments? And do you have any objections to the ia64 patch
> in this series?
The ia64 bits look OK. I haven't tested, but add my Acked-by: anyway.

-Tony

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:49               ` Luck, Tony
  0 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 19:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jan 04, 2016 at 08:28:52PM +0100, Ard Biesheuvel wrote:
> On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> > I suspect that means we will also need to go back to arch-specific
> > sorting for x86.
> >
> 
> AFAICT, Tony's patches are not incompatible with mine. The fixup
> address is offset with a large constant, but this does not affect the
> sort order (since that is based on the other member), and the swap
> operation that adds/subtracts the delta should not care about the
> class bits. (I don't see any changes to sort_extable() in Tony's
> patch)

Correct. Sorting is by the "insn" field (which I did not change).
The "fixup" field is just modified by an offset value, so survives
the math when moved to a new slot by the sort.

> @Tony: any comments? And do you have any objections to the ia64 patch
> in this series?
The ia64 bits look OK. I haven't tested, but add my Acked-by: anyway.

-Tony

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:49               ` Luck, Tony
  0 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 19:49 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: H. Peter Anvin, Will Deacon, linux-alpha, linux-kernel,
	linux-arm-kernel, linux-ia64, linux-s390, x86, mingo,
	heiko.carstens, schwidefsky, mattst88, ink, rth, Yu, Fenghua,
	catalin.marinas, arnd, akpm, mark.rutland, marc.zyngier

On Mon, Jan 04, 2016 at 08:28:52PM +0100, Ard Biesheuvel wrote:
> On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> > I suspect that means we will also need to go back to arch-specific
> > sorting for x86.
> >
> 
> AFAICT, Tony's patches are not incompatible with mine. The fixup
> address is offset with a large constant, but this does not affect the
> sort order (since that is based on the other member), and the swap
> operation that adds/subtracts the delta should not care about the
> class bits. (I don't see any changes to sort_extable() in Tony's
> patch)

Correct. Sorting is by the "insn" field (which I did not change).
The "fixup" field is just modified by an offset value, so survives
the math when moved to a new slot by the sort.

> @Tony: any comments? And do you have any objections to the ia64 patch
> in this series?
The ia64 bits look OK. I haven't tested, but add my Acked-by: anyway.

-Tony

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 6/6] arm64: switch to relative exception tables
@ 2016-01-04 19:49               ` Luck, Tony
  0 siblings, 0 replies; 56+ messages in thread
From: Luck, Tony @ 2016-01-04 19:49 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: H. Peter Anvin, Will Deacon, linux-alpha, linux-kernel,
	linux-arm-kernel, linux-ia64, linux-s390, x86, mingo,
	heiko.carstens, schwidefsky, mattst88, ink, rth, Yu, Fenghua,
	catalin.marinas, arnd, akpm@linux-foundation.org

On Mon, Jan 04, 2016 at 08:28:52PM +0100, Ard Biesheuvel wrote:
> On 4 January 2016 at 20:21, H. Peter Anvin <hpa@zytor.com> wrote:
> > I suspect that means we will also need to go back to arch-specific
> > sorting for x86.
> >
> 
> AFAICT, Tony's patches are not incompatible with mine. The fixup
> address is offset with a large constant, but this does not affect the
> sort order (since that is based on the other member), and the swap
> operation that adds/subtracts the delta should not care about the
> class bits. (I don't see any changes to sort_extable() in Tony's
> patch)

Correct. Sorting is by the "insn" field (which I did not change).
The "fixup" field is just modified by an offset value, so survives
the math when moved to a new slot by the sort.

> @Tony: any comments? And do you have any objections to the ia64 patch
> in this series?
The ia64 bits look OK. I haven't tested, but add my Acked-by: anyway.

-Tony

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 1/6] extable: add support for relative extables to search and sort routines
  2016-01-03 16:05   ` Ard Biesheuvel
  (?)
@ 2016-01-04 21:05     ` Helge Deller
  -1 siblings, 0 replies; 56+ messages in thread
From: Helge Deller @ 2016-01-04 21:05 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-alpha, linux-kernel, linux-arm-kernel,
	linux-ia64, linux-s390, x86, hpa, mingo, heiko.carstens,
	schwidefsky, mattst88, ink, rth, tony.luck, fenghua.yu,
	catalin.marinas, will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier

On 03.01.2016 17:05, Ard Biesheuvel wrote:
> 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.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

I tested the generic parts with an upcoming patch which handles relative
exception tables on the parisc platform.
Everything worked as expected.
So for the non arch-relevant changes:
Acked-by: Helge Deller <deller@gmx.de>


Helge

> ---
>  lib/extable.c | 50 ++++++++++++++++----
>  1 file changed, 41 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/extable.c b/lib/extable.c
> index 4cac81ec225e..0be02ad561e9 100644
> --- a/lib/extable.c
> +++ b/lib/extable.c
> @@ -14,7 +14,37 @@
>  #include <linux/sort.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_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
>   * 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)
>  	const struct exception_table_entry *x = a, *y = b;
>  
>  	/* avoid overflow */
> -	if (x->insn > y->insn)
> +	if (ex_to_insn(x) > ex_to_insn(y))
>  		return 1;
> -	if (x->insn < y->insn)
> +	if (ex_to_insn(x) < ex_to_insn(y))
>  		return -1;
>  	return 0;
>  }
> @@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start,
>  		  struct exception_table_entry *finish)
>  {
>  	sort(start, finish - start, sizeof(struct exception_table_entry),
> -	     cmp_ex, NULL);
> +	     cmp_ex, swap_ex);
>  }
>  
>  #ifdef CONFIG_MODULES
> @@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start,
>  void trim_init_extable(struct module *m)
>  {
>  	/*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->num_exentries--;
>  	}
>  	/*trim the end*/
>  	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--;
>  }
>  #endif /* CONFIG_MODULES */
> @@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first,
>  		 * careful, the distance between value and insn
>  		 * can be larger than MAX_LONG:
>  		 */
> -		if (mid->insn < value)
> +		if (ex_to_insn(mid) < value)
>  			first = mid + 1;
> -		else if (mid->insn > value)
> +		else if (ex_to_insn(mid) > value)
>  			last = mid - 1;
>  		else
>  			return mid;
> -        }
> -        return NULL;
> +	}
> +	return NULL;
>  }
>  #endif
> 


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [PATCH 1/6] extable: add support for relative extables to search and sort routines
@ 2016-01-04 21:05     ` Helge Deller
  0 siblings, 0 replies; 56+ messages in thread
From: Helge Deller @ 2016-01-04 21:05 UTC (permalink / raw)
  To: linux-arm-kernel

On 03.01.2016 17:05, Ard Biesheuvel wrote:
> 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.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

I tested the generic parts with an upcoming patch which handles relative
exception tables on the parisc platform.
Everything worked as expected.
So for the non arch-relevant changes:
Acked-by: Helge Deller <deller@gmx.de>


Helge

> ---
>  lib/extable.c | 50 ++++++++++++++++----
>  1 file changed, 41 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/extable.c b/lib/extable.c
> index 4cac81ec225e..0be02ad561e9 100644
> --- a/lib/extable.c
> +++ b/lib/extable.c
> @@ -14,7 +14,37 @@
>  #include <linux/sort.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_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
>   * 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)
>  	const struct exception_table_entry *x = a, *y = b;
>  
>  	/* avoid overflow */
> -	if (x->insn > y->insn)
> +	if (ex_to_insn(x) > ex_to_insn(y))
>  		return 1;
> -	if (x->insn < y->insn)
> +	if (ex_to_insn(x) < ex_to_insn(y))
>  		return -1;
>  	return 0;
>  }
> @@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start,
>  		  struct exception_table_entry *finish)
>  {
>  	sort(start, finish - start, sizeof(struct exception_table_entry),
> -	     cmp_ex, NULL);
> +	     cmp_ex, swap_ex);
>  }
>  
>  #ifdef CONFIG_MODULES
> @@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start,
>  void trim_init_extable(struct module *m)
>  {
>  	/*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->num_exentries--;
>  	}
>  	/*trim the end*/
>  	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--;
>  }
>  #endif /* CONFIG_MODULES */
> @@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first,
>  		 * careful, the distance between value and insn
>  		 * can be larger than MAX_LONG:
>  		 */
> -		if (mid->insn < value)
> +		if (ex_to_insn(mid) < value)
>  			first = mid + 1;
> -		else if (mid->insn > value)
> +		else if (ex_to_insn(mid) > value)
>  			last = mid - 1;
>  		else
>  			return mid;
> -        }
> -        return NULL;
> +	}
> +	return NULL;
>  }
>  #endif
> 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [PATCH 1/6] extable: add support for relative extables to search and sort routines
@ 2016-01-04 21:05     ` Helge Deller
  0 siblings, 0 replies; 56+ messages in thread
From: Helge Deller @ 2016-01-04 21:05 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-alpha, linux-kernel, linux-arm-kernel,
	linux-ia64, linux-s390, x86, hpa, mingo, heiko.carstens,
	schwidefsky, mattst88, ink, rth, tony.luck, fenghua.yu,
	catalin.marinas, will.deacon, arnd, akpm
  Cc: mark.rutland, marc.zyngier

On 03.01.2016 17:05, Ard Biesheuvel wrote:
> 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.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

I tested the generic parts with an upcoming patch which handles relative
exception tables on the parisc platform.
Everything worked as expected.
So for the non arch-relevant changes:
Acked-by: Helge Deller <deller@gmx.de>


Helge

> ---
>  lib/extable.c | 50 ++++++++++++++++----
>  1 file changed, 41 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/extable.c b/lib/extable.c
> index 4cac81ec225e..0be02ad561e9 100644
> --- a/lib/extable.c
> +++ b/lib/extable.c
> @@ -14,7 +14,37 @@
>  #include <linux/sort.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_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
>   * 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)
>  	const struct exception_table_entry *x = a, *y = b;
>  
>  	/* avoid overflow */
> -	if (x->insn > y->insn)
> +	if (ex_to_insn(x) > ex_to_insn(y))
>  		return 1;
> -	if (x->insn < y->insn)
> +	if (ex_to_insn(x) < ex_to_insn(y))
>  		return -1;
>  	return 0;
>  }
> @@ -37,7 +67,7 @@ void sort_extable(struct exception_table_entry *start,
>  		  struct exception_table_entry *finish)
>  {
>  	sort(start, finish - start, sizeof(struct exception_table_entry),
> -	     cmp_ex, NULL);
> +	     cmp_ex, swap_ex);
>  }
>  
>  #ifdef CONFIG_MODULES
> @@ -48,13 +78,15 @@ void sort_extable(struct exception_table_entry *start,
>  void trim_init_extable(struct module *m)
>  {
>  	/*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->num_exentries--;
>  	}
>  	/*trim the end*/
>  	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--;
>  }
>  #endif /* CONFIG_MODULES */
> @@ -81,13 +113,13 @@ search_extable(const struct exception_table_entry *first,
>  		 * careful, the distance between value and insn
>  		 * can be larger than MAX_LONG:
>  		 */
> -		if (mid->insn < value)
> +		if (ex_to_insn(mid) < value)
>  			first = mid + 1;
> -		else if (mid->insn > value)
> +		else if (ex_to_insn(mid) > value)
>  			last = mid - 1;
>  		else
>  			return mid;
> -        }
> -        return NULL;
> +	}
> +	return NULL;
>  }
>  #endif
> 


^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2016-01-04 21:07 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-03 16:05 [PATCH 0/6] generic relative extable support Ard Biesheuvel
2016-01-03 16:05 ` Ard Biesheuvel
2016-01-03 16:05 ` Ard Biesheuvel
2016-01-03 16:05 ` [PATCH 1/6] extable: add support for relative extables to search and sort routines Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-04 21:05   ` Helge Deller
2016-01-04 21:05     ` Helge Deller
2016-01-04 21:05     ` Helge Deller
2016-01-03 16:05 ` [PATCH 2/6] alpha/extable: use generic " Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05 ` [PATCH 3/6] s390/extable: " Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05 ` [PATCH 4/6] x86/extable: " Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05 ` [PATCH 5/6] ia64/extable: " Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05 ` [PATCH 6/6] arm64: switch to relative exception tables Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-03 16:05   ` Ard Biesheuvel
2016-01-04 14:46   ` Will Deacon
2016-01-04 14:46     ` Will Deacon
2016-01-04 14:46     ` Will Deacon
2016-01-04 18:13     ` H. Peter Anvin
2016-01-04 18:13       ` H. Peter Anvin
2016-01-04 18:13       ` H. Peter Anvin
2016-01-04 18:20       ` Luck, Tony
2016-01-04 18:20         ` Luck, Tony
2016-01-04 18:20         ` Luck, Tony
2016-01-04 18:20         ` Luck, Tony
2016-01-04 18:47         ` H. Peter Anvin
2016-01-04 18:47           ` H. Peter Anvin
2016-01-04 18:47           ` H. Peter Anvin
2016-01-04 18:47           ` H. Peter Anvin
2016-01-04 19:21         ` H. Peter Anvin
2016-01-04 19:21           ` H. Peter Anvin
2016-01-04 19:21           ` H. Peter Anvin
2016-01-04 19:21           ` H. Peter Anvin
2016-01-04 19:28           ` Ard Biesheuvel
2016-01-04 19:28             ` Ard Biesheuvel
2016-01-04 19:28             ` Ard Biesheuvel
2016-01-04 19:28             ` Ard Biesheuvel
2016-01-04 19:49             ` Luck, Tony
2016-01-04 19:49               ` Luck, Tony
2016-01-04 19:49               ` Luck, Tony
2016-01-04 19:49               ` Luck, Tony
2016-01-04 11:20 ` [PATCH 0/6] generic relative extable support Heiko Carstens
2016-01-04 11:20   ` Heiko Carstens
2016-01-04 11:20   ` Heiko Carstens
2016-01-04 18:15   ` H. Peter Anvin
2016-01-04 18:15     ` H. Peter Anvin
2016-01-04 18:15     ` H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.