From patchwork Wed Jan 27 10:55:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 60613 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2508771lbb; Wed, 27 Jan 2016 02:56:47 -0800 (PST) X-Received: by 10.66.161.227 with SMTP id xv3mr41587346pab.117.1453892207804; Wed, 27 Jan 2016 02:56:47 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id va5si8787957pac.165.2016.01.27.02.56.47; Wed, 27 Jan 2016 02:56:47 -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 S1754677AbcA0K4p (ORCPT + 30 others); Wed, 27 Jan 2016 05:56:45 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:33088 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754499AbcA0Kzl (ORCPT ); Wed, 27 Jan 2016 05:55:41 -0500 Received: by mail-wm0-f54.google.com with SMTP id 123so146366829wmz.0 for ; Wed, 27 Jan 2016 02:55:41 -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=xZnnyBMH0fyy0Z/wFXzBvL2zB3YXPEN6BOAaMmpfNKU=; b=c02JlbkrWyE5u66femKLkJmqVLbi+WwqS6Kw+ldetByczQfOhzIB1lIbyHg7zxppwM 0TxJOqXLvAFTK5ibcQKBSUwmqiIOCOfJIkxBpIWL0vm0yzd02xZ/efBN4qjyXxOyH/ZW XS61NcA3SFQifwbuO2tP82W8aHgC6Xa9h/+Bk= 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=xZnnyBMH0fyy0Z/wFXzBvL2zB3YXPEN6BOAaMmpfNKU=; b=VjhKUaPJUyKwAmhoM4EXefrS74TJZe0F1jft2QnJWwyEKYDTAaPMkubKN0Go0nTEFM dF1K+7tzg7VD68BAj9x3SbWvFju+I90X0J4DDmoXGj5T9pSJks14Ct3SdDVX71oMwwjg 6uQkHLUI2bB/9uKUd96Qzh7G5nJ8LKoGrnqk1ZYmjDVyMkJ3685MR63v+QidUN67ZypD Db0NdXXuOV/bDH9Xnwsoj3XzeWMqdn8+qEPgbF9g2roPV2ZQbMWmZH34b3C68f+XUboZ LdLNEAmaHZ6XQSv+Is1ArF0x+hHiZ0iMXls2GLitdR1eUzI9Gay+3YMWx490YlP1Wb9+ sxgQ== X-Gm-Message-State: AG10YOR5IiVXuGnf1rQhzbpDk2EYDUMDxfFZIaNV6vd0Q0zeCozW0yvEL57JWRAZAzgvY1S0 X-Received: by 10.28.98.198 with SMTP id w189mr28156896wmb.39.1453892140483; Wed, 27 Jan 2016 02:55:40 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id x186sm1199196wmg.19.2016.01.27.02.55.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Jan 2016 02:55:39 -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 5/6] ia64/extable: use generic search and sort routines Date: Wed, 27 Jan 2016 11:55:22 +0100 Message-Id: <1453892123-17973-6-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: Tony Luck Signed-off-by: Ard Biesheuvel --- arch/ia64/include/asm/uaccess.h | 8 +- arch/ia64/mm/extable.c | 97 +------------------- 2 files changed, 4 insertions(+), 101 deletions(-) -- 2.5.0 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 */ -#include - #include -#include - -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)