From patchwork Tue Jan 5 15:19:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 59191 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp6027777lbb; Tue, 5 Jan 2016 07:21:28 -0800 (PST) X-Received: by 10.66.180.48 with SMTP id dl16mr133368649pac.39.1452007287978; Tue, 05 Jan 2016 07:21:27 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xp4si67745203pab.1.2016.01.05.07.21.27; Tue, 05 Jan 2016 07:21:27 -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 S1752518AbcAEPVX (ORCPT + 29 others); Tue, 5 Jan 2016 10:21:23 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:38784 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752258AbcAEPUV (ORCPT ); Tue, 5 Jan 2016 10:20:21 -0500 Received: by mail-wm0-f45.google.com with SMTP id b14so34023333wmb.1 for ; Tue, 05 Jan 2016 07:20: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=xZnnyBMH0fyy0Z/wFXzBvL2zB3YXPEN6BOAaMmpfNKU=; b=BV4R5WP6CbtaiSxfz5o1dfhlLeolB4mq4PhmxY9m0W0VV03nzP+13LP51Zk3FTodMF REnEM26PwYcqwtiB2MbwjlfPKeyrpeYy+lkkspSckvuVpFxiuJIJvgBIYdPoxfBBUoSi /eDrtwTaMS4NPi65m2stR9yRW9Uj4frydRc/4= 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=ax+BVYJu3nqWM2c3IujgvJHz4mJuTcQRAHt7e0UR6NXKwEdZK0hGbkHUDEBtf10k3/ kR7dlZp0hn29MhbYbz083oa6ksHL3nK4PyM597EuIwMlZoAdojFWdHN3416K7d/JL9Kl IF+9KYt031ey0vHlefB3NBqlS6GcpJgydC0PXhhSzEftFgnaaxobHBvSdJ2kK7QsEIYw gagqR+HegLSfDYd9/ZIPsjxUrE3nvuvylyQqdk02vlS1U5ydu3vHLpCn3dMtFyYGjypi ihX10QQZzGJSzVIhk7u/j7uV2Hp6hclX3nXMkFvfy5ITz7f277CpLPy/Az6zv6JZGzw1 RGfw== X-Gm-Message-State: ALoCoQmfZkKpVs+TeWU371Wa5AxFVXM2z6eEJAiqEzC+/phSo1c+d/bsUy2AWZbOYKmlkE5pzNFYRMoDGfvkASVUDIhihgToLw== X-Received: by 10.28.130.7 with SMTP id e7mr4573505wmd.68.1452007220121; Tue, 05 Jan 2016 07:20: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 c203sm4058303wmd.5.2016.01.05.07.20.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Jan 2016 07:20:19 -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, 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 Cc: deller@gmx.de, mark.rutland@arm.com, Ard Biesheuvel Subject: [PATCH v2 5/6] ia64/extable: use generic search and sort routines Date: Tue, 5 Jan 2016 16:19:39 +0100 Message-Id: <1452007180-27411-6-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452007180-27411-1-git-send-email-ard.biesheuvel@linaro.org> References: <1452007180-27411-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 -- 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/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)