Re: [PATCH 4/4] perf mem: Fix a segfault with NULL event->name

From: Namhyung Kim
Date: Tue Jun 25 2024 - 01:07:56 EST


Hi Kan,

On Fri, Jun 21, 2024 at 1:11 PM Liang, Kan <kan.liang@xxxxxxxxxxxxxxx> wrote:
>
>
>
> On 2024-06-21 1:05 p.m., Namhyung Kim wrote:
> > Guilherme reported a crash in perf mem record. It's because the
> > perf_mem_event->name was NULL on his machine. It should just return
> > a NULL string when it has no format string in the name.
> >
> > But I'm not sure why it returns TRUE if it doesn't have event_name in
> > perf_pmu__mem_events_supported().
>
> AMD doesn't have the event_name.
>
> struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {
> E(NULL, NULL, NULL, false, 0),
> E(NULL, NULL, NULL, false, 0),
> E("mem-ldst", "%s//", NULL, false, 0),
> };
>
> It looks like as long as it's a "ibs_op" PMU, the mem event is always
> available. The "ibs_op" check has been moved into perf_pmu__arch_init().
> So the event_name is empty.
>
> The "e->tag" in the perf_pmu__mem_events_init() can help to skip the
> case E(NULL, NULL, NULL, false, 0).
> So the perf_pmu__mem_events_supported() returns TRUE for the !event_name.

Ok, thanks for the explanation!

Namhyung