Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1300325

[PATCH 1/6] extable: add support for relative extables to search and sort routines

Path csiph.com!fu-berlin.de!bofh.it!news.nic.it!robomod
From Ard Biesheuvel <ard.biesheuvel@linaro.org>
Newsgroups linux.kernel
Subject [PATCH 1/6] extable: add support for relative extables to search and sort routines
Date Sun, 03 Jan 2016 17:10:02 +0100
Message-ID <qMToe-7DP-19@gated-at.bofh.it> (permalink)
References <qMTod-7DP-3@gated-at.bofh.it>
X-Original-To linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-s390@vger.kernel.org, x86@kernel.org, hpa@zytor.com, mingo@redhat.com, heiko.carstens@de.ibm.com, schwidefsky@de.ibm.com, mattst88@gmail.com, ink@jurassic.park.msu.ru, rth@twiddle.net, tony.luck@intel.com, fenghua.yu@intel.com, catalin.marinas@arm.com, will.deacon@arm.com, arnd@arndb.de, akpm@linux-foundation.org
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qd2asYQFnQw2fF4FpFyCDQL+rTBxDs7n5fhzJe57xcc=; b=gbBoZ/3D2jZxoPC/9wvg9I1KJ5sHlJg67c1zUg8lxFGYaz/pmf9Ktb70kHJqE2HUBY 0JfBhP2AGVdq5wxdbU69I6KI3CjHu3Le6vfTRDVLa91w72XslFnxeCldCUKVJhPnN+n5 meo1HuABiGc8wKgTHeDsEcQe5OrVqJc9gJcvU=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Qd2asYQFnQw2fF4FpFyCDQL+rTBxDs7n5fhzJe57xcc=; b=MTDAC0eEkmFKjAYv106wndeo6S+xY4Yi7e2VhGDzxEj85M4ZzKn0S4NAhkIDAqxtpj 0qJA5RuUg30N1d/hbkQZqUW4elMXo1ZlNZUO6d7kgIOWw+wZzpHGEtpiraHDvBHtMW+G 1dsXlnj6OUs801+ce9BFm6OSbUYwabri37D4iXxXws+/Hj0++fNlMhmZ0n2SnToKQJsF Tv4HNkZyyfRBrfJzxh5MyDhiEwxUpZdSevkbzMWcdLmdPqd4dIFEZC322H4Xcq1I6zNa JtLMJDW9ukfxmSQrymN1tv5AsWMvMr04b7WAHS+iJrXKV9T6t6Fzi0aAonx3d7wZ7OFS Zpsw==
X-Gm-Message-State ALoCoQkZK0M4zKTetjsokA7w+Wka5mw45y1QxXEzVo7hN6inM6M4E9X6rQEWy9V0grC6ZUsSTNKBvN1Phb/WjWKCatLn8SDCLw==
X-Received by 10.28.85.70 with SMTP id j67mr96720362wmb.80.1451837177680; Sun, 03 Jan 2016 08:06:17 -0800 (PST)
X-Mailer git-send-email 1.9.1
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 116
Organization linux.* mail to news gateway
X-Original-Cc mark.rutland@arm.com, marc.zyngier@arm.com, Ard Biesheuvel <ard.biesheuvel@linaro.org>
X-Original-Date Sun, 3 Jan 2016 17:05:52 +0100
X-Original-Message-ID <1451837157-447-2-git-send-email-ard.biesheuvel@linaro.org>
X-Original-References <1451837157-447-1-git-send-email-ard.biesheuvel@linaro.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1300325

Show key headers only | View raw


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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/6] generic relative extable support Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2016-01-03 17:10 +0100
  [PATCH 1/6] extable: add support for relative extables to search and sort routines Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2016-01-03 17:10 +0100
    Re: [PATCH 1/6] extable: add support for relative extables to search  and sort routines Helge Deller <deller@gmx.de> - 2016-01-04 22:10 +0100
  [PATCH 5/6] ia64/extable: use generic search and sort routines Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2016-01-03 17:10 +0100
  [PATCH 4/6] x86/extable: use generic search and sort routines Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2016-01-03 17:10 +0100
  [PATCH 6/6] arm64: switch to relative exception tables Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2016-01-03 17:10 +0100
    Re: [PATCH 6/6] arm64: switch to relative exception tables Will Deacon <will.deacon@arm.com> - 2016-01-04 15:50 +0100
      Re: [PATCH 6/6] arm64: switch to relative exception tables "H. Peter Anvin" <hpa@zytor.com> - 2016-01-04 19:20 +0100
        RE: [PATCH 6/6] arm64: switch to relative exception tables "Luck, Tony" <tony.luck@intel.com> - 2016-01-04 19:30 +0100
          Re: [PATCH 6/6] arm64: switch to relative exception tables "H. Peter Anvin" <hpa@zytor.com> - 2016-01-04 19:50 +0100
          Re: [PATCH 6/6] arm64: switch to relative exception tables Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2016-01-04 20:30 +0100
            Re: [PATCH 6/6] arm64: switch to relative exception tables "Luck, Tony" <tony.luck@intel.com> - 2016-01-04 20:50 +0100
          Re: [PATCH 6/6] arm64: switch to relative exception tables "H. Peter Anvin" <hpa@zytor.com> - 2016-01-04 20:30 +0100
  Re: [PATCH 0/6] generic relative extable support Heiko Carstens <heiko.carstens@de.ibm.com> - 2016-01-04 12:30 +0100
    Re: [PATCH 0/6] generic relative extable support "H. Peter Anvin" <hpa@zytor.com> - 2016-01-04 19:20 +0100

csiph-web