From: James Clark <james.clark@arm.com>
To: Leo Yan <leo.yan@linaro.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Namhyung Kim <namhyung@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>, Jin Yao <yao.jin@linux.intel.com>,
John Garry <john.garry@huawei.com>,
Yonatan Goldschmidt <yonatan.goldschmidt@granulate.io>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v1 2/2] perf evlist: Don't run perf in non-root PID namespace when launch workload
Date: Mon, 13 Dec 2021 13:54:33 +0000 [thread overview]
Message-ID: <6cad0a2e-c4b8-9788-fa0d-05405453a0dd@arm.com> (raw)
In-Reply-To: <20211212134721.1721245-3-leo.yan@linaro.org>
On 12/12/2021 13:47, Leo Yan wrote:
> In function evlist__prepare_workload(), after perf forks a child process
> and launches a workload in the created process, it needs to retrieve
> process and namespace related info via '/proc/$PID/' node.
>
> The process folders under 'proc' file system use the PID number from the
> root PID namespace, when perf tool runs in non-root PID namespace and
> creates new process for profiled program, this leads to the perf tool
> wrongly gather process info since it uses PID from non-root namespace to
> access nodes under '/proc'.
>
> Let's see an example:
>
> unshare --fork --pid perf record -e cs_etm//u -a -- test_program
>
> This command runs perf tool and the profiled program 'test_program' in
> the non-root PID namespace. When perf tool launches 'test_program',
> e.g. the forked PID number is 2, perf tool retrieves process info for
> 'test_program' from the folder '/proc/2'. But '/proc/2' is actually for
> a kernel thread so perf tool wrongly gather info for 'test_program'.
Hi Leo,
Which features aren't working exactly when you run in a non root namespace?
I did "perf record -- ls" and it seemed to be working for me. At least kernel
sampling would be working in a namespace, even if there was something wrong
with userspace.
I think causing a failure might be too restrictive and would prevent people
from using perf in a container. Maybe we could show a warning instead, but
I'm not sure exactly what's not working because I thought perf looked up stuff
based on the path of the process not the pid.
James
>
> To fix this issue, we don't allow perf tool runs in non-root PID
> namespace when it launches workload and reports error in this
> case. This can notify users to run the perf tool in root PID namespace
> to gather correct info for profiled program.
>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
> tools/perf/util/evlist.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 5f92319ce258..bdf79a97db66 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -11,6 +11,7 @@
> #include <poll.h>
> #include "cpumap.h"
> #include "util/mmap.h"
> +#include "util/namespaces.h"
> #include "thread_map.h"
> #include "target.h"
> #include "evlist.h"
> @@ -1364,6 +1365,12 @@ int evlist__prepare_workload(struct evlist *evlist, struct target *target, const
> int child_ready_pipe[2], go_pipe[2];
> char bf;
>
> + if (!nsinfo__is_in_root_namespace()) {
> + pr_err("Perf runs in non-root PID namespace; please run perf tool ");
> + pr_err("in the root PID namespace for gathering process info.\n");
> + return -EPERM;
> + }
> +
> if (pipe(child_ready_pipe) < 0) {
> perror("failed to create 'ready' pipe");
> return -1;
>
next prev parent reply other threads:[~2021-12-13 13:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-12 13:47 [PATCH v1 0/2] perf: Fix perf in non-root PID namespace Leo Yan
2021-12-12 13:47 ` [PATCH v1 1/2] perf namespaces: Add helper nsinfo__is_in_root_namespace() Leo Yan
2021-12-13 18:20 ` Arnaldo Carvalho de Melo
2021-12-12 13:47 ` [PATCH v1 2/2] perf evlist: Don't run perf in non-root PID namespace when launch workload Leo Yan
2021-12-13 13:54 ` James Clark [this message]
2021-12-14 3:24 ` Leo Yan
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=6cad0a2e-c4b8-9788-fa0d-05405453a0dd@arm.com \
--to=james.clark@arm.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=john.garry@huawei.com \
--cc=jolsa@redhat.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=songliubraving@fb.com \
--cc=yao.jin@linux.intel.com \
--cc=yhs@fb.com \
--cc=yonatan.goldschmidt@granulate.io \
/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