From patchwork Tue Mar 15 17:56:42 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: 8591311 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 89C37C0553 for ; Tue, 15 Mar 2016 18:03:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A24620122 for ; Tue, 15 Mar 2016 18:03:12 +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 3BD7420155 for ; Tue, 15 Mar 2016 18:03:11 +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 1aftHZ-00031z-Bi; Tue, 15 Mar 2016 18:01:25 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aftHY-000303-9z for xen-devel@lists.xenproject.org; Tue, 15 Mar 2016 18:01:24 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id F6/35-02479-3FD48E65; Tue, 15 Mar 2016 18:01:23 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1458064881!29241316!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 17603 invoked from network); 15 Mar 2016 18:01:22 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Mar 2016 18:01:22 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u2FI0H86011466 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Mar 2016 18:00:17 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u2FI0G4r016333 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 15 Mar 2016 18:00:16 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u2FI0FUa005970; Tue, 15 Mar 2016 18:00:15 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 Mar 2016 11:00:15 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id B56086A00E2; Tue, 15 Mar 2016 13:59:43 -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: Tue, 15 Mar 2016 13:56:42 -0400 Message-Id: <1458064616-23101-21-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458064616-23101-1-git-send-email-konrad.wilk@oracle.com> References: <1458064616-23101-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 v4 20/34] 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=-1.9 required=5.0 tests=BAYES_00, 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 --- 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' v5: Redo the vsprintf handling of payload name. --- xen/common/vsprintf.c | 15 +++++++++--- xen/common/xsplice.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 4 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 54120bb..a3366ef 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -3,6 +3,7 @@ * */ +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +52,7 @@ 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 bug_ex_region; /*.bug.frame patching and exception table. */ struct xsplice_symbol *symtab; /* All symbols. */ char *strtab; /* Pointer to .strtab. */ unsigned int nsyms; /* Nr of entries in .strtab and symbols. */ @@ -103,6 +106,12 @@ static int verify_payload(const xen_sysctl_xsplice_upload_t *upload) return 0; } +static bool_t ignore_region(unsigned int flag, unsigned long priv) +{ + /* See CHECKING_[SYMBOL|BUG_FRAME|EXCEPTION]. */ + return !(flag & priv); +} + uint64_t xsplice_symbols_lookup_by_name(const char *symname) { struct payload *data; @@ -131,6 +140,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->payload_address && + (void *)addr < (data->payload_address + data->core_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; +} + static int find_payload(const xen_xsplice_name_t *name, struct payload **f) { struct payload *data; @@ -325,6 +379,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 ) @@ -377,6 +432,15 @@ static int prepare_payload(struct payload *payload, XSPLICE, elf->name, f->name, f->old_addr); } } + + /* Setup the virtual region with proper data. */ + region = &payload->bug_ex_region; + region->skip = ignore_region; + region->symbols_lookup = xsplice_symbols_lookup; + region->priv = CHECKING_SYMBOL; + region->start = (unsigned long)payload->payload_address; + region->end = (unsigned long)(payload->payload_address + payload->core_text_size); + return 0; } @@ -479,7 +543,6 @@ static int build_symbol_table(struct payload *payload, payload->symtab = symtab; payload->strtab = strtab; payload->nsyms = nsyms; - return 0; } @@ -707,6 +770,7 @@ static int apply_payload(struct payload *data) arch_xsplice_patching_leave(); list_add_tail(&data->applied_list, &applied_list); + register_virtual_region(&data->bug_ex_region); return 0; } @@ -729,6 +793,7 @@ static int revert_payload(struct payload *data) arch_xsplice_patching_leave(); list_del_init(&data->applied_list); + unregister_virtual_region(&data->bug_ex_region); return 0; }