From patchwork Thu Apr 7 03:49:32 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: 8768321 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 76AC8C0553 for ; Thu, 7 Apr 2016 03:52:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5FD4C2020F for ; Thu, 7 Apr 2016 03:52: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 27B14201CD for ; Thu, 7 Apr 2016 03:52:08 +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 1ao0xH-0004m8-Kr; Thu, 07 Apr 2016 03:50:03 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ao0xG-0004jb-Ks for xen-devel@lists.xenproject.org; Thu, 07 Apr 2016 03:50:02 +0000 Received: from [193.109.254.147] by server-7.bemta-14.messagelabs.com id 32/B5-04065-9E8D5075; Thu, 07 Apr 2016 03:50:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42KZM10+UPflDdZ wg9e/+Sy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owth9exF3y2qFj7cxJTA+MGrS5GLg4hgQlM Es8+/WOGcL4ySjR972GCcDYwSpxf+oodwulmlJh7bhtbFyMnkFMkceHqaqAEBwebgInEm1WOI DUiAssZJTr3rWYDcZgFTjFK7O/+wgRSJCyQJNGzUh7EZBFQldjYlQMyhlfAXeL+z61gFRICch ILLqSDhDmBwv/adrNDbHKTWPq9hxXElhAwlPi8cSnzBEb+BYwMqxjVi1OLylKLdE30kooy0zN KchMzc3QNDU30clOLixPTU3MSk4r1kvNzNzECw4cBCHYwrljofIhRkoNJSZTXtZI1XIgvKT+l MiOxOCO+qDQntfgQowwHh5IErzIwHIUEi1LTUyvSMnOAgQyTluDgURLh3XgdKM1bXJCYW5yZD pE6xagoJc5rAtInAJLIKM2Da4NFzyVGWSlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ8xqATOHJzC uBm/4KaDET0OJ6YSaQxSWJCCmpBsYK/64PCcumbtnPPEOwqmmS1oFPPc/rnczLn8s4uR35skV W+H1lzuWtU032aW8Qm952f8/cSV7fj67Y8S2CwT7JNnnjFb0/E75+KxMX1lM5f/yI2HTRJivm zSnuHf+OcjF8krnZtojFPc639O+3hMhbvYe7573g4XJvnTktQGnygjfVRf8PSW1SYinOSDTUY i4qTgQAeszRRpkCAAA= X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1460000999!23887474!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.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9727 invoked from network); 7 Apr 2016 03:50:00 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-14.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 7 Apr 2016 03:50:00 -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 u373nqrc004229 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Apr 2016 03:49:52 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u373np8m024600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 7 Apr 2016 03:49:52 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u373np5G020019; Thu, 7 Apr 2016 03:49:51 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Apr 2016 20:49:51 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 79C476A00EB; Wed, 6 Apr 2016 23:49:49 -0400 (EDT) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, konrad@kernel.org, ross.lagerwall@citrix.com, mpohlack@amazon.de, sasha.levin@oracle.com, andrew.cooper3@citrix.com Date: Wed, 6 Apr 2016 23:49:32 -0400 Message-Id: <1460000983-28170-14-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460000983-28170-1-git-send-email-konrad.wilk@oracle.com> References: <1460000983-28170-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Keir Fraser , Tim Deegan , Ian Jackson , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v6 13/24] 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 From: Ross Lagerwall 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 Reviewed-by: Andrew Cooper --- 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 v6: Add comment explaining the purpose behind the strcmp. Redid per Jan's review. --- --- xen/common/vsprintf.c | 19 +++++++++++++++-- xen/common/xsplice.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index 18d2634..a1bb8b8 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -331,16 +332,23 @@ 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; + /* + * namebuf contents and s for core hypervisor are same but for xSplice + * payloads they differ (namebuf contains the name of the payload). + */ + if ( strncmp(namebuf, s, KSYM_NAME_LEN) ) + payload = 1; + /* Print symbol name */ str = string(str, end, s, -1, -1, 0); @@ -354,6 +362,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 b23560e..ca650e6 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -54,6 +56,8 @@ struct payload { struct list_head applied_list; /* Linked to 'applied_list'. */ struct xsplice_patch_func_internal *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. */ @@ -142,6 +146,51 @@ unsigned long xsplice_symbols_lookup_by_name(const char *symname) return 0; } +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->pages * PAGE_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; +} + static struct payload *find_payload(const char *name) { struct payload *data, *found = NULL; @@ -361,6 +410,7 @@ static int prepare_payload(struct payload *payload, const struct xsplice_elf_sec *sec; unsigned int i; struct xsplice_patch_func_internal *f; + struct virtual_region *region; sec = xsplice_elf_sec_by_name(elf, ".xsplice.funcs"); ASSERT(sec); @@ -422,6 +472,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; } @@ -768,6 +825,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; } @@ -786,6 +844,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; }