Re: [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint

From: Masami Hiramatsu
Date: Tue Feb 25 2020 - 17:34:51 EST


Hi,

Thanks for reporting. This bug has been reported and I should fixed last year...

https://lkml.org/lkml/2019/12/3/136

Arnaldo, haven't you picked it yet?

Thank you,


On Tue, 25 Feb 2020 22:41:42 +0800
<zhe.he@xxxxxxxxxxxxx> wrote:

> From: He Zhe <zhe.he@xxxxxxxxxxxxx>
>
> Since commit 72363540c009 ("perf probe: Support multiprobe event") and its
> series, if there are multiple probes for one event,
> __probe_file__get_namelist would return -EEXIST and cause the following
> failure without proper hint, due to adding existing entry to output list.
>
> root@qemuarm64:~# perf probe -x /lib64/libc.so.6 free
> Added new events:
> probe_libc:free (on free in /lib64/libc-2.31.so)
> probe_libc:free (on free in /lib64/libc-2.31.so)
>
> You can now use it in all perf tools, such as:
>
> perf record -e probe_libc:free -aR sleep 1
>
> root@qemuarm64:~# perf probe -l
> probe_libc:free (on free@plt in /lib64/libc-2.31.so)
> probe_libc:free (on cfree in /lib64/libc-2.31.so)
> root@qemuarm64:~# perf probe -x /lib64/libc.so.6 free
> Error: Failed to add events.
>
> As we just want to check if there is any probe with the same name, -EEXIST
> can be ignored, so we can have the right hint as before.
>
> root@qemuarm64:~# perf probe -x /lib64/libc.so.6 free
> Error: event "free" already exists.
> Hint: Remove existing event by 'perf probe -d'
> or force duplicates by 'perf probe -f'
> or set 'force=yes' in BPF source.
> Error: Failed to add events.
>
> Signed-off-by: He Zhe <zhe.he@xxxxxxxxxxxxx>
> ---
> tools/perf/util/probe-file.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> index 5003ba403345..cf44c05f89c1 100644
> --- a/tools/perf/util/probe-file.c
> +++ b/tools/perf/util/probe-file.c
> @@ -201,10 +201,16 @@ static struct strlist *__probe_file__get_namelist(int fd, bool include_group)
> if (include_group) {
> ret = e_snprintf(buf, 128, "%s:%s", tev.group,
> tev.event);
> - if (ret >= 0)
> + if (ret >= 0) {
> ret = strlist__add(sl, buf);
> - } else
> + if (ret == -EEXIST)
> + ret = 0;
> + }
> + } else {
> ret = strlist__add(sl, tev.event);
> + if (ret == -EEXIST)
> + ret = 0;
> + }
> clear_probe_trace_event(&tev);
> if (ret < 0)
> break;
> --
> 2.24.1
>


--
Masami Hiramatsu <mhiramat@xxxxxxxxxx>