From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751304AbdBWLjJ (ORCPT ); Thu, 23 Feb 2017 06:39:09 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40760 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751032AbdBWLjF (ORCPT ); Thu, 23 Feb 2017 06:39:05 -0500 From: "Naveen N. Rao" To: Masami Hiramatsu Cc: Ananth N Mavinakayanahalli , Ingo Molnar , Michael Ellerman , Arnaldo Carvalho de Melo , Steven Rostedt , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v3 2/2] perf: kretprobes: offset from reloc_sym if kernel supports it Date: Thu, 23 Feb 2017 17:07:24 +0530 X-Mailer: git-send-email 2.11.1 In-Reply-To: References: In-Reply-To: <20170223181022.7d4427714cabbb7ccd6d6673@kernel.org> References: <20170223181022.7d4427714cabbb7ccd6d6673@kernel.org> X-TM-AS-MML: disable x-cbid: 17022311-0032-0000-0000-000001EC68D7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022311-0033-0000-0000-0000121D6F9F Message-Id: <2f4181ecccf794d05065cb10648badc290aa4c28.1487849577.git.naveen.n.rao@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-02-23_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702230111 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We indicate support for accepting sym+offset with kretprobes through a line in ftrace README. Parse the same to identify support and choose the appropriate format for kprobe_events. Signed-off-by: Naveen N. Rao --- tools/perf/util/probe-event.c | 49 ++++++++++++++++++++++++++++++++++++------- tools/perf/util/probe-event.h | 2 ++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 35f5b7b7715c..dd6b9ce0eef3 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -737,6 +737,43 @@ post_process_module_probe_trace_events(struct probe_trace_event *tevs, return ret; } +bool is_kretprobe_offset_supported(void) +{ + FILE *fp; + char *buf = NULL; + size_t len = 0; + bool target_line = false; + static int supported = -1; + int fd; + + if (supported >= 0) + return !!supported; + + fd = open_trace_file("README", false); + if (fd < 0) + return false; + + fp = fdopen(fd, "r"); + if (!fp) { + close(fd); + return false; + } + + while (getline(&buf, &len, fp) > 0) { + target_line = !!strstr(buf, "place (kretprobe): "); + if (!target_line) + continue; + supported = 1; + } + if (supported == -1) + supported = 0; + + fclose(fp); + free(buf); + + return !!supported; +} + static int post_process_kernel_probe_trace_events(struct probe_trace_event *tevs, int ntevs) @@ -757,7 +794,9 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs, } for (i = 0; i < ntevs; i++) { - if (!tevs[i].point.address || tevs[i].point.retprobe) + if (!tevs[i].point.address) + continue; + if (tevs[i].point.retprobe && !is_kretprobe_offset_supported()) continue; /* If we found a wrong one, mark it by NULL symbol */ if (kprobe_warn_out_range(tevs[i].point.symbol, @@ -1528,11 +1567,6 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) return -EINVAL; } - if (pp->retprobe && !pp->function) { - semantic_error("Return probe requires an entry function.\n"); - return -EINVAL; - } - if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) { semantic_error("Offset/Line/Lazy pattern can't be used with " "return probe.\n"); @@ -2841,7 +2875,8 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, } /* Note that the symbols in the kmodule are not relocated */ - if (!pev->uprobes && !pp->retprobe && !pev->target) { + if (!pev->uprobes && !pev->target && + (!pp->retprobe || is_kretprobe_offset_supported())) { reloc_sym = kernel_get_ref_reloc_sym(); if (!reloc_sym) { pr_warning("Relocated base symbol is not found!\n"); diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 5d4e94061402..449d4f311355 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h @@ -135,6 +135,8 @@ bool perf_probe_with_var(struct perf_probe_event *pev); /* Check the perf_probe_event needs debuginfo */ bool perf_probe_event_need_dwarf(struct perf_probe_event *pev); +bool is_kretprobe_offset_supported(void); + /* Release event contents */ void clear_perf_probe_event(struct perf_probe_event *pev); void clear_probe_trace_event(struct probe_trace_event *tev); -- 2.11.1