The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	mingo@elte.hu, acme@redhat.com, irogers@google.com
Subject: Re: [PATCH] perf/tools: fix perf_evsel__fallback() for paranoid=2 and -b
Date: Wed, 25 Mar 2020 12:08:57 +0100	[thread overview]
Message-ID: <20200325110857.GB1856035@krava> (raw)
In-Reply-To: <20200324181020.229914-1-eranian@google.com>

On Tue, Mar 24, 2020 at 11:10:20AM -0700, Stephane Eranian wrote:
> When perf_event_paranoid=2, regular users are prevented from sampling
> at the kernel level. However, it the user passes an event without
> a privilege level, the tool will force :u when it detects paranoid>1.
> This works well, except when branch sampling is requested. It has a more
> stringent requirement especially with exclude_hv.
> $ perf record ls
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.001 MB /tmp/perf.data ]
> 
> But:
> $ perf record -b ls
> 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_SYS_ADMIN).
> 
> The current value is 2:
> 
>       -1: Allow use of (almost) all events by all users
>     >= 0: Disallow raw tracepoint access by users without CAP_IOC_LOCK
>     >= 1: Disallow CPU event access by users without CAP_SYS_ADMIN
>     >= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN
> 
> To make this setting permanent, edit /etc/sysctl.conf too, e.g.:
> 
>     kernel.perf_event_paranoid = -1
> 
> The problem is that in the fallback cod only exclude_kernel is checked and
> if set, then exclude_hv is not forced to 1. When branch sampling is enabled
> exclude_hv must be set.
> 
> This patch fixes the bug in the fallback code by considering the value of
> exclude_hv and not just exclude_kernel. We prefer this approach to give a
> chance to exclude_hv=0.
> 
> Signed-off-by: Stephane Eranian <eranian@google.com>

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

> ---
>  tools/perf/util/evsel.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 816d930d774e7..db0e6112992e5 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -2424,7 +2424,8 @@ bool perf_evsel__fallback(struct evsel *evsel, int err,
>  
>  		zfree(&evsel->name);
>  		return true;
> -	} else if (err == EACCES && !evsel->core.attr.exclude_kernel &&
> +	} else if (err == EACCES &&
> +		   (!evsel->core.attr.exclude_kernel || !evsel->core.attr.exclude_hv) &&
>  		   (paranoid = perf_event_paranoid()) > 1) {
>  		const char *name = perf_evsel__name(evsel);
>  		char *new_name;
> -- 
> 2.25.1.696.g5e7596f4ac-goog
> 


      reply	other threads:[~2020-03-25 11:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 18:10 [PATCH] perf/tools: fix perf_evsel__fallback() for paranoid=2 and -b Stephane Eranian
2020-03-25 11:08 ` Jiri Olsa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200325110857.GB1856035@krava \
    --to=jolsa@redhat.com \
    --cc=acme@redhat.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox