[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <fcc4a9091ff02606df9495fd16b00094216a933e.1755096883.git.robin.murphy@arm.com>
Date: Wed, 13 Aug 2025 18:00:57 +0100
From: Robin Murphy <robin.murphy@....com>
To: peterz@...radead.org,
mingo@...hat.com,
will@...nel.org,
mark.rutland@....com,
acme@...nel.org,
namhyung@...nel.org,
alexander.shishkin@...ux.intel.com,
jolsa@...nel.org,
irogers@...gle.com,
adrian.hunter@...el.com,
kan.liang@...ux.intel.com
Cc: linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-alpha@...r.kernel.org,
linux-snps-arc@...ts.infradead.org,
linux-arm-kernel@...ts.infradead.org,
imx@...ts.linux.dev,
linux-csky@...r.kernel.org,
loongarch@...ts.linux.dev,
linux-mips@...r.kernel.org,
linuxppc-dev@...ts.ozlabs.org,
linux-s390@...r.kernel.org,
linux-sh@...r.kernel.org,
sparclinux@...r.kernel.org,
linux-pm@...r.kernel.org,
linux-rockchip@...ts.infradead.org,
dmaengine@...r.kernel.org,
linux-fpga@...r.kernel.org,
amd-gfx@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org,
intel-gfx@...ts.freedesktop.org,
intel-xe@...ts.freedesktop.org,
coresight@...ts.linaro.org,
iommu@...ts.linux.dev,
linux-amlogic@...ts.infradead.org,
linux-cxl@...r.kernel.org,
linux-arm-msm@...r.kernel.org,
linux-riscv@...ts.infradead.org
Subject: [PATCH 05/19] iommu/vt-d: Fix perfmon group validation
The group validation here has a few issues to fix: firstly, failing to
count the group leader or the event being opened itself. Secondly it
appears wrong not to count disabled sibling events given that they could
be enabled later. Finally there's the subtlety that we should avoid racy
access to the sibling list when the event is its own group leader.
Signed-off-by: Robin Murphy <robin.murphy@....com>
---
drivers/iommu/intel/perfmon.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/iommu/intel/perfmon.c b/drivers/iommu/intel/perfmon.c
index 75f493bcb353..c3a1ac14cb2b 100644
--- a/drivers/iommu/intel/perfmon.c
+++ b/drivers/iommu/intel/perfmon.c
@@ -258,21 +258,25 @@ static int iommu_pmu_validate_group(struct perf_event *event)
{
struct iommu_pmu *iommu_pmu = iommu_event_to_pmu(event);
struct perf_event *sibling;
- int nr = 0;
+ int nr = 1;
+ if (event == event->group_leader)
+ return 0;
/*
* All events in a group must be scheduled simultaneously.
* Check whether there is enough counters for all the events.
*/
- for_each_sibling_event(sibling, event->group_leader) {
- if (!is_iommu_pmu_event(iommu_pmu, sibling) ||
- sibling->state <= PERF_EVENT_STATE_OFF)
- continue;
+ if (is_iommu_pmu_event(iommu_pmu, event->group_leader))
+ ++nr;
- if (++nr > iommu_pmu->num_cntr)
- return -EINVAL;
+ for_each_sibling_event(sibling, event->group_leader) {
+ if (is_iommu_pmu_event(iommu_pmu, sibling))
+ ++nr;
}
+ if (nr > iommu_pmu->num_cntr)
+ return -EINVAL;
+
return 0;
}
--
2.39.2.101.g768bb238c484.dirty
Powered by blists - more mailing lists