From patchwork Thu Mar 24 20:00:29 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: 8664431 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 19C339F326 for ; Thu, 24 Mar 2016 20:04:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05BC02037E for ; Thu, 24 Mar 2016 20:04:09 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E17E420380 for ; Thu, 24 Mar 2016 20:04:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajBRU-0007LH-FB; Thu, 24 Mar 2016 20:01:16 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajBRT-0007Kj-5n for xen-devel@lists.xenproject.org; Thu, 24 Mar 2016 20:01:15 +0000 Received: from [193.109.254.147] by server-5.bemta-14.messagelabs.com id 3F/D4-03497-A8744F65; Thu, 24 Mar 2016 20:01:14 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1458849672!33673686!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32200 invoked from network); 24 Mar 2016 20:01:13 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-7.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Mar 2016 20:01:13 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u2OK17Rr011542 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Mar 2016 20:01:07 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u2OK162x000371 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Mar 2016 20:01:07 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u2OK16go023720; Thu, 24 Mar 2016 20:01:06 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Mar 2016 13:01:06 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id C1E116A00E4; Thu, 24 Mar 2016 16:01:03 -0400 (EDT) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, konrad@kernel.org, andrew.cooper3@citrix.com, mpohlack@amazon.de, sasha.levin@oracle.com Date: Thu, 24 Mar 2016 16:00:29 -0400 Message-Id: <1458849640-22588-18-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458849640-22588-1-git-send-email-konrad.wilk@oracle.com> References: <1458849640-22588-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: Keir Fraser , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v5 17/28] xsplice: Add support for exception tables. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" 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. Also we add an test-case to make sure we have an exception that is handled. Signed-off-by: Ross Lagerwall Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Keir Fraser Cc: Jan Beulich Cc: Andrew Cooper v3: - s/module/payload/ - sanity checks. - Move code around. - s/module/payload/ v4: Use 'struct virtual_region' v5: - Expand test-case. --- xen/arch/x86/extable.c | 30 +++++++++++++++++------------- xen/arch/x86/test/xen_hello_world.c | 11 +++++++++++ xen/common/xsplice.c | 19 +++++++++++++++++++ xen/include/asm-x86/uaccess.h | 5 +++++ 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c index c6c367a..a7f0144 100644 --- a/xen/arch/x86/extable.c +++ b/xen/arch/x86/extable.c @@ -20,7 +20,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); @@ -35,7 +35,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; @@ -48,19 +48,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; @@ -85,7 +89,7 @@ search_exception_table(unsigned long addr) struct virtual_region *region = search_for_text(addr); if ( region && region->ex ) - return search_one_table(region->ex, region->ex_end-1, addr); + return search_one_extable(region->ex, region->ex_end-1, addr); return 0; } @@ -94,7 +98,7 @@ 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/arch/x86/test/xen_hello_world.c b/xen/arch/x86/test/xen_hello_world.c index 5364114..0f26b06 100644 --- a/xen/arch/x86/test/xen_hello_world.c +++ b/xen/arch/x86/test/xen_hello_world.c @@ -12,6 +12,7 @@ static char xen_hello_world_name[] = "xen_hello_world"; extern const char *xen_hello_world(void); +static unsigned long *non_canonical_addr = (unsigned long *)(1UL<<48); /* External symbol. */ extern const char *xen_extra_version(void); @@ -26,10 +27,20 @@ void apply_hook(void) void revert_hook(void) { + unsigned long tmp = 0xdeadbeef; + int rc; + printk(KERN_DEBUG "Hook unloaded.\n"); /* The hook is called _after_ the unpatching. */ if ( !strcmp(xen_extra_version(), "Hello World") ) BUG(); + /* + * But before unregistering the virtual region. Which means any + * BUG, or WARN_ON will contain symbol name. And also exceptions + * will be caught and processed properly. + */ + rc = __get_user(tmp, non_canonical_addr); + BUG_ON(rc != -EFAULT); } XSPLICE_LOAD_HOOK(apply_hook); diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 7b92602..4548b8b 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -573,6 +573,25 @@ static int prepare_payload(struct payload *payload, region->frame[i].n_bugs = sec->sec->sh_size / sizeof(struct bug_frame); } +#ifdef CONFIG_X86 + sec = xsplice_elf_sec_by_name(elf, ".ex_table"); + if ( sec ) + { + if ( !sec->sec->sh_size || + (sec->sec->sh_size % sizeof (struct exception_table_entry)) ) + { + dprintk(XENLOG_DEBUG, "%s%s: Wrong size of .ex_table (exp:%lu vs %lu)!\n", + XSPLICE, elf->name, sizeof (struct exception_table_entry), + sec->sec->sh_size); + return -EINVAL; + } + + region->ex = (struct exception_table_entry *)sec->load_addr; + region->ex_end = (struct exception_table_entry *)(sec->load_addr + sec->sec->sh_size); + + sort_exception_table(region->ex, region->ex_end); + } +#endif return 0; } 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__ */