Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4827307ybl; Wed, 22 Jan 2020 05:29:24 -0800 (PST) X-Google-Smtp-Source: APXvYqyVY9wSHdkKHXY9ub1bq76Vl+KEd8ARrZMiDfCUCAqIpaloIij3JwR3HaRo5PVlQfDfs2JD X-Received: by 2002:a9d:6f82:: with SMTP id h2mr7228298otq.69.1579699764481; Wed, 22 Jan 2020 05:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699764; cv=none; d=google.com; s=arc-20160816; b=0zHVtqmHTko7+jkaZb7x3l1BR/u5OZT+8k4Rh3y+82qQgccxHhNzhxLP0jBj5Fe5P5 /KsZ+ASL4X53C94FG6/rg8ROAuQuXOFyVZtGPcc+1MuyRe7O0j6c6srxplhjNQEI+cIM 1LafQFP3pmF/rBIiQ/FMZSACn0yJTZhZdBkNCeArduOVOBN5KTPDaNp+OZcfYvwb9wEU gyM2IlD5xWoHGHdYoJUEQn386+45HQkEDNApkF1LhlmFkW3BWGMRn6whw0uMNZR0Vapl j0EsPo+18cZEzczjW3tY3WZxMG90Uxov5hpzGMHf/+xefORVGbW6ACWafujuK5NZZEJc cZ4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LSouRSQcAlSEzA3KQ3ydMPncb4G+mJg7SAhYfJMohMo=; b=tAiwfrSoW7FxX3kyAWhlIOqesoRRckiPjT4IG4f7ODNt/M4xGJNDGsQnPqv32sQR+/ tKWHSQFaqrrEbAiD1sIOx0TXe7t0eRhlbSMExI1OLeDm6fkXJ9Z1aOvKhRHL3y0QZuA4 4l4lV/qg/Lomh0rORb7hMkgolzZLFxPZXVhdW+Ai040DnOYU95VwM+RJFLsz6iZOKMAG 82X/qears2w39Bx0RvKfjtD0k+GGMCmjhgVTLdgYFE1bdcNi/Bs1GODzywuKWlGDu1Yy XiC4W+CE1w4KXtSrR7+/C87V71ZxhVNd0clvL2++rSyagrUVsYzen0RmR18eF1Ko+EhD MeAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FxF4bMDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p17si984470otq.261.2020.01.22.05.29.12; Wed, 22 Jan 2020 05:29:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FxF4bMDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731931AbgAVN15 (ORCPT + 99 others); Wed, 22 Jan 2020 08:27:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:49734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731005AbgAVN14 (ORCPT ); Wed, 22 Jan 2020 08:27:56 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2DF3E20678; Wed, 22 Jan 2020 13:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699675; bh=xcWkAncjJEirlvmD7/ZgT3G9R4hSi6j7tn63o+LVIuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxF4bMDU5vRoFIEa+GD30lVwrhwLw0wLauMc4nSWnKyWv+V+3j/CLhxeKO90JTA3f khM4rCU295PIW7XqbKDNEoNBSCSEQCz4LqzlQPrh4sI7hCZPRVLc5kPTHgrRtSD6X9 0eHNdbm5ddnd00oOzsIvhwWHeq643ySgY7uBVrtE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnaldo Carvalho de Melo , Arnaldo Carvalho de Melo , Masami Hiramatsu , Jiri Olsa , Namhyung Kim Subject: [PATCH 5.4 215/222] perf probe: Fix wrong address verification Date: Wed, 22 Jan 2020 10:30:01 +0100 Message-Id: <20200122092849.088567780@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masami Hiramatsu commit 07d369857808b7e8e471bbbbb0074a6718f89b31 upstream. Since there are some DIE which has only ranges instead of the combination of entrypc/highpc, address verification must use dwarf_haspc() instead of dwarf_entrypc/dwarf_highpc. Also, the ranges only DIE will have a partial code in different section (e.g. unlikely code will be in text.unlikely as "FUNC.cold" symbol). In that case, we can not use dwarf_entrypc() or die_entrypc(), because the offset from original DIE can be a minus value. Instead, this simply gets the symbol and offset from symtab. Without this patch; # perf probe -D clear_tasks_mm_cpumask:1 Failed to get entry address of clear_tasks_mm_cpumask Error: Failed to add events. And with this patch: # perf probe -D clear_tasks_mm_cpumask:1 p:probe/clear_tasks_mm_cpumask clear_tasks_mm_cpumask+0 p:probe/clear_tasks_mm_cpumask_1 clear_tasks_mm_cpumask+5 p:probe/clear_tasks_mm_cpumask_2 clear_tasks_mm_cpumask+8 p:probe/clear_tasks_mm_cpumask_3 clear_tasks_mm_cpumask+16 p:probe/clear_tasks_mm_cpumask_4 clear_tasks_mm_cpumask+82 Committer testing: I managed to reproduce the above: [root@quaco ~]# perf probe -D clear_tasks_mm_cpumask:1 p:probe/clear_tasks_mm_cpumask _text+919968 p:probe/clear_tasks_mm_cpumask_1 _text+919973 p:probe/clear_tasks_mm_cpumask_2 _text+919976 [root@quaco ~]# But then when trying to actually put the probe in place, it fails if I use :0 as the offset: [root@quaco ~]# perf probe -L clear_tasks_mm_cpumask | head -5 0 void clear_tasks_mm_cpumask(int cpu) 1 { 2 struct task_struct *p; [root@quaco ~]# perf probe clear_tasks_mm_cpumask:0 Probe point 'clear_tasks_mm_cpumask' not found. Error: Failed to add events. [root@quaco The next patch is needed to fix this case. Fixes: 576b523721b7 ("perf probe: Fix probing symbols with optimization suffix") Reported-by: Arnaldo Carvalho de Melo Tested-by: Arnaldo Carvalho de Melo Signed-off-by: Masami Hiramatsu Cc: Jiri Olsa Cc: Namhyung Kim Link: http://lore.kernel.org/lkml/157199318513.8075.10463906803299647907.stgit@devnote2 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/probe-finder.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -604,38 +604,26 @@ static int convert_to_trace_point(Dwarf_ const char *function, struct probe_trace_point *tp) { - Dwarf_Addr eaddr, highaddr; + Dwarf_Addr eaddr; GElf_Sym sym; const char *symbol; /* Verify the address is correct */ - if (dwarf_entrypc(sp_die, &eaddr) != 0) { - pr_warning("Failed to get entry address of %s\n", - dwarf_diename(sp_die)); - return -ENOENT; - } - if (dwarf_highpc(sp_die, &highaddr) != 0) { - pr_warning("Failed to get end address of %s\n", - dwarf_diename(sp_die)); - return -ENOENT; - } - if (paddr > highaddr) { - pr_warning("Offset specified is greater than size of %s\n", + if (!dwarf_haspc(sp_die, paddr)) { + pr_warning("Specified offset is out of %s\n", dwarf_diename(sp_die)); return -EINVAL; } - symbol = dwarf_diename(sp_die); + /* Try to get actual symbol name from symtab */ + symbol = dwfl_module_addrsym(mod, paddr, &sym, NULL); if (!symbol) { - /* Try to get the symbol name from symtab */ - symbol = dwfl_module_addrsym(mod, paddr, &sym, NULL); - if (!symbol) { - pr_warning("Failed to find symbol at 0x%lx\n", - (unsigned long)paddr); - return -ENOENT; - } - eaddr = sym.st_value; + pr_warning("Failed to find symbol at 0x%lx\n", + (unsigned long)paddr); + return -ENOENT; } + eaddr = sym.st_value; + tp->offset = (unsigned long)(paddr - eaddr); tp->address = (unsigned long)paddr; tp->symbol = strdup(symbol);