From patchwork Fri Feb 12 18:05:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 8294971 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9050F9F1E0 for ; Fri, 12 Feb 2016 18:09:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2682920461 for ; Fri, 12 Feb 2016 18:09:34 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 07CED20444 for ; Fri, 12 Feb 2016 18:09:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUI8O-00080r-KP; Fri, 12 Feb 2016 18:08:00 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUI8G-0007lE-UN for xen-devel@lists.xenproject.org; Fri, 12 Feb 2016 18:07:53 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 15/02-15353-87F1EB65; Fri, 12 Feb 2016 18:07:52 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1455300470!22061583!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26172 invoked from network); 12 Feb 2016 18:07:51 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-2.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 12 Feb 2016 18:07:51 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1CI6hUq025056 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 12 Feb 2016 18:06:44 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1CI6hfT014619 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 12 Feb 2016 18:06:43 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u1CI6gvj008936; Fri, 12 Feb 2016 18:06:42 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 12 Feb 2016 10:06:42 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id 30FCF6A4BFA; Fri, 12 Feb 2016 13:06:40 -0500 (EST) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com, konrad@kernel.org, mpohlack@amazon.de, ross.lagerwall@citrix.com, sasha.levin@citrix.com, jinsong.liu@alibaba-inc.com, Keir Fraser , Jan Beulich , xen-devel@lists.xen.org Date: Fri, 12 Feb 2016 13:05:48 -0500 Message-Id: <1455300361-13092-11-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1455300361-13092-1-git-send-email-konrad.wilk@oracle.com> References: <1455300361-13092-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v3 10/23] xsplice: Add support for exception tables. (v2) X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ross Lagerwall Add support for exception tables contained within xSplice payloads. If an exception occurs search either the main exception table or a particular active payload's exception table depending on the instruction pointer. Signed-off-by: Ross Lagerwall Signed-off-by: Konrad Rzeszutek Wilk --- v2: - s/module/payload/ - sanity checks. --- xen/arch/x86/extable.c | 36 +++++++++++++++++++++-------------- xen/common/xsplice.c | 44 +++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/uaccess.h | 5 +++++ xen/include/xen/xsplice.h | 5 +++++ 4 files changed, 76 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c index 89b5bcb..2787a92 100644 --- a/xen/arch/x86/extable.c +++ b/xen/arch/x86/extable.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #define EX_FIELD(ptr, field) ((unsigned long)&(ptr)->field + (ptr)->field) @@ -18,7 +19,7 @@ static inline unsigned long ex_cont(const struct exception_table_entry *x) return EX_FIELD(x, cont); } -static int __init cmp_ex(const void *a, const void *b) +static int cmp_ex(const void *a, const void *b) { const struct exception_table_entry *l = a, *r = b; unsigned long lip = ex_addr(l); @@ -33,7 +34,7 @@ static int __init cmp_ex(const void *a, const void *b) } #ifndef swap_ex -static void __init swap_ex(void *a, void *b, int size) +static void swap_ex(void *a, void *b, int size) { struct exception_table_entry *l = a, *r = b, tmp; long delta = b - a; @@ -46,19 +47,23 @@ static void __init swap_ex(void *a, void *b, int size) } #endif -void __init sort_exception_tables(void) +void sort_exception_table(struct exception_table_entry *start, + struct exception_table_entry *stop) { - sort(__start___ex_table, __stop___ex_table - __start___ex_table, - sizeof(struct exception_table_entry), cmp_ex, swap_ex); - sort(__start___pre_ex_table, - __stop___pre_ex_table - __start___pre_ex_table, + sort(start, stop - start, sizeof(struct exception_table_entry), cmp_ex, swap_ex); } -static inline unsigned long -search_one_table(const struct exception_table_entry *first, - const struct exception_table_entry *last, - unsigned long value) +void __init sort_exception_tables(void) +{ + sort_exception_table(__start___ex_table, __stop___ex_table); + sort_exception_table(__start___pre_ex_table, __stop___pre_ex_table); +} + +unsigned long +search_one_extable(const struct exception_table_entry *first, + const struct exception_table_entry *last, + unsigned long value) { const struct exception_table_entry *mid; long diff; @@ -80,15 +85,18 @@ search_one_table(const struct exception_table_entry *first, unsigned long search_exception_table(unsigned long addr) { - return search_one_table( - __start___ex_table, __stop___ex_table-1, addr); + if ( likely(is_kernel(addr)) ) + return search_one_extable( + __start___ex_table, __stop___ex_table-1, addr); + else + return search_module_extables(addr); } unsigned long search_pre_exception_table(struct cpu_user_regs *regs) { unsigned long addr = (unsigned long)regs->eip; - unsigned long fixup = search_one_table( + unsigned long fixup = search_one_extable( __start___pre_ex_table, __stop___pre_ex_table-1, addr); if ( fixup ) { diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 7f71ac6..d863a99 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -46,6 +46,10 @@ struct payload { size_t core_text_size; /* Only .text size. */ struct bug_frame *start_bug_frames[BUGFRAME_NR]; /* .bug.frame patching. */ struct bug_frame *stop_bug_frames[BUGFRAME_NR]; +#ifdef CONFIG_X86 + struct exception_table_entry *start_ex_table; + struct exception_table_entry *stop_ex_table; +#endif char name[XEN_XSPLICE_NAME_SIZE + 1];/* Name of it. */ }; @@ -686,6 +690,20 @@ static int find_special_sections(struct payload *payload, payload->start_bug_frames[i] = (struct bug_frame *)sec->load_addr; payload->stop_bug_frames[i] = (struct bug_frame *)(sec->load_addr + sec->sec->sh_size); } +#ifdef CONFIG_X86 + sec = xsplice_elf_sec_by_name(elf, ".ex_table"); + if ( sec ) + { + if ( ( !sec->sec->sh_size ) || + ( sec->sec->sh_size % sizeof *sec->load_addr ) ) + return -EINVAL; + + payload->start_ex_table = (struct exception_table_entry *)sec->load_addr; + payload->stop_ex_table = (struct exception_table_entry *)(sec->load_addr + sec->sec->sh_size); + + sort_exception_table(payload->start_ex_table, payload->stop_ex_table); + } +#endif return 0; } @@ -1050,6 +1068,32 @@ bool_t is_active_module_text(unsigned long addr) return 0; } +#ifdef CONFIG_X86 +unsigned long search_module_extables(unsigned long addr) +{ + struct payload *data; + unsigned long ret; + + /* No locking since this list is only ever changed during apply or revert + * context. */ + list_for_each_entry ( data, &applied_list, applied_list ) + { + if ( !data->start_ex_table ) + continue; + if ( !((void *)addr >= data->payload_address && + (void *)addr < (data->payload_address + data->core_text_size))) + continue; + + ret = search_one_extable(data->start_ex_table, data->stop_ex_table - 1, + addr); + if ( ret ) + return ret; + } + + return 0; +} +#endif + static int __init xsplice_init(void) { register_keyhandler('x', xsplice_printall, "print xsplicing info", 1); diff --git a/xen/include/asm-x86/uaccess.h b/xen/include/asm-x86/uaccess.h index 947470d..9e67bf0 100644 --- a/xen/include/asm-x86/uaccess.h +++ b/xen/include/asm-x86/uaccess.h @@ -276,6 +276,11 @@ extern struct exception_table_entry __start___pre_ex_table[]; extern struct exception_table_entry __stop___pre_ex_table[]; extern unsigned long search_exception_table(unsigned long); +extern unsigned long search_one_extable(const struct exception_table_entry *first, + const struct exception_table_entry *last, + unsigned long value); extern void sort_exception_tables(void); +extern void sort_exception_table(struct exception_table_entry *start, + struct exception_table_entry *stop); #endif /* __X86_UACCESS_H__ */ diff --git a/xen/include/xen/xsplice.h b/xen/include/xen/xsplice.h index c257b3a..3a9948a 100644 --- a/xen/include/xen/xsplice.h +++ b/xen/include/xen/xsplice.h @@ -29,6 +29,7 @@ void do_xsplice(void); struct bug_frame *xsplice_find_bug(const char *eip, int *id); bool_t is_module(const void *addr); bool_t is_active_module_text(unsigned long addr); +unsigned long search_module_extables(unsigned long addr); /* Arch hooks */ int xsplice_verify_elf(struct xsplice_elf *elf, uint8_t *data); @@ -59,5 +60,9 @@ static inline bool_t is_active_module_text(unsigned long addr) { return 0; } +static inline unsigned long search_module_extables(unsigned long addr) +{ + return 0; +} #endif #endif /* __XEN_XSPLICE_H__ */