perf/amd: Prevent grouping of IBS events
authorRavi Bangoria <ravi.bangoria@amd.com>
Tue, 20 Jun 2023 09:16:03 +0000 (14:46 +0530)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 10 Jul 2023 07:52:34 +0000 (09:52 +0200)
IBS PMUs can have only one event active at any point in time. Restrict
grouping of multiple IBS events.

Reported-by: Sandipan Das <sandipan.das@amd.com>
Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230620091603.269-1-ravi.bangoria@amd.com
arch/x86/events/amd/ibs.c

index 371014802191670e2697925e7e90e64e8cdb2530..74e664266753fc3544b0539e4b0b8629ed15b25d 100644 (file)
@@ -247,11 +247,33 @@ int forward_event_to_ibs(struct perf_event *event)
        return -ENOENT;
 }
 
+/*
+ * Grouping of IBS events is not possible since IBS can have only
+ * one event active at any point in time.
+ */
+static int validate_group(struct perf_event *event)
+{
+       struct perf_event *sibling;
+
+       if (event->group_leader == event)
+               return 0;
+
+       if (event->group_leader->pmu == event->pmu)
+               return -EINVAL;
+
+       for_each_sibling_event(sibling, event->group_leader) {
+               if (sibling->pmu == event->pmu)
+                       return -EINVAL;
+       }
+       return 0;
+}
+
 static int perf_ibs_init(struct perf_event *event)
 {
        struct hw_perf_event *hwc = &event->hw;
        struct perf_ibs *perf_ibs;
        u64 max_cnt, config;
+       int ret;
 
        perf_ibs = get_ibs_pmu(event->attr.type);
        if (!perf_ibs)
@@ -265,6 +287,10 @@ static int perf_ibs_init(struct perf_event *event)
        if (config & ~perf_ibs->config_mask)
                return -EINVAL;
 
+       ret = validate_group(event);
+       if (ret)
+               return ret;
+
        if (hwc->sample_period) {
                if (config & perf_ibs->cnt_mask)
                        /* raw max_cnt may not be set */