From patchwork Fri Feb 12 18:05:58 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: 8294821 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 BD78F9F6E4 for ; Fri, 12 Feb 2016 18:08:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3D6C2041D for ; Fri, 12 Feb 2016 18:08:53 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A4652041F for ; Fri, 12 Feb 2016 18:08:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUI7i-0006dt-Ma; Fri, 12 Feb 2016 18:07:18 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUI7N-00062r-74 for xen-devel@lists.xen.org; Fri, 12 Feb 2016 18:06:57 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id 99/B3-09062-04F1EB65; Fri, 12 Feb 2016 18:06:56 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1455300414!14578382!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: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1073 invoked from network); 12 Feb 2016 18:06:55 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-7.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 12 Feb 2016 18:06:55 -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 u1CI6imv004489 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Feb 2016 18:06:44 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u1CI6iWC006157 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 12 Feb 2016 18:06:44 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u1CI6hJa008947; Fri, 12 Feb 2016 18:06:43 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 12 Feb 2016 10:06:43 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id 38F706A4BF4; Fri, 12 Feb 2016 13:06:41 -0500 (EST) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com, konrad@kernel.org, mpohlack@amazon.de, ross.lagerwall@citrix.com, sasha.levin@citrix.com, jinsong.liu@alibaba-inc.com, Keir Fraser , Jan Beulich , xen-devel@lists.xen.org Date: Fri, 12 Feb 2016 13:05:58 -0500 Message-Id: <1455300361-13092-21-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1455300361-13092-1-git-send-email-konrad.wilk@oracle.com> References: <1455300361-13092-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v3 20/23] x86, xsplice: Print payload's symbol name and module in backtraces X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org 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 Signed-off-by: Ross Lagerwall Signed-off-by: Konrad Rzeszutek Wilk --- xen/arch/x86/traps.c | 6 +++--- xen/common/vsprintf.c | 18 ++++++++++++++-- xen/common/xsplice.c | 52 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/xen/xsplice.h | 11 ++++++++++ 4 files changed, 78 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index f3adefa..36d42fe 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -341,7 +341,7 @@ static void _show_trace(unsigned long sp, unsigned long __maybe_unused bp) while ( stack <= bottom ) { addr = *stack++; - if ( is_active_kernel_text(addr) ) + if ( is_active_text(addr) ) printk(" [<%p>] %pS\n", _p(addr), _p(addr)); } } @@ -403,8 +403,8 @@ static void show_trace(const struct cpu_user_regs *regs) * If RIP looks sensible, or the top of the stack doesn't, print RIP at * the top of the stack trace. */ - if ( is_active_kernel_text(regs->rip) || - !is_active_kernel_text(*sp) ) + if ( is_active_text(regs->rip) || + !is_active_text(*sp) ) printk(" [<%p>] %pS\n", _p(regs->rip), _p(regs->rip)); /* * Else RIP looks bad but the top of the stack looks good. Perhaps we diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index 51b5e4e..cfe63a4 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -305,15 +306,21 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, { unsigned long sym_size, sym_offset; char namebuf[KSYM_NAME_LEN+1]; + const char *module = NULL; /* 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 ( !s ) - break; + { + s = xsplice_symbols_lookup((unsigned long)arg, &sym_size, + &sym_offset, &module); + /* If the symbol is not found, fall back to printing the address */ + if ( !s ) + break; + } /* Print symbol name */ str = string(str, end, s, -1, -1, 0); @@ -328,6 +335,13 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, str = number(str, end, sym_size, 16, -1, -1, SPECIAL); } + if ( module ) + { + str = string(str, end, " [", -1, -1, 0); + str = string(str, end, module, -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 0b42a16..ae2882f 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -873,7 +873,6 @@ static int build_symbol_table(struct payload *payload, struct xsplice_elf *elf) symtab[nsyms].name = strtab + strtab_len; symtab[nsyms].size = elf->sym[i].sym->st_size; symtab[nsyms].value = elf->sym[i].sym->st_value; - symtab[nsyms].flags = 0; strtab_len += strlcpy(strtab + strtab_len, elf->sym[i].name, KSYM_NAME_LEN) + 1; nsyms++; @@ -1276,7 +1275,7 @@ struct bug_frame *xsplice_find_bug(const char *eip, int *id) { struct payload *data; struct bug_frame *bug; - int i; + unsigned int i; /* No locking since this list is only ever changed during apply or revert * context. */ @@ -1286,10 +1285,12 @@ struct bug_frame *xsplice_find_bug(const char *eip, int *id) if (!data->start_bug_frames[i]) continue; if ( !((void *)eip >= data->payload_address && - (void *)eip < (data->payload_address + data->core_text_size))) + (void *)eip < (data->payload_address + data->core_text_size)) ) continue; - for ( bug = data->start_bug_frames[i]; bug != data->stop_bug_frames[i]; ++bug ) { + for ( bug = data->start_bug_frames[i]; + bug != data->stop_bug_frames[i]; ++bug ) + { if ( bug_loc(bug) == eip ) { *id = i; @@ -1385,6 +1386,49 @@ out: return value; } +const char *xsplice_symbols_lookup(unsigned long addr, + unsigned long *symbolsize, + unsigned long *offset, + const char **module) +{ + 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 ( module ) + *module = data->name; + + return data->symtab[best].name; + } + + return NULL; +} + static int __init xsplice_init(void) { register_keyhandler('x', xsplice_printall, "print xsplicing info", 1); diff --git a/xen/include/xen/xsplice.h b/xen/include/xen/xsplice.h index 1045213..482483b 100644 --- a/xen/include/xen/xsplice.h +++ b/xen/include/xen/xsplice.h @@ -43,6 +43,10 @@ bool_t is_module(const void *addr); bool_t is_active_module_text(unsigned long addr); unsigned long search_module_extables(unsigned long addr); uint64_t xsplice_symbols_lookup_by_name(const char *symname); +const char *xsplice_symbols_lookup(unsigned long addr, + unsigned long *symbolsize, + unsigned long *offset, + const char **module); /* Arch hooks */ int xsplice_verify_elf(struct xsplice_elf *elf, uint8_t *data); @@ -77,5 +81,12 @@ static inline unsigned long search_module_extables(unsigned long addr) { return 0; } +static inline const char *xsplice_symbols_lookup(unsigned long addr, + unsigned long *symbolsize, + unsigned long *offset, + const char **module) +{ + return NULL; +} #endif #endif /* __XEN_XSPLICE_H__ */