linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf hist: Don't set hpp_fmt_value for members in --no-group
@ 2024-08-20 18:32 kan.liang
  2024-08-22  0:38 ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: kan.liang @ 2024-08-20 18:32 UTC (permalink / raw)
  To: acme, namhyung, irogers, peterz, mingo, linux-kernel,
	linux-perf-users
  Cc: Kan Liang

From: Kan Liang <kan.liang@linux.intel.com>

Perf crashes as below when applying --no-group

perf record -e "{cache-misses,branches"} -b sleep 1
perf report --stdio --no-group
free(): invalid next size (fast)
Aborted (core dumped)

In the __hpp__fmt(), only 1 hpp_fmt_value is allocated for the current
event when --no-group is applied. However, the current implementation
tries to assign the hists from all members to the hpp_fmt_value, which
exceeds the allocated memory.

Fixes: 8f6071a3dce4 ("perf hist: Simplify __hpp_fmt() using hpp_fmt_data")
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
 tools/perf/ui/hist.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 5d1f04f66a5a..e5491995adf0 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -62,7 +62,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
 	struct evsel *pos;
 	char *buf = hpp->buf;
 	size_t size = hpp->size;
-	int i, nr_members = 1;
+	int i = 0, nr_members = 1;
 	struct hpp_fmt_value *values;
 
 	if (evsel__is_group_event(evsel))
@@ -72,16 +72,16 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
 	if (values == NULL)
 		return 0;
 
-	i = 0;
-	for_each_group_evsel(pos, evsel)
-		values[i++].hists = evsel__hists(pos);
-
+	values[0].hists = evsel__hists(evsel);
 	values[0].val = get_field(he);
 	values[0].samples = he->stat.nr_events;
 
 	if (evsel__is_group_event(evsel)) {
 		struct hist_entry *pair;
 
+		for_each_group_member(pos, evsel)
+			values[++i].hists = evsel__hists(pos);
+
 		list_for_each_entry(pair, &he->pairs.head, pairs.node) {
 			for (i = 0; i < nr_members; i++) {
 				if (values[i].hists != pair->hists)
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf hist: Don't set hpp_fmt_value for members in --no-group
  2024-08-20 18:32 [PATCH] perf hist: Don't set hpp_fmt_value for members in --no-group kan.liang
@ 2024-08-22  0:38 ` Namhyung Kim
  2024-08-26 14:33   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2024-08-22  0:38 UTC (permalink / raw)
  To: kan.liang; +Cc: acme, irogers, peterz, mingo, linux-kernel, linux-perf-users

Hi Kan,

On Tue, Aug 20, 2024 at 11:31 AM <kan.liang@linux.intel.com> wrote:
>
> From: Kan Liang <kan.liang@linux.intel.com>
>
> Perf crashes as below when applying --no-group
>
> perf record -e "{cache-misses,branches"} -b sleep 1
> perf report --stdio --no-group
> free(): invalid next size (fast)
> Aborted (core dumped)
>
> In the __hpp__fmt(), only 1 hpp_fmt_value is allocated for the current
> event when --no-group is applied. However, the current implementation
> tries to assign the hists from all members to the hpp_fmt_value, which
> exceeds the allocated memory.
>
> Fixes: 8f6071a3dce4 ("perf hist: Simplify __hpp_fmt() using hpp_fmt_data")
> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

> ---
>  tools/perf/ui/hist.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
> index 5d1f04f66a5a..e5491995adf0 100644
> --- a/tools/perf/ui/hist.c
> +++ b/tools/perf/ui/hist.c
> @@ -62,7 +62,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
>         struct evsel *pos;
>         char *buf = hpp->buf;
>         size_t size = hpp->size;
> -       int i, nr_members = 1;
> +       int i = 0, nr_members = 1;
>         struct hpp_fmt_value *values;
>
>         if (evsel__is_group_event(evsel))
> @@ -72,16 +72,16 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
>         if (values == NULL)
>                 return 0;
>
> -       i = 0;
> -       for_each_group_evsel(pos, evsel)
> -               values[i++].hists = evsel__hists(pos);
> -
> +       values[0].hists = evsel__hists(evsel);
>         values[0].val = get_field(he);
>         values[0].samples = he->stat.nr_events;
>
>         if (evsel__is_group_event(evsel)) {
>                 struct hist_entry *pair;
>
> +               for_each_group_member(pos, evsel)
> +                       values[++i].hists = evsel__hists(pos);
> +
>                 list_for_each_entry(pair, &he->pairs.head, pairs.node) {
>                         for (i = 0; i < nr_members; i++) {
>                                 if (values[i].hists != pair->hists)
> --
> 2.38.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf hist: Don't set hpp_fmt_value for members in --no-group
  2024-08-22  0:38 ` Namhyung Kim
@ 2024-08-26 14:33   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-08-26 14:33 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: kan.liang, irogers, peterz, mingo, linux-kernel, linux-perf-users

On Wed, Aug 21, 2024 at 05:38:45PM -0700, Namhyung Kim wrote:
> Hi Kan,
> 
> On Tue, Aug 20, 2024 at 11:31 AM <kan.liang@linux.intel.com> wrote:
> >
> > From: Kan Liang <kan.liang@linux.intel.com>
> >
> > Perf crashes as below when applying --no-group
> >
> > perf record -e "{cache-misses,branches"} -b sleep 1
> > perf report --stdio --no-group
> > free(): invalid next size (fast)
> > Aborted (core dumped)
> >
> > In the __hpp__fmt(), only 1 hpp_fmt_value is allocated for the current
> > event when --no-group is applied. However, the current implementation
> > tries to assign the hists from all members to the hpp_fmt_value, which
> > exceeds the allocated memory.
> >
> > Fixes: 8f6071a3dce4 ("perf hist: Simplify __hpp_fmt() using hpp_fmt_data")
> > Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks, applied to perf-tools-next,

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-26 14:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-20 18:32 [PATCH] perf hist: Don't set hpp_fmt_value for members in --no-group kan.liang
2024-08-22  0:38 ` Namhyung Kim
2024-08-26 14:33   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).