Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp36384pxv; Wed, 14 Jul 2021 18:42:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzthEQiCwDZ0pe+jqXhSo/8JPWd5nrjA9uV3qnYX6j0cXob+vCy+cbSAs8lTfK86gD1Liqq X-Received: by 2002:a50:c907:: with SMTP id o7mr2077814edh.120.1626313346241; Wed, 14 Jul 2021 18:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626313346; cv=none; d=google.com; s=arc-20160816; b=c1moV1B52wPp2zHlaQQeCu9c855Jy9QXn4TpFf+1f+oPgOStWSjrOsbQ85mKQZv2A8 BLBuLieDps7PVfvvlz60UnQufexmXnwgOCR80gmAsSzMhNm5NRCr2ci6Zex6EUtqmG9E qqtFEOX+m5PhSF6oga+Le3Tt+gA3DAlhA13Q1fMTMyR2BRavjKFPq5DzvNJHUW5ygp4D dqmvbTDJQiqSwvxa5SFrpF3nuDBIlALpbssu9x9sysW6hG5U+XTgllq3KhE4SOVhW00h MsJ9/s4Yt+LzYOUzubmyC1xDHUWUEhSzDxFIMNpZgwZFDlbweuPwkXX6j8d22GUpZpXf QpoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ZhQ9Pa8mytsJe3XZ9D/DRNf0GrpjI+2rT0Y4jynkgA8=; b=Jrd3bC6sDkLytltsnCkjIJhNkHSxCrr3sG6NPtlj1bX0u+UD9vgwsjUzs/8dn0uzUr AYqe3QHCZ/C4LVS8gcc0fyfRY65aAeuob3KXyBuAxgjgqrc7SqkE14jIf9zSaG7EHubz n8thrHxDgAhcxKb71S3ayVMD2k09iNZwz0XKXQ+BvVYWuL2mOODOHxk5aDZCuQddSrv8 qDgCWTI6N9PaL762XNULhGknVBAy5Ndqvdx4ea7X47zJ2Q1ibtQGlq7IH6qdNYbplYho nIlEbFckytXkTU3Nn9Z1NxpsjFPsvH2KEgr2iIoMcSZReSBc1k26g6/KShMWcVgiEJHw gSbA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 11si4392158ejv.229.2021.07.14.18.42.03; Wed, 14 Jul 2021 18:42:26 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232529AbhGOBXC (ORCPT + 99 others); Wed, 14 Jul 2021 21:23:02 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6819 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230087AbhGOBXC (ORCPT ); Wed, 14 Jul 2021 21:23:02 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GQGcJ09KhzXtFy; Thu, 15 Jul 2021 09:14:24 +0800 (CST) Received: from dggpemm000003.china.huawei.com (7.185.36.128) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 15 Jul 2021 09:20:01 +0800 Received: from [10.67.102.248] (10.67.102.248) by dggpemm000003.china.huawei.com (7.185.36.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 15 Jul 2021 09:20:01 +0800 Subject: Re: [PATCH] perf probe: Fix add event failed when 32-bit perf running in 64-bit kernel To: Masami Hiramatsu CC: , , , , , , , , , , , , , , , References: <20210714065432.188061-1-yangjihong1@huawei.com> <20210714173553.944cef13897dfe1bea7b8d78@kernel.org> From: Yang Jihong Message-ID: <9cb859df-f2ef-732b-756e-c8d2acefe85c@huawei.com> Date: Thu, 15 Jul 2021 09:20:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210714173553.944cef13897dfe1bea7b8d78@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.248] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm000003.china.huawei.com (7.185.36.128) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Hiramatsu, On 2021/7/14 16:35, Masami Hiramatsu wrote: > 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(). Yes, I tried the following diff and now it can show the filename (as is function entry, relative line number is 0), thank you very much :) The test result in my environment is as follows: # perf 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 schedule -k vmlinux.debug probe:schedule (on schedule@kernel/sched/core.c) Can I put the following diff together and submit a v2 patch? > > 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; > >