Re: [PATCH v2] perf stat: force error in fallback on :k events

From: Jiri Olsa
Date: Wed Apr 15 2020 - 05:18:52 EST


On Tue, Apr 14, 2020 at 09:15:50AM -0700, Ian Rogers wrote:

SNIP

> New behavior with paranoid 2:
> $ sudo bash -c "echo 2 > /proc/sys/kernel/perf_event_paranoid"
> $ perf stat -e cycles:k sleep 1
> Error:
> You may not have permission to collect stats.
>
> Consider tweaking /proc/sys/kernel/perf_event_paranoid,
> which controls use of the performance events system by
> unprivileged users (without CAP_PERFMON or CAP_SYS_ADMIN).
>
> The current value is 2:
>
> -1: Allow use of (almost) all events by all users
> Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
> >= 0: Disallow ftrace function tracepoint by users without CAP_PERFMON or CAP_SYS_ADMIN
> Disallow raw tracepoint access by users without CAP_SYS_PERFMON or CAP_SYS_ADMIN
> >= 1: Disallow CPU event access by users without CAP_PERFMON or CAP_SYS_ADMIN
> >= 2: Disallow kernel profiling by users without CAP_PERFMON or CAP_SYS_ADMIN
>
> To make this setting permanent, edit /etc/sysctl.conf too, e.g.:
>
> kernel.perf_event_paranoid = -1
>
> v2 of this patch addresses the review feedback from jolsa@xxxxxxxxxxx
>
> Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
> Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>
> ---
> tools/perf/util/evsel.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index d23db6755f51..b4e8bcb5ab05 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -2446,6 +2446,10 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
> char *new_name;
> const char *sep = ":";
>
> + /* If event has exclude user then don't exclude kernel. */
> + if (evsel->core.attr.exclude_user)
> + return false;
> +

nice, it's much simpler

Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>

thanks,
jirka

> /* Is there already the separator in the name. */
> if (strchr(name, '/') ||
> strchr(name, ':'))
> --
> 2.26.0.110.g2183baf09c-goog
>