From patchwork Wed Jan 27 10:55:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 60611 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2508408lbb; Wed, 27 Jan 2016 02:55:54 -0800 (PST) X-Received: by 10.98.7.156 with SMTP id 28mr41586845pfh.49.1453892154357; Wed, 27 Jan 2016 02:55:54 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si3071536pfi.36.2016.01.27.02.55.54; Wed, 27 Jan 2016 02:55:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754611AbcA0Kzs (ORCPT + 30 others); Wed, 27 Jan 2016 05:55:48 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:32954 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754387AbcA0Kzf (ORCPT ); Wed, 27 Jan 2016 05:55:35 -0500 Received: by mail-wm0-f54.google.com with SMTP id 123so146362787wmz.0 for ; Wed, 27 Jan 2016 02:55:34 -0800 (PST) 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=0aGpHOCn76abuSMXHWZ/9WePKJSV4Qi7H/jHAPByYXQ=; b=RT1ov3XSTqpQJBA5zlIAhFtV7DhDO3g+HEw1kOGVMT+BhjdcmNcge9gJJKIxfjnGMD hqQ7S2NT+67oa3Dd59TWi0EBZxikGFWBYsyIuFMNRBm3SCvmN2/zs2abqgzbDluJ0lL1 o5ndZTqViskPsXRqkh2enp5g9RqA6BACQ7Vzk= 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=0aGpHOCn76abuSMXHWZ/9WePKJSV4Qi7H/jHAPByYXQ=; b=KPhNvYJaDQXz0pvqW3t1wO+yCvBmqtbE7P/MFkttzMa9rFCWi/ZrIZkvlWI0cjtYQt 63TEm8LumgE91Fsf8YTr4ycyLqfF31d4HypcUFbUgbMG8QL6jxMSXqwH/xrMeiWrmtch 8g29FHA8GSzX9cVLjwUgyqPRI9eOlzFpxaatbvf4Hy6gDNA/TOve62B3SEu9KnidQDrb nFrE1VhpPHrS1fccJoWqDPAGR6SC/JMQ8J0KvwOHtbmHWjmXEm2vw4NU2OllK1HEp3RQ RcfdflNrKl3um68Tn0gR4fjAX1dNzNVXsUt92dYQS8bpXTA9+otq788+3uJnm5b74k7B KLhg== X-Gm-Message-State: AG10YOTUdVT/QJvlxOX3UZljqYMEMqvxQ+F0lWI5CNUMZxClmd9offSlWv2pC6olk3zwF8xt X-Received: by 10.194.173.65 with SMTP id bi1mr28233127wjc.110.1453892134158; Wed, 27 Jan 2016 02:55:34 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id x186sm1199196wmg.19.2016.01.27.02.55.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Jan 2016 02:55:33 -0800 (PST) From: Ard Biesheuvel To: akpm@linux-foundation.org, 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, heiko.carstens@de.ibm.com, rth@twiddle.net, tony.luck@intel.com, will.deacon@arm.com Cc: deller@gmx.de, Ard Biesheuvel Subject: [PATCH v2 resend 2/6] alpha/extable: use generic search and sort routines Date: Wed, 27 Jan 2016 11:55:19 +0100 Message-Id: <1453892123-17973-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1453892123-17973-1-git-send-email-ard.biesheuvel@linaro.org> References: <1453892123-17973-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Acked-by: Richard Henderson Signed-off-by: Ard Biesheuvel --- 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(-) -- 2.5.0 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 -#include -#include - -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; -}