From patchwork Thu Mar 24 20:00:26 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: 8664391 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 69BC19F326 for ; Thu, 24 Mar 2016 20:04:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5143F20380 for ; Thu, 24 Mar 2016 20:04:06 +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 AE03B20390 for ; Thu, 24 Mar 2016 20:04:04 +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 1ajBST-0000B7-98; Thu, 24 Mar 2016 20:02:17 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajBSS-0000A2-HB for xen-devel@lists.xenproject.org; Thu, 24 Mar 2016 20:02:16 +0000 Received: from [193.109.254.147] by server-6.bemta-14.messagelabs.com id 57/D3-03497-7C744F65; Thu, 24 Mar 2016 20:02:15 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1458849733!33743700!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: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30943 invoked from network); 24 Mar 2016 20:02:15 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-6.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Mar 2016 20:02:15 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u2OK17Q9015302 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Mar 2016 20:01:07 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u2OK17XF013807 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 Mar 2016 20:01:07 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u2OK16VL025693; 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:05 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 867A46A00DC; 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:26 -0400 Message-Id: <1458849640-22588-15-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: aserv0021.oracle.com [141.146.126.233] Cc: Keir Fraser , Tim Deegan , Ian Jackson , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v5 14/28] x86, xsplice: Print payload's symbol name and payload name in backtraces 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 Naturally the backtrace is presented when an instruction hits an bug_frame or %p is used. The payloads do not support bug_frames yet - however the functions the payloads call could hit an BUG() or WARN(). The traps.c has logic to scan for it this - and eventually it will find the correct bug_frame and the walk the stack using %p to print the backtrace. For %p and symbols to print a string - the 'is_active_kernel_text' is consulted which uses an 'struct virtual_region'. Therefore we register our start->end addresses so that 'is_active_kernel_text' will include our payload address. We also register our symbol lookup table function so that it can scan the list of payloads and retrieve the correct name. Lastly we change vsprintf to take into account s and namebuf. For core code they are the same, but for payloads they are different. This gets us: Xen call trace: [] revert_hook+0x31/0x35 [xen_hello_world] [] xsplice.c#revert_payload+0x86/0xc6 [] check_for_xsplice_work+0x233/0x3cd [] domain.c#continue_idle_domain+0x9/0x1f Which is great if payloads have similar or same symbol names. Signed-off-by: Ross Lagerwall Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Ian Jackson Cc: Jan Beulich Cc: Keir Fraser Cc: Tim Deegan v2: Add missing full stop. v3: s/module/payload/ v4: Expand comment and include registration of 'virtual_region' Redo the vsprintf handling of payload name. Drop the ->skip function --- xen/common/vsprintf.c | 15 ++++++++++--- xen/common/xsplice.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index 18d2634..f0b743f 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -331,16 +332,17 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, { unsigned long sym_size, sym_offset; char namebuf[KSYM_NAME_LEN+1]; + bool_t payload = 0; /* Advance parents fmt string, as we have consumed 's' or 'S' */ ++*fmt_ptr; s = symbols_lookup((unsigned long)arg, &sym_size, &sym_offset, namebuf); - - /* If the symbol is not found, fall back to printing the address */ + /* If the symbol is not found, fall back to printing the address. */ if ( !s ) break; - + if ( strncmp(namebuf, s, KSYM_NAME_LEN) ) + payload = 1; /* Print symbol name */ str = string(str, end, s, -1, -1, 0); @@ -354,6 +356,13 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, str = number(str, end, sym_size, 16, -1, -1, SPECIAL); } + if ( payload ) + { + str = string(str, end, " [", -1, -1, 0); + str = string(str, end, namebuf, -1, -1, 0); + str = string(str, end, "]", -1, -1, 0); + } + return str; } diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 24100e7..5e77360 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -55,6 +57,8 @@ struct payload { struct list_head applied_list; /* Linked to 'applied_list'. */ struct xsplice_patch_func *funcs; /* The array of functions to patch. */ unsigned int nfuncs; /* Nr of functions to patch. */ + struct virtual_region region; /* symbol, bug.frame patching and + exception table (x86). */ struct xsplice_symbol *symtab; /* All symbols. */ char *strtab; /* Pointer to .strtab. */ unsigned int nsyms; /* Nr of entries in .strtab and symbols. */ @@ -139,6 +143,51 @@ out: return value; } +static const char *xsplice_symbols_lookup(unsigned long addr, + unsigned long *symbolsize, + unsigned long *offset, + char *namebuf) +{ + struct payload *data; + unsigned int i; + int best; + + /* + * No locking since this list is only ever changed during apply or revert + * context. + */ + list_for_each_entry ( data, &applied_list, applied_list ) + { + if ( !((void *)addr >= data->text_addr && + (void *)addr < (data->text_addr + data->text_size)) ) + continue; + + best = -1; + + for ( i = 0; i < data->nsyms; i++ ) + { + if ( data->symtab[i].value <= addr && + ( best == -1 || + data->symtab[best].value < data->symtab[i].value) ) + best = i; + } + + if ( best == -1 ) + return NULL; + + if ( symbolsize ) + *symbolsize = data->symtab[best].size; + if ( offset ) + *offset = addr - data->symtab[best].value; + if ( namebuf ) + strlcpy(namebuf, data->name, KSYM_NAME_LEN); + + return data->symtab[best].name; + } + + return NULL; +} + /* * We may be holding the payload_lock or not. Hence we need * the recursive spinlock. Or we can judiciously use an @@ -394,6 +443,7 @@ static int prepare_payload(struct payload *payload, struct xsplice_elf_sec *sec; unsigned int i; struct xsplice_patch_func *f; + struct virtual_region *region; sec = xsplice_elf_sec_by_name(elf, ".xsplice.funcs"); if ( sec ) @@ -449,6 +499,13 @@ static int prepare_payload(struct payload *payload, } } + /* Setup the virtual region with proper data. */ + region = &payload->region; + + region->symbols_lookup = xsplice_symbols_lookup; + region->start = (unsigned long)payload->text_addr; + region->end = (unsigned long)(payload->text_addr + payload->text_size); + return 0; } @@ -795,6 +852,7 @@ static int apply_payload(struct payload *data) arch_xsplice_patching_leave(); list_add_tail(&data->applied_list, &applied_list); + register_virtual_region(&data->region); return 0; } @@ -817,6 +875,7 @@ static int revert_payload(struct payload *data) arch_xsplice_patching_leave(); list_del_init(&data->applied_list); + unregister_virtual_region(&data->region); return 0; }