perf jevents: Fix event code for events referencing std arch events
PATCH 1/1 perf jevents: Fix event code for events referencing std arch events
The event code for events referencing std arch events is incorrectly evaluated in json_events().
The issue is that je.event is evaluated properly from try_fixup(), but later NULLified from the real_event() call, as "event" may be NULL.
Fix by setting "event" same je.event in try_fixup().
Also remove support for overwriting event code for events using std arch events, as it is not used.
tools/perf/pmu-events/jevents.c +3 -8
@@ -505,20 +505,15 @@ static char *real_event(const char *name, char *event) }static int -try_fixup (const char *fn,char *arch_std,unsigned long long eventcode, -struct json_event *je) +try_fixup (const char *fn,char *arch_std,struct json_event *je,char **event) {/* try to find matching event from arch standard values */ struct event_struct *es;list_for_each_entry (es, &arch_std_events, list) {if (!strcmp (arch_std, es->name)) { -if (!eventcode && es->event) { -/* allow EventCode to be overridden */ -free (je->event); - je->event =NULL ; - }FOR_ALL_EVENT_STRUCT_FIELDS (TRY_FIXUP_FIELD ); + *event = je->event;return 0 ; } }
@@ -678,7 +673,7 @@ static int json_events(const char *fn,* An arch standard event is referenced, so try to * fixup any unassigned values. */ - err =try_fixup (fn, arch_std, eventcode, &je); + err =try_fixup (fn, arch_std, &je, &event);if (err) goto free_strings; }
Signature · 1 line
2.26.2
Quoted 10 lines · John Garry
The event code for events referencing std arch events is incorrectly evaluated in
json_events().The issue is that je.event is evaluated properly from
try_fixup(), but later NULLified from thereal_event()call, as "event" may be NULL.Fix by setting "event" same je.event in
try_fixup().Also remove support for overwriting event code for events using std arch events, as it is not used.
Patch looks good to me. Not sure if any adding any example with this issue is helpful.
Thanks,
Kajol Jain
Quoted 40 lines
Signed-off-by John Garry <[email protected]>tools/perf/pmu-events/jevents.c +3
-8@@ -505,20 +505,15 @@ static char *real_event(const char *name, char *event) }static int -try_fixup (const char *fn,char *arch_std,unsigned long long eventcode, -struct json_event *je) +try_fixup (const char *fn,char *arch_std,struct json_event *je,char **event) {/* try to find matching event from arch standard values */ struct event_struct *es;list_for_each_entry (es, &arch_std_events, list) {if (!strcmp (arch_std, es->name)) { -if (!eventcode && es->event) { -/* allow EventCode to be overridden */ -free (je->event); - je->event =NULL ; - }FOR_ALL_EVENT_STRUCT_FIELDS (TRY_FIXUP_FIELD ); + *event = je->event;return 0 ; } }@@ -678,7 +673,7 @@ static int json_events(const char *fn,* An arch standard event is referenced, so try to * fixup any unassigned values. */ - err =try_fixup (fn, arch_std, eventcode, &je); + err =try_fixup (fn, arch_std, &je, &event);if (err) goto free_strings; }
Quoted 8 lines · kajoljain
Quoted 6 lines · John Garry
The event code for events referencing std arch events is incorrectly evaluated in
json_events().The issue is that je.event is evaluated properly from
try_fixup(), but later NULLified from thereal_event()call, as "event" may be NULL.
Quoted 6 lines
Quoted 4 lines
Fix by setting "event" same je.event in
try_fixup().Also remove support for overwriting event code for events using std arch events, as it is not used.
Patch looks good to me. Not sure if any adding any example with this issue is helpful.
So we get something like this in pmu-events.c:
{
.name = "l1d_cache_wb_victim",
.event = "event=0x0",[...]
},
But event should "event=0x46".
I can add this if Arnaldo wants a v2.
Quoted 2 lines
Reviewed-by Kajol Jain<[email protected]>
thanks
Quoted 27 lines · John Garry
The event code for events referencing std arch events is incorrectly evaluated in
json_events().The issue is that je.event is evaluated properly from
try_fixup(), but later NULLified from thereal_event()call, as "event" may be NULL.Fix by setting "event" same je.event in
try_fixup().Also remove support for overwriting event code for events using std arch events, as it is not used.
Signed-off-by John Garry <[email protected]>tools/perf/pmu-events/jevents.c +1
-2@@ -505,20 +505,15 @@ static char *real_event(const char *name, char *event) }static int -try_fixup (const char *fn,char *arch_std,unsigned long long eventcode, -struct json_event *je) +try_fixup (const char *fn,char *arch_std,struct json_event *je,char **event) {/* try to find matching event from arch standard values */ struct event_struct *es;
tools/perf/pmu-events/jevents.c static char *real_event(const char *name, char *event) · line 516
Quoted 10 lines
tools/perf/pmu-events/jevents.c +1
-5list_for_each_entry (es, &arch_std_events, list) {if (!strcmp (arch_std, es->name)) { -if (!eventcode && es->event) { -/* allow EventCode to be overridden */ -free (je->event); - je->event =NULL ; - }FOR_ALL_EVENT_STRUCT_FIELDS (TRY_FIXUP_FIELD ); + *event = je->event;
I'm bit rusty on this code, but isn't je->event NULL at this point?
jirka
Quoted 15 lines
tools/perf/pmu-events/jevents.c +1
-1return 0 ; } }@@ -678,7 +673,7 @@ static int json_events(const char *fn,* An arch standard event is referenced, so try to * fixup any unassigned values. */ - err =try_fixup (fn, arch_std, eventcode, &je); + err =try_fixup (fn, arch_std, &je, &event);if (err) goto free_strings; }Signature · 1 line
2.26.2
Quoted 15 lines · Jiri Olsa
Quoted 15 lines
ff --git
a/tools/perf/pmu-events/jevents.cb/tools/perf/pmu-events/jevents.cindex99df41a9543d..e47644cab3fa100644tools/perf/pmu-events/jevents.c +1
-2@@ -505,20 +505,15 @@ static char *real_event(const char *name, char *event) }static int -try_fixup (const char *fn,char *arch_std,unsigned long long eventcode, -struct json_event *je) +try_fixup (const char *fn,char *arch_std,struct json_event *je,char **event) {/* try to find matching event from arch standard values */ struct event_struct *es;
Quoted 10 lines
tools/perf/pmu-events/jevents.c static char *real_event(const char *name, char *event) · line 516
Quoted 9 lines
tools/perf/pmu-events/jevents.c +1
-5list_for_each_entry (es, &arch_std_events, list) {if (!strcmp (arch_std, es->name)) { -if (!eventcode && es->event) { -/* allow EventCode to be overridden */ -free (je->event); - je->event =NULL ; - }FOR_ALL_EVENT_STRUCT_FIELDS (TRY_FIXUP_FIELD ); + *event = je->event;I'm bit rusty on this code, but isn't
je->eventNULL at this point?
je->event should be now assigned from es->event because of FOR_ALL_EVENT_STRUCT_FIELDS(TRY_FIXUP_FIELD):
#define TRY_FIXUP_FIELD(field) do { if (es->field && !*field) {\
*field = strdup(es->field); \
if (!*field) \
return -ENOMEM; \
} } while (0)And es->event should be set.
Thanks,
John
Jiri Olsa
Acked-byQuoted 28 lines · John Garry
Quoted 15 lines · Jiri Olsa
Quoted 15 lines
ff --git
a/tools/perf/pmu-events/jevents.cb/tools/perf/pmu-events/jevents.cindex99df41a9543d..e47644cab3fa100644tools/perf/pmu-events/jevents.c +1
-2@@ -505,20 +505,15 @@ static char *real_event(const char *name, char *event) }static int -try_fixup (const char *fn,char *arch_std,unsigned long long eventcode, -struct json_event *je) +try_fixup (const char *fn,char *arch_std,struct json_event *je,char **event) {/* try to find matching event from arch standard values */ struct event_struct *es;list_for_each_entry (es, &arch_std_events, list) {if (!strcmp (arch_std, es->name)) {Quoted 8 lines
tools/perf/pmu-events/jevents.c static char *real_event(const char *name, char *event) · line 516
Quoted 7 lines
tools/perf/pmu-events/jevents.c +1
-5-if (!eventcode && es->event) { -/* allow EventCode to be overridden */ -free (je->event); - je->event =NULL ; - }FOR_ALL_EVENT_STRUCT_FIELDS (TRY_FIXUP_FIELD ); + *event = je->event;I'm bit rusty on this code, but isn't
je->eventNULL at this point?
je->eventshould be now assigned fromes->eventbecause ofFOR_ALL_EVENT_STRUCT_FIELDS(TRY_FIXUP_FIELD):
Quoted 7 lines
#define TRY_FIXUP_FIELD(field) do { if (es->field && !*field) {\ *field = strdup(es->field); \ if (!*field) \ return -ENOMEM; \ } } while (0)And
es->eventshould be set.
right, thanks
jirka
Quoted 37 lines · Jiri Olsa
Quoted 28 lines · John Garry
Quoted 15 lines · Jiri Olsa
Quoted 15 lines
ff --git
a/tools/perf/pmu-events/jevents.cb/tools/perf/pmu-events/jevents.cindex99df41a9543d..e47644cab3fa100644tools/perf/pmu-events/jevents.c +1
-2@@ -505,20 +505,15 @@ static char *real_event(const char *name, char *event) }static int -try_fixup (const char *fn,char *arch_std,unsigned long long eventcode, -struct json_event *je) +try_fixup (const char *fn,char *arch_std,struct json_event *je,char **event) {/* try to find matching event from arch standard values */ struct event_struct *es;list_for_each_entry (es, &arch_std_events, list) {if (!strcmp (arch_std, es->name)) {Quoted 8 lines
tools/perf/pmu-events/jevents.c static char *real_event(const char *name, char *event) · line 516
Quoted 7 lines
tools/perf/pmu-events/jevents.c +1
-5-if (!eventcode && es->event) { -/* allow EventCode to be overridden */ -free (je->event); - je->event =NULL ; - }FOR_ALL_EVENT_STRUCT_FIELDS (TRY_FIXUP_FIELD ); + *event = je->event;I'm bit rusty on this code, but isn't
je->eventNULL at this point?
je->eventshould be now assigned fromes->eventbecause ofFOR_ALL_EVENT_STRUCT_FIELDS(TRY_FIXUP_FIELD):Quoted 7 lines
#define TRY_FIXUP_FIELD(field) do { if (es->field && !*field) {\ *field = strdup(es->field); \ if (!*field) \ return -ENOMEM; \ } } while (0)And
es->eventshould be set.
Quoted 8 lines
right, thanks
Acked-by Jiri Olsa <[email protected]>jirka
.
"PMU events" testcase was still passing as it does not cover this scenario, so I'll look to expand the test to catch such problems.
Thanks,
John
Arnaldo Carvalho de Melo
maintainerEm Mon, Oct 12, 2020 at 01:24:19PM +0200, Jiri Olsa escreveu:
Quoted 35 lines · John Garry
Quoted 34 lines · Jiri Olsa
Quoted 15 lines
Quoted 15 lines
ff --git
a/tools/perf/pmu-events/jevents.cb/tools/perf/pmu-events/jevents.cindex99df41a9543d..e47644cab3fa100644tools/perf/pmu-events/jevents.c +1
-2@@ -505,20 +505,15 @@ static char *real_event(const char *name, char *event) }static int -try_fixup (const char *fn,char *arch_std,unsigned long long eventcode, -struct json_event *je) +try_fixup (const char *fn,char *arch_std,struct json_event *je,char **event) {/* try to find matching event from arch standard values */ struct event_struct *es;list_for_each_entry (es, &arch_std_events, list) {if (!strcmp (arch_std, es->name)) {Quoted 8 lines
tools/perf/pmu-events/jevents.c static char *real_event(const char *name, char *event) · line 516
Quoted 7 lines
tools/perf/pmu-events/jevents.c +1
-5-if (!eventcode && es->event) { -/* allow EventCode to be overridden */ -free (je->event); - je->event =NULL ; - }FOR_ALL_EVENT_STRUCT_FIELDS (TRY_FIXUP_FIELD ); + *event = je->event;I'm bit rusty on this code, but isn't
je->eventNULL at this point?
je->eventshould be now assigned fromes->eventbecause ofFOR_ALL_EVENT_STRUCT_FIELDS(TRY_FIXUP_FIELD):#define TRY_FIXUP_FIELD(field) do { if (es->field && !*field) {\ *field = strdup(es->field); \ if (!*field) \ return -ENOMEM; \ } } while (0)
Quoted 5 lines
Quoted 1 line
And
es->eventshould be set.right, thanks
Acked-by Jiri Olsa <[email protected]>
Ok, applied, please consider adding a Fixes tag next time.
- Arnaldo
Quoted 1 line · Arnaldo Carvalho de Melo
Ok, applied,
Thanks
Quoted 2 lines
please consider adding a Fixes tag next time.
Can do if it helps, but I only thought it appropriate when fixing something merged to mainline.
John
Arnaldo Carvalho de Melo
maintainerEm Wed, Oct 14, 2020 at 06:46:12PM +0100, John Garry escreveu:
Quoted 10 lines · Arnaldo Carvalho de Melo
Quoted 1 line
Ok, applied,
Thanks
Quoted 2 lines
please consider adding a Fixes tag next time.
Can do if it helps, but I only thought it appropriate when fixing something merged to mainline.
Please do, I think it appropriate in all cases, people doing backports may decide to pick something and if it has some subtle issue this can be automatically checked for by looking at any later Fixes for that specific cset.
I decided not to do any rebase on perf/core, so those Fixes will remain valid.
- Arnaldo
Quoted 4 lines
I decided not to do any rebase on perf/core, so those Fixes will remain valid.
Ah, ok. Then that should be fine wrt fixes tags.
Cheers,
John