From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Hangliang Lai <laihangliang1@huawei.com>
Cc: namhyung@kernel.org, adrian.hunter@intel.com,
alexander.shishkin@linux.intel.com, brauner@kernel.org,
hewenliang4@huawei.com, irogers@google.com, jolsa@kernel.org,
linfeilong@huawei.com, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org, liuwenyu7@huawei.com,
mark.rutland@arm.com, mingo@redhat.com, yeyunfeng@huawei.com
Subject: Re: [PATCH v4] perf top: expand the range of multithreaded phase
Date: Wed, 12 Apr 2023 10:39:25 -0300 [thread overview]
Message-ID: <ZDa0jXAk0F+tLw1V@kernel.org> (raw)
In-Reply-To: <20230411013224.2079-1-laihangliang1@huawei.com>
Em Tue, Apr 11, 2023 at 09:32:24AM +0800, Hangliang Lai escreveu:
> In __cmd_top, perf_set_multithreaded is used to enable pthread_rwlock, thus
> donw_read and down_write can work to handle concurrency problems. Then top
> use perf_set_singlethreaded and switch to single threaded phase, assuming
> that no thread concurrency will happen later.
> However, a UAF problem could occur in perf top in single threaded phase,
> The concurrent procedure is like this:
> display_thread process_thread
> -------------- --------------
> thread__comm_len
> -> thread__comm_str
> -> __thread__comm_str(thread)
> thread__delete
> -> comm__free
> -> comm_str__put
> -> zfree(&cs->str)
> -> thread->comm_len = strlen(comm);
> Since in single thread phase, perf_singlethreaded is true, down_read and
> down_write can not work to avoid concurrency problems.
> This patch put perf_set_singlethreaded to the function tail to expand the
> multithreaded phase range, make display_thread and process_thread run
> safe.
>
> Signed-off-by: Hangliang Lai <laihangliang1@huawei.com>
> Co-developed-by: Wenyu Liu <liuwenyu7@huawei.com>
> Reviewed-by: Yunfeng Ye <yeyunfeng@huawei.com>
> Acked-by: Namhyung Kim <namhyung@kernel.org>
Thanks, applied.
- Arnaldo
> ---
> v3 -> v4
> - Add Acked-by and Co-developed-by.
>
> tools/perf/builtin-top.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
> index d4b5b02bab73..ae96ddaf85c4 100644
> --- a/tools/perf/builtin-top.c
> +++ b/tools/perf/builtin-top.c
> @@ -1273,8 +1273,7 @@ static int __cmd_top(struct perf_top *top)
> top->evlist->core.threads, true, false,
> top->nr_threads_synthesize);
>
> - if (top->nr_threads_synthesize > 1)
> - perf_set_singlethreaded();
> + perf_set_multithreaded();
>
> if (perf_hpp_list.socket) {
> ret = perf_env__read_cpu_topology_map(&perf_env);
> @@ -1352,6 +1351,7 @@ static int __cmd_top(struct perf_top *top)
> out_join_thread:
> cond_signal(&top->qe.cond);
> pthread_join(thread_process, NULL);
> + perf_set_singlethreaded();
> return ret;
> }
>
> --
> 2.33.0
>
--
- Arnaldo
prev parent reply other threads:[~2023-04-12 13:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-17 10:05 [PATCH] perf top: expand the range of multithreaded phase Hangliang Lai
2023-04-01 0:11 ` Namhyung Kim
2023-04-06 2:53 ` [PATCH v2] " Hangliang Lai
2023-04-07 21:21 ` Namhyung Kim
2023-04-10 2:58 ` Hangliang Lai
2023-04-10 3:38 ` Wenyu Liu(D)
2023-04-10 13:22 ` [PATCH v3] " Hangliang Lai
2023-04-10 15:36 ` Namhyung Kim
2023-04-11 1:32 ` [PATCH v4] " Hangliang Lai
2023-04-12 13:39 ` Arnaldo Carvalho de Melo [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=ZDa0jXAk0F+tLw1V@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=brauner@kernel.org \
--cc=hewenliang4@huawei.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=laihangliang1@huawei.com \
--cc=linfeilong@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=liuwenyu7@huawei.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=yeyunfeng@huawei.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.