perf: Fix exclusive events' grouping
Alexander Shishkin
reviewerPATCH 1/1 perf: Fix exclusive events' grouping
So far, we tried to disallow grouping exclusive events for the fear of complications they would cause with moving between contexts. Specifically, moving a software group to a hardware context would violate the exclusivity rules if both groups contain matching exclusive events.
This attempt was, however, unsuccessful: the check that we have in the perf_event_open() syscall is both wrong (looks at wrong PMU) and insufficient (group leader may still be exclusive), as can be illustrated by running
$ perf record -e '{intel_pt//,cycles}' uname
$ perf record -e '{cycles,intel_pt//}' unameultimately successfully.
Furthermore, we are completely free to trigger the exclusivity violation by -e '{cycles,intel_pt//}' -e '{intel_pt//,instructions}', even though the helpful perf record will not allow that, the ABI will. The warning later in the perf_event_open() path will also not trigger, because it's also wrong.
Fix all this by validating the original group before moving, getting rid of broken safeguards and placing a useful one to perf_install_in_context(). And while at it, place exclusive events on their own list to avoid iterating through all events.
--- include/linux/perf_event.h | 12 +++++++++++ kernel/events/core.c | 41 ++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 13 deletions(-)
include/linux/perf_event.h +12 -0
@@ -574,6 +574,12 @@ struct perf_event {*/ struct list_head sibling_list;struct list_head active_list; + +/* +* Link to ctx::exclusive_list +*/ +struct list_head exclusive_entry; +/* * Node on the pinned or flexible tree located at the event context; */
@@ -739,6 +745,7 @@ struct perf_event_context {struct perf_event_groups pinned_groups;struct perf_event_groups flexible_groups;struct list_head event_list; +struct list_head exclusive_list;struct list_head pinned_active;struct list_head flexible_active;
@@ -1054,6 +1061,11 @@ static inline int in_software_context(struct perf_event *event)return event->ctx->pmu->task_ctx_nr == perf_sw_context; } +static inline int is_exclusive_pmu (struct pmu *pmu) +{ +return pmu->capabilities &PERF_PMU_CAP_EXCLUSIVE ; +} +extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX ];extern void ___perf_sw_event (u32 ,u64 ,struct pt_regs *,u64 );
kernel/events/core.c +28 -13
115 lines not on this page · raw message
Signature · 1 line
2.20.1