Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp193712pxv; Wed, 14 Jul 2021 01:37:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzozw5WmEG+t3s8QH7qWZ8BC3ukV0+twqBhWfccC1c2hjnVEthZt7sLA8ZJBsaSufAUPUeR X-Received: by 2002:a17:906:90ca:: with SMTP id v10mr11191926ejw.325.1626251835557; Wed, 14 Jul 2021 01:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626251835; cv=none; d=google.com; s=arc-20160816; b=llbO2ffsTyUTG4FTRdi/yatxYQp1sPBszBALRNJ10Fu0xuhtkWzREmMObux/3uT4Dk h1bADEdueGJ9VhIBieg/UD+VCmLsPQ3v+gMq+KL9zZMLz7TNGdWP9nwYa/hdecW1dkJd i5K9d/q8O7kcXwG9EGJFRvlaUFyaPwdsbRgexollnPz9BYY2ZBKivwfqXfrinbXp1hjX 6caNWPwdoBGd1SiwglCKvppKlIGbcPdWvBdaTi171u3gdq3W6wx7GPShNevGNWl7WJ1c ArK6N9kYeF085hwwq77YsnunuGglauIg/MDiT72wp5BMnjjlHyTBl1PskEyp2XYWvO02 qkxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0yyRIQIP3Yix4q0mrybPdhbqICs3lulNLuVb5IM99+c=; b=DO/Nz2GXbsqFbaO8p6jUZgvcuX0ZqFlQ/e4s3cKPNrO2S0FwY3nEJlvvcvhGdTe+MH 1QdemQ/OV2flMCI61ZFKEpaHXugTn8oRIRW0M2cRGl2gq3iqLJUqUpn8gmC5RYcrLWTI jjhbWjlb6woYcbn6KXDECOjaAuL93d2Hfl3UvCTPjiLUyYN05CtYn37E3OrkjR0U6kd3 HtBSUKTBQFWWEEttCkV6ZQnE5cNxGgY1N2Jqbr6gP8kdDyfDIpqrNFyrNvbgOGOzD4kj FjsuukM21AYNU+t0rE89Y0AyBOnJ2sGGhWhoG48/L2JSXr4BFxIO5vx4UuttlBpw7inM E4hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="RB/QPHzl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h15si1776441ejj.98.2021.07.14.01.36.50; Wed, 14 Jul 2021 01:37:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="RB/QPHzl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238535AbhGNIit (ORCPT + 99 others); Wed, 14 Jul 2021 04:38:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:40658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238482AbhGNIit (ORCPT ); Wed, 14 Jul 2021 04:38:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D43B16115A; Wed, 14 Jul 2021 08:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626251758; bh=HDymZW8IKRKt/jb2rj2qbgVXui81unjwJTpptk8kJ7c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RB/QPHzlz7sU+FJoEw2Rl9ORqYNYDU0ByM2fH+ZDN8PFpW72iGwx2iJTvk34xXdDK 4afkxT3NphonGmGcHZDxnWFZ4lKMQboC5f7pX9/gFmeZdoaXOYj1L75Q0sxdjkFEFQ VcH5G+mYU4/gBv5D1pr9vF10r0Hn6jAwiGok9NiDCzN/SpQbBq6mnLsA/qvXhiy+Gg l+xcAQNJMAH9+OoQyRKGxGjRtUi2zYRqBteaHq/g1Rbu2Nct06EorWxVIS/0uehre2 Xt4WnHe29rmSkUuhrgDndDxPRvg0wkqqITtZmFIA4OrmUMBFVir8u54QK5+2e1TzzH jgjRxZ6A3X7SA== Date: Wed, 14 Jul 2021 17:35:53 +0900 From: Masami Hiramatsu To: Yang Jihong Cc: , , , , , , , , , , , , , , , Subject: Re: [PATCH] perf probe: Fix add event failed when 32-bit perf running in 64-bit kernel Message-Id: <20210714173553.944cef13897dfe1bea7b8d78@kernel.org> In-Reply-To: <20210714065432.188061-1-yangjihong1@huawei.com> References: <20210714065432.188061-1-yangjihong1@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yang, On Wed, 14 Jul 2021 14:54:32 +0800 Yang Jihong wrote: > The "address" member of "struct probe_trace_point" uses long data type. > If kernel is 64-bit and perf program is 32-bit, size of "address" variable is > 32 bits. As a result, upper 32 bits of address read from kernel are truncated, > An error occurs during address comparison in kprobe_warn_out_range function. Good catch! I didn't imagine that such a use case. But that is important because perf probe can be used for cross-arch probe definition too. > > Before: > > # perf probe -a schedule > schedule is out of .text, skip it. > Error: Failed to add events. > > Solution: > Change data type of "address" variable to u64 and change corresponding > address printing and value assignment. OK, as far as I can see, the other parts of the perf also uses u64 for "address" storing variables. (e.g. symbols, maps etc.) > > After: > > # perf.new.new probe -a schedule > Added new event: > probe:schedule (on schedule) > > You can now use it in all perf tools, such as: > > perf record -e probe:schedule -aR sleep 1 > > # perf probe -l > probe:schedule (on schedule) I think you missed one thing here. Usually, this shows the filename and line number of schedule(). Could you try below diff? diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 7d2ba8419b0c..609ca1671501 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -113,14 +113,14 @@ static Dwarf_Line *cu_getsrc_die(Dwarf_Die *cu_die, Dwarf_Addr addr) * * Find a line number and file name for @addr in @cu_die. */ -int cu_find_lineinfo(Dwarf_Die *cu_die, unsigned long addr, - const char **fname, int *lineno) +int cu_find_lineinfo(Dwarf_Die *cu_die, Dwarf_Addr addr, + const char **fname, int *lineno) { Dwarf_Line *line; Dwarf_Die die_mem; Dwarf_Addr faddr; - if (die_find_realfunc(cu_die, (Dwarf_Addr)addr, &die_mem) + if (die_find_realfunc(cu_die, addr, &die_mem) && die_entrypc(&die_mem, &faddr) == 0 && faddr == addr) { *fname = dwarf_decl_file(&die_mem); @@ -128,7 +128,7 @@ int cu_find_lineinfo(Dwarf_Die *cu_die, unsigned long addr, goto out; } - line = cu_getsrc_die(cu_die, (Dwarf_Addr)addr); + line = cu_getsrc_die(cu_die, addr); if (line && dwarf_lineno(line, lineno) == 0) { *fname = dwarf_linesrc(line, NULL, NULL); if (!*fname) diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h index cb99646843a9..7ee0fa19b5c4 100644 --- a/tools/perf/util/dwarf-aux.h +++ b/tools/perf/util/dwarf-aux.h @@ -19,7 +19,7 @@ const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname); const char *cu_get_comp_dir(Dwarf_Die *cu_die); /* Get a line number and file name for given address */ -int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr, +int cu_find_lineinfo(Dwarf_Die *cudie, Dwarf_Addr addr, const char **fname, int *lineno); /* Walk on functions at given address */ diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 8ba01bbdf05c..50d861a80f57 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -1727,7 +1727,7 @@ int debuginfo__find_probe_point(struct debuginfo *dbg, u64 addr, } /* Find a corresponding line (filename and lineno) */ - cu_find_lineinfo(&cudie, addr, &fname, &lineno); + cu_find_lineinfo(&cudie, (Dwarf_Addr)addr, &fname, &lineno); /* Don't care whether it failed or not */ /* Find a corresponding function (name, baseline and baseaddr) */ @@ -1828,8 +1828,7 @@ static int line_range_add_line(const char *src, unsigned int lineno, } static int line_range_walk_cb(const char *fname, int lineno, - Dwarf_Addr addr __maybe_unused, - void *data) + Dwarf_Addr addr, void *data) { struct line_finder *lf = data; const char *__fname; -- Masami Hiramatsu