From patchwork Thu Mar 24 20:00:28 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: 8664351 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5A685C0553 for ; Thu, 24 Mar 2016 20:03:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4D1D720382 for ; Thu, 24 Mar 2016 20:03:56 +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 3A2D6201F5 for ; Thu, 24 Mar 2016 20:03:55 +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 1ajBRn-0007q7-8B; Thu, 24 Mar 2016 20:01:35 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajBRl-0007nc-Fs for xen-devel@lists.xenproject.org; Thu, 24 Mar 2016 20:01:33 +0000 Received: from [193.109.254.147] by server-7.bemta-14.messagelabs.com id 00/72-04065-C9744F65; Thu, 24 Mar 2016 20:01:32 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1458849690!33618063!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 40029 invoked from network); 24 Mar 2016 20:01:31 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-12.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Mar 2016 20:01:31 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u2OK18sR011596 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Mar 2016 20:01:08 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u2OK17en007002 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Mar 2016 20:01:08 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u2OK17LC025710; Thu, 24 Mar 2016 20:01:07 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:07 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id A957D6A00E1; 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:28 -0400 Message-Id: <1458849640-22588-17-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: userv0022.oracle.com [156.151.31.74] Cc: Keir Fraser , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v5 16/28] xsplice: Add support for bug frames. 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 handling bug frames contained with xsplice modules. If a trap occurs search either the kernel bug table or an applied payload's bug table depending on the instruction pointer. We also include a test-case - which will test the function that was patched to make sure it has the right value. And will only be triggered if something has gone horribly wrong. P.S. If one really wants to test, insert an WARN_ON(1) at the end of the revert_hook. Signed-off-by: Ross Lagerwall Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Keir Fraser Cc: Jan Beulich Cc: Andrew Cooper v2:- s/module/payload/ - add build time check in case amount of bug frames expands. - add define for the number of bug-frames. v3: - add missing BUGFRAME_NR, squash s/core_size/core/ in earlier patch. - Moved code around. - Changed per Andrew's recommendation. - Fixed style changes. - Made it compile under ARM (PRIu32,PRIu64) v4: Use 'struct virtual_region' - Rip more of the is_active_text code. - Use one function for the ->skip - Include test-case v5: Rip out the ->skip function. --- xen/arch/x86/test/xen_hello_world.c | 6 ++++++ xen/arch/x86/traps.c | 5 +++-- xen/common/xsplice.c | 40 +++++++++++++++++++++++++++++++++++++ xen/include/xen/xsplice.h | 5 +++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/test/xen_hello_world.c b/xen/arch/x86/test/xen_hello_world.c index d2b3cc2..5364114 100644 --- a/xen/arch/x86/test/xen_hello_world.c +++ b/xen/arch/x86/test/xen_hello_world.c @@ -19,11 +19,17 @@ extern const char *xen_extra_version(void); void apply_hook(void) { printk(KERN_DEBUG "Hook executing.\n"); + /* The hook is called _after_ the patching. */ + if ( strcmp(xen_extra_version(), "Hello World") ) + BUG(); } void revert_hook(void) { printk(KERN_DEBUG "Hook unloaded.\n"); + /* The hook is called _after_ the unpatching. */ + if ( !strcmp(xen_extra_version(), "Hello World") ) + BUG(); } XSPLICE_LOAD_HOOK(apply_hook); diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 6c73198..e05656a 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1190,7 +1191,7 @@ void do_invalid_op(struct cpu_user_regs *regs) /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ filename = bug_ptr(bug); - if ( !is_kernel(filename) ) + if ( !is_kernel(filename) && !is_patch(filename) ) goto die; fixup = strlen(filename); if ( fixup > 50 ) @@ -1217,7 +1218,7 @@ void do_invalid_op(struct cpu_user_regs *regs) case BUGFRAME_assert: /* ASSERT: decode the predicate string pointer. */ predicate = bug_msg(bug); - if ( !is_kernel(predicate) ) + if ( !is_kernel(predicate) && !is_patch(predicate) ) predicate = ""; printk("Assertion '%s' failed at %s%s:%d\n", diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 03b32e4..7b92602 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -120,6 +120,24 @@ static int verify_payload(const xen_sysctl_xsplice_upload_t *upload) return 0; } +bool_t is_patch(const void *ptr) +{ + struct payload *data; + + /* + * No locking since this list is only ever changed during apply or revert + * context. + */ + list_for_each_entry ( data, &applied_list, applied_list ) + { + if ( ptr >= data->ro_addr && + ptr < (data->ro_addr + data->ro_size) ) + return 1; + } + + return 0; +} + uint64_t xsplice_symbols_lookup_by_name(const char *symname) { struct payload *data; @@ -533,6 +551,28 @@ static int prepare_payload(struct payload *payload, region->start = (unsigned long)payload->text_addr; region->end = (unsigned long)(payload->text_addr + payload->text_size); + /* Optional sections. */ + for ( i = 0; i < BUGFRAME_NR; i++ ) + { + char str[14]; + + snprintf(str, sizeof str, ".bug_frames.%u", i); + sec = xsplice_elf_sec_by_name(elf, str); + if ( !sec ) + continue; + + if ( !sec->sec->sh_size || + (sec->sec->sh_size % sizeof (struct bug_frame)) ) + { + dprintk(XENLOG_DEBUG, "%s%s: Wrong size of .bug_frames.%u!\n", + XSPLICE, elf->name, i); + return -EINVAL; + } + + region->frame[i].bugs = (struct bug_frame *)sec->load_addr; + region->frame[i].n_bugs = sec->sec->sh_size / sizeof(struct bug_frame); + } + return 0; } diff --git a/xen/include/xen/xsplice.h b/xen/include/xen/xsplice.h index 8bc55f3..47ef1c2 100644 --- a/xen/include/xen/xsplice.h +++ b/xen/include/xen/xsplice.h @@ -42,6 +42,7 @@ struct xsplice_symbol { int xsplice_op(struct xen_sysctl_xsplice_op *); void check_for_xsplice_work(void); +bool_t is_patch(const void *addr); uint64_t xsplice_symbols_lookup_by_name(const char *symname); /* Arch hooks. */ @@ -106,6 +107,10 @@ static inline int xsplice_op(struct xen_sysctl_xsplice_op *op) return -EOPNOTSUPP; } static inline void check_for_xsplice_work(void) { }; +static inline bool_t is_patch(const void *addr) +{ + return 0; +} #endif /* CONFIG_XSPLICE */ #endif /* __XEN_XSPLICE_H__ */