Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161033AbbKSTJY (ORCPT ); Thu, 19 Nov 2015 14:09:24 -0500 Received: from mail-bn1bon0112.outbound.protection.outlook.com ([157.56.111.112]:8000 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933712AbbKSTJW (ORCPT ); Thu, 19 Nov 2015 14:09:22 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brianrob@microsoft.com; From: Brian Robbins To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo Cc: Brian Robbins , linux-kernel@vger.kernel.org Subject: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries. Date: Thu, 19 Nov 2015 11:09:07 -0800 Message-Id: <1447960147-2681-1-git-send-email-brianrob@microsoft.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [131.107.159.79] X-ClientProxiedBy: BY2PR08CA036.namprd08.prod.outlook.com (10.141.248.154) To BY2PR0301MB1589.namprd03.prod.outlook.com (25.163.28.19) X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1589;2:ojza613/1f4LLJeTQRjC24ZKSbPa2C//6YRjsnky/d22WDbxlWRB7C/Hv1lQA7Cx7ogND5covWoB1VcUYkp6nC6htUfFxV0hnivQKvSZA6mC0IqCOwE89fPHA+Fd4+oIGUejadzTE3e9r2keZZ5u0g==;3:lbD2v1HFYOlEuV9ZCWSCyi3SiH+IsChhqz2PNymJGF+F10HcL4HjwqI/nUjmxdVQaOVOCNQhnLeJteChLUAg1OFxO0GV8qTTATSA/CAz74VhG+cPxaDRUPPpdeDpJiKS;25:rjsVDsN2bfDAZRJlw9x67vuddkW1fzZTC/6ZrJYcoh3bIs11ub49WwXe4KBfBwVU6TzpYdSxGAH/D5b65HNWOMpYBn+UYzQdtoW8NTmepv/Cl07gzZ0eMogkKiZwlZ+mQVC/Z5l7lDQ1jdFVeoYmQ18CkxeLcVExyQ91bcS2CJUzogSPEGyC6FJUgwbhHKuSNZgqvIIZoQOx5yC5Vc/rE5KLiM6RORXEJ9dC6maCJFwH/tUFDGK0nyx6v5dSOUySJsMPB/tMhN2L9e9cGIN3ig== X-Exchange-Antispam-Report-Test: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1589;UriScan:(108003899814671); X-O365ENT-EOP-Header: Message processed by - O365_ENT: Allow from ranges (Engineering ONLY) X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1589;20:qME+GXmQAWqKNp/PSEkBgkdGpALc8EsxKdMdzYf1B3PSBh34GMNNZzOkTVN3ztpbyiTZ0Q3DUAc+lWnfjju9iA8s1ISmtUheW8/jcrTWYObzTy2NzlC7s2K3Rv3FqVKVMf8IZaiv+CwDSmoMhz3Nopx3Q+wExTpx/F1h2NBQ7mV9lSAEeD+I+Bl+yBirMlLI7AKxxQw/bHU65dBPHzamoo2g369ImssS2btiee1CknWn0agxHIuI9f42uSQxq6Y0BL0WH2wV4WwHRIe4HTsWFQcR39EkkRxa8hUXKg7eNEsITKQ/b/+xTK1bmlETZpMQcGQybZuw/67BmRxxJ2ozC7DlKuobNfUaRxW2reCdd/ACpwMV7g24Lkja0bVB/DNBU5ZbFcu3fWREI982za8a4VpmeoNPQintUqx8pYgXl/G0Q8JiW4muLIwNEGD1EEOrKLqup1uZfdT64ut6l9tT2pNUQ1oQkVHvpvf+8w0QHalLr8UgZ5SyI4jIca9IqtFUlnLykmzSkNRWhDqmTSVfMDgIhZ42TLTRFUn8oIxzzX+kSV5gO6yWPfFceTUTeEnyFdsrLFO/GJ6JaIeZsMepXmlMBD9DwIkuFchHqBLeWmw= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(10201501046)(3002001);SRVR:BY2PR0301MB1589;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1589; X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1589;4:ey6lpSnSc3KJ4eg+i3uloHd4UOEACfA2xpujfvo8AV/Ghe7V5pH7VCOXqJzPRT0NeBn2pEnfVaNZrvJPwGhECMkhMlAFTmI+jRnLffx0oqYsS4UbnoTKuS/Hm1HdrwG2nKzo+ElGw2oLdfuGZ25Cm07rAB843pBufsqqAzvF4Q9hBxP3Hh/g6Pt2CQN5ZRjQFi+T4rQa1psVw577X1CTb0MFT3AaBL0cABwInOiN6v/PlTbV1ll6TnE8fzvqWl+HWHk+RZpLIsE7Mqtl4yDDVU90XISZK+pKG9goxBbG5saVBHFA2fof8DnpLTyp7x2jmnDt+OAHntryDllSmvxWrnHNRm4uuXMIQhsJKH2jAZD5pdmzJVsb61vEuFlgmn06fdJQgBP/WoZ6R9GqBxjzlpjF0XRf3icqEx56kgH3/EfNJN8/cjKM9LfqLEHotqli X-Forefront-PRVS: 07658B8EA3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(199003)(189002)(106356001)(105586002)(33646002)(77096005)(19580395003)(19580405001)(101416001)(229853001)(40100003)(87976001)(86612001)(50986999)(86362001)(42186005)(5008740100001)(122386002)(586003)(6116002)(3846002)(5004730100002)(5007970100001)(92566002)(10090500001)(5003940100001)(5001920100001)(5001770100001)(81156007)(97736004)(189998001)(5001960100002)(48376002)(50466002)(50226001)(47776003)(66066001)(5005710100001)(10290500002)(36756003);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR0301MB1589;H:BRIANROB-ZB-1.corp.microsoft.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR0301MB1589;23:XrRiOGL7uDI3WwheKTEmnzz8gYSYOvqOX9yM4tF?= =?us-ascii?Q?DsL/vX+xXSE/qg68rJNx2tR05m0yhayWLwZoy5lQ5AeztBX2tO8w1Lh+3RAJ?= =?us-ascii?Q?hnj89d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WnjvO?= =?us-ascii?Q?uKrFHgX0BhEwug3vhze99vQns4fx/wb4Lw1etPzG4KSmeizzjyJXKRtmC71u?= =?us-ascii?Q?PvxEvDVoeCuFYx2iN41aVnRZ7ZROZAXsEPM9i1TNbimWjaxo9OytMRUxosOL?= =?us-ascii?Q?d+gskBLZNTPlGvvW3JjluTUWoKopOj/vf?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1589;5:bpq4EmMbPneYBaqr+T8TI+mBrdUFvGgWoAjx3rQ8ZgF/GosZQvz6ZSTCiNrAUM8K2RpBQ4GAqVe0uWa+gEsk22vRijbULzwAhNkJllJuk7i3HjGhB5BZdniELJq67N2vNEmwCxRg52vEF+7ZqsnH/Q==;24:W3Bf/IOboRzS7n6f30oUOr88DEZFlldMncY8gPKuwuzmSqvKGdUvPLWNEMJhDtWJJqjfKyAO5bx0waZh6i0jgazXXAyL+QXOwCXt0XS/kDg= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2015 19:09:19.3731 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB1589 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3050 Lines: 100 Programs can execute code contained in files that don't conform to the ELF standard. This is common for cross-platform runtimes that support ahead-of-time compilation. In this case, perf is unable to resolve addresses to symbolic names, as the format of the mmap'd file is unknown to perf. Make perf fallback to JIT support (/tmp/perf-%pid.map) when resolving function names if the file containing the code is not an ELF binary. Signed-off-by: Brian Robbins --- tools/perf/util/map.c | 1 + tools/perf/util/map.h | 1 + tools/perf/util/symbol.c | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 4e38c39..b33d460 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -164,6 +164,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, map->ino_generation = ino_gen; map->prot = prot; map->flags = flags; + map->pid = pid; if ((anon || no_dso) && type == MAP__FUNCTION) { snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", pid); diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 7309d64..ba80f13 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -52,6 +52,7 @@ struct map { struct dso *dso; struct map_groups *groups; atomic_t refcnt; + u32 pid; }; struct kmap { diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index b4cc766..12bc2f5 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1516,7 +1516,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) } if (!runtime_ss && !syms_ss) - goto out_free; + goto jit_fallback; if (runtime_ss && !syms_ss) { syms_ss = runtime_ss; @@ -1541,7 +1541,36 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) for (; ss_pos > 0; ss_pos--) symsrc__destroy(&ss_[ss_pos - 1]); -out_free: + +jit_fallback: + /* If we couldn't load symbols, fall back to /tmp/perf-%pid.map. */ + if (ret < 0) { + struct stat st; + const char *origlongname; + snprintf(name, PATH_MAX, "/tmp/perf-%d.map", map->pid); + + if (lstat(name, &st) < 0) + goto out; + + if (st.st_uid && (st.st_uid != geteuid())) { + pr_warning("File %s not owned by current user or root, " + "ignoring it.\n", name); + goto out; + } + + origlongname = dso->long_name; + dso->long_name = name; + + ret = dso__load_perf_map(dso, map, filter); + + dso->long_name = origlongname; + dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT : + DSO_BINARY_TYPE__NOT_FOUND; + + if (ret > 0) + map->map_ip = map->unmap_ip = identity__map_ip; + } + free(name); if (ret < 0 && strstr(dso->name, " (deleted)") != NULL) ret = 0; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/