From patchwork Sun Jan 3 16:05:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 59105 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp4917034lbb; Sun, 3 Jan 2016 08:08:04 -0800 (PST) X-Received: by 10.98.80.147 with SMTP id g19mr107304119pfj.26.1451837282247; Sun, 03 Jan 2016 08:08:02 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17si19183762pfd.90.2016.01.03.08.08.01; Sun, 03 Jan 2016 08:08:02 -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=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752196AbcACQGm (ORCPT + 29 others); Sun, 3 Jan 2016 11:06:42 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35126 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751983AbcACQGV (ORCPT ); Sun, 3 Jan 2016 11:06:21 -0500 Received: by mail-wm0-f46.google.com with SMTP id f206so117135489wmf.0 for ; Sun, 03 Jan 2016 08:06:20 -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=a/8gVTUAhiq/nL/wK0G8wrcp99m5DIKjyp3Os1Nz2Nc=; b=dOJVvxE53RUKqhmIlfTGw5wIZhan8pfj+LMKkGbrqT6D4nnIa3QZ+LZTREe2lKrjAU MiSB4U2wkQeFVBD6gkfaAUuFSdcaYPdmt6OTv2nqd6fbvUYSrVHogJRYeW19nPmcdIfd IIQ+yziTgB7xqMqBUEBRLouQqUg0q2uXKTquY= 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=a/8gVTUAhiq/nL/wK0G8wrcp99m5DIKjyp3Os1Nz2Nc=; b=P1dUwcf7IFAy0OBw66du0jFlj+wZmHNXJT5bJ2j+lWI5oSRLz+1v2CXVt5FqRq/gTe gUJhJYJwlT7n5Y0NIEdjrlCYNkbmefoo7WulY9ZBotUXrbwP2lADIq+/+nCfut6pyJ74 7fWSCVh6udJVU3c4B7w1LkMDDMKLNg1VSkhOo/8/IZjafBUjiOePJ0u6J9jUSrBG5DbJ 9xqNssvYGZKmAt90+0ecwNb2LfddCRzuQALjLxbWX23yqpNcB2+73zs+Y7AYfb+IlHkS NmwHgIs5DtyjDMkAau9+ZZg6+gIt38A5BCD7TX+GMLRQ+XhegoJvE4v3nw62PfZB1UQr MpOQ== X-Gm-Message-State: ALoCoQkxkSRDNx4tfcwaZZI9hhvZjjvrKXGYesLAQKmxr1+WrssHinUyIrKMKlO/LI4GIVnEiISf27HMeWgmqZ6xAy6nwIq/lg== X-Received: by 10.28.49.65 with SMTP id x62mr96258482wmx.49.1451837180021; Sun, 03 Jan 2016 08:06:20 -0800 (PST) Received: from localhost.localdomain (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by smtp.gmail.com with ESMTPSA id i196sm62524801wmf.23.2016.01.03.08.06.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Jan 2016 08:06:19 -0800 (PST) From: Ard Biesheuvel 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 Cc: mark.rutland@arm.com, marc.zyngier@arm.com, Ard Biesheuvel Subject: [PATCH 2/6] alpha/extable: use generic search and sort routines Date: Sun, 3 Jan 2016 17:05:53 +0100 Message-Id: <1451837157-447-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451837157-447-1-git-send-email-ard.biesheuvel@linaro.org> References: <1451837157-447-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. Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner 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(-) -- 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/ 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; -}